2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <asm/unaligned.h>
59 #include "mpt3sas_base.h"
61 #define RAID_CHANNEL 1
63 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
64 struct _sas_node *sas_expander);
65 static void _firmware_event_work(struct work_struct *work);
67 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
68 struct _sas_device *sas_device);
69 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
70 u8 retry_count, u8 is_pd);
72 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
74 /* global parameters */
75 LIST_HEAD(mpt3sas_ioc_list);
76 /* global ioc lock for list operations */
77 DEFINE_SPINLOCK(gioc_lock);
79 MODULE_AUTHOR(MPT3SAS_AUTHOR);
80 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
83 MODULE_ALIAS("mpt2sas");
85 /* local parameters */
86 static u8 scsi_io_cb_idx = -1;
87 static u8 tm_cb_idx = -1;
88 static u8 ctl_cb_idx = -1;
89 static u8 base_cb_idx = -1;
90 static u8 port_enable_cb_idx = -1;
91 static u8 transport_cb_idx = -1;
92 static u8 scsih_cb_idx = -1;
93 static u8 config_cb_idx = -1;
97 static u8 tm_tr_cb_idx = -1 ;
98 static u8 tm_tr_volume_cb_idx = -1 ;
99 static u8 tm_sas_control_cb_idx = -1;
101 /* command line options */
102 static u32 logging_level;
103 MODULE_PARM_DESC(logging_level,
104 " bits for enabling additional logging info (default=0)");
107 static ushort max_sectors = 0xFFFF;
108 module_param(max_sectors, ushort, 0);
109 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
112 static int missing_delay[2] = {-1, -1};
113 module_param_array(missing_delay, int, NULL, 0);
114 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
116 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
117 #define MPT3SAS_MAX_LUN (16895)
118 static u64 max_lun = MPT3SAS_MAX_LUN;
119 module_param(max_lun, ullong, 0);
120 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122 static ushort hbas_to_enumerate;
123 module_param(hbas_to_enumerate, ushort, 0);
124 MODULE_PARM_DESC(hbas_to_enumerate,
125 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
126 1 - enumerates only SAS 2.0 generation HBAs\n \
127 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
129 /* diag_buffer_enable is bitwise
131 * bit 1 set = SNAPSHOT
132 * bit 2 set = EXTENDED
134 * Either bit can be set, or both
136 static int diag_buffer_enable = -1;
137 module_param(diag_buffer_enable, int, 0);
138 MODULE_PARM_DESC(diag_buffer_enable,
139 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
140 static int disable_discovery = -1;
141 module_param(disable_discovery, int, 0);
142 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
145 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
146 static int prot_mask = -1;
147 module_param(prot_mask, int, 0);
148 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
151 /* raid transport support */
152 struct raid_template *mpt3sas_raid_template;
153 struct raid_template *mpt2sas_raid_template;
157 * struct sense_info - common structure for obtaining sense keys
159 * @asc: additional sense code
160 * @ascq: additional sense code qualifier
168 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
169 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
170 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
171 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
172 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
174 * struct fw_event_work - firmware event struct
175 * @list: link list framework
176 * @work: work object (ioc->fault_reset_work_q)
177 * @ioc: per adapter object
178 * @device_handle: device handle
179 * @VF_ID: virtual function id
180 * @VP_ID: virtual port id
181 * @ignore: flag meaning this event has been marked to ignore
182 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
183 * @refcount: kref for this event
184 * @event_data: reply event data payload follows
186 * This object stored on ioc->fw_event_list.
188 struct fw_event_work {
189 struct list_head list;
190 struct work_struct work;
192 struct MPT3SAS_ADAPTER *ioc;
198 struct kref refcount;
199 char event_data[0] __aligned(4);
202 static void fw_event_work_free(struct kref *r)
204 kfree(container_of(r, struct fw_event_work, refcount));
207 static void fw_event_work_get(struct fw_event_work *fw_work)
209 kref_get(&fw_work->refcount);
212 static void fw_event_work_put(struct fw_event_work *fw_work)
214 kref_put(&fw_work->refcount, fw_event_work_free);
217 static struct fw_event_work *alloc_fw_event_work(int len)
219 struct fw_event_work *fw_event;
221 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
225 kref_init(&fw_event->refcount);
230 * struct _scsi_io_transfer - scsi io transfer
231 * @handle: sas device handle (assigned by firmware)
232 * @is_raid: flag set for hidden raid components
233 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
234 * @data_length: data transfer length
235 * @data_dma: dma pointer to data
238 * @cdb_length: cdb length
240 * @timeout: timeout for this command
241 * @VF_ID: virtual function id
242 * @VP_ID: virtual port id
243 * @valid_reply: flag set for reply message
244 * @sense_length: sense length
245 * @ioc_status: ioc status
246 * @scsi_state: scsi state
247 * @scsi_status: scsi staus
248 * @log_info: log information
249 * @transfer_length: data length transfer when there is a reply message
251 * Used for sending internal scsi commands to devices within this module.
252 * Refer to _scsi_send_scsi_io().
254 struct _scsi_io_transfer {
257 enum dma_data_direction dir;
260 u8 sense[SCSI_SENSE_BUFFERSIZE];
268 /* the following bits are only valid when 'valid_reply = 1' */
278 * _scsih_set_debug_level - global setting of ioc->logging_level.
280 * Note: The logging levels are defined in mpt3sas_debug.h.
283 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
285 int ret = param_set_int(val, kp);
286 struct MPT3SAS_ADAPTER *ioc;
291 pr_info("setting logging_level(0x%08x)\n", logging_level);
292 spin_lock(&gioc_lock);
293 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
294 ioc->logging_level = logging_level;
295 spin_unlock(&gioc_lock);
298 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
299 &logging_level, 0644);
302 * _scsih_srch_boot_sas_address - search based on sas_address
303 * @sas_address: sas address
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_srch_boot_sas_address(u64 sas_address,
310 Mpi2BootDeviceSasWwid_t *boot_device)
312 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
316 * _scsih_srch_boot_device_name - search based on device name
317 * @device_name: device name specified in INDENTIFY fram
318 * @boot_device: boot device object from bios page 2
320 * Returns 1 when there's a match, 0 means no match.
323 _scsih_srch_boot_device_name(u64 device_name,
324 Mpi2BootDeviceDeviceName_t *boot_device)
326 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
330 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
331 * @enclosure_logical_id: enclosure logical id
332 * @slot_number: slot number
333 * @boot_device: boot device object from bios page 2
335 * Returns 1 when there's a match, 0 means no match.
338 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
339 Mpi2BootDeviceEnclosureSlot_t *boot_device)
341 return (enclosure_logical_id == le64_to_cpu(boot_device->
342 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
343 SlotNumber)) ? 1 : 0;
347 * _scsih_is_boot_device - search for matching boot device.
348 * @sas_address: sas address
349 * @device_name: device name specified in INDENTIFY fram
350 * @enclosure_logical_id: enclosure logical id
351 * @slot_number: slot number
352 * @form: specifies boot device form
353 * @boot_device: boot device object from bios page 2
355 * Returns 1 when there's a match, 0 means no match.
358 _scsih_is_boot_device(u64 sas_address, u64 device_name,
359 u64 enclosure_logical_id, u16 slot, u8 form,
360 Mpi2BiosPage2BootDevice_t *boot_device)
365 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
368 rc = _scsih_srch_boot_sas_address(
369 sas_address, &boot_device->SasWwid);
371 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
372 if (!enclosure_logical_id)
374 rc = _scsih_srch_boot_encl_slot(
375 enclosure_logical_id,
376 slot, &boot_device->EnclosureSlot);
378 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
381 rc = _scsih_srch_boot_device_name(
382 device_name, &boot_device->DeviceName);
384 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
392 * _scsih_get_sas_address - set the sas_address for given device handle
393 * @handle: device handle
394 * @sas_address: sas address
396 * Returns 0 success, non-zero when failure
399 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
402 Mpi2SasDevicePage0_t sas_device_pg0;
403 Mpi2ConfigReply_t mpi_reply;
408 if (handle <= ioc->sas_hba.num_phys) {
409 *sas_address = ioc->sas_hba.sas_address;
413 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
415 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
416 __FILE__, __LINE__, __func__);
420 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
421 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
422 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
426 /* we hit this because the given parent handle doesn't exist */
427 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
430 /* else error case */
432 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
433 ioc->name, handle, ioc_status,
434 __FILE__, __LINE__, __func__);
439 * _scsih_determine_boot_device - determine boot device.
440 * @ioc: per adapter object
441 * @device: either sas_device or raid_device object
442 * @is_raid: [flag] 1 = raid object, 0 = sas object
444 * Determines whether this device should be first reported device to
445 * to scsi-ml or sas transport, this purpose is for persistent boot device.
446 * There are primary, alternate, and current entries in bios page 2. The order
447 * priority is primary, alternate, then current. This routine saves
448 * the corresponding device object and is_raid flag in the ioc object.
449 * The saved data to be used later in _scsih_probe_boot_devices().
452 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
453 void *device, u8 is_raid)
455 struct _sas_device *sas_device;
456 struct _raid_device *raid_device;
459 u64 enclosure_logical_id;
462 /* only process this function when driver loads */
463 if (!ioc->is_driver_loading)
466 /* no Bios, return immediately */
467 if (!ioc->bios_pg3.BiosVersion)
472 sas_address = sas_device->sas_address;
473 device_name = sas_device->device_name;
474 enclosure_logical_id = sas_device->enclosure_logical_id;
475 slot = sas_device->slot;
477 raid_device = device;
478 sas_address = raid_device->wwid;
480 enclosure_logical_id = 0;
484 if (!ioc->req_boot_device.device) {
485 if (_scsih_is_boot_device(sas_address, device_name,
486 enclosure_logical_id, slot,
487 (ioc->bios_pg2.ReqBootDeviceForm &
488 MPI2_BIOSPAGE2_FORM_MASK),
489 &ioc->bios_pg2.RequestedBootDevice)) {
490 dinitprintk(ioc, pr_info(MPT3SAS_FMT
491 "%s: req_boot_device(0x%016llx)\n",
493 (unsigned long long)sas_address));
494 ioc->req_boot_device.device = device;
495 ioc->req_boot_device.is_raid = is_raid;
499 if (!ioc->req_alt_boot_device.device) {
500 if (_scsih_is_boot_device(sas_address, device_name,
501 enclosure_logical_id, slot,
502 (ioc->bios_pg2.ReqAltBootDeviceForm &
503 MPI2_BIOSPAGE2_FORM_MASK),
504 &ioc->bios_pg2.RequestedAltBootDevice)) {
505 dinitprintk(ioc, pr_info(MPT3SAS_FMT
506 "%s: req_alt_boot_device(0x%016llx)\n",
508 (unsigned long long)sas_address));
509 ioc->req_alt_boot_device.device = device;
510 ioc->req_alt_boot_device.is_raid = is_raid;
514 if (!ioc->current_boot_device.device) {
515 if (_scsih_is_boot_device(sas_address, device_name,
516 enclosure_logical_id, slot,
517 (ioc->bios_pg2.CurrentBootDeviceForm &
518 MPI2_BIOSPAGE2_FORM_MASK),
519 &ioc->bios_pg2.CurrentBootDevice)) {
520 dinitprintk(ioc, pr_info(MPT3SAS_FMT
521 "%s: current_boot_device(0x%016llx)\n",
523 (unsigned long long)sas_address));
524 ioc->current_boot_device.device = device;
525 ioc->current_boot_device.is_raid = is_raid;
530 static struct _sas_device *
531 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
532 struct MPT3SAS_TARGET *tgt_priv)
534 struct _sas_device *ret;
536 assert_spin_locked(&ioc->sas_device_lock);
538 ret = tgt_priv->sdev;
545 static struct _sas_device *
546 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
547 struct MPT3SAS_TARGET *tgt_priv)
549 struct _sas_device *ret;
552 spin_lock_irqsave(&ioc->sas_device_lock, flags);
553 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
554 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
561 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
564 struct _sas_device *sas_device;
566 assert_spin_locked(&ioc->sas_device_lock);
568 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
569 if (sas_device->sas_address == sas_address)
572 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
573 if (sas_device->sas_address == sas_address)
579 sas_device_get(sas_device);
584 * mpt3sas_get_sdev_by_addr - sas device search
585 * @ioc: per adapter object
586 * @sas_address: sas address
587 * Context: Calling function should acquire ioc->sas_device_lock
589 * This searches for sas_device based on sas_address, then return sas_device
593 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
596 struct _sas_device *sas_device;
599 spin_lock_irqsave(&ioc->sas_device_lock, flags);
600 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
602 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
607 static struct _sas_device *
608 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
610 struct _sas_device *sas_device;
612 assert_spin_locked(&ioc->sas_device_lock);
614 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
615 if (sas_device->handle == handle)
618 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
619 if (sas_device->handle == handle)
625 sas_device_get(sas_device);
630 * mpt3sas_get_sdev_by_handle - sas device search
631 * @ioc: per adapter object
632 * @handle: sas device handle (assigned by firmware)
633 * Context: Calling function should acquire ioc->sas_device_lock
635 * This searches for sas_device based on sas_address, then return sas_device
638 static struct _sas_device *
639 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
641 struct _sas_device *sas_device;
644 spin_lock_irqsave(&ioc->sas_device_lock, flags);
645 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
646 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
652 * _scsih_sas_device_remove - remove sas_device from list.
653 * @ioc: per adapter object
654 * @sas_device: the sas_device object
655 * Context: This function will acquire ioc->sas_device_lock.
657 * If sas_device is on the list, remove it and decrement its reference count.
660 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
661 struct _sas_device *sas_device)
668 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
669 ioc->name, sas_device->handle,
670 (unsigned long long) sas_device->sas_address);
672 if (sas_device->enclosure_handle != 0)
674 "removing enclosure logical id(0x%016llx), slot(%d)\n",
675 ioc->name, (unsigned long long)
676 sas_device->enclosure_logical_id, sas_device->slot);
678 if (sas_device->connector_name[0] != '\0')
680 "removing enclosure level(0x%04x), connector name( %s)\n",
681 ioc->name, sas_device->enclosure_level,
682 sas_device->connector_name);
685 * The lock serializes access to the list, but we still need to verify
686 * that nobody removed the entry while we were waiting on the lock.
688 spin_lock_irqsave(&ioc->sas_device_lock, flags);
689 if (!list_empty(&sas_device->list)) {
690 list_del_init(&sas_device->list);
691 sas_device_put(sas_device);
693 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
697 * _scsih_device_remove_by_handle - removing device object by handle
698 * @ioc: per adapter object
699 * @handle: device handle
704 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
706 struct _sas_device *sas_device;
709 if (ioc->shost_recovery)
712 spin_lock_irqsave(&ioc->sas_device_lock, flags);
713 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
715 list_del_init(&sas_device->list);
716 sas_device_put(sas_device);
718 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
720 _scsih_remove_device(ioc, sas_device);
721 sas_device_put(sas_device);
726 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
727 * @ioc: per adapter object
728 * @sas_address: device sas_address
733 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
736 struct _sas_device *sas_device;
739 if (ioc->shost_recovery)
742 spin_lock_irqsave(&ioc->sas_device_lock, flags);
743 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
745 list_del_init(&sas_device->list);
746 sas_device_put(sas_device);
748 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
750 _scsih_remove_device(ioc, sas_device);
751 sas_device_put(sas_device);
756 * _scsih_sas_device_add - insert sas_device to the list.
757 * @ioc: per adapter object
758 * @sas_device: the sas_device object
759 * Context: This function will acquire ioc->sas_device_lock.
761 * Adding new object to the ioc->sas_device_list.
764 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
765 struct _sas_device *sas_device)
769 dewtprintk(ioc, pr_info(MPT3SAS_FMT
770 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
771 ioc->name, __func__, sas_device->handle,
772 (unsigned long long)sas_device->sas_address));
774 if (sas_device->enclosure_handle != 0)
775 dewtprintk(ioc, pr_info(MPT3SAS_FMT
776 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
777 ioc->name, __func__, (unsigned long long)
778 sas_device->enclosure_logical_id, sas_device->slot));
780 if (sas_device->connector_name[0] != '\0')
781 dewtprintk(ioc, pr_info(MPT3SAS_FMT
782 "%s: enclosure level(0x%04x), connector name( %s)\n",
784 sas_device->enclosure_level, sas_device->connector_name));
786 spin_lock_irqsave(&ioc->sas_device_lock, flags);
787 sas_device_get(sas_device);
788 list_add_tail(&sas_device->list, &ioc->sas_device_list);
789 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
791 if (ioc->hide_drives) {
792 clear_bit(sas_device->handle, ioc->pend_os_device_add);
796 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
797 sas_device->sas_address_parent)) {
798 _scsih_sas_device_remove(ioc, sas_device);
799 } else if (!sas_device->starget) {
801 * When asyn scanning is enabled, its not possible to remove
802 * devices while scanning is turned on due to an oops in
803 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
805 if (!ioc->is_driver_loading) {
806 mpt3sas_transport_port_remove(ioc,
807 sas_device->sas_address,
808 sas_device->sas_address_parent);
809 _scsih_sas_device_remove(ioc, sas_device);
812 clear_bit(sas_device->handle, ioc->pend_os_device_add);
816 * _scsih_sas_device_init_add - insert sas_device to the list.
817 * @ioc: per adapter object
818 * @sas_device: the sas_device object
819 * Context: This function will acquire ioc->sas_device_lock.
821 * Adding new object at driver load time to the ioc->sas_device_init_list.
824 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
825 struct _sas_device *sas_device)
829 dewtprintk(ioc, pr_info(MPT3SAS_FMT
830 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
831 __func__, sas_device->handle,
832 (unsigned long long)sas_device->sas_address));
834 if (sas_device->enclosure_handle != 0)
835 dewtprintk(ioc, pr_info(MPT3SAS_FMT
836 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
837 ioc->name, __func__, (unsigned long long)
838 sas_device->enclosure_logical_id, sas_device->slot));
840 if (sas_device->connector_name[0] != '\0')
841 dewtprintk(ioc, pr_info(MPT3SAS_FMT
842 "%s: enclosure level(0x%04x), connector name( %s)\n",
843 ioc->name, __func__, sas_device->enclosure_level,
844 sas_device->connector_name));
846 spin_lock_irqsave(&ioc->sas_device_lock, flags);
847 sas_device_get(sas_device);
848 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
849 _scsih_determine_boot_device(ioc, sas_device, 0);
850 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
854 * _scsih_raid_device_find_by_id - raid device search
855 * @ioc: per adapter object
856 * @id: sas device target id
857 * @channel: sas device channel
858 * Context: Calling function should acquire ioc->raid_device_lock
860 * This searches for raid_device based on target id, then return raid_device
863 static struct _raid_device *
864 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
866 struct _raid_device *raid_device, *r;
869 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
870 if (raid_device->id == id && raid_device->channel == channel) {
881 * mpt3sas_raid_device_find_by_handle - raid device search
882 * @ioc: per adapter object
883 * @handle: sas device handle (assigned by firmware)
884 * Context: Calling function should acquire ioc->raid_device_lock
886 * This searches for raid_device based on handle, then return raid_device
889 struct _raid_device *
890 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
892 struct _raid_device *raid_device, *r;
895 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
896 if (raid_device->handle != handle)
907 * _scsih_raid_device_find_by_wwid - raid device search
908 * @ioc: per adapter object
909 * @handle: sas device handle (assigned by firmware)
910 * Context: Calling function should acquire ioc->raid_device_lock
912 * This searches for raid_device based on wwid, then return raid_device
915 static struct _raid_device *
916 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
918 struct _raid_device *raid_device, *r;
921 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
922 if (raid_device->wwid != wwid)
933 * _scsih_raid_device_add - add raid_device object
934 * @ioc: per adapter object
935 * @raid_device: raid_device object
937 * This is added to the raid_device_list link list.
940 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
941 struct _raid_device *raid_device)
945 dewtprintk(ioc, pr_info(MPT3SAS_FMT
946 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
947 raid_device->handle, (unsigned long long)raid_device->wwid));
949 spin_lock_irqsave(&ioc->raid_device_lock, flags);
950 list_add_tail(&raid_device->list, &ioc->raid_device_list);
951 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
955 * _scsih_raid_device_remove - delete raid_device object
956 * @ioc: per adapter object
957 * @raid_device: raid_device object
961 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
962 struct _raid_device *raid_device)
966 spin_lock_irqsave(&ioc->raid_device_lock, flags);
967 list_del(&raid_device->list);
969 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
973 * mpt3sas_scsih_expander_find_by_handle - expander device search
974 * @ioc: per adapter object
975 * @handle: expander handle (assigned by firmware)
976 * Context: Calling function should acquire ioc->sas_device_lock
978 * This searches for expander device based on handle, then returns the
982 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
984 struct _sas_node *sas_expander, *r;
987 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
988 if (sas_expander->handle != handle)
998 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
999 * @ioc: per adapter object
1000 * @sas_address: sas address
1001 * Context: Calling function should acquire ioc->sas_node_lock.
1003 * This searches for expander device based on sas_address, then returns the
1007 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1010 struct _sas_node *sas_expander, *r;
1013 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1014 if (sas_expander->sas_address != sas_address)
1024 * _scsih_expander_node_add - insert expander device to the list.
1025 * @ioc: per adapter object
1026 * @sas_expander: the sas_device object
1027 * Context: This function will acquire ioc->sas_node_lock.
1029 * Adding new object to the ioc->sas_expander_list.
1034 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1035 struct _sas_node *sas_expander)
1037 unsigned long flags;
1039 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1040 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1041 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1045 * _scsih_is_end_device - determines if device is an end device
1046 * @device_info: bitfield providing information about the device.
1049 * Returns 1 if end device.
1052 _scsih_is_end_device(u32 device_info)
1054 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1055 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1056 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1057 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1064 * _scsih_scsi_lookup_get - returns scmd entry
1065 * @ioc: per adapter object
1066 * @smid: system request message index
1068 * Returns the smid stored scmd pointer.
1070 static struct scsi_cmnd *
1071 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1073 return ioc->scsi_lookup[smid - 1].scmd;
1077 * _scsih_scsi_lookup_get_clear - returns scmd entry
1078 * @ioc: per adapter object
1079 * @smid: system request message index
1081 * Returns the smid stored scmd pointer.
1082 * Then will derefrence the stored scmd pointer.
1084 static inline struct scsi_cmnd *
1085 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1087 unsigned long flags;
1088 struct scsi_cmnd *scmd;
1090 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1091 scmd = ioc->scsi_lookup[smid - 1].scmd;
1092 ioc->scsi_lookup[smid - 1].scmd = NULL;
1093 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1099 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1100 * @ioc: per adapter object
1101 * @smid: system request message index
1102 * @scmd: pointer to scsi command object
1103 * Context: This function will acquire ioc->scsi_lookup_lock.
1105 * This will search for a scmd pointer in the scsi_lookup array,
1106 * returning the revelent smid. A returned value of zero means invalid.
1109 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1113 unsigned long flags;
1116 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1118 for (i = 0; i < ioc->scsiio_depth; i++) {
1119 if (ioc->scsi_lookup[i].scmd == scmd) {
1120 smid = ioc->scsi_lookup[i].smid;
1125 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1130 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1131 * @ioc: per adapter object
1134 * Context: This function will acquire ioc->scsi_lookup_lock.
1136 * This will search for a matching channel:id in the scsi_lookup array,
1137 * returning 1 if found.
1140 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1144 unsigned long flags;
1147 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1149 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1150 if (ioc->scsi_lookup[i].scmd &&
1151 (ioc->scsi_lookup[i].scmd->device->id == id &&
1152 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1158 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1163 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1164 * @ioc: per adapter object
1168 * Context: This function will acquire ioc->scsi_lookup_lock.
1170 * This will search for a matching channel:id:lun in the scsi_lookup array,
1171 * returning 1 if found.
1174 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1175 unsigned int lun, int channel)
1178 unsigned long flags;
1181 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1183 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1184 if (ioc->scsi_lookup[i].scmd &&
1185 (ioc->scsi_lookup[i].scmd->device->id == id &&
1186 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1187 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1193 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1198 * scsih_change_queue_depth - setting device queue depth
1199 * @sdev: scsi device struct
1200 * @qdepth: requested queue depth
1202 * Returns queue depth.
1205 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1207 struct Scsi_Host *shost = sdev->host;
1209 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1210 struct MPT3SAS_DEVICE *sas_device_priv_data;
1211 struct MPT3SAS_TARGET *sas_target_priv_data;
1212 struct _sas_device *sas_device;
1213 unsigned long flags;
1215 max_depth = shost->can_queue;
1217 /* limit max device queue for SATA to 32 */
1218 sas_device_priv_data = sdev->hostdata;
1219 if (!sas_device_priv_data)
1221 sas_target_priv_data = sas_device_priv_data->sas_target;
1222 if (!sas_target_priv_data)
1224 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1227 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1228 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1230 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1231 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1233 sas_device_put(sas_device);
1235 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1239 if (!sdev->tagged_supported)
1241 if (qdepth > max_depth)
1243 return scsi_change_queue_depth(sdev, qdepth);
1247 * scsih_target_alloc - target add routine
1248 * @starget: scsi target struct
1250 * Returns 0 if ok. Any other return is assumed to be an error and
1251 * the device is ignored.
1254 scsih_target_alloc(struct scsi_target *starget)
1256 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1257 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1258 struct MPT3SAS_TARGET *sas_target_priv_data;
1259 struct _sas_device *sas_device;
1260 struct _raid_device *raid_device;
1261 unsigned long flags;
1262 struct sas_rphy *rphy;
1264 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1266 if (!sas_target_priv_data)
1269 starget->hostdata = sas_target_priv_data;
1270 sas_target_priv_data->starget = starget;
1271 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1274 if (starget->channel == RAID_CHANNEL) {
1275 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1276 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1279 sas_target_priv_data->handle = raid_device->handle;
1280 sas_target_priv_data->sas_address = raid_device->wwid;
1281 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1282 if (ioc->is_warpdrive)
1283 sas_target_priv_data->raid_device = raid_device;
1284 raid_device->starget = starget;
1286 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1290 /* sas/sata devices */
1291 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1292 rphy = dev_to_rphy(starget->dev.parent);
1293 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1294 rphy->identify.sas_address);
1297 sas_target_priv_data->handle = sas_device->handle;
1298 sas_target_priv_data->sas_address = sas_device->sas_address;
1299 sas_target_priv_data->sdev = sas_device;
1300 sas_device->starget = starget;
1301 sas_device->id = starget->id;
1302 sas_device->channel = starget->channel;
1303 if (test_bit(sas_device->handle, ioc->pd_handles))
1304 sas_target_priv_data->flags |=
1305 MPT_TARGET_FLAGS_RAID_COMPONENT;
1306 if (sas_device->fast_path)
1307 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1309 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1315 * scsih_target_destroy - target destroy routine
1316 * @starget: scsi target struct
1321 scsih_target_destroy(struct scsi_target *starget)
1323 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1324 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1325 struct MPT3SAS_TARGET *sas_target_priv_data;
1326 struct _sas_device *sas_device;
1327 struct _raid_device *raid_device;
1328 unsigned long flags;
1330 sas_target_priv_data = starget->hostdata;
1331 if (!sas_target_priv_data)
1334 if (starget->channel == RAID_CHANNEL) {
1335 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1336 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1339 raid_device->starget = NULL;
1340 raid_device->sdev = NULL;
1342 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1346 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1347 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1348 if (sas_device && (sas_device->starget == starget) &&
1349 (sas_device->id == starget->id) &&
1350 (sas_device->channel == starget->channel))
1351 sas_device->starget = NULL;
1355 * Corresponding get() is in _scsih_target_alloc()
1357 sas_target_priv_data->sdev = NULL;
1358 sas_device_put(sas_device);
1360 sas_device_put(sas_device);
1362 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1365 kfree(sas_target_priv_data);
1366 starget->hostdata = NULL;
1370 * scsih_slave_alloc - device add routine
1371 * @sdev: scsi device struct
1373 * Returns 0 if ok. Any other return is assumed to be an error and
1374 * the device is ignored.
1377 scsih_slave_alloc(struct scsi_device *sdev)
1379 struct Scsi_Host *shost;
1380 struct MPT3SAS_ADAPTER *ioc;
1381 struct MPT3SAS_TARGET *sas_target_priv_data;
1382 struct MPT3SAS_DEVICE *sas_device_priv_data;
1383 struct scsi_target *starget;
1384 struct _raid_device *raid_device;
1385 struct _sas_device *sas_device;
1386 unsigned long flags;
1388 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1390 if (!sas_device_priv_data)
1393 sas_device_priv_data->lun = sdev->lun;
1394 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1396 starget = scsi_target(sdev);
1397 sas_target_priv_data = starget->hostdata;
1398 sas_target_priv_data->num_luns++;
1399 sas_device_priv_data->sas_target = sas_target_priv_data;
1400 sdev->hostdata = sas_device_priv_data;
1401 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1402 sdev->no_uld_attach = 1;
1404 shost = dev_to_shost(&starget->dev);
1405 ioc = shost_priv(shost);
1406 if (starget->channel == RAID_CHANNEL) {
1407 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1408 raid_device = _scsih_raid_device_find_by_id(ioc,
1409 starget->id, starget->channel);
1411 raid_device->sdev = sdev; /* raid is single lun */
1412 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1415 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1416 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1417 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1418 sas_target_priv_data->sas_address);
1419 if (sas_device && (sas_device->starget == NULL)) {
1420 sdev_printk(KERN_INFO, sdev,
1421 "%s : sas_device->starget set to starget @ %d\n",
1422 __func__, __LINE__);
1423 sas_device->starget = starget;
1427 sas_device_put(sas_device);
1429 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1436 * scsih_slave_destroy - device destroy routine
1437 * @sdev: scsi device struct
1442 scsih_slave_destroy(struct scsi_device *sdev)
1444 struct MPT3SAS_TARGET *sas_target_priv_data;
1445 struct scsi_target *starget;
1446 struct Scsi_Host *shost;
1447 struct MPT3SAS_ADAPTER *ioc;
1448 struct _sas_device *sas_device;
1449 unsigned long flags;
1451 if (!sdev->hostdata)
1454 starget = scsi_target(sdev);
1455 sas_target_priv_data = starget->hostdata;
1456 sas_target_priv_data->num_luns--;
1458 shost = dev_to_shost(&starget->dev);
1459 ioc = shost_priv(shost);
1461 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1462 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1463 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1464 sas_target_priv_data);
1465 if (sas_device && !sas_target_priv_data->num_luns)
1466 sas_device->starget = NULL;
1469 sas_device_put(sas_device);
1470 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1473 kfree(sdev->hostdata);
1474 sdev->hostdata = NULL;
1478 * _scsih_display_sata_capabilities - sata capabilities
1479 * @ioc: per adapter object
1480 * @handle: device handle
1481 * @sdev: scsi device struct
1484 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1485 u16 handle, struct scsi_device *sdev)
1487 Mpi2ConfigReply_t mpi_reply;
1488 Mpi2SasDevicePage0_t sas_device_pg0;
1493 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1494 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1495 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1496 ioc->name, __FILE__, __LINE__, __func__);
1500 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1501 MPI2_IOCSTATUS_MASK;
1502 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1503 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1504 ioc->name, __FILE__, __LINE__, __func__);
1508 flags = le16_to_cpu(sas_device_pg0.Flags);
1509 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1511 sdev_printk(KERN_INFO, sdev,
1512 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1513 "sw_preserve(%s)\n",
1514 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1515 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1516 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1518 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1519 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1520 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1524 * raid transport support -
1525 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1526 * unloading the driver followed by a load - I believe that the subroutine
1527 * raid_class_release() is not cleaning up properly.
1531 * scsih_is_raid - return boolean indicating device is raid volume
1532 * @dev the device struct object
1535 scsih_is_raid(struct device *dev)
1537 struct scsi_device *sdev = to_scsi_device(dev);
1538 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1540 if (ioc->is_warpdrive)
1542 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1546 * scsih_get_resync - get raid volume resync percent complete
1547 * @dev the device struct object
1550 scsih_get_resync(struct device *dev)
1552 struct scsi_device *sdev = to_scsi_device(dev);
1553 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1554 static struct _raid_device *raid_device;
1555 unsigned long flags;
1556 Mpi2RaidVolPage0_t vol_pg0;
1557 Mpi2ConfigReply_t mpi_reply;
1558 u32 volume_status_flags;
1559 u8 percent_complete;
1562 percent_complete = 0;
1564 if (ioc->is_warpdrive)
1567 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1568 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1571 handle = raid_device->handle;
1572 percent_complete = raid_device->percent_complete;
1574 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1579 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1580 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1581 sizeof(Mpi2RaidVolPage0_t))) {
1582 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1583 ioc->name, __FILE__, __LINE__, __func__);
1584 percent_complete = 0;
1588 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1589 if (!(volume_status_flags &
1590 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1591 percent_complete = 0;
1595 switch (ioc->hba_mpi_version_belonged) {
1597 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1601 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1607 * scsih_get_state - get raid volume level
1608 * @dev the device struct object
1611 scsih_get_state(struct device *dev)
1613 struct scsi_device *sdev = to_scsi_device(dev);
1614 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1615 static struct _raid_device *raid_device;
1616 unsigned long flags;
1617 Mpi2RaidVolPage0_t vol_pg0;
1618 Mpi2ConfigReply_t mpi_reply;
1620 enum raid_state state = RAID_STATE_UNKNOWN;
1623 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1624 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1627 handle = raid_device->handle;
1628 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1633 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1634 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1635 sizeof(Mpi2RaidVolPage0_t))) {
1636 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1637 ioc->name, __FILE__, __LINE__, __func__);
1641 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1642 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1643 state = RAID_STATE_RESYNCING;
1647 switch (vol_pg0.VolumeState) {
1648 case MPI2_RAID_VOL_STATE_OPTIMAL:
1649 case MPI2_RAID_VOL_STATE_ONLINE:
1650 state = RAID_STATE_ACTIVE;
1652 case MPI2_RAID_VOL_STATE_DEGRADED:
1653 state = RAID_STATE_DEGRADED;
1655 case MPI2_RAID_VOL_STATE_FAILED:
1656 case MPI2_RAID_VOL_STATE_MISSING:
1657 state = RAID_STATE_OFFLINE;
1661 switch (ioc->hba_mpi_version_belonged) {
1663 raid_set_state(mpt2sas_raid_template, dev, state);
1667 raid_set_state(mpt3sas_raid_template, dev, state);
1673 * _scsih_set_level - set raid level
1674 * @sdev: scsi device struct
1675 * @volume_type: volume type
1678 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1679 struct scsi_device *sdev, u8 volume_type)
1681 enum raid_level level = RAID_LEVEL_UNKNOWN;
1683 switch (volume_type) {
1684 case MPI2_RAID_VOL_TYPE_RAID0:
1685 level = RAID_LEVEL_0;
1687 case MPI2_RAID_VOL_TYPE_RAID10:
1688 level = RAID_LEVEL_10;
1690 case MPI2_RAID_VOL_TYPE_RAID1E:
1691 level = RAID_LEVEL_1E;
1693 case MPI2_RAID_VOL_TYPE_RAID1:
1694 level = RAID_LEVEL_1;
1698 switch (ioc->hba_mpi_version_belonged) {
1700 raid_set_level(mpt2sas_raid_template,
1701 &sdev->sdev_gendev, level);
1705 raid_set_level(mpt3sas_raid_template,
1706 &sdev->sdev_gendev, level);
1713 * _scsih_get_volume_capabilities - volume capabilities
1714 * @ioc: per adapter object
1715 * @sas_device: the raid_device object
1717 * Returns 0 for success, else 1
1720 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1721 struct _raid_device *raid_device)
1723 Mpi2RaidVolPage0_t *vol_pg0;
1724 Mpi2RaidPhysDiskPage0_t pd_pg0;
1725 Mpi2SasDevicePage0_t sas_device_pg0;
1726 Mpi2ConfigReply_t mpi_reply;
1730 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1731 &num_pds)) || !num_pds) {
1732 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1733 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1738 raid_device->num_pds = num_pds;
1739 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1740 sizeof(Mpi2RaidVol0PhysDisk_t));
1741 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1743 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1744 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1749 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1750 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1751 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1752 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1758 raid_device->volume_type = vol_pg0->VolumeType;
1760 /* figure out what the underlying devices are by
1761 * obtaining the device_info bits for the 1st device
1763 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1764 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1765 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1766 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1767 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1768 le16_to_cpu(pd_pg0.DevHandle)))) {
1769 raid_device->device_info =
1770 le32_to_cpu(sas_device_pg0.DeviceInfo);
1779 * _scsih_enable_tlr - setting TLR flags
1780 * @ioc: per adapter object
1781 * @sdev: scsi device struct
1783 * Enabling Transaction Layer Retries for tape devices when
1784 * vpd page 0x90 is present
1788 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1792 if (sdev->type != TYPE_TAPE)
1795 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1798 sas_enable_tlr(sdev);
1799 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1800 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1806 * scsih_slave_configure - device configure routine.
1807 * @sdev: scsi device struct
1809 * Returns 0 if ok. Any other return is assumed to be an error and
1810 * the device is ignored.
1813 scsih_slave_configure(struct scsi_device *sdev)
1815 struct Scsi_Host *shost = sdev->host;
1816 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1817 struct MPT3SAS_DEVICE *sas_device_priv_data;
1818 struct MPT3SAS_TARGET *sas_target_priv_data;
1819 struct _sas_device *sas_device;
1820 struct _raid_device *raid_device;
1821 unsigned long flags;
1826 u16 handle, volume_handle = 0;
1827 u64 volume_wwid = 0;
1830 sas_device_priv_data = sdev->hostdata;
1831 sas_device_priv_data->configured_lun = 1;
1832 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1833 sas_target_priv_data = sas_device_priv_data->sas_target;
1834 handle = sas_target_priv_data->handle;
1836 /* raid volume handling */
1837 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1839 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1840 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1841 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1843 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1844 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1845 __LINE__, __func__));
1849 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1850 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1851 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1852 __LINE__, __func__));
1857 * WARPDRIVE: Initialize the required data for Direct IO
1859 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1861 /* RAID Queue Depth Support
1862 * IS volume = underlying qdepth of drive type, either
1863 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1864 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1866 if (raid_device->device_info &
1867 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1868 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1871 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1872 if (raid_device->device_info &
1873 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1879 switch (raid_device->volume_type) {
1880 case MPI2_RAID_VOL_TYPE_RAID0:
1883 case MPI2_RAID_VOL_TYPE_RAID1E:
1884 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1885 if (ioc->manu_pg10.OEMIdentifier &&
1886 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1887 MFG10_GF0_R10_DISPLAY) &&
1888 !(raid_device->num_pds % 2))
1893 case MPI2_RAID_VOL_TYPE_RAID1:
1894 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1897 case MPI2_RAID_VOL_TYPE_RAID10:
1898 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1901 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1903 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1908 if (!ioc->hide_ir_msg)
1909 sdev_printk(KERN_INFO, sdev,
1910 "%s: handle(0x%04x), wwid(0x%016llx),"
1911 " pd_count(%d), type(%s)\n",
1912 r_level, raid_device->handle,
1913 (unsigned long long)raid_device->wwid,
1914 raid_device->num_pds, ds);
1916 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
1917 blk_queue_max_hw_sectors(sdev->request_queue,
1918 MPT3SAS_RAID_MAX_SECTORS);
1919 sdev_printk(KERN_INFO, sdev,
1920 "Set queue's max_sector to: %u\n",
1921 MPT3SAS_RAID_MAX_SECTORS);
1924 scsih_change_queue_depth(sdev, qdepth);
1926 /* raid transport support */
1927 if (!ioc->is_warpdrive)
1928 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1932 /* non-raid handling */
1933 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1934 if (mpt3sas_config_get_volume_handle(ioc, handle,
1936 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1937 "failure at %s:%d/%s()!\n", ioc->name,
1938 __FILE__, __LINE__, __func__));
1941 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1942 volume_handle, &volume_wwid)) {
1943 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1944 "failure at %s:%d/%s()!\n", ioc->name,
1945 __FILE__, __LINE__, __func__));
1950 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1951 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1952 sas_device_priv_data->sas_target->sas_address);
1954 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1955 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1956 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1961 sas_device->volume_handle = volume_handle;
1962 sas_device->volume_wwid = volume_wwid;
1963 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1964 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1966 if (sas_device->device_info &
1967 MPI2_SAS_DEVICE_INFO_SEP) {
1968 sdev_printk(KERN_WARNING, sdev,
1969 "set ignore_delay_remove for handle(0x%04x)\n",
1970 sas_device_priv_data->sas_target->handle);
1971 sas_device_priv_data->ignore_delay_remove = 1;
1976 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1977 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1979 else if (sas_device->device_info &
1980 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1984 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1985 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1986 ds, handle, (unsigned long long)sas_device->sas_address,
1987 sas_device->phy, (unsigned long long)sas_device->device_name);
1988 if (sas_device->enclosure_handle != 0)
1989 sdev_printk(KERN_INFO, sdev,
1990 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1991 ds, (unsigned long long)
1992 sas_device->enclosure_logical_id, sas_device->slot);
1993 if (sas_device->connector_name[0] != '\0')
1994 sdev_printk(KERN_INFO, sdev,
1995 "%s: enclosure level(0x%04x), connector name( %s)\n",
1996 ds, sas_device->enclosure_level,
1997 sas_device->connector_name);
1999 sas_device_put(sas_device);
2000 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2003 _scsih_display_sata_capabilities(ioc, handle, sdev);
2006 scsih_change_queue_depth(sdev, qdepth);
2009 sas_read_port_mode_page(sdev);
2010 _scsih_enable_tlr(ioc, sdev);
2017 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2018 * @sdev: scsi device struct
2019 * @bdev: pointer to block device context
2020 * @capacity: device size (in 512 byte sectors)
2021 * @params: three element array to place output:
2022 * params[0] number of heads (max 255)
2023 * params[1] number of sectors (max 63)
2024 * params[2] number of cylinders
2029 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2030 sector_t capacity, int params[])
2040 dummy = heads * sectors;
2041 cylinders = capacity;
2042 sector_div(cylinders, dummy);
2045 * Handle extended translation size for logical drives
2048 if ((ulong)capacity >= 0x200000) {
2051 dummy = heads * sectors;
2052 cylinders = capacity;
2053 sector_div(cylinders, dummy);
2058 params[1] = sectors;
2059 params[2] = cylinders;
2065 * _scsih_response_code - translation of device response code
2066 * @ioc: per adapter object
2067 * @response_code: response code returned by the device
2072 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2076 switch (response_code) {
2077 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2078 desc = "task management request completed";
2080 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2081 desc = "invalid frame";
2083 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2084 desc = "task management request not supported";
2086 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2087 desc = "task management request failed";
2089 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2090 desc = "task management request succeeded";
2092 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2093 desc = "invalid lun";
2096 desc = "overlapped tag attempted";
2098 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2099 desc = "task queued, however not sent to target";
2105 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2106 ioc->name, response_code, desc);
2110 * _scsih_tm_done - tm completion routine
2111 * @ioc: per adapter object
2112 * @smid: system request message index
2113 * @msix_index: MSIX table index supplied by the OS
2114 * @reply: reply message frame(lower 32bit addr)
2117 * The callback handler when using scsih_issue_tm.
2119 * Return 1 meaning mf should be freed from _base_interrupt
2120 * 0 means the mf is freed from this function.
2123 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2125 MPI2DefaultReply_t *mpi_reply;
2127 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2129 if (ioc->tm_cmds.smid != smid)
2131 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2132 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2134 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2135 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2137 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2138 complete(&ioc->tm_cmds.done);
2143 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2144 * @ioc: per adapter object
2145 * @handle: device handle
2147 * During taskmangement request, we need to freeze the device queue.
2150 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2152 struct MPT3SAS_DEVICE *sas_device_priv_data;
2153 struct scsi_device *sdev;
2156 shost_for_each_device(sdev, ioc->shost) {
2159 sas_device_priv_data = sdev->hostdata;
2160 if (!sas_device_priv_data)
2162 if (sas_device_priv_data->sas_target->handle == handle) {
2163 sas_device_priv_data->sas_target->tm_busy = 1;
2165 ioc->ignore_loginfos = 1;
2171 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2172 * @ioc: per adapter object
2173 * @handle: device handle
2175 * During taskmangement request, we need to freeze the device queue.
2178 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2180 struct MPT3SAS_DEVICE *sas_device_priv_data;
2181 struct scsi_device *sdev;
2184 shost_for_each_device(sdev, ioc->shost) {
2187 sas_device_priv_data = sdev->hostdata;
2188 if (!sas_device_priv_data)
2190 if (sas_device_priv_data->sas_target->handle == handle) {
2191 sas_device_priv_data->sas_target->tm_busy = 0;
2193 ioc->ignore_loginfos = 0;
2199 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2200 * @ioc: per adapter struct
2201 * @device_handle: device handle
2202 * @channel: the channel assigned by the OS
2203 * @id: the id assigned by the OS
2205 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2206 * @smid_task: smid assigned to the task
2207 * @timeout: timeout in seconds
2210 * A generic API for sending task management requests to firmware.
2212 * The callback index is set inside `ioc->tm_cb_idx`.
2214 * Return SUCCESS or FAILED.
2217 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2218 uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
2220 Mpi2SCSITaskManagementRequest_t *mpi_request;
2221 Mpi2SCSITaskManagementReply_t *mpi_reply;
2224 struct scsiio_tracker *scsi_lookup = NULL;
2228 lockdep_assert_held(&ioc->tm_cmds.mutex);
2230 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2231 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2232 __func__, ioc->name);
2236 if (ioc->shost_recovery || ioc->remove_host ||
2237 ioc->pci_error_recovery) {
2238 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2239 __func__, ioc->name);
2243 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2244 if (ioc_state & MPI2_DOORBELL_USED) {
2245 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2246 "unexpected doorbell active!\n", ioc->name));
2247 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2248 return (!rc) ? SUCCESS : FAILED;
2251 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2252 mpt3sas_base_fault_info(ioc, ioc_state &
2253 MPI2_DOORBELL_DATA_MASK);
2254 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2255 return (!rc) ? SUCCESS : FAILED;
2258 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2260 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2261 ioc->name, __func__);
2265 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2266 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2268 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2269 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2270 ioc->name, handle, type, smid_task));
2271 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2272 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2273 ioc->tm_cmds.smid = smid;
2274 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2275 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2276 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2277 mpi_request->DevHandle = cpu_to_le16(handle);
2278 mpi_request->TaskType = type;
2279 mpi_request->TaskMID = cpu_to_le16(smid_task);
2280 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2281 mpt3sas_scsih_set_tm_flag(ioc, handle);
2282 init_completion(&ioc->tm_cmds.done);
2283 if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
2284 (scsi_lookup->msix_io < ioc->reply_queue_count))
2285 msix_task = scsi_lookup->msix_io;
2288 ioc->put_smid_hi_priority(ioc, smid, msix_task);
2289 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2290 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2291 pr_err(MPT3SAS_FMT "%s: timeout\n",
2292 ioc->name, __func__);
2293 _debug_dump_mf(mpi_request,
2294 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2295 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2296 rc = mpt3sas_base_hard_reset_handler(ioc,
2298 rc = (!rc) ? SUCCESS : FAILED;
2303 /* sync IRQs in case those were busy during flush. */
2304 mpt3sas_base_sync_reply_irqs(ioc);
2306 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2307 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2308 mpi_reply = ioc->tm_cmds.reply;
2309 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2310 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2311 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2312 le32_to_cpu(mpi_reply->IOCLogInfo),
2313 le32_to_cpu(mpi_reply->TerminationCount)));
2314 if (ioc->logging_level & MPT_DEBUG_TM) {
2315 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2316 if (mpi_reply->IOCStatus)
2317 _debug_dump_mf(mpi_request,
2318 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2323 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2325 if (scsi_lookup->scmd == NULL)
2330 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2331 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2336 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2337 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2338 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2343 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2352 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2353 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2357 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2358 uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
2362 mutex_lock(&ioc->tm_cmds.mutex);
2363 ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type,
2364 smid_task, timeout);
2365 mutex_unlock(&ioc->tm_cmds.mutex);
2371 * _scsih_tm_display_info - displays info about the device
2372 * @ioc: per adapter struct
2373 * @scmd: pointer to scsi command object
2375 * Called by task management callback handlers.
2378 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2380 struct scsi_target *starget = scmd->device->sdev_target;
2381 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2382 struct _sas_device *sas_device = NULL;
2383 unsigned long flags;
2384 char *device_str = NULL;
2388 if (ioc->hide_ir_msg)
2389 device_str = "WarpDrive";
2391 device_str = "volume";
2393 scsi_print_command(scmd);
2394 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2395 starget_printk(KERN_INFO, starget,
2396 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2397 device_str, priv_target->handle,
2398 device_str, (unsigned long long)priv_target->sas_address);
2400 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2401 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2403 if (priv_target->flags &
2404 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2405 starget_printk(KERN_INFO, starget,
2406 "volume handle(0x%04x), "
2407 "volume wwid(0x%016llx)\n",
2408 sas_device->volume_handle,
2409 (unsigned long long)sas_device->volume_wwid);
2411 starget_printk(KERN_INFO, starget,
2412 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2414 (unsigned long long)sas_device->sas_address,
2416 if (sas_device->enclosure_handle != 0)
2417 starget_printk(KERN_INFO, starget,
2418 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2419 (unsigned long long)
2420 sas_device->enclosure_logical_id,
2422 if (sas_device->connector_name[0] != '\0')
2423 starget_printk(KERN_INFO, starget,
2424 "enclosure level(0x%04x),connector name(%s)\n",
2425 sas_device->enclosure_level,
2426 sas_device->connector_name);
2428 sas_device_put(sas_device);
2430 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2435 * scsih_abort - eh threads main abort routine
2436 * @scmd: pointer to scsi command object
2438 * Returns SUCCESS if command aborted else FAILED
2441 scsih_abort(struct scsi_cmnd *scmd)
2443 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2444 struct MPT3SAS_DEVICE *sas_device_priv_data;
2449 sdev_printk(KERN_INFO, scmd->device,
2450 "attempting task abort! scmd(%p)\n", scmd);
2451 _scsih_tm_display_info(ioc, scmd);
2453 sas_device_priv_data = scmd->device->hostdata;
2454 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2455 sdev_printk(KERN_INFO, scmd->device,
2456 "device been deleted! scmd(%p)\n", scmd);
2457 scmd->result = DID_NO_CONNECT << 16;
2458 scmd->scsi_done(scmd);
2463 /* search for the command */
2464 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2466 scmd->result = DID_RESET << 16;
2471 /* for hidden raid components and volumes this is not supported */
2472 if (sas_device_priv_data->sas_target->flags &
2473 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2474 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2475 scmd->result = DID_RESET << 16;
2480 mpt3sas_halt_firmware(ioc);
2482 handle = sas_device_priv_data->sas_target->handle;
2483 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2484 scmd->device->id, scmd->device->lun,
2485 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
2488 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2489 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2494 * scsih_dev_reset - eh threads main device reset routine
2495 * @scmd: pointer to scsi command object
2497 * Returns SUCCESS if command aborted else FAILED
2500 scsih_dev_reset(struct scsi_cmnd *scmd)
2502 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2503 struct MPT3SAS_DEVICE *sas_device_priv_data;
2504 struct _sas_device *sas_device = NULL;
2508 struct scsi_target *starget = scmd->device->sdev_target;
2509 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2511 sdev_printk(KERN_INFO, scmd->device,
2512 "attempting device reset! scmd(%p)\n", scmd);
2513 _scsih_tm_display_info(ioc, scmd);
2515 sas_device_priv_data = scmd->device->hostdata;
2516 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2517 sdev_printk(KERN_INFO, scmd->device,
2518 "device been deleted! scmd(%p)\n", scmd);
2519 scmd->result = DID_NO_CONNECT << 16;
2520 scmd->scsi_done(scmd);
2525 /* for hidden raid components obtain the volume_handle */
2527 if (sas_device_priv_data->sas_target->flags &
2528 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2529 sas_device = mpt3sas_get_sdev_from_target(ioc,
2532 handle = sas_device->volume_handle;
2534 handle = sas_device_priv_data->sas_target->handle;
2537 scmd->result = DID_RESET << 16;
2542 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2543 scmd->device->id, scmd->device->lun,
2544 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30);
2547 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2548 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2551 sas_device_put(sas_device);
2557 * scsih_target_reset - eh threads main target reset routine
2558 * @scmd: pointer to scsi command object
2560 * Returns SUCCESS if command aborted else FAILED
2563 scsih_target_reset(struct scsi_cmnd *scmd)
2565 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2566 struct MPT3SAS_DEVICE *sas_device_priv_data;
2567 struct _sas_device *sas_device = NULL;
2570 struct scsi_target *starget = scmd->device->sdev_target;
2571 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2573 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2575 _scsih_tm_display_info(ioc, scmd);
2577 sas_device_priv_data = scmd->device->hostdata;
2578 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2579 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2581 scmd->result = DID_NO_CONNECT << 16;
2582 scmd->scsi_done(scmd);
2587 /* for hidden raid components obtain the volume_handle */
2589 if (sas_device_priv_data->sas_target->flags &
2590 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2591 sas_device = mpt3sas_get_sdev_from_target(ioc,
2594 handle = sas_device->volume_handle;
2596 handle = sas_device_priv_data->sas_target->handle;
2599 scmd->result = DID_RESET << 16;
2604 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2605 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2609 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2610 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2613 sas_device_put(sas_device);
2620 * scsih_host_reset - eh threads main host reset routine
2621 * @scmd: pointer to scsi command object
2623 * Returns SUCCESS if command aborted else FAILED
2626 scsih_host_reset(struct scsi_cmnd *scmd)
2628 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2631 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2633 scsi_print_command(scmd);
2635 if (ioc->is_driver_loading) {
2636 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2642 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2643 r = (retval < 0) ? FAILED : SUCCESS;
2645 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2646 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2652 * _scsih_fw_event_add - insert and queue up fw_event
2653 * @ioc: per adapter object
2654 * @fw_event: object describing the event
2655 * Context: This function will acquire ioc->fw_event_lock.
2657 * This adds the firmware event object into link list, then queues it up to
2658 * be processed from user context.
2663 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2665 unsigned long flags;
2667 if (ioc->firmware_event_thread == NULL)
2670 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2671 fw_event_work_get(fw_event);
2672 INIT_LIST_HEAD(&fw_event->list);
2673 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2674 INIT_WORK(&fw_event->work, _firmware_event_work);
2675 fw_event_work_get(fw_event);
2676 queue_work(ioc->firmware_event_thread, &fw_event->work);
2677 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2681 * _scsih_fw_event_del_from_list - delete fw_event from the list
2682 * @ioc: per adapter object
2683 * @fw_event: object describing the event
2684 * Context: This function will acquire ioc->fw_event_lock.
2686 * If the fw_event is on the fw_event_list, remove it and do a put.
2691 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2694 unsigned long flags;
2696 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2697 if (!list_empty(&fw_event->list)) {
2698 list_del_init(&fw_event->list);
2699 fw_event_work_put(fw_event);
2701 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2706 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2707 * @ioc: per adapter object
2708 * @event_data: trigger event data
2713 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2714 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2716 struct fw_event_work *fw_event;
2719 if (ioc->is_driver_loading)
2721 sz = sizeof(*event_data);
2722 fw_event = alloc_fw_event_work(sz);
2725 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2726 fw_event->ioc = ioc;
2727 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2728 _scsih_fw_event_add(ioc, fw_event);
2729 fw_event_work_put(fw_event);
2733 * _scsih_error_recovery_delete_devices - remove devices not responding
2734 * @ioc: per adapter object
2739 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2741 struct fw_event_work *fw_event;
2743 if (ioc->is_driver_loading)
2745 fw_event = alloc_fw_event_work(0);
2748 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2749 fw_event->ioc = ioc;
2750 _scsih_fw_event_add(ioc, fw_event);
2751 fw_event_work_put(fw_event);
2755 * mpt3sas_port_enable_complete - port enable completed (fake event)
2756 * @ioc: per adapter object
2761 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2763 struct fw_event_work *fw_event;
2765 fw_event = alloc_fw_event_work(0);
2768 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2769 fw_event->ioc = ioc;
2770 _scsih_fw_event_add(ioc, fw_event);
2771 fw_event_work_put(fw_event);
2774 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2776 unsigned long flags;
2777 struct fw_event_work *fw_event = NULL;
2779 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2780 if (!list_empty(&ioc->fw_event_list)) {
2781 fw_event = list_first_entry(&ioc->fw_event_list,
2782 struct fw_event_work, list);
2783 list_del_init(&fw_event->list);
2785 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2791 * _scsih_fw_event_cleanup_queue - cleanup event queue
2792 * @ioc: per adapter object
2794 * Walk the firmware event queue, either killing timers, or waiting
2795 * for outstanding events to complete
2800 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2802 struct fw_event_work *fw_event;
2804 if (list_empty(&ioc->fw_event_list) ||
2805 !ioc->firmware_event_thread || in_interrupt())
2808 while ((fw_event = dequeue_next_fw_event(ioc))) {
2810 * Wait on the fw_event to complete. If this returns 1, then
2811 * the event was never executed, and we need a put for the
2812 * reference the work had on the fw_event.
2814 * If it did execute, we wait for it to finish, and the put will
2815 * happen from _firmware_event_work()
2817 if (cancel_work_sync(&fw_event->work))
2818 fw_event_work_put(fw_event);
2820 fw_event_work_put(fw_event);
2825 * _scsih_internal_device_block - block the sdev device
2826 * @sdev: per device object
2827 * @sas_device_priv_data : per device driver private data
2829 * make sure device is blocked without error, if not
2833 _scsih_internal_device_block(struct scsi_device *sdev,
2834 struct MPT3SAS_DEVICE *sas_device_priv_data)
2838 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2839 sas_device_priv_data->sas_target->handle);
2840 sas_device_priv_data->block = 1;
2842 r = scsi_internal_device_block(sdev);
2844 sdev_printk(KERN_WARNING, sdev,
2845 "device_block failed with return(%d) for handle(0x%04x)\n",
2846 r, sas_device_priv_data->sas_target->handle);
2850 * _scsih_internal_device_unblock - unblock the sdev device
2851 * @sdev: per device object
2852 * @sas_device_priv_data : per device driver private data
2853 * make sure device is unblocked without error, if not retry
2854 * by blocking and then unblocking
2858 _scsih_internal_device_unblock(struct scsi_device *sdev,
2859 struct MPT3SAS_DEVICE *sas_device_priv_data)
2863 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2864 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2865 sas_device_priv_data->block = 0;
2866 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2868 /* The device has been set to SDEV_RUNNING by SD layer during
2869 * device addition but the request queue is still stopped by
2870 * our earlier block call. We need to perform a block again
2871 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2873 sdev_printk(KERN_WARNING, sdev,
2874 "device_unblock failed with return(%d) for handle(0x%04x) "
2875 "performing a block followed by an unblock\n",
2876 r, sas_device_priv_data->sas_target->handle);
2877 sas_device_priv_data->block = 1;
2878 r = scsi_internal_device_block(sdev);
2880 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2881 "failed with return(%d) for handle(0x%04x)\n",
2882 r, sas_device_priv_data->sas_target->handle);
2884 sas_device_priv_data->block = 0;
2885 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2887 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2888 " failed with return(%d) for handle(0x%04x)\n",
2889 r, sas_device_priv_data->sas_target->handle);
2894 * _scsih_ublock_io_all_device - unblock every device
2895 * @ioc: per adapter object
2897 * change the device state from block to running
2900 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2902 struct MPT3SAS_DEVICE *sas_device_priv_data;
2903 struct scsi_device *sdev;
2905 shost_for_each_device(sdev, ioc->shost) {
2906 sas_device_priv_data = sdev->hostdata;
2907 if (!sas_device_priv_data)
2909 if (!sas_device_priv_data->block)
2912 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2913 "device_running, handle(0x%04x)\n",
2914 sas_device_priv_data->sas_target->handle));
2915 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2921 * _scsih_ublock_io_device - prepare device to be deleted
2922 * @ioc: per adapter object
2923 * @sas_addr: sas address
2925 * unblock then put device in offline state
2928 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2930 struct MPT3SAS_DEVICE *sas_device_priv_data;
2931 struct scsi_device *sdev;
2933 shost_for_each_device(sdev, ioc->shost) {
2934 sas_device_priv_data = sdev->hostdata;
2935 if (!sas_device_priv_data)
2937 if (sas_device_priv_data->sas_target->sas_address
2940 if (sas_device_priv_data->block)
2941 _scsih_internal_device_unblock(sdev,
2942 sas_device_priv_data);
2947 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2948 * @ioc: per adapter object
2949 * @handle: device handle
2951 * During device pull we need to appropriately set the sdev state.
2954 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2956 struct MPT3SAS_DEVICE *sas_device_priv_data;
2957 struct scsi_device *sdev;
2959 shost_for_each_device(sdev, ioc->shost) {
2960 sas_device_priv_data = sdev->hostdata;
2961 if (!sas_device_priv_data)
2963 if (sas_device_priv_data->block)
2965 if (sas_device_priv_data->ignore_delay_remove) {
2966 sdev_printk(KERN_INFO, sdev,
2967 "%s skip device_block for SES handle(0x%04x)\n",
2968 __func__, sas_device_priv_data->sas_target->handle);
2971 _scsih_internal_device_block(sdev, sas_device_priv_data);
2976 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2977 * @ioc: per adapter object
2978 * @handle: device handle
2980 * During device pull we need to appropriately set the sdev state.
2983 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2985 struct MPT3SAS_DEVICE *sas_device_priv_data;
2986 struct scsi_device *sdev;
2987 struct _sas_device *sas_device;
2989 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2993 shost_for_each_device(sdev, ioc->shost) {
2994 sas_device_priv_data = sdev->hostdata;
2995 if (!sas_device_priv_data)
2997 if (sas_device_priv_data->sas_target->handle != handle)
2999 if (sas_device_priv_data->block)
3001 if (sas_device->pend_sas_rphy_add)
3003 if (sas_device_priv_data->ignore_delay_remove) {
3004 sdev_printk(KERN_INFO, sdev,
3005 "%s skip device_block for SES handle(0x%04x)\n",
3006 __func__, sas_device_priv_data->sas_target->handle);
3009 _scsih_internal_device_block(sdev, sas_device_priv_data);
3012 sas_device_put(sas_device);
3016 * _scsih_block_io_to_children_attached_to_ex
3017 * @ioc: per adapter object
3018 * @sas_expander: the sas_device object
3020 * This routine set sdev state to SDEV_BLOCK for all devices
3021 * attached to this expander. This function called when expander is
3025 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3026 struct _sas_node *sas_expander)
3028 struct _sas_port *mpt3sas_port;
3029 struct _sas_device *sas_device;
3030 struct _sas_node *expander_sibling;
3031 unsigned long flags;
3036 list_for_each_entry(mpt3sas_port,
3037 &sas_expander->sas_port_list, port_list) {
3038 if (mpt3sas_port->remote_identify.device_type ==
3040 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3041 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3042 mpt3sas_port->remote_identify.sas_address);
3044 set_bit(sas_device->handle,
3045 ioc->blocking_handles);
3046 sas_device_put(sas_device);
3048 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3052 list_for_each_entry(mpt3sas_port,
3053 &sas_expander->sas_port_list, port_list) {
3055 if (mpt3sas_port->remote_identify.device_type ==
3056 SAS_EDGE_EXPANDER_DEVICE ||
3057 mpt3sas_port->remote_identify.device_type ==
3058 SAS_FANOUT_EXPANDER_DEVICE) {
3060 mpt3sas_scsih_expander_find_by_sas_address(
3061 ioc, mpt3sas_port->remote_identify.sas_address);
3062 _scsih_block_io_to_children_attached_to_ex(ioc,
3069 * _scsih_block_io_to_children_attached_directly
3070 * @ioc: per adapter object
3071 * @event_data: topology change event data
3073 * This routine set sdev state to SDEV_BLOCK for all devices
3074 * direct attached during device pull.
3077 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3078 Mpi2EventDataSasTopologyChangeList_t *event_data)
3084 for (i = 0; i < event_data->NumEntries; i++) {
3085 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3088 reason_code = event_data->PHY[i].PhyStatus &
3089 MPI2_EVENT_SAS_TOPO_RC_MASK;
3090 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3091 _scsih_block_io_device(ioc, handle);
3096 * _scsih_tm_tr_send - send task management request
3097 * @ioc: per adapter object
3098 * @handle: device handle
3099 * Context: interrupt time.
3101 * This code is to initiate the device removal handshake protocol
3102 * with controller firmware. This function will issue target reset
3103 * using high priority request queue. It will send a sas iounit
3104 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3106 * This is designed to send muliple task management request at the same
3107 * time to the fifo. If the fifo is full, we will append the request,
3108 * and process it in a future completion.
3111 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3113 Mpi2SCSITaskManagementRequest_t *mpi_request;
3115 struct _sas_device *sas_device = NULL;
3116 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3117 u64 sas_address = 0;
3118 unsigned long flags;
3119 struct _tr_list *delayed_tr;
3122 if (ioc->remove_host) {
3123 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3124 "%s: host has been removed: handle(0x%04x)\n",
3125 __func__, ioc->name, handle));
3127 } else if (ioc->pci_error_recovery) {
3128 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3129 "%s: host in pci error recovery: handle(0x%04x)\n",
3130 __func__, ioc->name,
3134 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3135 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3136 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3137 "%s: host is not operational: handle(0x%04x)\n",
3138 __func__, ioc->name,
3143 /* if PD, then return */
3144 if (test_bit(handle, ioc->pd_handles))
3147 clear_bit(handle, ioc->pend_os_device_add);
3149 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3150 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3151 if (sas_device && sas_device->starget &&
3152 sas_device->starget->hostdata) {
3153 sas_target_priv_data = sas_device->starget->hostdata;
3154 sas_target_priv_data->deleted = 1;
3155 sas_address = sas_device->sas_address;
3157 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3159 if (sas_target_priv_data) {
3160 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3161 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3163 (unsigned long long)sas_address));
3164 if (sas_device->enclosure_handle != 0)
3165 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3166 "setting delete flag:enclosure logical id(0x%016llx),"
3167 " slot(%d)\n", ioc->name, (unsigned long long)
3168 sas_device->enclosure_logical_id,
3170 if (sas_device->connector_name[0] != '\0')
3171 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3172 "setting delete flag: enclosure level(0x%04x),"
3173 " connector name( %s)\n", ioc->name,
3174 sas_device->enclosure_level,
3175 sas_device->connector_name));
3176 _scsih_ublock_io_device(ioc, sas_address);
3177 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3180 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3182 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3185 INIT_LIST_HEAD(&delayed_tr->list);
3186 delayed_tr->handle = handle;
3187 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3188 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3189 "DELAYED:tr:handle(0x%04x), (open)\n",
3190 ioc->name, handle));
3194 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3195 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3196 ioc->name, handle, smid,
3197 ioc->tm_tr_cb_idx));
3198 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3199 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3200 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3201 mpi_request->DevHandle = cpu_to_le16(handle);
3202 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3203 set_bit(handle, ioc->device_remove_in_progress);
3204 ioc->put_smid_hi_priority(ioc, smid, 0);
3205 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3209 sas_device_put(sas_device);
3213 * _scsih_tm_tr_complete -
3214 * @ioc: per adapter object
3215 * @smid: system request message index
3216 * @msix_index: MSIX table index supplied by the OS
3217 * @reply: reply message frame(lower 32bit addr)
3218 * Context: interrupt time.
3220 * This is the target reset completion routine.
3221 * This code is part of the code to initiate the device removal
3222 * handshake protocol with controller firmware.
3223 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3225 * Return 1 meaning mf should be freed from _base_interrupt
3226 * 0 means the mf is freed from this function.
3229 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3233 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3234 Mpi2SCSITaskManagementReply_t *mpi_reply =
3235 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3236 Mpi2SasIoUnitControlRequest_t *mpi_request;
3239 struct _sc_list *delayed_sc;
3241 if (ioc->remove_host) {
3242 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3243 "%s: host has been removed\n", __func__, ioc->name));
3245 } else if (ioc->pci_error_recovery) {
3246 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3247 "%s: host in pci error recovery\n", __func__,
3251 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3252 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3253 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3254 "%s: host is not operational\n", __func__, ioc->name));
3257 if (unlikely(!mpi_reply)) {
3258 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3259 ioc->name, __FILE__, __LINE__, __func__);
3262 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3263 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3264 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3265 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3266 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3268 le16_to_cpu(mpi_reply->DevHandle), smid));
3272 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3273 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3274 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3275 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3276 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3277 le32_to_cpu(mpi_reply->IOCLogInfo),
3278 le32_to_cpu(mpi_reply->TerminationCount)));
3280 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3281 if (!smid_sas_ctrl) {
3282 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3284 return _scsih_check_for_pending_tm(ioc, smid);
3285 INIT_LIST_HEAD(&delayed_sc->list);
3286 delayed_sc->handle = mpi_request_tm->DevHandle;
3287 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3288 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3289 "DELAYED:sc:handle(0x%04x), (open)\n",
3290 ioc->name, handle));
3291 return _scsih_check_for_pending_tm(ioc, smid);
3294 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3295 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3296 ioc->name, handle, smid_sas_ctrl,
3297 ioc->tm_sas_control_cb_idx));
3298 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3299 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3300 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3301 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3302 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3303 ioc->put_smid_default(ioc, smid_sas_ctrl);
3305 return _scsih_check_for_pending_tm(ioc, smid);
3310 * _scsih_sas_control_complete - completion routine
3311 * @ioc: per adapter object
3312 * @smid: system request message index
3313 * @msix_index: MSIX table index supplied by the OS
3314 * @reply: reply message frame(lower 32bit addr)
3315 * Context: interrupt time.
3317 * This is the sas iounit control completion routine.
3318 * This code is part of the code to initiate the device removal
3319 * handshake protocol with controller firmware.
3321 * Return 1 meaning mf should be freed from _base_interrupt
3322 * 0 means the mf is freed from this function.
3325 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3326 u8 msix_index, u32 reply)
3328 Mpi2SasIoUnitControlReply_t *mpi_reply =
3329 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3331 if (likely(mpi_reply)) {
3332 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3333 "sc_complete:handle(0x%04x), (open) "
3334 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3335 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3336 le16_to_cpu(mpi_reply->IOCStatus),
3337 le32_to_cpu(mpi_reply->IOCLogInfo)));
3338 if (le16_to_cpu(mpi_reply->IOCStatus) ==
3339 MPI2_IOCSTATUS_SUCCESS) {
3340 clear_bit(le16_to_cpu(mpi_reply->DevHandle),
3341 ioc->device_remove_in_progress);
3344 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3345 ioc->name, __FILE__, __LINE__, __func__);
3347 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3351 * _scsih_tm_tr_volume_send - send target reset request for volumes
3352 * @ioc: per adapter object
3353 * @handle: device handle
3354 * Context: interrupt time.
3356 * This is designed to send muliple task management request at the same
3357 * time to the fifo. If the fifo is full, we will append the request,
3358 * and process it in a future completion.
3361 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3363 Mpi2SCSITaskManagementRequest_t *mpi_request;
3365 struct _tr_list *delayed_tr;
3367 if (ioc->shost_recovery || ioc->remove_host ||
3368 ioc->pci_error_recovery) {
3369 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3370 "%s: host reset in progress!\n",
3371 __func__, ioc->name));
3375 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3377 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3380 INIT_LIST_HEAD(&delayed_tr->list);
3381 delayed_tr->handle = handle;
3382 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3383 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3384 "DELAYED:tr:handle(0x%04x), (open)\n",
3385 ioc->name, handle));
3389 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3390 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3391 ioc->name, handle, smid,
3392 ioc->tm_tr_volume_cb_idx));
3393 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3394 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3395 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3396 mpi_request->DevHandle = cpu_to_le16(handle);
3397 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3398 ioc->put_smid_hi_priority(ioc, smid, 0);
3402 * _scsih_tm_volume_tr_complete - target reset completion
3403 * @ioc: per adapter object
3404 * @smid: system request message index
3405 * @msix_index: MSIX table index supplied by the OS
3406 * @reply: reply message frame(lower 32bit addr)
3407 * Context: interrupt time.
3409 * Return 1 meaning mf should be freed from _base_interrupt
3410 * 0 means the mf is freed from this function.
3413 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3414 u8 msix_index, u32 reply)
3417 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3418 Mpi2SCSITaskManagementReply_t *mpi_reply =
3419 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3421 if (ioc->shost_recovery || ioc->remove_host ||
3422 ioc->pci_error_recovery) {
3423 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3424 "%s: host reset in progress!\n",
3425 __func__, ioc->name));
3428 if (unlikely(!mpi_reply)) {
3429 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3430 ioc->name, __FILE__, __LINE__, __func__);
3434 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3435 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3436 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3437 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3438 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3440 le16_to_cpu(mpi_reply->DevHandle), smid));
3444 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3445 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3446 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3447 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3448 le32_to_cpu(mpi_reply->IOCLogInfo),
3449 le32_to_cpu(mpi_reply->TerminationCount)));
3451 return _scsih_check_for_pending_tm(ioc, smid);
3455 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3456 * @ioc: per adapter object
3457 * @smid: system request message index
3459 * @event_context: used to track events uniquely
3461 * Context - processed in interrupt context.
3464 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event,
3467 Mpi2EventAckRequest_t *ack_request;
3468 int i = smid - ioc->internal_smid;
3469 unsigned long flags;
3471 /* Without releasing the smid just update the
3472 * call back index and reuse the same smid for
3473 * processing this delayed request
3475 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3476 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3477 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3479 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3480 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3481 ioc->name, le16_to_cpu(event), smid,
3483 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
3484 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
3485 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
3486 ack_request->Event = event;
3487 ack_request->EventContext = event_context;
3488 ack_request->VF_ID = 0; /* TODO */
3489 ack_request->VP_ID = 0;
3490 ioc->put_smid_default(ioc, smid);
3494 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3495 * sas_io_unit_ctrl messages
3496 * @ioc: per adapter object
3497 * @smid: system request message index
3498 * @handle: device handle
3500 * Context - processed in interrupt context.
3503 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
3504 u16 smid, u16 handle)
3506 Mpi2SasIoUnitControlRequest_t *mpi_request;
3508 int i = smid - ioc->internal_smid;
3509 unsigned long flags;
3511 if (ioc->remove_host) {
3512 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3513 "%s: host has been removed\n",
3514 __func__, ioc->name));
3516 } else if (ioc->pci_error_recovery) {
3517 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3518 "%s: host in pci error recovery\n",
3519 __func__, ioc->name));
3522 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3523 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3524 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3525 "%s: host is not operational\n",
3526 __func__, ioc->name));
3530 /* Without releasing the smid just update the
3531 * call back index and reuse the same smid for
3532 * processing this delayed request
3534 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3535 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
3536 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3538 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3539 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3540 ioc->name, le16_to_cpu(handle), smid,
3541 ioc->tm_sas_control_cb_idx));
3542 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3543 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3544 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3545 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3546 mpi_request->DevHandle = handle;
3547 ioc->put_smid_default(ioc, smid);
3551 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3552 * @ioc: per adapter object
3553 * @smid: system request message index
3555 * Context: Executed in interrupt context
3557 * This will check delayed internal messages list, and process the
3560 * Return 1 meaning mf should be freed from _base_interrupt
3561 * 0 means the mf is freed from this function.
3564 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3566 struct _sc_list *delayed_sc;
3567 struct _event_ack_list *delayed_event_ack;
3569 if (!list_empty(&ioc->delayed_event_ack_list)) {
3570 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
3571 struct _event_ack_list, list);
3572 _scsih_issue_delayed_event_ack(ioc, smid,
3573 delayed_event_ack->Event, delayed_event_ack->EventContext);
3574 list_del(&delayed_event_ack->list);
3575 kfree(delayed_event_ack);
3579 if (!list_empty(&ioc->delayed_sc_list)) {
3580 delayed_sc = list_entry(ioc->delayed_sc_list.next,
3581 struct _sc_list, list);
3582 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
3583 delayed_sc->handle);
3584 list_del(&delayed_sc->list);
3592 * _scsih_check_for_pending_tm - check for pending task management
3593 * @ioc: per adapter object
3594 * @smid: system request message index
3596 * This will check delayed target reset list, and feed the
3599 * Return 1 meaning mf should be freed from _base_interrupt
3600 * 0 means the mf is freed from this function.
3603 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3605 struct _tr_list *delayed_tr;
3607 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3608 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3609 struct _tr_list, list);
3610 mpt3sas_base_free_smid(ioc, smid);
3611 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3612 list_del(&delayed_tr->list);
3617 if (!list_empty(&ioc->delayed_tr_list)) {
3618 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3619 struct _tr_list, list);
3620 mpt3sas_base_free_smid(ioc, smid);
3621 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3622 list_del(&delayed_tr->list);
3631 * _scsih_check_topo_delete_events - sanity check on topo events
3632 * @ioc: per adapter object
3633 * @event_data: the event data payload
3635 * This routine added to better handle cable breaker.
3637 * This handles the case where driver receives multiple expander
3638 * add and delete events in a single shot. When there is a delete event
3639 * the routine will void any pending add events waiting in the event queue.
3644 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3645 Mpi2EventDataSasTopologyChangeList_t *event_data)
3647 struct fw_event_work *fw_event;
3648 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3649 u16 expander_handle;
3650 struct _sas_node *sas_expander;
3651 unsigned long flags;
3655 for (i = 0 ; i < event_data->NumEntries; i++) {
3656 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3659 reason_code = event_data->PHY[i].PhyStatus &
3660 MPI2_EVENT_SAS_TOPO_RC_MASK;
3661 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3662 _scsih_tm_tr_send(ioc, handle);
3665 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3666 if (expander_handle < ioc->sas_hba.num_phys) {
3667 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3670 if (event_data->ExpStatus ==
3671 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3672 /* put expander attached devices into blocking state */
3673 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3674 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3676 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3677 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3679 handle = find_first_bit(ioc->blocking_handles,
3680 ioc->facts.MaxDevHandle);
3681 if (handle < ioc->facts.MaxDevHandle)
3682 _scsih_block_io_device(ioc, handle);
3683 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3684 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3685 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3687 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3690 /* mark ignore flag for pending events */
3691 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3692 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3693 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3696 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3697 fw_event->event_data;
3698 if (local_event_data->ExpStatus ==
3699 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3700 local_event_data->ExpStatus ==
3701 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3702 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3704 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3705 "setting ignoring flag\n", ioc->name));
3706 fw_event->ignore = 1;
3710 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3714 * _scsih_set_volume_delete_flag - setting volume delete flag
3715 * @ioc: per adapter object
3716 * @handle: device handle
3718 * This returns nothing.
3721 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3723 struct _raid_device *raid_device;
3724 struct MPT3SAS_TARGET *sas_target_priv_data;
3725 unsigned long flags;
3727 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3728 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3729 if (raid_device && raid_device->starget &&
3730 raid_device->starget->hostdata) {
3731 sas_target_priv_data =
3732 raid_device->starget->hostdata;
3733 sas_target_priv_data->deleted = 1;
3734 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3735 "setting delete flag: handle(0x%04x), "
3736 "wwid(0x%016llx)\n", ioc->name, handle,
3737 (unsigned long long) raid_device->wwid));
3739 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3743 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3744 * @handle: input handle
3745 * @a: handle for volume a
3746 * @b: handle for volume b
3748 * IR firmware only supports two raid volumes. The purpose of this
3749 * routine is to set the volume handle in either a or b. When the given
3750 * input handle is non-zero, or when a and b have not been set before.
3753 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3755 if (!handle || handle == *a || handle == *b)
3764 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3765 * @ioc: per adapter object
3766 * @event_data: the event data payload
3767 * Context: interrupt time.
3769 * This routine will send target reset to volume, followed by target
3770 * resets to the PDs. This is called when a PD has been removed, or
3771 * volume has been deleted or removed. When the target reset is sent
3772 * to volume, the PD target resets need to be queued to start upon
3773 * completion of the volume target reset.
3778 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3779 Mpi2EventDataIrConfigChangeList_t *event_data)
3781 Mpi2EventIrConfigElement_t *element;
3783 u16 handle, volume_handle, a, b;
3784 struct _tr_list *delayed_tr;
3789 if (ioc->is_warpdrive)
3792 /* Volume Resets for Deleted or Removed */
3793 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3794 for (i = 0; i < event_data->NumElements; i++, element++) {
3795 if (le32_to_cpu(event_data->Flags) &
3796 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3798 if (element->ReasonCode ==
3799 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3800 element->ReasonCode ==
3801 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3802 volume_handle = le16_to_cpu(element->VolDevHandle);
3803 _scsih_set_volume_delete_flag(ioc, volume_handle);
3804 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3808 /* Volume Resets for UNHIDE events */
3809 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3810 for (i = 0; i < event_data->NumElements; i++, element++) {
3811 if (le32_to_cpu(event_data->Flags) &
3812 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3814 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3815 volume_handle = le16_to_cpu(element->VolDevHandle);
3816 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3821 _scsih_tm_tr_volume_send(ioc, a);
3823 _scsih_tm_tr_volume_send(ioc, b);
3825 /* PD target resets */
3826 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3827 for (i = 0; i < event_data->NumElements; i++, element++) {
3828 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3830 handle = le16_to_cpu(element->PhysDiskDevHandle);
3831 volume_handle = le16_to_cpu(element->VolDevHandle);
3832 clear_bit(handle, ioc->pd_handles);
3834 _scsih_tm_tr_send(ioc, handle);
3835 else if (volume_handle == a || volume_handle == b) {
3836 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3837 BUG_ON(!delayed_tr);
3838 INIT_LIST_HEAD(&delayed_tr->list);
3839 delayed_tr->handle = handle;
3840 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3841 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3842 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3845 _scsih_tm_tr_send(ioc, handle);
3851 * _scsih_check_volume_delete_events - set delete flag for volumes
3852 * @ioc: per adapter object
3853 * @event_data: the event data payload
3854 * Context: interrupt time.
3856 * This will handle the case when the cable connected to entire volume is
3857 * pulled. We will take care of setting the deleted flag so normal IO will
3863 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3864 Mpi2EventDataIrVolume_t *event_data)
3868 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3870 state = le32_to_cpu(event_data->NewValue);
3871 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3872 MPI2_RAID_VOL_STATE_FAILED)
3873 _scsih_set_volume_delete_flag(ioc,
3874 le16_to_cpu(event_data->VolDevHandle));
3878 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3879 * @ioc: per adapter object
3880 * @event_data: the temp threshold event data
3881 * Context: interrupt time.
3886 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3887 Mpi2EventDataTemperature_t *event_data)
3889 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3890 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3891 " exceeded for Sensor: %d !!!\n", ioc->name,
3892 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3893 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3894 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3895 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3896 event_data->SensorNum);
3897 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3898 ioc->name, event_data->CurrentTemperature);
3902 static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
3904 return (scmd->cmnd[0] == ATA_12 || scmd->cmnd[0] == ATA_16);
3908 * _scsih_flush_running_cmds - completing outstanding commands.
3909 * @ioc: per adapter object
3911 * The flushing out of all pending scmd commands following host reset,
3912 * where all IO is dropped to the floor.
3917 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3919 struct scsi_cmnd *scmd;
3923 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3924 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3928 if (ata_12_16_cmd(scmd))
3929 scsi_internal_device_unblock(scmd->device,
3931 mpt3sas_base_free_smid(ioc, smid);
3932 scsi_dma_unmap(scmd);
3933 if (ioc->pci_error_recovery)
3934 scmd->result = DID_NO_CONNECT << 16;
3936 scmd->result = DID_RESET << 16;
3937 scmd->scsi_done(scmd);
3939 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3944 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3945 * @ioc: per adapter object
3946 * @scmd: pointer to scsi command object
3947 * @mpi_request: pointer to the SCSI_IO request message frame
3949 * Supporting protection 1 and 3.
3954 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3955 Mpi2SCSIIORequest_t *mpi_request)
3958 unsigned char prot_op = scsi_get_prot_op(scmd);
3959 unsigned char prot_type = scsi_get_prot_type(scmd);
3960 Mpi25SCSIIORequest_t *mpi_request_3v =
3961 (Mpi25SCSIIORequest_t *)mpi_request;
3963 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3966 if (prot_op == SCSI_PROT_READ_STRIP)
3967 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3968 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3969 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3973 switch (prot_type) {
3974 case SCSI_PROT_DIF_TYPE1:
3975 case SCSI_PROT_DIF_TYPE2:
3978 * enable ref/guard checking
3979 * auto increment ref tag
3981 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3982 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3983 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3984 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3985 cpu_to_be32(scsi_prot_ref_tag(scmd));
3988 case SCSI_PROT_DIF_TYPE3:
3991 * enable guard checking
3993 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3998 mpi_request_3v->EEDPBlockSize =
3999 cpu_to_le16(scmd->device->sector_size);
4001 if (ioc->is_gen35_ioc)
4002 eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
4003 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
4007 * _scsih_eedp_error_handling - return sense code for EEDP errors
4008 * @scmd: pointer to scsi command object
4009 * @ioc_status: ioc status
4014 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4018 switch (ioc_status) {
4019 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4022 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4025 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4032 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4034 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4035 SAM_STAT_CHECK_CONDITION;
4039 * scsih_qcmd - main scsi request entry point
4040 * @scmd: pointer to scsi command object
4041 * @done: function pointer to be invoked on completion
4043 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4045 * Returns 0 on success. If there's a failure, return either:
4046 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4047 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4050 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4052 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4053 struct MPT3SAS_DEVICE *sas_device_priv_data;
4054 struct MPT3SAS_TARGET *sas_target_priv_data;
4055 struct _raid_device *raid_device;
4056 struct request *rq = scmd->request;
4058 Mpi2SCSIIORequest_t *mpi_request;
4063 if (ioc->logging_level & MPT_DEBUG_SCSI)
4064 scsi_print_command(scmd);
4067 * Lock the device for any subsequent command until command is
4070 if (ata_12_16_cmd(scmd))
4071 scsi_internal_device_block(scmd->device);
4073 sas_device_priv_data = scmd->device->hostdata;
4074 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4075 scmd->result = DID_NO_CONNECT << 16;
4076 scmd->scsi_done(scmd);
4080 if (ioc->pci_error_recovery || ioc->remove_host) {
4081 scmd->result = DID_NO_CONNECT << 16;
4082 scmd->scsi_done(scmd);
4086 sas_target_priv_data = sas_device_priv_data->sas_target;
4088 /* invalid device handle */
4089 handle = sas_target_priv_data->handle;
4090 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4091 scmd->result = DID_NO_CONNECT << 16;
4092 scmd->scsi_done(scmd);
4097 /* host recovery or link resets sent via IOCTLs */
4098 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4099 return SCSI_MLQUEUE_HOST_BUSY;
4101 /* device has been deleted */
4102 else if (sas_target_priv_data->deleted) {
4103 scmd->result = DID_NO_CONNECT << 16;
4104 scmd->scsi_done(scmd);
4106 /* device busy with task management */
4107 } else if (sas_target_priv_data->tm_busy ||
4108 sas_device_priv_data->block)
4109 return SCSI_MLQUEUE_DEVICE_BUSY;
4111 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4112 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4113 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4114 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4116 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4119 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4120 /* NCQ Prio supported, make sure control indicated high priority */
4121 if (sas_device_priv_data->ncq_prio_enable) {
4122 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
4123 if (class == IOPRIO_CLASS_RT)
4124 mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
4126 /* Make sure Device is not raid volume.
4127 * We do not expose raid functionality to upper layer for warpdrive.
4129 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
4130 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4131 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4133 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4135 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
4136 ioc->name, __func__);
4139 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4140 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4141 _scsih_setup_eedp(ioc, scmd, mpi_request);
4143 if (scmd->cmd_len == 32)
4144 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4145 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4146 if (sas_device_priv_data->sas_target->flags &
4147 MPT_TARGET_FLAGS_RAID_COMPONENT)
4148 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4150 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4151 mpi_request->DevHandle = cpu_to_le16(handle);
4152 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4153 mpi_request->Control = cpu_to_le32(mpi_control);
4154 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4155 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4156 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4157 mpi_request->SenseBufferLowAddress =
4158 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4159 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4160 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4162 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4164 if (mpi_request->DataLength) {
4165 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
4166 mpt3sas_base_free_smid(ioc, smid);
4170 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4172 raid_device = sas_target_priv_data->raid_device;
4173 if (raid_device && raid_device->direct_io_enabled)
4174 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4177 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4178 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4179 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4180 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4181 ioc->put_smid_fast_path(ioc, smid, handle);
4183 ioc->put_smid_scsi_io(ioc, smid,
4184 le16_to_cpu(mpi_request->DevHandle));
4186 ioc->put_smid_default(ioc, smid);
4190 return SCSI_MLQUEUE_HOST_BUSY;
4194 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4195 * @sense_buffer: sense data returned by target
4196 * @data: normalized skey/asc/ascq
4201 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4203 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4204 /* descriptor format */
4205 data->skey = sense_buffer[1] & 0x0F;
4206 data->asc = sense_buffer[2];
4207 data->ascq = sense_buffer[3];
4210 data->skey = sense_buffer[2] & 0x0F;
4211 data->asc = sense_buffer[12];
4212 data->ascq = sense_buffer[13];
4217 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4218 * @ioc: per adapter object
4219 * @scmd: pointer to scsi command object
4220 * @mpi_reply: reply mf payload returned from firmware
4222 * scsi_status - SCSI Status code returned from target device
4223 * scsi_state - state info associated with SCSI_IO determined by ioc
4224 * ioc_status - ioc supplied status info
4229 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4230 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4234 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4235 MPI2_IOCSTATUS_MASK;
4236 u8 scsi_state = mpi_reply->SCSIState;
4237 u8 scsi_status = mpi_reply->SCSIStatus;
4238 char *desc_ioc_state = NULL;
4239 char *desc_scsi_status = NULL;
4240 char *desc_scsi_state = ioc->tmp_string;
4241 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4242 struct _sas_device *sas_device = NULL;
4243 struct scsi_target *starget = scmd->device->sdev_target;
4244 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4245 char *device_str = NULL;
4249 if (ioc->hide_ir_msg)
4250 device_str = "WarpDrive";
4252 device_str = "volume";
4254 if (log_info == 0x31170000)
4257 switch (ioc_status) {
4258 case MPI2_IOCSTATUS_SUCCESS:
4259 desc_ioc_state = "success";
4261 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4262 desc_ioc_state = "invalid function";
4264 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4265 desc_ioc_state = "scsi recovered error";
4267 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4268 desc_ioc_state = "scsi invalid dev handle";
4270 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4271 desc_ioc_state = "scsi device not there";
4273 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4274 desc_ioc_state = "scsi data overrun";
4276 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4277 desc_ioc_state = "scsi data underrun";
4279 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4280 desc_ioc_state = "scsi io data error";
4282 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4283 desc_ioc_state = "scsi protocol error";
4285 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4286 desc_ioc_state = "scsi task terminated";
4288 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4289 desc_ioc_state = "scsi residual mismatch";
4291 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4292 desc_ioc_state = "scsi task mgmt failed";
4294 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4295 desc_ioc_state = "scsi ioc terminated";
4297 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4298 desc_ioc_state = "scsi ext terminated";
4300 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4301 desc_ioc_state = "eedp guard error";
4303 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4304 desc_ioc_state = "eedp ref tag error";
4306 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4307 desc_ioc_state = "eedp app tag error";
4309 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4310 desc_ioc_state = "insufficient power";
4313 desc_ioc_state = "unknown";
4317 switch (scsi_status) {
4318 case MPI2_SCSI_STATUS_GOOD:
4319 desc_scsi_status = "good";
4321 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4322 desc_scsi_status = "check condition";
4324 case MPI2_SCSI_STATUS_CONDITION_MET:
4325 desc_scsi_status = "condition met";
4327 case MPI2_SCSI_STATUS_BUSY:
4328 desc_scsi_status = "busy";
4330 case MPI2_SCSI_STATUS_INTERMEDIATE:
4331 desc_scsi_status = "intermediate";
4333 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4334 desc_scsi_status = "intermediate condmet";
4336 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4337 desc_scsi_status = "reservation conflict";
4339 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4340 desc_scsi_status = "command terminated";
4342 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4343 desc_scsi_status = "task set full";
4345 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4346 desc_scsi_status = "aca active";
4348 case MPI2_SCSI_STATUS_TASK_ABORTED:
4349 desc_scsi_status = "task aborted";
4352 desc_scsi_status = "unknown";
4356 desc_scsi_state[0] = '\0';
4358 desc_scsi_state = " ";
4359 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4360 strcat(desc_scsi_state, "response info ");
4361 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4362 strcat(desc_scsi_state, "state terminated ");
4363 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4364 strcat(desc_scsi_state, "no status ");
4365 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4366 strcat(desc_scsi_state, "autosense failed ");
4367 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4368 strcat(desc_scsi_state, "autosense valid ");
4370 scsi_print_command(scmd);
4372 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4373 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4374 device_str, (unsigned long long)priv_target->sas_address);
4376 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4379 "\tsas_address(0x%016llx), phy(%d)\n",
4380 ioc->name, (unsigned long long)
4381 sas_device->sas_address, sas_device->phy);
4382 if (sas_device->enclosure_handle != 0)
4384 "\tenclosure_logical_id(0x%016llx),"
4385 "slot(%d)\n", ioc->name,
4386 (unsigned long long)
4387 sas_device->enclosure_logical_id,
4389 if (sas_device->connector_name[0])
4391 "\tenclosure level(0x%04x),"
4392 " connector name( %s)\n", ioc->name,
4393 sas_device->enclosure_level,
4394 sas_device->connector_name);
4396 sas_device_put(sas_device);
4401 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4402 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4403 desc_ioc_state, ioc_status, smid);
4405 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4406 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4407 scsi_get_resid(scmd));
4409 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4410 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4411 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4413 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4414 ioc->name, desc_scsi_status,
4415 scsi_status, desc_scsi_state, scsi_state);
4417 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4418 struct sense_info data;
4419 _scsih_normalize_sense(scmd->sense_buffer, &data);
4421 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4422 ioc->name, data.skey,
4423 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4426 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4427 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4428 response_bytes = (u8 *)&response_info;
4429 _scsih_response_code(ioc, response_bytes[0]);
4434 * _scsih_turn_on_pfa_led - illuminate PFA LED
4435 * @ioc: per adapter object
4436 * @handle: device handle
4442 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4444 Mpi2SepReply_t mpi_reply;
4445 Mpi2SepRequest_t mpi_request;
4446 struct _sas_device *sas_device;
4448 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4452 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4453 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4454 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4455 mpi_request.SlotStatus =
4456 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4457 mpi_request.DevHandle = cpu_to_le16(handle);
4458 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4459 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4460 &mpi_request)) != 0) {
4461 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4462 __FILE__, __LINE__, __func__);
4465 sas_device->pfa_led_on = 1;
4467 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4468 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4469 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4470 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4471 le32_to_cpu(mpi_reply.IOCLogInfo)));
4475 sas_device_put(sas_device);
4479 * _scsih_turn_off_pfa_led - turn off Fault LED
4480 * @ioc: per adapter object
4481 * @sas_device: sas device whose PFA LED has to turned off
4487 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4488 struct _sas_device *sas_device)
4490 Mpi2SepReply_t mpi_reply;
4491 Mpi2SepRequest_t mpi_request;
4493 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4494 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4495 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4496 mpi_request.SlotStatus = 0;
4497 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4498 mpi_request.DevHandle = 0;
4499 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4500 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4501 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4502 &mpi_request)) != 0) {
4503 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4504 __FILE__, __LINE__, __func__);
4508 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4509 dewtprintk(ioc, printk(MPT3SAS_FMT
4510 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4511 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4512 le32_to_cpu(mpi_reply.IOCLogInfo)));
4518 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4519 * @ioc: per adapter object
4520 * @handle: device handle
4521 * Context: interrupt.
4526 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4528 struct fw_event_work *fw_event;
4530 fw_event = alloc_fw_event_work(0);
4533 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4534 fw_event->device_handle = handle;
4535 fw_event->ioc = ioc;
4536 _scsih_fw_event_add(ioc, fw_event);
4537 fw_event_work_put(fw_event);
4541 * _scsih_smart_predicted_fault - process smart errors
4542 * @ioc: per adapter object
4543 * @handle: device handle
4544 * Context: interrupt.
4549 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4551 struct scsi_target *starget;
4552 struct MPT3SAS_TARGET *sas_target_priv_data;
4553 Mpi2EventNotificationReply_t *event_reply;
4554 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4555 struct _sas_device *sas_device;
4557 unsigned long flags;
4559 /* only handle non-raid devices */
4560 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4561 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4565 starget = sas_device->starget;
4566 sas_target_priv_data = starget->hostdata;
4568 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4569 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4572 if (sas_device->enclosure_handle != 0)
4573 starget_printk(KERN_INFO, starget, "predicted fault, "
4574 "enclosure logical id(0x%016llx), slot(%d)\n",
4575 (unsigned long long)sas_device->enclosure_logical_id,
4577 if (sas_device->connector_name[0] != '\0')
4578 starget_printk(KERN_WARNING, starget, "predicted fault, "
4579 "enclosure level(0x%04x), connector name( %s)\n",
4580 sas_device->enclosure_level,
4581 sas_device->connector_name);
4582 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4584 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4585 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4587 /* insert into event log */
4588 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4589 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4590 event_reply = kzalloc(sz, GFP_KERNEL);
4592 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4593 ioc->name, __FILE__, __LINE__, __func__);
4597 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4598 event_reply->Event =
4599 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4600 event_reply->MsgLength = sz/4;
4601 event_reply->EventDataLength =
4602 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4603 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4604 event_reply->EventData;
4605 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4606 event_data->ASC = 0x5D;
4607 event_data->DevHandle = cpu_to_le16(handle);
4608 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4609 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4613 sas_device_put(sas_device);
4617 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4622 * _scsih_io_done - scsi request callback
4623 * @ioc: per adapter object
4624 * @smid: system request message index
4625 * @msix_index: MSIX table index supplied by the OS
4626 * @reply: reply message frame(lower 32bit addr)
4628 * Callback handler when using _scsih_qcmd.
4630 * Return 1 meaning mf should be freed from _base_interrupt
4631 * 0 means the mf is freed from this function.
4634 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4636 Mpi2SCSIIORequest_t *mpi_request;
4637 Mpi2SCSIIOReply_t *mpi_reply;
4638 struct scsi_cmnd *scmd;
4644 struct MPT3SAS_DEVICE *sas_device_priv_data;
4645 u32 response_code = 0;
4646 unsigned long flags;
4648 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4649 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4653 if (ata_12_16_cmd(scmd))
4654 scsi_internal_device_unblock(scmd->device, SDEV_RUNNING);
4656 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4658 if (mpi_reply == NULL) {
4659 scmd->result = DID_OK << 16;
4663 sas_device_priv_data = scmd->device->hostdata;
4664 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4665 sas_device_priv_data->sas_target->deleted) {
4666 scmd->result = DID_NO_CONNECT << 16;
4669 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4672 * WARPDRIVE: If direct_io is set then it is directIO,
4673 * the failed direct I/O should be redirected to volume
4675 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4676 ((ioc_status & MPI2_IOCSTATUS_MASK)
4677 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4678 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4679 ioc->scsi_lookup[smid - 1].scmd = scmd;
4680 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4681 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4682 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4683 mpi_request->DevHandle =
4684 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4685 ioc->put_smid_scsi_io(ioc, smid,
4686 sas_device_priv_data->sas_target->handle);
4689 /* turning off TLR */
4690 scsi_state = mpi_reply->SCSIState;
4691 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4693 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4694 if (!sas_device_priv_data->tlr_snoop_check) {
4695 sas_device_priv_data->tlr_snoop_check++;
4696 if (!ioc->is_warpdrive &&
4697 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4698 sas_is_tlr_enabled(scmd->device) &&
4699 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4700 sas_disable_tlr(scmd->device);
4701 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4705 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4706 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4707 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4708 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4711 ioc_status &= MPI2_IOCSTATUS_MASK;
4712 scsi_status = mpi_reply->SCSIStatus;
4714 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4715 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4716 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4717 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4718 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4721 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4722 struct sense_info data;
4723 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4725 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4726 le32_to_cpu(mpi_reply->SenseCount));
4727 memcpy(scmd->sense_buffer, sense_data, sz);
4728 _scsih_normalize_sense(scmd->sense_buffer, &data);
4729 /* failure prediction threshold exceeded */
4730 if (data.asc == 0x5D)
4731 _scsih_smart_predicted_fault(ioc,
4732 le16_to_cpu(mpi_reply->DevHandle));
4733 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4735 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
4736 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4737 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4738 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4739 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4741 switch (ioc_status) {
4742 case MPI2_IOCSTATUS_BUSY:
4743 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4744 scmd->result = SAM_STAT_BUSY;
4747 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4748 scmd->result = DID_NO_CONNECT << 16;
4751 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4752 if (sas_device_priv_data->block) {
4753 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4756 if (log_info == 0x31110630) {
4757 if (scmd->retries > 2) {
4758 scmd->result = DID_NO_CONNECT << 16;
4759 scsi_device_set_state(scmd->device,
4762 scmd->result = DID_SOFT_ERROR << 16;
4763 scmd->device->expecting_cc_ua = 1;
4766 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4767 scmd->result = DID_RESET << 16;
4770 scmd->result = DID_SOFT_ERROR << 16;
4772 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4773 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4774 scmd->result = DID_RESET << 16;
4777 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4778 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4779 scmd->result = DID_SOFT_ERROR << 16;
4781 scmd->result = (DID_OK << 16) | scsi_status;
4784 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4785 scmd->result = (DID_OK << 16) | scsi_status;
4787 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4790 if (xfer_cnt < scmd->underflow) {
4791 if (scsi_status == SAM_STAT_BUSY)
4792 scmd->result = SAM_STAT_BUSY;
4794 scmd->result = DID_SOFT_ERROR << 16;
4795 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4796 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4797 scmd->result = DID_SOFT_ERROR << 16;
4798 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4799 scmd->result = DID_RESET << 16;
4800 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4801 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4802 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4803 scmd->result = (DRIVER_SENSE << 24) |
4804 SAM_STAT_CHECK_CONDITION;
4805 scmd->sense_buffer[0] = 0x70;
4806 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4807 scmd->sense_buffer[12] = 0x20;
4808 scmd->sense_buffer[13] = 0;
4812 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4813 scsi_set_resid(scmd, 0);
4814 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4815 case MPI2_IOCSTATUS_SUCCESS:
4816 scmd->result = (DID_OK << 16) | scsi_status;
4817 if (response_code ==
4818 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4819 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4820 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4821 scmd->result = DID_SOFT_ERROR << 16;
4822 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4823 scmd->result = DID_RESET << 16;
4826 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4827 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4828 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4829 _scsih_eedp_error_handling(scmd, ioc_status);
4832 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4833 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4834 case MPI2_IOCSTATUS_INVALID_SGL:
4835 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4836 case MPI2_IOCSTATUS_INVALID_FIELD:
4837 case MPI2_IOCSTATUS_INVALID_STATE:
4838 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4839 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4840 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4842 scmd->result = DID_SOFT_ERROR << 16;
4847 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4848 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4852 scsi_dma_unmap(scmd);
4854 scmd->scsi_done(scmd);
4859 * _scsih_sas_host_refresh - refreshing sas host object contents
4860 * @ioc: per adapter object
4863 * During port enable, fw will send topology events for every device. Its
4864 * possible that the handles may change from the previous setting, so this
4865 * code keeping handles updating if changed.
4870 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4875 Mpi2ConfigReply_t mpi_reply;
4876 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4877 u16 attached_handle;
4880 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4881 "updating handles for sas_host(0x%016llx)\n",
4882 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4884 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4885 * sizeof(Mpi2SasIOUnit0PhyData_t));
4886 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4887 if (!sas_iounit_pg0) {
4888 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4889 ioc->name, __FILE__, __LINE__, __func__);
4893 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4894 sas_iounit_pg0, sz)) != 0)
4896 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4897 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4899 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4900 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4902 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4903 PhyData[0].ControllerDevHandle);
4904 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4905 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4907 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4908 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4909 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4910 attached_handle, i, link_rate);
4913 kfree(sas_iounit_pg0);
4917 * _scsih_sas_host_add - create sas host object
4918 * @ioc: per adapter object
4920 * Creating host side data object, stored in ioc->sas_hba
4925 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4928 Mpi2ConfigReply_t mpi_reply;
4929 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4930 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4931 Mpi2SasPhyPage0_t phy_pg0;
4932 Mpi2SasDevicePage0_t sas_device_pg0;
4933 Mpi2SasEnclosurePage0_t enclosure_pg0;
4936 u8 device_missing_delay;
4939 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
4941 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4942 ioc->name, __FILE__, __LINE__, __func__);
4945 ioc->sas_hba.phy = kcalloc(num_phys,
4946 sizeof(struct _sas_phy), GFP_KERNEL);
4947 if (!ioc->sas_hba.phy) {
4948 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4949 ioc->name, __FILE__, __LINE__, __func__);
4952 ioc->sas_hba.num_phys = num_phys;
4954 /* sas_iounit page 0 */
4955 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4956 sizeof(Mpi2SasIOUnit0PhyData_t));
4957 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4958 if (!sas_iounit_pg0) {
4959 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4960 ioc->name, __FILE__, __LINE__, __func__);
4963 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4964 sas_iounit_pg0, sz))) {
4965 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4966 ioc->name, __FILE__, __LINE__, __func__);
4969 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4970 MPI2_IOCSTATUS_MASK;
4971 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4972 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4973 ioc->name, __FILE__, __LINE__, __func__);
4977 /* sas_iounit page 1 */
4978 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4979 sizeof(Mpi2SasIOUnit1PhyData_t));
4980 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4981 if (!sas_iounit_pg1) {
4982 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4983 ioc->name, __FILE__, __LINE__, __func__);
4986 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4987 sas_iounit_pg1, sz))) {
4988 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4989 ioc->name, __FILE__, __LINE__, __func__);
4992 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4993 MPI2_IOCSTATUS_MASK;
4994 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4995 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4996 ioc->name, __FILE__, __LINE__, __func__);
5000 ioc->io_missing_delay =
5001 sas_iounit_pg1->IODeviceMissingDelay;
5002 device_missing_delay =
5003 sas_iounit_pg1->ReportDeviceMissingDelay;
5004 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
5005 ioc->device_missing_delay = (device_missing_delay &
5006 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
5008 ioc->device_missing_delay = device_missing_delay &
5009 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
5011 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
5012 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5013 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5015 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5016 ioc->name, __FILE__, __LINE__, __func__);
5019 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5020 MPI2_IOCSTATUS_MASK;
5021 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5022 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5023 ioc->name, __FILE__, __LINE__, __func__);
5028 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5029 PhyData[0].ControllerDevHandle);
5030 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5031 ioc->sas_hba.phy[i].phy_id = i;
5032 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
5033 phy_pg0, ioc->sas_hba.parent_dev);
5035 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5036 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
5037 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5038 ioc->name, __FILE__, __LINE__, __func__);
5041 ioc->sas_hba.enclosure_handle =
5042 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5043 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5045 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5046 ioc->name, ioc->sas_hba.handle,
5047 (unsigned long long) ioc->sas_hba.sas_address,
5048 ioc->sas_hba.num_phys) ;
5050 if (ioc->sas_hba.enclosure_handle) {
5051 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5052 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5053 ioc->sas_hba.enclosure_handle)))
5054 ioc->sas_hba.enclosure_logical_id =
5055 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5059 kfree(sas_iounit_pg1);
5060 kfree(sas_iounit_pg0);
5064 * _scsih_expander_add - creating expander object
5065 * @ioc: per adapter object
5066 * @handle: expander handle
5068 * Creating expander object, stored in ioc->sas_expander_list.
5070 * Return 0 for success, else error.
5073 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5075 struct _sas_node *sas_expander;
5076 Mpi2ConfigReply_t mpi_reply;
5077 Mpi2ExpanderPage0_t expander_pg0;
5078 Mpi2ExpanderPage1_t expander_pg1;
5079 Mpi2SasEnclosurePage0_t enclosure_pg0;
5082 u64 sas_address, sas_address_parent = 0;
5084 unsigned long flags;
5085 struct _sas_port *mpt3sas_port = NULL;
5092 if (ioc->shost_recovery || ioc->pci_error_recovery)
5095 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5096 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5097 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5098 ioc->name, __FILE__, __LINE__, __func__);
5102 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5103 MPI2_IOCSTATUS_MASK;
5104 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5105 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5106 ioc->name, __FILE__, __LINE__, __func__);
5110 /* handle out of order topology events */
5111 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5112 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5114 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5115 ioc->name, __FILE__, __LINE__, __func__);
5118 if (sas_address_parent != ioc->sas_hba.sas_address) {
5119 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5120 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5121 sas_address_parent);
5122 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5123 if (!sas_expander) {
5124 rc = _scsih_expander_add(ioc, parent_handle);
5130 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5131 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5132 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5134 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5139 sas_expander = kzalloc(sizeof(struct _sas_node),
5141 if (!sas_expander) {
5142 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5143 ioc->name, __FILE__, __LINE__, __func__);
5147 sas_expander->handle = handle;
5148 sas_expander->num_phys = expander_pg0.NumPhys;
5149 sas_expander->sas_address_parent = sas_address_parent;
5150 sas_expander->sas_address = sas_address;
5152 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5153 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5154 handle, parent_handle, (unsigned long long)
5155 sas_expander->sas_address, sas_expander->num_phys);
5157 if (!sas_expander->num_phys)
5159 sas_expander->phy = kcalloc(sas_expander->num_phys,
5160 sizeof(struct _sas_phy), GFP_KERNEL);
5161 if (!sas_expander->phy) {
5162 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5163 ioc->name, __FILE__, __LINE__, __func__);
5168 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5169 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5170 sas_address_parent);
5171 if (!mpt3sas_port) {
5172 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5173 ioc->name, __FILE__, __LINE__, __func__);
5177 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5179 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5180 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5181 &expander_pg1, i, handle))) {
5182 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5183 ioc->name, __FILE__, __LINE__, __func__);
5187 sas_expander->phy[i].handle = handle;
5188 sas_expander->phy[i].phy_id = i;
5190 if ((mpt3sas_transport_add_expander_phy(ioc,
5191 &sas_expander->phy[i], expander_pg1,
5192 sas_expander->parent_dev))) {
5193 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5194 ioc->name, __FILE__, __LINE__, __func__);
5200 if (sas_expander->enclosure_handle) {
5201 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5202 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5203 sas_expander->enclosure_handle)))
5204 sas_expander->enclosure_logical_id =
5205 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5208 _scsih_expander_node_add(ioc, sas_expander);
5214 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5215 sas_address_parent);
5216 kfree(sas_expander);
5221 * mpt3sas_expander_remove - removing expander object
5222 * @ioc: per adapter object
5223 * @sas_address: expander sas_address
5228 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5230 struct _sas_node *sas_expander;
5231 unsigned long flags;
5233 if (ioc->shost_recovery)
5236 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5237 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5240 list_del(&sas_expander->list);
5241 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5243 _scsih_expander_node_remove(ioc, sas_expander);
5247 * _scsih_done - internal SCSI_IO callback handler.
5248 * @ioc: per adapter object
5249 * @smid: system request message index
5250 * @msix_index: MSIX table index supplied by the OS
5251 * @reply: reply message frame(lower 32bit addr)
5253 * Callback handler when sending internal generated SCSI_IO.
5254 * The callback index passed is `ioc->scsih_cb_idx`
5256 * Return 1 meaning mf should be freed from _base_interrupt
5257 * 0 means the mf is freed from this function.
5260 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5262 MPI2DefaultReply_t *mpi_reply;
5264 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5265 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5267 if (ioc->scsih_cmds.smid != smid)
5269 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5271 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5272 mpi_reply->MsgLength*4);
5273 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5275 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5276 complete(&ioc->scsih_cmds.done);
5283 #define MPT3_MAX_LUNS (255)
5287 * _scsih_check_access_status - check access flags
5288 * @ioc: per adapter object
5289 * @sas_address: sas address
5290 * @handle: sas device handle
5291 * @access_flags: errors returned during discovery of the device
5293 * Return 0 for success, else failure
5296 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5297 u16 handle, u8 access_status)
5302 switch (access_status) {
5303 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5304 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5307 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5308 desc = "sata capability failed";
5310 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5311 desc = "sata affiliation conflict";
5313 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5314 desc = "route not addressable";
5316 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5317 desc = "smp error not addressable";
5319 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5320 desc = "device blocked";
5322 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5323 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5324 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5325 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5326 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5327 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5328 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5329 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5330 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5331 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5332 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5333 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5334 desc = "sata initialization failed";
5345 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5346 ioc->name, desc, (unsigned long long)sas_address, handle);
5351 * _scsih_check_device - checking device responsiveness
5352 * @ioc: per adapter object
5353 * @parent_sas_address: sas address of parent expander or sas host
5354 * @handle: attached device handle
5355 * @phy_numberv: phy number
5356 * @link_rate: new link rate
5361 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5362 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5364 Mpi2ConfigReply_t mpi_reply;
5365 Mpi2SasDevicePage0_t sas_device_pg0;
5366 struct _sas_device *sas_device;
5368 unsigned long flags;
5370 struct scsi_target *starget;
5371 struct MPT3SAS_TARGET *sas_target_priv_data;
5375 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5376 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5379 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5380 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5383 /* wide port handling ~ we need only handle device once for the phy that
5384 * is matched in sas device page zero
5386 if (phy_number != sas_device_pg0.PhyNum)
5389 /* check if this is end device */
5390 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5391 if (!(_scsih_is_end_device(device_info)))
5394 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5395 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5396 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5402 if (unlikely(sas_device->handle != handle)) {
5403 starget = sas_device->starget;
5404 sas_target_priv_data = starget->hostdata;
5405 starget_printk(KERN_INFO, starget,
5406 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5407 sas_device->handle, handle);
5408 sas_target_priv_data->handle = handle;
5409 sas_device->handle = handle;
5410 if (le16_to_cpu(sas_device_pg0.Flags) &
5411 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5412 sas_device->enclosure_level =
5413 sas_device_pg0.EnclosureLevel;
5414 memcpy(sas_device->connector_name,
5415 sas_device_pg0.ConnectorName, 4);
5416 sas_device->connector_name[4] = '\0';
5418 sas_device->enclosure_level = 0;
5419 sas_device->connector_name[0] = '\0';
5423 /* check if device is present */
5424 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5425 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5427 "device is not present handle(0x%04x), flags!!!\n",
5432 /* check if there were any issues with discovery */
5433 if (_scsih_check_access_status(ioc, sas_address, handle,
5434 sas_device_pg0.AccessStatus))
5437 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5438 _scsih_ublock_io_device(ioc, sas_address);
5441 sas_device_put(sas_device);
5445 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5447 sas_device_put(sas_device);
5451 * _scsih_add_device - creating sas device object
5452 * @ioc: per adapter object
5453 * @handle: sas device handle
5454 * @phy_num: phy number end device attached to
5455 * @is_pd: is this hidden raid component
5457 * Creating end device object, stored in ioc->sas_device_list.
5459 * Returns 0 for success, non-zero for failure.
5462 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5465 Mpi2ConfigReply_t mpi_reply;
5466 Mpi2SasDevicePage0_t sas_device_pg0;
5467 Mpi2SasEnclosurePage0_t enclosure_pg0;
5468 struct _sas_device *sas_device;
5473 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5474 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5475 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5476 ioc->name, __FILE__, __LINE__, __func__);
5480 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5481 MPI2_IOCSTATUS_MASK;
5482 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5483 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5484 ioc->name, __FILE__, __LINE__, __func__);
5488 /* check if this is end device */
5489 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5490 if (!(_scsih_is_end_device(device_info)))
5492 set_bit(handle, ioc->pend_os_device_add);
5493 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5495 /* check if device is present */
5496 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5497 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5498 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5503 /* check if there were any issues with discovery */
5504 if (_scsih_check_access_status(ioc, sas_address, handle,
5505 sas_device_pg0.AccessStatus))
5508 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5511 clear_bit(handle, ioc->pend_os_device_add);
5512 sas_device_put(sas_device);
5516 sas_device = kzalloc(sizeof(struct _sas_device),
5519 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5520 ioc->name, __FILE__, __LINE__, __func__);
5524 kref_init(&sas_device->refcount);
5525 sas_device->handle = handle;
5526 if (_scsih_get_sas_address(ioc,
5527 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5528 &sas_device->sas_address_parent) != 0)
5529 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5530 ioc->name, __FILE__, __LINE__, __func__);
5531 sas_device->enclosure_handle =
5532 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5533 if (sas_device->enclosure_handle != 0)
5535 le16_to_cpu(sas_device_pg0.Slot);
5536 sas_device->device_info = device_info;
5537 sas_device->sas_address = sas_address;
5538 sas_device->phy = sas_device_pg0.PhyNum;
5539 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5540 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5542 if (le16_to_cpu(sas_device_pg0.Flags)
5543 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5544 sas_device->enclosure_level =
5545 sas_device_pg0.EnclosureLevel;
5546 memcpy(sas_device->connector_name,
5547 sas_device_pg0.ConnectorName, 4);
5548 sas_device->connector_name[4] = '\0';
5550 sas_device->enclosure_level = 0;
5551 sas_device->connector_name[0] = '\0';
5553 /* get enclosure_logical_id */
5554 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5555 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5556 sas_device->enclosure_handle)))
5557 sas_device->enclosure_logical_id =
5558 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5560 /* get device name */
5561 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5563 if (ioc->wait_for_discovery_to_complete)
5564 _scsih_sas_device_init_add(ioc, sas_device);
5566 _scsih_sas_device_add(ioc, sas_device);
5568 sas_device_put(sas_device);
5573 * _scsih_remove_device - removing sas device object
5574 * @ioc: per adapter object
5575 * @sas_device_delete: the sas_device object
5580 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5581 struct _sas_device *sas_device)
5583 struct MPT3SAS_TARGET *sas_target_priv_data;
5585 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5586 (sas_device->pfa_led_on)) {
5587 _scsih_turn_off_pfa_led(ioc, sas_device);
5588 sas_device->pfa_led_on = 0;
5590 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5591 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5592 ioc->name, __func__,
5593 sas_device->handle, (unsigned long long)
5594 sas_device->sas_address));
5595 if (sas_device->enclosure_handle != 0)
5596 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5597 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5598 ioc->name, __func__,
5599 (unsigned long long)sas_device->enclosure_logical_id,
5601 if (sas_device->connector_name[0] != '\0')
5602 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5603 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5604 ioc->name, __func__,
5605 sas_device->enclosure_level,
5606 sas_device->connector_name));
5608 if (sas_device->starget && sas_device->starget->hostdata) {
5609 sas_target_priv_data = sas_device->starget->hostdata;
5610 sas_target_priv_data->deleted = 1;
5611 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5612 sas_target_priv_data->handle =
5613 MPT3SAS_INVALID_DEVICE_HANDLE;
5616 if (!ioc->hide_drives)
5617 mpt3sas_transport_port_remove(ioc,
5618 sas_device->sas_address,
5619 sas_device->sas_address_parent);
5622 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5623 ioc->name, sas_device->handle,
5624 (unsigned long long) sas_device->sas_address);
5625 if (sas_device->enclosure_handle != 0)
5627 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5629 (unsigned long long)sas_device->enclosure_logical_id,
5631 if (sas_device->connector_name[0] != '\0')
5633 "removing enclosure level(0x%04x), connector name( %s)\n",
5634 ioc->name, sas_device->enclosure_level,
5635 sas_device->connector_name);
5637 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5638 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5639 ioc->name, __func__,
5640 sas_device->handle, (unsigned long long)
5641 sas_device->sas_address));
5642 if (sas_device->enclosure_handle != 0)
5643 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5644 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5645 ioc->name, __func__,
5646 (unsigned long long)sas_device->enclosure_logical_id,
5648 if (sas_device->connector_name[0] != '\0')
5649 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5650 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5651 ioc->name, __func__, sas_device->enclosure_level,
5652 sas_device->connector_name));
5656 * _scsih_sas_topology_change_event_debug - debug for topology event
5657 * @ioc: per adapter object
5658 * @event_data: event data payload
5662 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5663 Mpi2EventDataSasTopologyChangeList_t *event_data)
5669 char *status_str = NULL;
5670 u8 link_rate, prev_link_rate;
5672 switch (event_data->ExpStatus) {
5673 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5676 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5677 status_str = "remove";
5679 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5681 status_str = "responding";
5683 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5684 status_str = "remove delay";
5687 status_str = "unknown status";
5690 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5691 ioc->name, status_str);
5692 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5693 "start_phy(%02d), count(%d)\n",
5694 le16_to_cpu(event_data->ExpanderDevHandle),
5695 le16_to_cpu(event_data->EnclosureHandle),
5696 event_data->StartPhyNum, event_data->NumEntries);
5697 for (i = 0; i < event_data->NumEntries; i++) {
5698 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5701 phy_number = event_data->StartPhyNum + i;
5702 reason_code = event_data->PHY[i].PhyStatus &
5703 MPI2_EVENT_SAS_TOPO_RC_MASK;
5704 switch (reason_code) {
5705 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5706 status_str = "target add";
5708 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5709 status_str = "target remove";
5711 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5712 status_str = "delay target remove";
5714 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5715 status_str = "link rate change";
5717 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5718 status_str = "target responding";
5721 status_str = "unknown";
5724 link_rate = event_data->PHY[i].LinkRate >> 4;
5725 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5726 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5727 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5728 handle, status_str, link_rate, prev_link_rate);
5734 * _scsih_sas_topology_change_event - handle topology changes
5735 * @ioc: per adapter object
5736 * @fw_event: The fw_event_work object
5741 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5742 struct fw_event_work *fw_event)
5745 u16 parent_handle, handle;
5747 u8 phy_number, max_phys;
5748 struct _sas_node *sas_expander;
5750 unsigned long flags;
5751 u8 link_rate, prev_link_rate;
5752 Mpi2EventDataSasTopologyChangeList_t *event_data =
5753 (Mpi2EventDataSasTopologyChangeList_t *)
5754 fw_event->event_data;
5756 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5757 _scsih_sas_topology_change_event_debug(ioc, event_data);
5759 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5762 if (!ioc->sas_hba.num_phys)
5763 _scsih_sas_host_add(ioc);
5765 _scsih_sas_host_refresh(ioc);
5767 if (fw_event->ignore) {
5768 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5769 "ignoring expander event\n", ioc->name));
5773 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5775 /* handle expander add */
5776 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5777 if (_scsih_expander_add(ioc, parent_handle) != 0)
5780 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5781 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5784 sas_address = sas_expander->sas_address;
5785 max_phys = sas_expander->num_phys;
5786 } else if (parent_handle < ioc->sas_hba.num_phys) {
5787 sas_address = ioc->sas_hba.sas_address;
5788 max_phys = ioc->sas_hba.num_phys;
5790 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5793 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5795 /* handle siblings events */
5796 for (i = 0; i < event_data->NumEntries; i++) {
5797 if (fw_event->ignore) {
5798 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5799 "ignoring expander event\n", ioc->name));
5802 if (ioc->remove_host || ioc->pci_error_recovery)
5804 phy_number = event_data->StartPhyNum + i;
5805 if (phy_number >= max_phys)
5807 reason_code = event_data->PHY[i].PhyStatus &
5808 MPI2_EVENT_SAS_TOPO_RC_MASK;
5809 if ((event_data->PHY[i].PhyStatus &
5810 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5811 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5813 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5816 link_rate = event_data->PHY[i].LinkRate >> 4;
5817 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5818 switch (reason_code) {
5819 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5821 if (ioc->shost_recovery)
5824 if (link_rate == prev_link_rate)
5827 mpt3sas_transport_update_links(ioc, sas_address,
5828 handle, phy_number, link_rate);
5830 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5833 _scsih_check_device(ioc, sas_address, handle,
5834 phy_number, link_rate);
5836 if (!test_bit(handle, ioc->pend_os_device_add))
5840 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5842 if (ioc->shost_recovery)
5845 mpt3sas_transport_update_links(ioc, sas_address,
5846 handle, phy_number, link_rate);
5848 _scsih_add_device(ioc, handle, phy_number, 0);
5851 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5853 _scsih_device_remove_by_handle(ioc, handle);
5858 /* handle expander removal */
5859 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5861 mpt3sas_expander_remove(ioc, sas_address);
5867 * _scsih_sas_device_status_change_event_debug - debug for device event
5868 * @event_data: event data payload
5874 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5875 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5877 char *reason_str = NULL;
5879 switch (event_data->ReasonCode) {
5880 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5881 reason_str = "smart data";
5883 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5884 reason_str = "unsupported device discovered";
5886 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5887 reason_str = "internal device reset";
5889 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5890 reason_str = "internal task abort";
5892 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5893 reason_str = "internal task abort set";
5895 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5896 reason_str = "internal clear task set";
5898 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5899 reason_str = "internal query task";
5901 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5902 reason_str = "sata init failure";
5904 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5905 reason_str = "internal device reset complete";
5907 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5908 reason_str = "internal task abort complete";
5910 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5911 reason_str = "internal async notification";
5913 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5914 reason_str = "expander reduced functionality";
5916 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5917 reason_str = "expander reduced functionality complete";
5920 reason_str = "unknown reason";
5923 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5924 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5925 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5926 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5927 le16_to_cpu(event_data->TaskTag));
5928 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5929 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5930 event_data->ASC, event_data->ASCQ);
5935 * _scsih_sas_device_status_change_event - handle device status change
5936 * @ioc: per adapter object
5937 * @fw_event: The fw_event_work object
5943 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5944 struct fw_event_work *fw_event)
5946 struct MPT3SAS_TARGET *target_priv_data;
5947 struct _sas_device *sas_device;
5949 unsigned long flags;
5950 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5951 (Mpi2EventDataSasDeviceStatusChange_t *)
5952 fw_event->event_data;
5954 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5955 _scsih_sas_device_status_change_event_debug(ioc,
5958 /* In MPI Revision K (0xC), the internal device reset complete was
5959 * implemented, so avoid setting tm_busy flag for older firmware.
5961 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5964 if (event_data->ReasonCode !=
5965 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5966 event_data->ReasonCode !=
5967 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5970 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5971 sas_address = le64_to_cpu(event_data->SASAddress);
5972 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5975 if (!sas_device || !sas_device->starget)
5978 target_priv_data = sas_device->starget->hostdata;
5979 if (!target_priv_data)
5982 if (event_data->ReasonCode ==
5983 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5984 target_priv_data->tm_busy = 1;
5986 target_priv_data->tm_busy = 0;
5990 sas_device_put(sas_device);
5992 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5997 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5999 * @ioc: per adapter object
6000 * @event_data: event data payload
6006 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6007 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
6009 char *reason_str = NULL;
6011 switch (event_data->ReasonCode) {
6012 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
6013 reason_str = "enclosure add";
6015 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
6016 reason_str = "enclosure remove";
6019 reason_str = "unknown reason";
6023 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
6024 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
6025 " number slots(%d)\n", ioc->name, reason_str,
6026 le16_to_cpu(event_data->EnclosureHandle),
6027 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
6028 le16_to_cpu(event_data->StartSlot));
6032 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
6033 * @ioc: per adapter object
6034 * @fw_event: The fw_event_work object
6040 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
6041 struct fw_event_work *fw_event)
6043 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6044 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
6045 (Mpi2EventDataSasEnclDevStatusChange_t *)
6046 fw_event->event_data);
6050 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6051 * @ioc: per adapter object
6052 * @fw_event: The fw_event_work object
6058 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
6059 struct fw_event_work *fw_event)
6061 struct scsi_cmnd *scmd;
6062 struct scsi_device *sdev;
6065 struct MPT3SAS_DEVICE *sas_device_priv_data;
6066 u32 termination_count;
6068 Mpi2SCSITaskManagementReply_t *mpi_reply;
6069 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
6070 (Mpi2EventDataSasBroadcastPrimitive_t *)
6071 fw_event->event_data;
6073 unsigned long flags;
6076 u8 task_abort_retries;
6078 mutex_lock(&ioc->tm_cmds.mutex);
6080 "%s: enter: phy number(%d), width(%d)\n",
6081 ioc->name, __func__, event_data->PhyNum,
6082 event_data->PortWidth);
6084 _scsih_block_io_all_device(ioc);
6086 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6087 mpi_reply = ioc->tm_cmds.reply;
6088 broadcast_aen_retry:
6090 /* sanity checks for retrying this loop */
6091 if (max_retries++ == 5) {
6092 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
6093 ioc->name, __func__));
6095 } else if (max_retries > 1)
6096 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
6097 ioc->name, __func__, max_retries - 1));
6099 termination_count = 0;
6101 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
6102 if (ioc->shost_recovery)
6104 scmd = _scsih_scsi_lookup_get(ioc, smid);
6107 sdev = scmd->device;
6108 sas_device_priv_data = sdev->hostdata;
6109 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
6111 /* skip hidden raid components */
6112 if (sas_device_priv_data->sas_target->flags &
6113 MPT_TARGET_FLAGS_RAID_COMPONENT)
6116 if (sas_device_priv_data->sas_target->flags &
6117 MPT_TARGET_FLAGS_VOLUME)
6120 handle = sas_device_priv_data->sas_target->handle;
6121 lun = sas_device_priv_data->lun;
6124 if (ioc->shost_recovery)
6127 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6128 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6129 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
6131 sdev_printk(KERN_WARNING, sdev,
6132 "mpt3sas_scsih_issue_tm: FAILED when sending "
6133 "QUERY_TASK: scmd(%p)\n", scmd);
6134 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6135 goto broadcast_aen_retry;
6137 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6138 & MPI2_IOCSTATUS_MASK;
6139 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6140 sdev_printk(KERN_WARNING, sdev,
6141 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6143 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6144 goto broadcast_aen_retry;
6147 /* see if IO is still owned by IOC and target */
6148 if (mpi_reply->ResponseCode ==
6149 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6150 mpi_reply->ResponseCode ==
6151 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6152 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6155 task_abort_retries = 0;
6157 if (task_abort_retries++ == 60) {
6158 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6159 "%s: ABORT_TASK: giving up\n", ioc->name,
6161 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6162 goto broadcast_aen_retry;
6165 if (ioc->shost_recovery)
6168 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6169 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
6172 sdev_printk(KERN_WARNING, sdev,
6173 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6174 "scmd(%p)\n", scmd);
6178 if (task_abort_retries > 1)
6179 sdev_printk(KERN_WARNING, sdev,
6180 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6182 task_abort_retries - 1, scmd);
6184 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6185 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6188 if (ioc->broadcast_aen_pending) {
6189 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6190 "%s: loop back due to pending AEN\n",
6191 ioc->name, __func__));
6192 ioc->broadcast_aen_pending = 0;
6193 goto broadcast_aen_retry;
6197 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6200 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6201 "%s - exit, query_count = %d termination_count = %d\n",
6202 ioc->name, __func__, query_count, termination_count));
6204 ioc->broadcast_aen_busy = 0;
6205 if (!ioc->shost_recovery)
6206 _scsih_ublock_io_all_device(ioc);
6207 mutex_unlock(&ioc->tm_cmds.mutex);
6211 * _scsih_sas_discovery_event - handle discovery events
6212 * @ioc: per adapter object
6213 * @fw_event: The fw_event_work object
6219 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
6220 struct fw_event_work *fw_event)
6222 Mpi2EventDataSasDiscovery_t *event_data =
6223 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
6225 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6226 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
6227 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6229 if (event_data->DiscoveryStatus)
6230 pr_info("discovery_status(0x%08x)",
6231 le32_to_cpu(event_data->DiscoveryStatus));
6235 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6236 !ioc->sas_hba.num_phys) {
6237 if (disable_discovery > 0 && ioc->shost_recovery) {
6238 /* Wait for the reset to complete */
6239 while (ioc->shost_recovery)
6242 _scsih_sas_host_add(ioc);
6247 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6248 * @ioc: per adapter object
6249 * @handle: device handle for physical disk
6250 * @phys_disk_num: physical disk number
6252 * Return 0 for success, else failure.
6255 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6257 Mpi2RaidActionRequest_t *mpi_request;
6258 Mpi2RaidActionReply_t *mpi_reply;
6265 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6268 mutex_lock(&ioc->scsih_cmds.mutex);
6270 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6271 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6272 ioc->name, __func__);
6276 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6278 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6280 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6281 ioc->name, __func__);
6282 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6287 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6288 ioc->scsih_cmds.smid = smid;
6289 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6291 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6292 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6293 mpi_request->PhysDiskNum = phys_disk_num;
6295 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6296 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6297 handle, phys_disk_num));
6299 init_completion(&ioc->scsih_cmds.done);
6300 ioc->put_smid_default(ioc, smid);
6301 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6303 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6304 pr_err(MPT3SAS_FMT "%s: timeout\n",
6305 ioc->name, __func__);
6306 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6312 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6314 mpi_reply = ioc->scsih_cmds.reply;
6315 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6316 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6317 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6320 ioc_status &= MPI2_IOCSTATUS_MASK;
6321 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6322 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6323 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6324 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6328 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6329 "IR RAID_ACTION: completed successfully\n",
6334 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6335 mutex_unlock(&ioc->scsih_cmds.mutex);
6338 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
6343 * _scsih_reprobe_lun - reprobing lun
6344 * @sdev: scsi device struct
6345 * @no_uld_attach: sdev->no_uld_attach flag setting
6349 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6351 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6352 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6353 sdev->no_uld_attach ? "hiding" : "exposing");
6354 WARN_ON(scsi_device_reprobe(sdev));
6358 * _scsih_sas_volume_add - add new volume
6359 * @ioc: per adapter object
6360 * @element: IR config element data
6366 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6367 Mpi2EventIrConfigElement_t *element)
6369 struct _raid_device *raid_device;
6370 unsigned long flags;
6372 u16 handle = le16_to_cpu(element->VolDevHandle);
6375 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6378 "failure at %s:%d/%s()!\n", ioc->name,
6379 __FILE__, __LINE__, __func__);
6383 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6384 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6385 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6390 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6393 "failure at %s:%d/%s()!\n", ioc->name,
6394 __FILE__, __LINE__, __func__);
6398 raid_device->id = ioc->sas_id++;
6399 raid_device->channel = RAID_CHANNEL;
6400 raid_device->handle = handle;
6401 raid_device->wwid = wwid;
6402 _scsih_raid_device_add(ioc, raid_device);
6403 if (!ioc->wait_for_discovery_to_complete) {
6404 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6405 raid_device->id, 0);
6407 _scsih_raid_device_remove(ioc, raid_device);
6409 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6410 _scsih_determine_boot_device(ioc, raid_device, 1);
6411 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6416 * _scsih_sas_volume_delete - delete volume
6417 * @ioc: per adapter object
6418 * @handle: volume device handle
6424 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6426 struct _raid_device *raid_device;
6427 unsigned long flags;
6428 struct MPT3SAS_TARGET *sas_target_priv_data;
6429 struct scsi_target *starget = NULL;
6431 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6432 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6434 if (raid_device->starget) {
6435 starget = raid_device->starget;
6436 sas_target_priv_data = starget->hostdata;
6437 sas_target_priv_data->deleted = 1;
6439 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6440 ioc->name, raid_device->handle,
6441 (unsigned long long) raid_device->wwid);
6442 list_del(&raid_device->list);
6445 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6447 scsi_remove_target(&starget->dev);
6451 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6452 * @ioc: per adapter object
6453 * @element: IR config element data
6459 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6460 Mpi2EventIrConfigElement_t *element)
6462 struct _sas_device *sas_device;
6463 struct scsi_target *starget = NULL;
6464 struct MPT3SAS_TARGET *sas_target_priv_data;
6465 unsigned long flags;
6466 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6468 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6469 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6471 sas_device->volume_handle = 0;
6472 sas_device->volume_wwid = 0;
6473 clear_bit(handle, ioc->pd_handles);
6474 if (sas_device->starget && sas_device->starget->hostdata) {
6475 starget = sas_device->starget;
6476 sas_target_priv_data = starget->hostdata;
6477 sas_target_priv_data->flags &=
6478 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6481 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6485 /* exposing raid component */
6487 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6489 sas_device_put(sas_device);
6493 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6494 * @ioc: per adapter object
6495 * @element: IR config element data
6501 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6502 Mpi2EventIrConfigElement_t *element)
6504 struct _sas_device *sas_device;
6505 struct scsi_target *starget = NULL;
6506 struct MPT3SAS_TARGET *sas_target_priv_data;
6507 unsigned long flags;
6508 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6509 u16 volume_handle = 0;
6510 u64 volume_wwid = 0;
6512 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6514 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6517 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6518 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6520 set_bit(handle, ioc->pd_handles);
6521 if (sas_device->starget && sas_device->starget->hostdata) {
6522 starget = sas_device->starget;
6523 sas_target_priv_data = starget->hostdata;
6524 sas_target_priv_data->flags |=
6525 MPT_TARGET_FLAGS_RAID_COMPONENT;
6526 sas_device->volume_handle = volume_handle;
6527 sas_device->volume_wwid = volume_wwid;
6530 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6534 /* hiding raid component */
6535 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6538 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6540 sas_device_put(sas_device);
6544 * _scsih_sas_pd_delete - delete pd component
6545 * @ioc: per adapter object
6546 * @element: IR config element data
6552 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6553 Mpi2EventIrConfigElement_t *element)
6555 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6557 _scsih_device_remove_by_handle(ioc, handle);
6561 * _scsih_sas_pd_add - remove pd component
6562 * @ioc: per adapter object
6563 * @element: IR config element data
6569 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6570 Mpi2EventIrConfigElement_t *element)
6572 struct _sas_device *sas_device;
6573 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6574 Mpi2ConfigReply_t mpi_reply;
6575 Mpi2SasDevicePage0_t sas_device_pg0;
6580 set_bit(handle, ioc->pd_handles);
6582 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6584 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6585 sas_device_put(sas_device);
6589 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6590 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6591 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6592 ioc->name, __FILE__, __LINE__, __func__);
6596 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6597 MPI2_IOCSTATUS_MASK;
6598 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6599 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6600 ioc->name, __FILE__, __LINE__, __func__);
6604 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6605 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6606 mpt3sas_transport_update_links(ioc, sas_address, handle,
6607 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6609 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6610 _scsih_add_device(ioc, handle, 0, 1);
6614 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6615 * @ioc: per adapter object
6616 * @event_data: event data payload
6622 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6623 Mpi2EventDataIrConfigChangeList_t *event_data)
6625 Mpi2EventIrConfigElement_t *element;
6628 char *reason_str = NULL, *element_str = NULL;
6630 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6632 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6633 ioc->name, (le32_to_cpu(event_data->Flags) &
6634 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6635 "foreign" : "native", event_data->NumElements);
6636 for (i = 0; i < event_data->NumElements; i++, element++) {
6637 switch (element->ReasonCode) {
6638 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6641 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6642 reason_str = "remove";
6644 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6645 reason_str = "no change";
6647 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6648 reason_str = "hide";
6650 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6651 reason_str = "unhide";
6653 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6654 reason_str = "volume_created";
6656 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6657 reason_str = "volume_deleted";
6659 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6660 reason_str = "pd_created";
6662 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6663 reason_str = "pd_deleted";
6666 reason_str = "unknown reason";
6669 element_type = le16_to_cpu(element->ElementFlags) &
6670 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6671 switch (element_type) {
6672 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6673 element_str = "volume";
6675 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6676 element_str = "phys disk";
6678 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6679 element_str = "hot spare";
6682 element_str = "unknown element";
6685 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6686 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6687 reason_str, le16_to_cpu(element->VolDevHandle),
6688 le16_to_cpu(element->PhysDiskDevHandle),
6689 element->PhysDiskNum);
6694 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6695 * @ioc: per adapter object
6696 * @fw_event: The fw_event_work object
6702 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6703 struct fw_event_work *fw_event)
6705 Mpi2EventIrConfigElement_t *element;
6708 Mpi2EventDataIrConfigChangeList_t *event_data =
6709 (Mpi2EventDataIrConfigChangeList_t *)
6710 fw_event->event_data;
6712 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6713 (!ioc->hide_ir_msg))
6714 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6716 foreign_config = (le32_to_cpu(event_data->Flags) &
6717 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6719 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6720 if (ioc->shost_recovery &&
6721 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6722 for (i = 0; i < event_data->NumElements; i++, element++) {
6723 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6724 _scsih_ir_fastpath(ioc,
6725 le16_to_cpu(element->PhysDiskDevHandle),
6726 element->PhysDiskNum);
6731 for (i = 0; i < event_data->NumElements; i++, element++) {
6733 switch (element->ReasonCode) {
6734 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6735 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6736 if (!foreign_config)
6737 _scsih_sas_volume_add(ioc, element);
6739 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6740 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6741 if (!foreign_config)
6742 _scsih_sas_volume_delete(ioc,
6743 le16_to_cpu(element->VolDevHandle));
6745 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6746 if (!ioc->is_warpdrive)
6747 _scsih_sas_pd_hide(ioc, element);
6749 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6750 if (!ioc->is_warpdrive)
6751 _scsih_sas_pd_expose(ioc, element);
6753 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6754 if (!ioc->is_warpdrive)
6755 _scsih_sas_pd_add(ioc, element);
6757 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6758 if (!ioc->is_warpdrive)
6759 _scsih_sas_pd_delete(ioc, element);
6766 * _scsih_sas_ir_volume_event - IR volume event
6767 * @ioc: per adapter object
6768 * @fw_event: The fw_event_work object
6774 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6775 struct fw_event_work *fw_event)
6778 unsigned long flags;
6779 struct _raid_device *raid_device;
6783 Mpi2EventDataIrVolume_t *event_data =
6784 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6786 if (ioc->shost_recovery)
6789 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6792 handle = le16_to_cpu(event_data->VolDevHandle);
6793 state = le32_to_cpu(event_data->NewValue);
6794 if (!ioc->hide_ir_msg)
6795 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6796 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6797 ioc->name, __func__, handle,
6798 le32_to_cpu(event_data->PreviousValue), state));
6800 case MPI2_RAID_VOL_STATE_MISSING:
6801 case MPI2_RAID_VOL_STATE_FAILED:
6802 _scsih_sas_volume_delete(ioc, handle);
6805 case MPI2_RAID_VOL_STATE_ONLINE:
6806 case MPI2_RAID_VOL_STATE_DEGRADED:
6807 case MPI2_RAID_VOL_STATE_OPTIMAL:
6809 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6810 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6811 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6816 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6819 "failure at %s:%d/%s()!\n", ioc->name,
6820 __FILE__, __LINE__, __func__);
6824 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6827 "failure at %s:%d/%s()!\n", ioc->name,
6828 __FILE__, __LINE__, __func__);
6832 raid_device->id = ioc->sas_id++;
6833 raid_device->channel = RAID_CHANNEL;
6834 raid_device->handle = handle;
6835 raid_device->wwid = wwid;
6836 _scsih_raid_device_add(ioc, raid_device);
6837 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6838 raid_device->id, 0);
6840 _scsih_raid_device_remove(ioc, raid_device);
6843 case MPI2_RAID_VOL_STATE_INITIALIZING:
6850 * _scsih_sas_ir_physical_disk_event - PD event
6851 * @ioc: per adapter object
6852 * @fw_event: The fw_event_work object
6858 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6859 struct fw_event_work *fw_event)
6861 u16 handle, parent_handle;
6863 struct _sas_device *sas_device;
6864 Mpi2ConfigReply_t mpi_reply;
6865 Mpi2SasDevicePage0_t sas_device_pg0;
6867 Mpi2EventDataIrPhysicalDisk_t *event_data =
6868 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6871 if (ioc->shost_recovery)
6874 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6877 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6878 state = le32_to_cpu(event_data->NewValue);
6880 if (!ioc->hide_ir_msg)
6881 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6882 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6883 ioc->name, __func__, handle,
6884 le32_to_cpu(event_data->PreviousValue), state));
6887 case MPI2_RAID_PD_STATE_ONLINE:
6888 case MPI2_RAID_PD_STATE_DEGRADED:
6889 case MPI2_RAID_PD_STATE_REBUILDING:
6890 case MPI2_RAID_PD_STATE_OPTIMAL:
6891 case MPI2_RAID_PD_STATE_HOT_SPARE:
6893 if (!ioc->is_warpdrive)
6894 set_bit(handle, ioc->pd_handles);
6896 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6898 sas_device_put(sas_device);
6902 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6903 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6905 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6906 ioc->name, __FILE__, __LINE__, __func__);
6910 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6911 MPI2_IOCSTATUS_MASK;
6912 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6913 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6914 ioc->name, __FILE__, __LINE__, __func__);
6918 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6919 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6920 mpt3sas_transport_update_links(ioc, sas_address, handle,
6921 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6923 _scsih_add_device(ioc, handle, 0, 1);
6927 case MPI2_RAID_PD_STATE_OFFLINE:
6928 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6929 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6936 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6937 * @ioc: per adapter object
6938 * @event_data: event data payload
6944 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6945 Mpi2EventDataIrOperationStatus_t *event_data)
6947 char *reason_str = NULL;
6949 switch (event_data->RAIDOperation) {
6950 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6951 reason_str = "resync";
6953 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6954 reason_str = "online capacity expansion";
6956 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6957 reason_str = "consistency check";
6959 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6960 reason_str = "background init";
6962 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6963 reason_str = "make data consistent";
6970 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6971 "\thandle(0x%04x), percent complete(%d)\n",
6972 ioc->name, reason_str,
6973 le16_to_cpu(event_data->VolDevHandle),
6974 event_data->PercentComplete);
6978 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6979 * @ioc: per adapter object
6980 * @fw_event: The fw_event_work object
6986 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6987 struct fw_event_work *fw_event)
6989 Mpi2EventDataIrOperationStatus_t *event_data =
6990 (Mpi2EventDataIrOperationStatus_t *)
6991 fw_event->event_data;
6992 static struct _raid_device *raid_device;
6993 unsigned long flags;
6996 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6997 (!ioc->hide_ir_msg))
6998 _scsih_sas_ir_operation_status_event_debug(ioc,
7001 /* code added for raid transport support */
7002 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
7004 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7005 handle = le16_to_cpu(event_data->VolDevHandle);
7006 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
7008 raid_device->percent_complete =
7009 event_data->PercentComplete;
7010 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7015 * _scsih_prep_device_scan - initialize parameters prior to device scan
7016 * @ioc: per adapter object
7018 * Set the deleted flag prior to device scan. If the device is found during
7019 * the scan, then we clear the deleted flag.
7022 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
7024 struct MPT3SAS_DEVICE *sas_device_priv_data;
7025 struct scsi_device *sdev;
7027 shost_for_each_device(sdev, ioc->shost) {
7028 sas_device_priv_data = sdev->hostdata;
7029 if (sas_device_priv_data && sas_device_priv_data->sas_target)
7030 sas_device_priv_data->sas_target->deleted = 1;
7035 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
7036 * @ioc: per adapter object
7037 * @sas_device_pg0: SAS Device page 0
7039 * After host reset, find out whether devices are still responding.
7040 * Used in _scsih_remove_unresponsive_sas_devices.
7045 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
7046 Mpi2SasDevicePage0_t *sas_device_pg0)
7048 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7049 struct scsi_target *starget;
7050 struct _sas_device *sas_device;
7051 unsigned long flags;
7053 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7054 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
7055 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
7056 (sas_device->slot == sas_device_pg0->Slot)) {
7057 sas_device->responding = 1;
7058 starget = sas_device->starget;
7059 if (starget && starget->hostdata) {
7060 sas_target_priv_data = starget->hostdata;
7061 sas_target_priv_data->tm_busy = 0;
7062 sas_target_priv_data->deleted = 0;
7064 sas_target_priv_data = NULL;
7066 starget_printk(KERN_INFO, starget,
7067 "handle(0x%04x), sas_addr(0x%016llx)\n",
7068 sas_device_pg0->DevHandle,
7069 (unsigned long long)
7070 sas_device->sas_address);
7072 if (sas_device->enclosure_handle != 0)
7073 starget_printk(KERN_INFO, starget,
7074 "enclosure logical id(0x%016llx),"
7076 (unsigned long long)
7077 sas_device->enclosure_logical_id,
7080 if (sas_device_pg0->Flags &
7081 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
7082 sas_device->enclosure_level =
7083 sas_device_pg0->EnclosureLevel;
7084 memcpy(&sas_device->connector_name[0],
7085 &sas_device_pg0->ConnectorName[0], 4);
7087 sas_device->enclosure_level = 0;
7088 sas_device->connector_name[0] = '\0';
7091 if (sas_device->handle == sas_device_pg0->DevHandle)
7093 pr_info("\thandle changed from(0x%04x)!!!\n",
7094 sas_device->handle);
7095 sas_device->handle = sas_device_pg0->DevHandle;
7096 if (sas_target_priv_data)
7097 sas_target_priv_data->handle =
7098 sas_device_pg0->DevHandle;
7103 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7107 * _scsih_search_responding_sas_devices -
7108 * @ioc: per adapter object
7110 * After host reset, find out whether devices are still responding.
7116 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7118 Mpi2SasDevicePage0_t sas_device_pg0;
7119 Mpi2ConfigReply_t mpi_reply;
7124 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
7126 if (list_empty(&ioc->sas_device_list))
7130 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7131 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7133 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7134 MPI2_IOCSTATUS_MASK;
7135 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7137 handle = sas_device_pg0.DevHandle =
7138 le16_to_cpu(sas_device_pg0.DevHandle);
7139 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
7140 if (!(_scsih_is_end_device(device_info)))
7142 sas_device_pg0.SASAddress =
7143 le64_to_cpu(sas_device_pg0.SASAddress);
7144 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
7145 sas_device_pg0.Flags = le16_to_cpu(sas_device_pg0.Flags);
7146 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
7150 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
7155 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7156 * @ioc: per adapter object
7157 * @wwid: world wide identifier for raid volume
7158 * @handle: device handle
7160 * After host reset, find out whether devices are still responding.
7161 * Used in _scsih_remove_unresponsive_raid_devices.
7166 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
7169 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7170 struct scsi_target *starget;
7171 struct _raid_device *raid_device;
7172 unsigned long flags;
7174 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7175 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
7176 if (raid_device->wwid == wwid && raid_device->starget) {
7177 starget = raid_device->starget;
7178 if (starget && starget->hostdata) {
7179 sas_target_priv_data = starget->hostdata;
7180 sas_target_priv_data->deleted = 0;
7182 sas_target_priv_data = NULL;
7183 raid_device->responding = 1;
7184 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7185 starget_printk(KERN_INFO, raid_device->starget,
7186 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7187 (unsigned long long)raid_device->wwid);
7190 * WARPDRIVE: The handles of the PDs might have changed
7191 * across the host reset so re-initialize the
7192 * required data for Direct IO
7194 mpt3sas_init_warpdrive_properties(ioc, raid_device);
7195 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7196 if (raid_device->handle == handle) {
7197 spin_unlock_irqrestore(&ioc->raid_device_lock,
7201 pr_info("\thandle changed from(0x%04x)!!!\n",
7202 raid_device->handle);
7203 raid_device->handle = handle;
7204 if (sas_target_priv_data)
7205 sas_target_priv_data->handle = handle;
7206 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7210 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7214 * _scsih_search_responding_raid_devices -
7215 * @ioc: per adapter object
7217 * After host reset, find out whether devices are still responding.
7223 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
7225 Mpi2RaidVolPage1_t volume_pg1;
7226 Mpi2RaidVolPage0_t volume_pg0;
7227 Mpi2RaidPhysDiskPage0_t pd_pg0;
7228 Mpi2ConfigReply_t mpi_reply;
7233 if (!ioc->ir_firmware)
7236 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7239 if (list_empty(&ioc->raid_device_list))
7243 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7244 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7245 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7246 MPI2_IOCSTATUS_MASK;
7247 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7249 handle = le16_to_cpu(volume_pg1.DevHandle);
7251 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7252 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7253 sizeof(Mpi2RaidVolPage0_t)))
7256 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7257 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7258 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7259 _scsih_mark_responding_raid_device(ioc,
7260 le64_to_cpu(volume_pg1.WWID), handle);
7263 /* refresh the pd_handles */
7264 if (!ioc->is_warpdrive) {
7265 phys_disk_num = 0xFF;
7266 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7267 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7268 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7270 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7271 MPI2_IOCSTATUS_MASK;
7272 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7274 phys_disk_num = pd_pg0.PhysDiskNum;
7275 handle = le16_to_cpu(pd_pg0.DevHandle);
7276 set_bit(handle, ioc->pd_handles);
7280 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7285 * _scsih_mark_responding_expander - mark a expander as responding
7286 * @ioc: per adapter object
7287 * @sas_address: sas address
7290 * After host reset, find out whether devices are still responding.
7291 * Used in _scsih_remove_unresponsive_expanders.
7296 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7299 struct _sas_node *sas_expander;
7300 unsigned long flags;
7303 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7304 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7305 if (sas_expander->sas_address != sas_address)
7307 sas_expander->responding = 1;
7308 if (sas_expander->handle == handle)
7310 pr_info("\texpander(0x%016llx): handle changed" \
7311 " from(0x%04x) to (0x%04x)!!!\n",
7312 (unsigned long long)sas_expander->sas_address,
7313 sas_expander->handle, handle);
7314 sas_expander->handle = handle;
7315 for (i = 0 ; i < sas_expander->num_phys ; i++)
7316 sas_expander->phy[i].handle = handle;
7320 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7324 * _scsih_search_responding_expanders -
7325 * @ioc: per adapter object
7327 * After host reset, find out whether devices are still responding.
7333 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7335 Mpi2ExpanderPage0_t expander_pg0;
7336 Mpi2ConfigReply_t mpi_reply;
7341 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7343 if (list_empty(&ioc->sas_expander_list))
7347 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7348 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7350 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7351 MPI2_IOCSTATUS_MASK;
7352 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7355 handle = le16_to_cpu(expander_pg0.DevHandle);
7356 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7357 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7359 (unsigned long long)sas_address);
7360 _scsih_mark_responding_expander(ioc, sas_address, handle);
7364 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7368 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7369 * @ioc: per adapter object
7374 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7376 struct _sas_device *sas_device, *sas_device_next;
7377 struct _sas_node *sas_expander, *sas_expander_next;
7378 struct _raid_device *raid_device, *raid_device_next;
7379 struct list_head tmp_list;
7380 unsigned long flags;
7383 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7386 /* removing unresponding end devices */
7387 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7390 * Iterate, pulling off devices marked as non-responding. We become the
7391 * owner for the reference the list had on any object we prune.
7393 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7394 list_for_each_entry_safe(sas_device, sas_device_next,
7395 &ioc->sas_device_list, list) {
7396 if (!sas_device->responding)
7397 list_move_tail(&sas_device->list, &head);
7399 sas_device->responding = 0;
7401 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7404 * Now, uninitialize and remove the unresponding devices we pruned.
7406 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7407 _scsih_remove_device(ioc, sas_device);
7408 list_del_init(&sas_device->list);
7409 sas_device_put(sas_device);
7412 /* removing unresponding volumes */
7413 if (ioc->ir_firmware) {
7414 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7416 list_for_each_entry_safe(raid_device, raid_device_next,
7417 &ioc->raid_device_list, list) {
7418 if (!raid_device->responding)
7419 _scsih_sas_volume_delete(ioc,
7420 raid_device->handle);
7422 raid_device->responding = 0;
7426 /* removing unresponding expanders */
7427 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7429 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7430 INIT_LIST_HEAD(&tmp_list);
7431 list_for_each_entry_safe(sas_expander, sas_expander_next,
7432 &ioc->sas_expander_list, list) {
7433 if (!sas_expander->responding)
7434 list_move_tail(&sas_expander->list, &tmp_list);
7436 sas_expander->responding = 0;
7438 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7439 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7441 list_del(&sas_expander->list);
7442 _scsih_expander_node_remove(ioc, sas_expander);
7445 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7448 /* unblock devices */
7449 _scsih_ublock_io_all_device(ioc);
7453 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7454 struct _sas_node *sas_expander, u16 handle)
7456 Mpi2ExpanderPage1_t expander_pg1;
7457 Mpi2ConfigReply_t mpi_reply;
7460 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7461 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7462 &expander_pg1, i, handle))) {
7463 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7464 ioc->name, __FILE__, __LINE__, __func__);
7468 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7469 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7470 expander_pg1.NegotiatedLinkRate >> 4);
7475 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7476 * @ioc: per adapter object
7481 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7483 Mpi2ExpanderPage0_t expander_pg0;
7484 Mpi2SasDevicePage0_t sas_device_pg0;
7485 Mpi2RaidVolPage1_t volume_pg1;
7486 Mpi2RaidVolPage0_t volume_pg0;
7487 Mpi2RaidPhysDiskPage0_t pd_pg0;
7488 Mpi2EventIrConfigElement_t element;
7489 Mpi2ConfigReply_t mpi_reply;
7492 u16 handle, parent_handle;
7494 struct _sas_device *sas_device;
7495 struct _sas_node *expander_device;
7496 static struct _raid_device *raid_device;
7498 unsigned long flags;
7500 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7502 _scsih_sas_host_refresh(ioc);
7504 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7508 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7509 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7510 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7511 MPI2_IOCSTATUS_MASK;
7512 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7513 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7514 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7515 ioc->name, ioc_status,
7516 le32_to_cpu(mpi_reply.IOCLogInfo));
7519 handle = le16_to_cpu(expander_pg0.DevHandle);
7520 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7521 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7522 ioc, le64_to_cpu(expander_pg0.SASAddress));
7523 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7524 if (expander_device)
7525 _scsih_refresh_expander_links(ioc, expander_device,
7528 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7529 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7530 handle, (unsigned long long)
7531 le64_to_cpu(expander_pg0.SASAddress));
7532 _scsih_expander_add(ioc, handle);
7533 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7534 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7535 handle, (unsigned long long)
7536 le64_to_cpu(expander_pg0.SASAddress));
7540 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7543 if (!ioc->ir_firmware)
7546 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7549 phys_disk_num = 0xFF;
7550 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7551 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7553 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7554 MPI2_IOCSTATUS_MASK;
7555 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7556 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7557 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7558 ioc->name, ioc_status,
7559 le32_to_cpu(mpi_reply.IOCLogInfo));
7562 phys_disk_num = pd_pg0.PhysDiskNum;
7563 handle = le16_to_cpu(pd_pg0.DevHandle);
7564 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7566 sas_device_put(sas_device);
7569 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7570 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7573 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7574 MPI2_IOCSTATUS_MASK;
7575 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7576 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7577 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7578 ioc->name, ioc_status,
7579 le32_to_cpu(mpi_reply.IOCLogInfo));
7582 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7583 if (!_scsih_get_sas_address(ioc, parent_handle,
7585 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7586 " handle (0x%04x), sas_addr(0x%016llx)\n",
7587 ioc->name, handle, (unsigned long long)
7588 le64_to_cpu(sas_device_pg0.SASAddress));
7589 mpt3sas_transport_update_links(ioc, sas_address,
7590 handle, sas_device_pg0.PhyNum,
7591 MPI2_SAS_NEG_LINK_RATE_1_5);
7592 set_bit(handle, ioc->pd_handles);
7594 /* This will retry adding the end device.
7595 * _scsih_add_device() will decide on retries and
7596 * return "1" when it should be retried
7598 while (_scsih_add_device(ioc, handle, retry_count++,
7602 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7603 " handle (0x%04x), sas_addr(0x%016llx)\n",
7604 ioc->name, handle, (unsigned long long)
7605 le64_to_cpu(sas_device_pg0.SASAddress));
7609 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7612 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7616 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7617 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7618 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7619 MPI2_IOCSTATUS_MASK;
7620 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7621 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7622 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7623 ioc->name, ioc_status,
7624 le32_to_cpu(mpi_reply.IOCLogInfo));
7627 handle = le16_to_cpu(volume_pg1.DevHandle);
7628 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7629 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7630 le64_to_cpu(volume_pg1.WWID));
7631 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7634 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7635 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7636 sizeof(Mpi2RaidVolPage0_t)))
7638 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7639 MPI2_IOCSTATUS_MASK;
7640 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7641 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7642 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7643 ioc->name, ioc_status,
7644 le32_to_cpu(mpi_reply.IOCLogInfo));
7647 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7648 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7649 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7650 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7651 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7652 element.VolDevHandle = volume_pg1.DevHandle;
7654 "\tBEFORE adding volume: handle (0x%04x)\n",
7655 ioc->name, volume_pg1.DevHandle);
7656 _scsih_sas_volume_add(ioc, &element);
7658 "\tAFTER adding volume: handle (0x%04x)\n",
7659 ioc->name, volume_pg1.DevHandle);
7663 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7668 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7673 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7674 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7676 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7677 MPI2_IOCSTATUS_MASK;
7678 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7679 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7680 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7681 ioc->name, ioc_status,
7682 le32_to_cpu(mpi_reply.IOCLogInfo));
7685 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7686 if (!(_scsih_is_end_device(
7687 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7689 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7690 le64_to_cpu(sas_device_pg0.SASAddress));
7692 sas_device_put(sas_device);
7695 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7696 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7697 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7698 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7699 handle, (unsigned long long)
7700 le64_to_cpu(sas_device_pg0.SASAddress));
7701 mpt3sas_transport_update_links(ioc, sas_address, handle,
7702 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7704 /* This will retry adding the end device.
7705 * _scsih_add_device() will decide on retries and
7706 * return "1" when it should be retried
7708 while (_scsih_add_device(ioc, handle, retry_count++,
7712 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7713 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7714 handle, (unsigned long long)
7715 le64_to_cpu(sas_device_pg0.SASAddress));
7718 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7721 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7724 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7725 * @ioc: per adapter object
7726 * @reset_phase: phase
7728 * The handler for doing any required cleanup or initialization.
7730 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7731 * MPT3_IOC_DONE_RESET
7736 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7738 switch (reset_phase) {
7739 case MPT3_IOC_PRE_RESET:
7740 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7741 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7743 case MPT3_IOC_AFTER_RESET:
7744 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7745 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7746 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7747 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7748 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7749 complete(&ioc->scsih_cmds.done);
7751 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7752 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7753 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7754 complete(&ioc->tm_cmds.done);
7757 memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
7758 memset(ioc->device_remove_in_progress, 0,
7759 ioc->device_remove_in_progress_sz);
7760 _scsih_fw_event_cleanup_queue(ioc);
7761 _scsih_flush_running_cmds(ioc);
7763 case MPT3_IOC_DONE_RESET:
7764 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7765 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7766 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7767 !ioc->sas_hba.num_phys)) {
7768 _scsih_prep_device_scan(ioc);
7769 _scsih_search_responding_sas_devices(ioc);
7770 _scsih_search_responding_raid_devices(ioc);
7771 _scsih_search_responding_expanders(ioc);
7772 _scsih_error_recovery_delete_devices(ioc);
7779 * _mpt3sas_fw_work - delayed task for processing firmware events
7780 * @ioc: per adapter object
7781 * @fw_event: The fw_event_work object
7787 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7789 _scsih_fw_event_del_from_list(ioc, fw_event);
7791 /* the queue is being flushed so ignore this event */
7792 if (ioc->remove_host || ioc->pci_error_recovery) {
7793 fw_event_work_put(fw_event);
7797 switch (fw_event->event) {
7798 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7799 mpt3sas_process_trigger_data(ioc,
7800 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7801 fw_event->event_data);
7803 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7804 while (scsi_host_in_recovery(ioc->shost) ||
7805 ioc->shost_recovery) {
7807 * If we're unloading, bail. Otherwise, this can become
7810 if (ioc->remove_host)
7814 _scsih_remove_unresponding_sas_devices(ioc);
7815 _scsih_scan_for_devices_after_reset(ioc);
7817 case MPT3SAS_PORT_ENABLE_COMPLETE:
7818 ioc->start_scan = 0;
7819 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7820 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7822 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7823 "port enable: complete from worker thread\n",
7826 case MPT3SAS_TURN_ON_PFA_LED:
7827 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7829 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7830 _scsih_sas_topology_change_event(ioc, fw_event);
7832 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7833 _scsih_sas_device_status_change_event(ioc, fw_event);
7835 case MPI2_EVENT_SAS_DISCOVERY:
7836 _scsih_sas_discovery_event(ioc, fw_event);
7838 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7839 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7841 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7842 _scsih_sas_enclosure_dev_status_change_event(ioc,
7845 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7846 _scsih_sas_ir_config_change_event(ioc, fw_event);
7848 case MPI2_EVENT_IR_VOLUME:
7849 _scsih_sas_ir_volume_event(ioc, fw_event);
7851 case MPI2_EVENT_IR_PHYSICAL_DISK:
7852 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7854 case MPI2_EVENT_IR_OPERATION_STATUS:
7855 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7859 fw_event_work_put(fw_event);
7863 * _firmware_event_work
7864 * @ioc: per adapter object
7865 * @work: The fw_event_work object
7868 * wrappers for the work thread handling firmware events
7874 _firmware_event_work(struct work_struct *work)
7876 struct fw_event_work *fw_event = container_of(work,
7877 struct fw_event_work, work);
7879 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7883 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7884 * @ioc: per adapter object
7885 * @msix_index: MSIX table index supplied by the OS
7886 * @reply: reply message frame(lower 32bit addr)
7887 * Context: interrupt.
7889 * This function merely adds a new work task into ioc->firmware_event_thread.
7890 * The tasks are worked from _firmware_event_work in user context.
7892 * Return 1 meaning mf should be freed from _base_interrupt
7893 * 0 means the mf is freed from this function.
7896 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7899 struct fw_event_work *fw_event;
7900 Mpi2EventNotificationReply_t *mpi_reply;
7903 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
7905 /* events turned off due to host reset or driver unloading */
7906 if (ioc->remove_host || ioc->pci_error_recovery)
7909 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7911 if (unlikely(!mpi_reply)) {
7912 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7913 ioc->name, __FILE__, __LINE__, __func__);
7917 event = le16_to_cpu(mpi_reply->Event);
7919 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7920 mpt3sas_trigger_event(ioc, event, 0);
7924 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7926 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7927 (Mpi2EventDataSasBroadcastPrimitive_t *)
7928 mpi_reply->EventData;
7930 if (baen_data->Primitive !=
7931 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7934 if (ioc->broadcast_aen_busy) {
7935 ioc->broadcast_aen_pending++;
7938 ioc->broadcast_aen_busy = 1;
7942 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7943 _scsih_check_topo_delete_events(ioc,
7944 (Mpi2EventDataSasTopologyChangeList_t *)
7945 mpi_reply->EventData);
7947 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7948 _scsih_check_ir_config_unhide_events(ioc,
7949 (Mpi2EventDataIrConfigChangeList_t *)
7950 mpi_reply->EventData);
7952 case MPI2_EVENT_IR_VOLUME:
7953 _scsih_check_volume_delete_events(ioc,
7954 (Mpi2EventDataIrVolume_t *)
7955 mpi_reply->EventData);
7957 case MPI2_EVENT_LOG_ENTRY_ADDED:
7959 Mpi2EventDataLogEntryAdded_t *log_entry;
7962 if (!ioc->is_warpdrive)
7965 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7966 mpi_reply->EventData;
7967 log_code = (u32 *)log_entry->LogData;
7969 if (le16_to_cpu(log_entry->LogEntryQualifier)
7970 != MPT2_WARPDRIVE_LOGENTRY)
7973 switch (le32_to_cpu(*log_code)) {
7974 case MPT2_WARPDRIVE_LC_SSDT:
7975 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7976 "IO Throttling has occurred in the WarpDrive "
7977 "subsystem. Check WarpDrive documentation for "
7978 "additional details.\n", ioc->name);
7980 case MPT2_WARPDRIVE_LC_SSDLW:
7981 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7982 "Program/Erase Cycles for the WarpDrive subsystem "
7983 "in degraded range. Check WarpDrive documentation "
7984 "for additional details.\n", ioc->name);
7986 case MPT2_WARPDRIVE_LC_SSDLF:
7987 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7988 "There are no Program/Erase Cycles for the "
7989 "WarpDrive subsystem. The storage device will be "
7990 "in read-only mode. Check WarpDrive documentation "
7991 "for additional details.\n", ioc->name);
7993 case MPT2_WARPDRIVE_LC_BRMF:
7994 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7995 "The Backup Rail Monitor has failed on the "
7996 "WarpDrive subsystem. Check WarpDrive "
7997 "documentation for additional details.\n",
8004 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
8005 case MPI2_EVENT_IR_OPERATION_STATUS:
8006 case MPI2_EVENT_SAS_DISCOVERY:
8007 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
8008 case MPI2_EVENT_IR_PHYSICAL_DISK:
8011 case MPI2_EVENT_TEMP_THRESHOLD:
8012 _scsih_temp_threshold_events(ioc,
8013 (Mpi2EventDataTemperature_t *)
8014 mpi_reply->EventData);
8016 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
8017 ActiveCableEventData =
8018 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
8019 if (ActiveCableEventData->ReasonCode ==
8020 MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER) {
8021 pr_info(MPT3SAS_FMT "Currently an active cable with ReceptacleID %d",
8022 ioc->name, ActiveCableEventData->ReceptacleID);
8023 pr_info("cannot be powered and devices connected to this active cable");
8024 pr_info("will not be seen. This active cable");
8025 pr_info("requires %d mW of power",
8026 ActiveCableEventData->ActiveCablePowerRequirement);
8030 default: /* ignore the rest */
8034 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
8035 fw_event = alloc_fw_event_work(sz);
8037 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8038 ioc->name, __FILE__, __LINE__, __func__);
8042 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
8043 fw_event->ioc = ioc;
8044 fw_event->VF_ID = mpi_reply->VF_ID;
8045 fw_event->VP_ID = mpi_reply->VP_ID;
8046 fw_event->event = event;
8047 _scsih_fw_event_add(ioc, fw_event);
8048 fw_event_work_put(fw_event);
8053 * _scsih_expander_node_remove - removing expander device from list.
8054 * @ioc: per adapter object
8055 * @sas_expander: the sas_device object
8056 * Context: Calling function should acquire ioc->sas_node_lock.
8058 * Removing object and freeing associated memory from the
8059 * ioc->sas_expander_list.
8064 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
8065 struct _sas_node *sas_expander)
8067 struct _sas_port *mpt3sas_port, *next;
8069 /* remove sibling ports attached to this expander */
8070 list_for_each_entry_safe(mpt3sas_port, next,
8071 &sas_expander->sas_port_list, port_list) {
8072 if (ioc->shost_recovery)
8074 if (mpt3sas_port->remote_identify.device_type ==
8076 mpt3sas_device_remove_by_sas_address(ioc,
8077 mpt3sas_port->remote_identify.sas_address);
8078 else if (mpt3sas_port->remote_identify.device_type ==
8079 SAS_EDGE_EXPANDER_DEVICE ||
8080 mpt3sas_port->remote_identify.device_type ==
8081 SAS_FANOUT_EXPANDER_DEVICE)
8082 mpt3sas_expander_remove(ioc,
8083 mpt3sas_port->remote_identify.sas_address);
8086 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
8087 sas_expander->sas_address_parent);
8090 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8092 sas_expander->handle, (unsigned long long)
8093 sas_expander->sas_address);
8095 kfree(sas_expander->phy);
8096 kfree(sas_expander);
8100 * _scsih_ir_shutdown - IR shutdown notification
8101 * @ioc: per adapter object
8103 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8104 * the host system is shutting down.
8109 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
8111 Mpi2RaidActionRequest_t *mpi_request;
8112 Mpi2RaidActionReply_t *mpi_reply;
8115 /* is IR firmware build loaded ? */
8116 if (!ioc->ir_firmware)
8119 /* are there any volumes ? */
8120 if (list_empty(&ioc->raid_device_list))
8123 mutex_lock(&ioc->scsih_cmds.mutex);
8125 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
8126 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
8127 ioc->name, __func__);
8130 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
8132 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
8134 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
8135 ioc->name, __func__);
8136 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8140 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
8141 ioc->scsih_cmds.smid = smid;
8142 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
8144 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
8145 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
8147 if (!ioc->hide_ir_msg)
8148 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
8149 init_completion(&ioc->scsih_cmds.done);
8150 ioc->put_smid_default(ioc, smid);
8151 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
8153 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
8154 pr_err(MPT3SAS_FMT "%s: timeout\n",
8155 ioc->name, __func__);
8159 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
8160 mpi_reply = ioc->scsih_cmds.reply;
8161 if (!ioc->hide_ir_msg)
8162 pr_info(MPT3SAS_FMT "IR shutdown "
8163 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8164 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
8165 le32_to_cpu(mpi_reply->IOCLogInfo));
8169 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8170 mutex_unlock(&ioc->scsih_cmds.mutex);
8174 * scsih_remove - detach and remove add host
8175 * @pdev: PCI device struct
8177 * Routine called when unloading the driver.
8180 static void scsih_remove(struct pci_dev *pdev)
8182 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8183 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8184 struct _sas_port *mpt3sas_port, *next_port;
8185 struct _raid_device *raid_device, *next;
8186 struct MPT3SAS_TARGET *sas_target_priv_data;
8187 struct workqueue_struct *wq;
8188 unsigned long flags;
8190 ioc->remove_host = 1;
8191 _scsih_fw_event_cleanup_queue(ioc);
8193 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8194 wq = ioc->firmware_event_thread;
8195 ioc->firmware_event_thread = NULL;
8196 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8198 destroy_workqueue(wq);
8200 /* release all the volumes */
8201 _scsih_ir_shutdown(ioc);
8202 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8204 if (raid_device->starget) {
8205 sas_target_priv_data =
8206 raid_device->starget->hostdata;
8207 sas_target_priv_data->deleted = 1;
8208 scsi_remove_target(&raid_device->starget->dev);
8210 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
8211 ioc->name, raid_device->handle,
8212 (unsigned long long) raid_device->wwid);
8213 _scsih_raid_device_remove(ioc, raid_device);
8216 /* free ports attached to the sas_host */
8217 list_for_each_entry_safe(mpt3sas_port, next_port,
8218 &ioc->sas_hba.sas_port_list, port_list) {
8219 if (mpt3sas_port->remote_identify.device_type ==
8221 mpt3sas_device_remove_by_sas_address(ioc,
8222 mpt3sas_port->remote_identify.sas_address);
8223 else if (mpt3sas_port->remote_identify.device_type ==
8224 SAS_EDGE_EXPANDER_DEVICE ||
8225 mpt3sas_port->remote_identify.device_type ==
8226 SAS_FANOUT_EXPANDER_DEVICE)
8227 mpt3sas_expander_remove(ioc,
8228 mpt3sas_port->remote_identify.sas_address);
8231 /* free phys attached to the sas_host */
8232 if (ioc->sas_hba.num_phys) {
8233 kfree(ioc->sas_hba.phy);
8234 ioc->sas_hba.phy = NULL;
8235 ioc->sas_hba.num_phys = 0;
8238 sas_remove_host(shost);
8239 scsi_remove_host(shost);
8240 mpt3sas_base_detach(ioc);
8241 spin_lock(&gioc_lock);
8242 list_del(&ioc->list);
8243 spin_unlock(&gioc_lock);
8244 scsi_host_put(shost);
8248 * scsih_shutdown - routine call during system shutdown
8249 * @pdev: PCI device struct
8254 scsih_shutdown(struct pci_dev *pdev)
8256 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8257 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8258 struct workqueue_struct *wq;
8259 unsigned long flags;
8261 ioc->remove_host = 1;
8262 _scsih_fw_event_cleanup_queue(ioc);
8264 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8265 wq = ioc->firmware_event_thread;
8266 ioc->firmware_event_thread = NULL;
8267 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8269 destroy_workqueue(wq);
8271 _scsih_ir_shutdown(ioc);
8272 mpt3sas_base_detach(ioc);
8277 * _scsih_probe_boot_devices - reports 1st device
8278 * @ioc: per adapter object
8280 * If specified in bios page 2, this routine reports the 1st
8281 * device scsi-ml or sas transport for persistent boot device
8282 * purposes. Please refer to function _scsih_determine_boot_device()
8285 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8289 struct _sas_device *sas_device;
8290 struct _raid_device *raid_device;
8292 u64 sas_address_parent;
8294 unsigned long flags;
8297 /* no Bios, return immediately */
8298 if (!ioc->bios_pg3.BiosVersion)
8303 if (ioc->req_boot_device.device) {
8304 device = ioc->req_boot_device.device;
8305 is_raid = ioc->req_boot_device.is_raid;
8306 } else if (ioc->req_alt_boot_device.device) {
8307 device = ioc->req_alt_boot_device.device;
8308 is_raid = ioc->req_alt_boot_device.is_raid;
8309 } else if (ioc->current_boot_device.device) {
8310 device = ioc->current_boot_device.device;
8311 is_raid = ioc->current_boot_device.is_raid;
8318 raid_device = device;
8319 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8320 raid_device->id, 0);
8322 _scsih_raid_device_remove(ioc, raid_device);
8324 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8325 sas_device = device;
8326 handle = sas_device->handle;
8327 sas_address_parent = sas_device->sas_address_parent;
8328 sas_address = sas_device->sas_address;
8329 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8330 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8332 if (ioc->hide_drives)
8334 if (!mpt3sas_transport_port_add(ioc, handle,
8335 sas_address_parent)) {
8336 _scsih_sas_device_remove(ioc, sas_device);
8337 } else if (!sas_device->starget) {
8338 if (!ioc->is_driver_loading) {
8339 mpt3sas_transport_port_remove(ioc,
8341 sas_address_parent);
8342 _scsih_sas_device_remove(ioc, sas_device);
8349 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8350 * @ioc: per adapter object
8352 * Called during initial loading of the driver.
8355 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8357 struct _raid_device *raid_device, *raid_next;
8360 list_for_each_entry_safe(raid_device, raid_next,
8361 &ioc->raid_device_list, list) {
8362 if (raid_device->starget)
8364 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8365 raid_device->id, 0);
8367 _scsih_raid_device_remove(ioc, raid_device);
8371 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8373 struct _sas_device *sas_device = NULL;
8374 unsigned long flags;
8376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8377 if (!list_empty(&ioc->sas_device_init_list)) {
8378 sas_device = list_first_entry(&ioc->sas_device_init_list,
8379 struct _sas_device, list);
8380 sas_device_get(sas_device);
8382 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8387 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8388 struct _sas_device *sas_device)
8390 unsigned long flags;
8392 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8395 * Since we dropped the lock during the call to port_add(), we need to
8396 * be careful here that somebody else didn't move or delete this item
8397 * while we were busy with other things.
8399 * If it was on the list, we need a put() for the reference the list
8400 * had. Either way, we need a get() for the destination list.
8402 if (!list_empty(&sas_device->list)) {
8403 list_del_init(&sas_device->list);
8404 sas_device_put(sas_device);
8407 sas_device_get(sas_device);
8408 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8410 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8414 * _scsih_probe_sas - reporting sas devices to sas transport
8415 * @ioc: per adapter object
8417 * Called during initial loading of the driver.
8420 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8422 struct _sas_device *sas_device;
8424 if (ioc->hide_drives)
8427 while ((sas_device = get_next_sas_device(ioc))) {
8428 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8429 sas_device->sas_address_parent)) {
8430 _scsih_sas_device_remove(ioc, sas_device);
8431 sas_device_put(sas_device);
8433 } else if (!sas_device->starget) {
8435 * When asyn scanning is enabled, its not possible to
8436 * remove devices while scanning is turned on due to an
8437 * oops in scsi_sysfs_add_sdev()->add_device()->
8438 * sysfs_addrm_start()
8440 if (!ioc->is_driver_loading) {
8441 mpt3sas_transport_port_remove(ioc,
8442 sas_device->sas_address,
8443 sas_device->sas_address_parent);
8444 _scsih_sas_device_remove(ioc, sas_device);
8445 sas_device_put(sas_device);
8449 sas_device_make_active(ioc, sas_device);
8450 sas_device_put(sas_device);
8455 * _scsih_probe_devices - probing for devices
8456 * @ioc: per adapter object
8458 * Called during initial loading of the driver.
8461 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8463 u16 volume_mapping_flags;
8465 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8466 return; /* return when IOC doesn't support initiator mode */
8468 _scsih_probe_boot_devices(ioc);
8470 if (ioc->ir_firmware) {
8471 volume_mapping_flags =
8472 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8473 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8474 if (volume_mapping_flags ==
8475 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8476 _scsih_probe_raid(ioc);
8477 _scsih_probe_sas(ioc);
8479 _scsih_probe_sas(ioc);
8480 _scsih_probe_raid(ioc);
8483 _scsih_probe_sas(ioc);
8487 * scsih_scan_start - scsi lld callback for .scan_start
8488 * @shost: SCSI host pointer
8490 * The shost has the ability to discover targets on its own instead
8491 * of scanning the entire bus. In our implemention, we will kick off
8492 * firmware discovery.
8495 scsih_scan_start(struct Scsi_Host *shost)
8497 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8499 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8500 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8502 if (disable_discovery > 0)
8505 ioc->start_scan = 1;
8506 rc = mpt3sas_port_enable(ioc);
8509 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8513 * scsih_scan_finished - scsi lld callback for .scan_finished
8514 * @shost: SCSI host pointer
8515 * @time: elapsed time of the scan in jiffies
8517 * This function will be called periodicallyn until it returns 1 with the
8518 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8519 * we wait for firmware discovery to complete, then return 1.
8522 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8524 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8526 if (disable_discovery > 0) {
8527 ioc->is_driver_loading = 0;
8528 ioc->wait_for_discovery_to_complete = 0;
8532 if (time >= (300 * HZ)) {
8533 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8535 "port enable: FAILED with timeout (timeout=300s)\n",
8537 ioc->is_driver_loading = 0;
8541 if (ioc->start_scan)
8544 if (ioc->start_scan_failed) {
8546 "port enable: FAILED with (ioc_status=0x%08x)\n",
8547 ioc->name, ioc->start_scan_failed);
8548 ioc->is_driver_loading = 0;
8549 ioc->wait_for_discovery_to_complete = 0;
8550 ioc->remove_host = 1;
8554 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8555 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8557 if (ioc->wait_for_discovery_to_complete) {
8558 ioc->wait_for_discovery_to_complete = 0;
8559 _scsih_probe_devices(ioc);
8561 mpt3sas_base_start_watchdog(ioc);
8562 ioc->is_driver_loading = 0;
8566 /* shost template for SAS 2.0 HBA devices */
8567 static struct scsi_host_template mpt2sas_driver_template = {
8568 .module = THIS_MODULE,
8569 .name = "Fusion MPT SAS Host",
8570 .proc_name = MPT2SAS_DRIVER_NAME,
8571 .queuecommand = scsih_qcmd,
8572 .target_alloc = scsih_target_alloc,
8573 .slave_alloc = scsih_slave_alloc,
8574 .slave_configure = scsih_slave_configure,
8575 .target_destroy = scsih_target_destroy,
8576 .slave_destroy = scsih_slave_destroy,
8577 .scan_finished = scsih_scan_finished,
8578 .scan_start = scsih_scan_start,
8579 .change_queue_depth = scsih_change_queue_depth,
8580 .eh_abort_handler = scsih_abort,
8581 .eh_device_reset_handler = scsih_dev_reset,
8582 .eh_target_reset_handler = scsih_target_reset,
8583 .eh_host_reset_handler = scsih_host_reset,
8584 .bios_param = scsih_bios_param,
8587 .sg_tablesize = MPT2SAS_SG_DEPTH,
8588 .max_sectors = 32767,
8590 .use_clustering = ENABLE_CLUSTERING,
8591 .shost_attrs = mpt3sas_host_attrs,
8592 .sdev_attrs = mpt3sas_dev_attrs,
8593 .track_queue_depth = 1,
8596 /* raid transport support for SAS 2.0 HBA devices */
8597 static struct raid_function_template mpt2sas_raid_functions = {
8598 .cookie = &mpt2sas_driver_template,
8599 .is_raid = scsih_is_raid,
8600 .get_resync = scsih_get_resync,
8601 .get_state = scsih_get_state,
8604 /* shost template for SAS 3.0 HBA devices */
8605 static struct scsi_host_template mpt3sas_driver_template = {
8606 .module = THIS_MODULE,
8607 .name = "Fusion MPT SAS Host",
8608 .proc_name = MPT3SAS_DRIVER_NAME,
8609 .queuecommand = scsih_qcmd,
8610 .target_alloc = scsih_target_alloc,
8611 .slave_alloc = scsih_slave_alloc,
8612 .slave_configure = scsih_slave_configure,
8613 .target_destroy = scsih_target_destroy,
8614 .slave_destroy = scsih_slave_destroy,
8615 .scan_finished = scsih_scan_finished,
8616 .scan_start = scsih_scan_start,
8617 .change_queue_depth = scsih_change_queue_depth,
8618 .eh_abort_handler = scsih_abort,
8619 .eh_device_reset_handler = scsih_dev_reset,
8620 .eh_target_reset_handler = scsih_target_reset,
8621 .eh_host_reset_handler = scsih_host_reset,
8622 .bios_param = scsih_bios_param,
8625 .sg_tablesize = MPT3SAS_SG_DEPTH,
8626 .max_sectors = 32767,
8628 .use_clustering = ENABLE_CLUSTERING,
8629 .shost_attrs = mpt3sas_host_attrs,
8630 .sdev_attrs = mpt3sas_dev_attrs,
8631 .track_queue_depth = 1,
8634 /* raid transport support for SAS 3.0 HBA devices */
8635 static struct raid_function_template mpt3sas_raid_functions = {
8636 .cookie = &mpt3sas_driver_template,
8637 .is_raid = scsih_is_raid,
8638 .get_resync = scsih_get_resync,
8639 .get_state = scsih_get_state,
8643 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8644 * this device belongs to.
8645 * @pdev: PCI device struct
8647 * return MPI2_VERSION for SAS 2.0 HBA devices,
8648 * MPI25_VERSION for SAS 3.0 HBA devices, and
8649 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8652 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8655 switch (pdev->device) {
8656 case MPI2_MFGPAGE_DEVID_SSS6200:
8657 case MPI2_MFGPAGE_DEVID_SAS2004:
8658 case MPI2_MFGPAGE_DEVID_SAS2008:
8659 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8660 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8661 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8662 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8663 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8664 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8665 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8666 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8667 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8668 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8669 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8670 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8671 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8672 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8673 return MPI2_VERSION;
8674 case MPI25_MFGPAGE_DEVID_SAS3004:
8675 case MPI25_MFGPAGE_DEVID_SAS3008:
8676 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8677 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8678 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8679 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8680 return MPI25_VERSION;
8681 case MPI26_MFGPAGE_DEVID_SAS3216:
8682 case MPI26_MFGPAGE_DEVID_SAS3224:
8683 case MPI26_MFGPAGE_DEVID_SAS3316_1:
8684 case MPI26_MFGPAGE_DEVID_SAS3316_2:
8685 case MPI26_MFGPAGE_DEVID_SAS3316_3:
8686 case MPI26_MFGPAGE_DEVID_SAS3316_4:
8687 case MPI26_MFGPAGE_DEVID_SAS3324_1:
8688 case MPI26_MFGPAGE_DEVID_SAS3324_2:
8689 case MPI26_MFGPAGE_DEVID_SAS3324_3:
8690 case MPI26_MFGPAGE_DEVID_SAS3324_4:
8691 case MPI26_MFGPAGE_DEVID_SAS3508:
8692 case MPI26_MFGPAGE_DEVID_SAS3508_1:
8693 case MPI26_MFGPAGE_DEVID_SAS3408:
8694 case MPI26_MFGPAGE_DEVID_SAS3516:
8695 case MPI26_MFGPAGE_DEVID_SAS3516_1:
8696 case MPI26_MFGPAGE_DEVID_SAS3416:
8697 return MPI26_VERSION;
8703 * _scsih_probe - attach and add scsi host
8704 * @pdev: PCI device struct
8705 * @id: pci device id
8707 * Returns 0 success, anything else error.
8710 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8712 struct MPT3SAS_ADAPTER *ioc;
8713 struct Scsi_Host *shost = NULL;
8715 u16 hba_mpi_version;
8717 /* Determine in which MPI version class this pci device belongs */
8718 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8719 if (hba_mpi_version == 0)
8722 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8723 * for other generation HBA's return with -ENODEV
8725 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8728 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8729 * for other generation HBA's return with -ENODEV
8731 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
8732 || hba_mpi_version == MPI26_VERSION)))
8735 switch (hba_mpi_version) {
8737 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8738 shost = scsi_host_alloc(&mpt2sas_driver_template,
8739 sizeof(struct MPT3SAS_ADAPTER));
8742 ioc = shost_priv(shost);
8743 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8744 ioc->hba_mpi_version_belonged = hba_mpi_version;
8745 ioc->id = mpt2_ids++;
8746 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8747 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8748 ioc->is_warpdrive = 1;
8749 ioc->hide_ir_msg = 1;
8751 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8755 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8756 shost = scsi_host_alloc(&mpt3sas_driver_template,
8757 sizeof(struct MPT3SAS_ADAPTER));
8760 ioc = shost_priv(shost);
8761 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8762 ioc->hba_mpi_version_belonged = hba_mpi_version;
8763 ioc->id = mpt3_ids++;
8764 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8765 switch (pdev->device) {
8766 case MPI26_MFGPAGE_DEVID_SAS3508:
8767 case MPI26_MFGPAGE_DEVID_SAS3508_1:
8768 case MPI26_MFGPAGE_DEVID_SAS3408:
8769 case MPI26_MFGPAGE_DEVID_SAS3516:
8770 case MPI26_MFGPAGE_DEVID_SAS3516_1:
8771 case MPI26_MFGPAGE_DEVID_SAS3416:
8772 ioc->is_gen35_ioc = 1;
8775 ioc->is_gen35_ioc = 0;
8777 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
8778 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
8779 (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
8780 ioc->combined_reply_queue = 1;
8781 if (ioc->is_gen35_ioc)
8782 ioc->combined_reply_index_count =
8783 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
8785 ioc->combined_reply_index_count =
8786 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
8793 INIT_LIST_HEAD(&ioc->list);
8794 spin_lock(&gioc_lock);
8795 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8796 spin_unlock(&gioc_lock);
8799 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8800 ioc->tm_cb_idx = tm_cb_idx;
8801 ioc->ctl_cb_idx = ctl_cb_idx;
8802 ioc->base_cb_idx = base_cb_idx;
8803 ioc->port_enable_cb_idx = port_enable_cb_idx;
8804 ioc->transport_cb_idx = transport_cb_idx;
8805 ioc->scsih_cb_idx = scsih_cb_idx;
8806 ioc->config_cb_idx = config_cb_idx;
8807 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8808 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8809 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8810 ioc->logging_level = logging_level;
8811 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8812 /* misc semaphores and spin locks */
8813 mutex_init(&ioc->reset_in_progress_mutex);
8814 /* initializing pci_access_mutex lock */
8815 mutex_init(&ioc->pci_access_mutex);
8816 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8817 spin_lock_init(&ioc->scsi_lookup_lock);
8818 spin_lock_init(&ioc->sas_device_lock);
8819 spin_lock_init(&ioc->sas_node_lock);
8820 spin_lock_init(&ioc->fw_event_lock);
8821 spin_lock_init(&ioc->raid_device_lock);
8822 spin_lock_init(&ioc->diag_trigger_lock);
8824 INIT_LIST_HEAD(&ioc->sas_device_list);
8825 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8826 INIT_LIST_HEAD(&ioc->sas_expander_list);
8827 INIT_LIST_HEAD(&ioc->fw_event_list);
8828 INIT_LIST_HEAD(&ioc->raid_device_list);
8829 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8830 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8831 INIT_LIST_HEAD(&ioc->delayed_sc_list);
8832 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
8833 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8834 INIT_LIST_HEAD(&ioc->reply_queue_list);
8836 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8838 /* init shost parameters */
8839 shost->max_cmd_len = 32;
8840 shost->max_lun = max_lun;
8841 shost->transportt = mpt3sas_transport_template;
8842 shost->unique_id = ioc->id;
8844 if (max_sectors != 0xFFFF) {
8845 if (max_sectors < 64) {
8846 shost->max_sectors = 64;
8847 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8848 "for max_sectors, range is 64 to 32767. Assigning "
8849 "value of 64.\n", ioc->name, max_sectors);
8850 } else if (max_sectors > 32767) {
8851 shost->max_sectors = 32767;
8852 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8853 "for max_sectors, range is 64 to 32767. Assigning "
8854 "default value of 32767.\n", ioc->name,
8857 shost->max_sectors = max_sectors & 0xFFFE;
8859 "The max_sectors value is set to %d\n",
8860 ioc->name, shost->max_sectors);
8864 /* register EEDP capabilities with SCSI layer */
8866 scsi_host_set_prot(shost, prot_mask);
8868 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8869 | SHOST_DIF_TYPE2_PROTECTION
8870 | SHOST_DIF_TYPE3_PROTECTION);
8872 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8875 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8876 "fw_event_%s%d", ioc->driver_name, ioc->id);
8877 ioc->firmware_event_thread = alloc_ordered_workqueue(
8878 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8879 if (!ioc->firmware_event_thread) {
8880 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8881 ioc->name, __FILE__, __LINE__, __func__);
8883 goto out_thread_fail;
8886 ioc->is_driver_loading = 1;
8887 if ((mpt3sas_base_attach(ioc))) {
8888 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8889 ioc->name, __FILE__, __LINE__, __func__);
8891 goto out_attach_fail;
8894 if (ioc->is_warpdrive) {
8895 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8896 ioc->hide_drives = 0;
8897 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8898 ioc->hide_drives = 1;
8900 if (mpt3sas_get_num_volumes(ioc))
8901 ioc->hide_drives = 1;
8903 ioc->hide_drives = 0;
8906 ioc->hide_drives = 0;
8908 rv = scsi_add_host(shost, &pdev->dev);
8910 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8911 ioc->name, __FILE__, __LINE__, __func__);
8912 goto out_add_shost_fail;
8915 scsi_scan_host(shost);
8918 mpt3sas_base_detach(ioc);
8920 destroy_workqueue(ioc->firmware_event_thread);
8922 spin_lock(&gioc_lock);
8923 list_del(&ioc->list);
8924 spin_unlock(&gioc_lock);
8925 scsi_host_put(shost);
8931 * scsih_suspend - power management suspend main entry point
8932 * @pdev: PCI device struct
8933 * @state: PM state change to (usually PCI_D3)
8935 * Returns 0 success, anything else error.
8938 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8940 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8941 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8942 pci_power_t device_state;
8944 mpt3sas_base_stop_watchdog(ioc);
8945 flush_scheduled_work();
8946 scsi_block_requests(shost);
8947 device_state = pci_choose_state(pdev, state);
8949 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8950 ioc->name, pdev, pci_name(pdev), device_state);
8952 pci_save_state(pdev);
8953 mpt3sas_base_free_resources(ioc);
8954 pci_set_power_state(pdev, device_state);
8959 * scsih_resume - power management resume main entry point
8960 * @pdev: PCI device struct
8962 * Returns 0 success, anything else error.
8965 scsih_resume(struct pci_dev *pdev)
8967 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8968 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8969 pci_power_t device_state = pdev->current_state;
8973 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8974 ioc->name, pdev, pci_name(pdev), device_state);
8976 pci_set_power_state(pdev, PCI_D0);
8977 pci_enable_wake(pdev, PCI_D0, 0);
8978 pci_restore_state(pdev);
8980 r = mpt3sas_base_map_resources(ioc);
8984 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
8985 scsi_unblock_requests(shost);
8986 mpt3sas_base_start_watchdog(ioc);
8989 #endif /* CONFIG_PM */
8992 * scsih_pci_error_detected - Called when a PCI error is detected.
8993 * @pdev: PCI device struct
8994 * @state: PCI channel state
8996 * Description: Called when a PCI error is detected.
8999 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9001 static pci_ers_result_t
9002 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9004 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9005 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9007 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
9011 case pci_channel_io_normal:
9012 return PCI_ERS_RESULT_CAN_RECOVER;
9013 case pci_channel_io_frozen:
9014 /* Fatal error, prepare for slot reset */
9015 ioc->pci_error_recovery = 1;
9016 scsi_block_requests(ioc->shost);
9017 mpt3sas_base_stop_watchdog(ioc);
9018 mpt3sas_base_free_resources(ioc);
9019 return PCI_ERS_RESULT_NEED_RESET;
9020 case pci_channel_io_perm_failure:
9021 /* Permanent error, prepare for device removal */
9022 ioc->pci_error_recovery = 1;
9023 mpt3sas_base_stop_watchdog(ioc);
9024 _scsih_flush_running_cmds(ioc);
9025 return PCI_ERS_RESULT_DISCONNECT;
9027 return PCI_ERS_RESULT_NEED_RESET;
9031 * scsih_pci_slot_reset - Called when PCI slot has been reset.
9032 * @pdev: PCI device struct
9034 * Description: This routine is called by the pci error recovery
9035 * code after the PCI slot has been reset, just before we
9036 * should resume normal operations.
9038 static pci_ers_result_t
9039 scsih_pci_slot_reset(struct pci_dev *pdev)
9041 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9042 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9045 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
9048 ioc->pci_error_recovery = 0;
9050 pci_restore_state(pdev);
9051 rc = mpt3sas_base_map_resources(ioc);
9053 return PCI_ERS_RESULT_DISCONNECT;
9055 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
9057 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
9058 (rc == 0) ? "success" : "failed");
9061 return PCI_ERS_RESULT_RECOVERED;
9063 return PCI_ERS_RESULT_DISCONNECT;
9067 * scsih_pci_resume() - resume normal ops after PCI reset
9068 * @pdev: pointer to PCI device
9070 * Called when the error recovery driver tells us that its
9071 * OK to resume normal operation. Use completion to allow
9072 * halted scsi ops to resume.
9075 scsih_pci_resume(struct pci_dev *pdev)
9077 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9078 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9080 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
9082 pci_cleanup_aer_uncorrect_error_status(pdev);
9083 mpt3sas_base_start_watchdog(ioc);
9084 scsi_unblock_requests(ioc->shost);
9088 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9089 * @pdev: pointer to PCI device
9091 static pci_ers_result_t
9092 scsih_pci_mmio_enabled(struct pci_dev *pdev)
9094 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9095 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9097 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
9100 /* TODO - dump whatever for debugging purposes */
9102 /* This called only if scsih_pci_error_detected returns
9103 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
9104 * works, no need to reset slot.
9106 return PCI_ERS_RESULT_RECOVERED;
9110 * scsih__ncq_prio_supp - Check for NCQ command priority support
9111 * @sdev: scsi device struct
9113 * This is called when a user indicates they would like to enable
9114 * ncq command priorities. This works only on SATA devices.
9116 bool scsih_ncq_prio_supp(struct scsi_device *sdev)
9119 bool ncq_prio_supp = false;
9121 if (!scsi_device_supports_vpd(sdev))
9122 return ncq_prio_supp;
9124 buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL);
9126 return ncq_prio_supp;
9128 if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN))
9129 ncq_prio_supp = (buf[213] >> 4) & 1;
9132 return ncq_prio_supp;
9135 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9137 static const struct pci_device_id mpt3sas_pci_table[] = {
9138 /* Spitfire ~ 2004 */
9139 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
9140 PCI_ANY_ID, PCI_ANY_ID },
9142 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
9143 PCI_ANY_ID, PCI_ANY_ID },
9144 /* Liberator ~ 2108 */
9145 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
9146 PCI_ANY_ID, PCI_ANY_ID },
9147 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
9148 PCI_ANY_ID, PCI_ANY_ID },
9149 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
9150 PCI_ANY_ID, PCI_ANY_ID },
9152 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
9153 PCI_ANY_ID, PCI_ANY_ID },
9154 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
9155 PCI_ANY_ID, PCI_ANY_ID },
9156 /* Thunderbolt ~ 2208 */
9157 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
9158 PCI_ANY_ID, PCI_ANY_ID },
9159 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
9160 PCI_ANY_ID, PCI_ANY_ID },
9161 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
9162 PCI_ANY_ID, PCI_ANY_ID },
9163 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
9164 PCI_ANY_ID, PCI_ANY_ID },
9165 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
9166 PCI_ANY_ID, PCI_ANY_ID },
9167 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
9168 PCI_ANY_ID, PCI_ANY_ID },
9169 /* Mustang ~ 2308 */
9170 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
9171 PCI_ANY_ID, PCI_ANY_ID },
9172 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
9173 PCI_ANY_ID, PCI_ANY_ID },
9174 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
9175 PCI_ANY_ID, PCI_ANY_ID },
9177 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
9178 PCI_ANY_ID, PCI_ANY_ID },
9179 /* Fury ~ 3004 and 3008 */
9180 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
9181 PCI_ANY_ID, PCI_ANY_ID },
9182 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
9183 PCI_ANY_ID, PCI_ANY_ID },
9184 /* Invader ~ 3108 */
9185 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
9186 PCI_ANY_ID, PCI_ANY_ID },
9187 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
9188 PCI_ANY_ID, PCI_ANY_ID },
9189 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
9190 PCI_ANY_ID, PCI_ANY_ID },
9191 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
9192 PCI_ANY_ID, PCI_ANY_ID },
9193 /* Cutlass ~ 3216 and 3224 */
9194 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
9195 PCI_ANY_ID, PCI_ANY_ID },
9196 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
9197 PCI_ANY_ID, PCI_ANY_ID },
9198 /* Intruder ~ 3316 and 3324 */
9199 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
9200 PCI_ANY_ID, PCI_ANY_ID },
9201 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
9202 PCI_ANY_ID, PCI_ANY_ID },
9203 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
9204 PCI_ANY_ID, PCI_ANY_ID },
9205 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
9206 PCI_ANY_ID, PCI_ANY_ID },
9207 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
9208 PCI_ANY_ID, PCI_ANY_ID },
9209 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
9210 PCI_ANY_ID, PCI_ANY_ID },
9211 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
9212 PCI_ANY_ID, PCI_ANY_ID },
9213 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
9214 PCI_ANY_ID, PCI_ANY_ID },
9215 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
9216 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
9217 PCI_ANY_ID, PCI_ANY_ID },
9218 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
9219 PCI_ANY_ID, PCI_ANY_ID },
9220 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
9221 PCI_ANY_ID, PCI_ANY_ID },
9222 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
9223 PCI_ANY_ID, PCI_ANY_ID },
9224 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
9225 PCI_ANY_ID, PCI_ANY_ID },
9226 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
9227 PCI_ANY_ID, PCI_ANY_ID },
9228 {0} /* Terminating entry */
9230 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
9232 static struct pci_error_handlers _mpt3sas_err_handler = {
9233 .error_detected = scsih_pci_error_detected,
9234 .mmio_enabled = scsih_pci_mmio_enabled,
9235 .slot_reset = scsih_pci_slot_reset,
9236 .resume = scsih_pci_resume,
9239 static struct pci_driver mpt3sas_driver = {
9240 .name = MPT3SAS_DRIVER_NAME,
9241 .id_table = mpt3sas_pci_table,
9242 .probe = _scsih_probe,
9243 .remove = scsih_remove,
9244 .shutdown = scsih_shutdown,
9245 .err_handler = &_mpt3sas_err_handler,
9247 .suspend = scsih_suspend,
9248 .resume = scsih_resume,
9253 * scsih_init - main entry point for this driver.
9255 * Returns 0 success, anything else error.
9263 mpt3sas_base_initialize_callback_handler();
9265 /* queuecommand callback hander */
9266 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
9268 /* task management callback handler */
9269 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
9271 /* base internal commands callback handler */
9272 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
9273 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
9274 mpt3sas_port_enable_done);
9276 /* transport internal commands callback handler */
9277 transport_cb_idx = mpt3sas_base_register_callback_handler(
9278 mpt3sas_transport_done);
9280 /* scsih internal commands callback handler */
9281 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
9283 /* configuration page API internal commands callback handler */
9284 config_cb_idx = mpt3sas_base_register_callback_handler(
9285 mpt3sas_config_done);
9287 /* ctl module callback handler */
9288 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
9290 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
9291 _scsih_tm_tr_complete);
9293 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
9294 _scsih_tm_volume_tr_complete);
9296 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
9297 _scsih_sas_control_complete);
9303 * scsih_exit - exit point for this driver (when it is a module).
9305 * Returns 0 success, anything else error.
9311 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
9312 mpt3sas_base_release_callback_handler(tm_cb_idx);
9313 mpt3sas_base_release_callback_handler(base_cb_idx);
9314 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
9315 mpt3sas_base_release_callback_handler(transport_cb_idx);
9316 mpt3sas_base_release_callback_handler(scsih_cb_idx);
9317 mpt3sas_base_release_callback_handler(config_cb_idx);
9318 mpt3sas_base_release_callback_handler(ctl_cb_idx);
9320 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
9321 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
9322 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
9324 /* raid transport support */
9325 if (hbas_to_enumerate != 1)
9326 raid_class_release(mpt3sas_raid_template);
9327 if (hbas_to_enumerate != 2)
9328 raid_class_release(mpt2sas_raid_template);
9329 sas_release_transport(mpt3sas_transport_template);
9333 * _mpt3sas_init - main entry point for this driver.
9335 * Returns 0 success, anything else error.
9342 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
9343 MPT3SAS_DRIVER_VERSION);
9345 mpt3sas_transport_template =
9346 sas_attach_transport(&mpt3sas_transport_functions);
9347 if (!mpt3sas_transport_template)
9350 /* No need attach mpt3sas raid functions template
9351 * if hbas_to_enumarate value is one.
9353 if (hbas_to_enumerate != 1) {
9354 mpt3sas_raid_template =
9355 raid_class_attach(&mpt3sas_raid_functions);
9356 if (!mpt3sas_raid_template) {
9357 sas_release_transport(mpt3sas_transport_template);
9362 /* No need to attach mpt2sas raid functions template
9363 * if hbas_to_enumarate value is two
9365 if (hbas_to_enumerate != 2) {
9366 mpt2sas_raid_template =
9367 raid_class_attach(&mpt2sas_raid_functions);
9368 if (!mpt2sas_raid_template) {
9369 sas_release_transport(mpt3sas_transport_template);
9374 error = scsih_init();
9380 mpt3sas_ctl_init(hbas_to_enumerate);
9382 error = pci_register_driver(&mpt3sas_driver);
9390 * _mpt3sas_exit - exit point for this driver (when it is a module).
9396 pr_info("mpt3sas version %s unloading\n",
9397 MPT3SAS_DRIVER_VERSION);
9399 pci_unregister_driver(&mpt3sas_driver);
9401 mpt3sas_ctl_exit(hbas_to_enumerate);
9406 module_init(_mpt3sas_init);
9407 module_exit(_mpt3sas_exit);