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/pci-aspm.h>
55 #include <linux/interrupt.h>
56 #include <linux/aer.h>
57 #include <linux/raid_class.h>
58 #include <asm/unaligned.h>
60 #include "mpt3sas_base.h"
62 #define RAID_CHANNEL 1
64 #define PCIE_CHANNEL 2
67 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
68 struct _sas_node *sas_expander);
69 static void _firmware_event_work(struct work_struct *work);
71 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
72 struct _sas_device *sas_device);
73 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
74 u8 retry_count, u8 is_pd);
75 static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle);
76 static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
77 struct _pcie_device *pcie_device);
79 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle);
80 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
82 /* global parameters */
83 LIST_HEAD(mpt3sas_ioc_list);
84 /* global ioc lock for list operations */
85 DEFINE_SPINLOCK(gioc_lock);
87 MODULE_AUTHOR(MPT3SAS_AUTHOR);
88 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
91 MODULE_ALIAS("mpt2sas");
93 /* local parameters */
94 static u8 scsi_io_cb_idx = -1;
95 static u8 tm_cb_idx = -1;
96 static u8 ctl_cb_idx = -1;
97 static u8 base_cb_idx = -1;
98 static u8 port_enable_cb_idx = -1;
99 static u8 transport_cb_idx = -1;
100 static u8 scsih_cb_idx = -1;
101 static u8 config_cb_idx = -1;
105 static u8 tm_tr_cb_idx = -1 ;
106 static u8 tm_tr_volume_cb_idx = -1 ;
107 static u8 tm_sas_control_cb_idx = -1;
109 /* command line options */
110 static u32 logging_level;
111 MODULE_PARM_DESC(logging_level,
112 " bits for enabling additional logging info (default=0)");
115 static ushort max_sectors = 0xFFFF;
116 module_param(max_sectors, ushort, 0);
117 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
120 static int missing_delay[2] = {-1, -1};
121 module_param_array(missing_delay, int, NULL, 0);
122 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
124 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
125 #define MPT3SAS_MAX_LUN (16895)
126 static u64 max_lun = MPT3SAS_MAX_LUN;
127 module_param(max_lun, ullong, 0);
128 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
130 static ushort hbas_to_enumerate;
131 module_param(hbas_to_enumerate, ushort, 0);
132 MODULE_PARM_DESC(hbas_to_enumerate,
133 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
134 1 - enumerates only SAS 2.0 generation HBAs\n \
135 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
137 /* diag_buffer_enable is bitwise
139 * bit 1 set = SNAPSHOT
140 * bit 2 set = EXTENDED
142 * Either bit can be set, or both
144 static int diag_buffer_enable = -1;
145 module_param(diag_buffer_enable, int, 0);
146 MODULE_PARM_DESC(diag_buffer_enable,
147 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
148 static int disable_discovery = -1;
149 module_param(disable_discovery, int, 0);
150 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
153 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
154 static int prot_mask = -1;
155 module_param(prot_mask, int, 0);
156 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
159 /* raid transport support */
160 static struct raid_template *mpt3sas_raid_template;
161 static struct raid_template *mpt2sas_raid_template;
165 * struct sense_info - common structure for obtaining sense keys
167 * @asc: additional sense code
168 * @ascq: additional sense code qualifier
176 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
177 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
178 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
179 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
180 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
182 * struct fw_event_work - firmware event struct
183 * @list: link list framework
184 * @work: work object (ioc->fault_reset_work_q)
185 * @ioc: per adapter object
186 * @device_handle: device handle
187 * @VF_ID: virtual function id
188 * @VP_ID: virtual port id
189 * @ignore: flag meaning this event has been marked to ignore
190 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
191 * @refcount: kref for this event
192 * @event_data: reply event data payload follows
194 * This object stored on ioc->fw_event_list.
196 struct fw_event_work {
197 struct list_head list;
198 struct work_struct work;
200 struct MPT3SAS_ADAPTER *ioc;
206 struct kref refcount;
207 char event_data[0] __aligned(4);
210 static void fw_event_work_free(struct kref *r)
212 kfree(container_of(r, struct fw_event_work, refcount));
215 static void fw_event_work_get(struct fw_event_work *fw_work)
217 kref_get(&fw_work->refcount);
220 static void fw_event_work_put(struct fw_event_work *fw_work)
222 kref_put(&fw_work->refcount, fw_event_work_free);
225 static struct fw_event_work *alloc_fw_event_work(int len)
227 struct fw_event_work *fw_event;
229 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
233 kref_init(&fw_event->refcount);
238 * struct _scsi_io_transfer - scsi io transfer
239 * @handle: sas device handle (assigned by firmware)
240 * @is_raid: flag set for hidden raid components
241 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
242 * @data_length: data transfer length
243 * @data_dma: dma pointer to data
246 * @cdb_length: cdb length
248 * @timeout: timeout for this command
249 * @VF_ID: virtual function id
250 * @VP_ID: virtual port id
251 * @valid_reply: flag set for reply message
252 * @sense_length: sense length
253 * @ioc_status: ioc status
254 * @scsi_state: scsi state
255 * @scsi_status: scsi staus
256 * @log_info: log information
257 * @transfer_length: data length transfer when there is a reply message
259 * Used for sending internal scsi commands to devices within this module.
260 * Refer to _scsi_send_scsi_io().
262 struct _scsi_io_transfer {
265 enum dma_data_direction dir;
268 u8 sense[SCSI_SENSE_BUFFERSIZE];
276 /* the following bits are only valid when 'valid_reply = 1' */
286 * _scsih_set_debug_level - global setting of ioc->logging_level.
290 * Note: The logging levels are defined in mpt3sas_debug.h.
293 _scsih_set_debug_level(const char *val, const struct kernel_param *kp)
295 int ret = param_set_int(val, kp);
296 struct MPT3SAS_ADAPTER *ioc;
301 pr_info("setting logging_level(0x%08x)\n", logging_level);
302 spin_lock(&gioc_lock);
303 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
304 ioc->logging_level = logging_level;
305 spin_unlock(&gioc_lock);
308 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
309 &logging_level, 0644);
312 * _scsih_srch_boot_sas_address - search based on sas_address
313 * @sas_address: sas address
314 * @boot_device: boot device object from bios page 2
316 * Return: 1 when there's a match, 0 means no match.
319 _scsih_srch_boot_sas_address(u64 sas_address,
320 Mpi2BootDeviceSasWwid_t *boot_device)
322 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
326 * _scsih_srch_boot_device_name - search based on device name
327 * @device_name: device name specified in INDENTIFY fram
328 * @boot_device: boot device object from bios page 2
330 * Return: 1 when there's a match, 0 means no match.
333 _scsih_srch_boot_device_name(u64 device_name,
334 Mpi2BootDeviceDeviceName_t *boot_device)
336 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
340 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
341 * @enclosure_logical_id: enclosure logical id
342 * @slot_number: slot number
343 * @boot_device: boot device object from bios page 2
345 * Return: 1 when there's a match, 0 means no match.
348 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
349 Mpi2BootDeviceEnclosureSlot_t *boot_device)
351 return (enclosure_logical_id == le64_to_cpu(boot_device->
352 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
353 SlotNumber)) ? 1 : 0;
357 * _scsih_is_boot_device - search for matching boot device.
358 * @sas_address: sas address
359 * @device_name: device name specified in INDENTIFY fram
360 * @enclosure_logical_id: enclosure logical id
362 * @form: specifies boot device form
363 * @boot_device: boot device object from bios page 2
365 * Return: 1 when there's a match, 0 means no match.
368 _scsih_is_boot_device(u64 sas_address, u64 device_name,
369 u64 enclosure_logical_id, u16 slot, u8 form,
370 Mpi2BiosPage2BootDevice_t *boot_device)
375 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
378 rc = _scsih_srch_boot_sas_address(
379 sas_address, &boot_device->SasWwid);
381 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
382 if (!enclosure_logical_id)
384 rc = _scsih_srch_boot_encl_slot(
385 enclosure_logical_id,
386 slot, &boot_device->EnclosureSlot);
388 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
391 rc = _scsih_srch_boot_device_name(
392 device_name, &boot_device->DeviceName);
394 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
402 * _scsih_get_sas_address - set the sas_address for given device handle
404 * @handle: device handle
405 * @sas_address: sas address
407 * Return: 0 success, non-zero when failure
410 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
413 Mpi2SasDevicePage0_t sas_device_pg0;
414 Mpi2ConfigReply_t mpi_reply;
419 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
420 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
421 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
422 __FILE__, __LINE__, __func__);
426 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
427 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
428 /* For HBA, vSES doesn't return HBA SAS address. Instead return
429 * vSES's sas address.
431 if ((handle <= ioc->sas_hba.num_phys) &&
432 (!(le32_to_cpu(sas_device_pg0.DeviceInfo) &
433 MPI2_SAS_DEVICE_INFO_SEP)))
434 *sas_address = ioc->sas_hba.sas_address;
436 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
440 /* we hit this because the given parent handle doesn't exist */
441 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
444 /* else error case */
446 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
447 ioc->name, handle, ioc_status,
448 __FILE__, __LINE__, __func__);
453 * _scsih_determine_boot_device - determine boot device.
454 * @ioc: per adapter object
455 * @device: sas_device or pcie_device object
456 * @channel: SAS or PCIe channel
458 * Determines whether this device should be first reported device to
459 * to scsi-ml or sas transport, this purpose is for persistent boot device.
460 * There are primary, alternate, and current entries in bios page 2. The order
461 * priority is primary, alternate, then current. This routine saves
462 * the corresponding device object.
463 * The saved data to be used later in _scsih_probe_boot_devices().
466 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device,
469 struct _sas_device *sas_device;
470 struct _pcie_device *pcie_device;
471 struct _raid_device *raid_device;
474 u64 enclosure_logical_id;
477 /* only process this function when driver loads */
478 if (!ioc->is_driver_loading)
481 /* no Bios, return immediately */
482 if (!ioc->bios_pg3.BiosVersion)
485 if (channel == RAID_CHANNEL) {
486 raid_device = device;
487 sas_address = raid_device->wwid;
489 enclosure_logical_id = 0;
491 } else if (channel == PCIE_CHANNEL) {
492 pcie_device = device;
493 sas_address = pcie_device->wwid;
495 enclosure_logical_id = 0;
499 sas_address = sas_device->sas_address;
500 device_name = sas_device->device_name;
501 enclosure_logical_id = sas_device->enclosure_logical_id;
502 slot = sas_device->slot;
505 if (!ioc->req_boot_device.device) {
506 if (_scsih_is_boot_device(sas_address, device_name,
507 enclosure_logical_id, slot,
508 (ioc->bios_pg2.ReqBootDeviceForm &
509 MPI2_BIOSPAGE2_FORM_MASK),
510 &ioc->bios_pg2.RequestedBootDevice)) {
511 dinitprintk(ioc, pr_info(MPT3SAS_FMT
512 "%s: req_boot_device(0x%016llx)\n",
514 (unsigned long long)sas_address));
515 ioc->req_boot_device.device = device;
516 ioc->req_boot_device.channel = channel;
520 if (!ioc->req_alt_boot_device.device) {
521 if (_scsih_is_boot_device(sas_address, device_name,
522 enclosure_logical_id, slot,
523 (ioc->bios_pg2.ReqAltBootDeviceForm &
524 MPI2_BIOSPAGE2_FORM_MASK),
525 &ioc->bios_pg2.RequestedAltBootDevice)) {
526 dinitprintk(ioc, pr_info(MPT3SAS_FMT
527 "%s: req_alt_boot_device(0x%016llx)\n",
529 (unsigned long long)sas_address));
530 ioc->req_alt_boot_device.device = device;
531 ioc->req_alt_boot_device.channel = channel;
535 if (!ioc->current_boot_device.device) {
536 if (_scsih_is_boot_device(sas_address, device_name,
537 enclosure_logical_id, slot,
538 (ioc->bios_pg2.CurrentBootDeviceForm &
539 MPI2_BIOSPAGE2_FORM_MASK),
540 &ioc->bios_pg2.CurrentBootDevice)) {
541 dinitprintk(ioc, pr_info(MPT3SAS_FMT
542 "%s: current_boot_device(0x%016llx)\n",
544 (unsigned long long)sas_address));
545 ioc->current_boot_device.device = device;
546 ioc->current_boot_device.channel = channel;
551 static struct _sas_device *
552 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
553 struct MPT3SAS_TARGET *tgt_priv)
555 struct _sas_device *ret;
557 assert_spin_locked(&ioc->sas_device_lock);
559 ret = tgt_priv->sas_dev;
566 static struct _sas_device *
567 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
568 struct MPT3SAS_TARGET *tgt_priv)
570 struct _sas_device *ret;
573 spin_lock_irqsave(&ioc->sas_device_lock, flags);
574 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
575 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
580 static struct _pcie_device *
581 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
582 struct MPT3SAS_TARGET *tgt_priv)
584 struct _pcie_device *ret;
586 assert_spin_locked(&ioc->pcie_device_lock);
588 ret = tgt_priv->pcie_dev;
590 pcie_device_get(ret);
596 * mpt3sas_get_pdev_from_target - pcie device search
597 * @ioc: per adapter object
598 * @tgt_priv: starget private object
600 * Context: This function will acquire ioc->pcie_device_lock and will release
601 * before returning the pcie_device object.
603 * This searches for pcie_device from target, then return pcie_device object.
605 static struct _pcie_device *
606 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
607 struct MPT3SAS_TARGET *tgt_priv)
609 struct _pcie_device *ret;
612 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
613 ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv);
614 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
620 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
623 struct _sas_device *sas_device;
625 assert_spin_locked(&ioc->sas_device_lock);
627 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
628 if (sas_device->sas_address == sas_address)
631 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
632 if (sas_device->sas_address == sas_address)
638 sas_device_get(sas_device);
643 * mpt3sas_get_sdev_by_addr - sas device search
644 * @ioc: per adapter object
645 * @sas_address: sas address
646 * Context: Calling function should acquire ioc->sas_device_lock
648 * This searches for sas_device based on sas_address, then return sas_device
652 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
655 struct _sas_device *sas_device;
658 spin_lock_irqsave(&ioc->sas_device_lock, flags);
659 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
661 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
666 static struct _sas_device *
667 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
669 struct _sas_device *sas_device;
671 assert_spin_locked(&ioc->sas_device_lock);
673 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
674 if (sas_device->handle == handle)
677 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
678 if (sas_device->handle == handle)
684 sas_device_get(sas_device);
689 * mpt3sas_get_sdev_by_handle - sas device search
690 * @ioc: per adapter object
691 * @handle: sas device handle (assigned by firmware)
692 * Context: Calling function should acquire ioc->sas_device_lock
694 * This searches for sas_device based on sas_address, then return sas_device
698 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
700 struct _sas_device *sas_device;
703 spin_lock_irqsave(&ioc->sas_device_lock, flags);
704 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
705 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
711 * _scsih_display_enclosure_chassis_info - display device location info
712 * @ioc: per adapter object
713 * @sas_device: per sas device object
714 * @sdev: scsi device struct
715 * @starget: scsi target struct
718 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc,
719 struct _sas_device *sas_device, struct scsi_device *sdev,
720 struct scsi_target *starget)
723 if (sas_device->enclosure_handle != 0)
724 sdev_printk(KERN_INFO, sdev,
725 "enclosure logical id (0x%016llx), slot(%d) \n",
727 sas_device->enclosure_logical_id,
729 if (sas_device->connector_name[0] != '\0')
730 sdev_printk(KERN_INFO, sdev,
731 "enclosure level(0x%04x), connector name( %s)\n",
732 sas_device->enclosure_level,
733 sas_device->connector_name);
734 if (sas_device->is_chassis_slot_valid)
735 sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n",
736 sas_device->chassis_slot);
737 } else if (starget) {
738 if (sas_device->enclosure_handle != 0)
739 starget_printk(KERN_INFO, starget,
740 "enclosure logical id(0x%016llx), slot(%d) \n",
742 sas_device->enclosure_logical_id,
744 if (sas_device->connector_name[0] != '\0')
745 starget_printk(KERN_INFO, starget,
746 "enclosure level(0x%04x), connector name( %s)\n",
747 sas_device->enclosure_level,
748 sas_device->connector_name);
749 if (sas_device->is_chassis_slot_valid)
750 starget_printk(KERN_INFO, starget,
751 "chassis slot(0x%04x)\n",
752 sas_device->chassis_slot);
754 if (sas_device->enclosure_handle != 0)
756 "enclosure logical id(0x%016llx), slot(%d) \n",
757 ioc->name, (unsigned long long)
758 sas_device->enclosure_logical_id,
760 if (sas_device->connector_name[0] != '\0')
762 "enclosure level(0x%04x), connector name( %s)\n",
763 ioc->name, sas_device->enclosure_level,
764 sas_device->connector_name);
765 if (sas_device->is_chassis_slot_valid)
766 pr_info(MPT3SAS_FMT "chassis slot(0x%04x)\n",
767 ioc->name, sas_device->chassis_slot);
772 * _scsih_sas_device_remove - remove sas_device from list.
773 * @ioc: per adapter object
774 * @sas_device: the sas_device object
775 * Context: This function will acquire ioc->sas_device_lock.
777 * If sas_device is on the list, remove it and decrement its reference count.
780 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
781 struct _sas_device *sas_device)
788 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
789 ioc->name, sas_device->handle,
790 (unsigned long long) sas_device->sas_address);
792 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
795 * The lock serializes access to the list, but we still need to verify
796 * that nobody removed the entry while we were waiting on the lock.
798 spin_lock_irqsave(&ioc->sas_device_lock, flags);
799 if (!list_empty(&sas_device->list)) {
800 list_del_init(&sas_device->list);
801 sas_device_put(sas_device);
803 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
807 * _scsih_device_remove_by_handle - removing device object by handle
808 * @ioc: per adapter object
809 * @handle: device handle
812 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
814 struct _sas_device *sas_device;
817 if (ioc->shost_recovery)
820 spin_lock_irqsave(&ioc->sas_device_lock, flags);
821 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
823 list_del_init(&sas_device->list);
824 sas_device_put(sas_device);
826 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
828 _scsih_remove_device(ioc, sas_device);
829 sas_device_put(sas_device);
834 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
835 * @ioc: per adapter object
836 * @sas_address: device sas_address
839 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
842 struct _sas_device *sas_device;
845 if (ioc->shost_recovery)
848 spin_lock_irqsave(&ioc->sas_device_lock, flags);
849 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
851 list_del_init(&sas_device->list);
852 sas_device_put(sas_device);
854 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
856 _scsih_remove_device(ioc, sas_device);
857 sas_device_put(sas_device);
862 * _scsih_sas_device_add - insert sas_device to the list.
863 * @ioc: per adapter object
864 * @sas_device: the sas_device object
865 * Context: This function will acquire ioc->sas_device_lock.
867 * Adding new object to the ioc->sas_device_list.
870 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
871 struct _sas_device *sas_device)
875 dewtprintk(ioc, pr_info(MPT3SAS_FMT
876 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
877 ioc->name, __func__, sas_device->handle,
878 (unsigned long long)sas_device->sas_address));
880 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
883 spin_lock_irqsave(&ioc->sas_device_lock, flags);
884 sas_device_get(sas_device);
885 list_add_tail(&sas_device->list, &ioc->sas_device_list);
886 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
888 if (ioc->hide_drives) {
889 clear_bit(sas_device->handle, ioc->pend_os_device_add);
893 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
894 sas_device->sas_address_parent)) {
895 _scsih_sas_device_remove(ioc, sas_device);
896 } else if (!sas_device->starget) {
898 * When asyn scanning is enabled, its not possible to remove
899 * devices while scanning is turned on due to an oops in
900 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
902 if (!ioc->is_driver_loading) {
903 mpt3sas_transport_port_remove(ioc,
904 sas_device->sas_address,
905 sas_device->sas_address_parent);
906 _scsih_sas_device_remove(ioc, sas_device);
909 clear_bit(sas_device->handle, ioc->pend_os_device_add);
913 * _scsih_sas_device_init_add - insert sas_device to the list.
914 * @ioc: per adapter object
915 * @sas_device: the sas_device object
916 * Context: This function will acquire ioc->sas_device_lock.
918 * Adding new object at driver load time to the ioc->sas_device_init_list.
921 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
922 struct _sas_device *sas_device)
926 dewtprintk(ioc, pr_info(MPT3SAS_FMT
927 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
928 __func__, sas_device->handle,
929 (unsigned long long)sas_device->sas_address));
931 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
934 spin_lock_irqsave(&ioc->sas_device_lock, flags);
935 sas_device_get(sas_device);
936 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
937 _scsih_determine_boot_device(ioc, sas_device, 0);
938 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
942 static struct _pcie_device *
943 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
945 struct _pcie_device *pcie_device;
947 assert_spin_locked(&ioc->pcie_device_lock);
949 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
950 if (pcie_device->wwid == wwid)
953 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
954 if (pcie_device->wwid == wwid)
960 pcie_device_get(pcie_device);
966 * mpt3sas_get_pdev_by_wwid - pcie device search
967 * @ioc: per adapter object
970 * Context: This function will acquire ioc->pcie_device_lock and will release
971 * before returning the pcie_device object.
973 * This searches for pcie_device based on wwid, then return pcie_device object.
975 static struct _pcie_device *
976 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
978 struct _pcie_device *pcie_device;
981 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
982 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
983 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
989 static struct _pcie_device *
990 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id,
993 struct _pcie_device *pcie_device;
995 assert_spin_locked(&ioc->pcie_device_lock);
997 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
998 if (pcie_device->id == id && pcie_device->channel == channel)
1001 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
1002 if (pcie_device->id == id && pcie_device->channel == channel)
1008 pcie_device_get(pcie_device);
1012 static struct _pcie_device *
1013 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1015 struct _pcie_device *pcie_device;
1017 assert_spin_locked(&ioc->pcie_device_lock);
1019 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
1020 if (pcie_device->handle == handle)
1023 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
1024 if (pcie_device->handle == handle)
1030 pcie_device_get(pcie_device);
1036 * mpt3sas_get_pdev_by_handle - pcie device search
1037 * @ioc: per adapter object
1038 * @handle: Firmware device handle
1040 * Context: This function will acquire ioc->pcie_device_lock and will release
1041 * before returning the pcie_device object.
1043 * This searches for pcie_device based on handle, then return pcie_device
1046 struct _pcie_device *
1047 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1049 struct _pcie_device *pcie_device;
1050 unsigned long flags;
1052 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1053 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
1054 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1060 * _scsih_pcie_device_remove - remove pcie_device from list.
1061 * @ioc: per adapter object
1062 * @pcie_device: the pcie_device object
1063 * Context: This function will acquire ioc->pcie_device_lock.
1065 * If pcie_device is on the list, remove it and decrement its reference count.
1068 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc,
1069 struct _pcie_device *pcie_device)
1071 unsigned long flags;
1072 int was_on_pcie_device_list = 0;
1077 "removing handle(0x%04x), wwid(0x%016llx)\n",
1078 ioc->name, pcie_device->handle,
1079 (unsigned long long) pcie_device->wwid);
1080 if (pcie_device->enclosure_handle != 0)
1082 "removing enclosure logical id(0x%016llx), slot(%d)\n",
1084 (unsigned long long)pcie_device->enclosure_logical_id,
1086 if (pcie_device->connector_name[0] != '\0')
1088 "removing enclosure level(0x%04x), connector name( %s)\n",
1089 ioc->name, pcie_device->enclosure_level,
1090 pcie_device->connector_name);
1092 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1093 if (!list_empty(&pcie_device->list)) {
1094 list_del_init(&pcie_device->list);
1095 was_on_pcie_device_list = 1;
1097 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1098 if (was_on_pcie_device_list) {
1099 kfree(pcie_device->serial_number);
1100 pcie_device_put(pcie_device);
1106 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1107 * @ioc: per adapter object
1108 * @handle: device handle
1111 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1113 struct _pcie_device *pcie_device;
1114 unsigned long flags;
1115 int was_on_pcie_device_list = 0;
1117 if (ioc->shost_recovery)
1120 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1121 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
1123 if (!list_empty(&pcie_device->list)) {
1124 list_del_init(&pcie_device->list);
1125 was_on_pcie_device_list = 1;
1126 pcie_device_put(pcie_device);
1129 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1130 if (was_on_pcie_device_list) {
1131 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
1132 pcie_device_put(pcie_device);
1137 * _scsih_pcie_device_add - add pcie_device object
1138 * @ioc: per adapter object
1139 * @pcie_device: pcie_device object
1141 * This is added to the pcie_device_list link list.
1144 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc,
1145 struct _pcie_device *pcie_device)
1147 unsigned long flags;
1149 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1150 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
1151 pcie_device->handle, (unsigned long long)pcie_device->wwid));
1152 if (pcie_device->enclosure_handle != 0)
1153 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1154 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1155 ioc->name, __func__,
1156 (unsigned long long)pcie_device->enclosure_logical_id,
1157 pcie_device->slot));
1158 if (pcie_device->connector_name[0] != '\0')
1159 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1160 "%s: enclosure level(0x%04x), connector name( %s)\n",
1161 ioc->name, __func__, pcie_device->enclosure_level,
1162 pcie_device->connector_name));
1164 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1165 pcie_device_get(pcie_device);
1166 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
1167 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1169 if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) {
1170 _scsih_pcie_device_remove(ioc, pcie_device);
1171 } else if (!pcie_device->starget) {
1172 if (!ioc->is_driver_loading) {
1173 /*TODO-- Need to find out whether this condition will occur or not*/
1174 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1177 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1181 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1182 * @ioc: per adapter object
1183 * @pcie_device: the pcie_device object
1184 * Context: This function will acquire ioc->pcie_device_lock.
1186 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1189 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc,
1190 struct _pcie_device *pcie_device)
1192 unsigned long flags;
1194 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1195 "%s: handle (0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
1196 pcie_device->handle, (unsigned long long)pcie_device->wwid));
1197 if (pcie_device->enclosure_handle != 0)
1198 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1199 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1200 ioc->name, __func__,
1201 (unsigned long long)pcie_device->enclosure_logical_id,
1202 pcie_device->slot));
1203 if (pcie_device->connector_name[0] != '\0')
1204 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1205 "%s: enclosure level(0x%04x), connector name( %s)\n",
1206 ioc->name, __func__, pcie_device->enclosure_level,
1207 pcie_device->connector_name));
1209 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1210 pcie_device_get(pcie_device);
1211 list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list);
1212 _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL);
1213 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1216 * _scsih_raid_device_find_by_id - raid device search
1217 * @ioc: per adapter object
1218 * @id: sas device target id
1219 * @channel: sas device channel
1220 * Context: Calling function should acquire ioc->raid_device_lock
1222 * This searches for raid_device based on target id, then return raid_device
1225 static struct _raid_device *
1226 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
1228 struct _raid_device *raid_device, *r;
1231 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1232 if (raid_device->id == id && raid_device->channel == channel) {
1243 * mpt3sas_raid_device_find_by_handle - raid device search
1244 * @ioc: per adapter object
1245 * @handle: sas device handle (assigned by firmware)
1246 * Context: Calling function should acquire ioc->raid_device_lock
1248 * This searches for raid_device based on handle, then return raid_device
1251 struct _raid_device *
1252 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1254 struct _raid_device *raid_device, *r;
1257 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1258 if (raid_device->handle != handle)
1269 * _scsih_raid_device_find_by_wwid - raid device search
1270 * @ioc: per adapter object
1272 * Context: Calling function should acquire ioc->raid_device_lock
1274 * This searches for raid_device based on wwid, then return raid_device
1277 static struct _raid_device *
1278 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
1280 struct _raid_device *raid_device, *r;
1283 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1284 if (raid_device->wwid != wwid)
1295 * _scsih_raid_device_add - add raid_device object
1296 * @ioc: per adapter object
1297 * @raid_device: raid_device object
1299 * This is added to the raid_device_list link list.
1302 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
1303 struct _raid_device *raid_device)
1305 unsigned long flags;
1307 dewtprintk(ioc, pr_info(MPT3SAS_FMT
1308 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
1309 raid_device->handle, (unsigned long long)raid_device->wwid));
1311 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1312 list_add_tail(&raid_device->list, &ioc->raid_device_list);
1313 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1317 * _scsih_raid_device_remove - delete raid_device object
1318 * @ioc: per adapter object
1319 * @raid_device: raid_device object
1323 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
1324 struct _raid_device *raid_device)
1326 unsigned long flags;
1328 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1329 list_del(&raid_device->list);
1331 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1335 * mpt3sas_scsih_expander_find_by_handle - expander device search
1336 * @ioc: per adapter object
1337 * @handle: expander handle (assigned by firmware)
1338 * Context: Calling function should acquire ioc->sas_device_lock
1340 * This searches for expander device based on handle, then returns the
1344 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1346 struct _sas_node *sas_expander, *r;
1349 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1350 if (sas_expander->handle != handle)
1360 * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
1361 * @ioc: per adapter object
1362 * @handle: enclosure handle (assigned by firmware)
1363 * Context: Calling function should acquire ioc->sas_device_lock
1365 * This searches for enclosure device based on handle, then returns the
1368 static struct _enclosure_node *
1369 mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1371 struct _enclosure_node *enclosure_dev, *r;
1374 list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) {
1375 if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle)
1384 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1385 * @ioc: per adapter object
1386 * @sas_address: sas address
1387 * Context: Calling function should acquire ioc->sas_node_lock.
1389 * This searches for expander device based on sas_address, then returns the
1393 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1396 struct _sas_node *sas_expander, *r;
1399 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1400 if (sas_expander->sas_address != sas_address)
1410 * _scsih_expander_node_add - insert expander device to the list.
1411 * @ioc: per adapter object
1412 * @sas_expander: the sas_device object
1413 * Context: This function will acquire ioc->sas_node_lock.
1415 * Adding new object to the ioc->sas_expander_list.
1418 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1419 struct _sas_node *sas_expander)
1421 unsigned long flags;
1423 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1424 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1425 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1429 * _scsih_is_end_device - determines if device is an end device
1430 * @device_info: bitfield providing information about the device.
1433 * Return: 1 if end device.
1436 _scsih_is_end_device(u32 device_info)
1438 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1439 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1440 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1441 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1448 * _scsih_is_nvme_device - determines if device is an nvme device
1449 * @device_info: bitfield providing information about the device.
1452 * Return: 1 if nvme device.
1455 _scsih_is_nvme_device(u32 device_info)
1457 if ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE)
1458 == MPI26_PCIE_DEVINFO_NVME)
1465 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1466 * @ioc: per adapter object
1467 * @smid: system request message index
1469 * Return: the smid stored scmd pointer.
1470 * Then will dereference the stored scmd pointer.
1473 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1475 struct scsi_cmnd *scmd = NULL;
1476 struct scsiio_tracker *st;
1479 smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
1480 u32 unique_tag = smid - 1;
1482 scmd = scsi_host_find_tag(ioc->shost, unique_tag);
1484 st = scsi_cmd_priv(scmd);
1485 if (st->cb_idx == 0xFF || st->smid == 0)
1493 * scsih_change_queue_depth - setting device queue depth
1494 * @sdev: scsi device struct
1495 * @qdepth: requested queue depth
1497 * Return: queue depth.
1500 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1502 struct Scsi_Host *shost = sdev->host;
1504 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1505 struct MPT3SAS_DEVICE *sas_device_priv_data;
1506 struct MPT3SAS_TARGET *sas_target_priv_data;
1507 struct _sas_device *sas_device;
1508 unsigned long flags;
1510 max_depth = shost->can_queue;
1512 /* limit max device queue for SATA to 32 */
1513 sas_device_priv_data = sdev->hostdata;
1514 if (!sas_device_priv_data)
1516 sas_target_priv_data = sas_device_priv_data->sas_target;
1517 if (!sas_target_priv_data)
1519 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1522 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1523 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1525 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1526 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1528 sas_device_put(sas_device);
1530 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1534 if (!sdev->tagged_supported)
1536 if (qdepth > max_depth)
1538 return scsi_change_queue_depth(sdev, qdepth);
1542 * scsih_target_alloc - target add routine
1543 * @starget: scsi target struct
1545 * Return: 0 if ok. Any other return is assumed to be an error and
1546 * the device is ignored.
1549 scsih_target_alloc(struct scsi_target *starget)
1551 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1552 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1553 struct MPT3SAS_TARGET *sas_target_priv_data;
1554 struct _sas_device *sas_device;
1555 struct _raid_device *raid_device;
1556 struct _pcie_device *pcie_device;
1557 unsigned long flags;
1558 struct sas_rphy *rphy;
1560 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1562 if (!sas_target_priv_data)
1565 starget->hostdata = sas_target_priv_data;
1566 sas_target_priv_data->starget = starget;
1567 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1570 if (starget->channel == RAID_CHANNEL) {
1571 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1572 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1575 sas_target_priv_data->handle = raid_device->handle;
1576 sas_target_priv_data->sas_address = raid_device->wwid;
1577 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1578 if (ioc->is_warpdrive)
1579 sas_target_priv_data->raid_device = raid_device;
1580 raid_device->starget = starget;
1582 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1587 if (starget->channel == PCIE_CHANNEL) {
1588 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1589 pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id,
1592 sas_target_priv_data->handle = pcie_device->handle;
1593 sas_target_priv_data->sas_address = pcie_device->wwid;
1594 sas_target_priv_data->pcie_dev = pcie_device;
1595 pcie_device->starget = starget;
1596 pcie_device->id = starget->id;
1597 pcie_device->channel = starget->channel;
1598 sas_target_priv_data->flags |=
1599 MPT_TARGET_FLAGS_PCIE_DEVICE;
1600 if (pcie_device->fast_path)
1601 sas_target_priv_data->flags |=
1602 MPT_TARGET_FASTPATH_IO;
1604 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1608 /* sas/sata devices */
1609 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1610 rphy = dev_to_rphy(starget->dev.parent);
1611 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1612 rphy->identify.sas_address);
1615 sas_target_priv_data->handle = sas_device->handle;
1616 sas_target_priv_data->sas_address = sas_device->sas_address;
1617 sas_target_priv_data->sas_dev = sas_device;
1618 sas_device->starget = starget;
1619 sas_device->id = starget->id;
1620 sas_device->channel = starget->channel;
1621 if (test_bit(sas_device->handle, ioc->pd_handles))
1622 sas_target_priv_data->flags |=
1623 MPT_TARGET_FLAGS_RAID_COMPONENT;
1624 if (sas_device->fast_path)
1625 sas_target_priv_data->flags |=
1626 MPT_TARGET_FASTPATH_IO;
1628 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1634 * scsih_target_destroy - target destroy routine
1635 * @starget: scsi target struct
1638 scsih_target_destroy(struct scsi_target *starget)
1640 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1641 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1642 struct MPT3SAS_TARGET *sas_target_priv_data;
1643 struct _sas_device *sas_device;
1644 struct _raid_device *raid_device;
1645 struct _pcie_device *pcie_device;
1646 unsigned long flags;
1648 sas_target_priv_data = starget->hostdata;
1649 if (!sas_target_priv_data)
1652 if (starget->channel == RAID_CHANNEL) {
1653 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1654 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1657 raid_device->starget = NULL;
1658 raid_device->sdev = NULL;
1660 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1664 if (starget->channel == PCIE_CHANNEL) {
1665 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1666 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1667 sas_target_priv_data);
1668 if (pcie_device && (pcie_device->starget == starget) &&
1669 (pcie_device->id == starget->id) &&
1670 (pcie_device->channel == starget->channel))
1671 pcie_device->starget = NULL;
1675 * Corresponding get() is in _scsih_target_alloc()
1677 sas_target_priv_data->pcie_dev = NULL;
1678 pcie_device_put(pcie_device);
1679 pcie_device_put(pcie_device);
1681 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1685 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1686 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1687 if (sas_device && (sas_device->starget == starget) &&
1688 (sas_device->id == starget->id) &&
1689 (sas_device->channel == starget->channel))
1690 sas_device->starget = NULL;
1694 * Corresponding get() is in _scsih_target_alloc()
1696 sas_target_priv_data->sas_dev = NULL;
1697 sas_device_put(sas_device);
1699 sas_device_put(sas_device);
1701 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1704 kfree(sas_target_priv_data);
1705 starget->hostdata = NULL;
1709 * scsih_slave_alloc - device add routine
1710 * @sdev: scsi device struct
1712 * Return: 0 if ok. Any other return is assumed to be an error and
1713 * the device is ignored.
1716 scsih_slave_alloc(struct scsi_device *sdev)
1718 struct Scsi_Host *shost;
1719 struct MPT3SAS_ADAPTER *ioc;
1720 struct MPT3SAS_TARGET *sas_target_priv_data;
1721 struct MPT3SAS_DEVICE *sas_device_priv_data;
1722 struct scsi_target *starget;
1723 struct _raid_device *raid_device;
1724 struct _sas_device *sas_device;
1725 struct _pcie_device *pcie_device;
1726 unsigned long flags;
1728 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1730 if (!sas_device_priv_data)
1733 sas_device_priv_data->lun = sdev->lun;
1734 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1736 starget = scsi_target(sdev);
1737 sas_target_priv_data = starget->hostdata;
1738 sas_target_priv_data->num_luns++;
1739 sas_device_priv_data->sas_target = sas_target_priv_data;
1740 sdev->hostdata = sas_device_priv_data;
1741 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1742 sdev->no_uld_attach = 1;
1744 shost = dev_to_shost(&starget->dev);
1745 ioc = shost_priv(shost);
1746 if (starget->channel == RAID_CHANNEL) {
1747 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1748 raid_device = _scsih_raid_device_find_by_id(ioc,
1749 starget->id, starget->channel);
1751 raid_device->sdev = sdev; /* raid is single lun */
1752 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1754 if (starget->channel == PCIE_CHANNEL) {
1755 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1756 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
1757 sas_target_priv_data->sas_address);
1758 if (pcie_device && (pcie_device->starget == NULL)) {
1759 sdev_printk(KERN_INFO, sdev,
1760 "%s : pcie_device->starget set to starget @ %d\n",
1761 __func__, __LINE__);
1762 pcie_device->starget = starget;
1766 pcie_device_put(pcie_device);
1767 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1769 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1770 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1771 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1772 sas_target_priv_data->sas_address);
1773 if (sas_device && (sas_device->starget == NULL)) {
1774 sdev_printk(KERN_INFO, sdev,
1775 "%s : sas_device->starget set to starget @ %d\n",
1776 __func__, __LINE__);
1777 sas_device->starget = starget;
1781 sas_device_put(sas_device);
1783 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1790 * scsih_slave_destroy - device destroy routine
1791 * @sdev: scsi device struct
1794 scsih_slave_destroy(struct scsi_device *sdev)
1796 struct MPT3SAS_TARGET *sas_target_priv_data;
1797 struct scsi_target *starget;
1798 struct Scsi_Host *shost;
1799 struct MPT3SAS_ADAPTER *ioc;
1800 struct _sas_device *sas_device;
1801 struct _pcie_device *pcie_device;
1802 unsigned long flags;
1804 if (!sdev->hostdata)
1807 starget = scsi_target(sdev);
1808 sas_target_priv_data = starget->hostdata;
1809 sas_target_priv_data->num_luns--;
1811 shost = dev_to_shost(&starget->dev);
1812 ioc = shost_priv(shost);
1814 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
1815 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1816 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1817 sas_target_priv_data);
1818 if (pcie_device && !sas_target_priv_data->num_luns)
1819 pcie_device->starget = NULL;
1822 pcie_device_put(pcie_device);
1824 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1826 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1827 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1828 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1829 sas_target_priv_data);
1830 if (sas_device && !sas_target_priv_data->num_luns)
1831 sas_device->starget = NULL;
1834 sas_device_put(sas_device);
1835 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1838 kfree(sdev->hostdata);
1839 sdev->hostdata = NULL;
1843 * _scsih_display_sata_capabilities - sata capabilities
1844 * @ioc: per adapter object
1845 * @handle: device handle
1846 * @sdev: scsi device struct
1849 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1850 u16 handle, struct scsi_device *sdev)
1852 Mpi2ConfigReply_t mpi_reply;
1853 Mpi2SasDevicePage0_t sas_device_pg0;
1858 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1859 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1860 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1861 ioc->name, __FILE__, __LINE__, __func__);
1865 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1866 MPI2_IOCSTATUS_MASK;
1867 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1868 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1869 ioc->name, __FILE__, __LINE__, __func__);
1873 flags = le16_to_cpu(sas_device_pg0.Flags);
1874 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1876 sdev_printk(KERN_INFO, sdev,
1877 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1878 "sw_preserve(%s)\n",
1879 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1880 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1881 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1883 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1884 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1885 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1889 * raid transport support -
1890 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1891 * unloading the driver followed by a load - I believe that the subroutine
1892 * raid_class_release() is not cleaning up properly.
1896 * scsih_is_raid - return boolean indicating device is raid volume
1897 * @dev: the device struct object
1900 scsih_is_raid(struct device *dev)
1902 struct scsi_device *sdev = to_scsi_device(dev);
1903 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1905 if (ioc->is_warpdrive)
1907 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1911 scsih_is_nvme(struct device *dev)
1913 struct scsi_device *sdev = to_scsi_device(dev);
1915 return (sdev->channel == PCIE_CHANNEL) ? 1 : 0;
1919 * scsih_get_resync - get raid volume resync percent complete
1920 * @dev: the device struct object
1923 scsih_get_resync(struct device *dev)
1925 struct scsi_device *sdev = to_scsi_device(dev);
1926 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1927 static struct _raid_device *raid_device;
1928 unsigned long flags;
1929 Mpi2RaidVolPage0_t vol_pg0;
1930 Mpi2ConfigReply_t mpi_reply;
1931 u32 volume_status_flags;
1932 u8 percent_complete;
1935 percent_complete = 0;
1937 if (ioc->is_warpdrive)
1940 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1941 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1944 handle = raid_device->handle;
1945 percent_complete = raid_device->percent_complete;
1947 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1952 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1953 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1954 sizeof(Mpi2RaidVolPage0_t))) {
1955 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1956 ioc->name, __FILE__, __LINE__, __func__);
1957 percent_complete = 0;
1961 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1962 if (!(volume_status_flags &
1963 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1964 percent_complete = 0;
1968 switch (ioc->hba_mpi_version_belonged) {
1970 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1974 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1980 * scsih_get_state - get raid volume level
1981 * @dev: the device struct object
1984 scsih_get_state(struct device *dev)
1986 struct scsi_device *sdev = to_scsi_device(dev);
1987 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1988 static struct _raid_device *raid_device;
1989 unsigned long flags;
1990 Mpi2RaidVolPage0_t vol_pg0;
1991 Mpi2ConfigReply_t mpi_reply;
1993 enum raid_state state = RAID_STATE_UNKNOWN;
1996 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1997 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
2000 handle = raid_device->handle;
2001 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2006 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
2007 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
2008 sizeof(Mpi2RaidVolPage0_t))) {
2009 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
2010 ioc->name, __FILE__, __LINE__, __func__);
2014 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
2015 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
2016 state = RAID_STATE_RESYNCING;
2020 switch (vol_pg0.VolumeState) {
2021 case MPI2_RAID_VOL_STATE_OPTIMAL:
2022 case MPI2_RAID_VOL_STATE_ONLINE:
2023 state = RAID_STATE_ACTIVE;
2025 case MPI2_RAID_VOL_STATE_DEGRADED:
2026 state = RAID_STATE_DEGRADED;
2028 case MPI2_RAID_VOL_STATE_FAILED:
2029 case MPI2_RAID_VOL_STATE_MISSING:
2030 state = RAID_STATE_OFFLINE;
2034 switch (ioc->hba_mpi_version_belonged) {
2036 raid_set_state(mpt2sas_raid_template, dev, state);
2040 raid_set_state(mpt3sas_raid_template, dev, state);
2046 * _scsih_set_level - set raid level
2048 * @sdev: scsi device struct
2049 * @volume_type: volume type
2052 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
2053 struct scsi_device *sdev, u8 volume_type)
2055 enum raid_level level = RAID_LEVEL_UNKNOWN;
2057 switch (volume_type) {
2058 case MPI2_RAID_VOL_TYPE_RAID0:
2059 level = RAID_LEVEL_0;
2061 case MPI2_RAID_VOL_TYPE_RAID10:
2062 level = RAID_LEVEL_10;
2064 case MPI2_RAID_VOL_TYPE_RAID1E:
2065 level = RAID_LEVEL_1E;
2067 case MPI2_RAID_VOL_TYPE_RAID1:
2068 level = RAID_LEVEL_1;
2072 switch (ioc->hba_mpi_version_belonged) {
2074 raid_set_level(mpt2sas_raid_template,
2075 &sdev->sdev_gendev, level);
2079 raid_set_level(mpt3sas_raid_template,
2080 &sdev->sdev_gendev, level);
2087 * _scsih_get_volume_capabilities - volume capabilities
2088 * @ioc: per adapter object
2089 * @raid_device: the raid_device object
2091 * Return: 0 for success, else 1
2094 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
2095 struct _raid_device *raid_device)
2097 Mpi2RaidVolPage0_t *vol_pg0;
2098 Mpi2RaidPhysDiskPage0_t pd_pg0;
2099 Mpi2SasDevicePage0_t sas_device_pg0;
2100 Mpi2ConfigReply_t mpi_reply;
2104 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
2105 &num_pds)) || !num_pds) {
2106 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2107 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2112 raid_device->num_pds = num_pds;
2113 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
2114 sizeof(Mpi2RaidVol0PhysDisk_t));
2115 vol_pg0 = kzalloc(sz, GFP_KERNEL);
2117 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2118 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2123 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
2124 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
2125 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2126 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2132 raid_device->volume_type = vol_pg0->VolumeType;
2134 /* figure out what the underlying devices are by
2135 * obtaining the device_info bits for the 1st device
2137 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
2138 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
2139 vol_pg0->PhysDisk[0].PhysDiskNum))) {
2140 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
2141 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
2142 le16_to_cpu(pd_pg0.DevHandle)))) {
2143 raid_device->device_info =
2144 le32_to_cpu(sas_device_pg0.DeviceInfo);
2153 * _scsih_enable_tlr - setting TLR flags
2154 * @ioc: per adapter object
2155 * @sdev: scsi device struct
2157 * Enabling Transaction Layer Retries for tape devices when
2158 * vpd page 0x90 is present
2162 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
2166 if (sdev->type != TYPE_TAPE)
2169 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2172 sas_enable_tlr(sdev);
2173 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2174 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2180 * scsih_slave_configure - device configure routine.
2181 * @sdev: scsi device struct
2183 * Return: 0 if ok. Any other return is assumed to be an error and
2184 * the device is ignored.
2187 scsih_slave_configure(struct scsi_device *sdev)
2189 struct Scsi_Host *shost = sdev->host;
2190 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2191 struct MPT3SAS_DEVICE *sas_device_priv_data;
2192 struct MPT3SAS_TARGET *sas_target_priv_data;
2193 struct _sas_device *sas_device;
2194 struct _pcie_device *pcie_device;
2195 struct _raid_device *raid_device;
2196 unsigned long flags;
2201 u16 handle, volume_handle = 0;
2202 u64 volume_wwid = 0;
2205 sas_device_priv_data = sdev->hostdata;
2206 sas_device_priv_data->configured_lun = 1;
2207 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2208 sas_target_priv_data = sas_device_priv_data->sas_target;
2209 handle = sas_target_priv_data->handle;
2211 /* raid volume handling */
2212 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2214 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2215 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
2216 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2218 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2219 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2220 __LINE__, __func__));
2224 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2225 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2226 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2227 __LINE__, __func__));
2232 * WARPDRIVE: Initialize the required data for Direct IO
2234 mpt3sas_init_warpdrive_properties(ioc, raid_device);
2236 /* RAID Queue Depth Support
2237 * IS volume = underlying qdepth of drive type, either
2238 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2239 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2241 if (raid_device->device_info &
2242 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2243 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2246 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2247 if (raid_device->device_info &
2248 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2254 switch (raid_device->volume_type) {
2255 case MPI2_RAID_VOL_TYPE_RAID0:
2258 case MPI2_RAID_VOL_TYPE_RAID1E:
2259 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2260 if (ioc->manu_pg10.OEMIdentifier &&
2261 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2262 MFG10_GF0_R10_DISPLAY) &&
2263 !(raid_device->num_pds % 2))
2268 case MPI2_RAID_VOL_TYPE_RAID1:
2269 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2272 case MPI2_RAID_VOL_TYPE_RAID10:
2273 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2276 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2278 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2283 if (!ioc->hide_ir_msg)
2284 sdev_printk(KERN_INFO, sdev,
2285 "%s: handle(0x%04x), wwid(0x%016llx),"
2286 " pd_count(%d), type(%s)\n",
2287 r_level, raid_device->handle,
2288 (unsigned long long)raid_device->wwid,
2289 raid_device->num_pds, ds);
2291 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
2292 blk_queue_max_hw_sectors(sdev->request_queue,
2293 MPT3SAS_RAID_MAX_SECTORS);
2294 sdev_printk(KERN_INFO, sdev,
2295 "Set queue's max_sector to: %u\n",
2296 MPT3SAS_RAID_MAX_SECTORS);
2299 scsih_change_queue_depth(sdev, qdepth);
2301 /* raid transport support */
2302 if (!ioc->is_warpdrive)
2303 _scsih_set_level(ioc, sdev, raid_device->volume_type);
2307 /* non-raid handling */
2308 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2309 if (mpt3sas_config_get_volume_handle(ioc, handle,
2311 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2312 "failure at %s:%d/%s()!\n", ioc->name,
2313 __FILE__, __LINE__, __func__));
2316 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
2317 volume_handle, &volume_wwid)) {
2318 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2319 "failure at %s:%d/%s()!\n", ioc->name,
2320 __FILE__, __LINE__, __func__));
2326 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2327 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2328 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
2329 sas_device_priv_data->sas_target->sas_address);
2331 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2332 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2333 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2334 __LINE__, __func__));
2338 qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
2340 sdev_printk(KERN_INFO, sdev,
2341 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2342 ds, handle, (unsigned long long)pcie_device->wwid,
2343 pcie_device->port_num);
2344 if (pcie_device->enclosure_handle != 0)
2345 sdev_printk(KERN_INFO, sdev,
2346 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2348 (unsigned long long)pcie_device->enclosure_logical_id,
2350 if (pcie_device->connector_name[0] != '\0')
2351 sdev_printk(KERN_INFO, sdev,
2352 "%s: enclosure level(0x%04x),"
2353 "connector name( %s)\n", ds,
2354 pcie_device->enclosure_level,
2355 pcie_device->connector_name);
2357 if (pcie_device->nvme_mdts)
2358 blk_queue_max_hw_sectors(sdev->request_queue,
2359 pcie_device->nvme_mdts/512);
2361 pcie_device_put(pcie_device);
2362 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2363 scsih_change_queue_depth(sdev, qdepth);
2364 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2365 ** merged and can eliminate holes created during merging
2368 blk_queue_flag_set(QUEUE_FLAG_NOMERGES,
2369 sdev->request_queue);
2370 blk_queue_virt_boundary(sdev->request_queue,
2371 ioc->page_size - 1);
2375 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2376 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
2377 sas_device_priv_data->sas_target->sas_address);
2379 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2380 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2381 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2386 sas_device->volume_handle = volume_handle;
2387 sas_device->volume_wwid = volume_wwid;
2388 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2389 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2391 if (sas_device->device_info &
2392 MPI2_SAS_DEVICE_INFO_SEP) {
2393 sdev_printk(KERN_WARNING, sdev,
2394 "set ignore_delay_remove for handle(0x%04x)\n",
2395 sas_device_priv_data->sas_target->handle);
2396 sas_device_priv_data->ignore_delay_remove = 1;
2401 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2402 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2404 else if (sas_device->device_info &
2405 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2409 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
2410 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2411 ds, handle, (unsigned long long)sas_device->sas_address,
2412 sas_device->phy, (unsigned long long)sas_device->device_name);
2414 _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL);
2416 sas_device_put(sas_device);
2417 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2420 _scsih_display_sata_capabilities(ioc, handle, sdev);
2423 scsih_change_queue_depth(sdev, qdepth);
2426 sas_read_port_mode_page(sdev);
2427 _scsih_enable_tlr(ioc, sdev);
2434 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2435 * @sdev: scsi device struct
2436 * @bdev: pointer to block device context
2437 * @capacity: device size (in 512 byte sectors)
2438 * @params: three element array to place output:
2439 * params[0] number of heads (max 255)
2440 * params[1] number of sectors (max 63)
2441 * params[2] number of cylinders
2444 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2445 sector_t capacity, int params[])
2455 dummy = heads * sectors;
2456 cylinders = capacity;
2457 sector_div(cylinders, dummy);
2460 * Handle extended translation size for logical drives
2463 if ((ulong)capacity >= 0x200000) {
2466 dummy = heads * sectors;
2467 cylinders = capacity;
2468 sector_div(cylinders, dummy);
2473 params[1] = sectors;
2474 params[2] = cylinders;
2480 * _scsih_response_code - translation of device response code
2481 * @ioc: per adapter object
2482 * @response_code: response code returned by the device
2485 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2489 switch (response_code) {
2490 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2491 desc = "task management request completed";
2493 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2494 desc = "invalid frame";
2496 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2497 desc = "task management request not supported";
2499 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2500 desc = "task management request failed";
2502 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2503 desc = "task management request succeeded";
2505 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2506 desc = "invalid lun";
2509 desc = "overlapped tag attempted";
2511 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2512 desc = "task queued, however not sent to target";
2518 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2519 ioc->name, response_code, desc);
2523 * _scsih_tm_done - tm completion routine
2524 * @ioc: per adapter object
2525 * @smid: system request message index
2526 * @msix_index: MSIX table index supplied by the OS
2527 * @reply: reply message frame(lower 32bit addr)
2530 * The callback handler when using scsih_issue_tm.
2532 * Return: 1 meaning mf should be freed from _base_interrupt
2533 * 0 means the mf is freed from this function.
2536 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2538 MPI2DefaultReply_t *mpi_reply;
2540 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2542 if (ioc->tm_cmds.smid != smid)
2544 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2545 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2547 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2548 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2550 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2551 complete(&ioc->tm_cmds.done);
2556 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2557 * @ioc: per adapter object
2558 * @handle: device handle
2560 * During taskmangement request, we need to freeze the device queue.
2563 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2565 struct MPT3SAS_DEVICE *sas_device_priv_data;
2566 struct scsi_device *sdev;
2569 shost_for_each_device(sdev, ioc->shost) {
2572 sas_device_priv_data = sdev->hostdata;
2573 if (!sas_device_priv_data)
2575 if (sas_device_priv_data->sas_target->handle == handle) {
2576 sas_device_priv_data->sas_target->tm_busy = 1;
2578 ioc->ignore_loginfos = 1;
2584 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2585 * @ioc: per adapter object
2586 * @handle: device handle
2588 * During taskmangement request, we need to freeze the device queue.
2591 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2593 struct MPT3SAS_DEVICE *sas_device_priv_data;
2594 struct scsi_device *sdev;
2597 shost_for_each_device(sdev, ioc->shost) {
2600 sas_device_priv_data = sdev->hostdata;
2601 if (!sas_device_priv_data)
2603 if (sas_device_priv_data->sas_target->handle == handle) {
2604 sas_device_priv_data->sas_target->tm_busy = 0;
2606 ioc->ignore_loginfos = 0;
2612 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2613 * @ioc: per adapter struct
2614 * @handle: device handle
2616 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2617 * @smid_task: smid assigned to the task
2618 * @msix_task: MSIX table index supplied by the OS
2619 * @timeout: timeout in seconds
2620 * @tr_method: Target Reset Method
2623 * A generic API for sending task management requests to firmware.
2625 * The callback index is set inside `ioc->tm_cb_idx`.
2626 * The caller is responsible to check for outstanding commands.
2628 * Return: SUCCESS or FAILED.
2631 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun,
2632 u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method)
2634 Mpi2SCSITaskManagementRequest_t *mpi_request;
2635 Mpi2SCSITaskManagementReply_t *mpi_reply;
2640 lockdep_assert_held(&ioc->tm_cmds.mutex);
2642 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2643 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2644 __func__, ioc->name);
2648 if (ioc->shost_recovery || ioc->remove_host ||
2649 ioc->pci_error_recovery) {
2650 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2651 __func__, ioc->name);
2655 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2656 if (ioc_state & MPI2_DOORBELL_USED) {
2657 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2658 "unexpected doorbell active!\n", ioc->name));
2659 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2660 return (!rc) ? SUCCESS : FAILED;
2663 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2664 mpt3sas_base_fault_info(ioc, ioc_state &
2665 MPI2_DOORBELL_DATA_MASK);
2666 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2667 return (!rc) ? SUCCESS : FAILED;
2670 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2672 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2673 ioc->name, __func__);
2677 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2678 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
2679 ioc->name, handle, type, smid_task, timeout, tr_method));
2680 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2681 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2682 ioc->tm_cmds.smid = smid;
2683 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2684 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2685 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2686 mpi_request->DevHandle = cpu_to_le16(handle);
2687 mpi_request->TaskType = type;
2688 mpi_request->MsgFlags = tr_method;
2689 mpi_request->TaskMID = cpu_to_le16(smid_task);
2690 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2691 mpt3sas_scsih_set_tm_flag(ioc, handle);
2692 init_completion(&ioc->tm_cmds.done);
2693 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2694 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2695 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2696 if (mpt3sas_base_check_cmd_timeout(ioc,
2697 ioc->tm_cmds.status, mpi_request,
2698 sizeof(Mpi2SCSITaskManagementRequest_t)/4)) {
2699 rc = mpt3sas_base_hard_reset_handler(ioc,
2701 rc = (!rc) ? SUCCESS : FAILED;
2706 /* sync IRQs in case those were busy during flush. */
2707 mpt3sas_base_sync_reply_irqs(ioc);
2709 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2710 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2711 mpi_reply = ioc->tm_cmds.reply;
2712 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2713 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2714 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2715 le32_to_cpu(mpi_reply->IOCLogInfo),
2716 le32_to_cpu(mpi_reply->TerminationCount)));
2717 if (ioc->logging_level & MPT_DEBUG_TM) {
2718 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2719 if (mpi_reply->IOCStatus)
2720 _debug_dump_mf(mpi_request,
2721 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2727 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2728 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2732 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2733 u64 lun, u8 type, u16 smid_task, u16 msix_task,
2734 u8 timeout, u8 tr_method)
2738 mutex_lock(&ioc->tm_cmds.mutex);
2739 ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task,
2740 msix_task, timeout, tr_method);
2741 mutex_unlock(&ioc->tm_cmds.mutex);
2747 * _scsih_tm_display_info - displays info about the device
2748 * @ioc: per adapter struct
2749 * @scmd: pointer to scsi command object
2751 * Called by task management callback handlers.
2754 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2756 struct scsi_target *starget = scmd->device->sdev_target;
2757 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2758 struct _sas_device *sas_device = NULL;
2759 struct _pcie_device *pcie_device = NULL;
2760 unsigned long flags;
2761 char *device_str = NULL;
2765 if (ioc->hide_ir_msg)
2766 device_str = "WarpDrive";
2768 device_str = "volume";
2770 scsi_print_command(scmd);
2771 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2772 starget_printk(KERN_INFO, starget,
2773 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2774 device_str, priv_target->handle,
2775 device_str, (unsigned long long)priv_target->sas_address);
2777 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2778 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2779 pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target);
2781 starget_printk(KERN_INFO, starget,
2782 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2783 pcie_device->handle,
2784 (unsigned long long)pcie_device->wwid,
2785 pcie_device->port_num);
2786 if (pcie_device->enclosure_handle != 0)
2787 starget_printk(KERN_INFO, starget,
2788 "enclosure logical id(0x%016llx), slot(%d)\n",
2789 (unsigned long long)
2790 pcie_device->enclosure_logical_id,
2792 if (pcie_device->connector_name[0] != '\0')
2793 starget_printk(KERN_INFO, starget,
2794 "enclosure level(0x%04x), connector name( %s)\n",
2795 pcie_device->enclosure_level,
2796 pcie_device->connector_name);
2797 pcie_device_put(pcie_device);
2799 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2802 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2803 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2805 if (priv_target->flags &
2806 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2807 starget_printk(KERN_INFO, starget,
2808 "volume handle(0x%04x), "
2809 "volume wwid(0x%016llx)\n",
2810 sas_device->volume_handle,
2811 (unsigned long long)sas_device->volume_wwid);
2813 starget_printk(KERN_INFO, starget,
2814 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2816 (unsigned long long)sas_device->sas_address,
2819 _scsih_display_enclosure_chassis_info(NULL, sas_device,
2822 sas_device_put(sas_device);
2824 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2829 * scsih_abort - eh threads main abort routine
2830 * @scmd: pointer to scsi command object
2832 * Return: SUCCESS if command aborted else FAILED
2835 scsih_abort(struct scsi_cmnd *scmd)
2837 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2838 struct MPT3SAS_DEVICE *sas_device_priv_data;
2839 struct scsiio_tracker *st = scsi_cmd_priv(scmd);
2844 struct _pcie_device *pcie_device = NULL;
2845 sdev_printk(KERN_INFO, scmd->device,
2846 "attempting task abort! scmd(%p)\n", scmd);
2847 _scsih_tm_display_info(ioc, scmd);
2849 sas_device_priv_data = scmd->device->hostdata;
2850 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2852 sdev_printk(KERN_INFO, scmd->device,
2853 "device been deleted! scmd(%p)\n", scmd);
2854 scmd->result = DID_NO_CONNECT << 16;
2855 scmd->scsi_done(scmd);
2860 /* check for completed command */
2861 if (st == NULL || st->cb_idx == 0xFF) {
2862 scmd->result = DID_RESET << 16;
2867 /* for hidden raid components and volumes this is not supported */
2868 if (sas_device_priv_data->sas_target->flags &
2869 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2870 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2871 scmd->result = DID_RESET << 16;
2876 mpt3sas_halt_firmware(ioc);
2878 handle = sas_device_priv_data->sas_target->handle;
2879 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
2880 if (pcie_device && (!ioc->tm_custom_handling))
2881 timeout = ioc->nvme_abort_timeout;
2882 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
2883 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
2884 st->smid, st->msix_io, timeout, 0);
2885 /* Command must be cleared after abort */
2886 if (r == SUCCESS && st->cb_idx != 0xFF)
2889 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2890 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2892 pcie_device_put(pcie_device);
2897 * scsih_dev_reset - eh threads main device reset routine
2898 * @scmd: pointer to scsi command object
2900 * Return: SUCCESS if command aborted else FAILED
2903 scsih_dev_reset(struct scsi_cmnd *scmd)
2905 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2906 struct MPT3SAS_DEVICE *sas_device_priv_data;
2907 struct _sas_device *sas_device = NULL;
2908 struct _pcie_device *pcie_device = NULL;
2914 struct scsi_target *starget = scmd->device->sdev_target;
2915 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2917 sdev_printk(KERN_INFO, scmd->device,
2918 "attempting device reset! scmd(%p)\n", scmd);
2919 _scsih_tm_display_info(ioc, scmd);
2921 sas_device_priv_data = scmd->device->hostdata;
2922 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2924 sdev_printk(KERN_INFO, scmd->device,
2925 "device been deleted! scmd(%p)\n", scmd);
2926 scmd->result = DID_NO_CONNECT << 16;
2927 scmd->scsi_done(scmd);
2932 /* for hidden raid components obtain the volume_handle */
2934 if (sas_device_priv_data->sas_target->flags &
2935 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2936 sas_device = mpt3sas_get_sdev_from_target(ioc,
2939 handle = sas_device->volume_handle;
2941 handle = sas_device_priv_data->sas_target->handle;
2944 scmd->result = DID_RESET << 16;
2949 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
2951 if (pcie_device && (!ioc->tm_custom_handling)) {
2952 tr_timeout = pcie_device->reset_timeout;
2953 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
2955 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
2956 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
2957 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0,
2958 tr_timeout, tr_method);
2959 /* Check for busy commands after reset */
2960 if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
2963 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2964 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2967 sas_device_put(sas_device);
2969 pcie_device_put(pcie_device);
2975 * scsih_target_reset - eh threads main target reset routine
2976 * @scmd: pointer to scsi command object
2978 * Return: SUCCESS if command aborted else FAILED
2981 scsih_target_reset(struct scsi_cmnd *scmd)
2983 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2984 struct MPT3SAS_DEVICE *sas_device_priv_data;
2985 struct _sas_device *sas_device = NULL;
2986 struct _pcie_device *pcie_device = NULL;
2991 struct scsi_target *starget = scmd->device->sdev_target;
2992 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2994 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2996 _scsih_tm_display_info(ioc, scmd);
2998 sas_device_priv_data = scmd->device->hostdata;
2999 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
3001 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
3003 scmd->result = DID_NO_CONNECT << 16;
3004 scmd->scsi_done(scmd);
3009 /* for hidden raid components obtain the volume_handle */
3011 if (sas_device_priv_data->sas_target->flags &
3012 MPT_TARGET_FLAGS_RAID_COMPONENT) {
3013 sas_device = mpt3sas_get_sdev_from_target(ioc,
3016 handle = sas_device->volume_handle;
3018 handle = sas_device_priv_data->sas_target->handle;
3021 scmd->result = DID_RESET << 16;
3026 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
3028 if (pcie_device && (!ioc->tm_custom_handling)) {
3029 tr_timeout = pcie_device->reset_timeout;
3030 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3032 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3033 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0,
3034 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0,
3035 tr_timeout, tr_method);
3036 /* Check for busy commands after reset */
3037 if (r == SUCCESS && atomic_read(&starget->target_busy))
3040 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
3041 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3044 sas_device_put(sas_device);
3046 pcie_device_put(pcie_device);
3052 * scsih_host_reset - eh threads main host reset routine
3053 * @scmd: pointer to scsi command object
3055 * Return: SUCCESS if command aborted else FAILED
3058 scsih_host_reset(struct scsi_cmnd *scmd)
3060 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3063 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
3065 scsi_print_command(scmd);
3067 if (ioc->is_driver_loading || ioc->remove_host) {
3068 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
3074 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3075 r = (retval < 0) ? FAILED : SUCCESS;
3077 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
3078 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3084 * _scsih_fw_event_add - insert and queue up fw_event
3085 * @ioc: per adapter object
3086 * @fw_event: object describing the event
3087 * Context: This function will acquire ioc->fw_event_lock.
3089 * This adds the firmware event object into link list, then queues it up to
3090 * be processed from user context.
3093 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
3095 unsigned long flags;
3097 if (ioc->firmware_event_thread == NULL)
3100 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3101 fw_event_work_get(fw_event);
3102 INIT_LIST_HEAD(&fw_event->list);
3103 list_add_tail(&fw_event->list, &ioc->fw_event_list);
3104 INIT_WORK(&fw_event->work, _firmware_event_work);
3105 fw_event_work_get(fw_event);
3106 queue_work(ioc->firmware_event_thread, &fw_event->work);
3107 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3111 * _scsih_fw_event_del_from_list - delete fw_event from the list
3112 * @ioc: per adapter object
3113 * @fw_event: object describing the event
3114 * Context: This function will acquire ioc->fw_event_lock.
3116 * If the fw_event is on the fw_event_list, remove it and do a put.
3119 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
3122 unsigned long flags;
3124 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3125 if (!list_empty(&fw_event->list)) {
3126 list_del_init(&fw_event->list);
3127 fw_event_work_put(fw_event);
3129 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3134 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3135 * @ioc: per adapter object
3136 * @event_data: trigger event data
3139 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
3140 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
3142 struct fw_event_work *fw_event;
3145 if (ioc->is_driver_loading)
3147 sz = sizeof(*event_data);
3148 fw_event = alloc_fw_event_work(sz);
3151 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
3152 fw_event->ioc = ioc;
3153 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
3154 _scsih_fw_event_add(ioc, fw_event);
3155 fw_event_work_put(fw_event);
3159 * _scsih_error_recovery_delete_devices - remove devices not responding
3160 * @ioc: per adapter object
3163 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
3165 struct fw_event_work *fw_event;
3167 if (ioc->is_driver_loading)
3169 fw_event = alloc_fw_event_work(0);
3172 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
3173 fw_event->ioc = ioc;
3174 _scsih_fw_event_add(ioc, fw_event);
3175 fw_event_work_put(fw_event);
3179 * mpt3sas_port_enable_complete - port enable completed (fake event)
3180 * @ioc: per adapter object
3183 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
3185 struct fw_event_work *fw_event;
3187 fw_event = alloc_fw_event_work(0);
3190 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
3191 fw_event->ioc = ioc;
3192 _scsih_fw_event_add(ioc, fw_event);
3193 fw_event_work_put(fw_event);
3196 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
3198 unsigned long flags;
3199 struct fw_event_work *fw_event = NULL;
3201 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3202 if (!list_empty(&ioc->fw_event_list)) {
3203 fw_event = list_first_entry(&ioc->fw_event_list,
3204 struct fw_event_work, list);
3205 list_del_init(&fw_event->list);
3207 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3213 * _scsih_fw_event_cleanup_queue - cleanup event queue
3214 * @ioc: per adapter object
3216 * Walk the firmware event queue, either killing timers, or waiting
3217 * for outstanding events to complete
3220 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
3222 struct fw_event_work *fw_event;
3224 if (list_empty(&ioc->fw_event_list) ||
3225 !ioc->firmware_event_thread || in_interrupt())
3228 while ((fw_event = dequeue_next_fw_event(ioc))) {
3230 * Wait on the fw_event to complete. If this returns 1, then
3231 * the event was never executed, and we need a put for the
3232 * reference the work had on the fw_event.
3234 * If it did execute, we wait for it to finish, and the put will
3235 * happen from _firmware_event_work()
3237 if (cancel_work_sync(&fw_event->work))
3238 fw_event_work_put(fw_event);
3240 fw_event_work_put(fw_event);
3245 * _scsih_internal_device_block - block the sdev device
3246 * @sdev: per device object
3247 * @sas_device_priv_data : per device driver private data
3249 * make sure device is blocked without error, if not
3253 _scsih_internal_device_block(struct scsi_device *sdev,
3254 struct MPT3SAS_DEVICE *sas_device_priv_data)
3258 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
3259 sas_device_priv_data->sas_target->handle);
3260 sas_device_priv_data->block = 1;
3262 r = scsi_internal_device_block_nowait(sdev);
3264 sdev_printk(KERN_WARNING, sdev,
3265 "device_block failed with return(%d) for handle(0x%04x)\n",
3266 r, sas_device_priv_data->sas_target->handle);
3270 * _scsih_internal_device_unblock - unblock the sdev device
3271 * @sdev: per device object
3272 * @sas_device_priv_data : per device driver private data
3273 * make sure device is unblocked without error, if not retry
3274 * by blocking and then unblocking
3278 _scsih_internal_device_unblock(struct scsi_device *sdev,
3279 struct MPT3SAS_DEVICE *sas_device_priv_data)
3283 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
3284 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
3285 sas_device_priv_data->block = 0;
3286 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3288 /* The device has been set to SDEV_RUNNING by SD layer during
3289 * device addition but the request queue is still stopped by
3290 * our earlier block call. We need to perform a block again
3291 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3293 sdev_printk(KERN_WARNING, sdev,
3294 "device_unblock failed with return(%d) for handle(0x%04x) "
3295 "performing a block followed by an unblock\n",
3296 r, sas_device_priv_data->sas_target->handle);
3297 sas_device_priv_data->block = 1;
3298 r = scsi_internal_device_block_nowait(sdev);
3300 sdev_printk(KERN_WARNING, sdev, "retried device_block "
3301 "failed with return(%d) for handle(0x%04x)\n",
3302 r, sas_device_priv_data->sas_target->handle);
3304 sas_device_priv_data->block = 0;
3305 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3307 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
3308 " failed with return(%d) for handle(0x%04x)\n",
3309 r, sas_device_priv_data->sas_target->handle);
3314 * _scsih_ublock_io_all_device - unblock every device
3315 * @ioc: per adapter object
3317 * change the device state from block to running
3320 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3322 struct MPT3SAS_DEVICE *sas_device_priv_data;
3323 struct scsi_device *sdev;
3325 shost_for_each_device(sdev, ioc->shost) {
3326 sas_device_priv_data = sdev->hostdata;
3327 if (!sas_device_priv_data)
3329 if (!sas_device_priv_data->block)
3332 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3333 "device_running, handle(0x%04x)\n",
3334 sas_device_priv_data->sas_target->handle));
3335 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
3341 * _scsih_ublock_io_device - prepare device to be deleted
3342 * @ioc: per adapter object
3343 * @sas_address: sas address
3345 * unblock then put device in offline state
3348 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
3350 struct MPT3SAS_DEVICE *sas_device_priv_data;
3351 struct scsi_device *sdev;
3353 shost_for_each_device(sdev, ioc->shost) {
3354 sas_device_priv_data = sdev->hostdata;
3355 if (!sas_device_priv_data)
3357 if (sas_device_priv_data->sas_target->sas_address
3360 if (sas_device_priv_data->block)
3361 _scsih_internal_device_unblock(sdev,
3362 sas_device_priv_data);
3367 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3368 * @ioc: per adapter object
3370 * During device pull we need to appropriately set the sdev state.
3373 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3375 struct MPT3SAS_DEVICE *sas_device_priv_data;
3376 struct scsi_device *sdev;
3378 shost_for_each_device(sdev, ioc->shost) {
3379 sas_device_priv_data = sdev->hostdata;
3380 if (!sas_device_priv_data)
3382 if (sas_device_priv_data->block)
3384 if (sas_device_priv_data->ignore_delay_remove) {
3385 sdev_printk(KERN_INFO, sdev,
3386 "%s skip device_block for SES handle(0x%04x)\n",
3387 __func__, sas_device_priv_data->sas_target->handle);
3390 _scsih_internal_device_block(sdev, sas_device_priv_data);
3395 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3396 * @ioc: per adapter object
3397 * @handle: device handle
3399 * During device pull we need to appropriately set the sdev state.
3402 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3404 struct MPT3SAS_DEVICE *sas_device_priv_data;
3405 struct scsi_device *sdev;
3406 struct _sas_device *sas_device;
3408 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
3410 shost_for_each_device(sdev, ioc->shost) {
3411 sas_device_priv_data = sdev->hostdata;
3412 if (!sas_device_priv_data)
3414 if (sas_device_priv_data->sas_target->handle != handle)
3416 if (sas_device_priv_data->block)
3418 if (sas_device && sas_device->pend_sas_rphy_add)
3420 if (sas_device_priv_data->ignore_delay_remove) {
3421 sdev_printk(KERN_INFO, sdev,
3422 "%s skip device_block for SES handle(0x%04x)\n",
3423 __func__, sas_device_priv_data->sas_target->handle);
3426 _scsih_internal_device_block(sdev, sas_device_priv_data);
3430 sas_device_put(sas_device);
3434 * _scsih_block_io_to_children_attached_to_ex
3435 * @ioc: per adapter object
3436 * @sas_expander: the sas_device object
3438 * This routine set sdev state to SDEV_BLOCK for all devices
3439 * attached to this expander. This function called when expander is
3443 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3444 struct _sas_node *sas_expander)
3446 struct _sas_port *mpt3sas_port;
3447 struct _sas_device *sas_device;
3448 struct _sas_node *expander_sibling;
3449 unsigned long flags;
3454 list_for_each_entry(mpt3sas_port,
3455 &sas_expander->sas_port_list, port_list) {
3456 if (mpt3sas_port->remote_identify.device_type ==
3458 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3459 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3460 mpt3sas_port->remote_identify.sas_address);
3462 set_bit(sas_device->handle,
3463 ioc->blocking_handles);
3464 sas_device_put(sas_device);
3466 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3470 list_for_each_entry(mpt3sas_port,
3471 &sas_expander->sas_port_list, port_list) {
3473 if (mpt3sas_port->remote_identify.device_type ==
3474 SAS_EDGE_EXPANDER_DEVICE ||
3475 mpt3sas_port->remote_identify.device_type ==
3476 SAS_FANOUT_EXPANDER_DEVICE) {
3478 mpt3sas_scsih_expander_find_by_sas_address(
3479 ioc, mpt3sas_port->remote_identify.sas_address);
3480 _scsih_block_io_to_children_attached_to_ex(ioc,
3487 * _scsih_block_io_to_children_attached_directly
3488 * @ioc: per adapter object
3489 * @event_data: topology change event data
3491 * This routine set sdev state to SDEV_BLOCK for all devices
3492 * direct attached during device pull.
3495 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3496 Mpi2EventDataSasTopologyChangeList_t *event_data)
3502 for (i = 0; i < event_data->NumEntries; i++) {
3503 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3506 reason_code = event_data->PHY[i].PhyStatus &
3507 MPI2_EVENT_SAS_TOPO_RC_MASK;
3508 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3509 _scsih_block_io_device(ioc, handle);
3514 * _scsih_block_io_to_pcie_children_attached_directly
3515 * @ioc: per adapter object
3516 * @event_data: topology change event data
3518 * This routine set sdev state to SDEV_BLOCK for all devices
3519 * direct attached during device pull/reconnect.
3522 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3523 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
3529 for (i = 0; i < event_data->NumEntries; i++) {
3531 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
3534 reason_code = event_data->PortEntry[i].PortStatus;
3536 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING)
3537 _scsih_block_io_device(ioc, handle);
3541 * _scsih_tm_tr_send - send task management request
3542 * @ioc: per adapter object
3543 * @handle: device handle
3544 * Context: interrupt time.
3546 * This code is to initiate the device removal handshake protocol
3547 * with controller firmware. This function will issue target reset
3548 * using high priority request queue. It will send a sas iounit
3549 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3551 * This is designed to send muliple task management request at the same
3552 * time to the fifo. If the fifo is full, we will append the request,
3553 * and process it in a future completion.
3556 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3558 Mpi2SCSITaskManagementRequest_t *mpi_request;
3560 struct _sas_device *sas_device = NULL;
3561 struct _pcie_device *pcie_device = NULL;
3562 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3563 u64 sas_address = 0;
3564 unsigned long flags;
3565 struct _tr_list *delayed_tr;
3569 if (ioc->pci_error_recovery) {
3570 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3571 "%s: host in pci error recovery: handle(0x%04x)\n",
3572 __func__, ioc->name,
3576 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3577 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3578 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3579 "%s: host is not operational: handle(0x%04x)\n",
3580 __func__, ioc->name,
3585 /* if PD, then return */
3586 if (test_bit(handle, ioc->pd_handles))
3589 clear_bit(handle, ioc->pend_os_device_add);
3591 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3592 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3593 if (sas_device && sas_device->starget &&
3594 sas_device->starget->hostdata) {
3595 sas_target_priv_data = sas_device->starget->hostdata;
3596 sas_target_priv_data->deleted = 1;
3597 sas_address = sas_device->sas_address;
3599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3601 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
3602 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
3603 if (pcie_device && pcie_device->starget &&
3604 pcie_device->starget->hostdata) {
3605 sas_target_priv_data = pcie_device->starget->hostdata;
3606 sas_target_priv_data->deleted = 1;
3607 sas_address = pcie_device->wwid;
3609 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
3610 if (pcie_device && (!ioc->tm_custom_handling))
3612 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3614 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3616 if (sas_target_priv_data) {
3617 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3618 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3620 (unsigned long long)sas_address));
3622 if (sas_device->enclosure_handle != 0)
3623 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3624 "setting delete flag:enclosure logical "
3625 "id(0x%016llx), slot(%d)\n", ioc->name,
3626 (unsigned long long)
3627 sas_device->enclosure_logical_id,
3629 if (sas_device->connector_name[0] != '\0')
3630 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3631 "setting delete flag: enclosure "
3632 "level(0x%04x), connector name( %s)\n",
3633 ioc->name, sas_device->enclosure_level,
3634 sas_device->connector_name));
3635 } else if (pcie_device) {
3636 if (pcie_device->enclosure_handle != 0)
3637 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3638 "setting delete flag: logical "
3639 "id(0x%016llx), slot(%d)\n", ioc->name,
3640 (unsigned long long)
3641 pcie_device->enclosure_logical_id,
3642 pcie_device->slot));
3643 if (pcie_device->connector_name[0] != '\0')
3644 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3645 "setting delete flag:, enclosure "
3647 "connector name( %s)\n", ioc->name,
3648 pcie_device->enclosure_level,
3649 pcie_device->connector_name));
3651 _scsih_ublock_io_device(ioc, sas_address);
3652 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3655 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3657 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3660 INIT_LIST_HEAD(&delayed_tr->list);
3661 delayed_tr->handle = handle;
3662 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3663 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3664 "DELAYED:tr:handle(0x%04x), (open)\n",
3665 ioc->name, handle));
3669 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3670 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3671 ioc->name, handle, smid,
3672 ioc->tm_tr_cb_idx));
3673 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3674 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3675 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3676 mpi_request->DevHandle = cpu_to_le16(handle);
3677 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3678 mpi_request->MsgFlags = tr_method;
3679 set_bit(handle, ioc->device_remove_in_progress);
3680 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3681 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3685 sas_device_put(sas_device);
3687 pcie_device_put(pcie_device);
3691 * _scsih_tm_tr_complete -
3692 * @ioc: per adapter object
3693 * @smid: system request message index
3694 * @msix_index: MSIX table index supplied by the OS
3695 * @reply: reply message frame(lower 32bit addr)
3696 * Context: interrupt time.
3698 * This is the target reset completion routine.
3699 * This code is part of the code to initiate the device removal
3700 * handshake protocol with controller firmware.
3701 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3703 * Return: 1 meaning mf should be freed from _base_interrupt
3704 * 0 means the mf is freed from this function.
3707 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3711 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3712 Mpi2SCSITaskManagementReply_t *mpi_reply =
3713 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3714 Mpi2SasIoUnitControlRequest_t *mpi_request;
3717 struct _sc_list *delayed_sc;
3719 if (ioc->pci_error_recovery) {
3720 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3721 "%s: host in pci error recovery\n", __func__,
3725 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3726 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3727 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3728 "%s: host is not operational\n", __func__, ioc->name));
3731 if (unlikely(!mpi_reply)) {
3732 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3733 ioc->name, __FILE__, __LINE__, __func__);
3736 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3737 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3738 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3739 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3740 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3742 le16_to_cpu(mpi_reply->DevHandle), smid));
3746 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3747 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3748 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3749 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3750 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3751 le32_to_cpu(mpi_reply->IOCLogInfo),
3752 le32_to_cpu(mpi_reply->TerminationCount)));
3754 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3755 if (!smid_sas_ctrl) {
3756 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3758 return _scsih_check_for_pending_tm(ioc, smid);
3759 INIT_LIST_HEAD(&delayed_sc->list);
3760 delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle);
3761 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3762 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3763 "DELAYED:sc:handle(0x%04x), (open)\n",
3764 ioc->name, handle));
3765 return _scsih_check_for_pending_tm(ioc, smid);
3768 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3769 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3770 ioc->name, handle, smid_sas_ctrl,
3771 ioc->tm_sas_control_cb_idx));
3772 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3773 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3774 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3775 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3776 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3777 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3779 return _scsih_check_for_pending_tm(ioc, smid);
3784 * _scsih_sas_control_complete - completion routine
3785 * @ioc: per adapter object
3786 * @smid: system request message index
3787 * @msix_index: MSIX table index supplied by the OS
3788 * @reply: reply message frame(lower 32bit addr)
3789 * Context: interrupt time.
3791 * This is the sas iounit control completion routine.
3792 * This code is part of the code to initiate the device removal
3793 * handshake protocol with controller firmware.
3795 * Return: 1 meaning mf should be freed from _base_interrupt
3796 * 0 means the mf is freed from this function.
3799 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3800 u8 msix_index, u32 reply)
3802 Mpi2SasIoUnitControlReply_t *mpi_reply =
3803 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3805 if (likely(mpi_reply)) {
3806 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3807 "sc_complete:handle(0x%04x), (open) "
3808 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3809 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3810 le16_to_cpu(mpi_reply->IOCStatus),
3811 le32_to_cpu(mpi_reply->IOCLogInfo)));
3812 if (le16_to_cpu(mpi_reply->IOCStatus) ==
3813 MPI2_IOCSTATUS_SUCCESS) {
3814 clear_bit(le16_to_cpu(mpi_reply->DevHandle),
3815 ioc->device_remove_in_progress);
3818 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3819 ioc->name, __FILE__, __LINE__, __func__);
3821 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3825 * _scsih_tm_tr_volume_send - send target reset request for volumes
3826 * @ioc: per adapter object
3827 * @handle: device handle
3828 * Context: interrupt time.
3830 * This is designed to send muliple task management request at the same
3831 * time to the fifo. If the fifo is full, we will append the request,
3832 * and process it in a future completion.
3835 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3837 Mpi2SCSITaskManagementRequest_t *mpi_request;
3839 struct _tr_list *delayed_tr;
3841 if (ioc->pci_error_recovery) {
3842 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3843 "%s: host reset in progress!\n",
3844 __func__, ioc->name));
3848 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3850 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3853 INIT_LIST_HEAD(&delayed_tr->list);
3854 delayed_tr->handle = handle;
3855 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3856 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3857 "DELAYED:tr:handle(0x%04x), (open)\n",
3858 ioc->name, handle));
3862 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3863 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3864 ioc->name, handle, smid,
3865 ioc->tm_tr_volume_cb_idx));
3866 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3867 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3868 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3869 mpi_request->DevHandle = cpu_to_le16(handle);
3870 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3871 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3875 * _scsih_tm_volume_tr_complete - target reset completion
3876 * @ioc: per adapter object
3877 * @smid: system request message index
3878 * @msix_index: MSIX table index supplied by the OS
3879 * @reply: reply message frame(lower 32bit addr)
3880 * Context: interrupt time.
3882 * Return: 1 meaning mf should be freed from _base_interrupt
3883 * 0 means the mf is freed from this function.
3886 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3887 u8 msix_index, u32 reply)
3890 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3891 Mpi2SCSITaskManagementReply_t *mpi_reply =
3892 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3894 if (ioc->shost_recovery || ioc->pci_error_recovery) {
3895 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3896 "%s: host reset in progress!\n",
3897 __func__, ioc->name));
3900 if (unlikely(!mpi_reply)) {
3901 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3902 ioc->name, __FILE__, __LINE__, __func__);
3906 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3907 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3908 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3909 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3910 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3912 le16_to_cpu(mpi_reply->DevHandle), smid));
3916 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3917 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3918 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3919 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3920 le32_to_cpu(mpi_reply->IOCLogInfo),
3921 le32_to_cpu(mpi_reply->TerminationCount)));
3923 return _scsih_check_for_pending_tm(ioc, smid);
3927 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3928 * @ioc: per adapter object
3929 * @smid: system request message index
3931 * @event_context: used to track events uniquely
3933 * Context - processed in interrupt context.
3936 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event,
3939 Mpi2EventAckRequest_t *ack_request;
3940 int i = smid - ioc->internal_smid;
3941 unsigned long flags;
3943 /* Without releasing the smid just update the
3944 * call back index and reuse the same smid for
3945 * processing this delayed request
3947 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3948 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3949 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3951 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3952 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3953 ioc->name, le16_to_cpu(event), smid,
3955 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
3956 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
3957 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
3958 ack_request->Event = event;
3959 ack_request->EventContext = event_context;
3960 ack_request->VF_ID = 0; /* TODO */
3961 ack_request->VP_ID = 0;
3962 mpt3sas_base_put_smid_default(ioc, smid);
3966 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3967 * sas_io_unit_ctrl messages
3968 * @ioc: per adapter object
3969 * @smid: system request message index
3970 * @handle: device handle
3972 * Context - processed in interrupt context.
3975 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
3976 u16 smid, u16 handle)
3978 Mpi2SasIoUnitControlRequest_t *mpi_request;
3980 int i = smid - ioc->internal_smid;
3981 unsigned long flags;
3983 if (ioc->remove_host) {
3984 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3985 "%s: host has been removed\n",
3986 __func__, ioc->name));
3988 } else if (ioc->pci_error_recovery) {
3989 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3990 "%s: host in pci error recovery\n",
3991 __func__, ioc->name));
3994 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3995 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3996 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3997 "%s: host is not operational\n",
3998 __func__, ioc->name));
4002 /* Without releasing the smid just update the
4003 * call back index and reuse the same smid for
4004 * processing this delayed request
4006 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4007 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
4008 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4010 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4011 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4012 ioc->name, handle, smid,
4013 ioc->tm_sas_control_cb_idx));
4014 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4015 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
4016 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
4017 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
4018 mpi_request->DevHandle = cpu_to_le16(handle);
4019 mpt3sas_base_put_smid_default(ioc, smid);
4023 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4024 * @ioc: per adapter object
4025 * @smid: system request message index
4027 * Context: Executed in interrupt context
4029 * This will check delayed internal messages list, and process the
4032 * Return: 1 meaning mf should be freed from _base_interrupt
4033 * 0 means the mf is freed from this function.
4036 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4038 struct _sc_list *delayed_sc;
4039 struct _event_ack_list *delayed_event_ack;
4041 if (!list_empty(&ioc->delayed_event_ack_list)) {
4042 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
4043 struct _event_ack_list, list);
4044 _scsih_issue_delayed_event_ack(ioc, smid,
4045 delayed_event_ack->Event, delayed_event_ack->EventContext);
4046 list_del(&delayed_event_ack->list);
4047 kfree(delayed_event_ack);
4051 if (!list_empty(&ioc->delayed_sc_list)) {
4052 delayed_sc = list_entry(ioc->delayed_sc_list.next,
4053 struct _sc_list, list);
4054 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
4055 delayed_sc->handle);
4056 list_del(&delayed_sc->list);
4064 * _scsih_check_for_pending_tm - check for pending task management
4065 * @ioc: per adapter object
4066 * @smid: system request message index
4068 * This will check delayed target reset list, and feed the
4071 * Return: 1 meaning mf should be freed from _base_interrupt
4072 * 0 means the mf is freed from this function.
4075 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4077 struct _tr_list *delayed_tr;
4079 if (!list_empty(&ioc->delayed_tr_volume_list)) {
4080 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
4081 struct _tr_list, list);
4082 mpt3sas_base_free_smid(ioc, smid);
4083 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
4084 list_del(&delayed_tr->list);
4089 if (!list_empty(&ioc->delayed_tr_list)) {
4090 delayed_tr = list_entry(ioc->delayed_tr_list.next,
4091 struct _tr_list, list);
4092 mpt3sas_base_free_smid(ioc, smid);
4093 _scsih_tm_tr_send(ioc, delayed_tr->handle);
4094 list_del(&delayed_tr->list);
4103 * _scsih_check_topo_delete_events - sanity check on topo events
4104 * @ioc: per adapter object
4105 * @event_data: the event data payload
4107 * This routine added to better handle cable breaker.
4109 * This handles the case where driver receives multiple expander
4110 * add and delete events in a single shot. When there is a delete event
4111 * the routine will void any pending add events waiting in the event queue.
4114 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
4115 Mpi2EventDataSasTopologyChangeList_t *event_data)
4117 struct fw_event_work *fw_event;
4118 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
4119 u16 expander_handle;
4120 struct _sas_node *sas_expander;
4121 unsigned long flags;
4125 for (i = 0 ; i < event_data->NumEntries; i++) {
4126 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4129 reason_code = event_data->PHY[i].PhyStatus &
4130 MPI2_EVENT_SAS_TOPO_RC_MASK;
4131 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
4132 _scsih_tm_tr_send(ioc, handle);
4135 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
4136 if (expander_handle < ioc->sas_hba.num_phys) {
4137 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4140 if (event_data->ExpStatus ==
4141 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
4142 /* put expander attached devices into blocking state */
4143 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4144 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
4146 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
4147 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4149 handle = find_first_bit(ioc->blocking_handles,
4150 ioc->facts.MaxDevHandle);
4151 if (handle < ioc->facts.MaxDevHandle)
4152 _scsih_block_io_device(ioc, handle);
4153 } while (test_and_clear_bit(handle, ioc->blocking_handles));
4154 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
4155 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4157 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4160 /* mark ignore flag for pending events */
4161 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4162 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4163 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
4166 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
4167 fw_event->event_data;
4168 if (local_event_data->ExpStatus ==
4169 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4170 local_event_data->ExpStatus ==
4171 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4172 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
4174 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4175 "setting ignoring flag\n", ioc->name));
4176 fw_event->ignore = 1;
4180 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4184 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4186 * @ioc: per adapter object
4187 * @event_data: the event data payload
4189 * This handles the case where driver receives multiple switch
4190 * or device add and delete events in a single shot. When there
4191 * is a delete event the routine will void any pending add
4192 * events waiting in the event queue.
4195 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc,
4196 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
4198 struct fw_event_work *fw_event;
4199 Mpi26EventDataPCIeTopologyChangeList_t *local_event_data;
4200 unsigned long flags;
4202 u16 handle, switch_handle;
4204 for (i = 0; i < event_data->NumEntries; i++) {
4206 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
4209 reason_code = event_data->PortEntry[i].PortStatus;
4210 if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING)
4211 _scsih_tm_tr_send(ioc, handle);
4214 switch_handle = le16_to_cpu(event_data->SwitchDevHandle);
4215 if (!switch_handle) {
4216 _scsih_block_io_to_pcie_children_attached_directly(
4220 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4221 if ((event_data->SwitchStatus
4222 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) ||
4223 (event_data->SwitchStatus ==
4224 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING))
4225 _scsih_block_io_to_pcie_children_attached_directly(
4228 if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4231 /* mark ignore flag for pending events */
4232 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4233 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4234 if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
4238 (Mpi26EventDataPCIeTopologyChangeList_t *)
4239 fw_event->event_data;
4240 if (local_event_data->SwitchStatus ==
4241 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4242 local_event_data->SwitchStatus ==
4243 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4244 if (le16_to_cpu(local_event_data->SwitchDevHandle) ==
4246 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4247 "setting ignoring flag for switch event\n",
4249 fw_event->ignore = 1;
4253 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4257 * _scsih_set_volume_delete_flag - setting volume delete flag
4258 * @ioc: per adapter object
4259 * @handle: device handle
4261 * This returns nothing.
4264 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4266 struct _raid_device *raid_device;
4267 struct MPT3SAS_TARGET *sas_target_priv_data;
4268 unsigned long flags;
4270 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4271 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
4272 if (raid_device && raid_device->starget &&
4273 raid_device->starget->hostdata) {
4274 sas_target_priv_data =
4275 raid_device->starget->hostdata;
4276 sas_target_priv_data->deleted = 1;
4277 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4278 "setting delete flag: handle(0x%04x), "
4279 "wwid(0x%016llx)\n", ioc->name, handle,
4280 (unsigned long long) raid_device->wwid));
4282 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4286 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4287 * @handle: input handle
4288 * @a: handle for volume a
4289 * @b: handle for volume b
4291 * IR firmware only supports two raid volumes. The purpose of this
4292 * routine is to set the volume handle in either a or b. When the given
4293 * input handle is non-zero, or when a and b have not been set before.
4296 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
4298 if (!handle || handle == *a || handle == *b)
4307 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4308 * @ioc: per adapter object
4309 * @event_data: the event data payload
4310 * Context: interrupt time.
4312 * This routine will send target reset to volume, followed by target
4313 * resets to the PDs. This is called when a PD has been removed, or
4314 * volume has been deleted or removed. When the target reset is sent
4315 * to volume, the PD target resets need to be queued to start upon
4316 * completion of the volume target reset.
4319 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
4320 Mpi2EventDataIrConfigChangeList_t *event_data)
4322 Mpi2EventIrConfigElement_t *element;
4324 u16 handle, volume_handle, a, b;
4325 struct _tr_list *delayed_tr;
4330 if (ioc->is_warpdrive)
4333 /* Volume Resets for Deleted or Removed */
4334 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4335 for (i = 0; i < event_data->NumElements; i++, element++) {
4336 if (le32_to_cpu(event_data->Flags) &
4337 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4339 if (element->ReasonCode ==
4340 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
4341 element->ReasonCode ==
4342 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
4343 volume_handle = le16_to_cpu(element->VolDevHandle);
4344 _scsih_set_volume_delete_flag(ioc, volume_handle);
4345 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4349 /* Volume Resets for UNHIDE events */
4350 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4351 for (i = 0; i < event_data->NumElements; i++, element++) {
4352 if (le32_to_cpu(event_data->Flags) &
4353 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4355 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
4356 volume_handle = le16_to_cpu(element->VolDevHandle);
4357 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4362 _scsih_tm_tr_volume_send(ioc, a);
4364 _scsih_tm_tr_volume_send(ioc, b);
4366 /* PD target resets */
4367 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4368 for (i = 0; i < event_data->NumElements; i++, element++) {
4369 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
4371 handle = le16_to_cpu(element->PhysDiskDevHandle);
4372 volume_handle = le16_to_cpu(element->VolDevHandle);
4373 clear_bit(handle, ioc->pd_handles);
4375 _scsih_tm_tr_send(ioc, handle);
4376 else if (volume_handle == a || volume_handle == b) {
4377 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
4378 BUG_ON(!delayed_tr);
4379 INIT_LIST_HEAD(&delayed_tr->list);
4380 delayed_tr->handle = handle;
4381 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
4382 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4383 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
4386 _scsih_tm_tr_send(ioc, handle);
4392 * _scsih_check_volume_delete_events - set delete flag for volumes
4393 * @ioc: per adapter object
4394 * @event_data: the event data payload
4395 * Context: interrupt time.
4397 * This will handle the case when the cable connected to entire volume is
4398 * pulled. We will take care of setting the deleted flag so normal IO will
4402 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
4403 Mpi2EventDataIrVolume_t *event_data)
4407 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4409 state = le32_to_cpu(event_data->NewValue);
4410 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
4411 MPI2_RAID_VOL_STATE_FAILED)
4412 _scsih_set_volume_delete_flag(ioc,
4413 le16_to_cpu(event_data->VolDevHandle));
4417 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4418 * @ioc: per adapter object
4419 * @event_data: the temp threshold event data
4420 * Context: interrupt time.
4423 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
4424 Mpi2EventDataTemperature_t *event_data)
4426 if (ioc->temp_sensors_count >= event_data->SensorNum) {
4427 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
4428 " exceeded for Sensor: %d !!!\n", ioc->name,
4429 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
4430 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
4431 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
4432 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
4433 event_data->SensorNum);
4434 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
4435 ioc->name, event_data->CurrentTemperature);
4439 static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
4441 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
4443 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
4447 return test_and_set_bit(0, &priv->ata_command_pending);
4449 clear_bit(0, &priv->ata_command_pending);
4454 * _scsih_flush_running_cmds - completing outstanding commands.
4455 * @ioc: per adapter object
4457 * The flushing out of all pending scmd commands following host reset,
4458 * where all IO is dropped to the floor.
4461 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
4463 struct scsi_cmnd *scmd;
4464 struct scsiio_tracker *st;
4468 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
4469 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
4473 _scsih_set_satl_pending(scmd, false);
4474 st = scsi_cmd_priv(scmd);
4475 mpt3sas_base_clear_st(ioc, st);
4476 scsi_dma_unmap(scmd);
4477 if (ioc->pci_error_recovery || ioc->remove_host)
4478 scmd->result = DID_NO_CONNECT << 16;
4480 scmd->result = DID_RESET << 16;
4481 scmd->scsi_done(scmd);
4483 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
4488 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4489 * @ioc: per adapter object
4490 * @scmd: pointer to scsi command object
4491 * @mpi_request: pointer to the SCSI_IO request message frame
4493 * Supporting protection 1 and 3.
4496 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4497 Mpi25SCSIIORequest_t *mpi_request)
4500 unsigned char prot_op = scsi_get_prot_op(scmd);
4501 unsigned char prot_type = scsi_get_prot_type(scmd);
4502 Mpi25SCSIIORequest_t *mpi_request_3v =
4503 (Mpi25SCSIIORequest_t *)mpi_request;
4505 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
4508 if (prot_op == SCSI_PROT_READ_STRIP)
4509 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
4510 else if (prot_op == SCSI_PROT_WRITE_INSERT)
4511 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
4515 switch (prot_type) {
4516 case SCSI_PROT_DIF_TYPE1:
4517 case SCSI_PROT_DIF_TYPE2:
4520 * enable ref/guard checking
4521 * auto increment ref tag
4523 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
4524 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
4525 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4526 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
4527 cpu_to_be32(t10_pi_ref_tag(scmd->request));
4530 case SCSI_PROT_DIF_TYPE3:
4533 * enable guard checking
4535 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4540 mpi_request_3v->EEDPBlockSize =
4541 cpu_to_le16(scmd->device->sector_size);
4543 if (ioc->is_gen35_ioc)
4544 eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
4545 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
4549 * _scsih_eedp_error_handling - return sense code for EEDP errors
4550 * @scmd: pointer to scsi command object
4551 * @ioc_status: ioc status
4554 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4558 switch (ioc_status) {
4559 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4562 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4565 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4572 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4574 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4575 SAM_STAT_CHECK_CONDITION;
4579 * scsih_qcmd - main scsi request entry point
4580 * @shost: SCSI host pointer
4581 * @scmd: pointer to scsi command object
4583 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4585 * Return: 0 on success. If there's a failure, return either:
4586 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4587 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4590 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4592 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4593 struct MPT3SAS_DEVICE *sas_device_priv_data;
4594 struct MPT3SAS_TARGET *sas_target_priv_data;
4595 struct _raid_device *raid_device;
4596 struct request *rq = scmd->request;
4598 Mpi25SCSIIORequest_t *mpi_request;
4599 struct _pcie_device *pcie_device = NULL;
4604 if (ioc->logging_level & MPT_DEBUG_SCSI)
4605 scsi_print_command(scmd);
4607 sas_device_priv_data = scmd->device->hostdata;
4608 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4609 scmd->result = DID_NO_CONNECT << 16;
4610 scmd->scsi_done(scmd);
4614 if (ioc->pci_error_recovery || ioc->remove_host) {
4615 scmd->result = DID_NO_CONNECT << 16;
4616 scmd->scsi_done(scmd);
4620 sas_target_priv_data = sas_device_priv_data->sas_target;
4622 /* invalid device handle */
4623 handle = sas_target_priv_data->handle;
4624 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4625 scmd->result = DID_NO_CONNECT << 16;
4626 scmd->scsi_done(scmd);
4631 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
4632 /* host recovery or link resets sent via IOCTLs */
4633 return SCSI_MLQUEUE_HOST_BUSY;
4634 } else if (sas_target_priv_data->deleted) {
4635 /* device has been deleted */
4636 scmd->result = DID_NO_CONNECT << 16;
4637 scmd->scsi_done(scmd);
4639 } else if (sas_target_priv_data->tm_busy ||
4640 sas_device_priv_data->block) {
4641 /* device busy with task management */
4642 return SCSI_MLQUEUE_DEVICE_BUSY;
4646 * Bug work around for firmware SATL handling. The loop
4647 * is based on atomic operations and ensures consistency
4648 * since we're lockless at this point
4651 if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
4652 scmd->result = SAM_STAT_BUSY;
4653 scmd->scsi_done(scmd);
4656 } while (_scsih_set_satl_pending(scmd, true));
4658 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4659 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4660 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4661 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4663 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4666 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4667 /* NCQ Prio supported, make sure control indicated high priority */
4668 if (sas_device_priv_data->ncq_prio_enable) {
4669 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
4670 if (class == IOPRIO_CLASS_RT)
4671 mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
4673 /* Make sure Device is not raid volume.
4674 * We do not expose raid functionality to upper layer for warpdrive.
4676 if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev))
4677 && !scsih_is_nvme(&scmd->device->sdev_gendev))
4678 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4679 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4681 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4683 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
4684 ioc->name, __func__);
4685 _scsih_set_satl_pending(scmd, false);
4688 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4689 memset(mpi_request, 0, ioc->request_sz);
4690 _scsih_setup_eedp(ioc, scmd, mpi_request);
4692 if (scmd->cmd_len == 32)
4693 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4694 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4695 if (sas_device_priv_data->sas_target->flags &
4696 MPT_TARGET_FLAGS_RAID_COMPONENT)
4697 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4699 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4700 mpi_request->DevHandle = cpu_to_le16(handle);
4701 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4702 mpi_request->Control = cpu_to_le32(mpi_control);
4703 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4704 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4705 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4706 mpi_request->SenseBufferLowAddress =
4707 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4708 mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4;
4709 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4711 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4713 if (mpi_request->DataLength) {
4714 pcie_device = sas_target_priv_data->pcie_dev;
4715 if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) {
4716 mpt3sas_base_free_smid(ioc, smid);
4717 _scsih_set_satl_pending(scmd, false);
4721 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4723 raid_device = sas_target_priv_data->raid_device;
4724 if (raid_device && raid_device->direct_io_enabled)
4725 mpt3sas_setup_direct_io(ioc, scmd,
4726 raid_device, mpi_request);
4728 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4729 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4730 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4731 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4732 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
4734 ioc->put_smid_scsi_io(ioc, smid,
4735 le16_to_cpu(mpi_request->DevHandle));
4737 mpt3sas_base_put_smid_default(ioc, smid);
4741 return SCSI_MLQUEUE_HOST_BUSY;
4745 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4746 * @sense_buffer: sense data returned by target
4747 * @data: normalized skey/asc/ascq
4750 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4752 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4753 /* descriptor format */
4754 data->skey = sense_buffer[1] & 0x0F;
4755 data->asc = sense_buffer[2];
4756 data->ascq = sense_buffer[3];
4759 data->skey = sense_buffer[2] & 0x0F;
4760 data->asc = sense_buffer[12];
4761 data->ascq = sense_buffer[13];
4766 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4767 * @ioc: per adapter object
4768 * @scmd: pointer to scsi command object
4769 * @mpi_reply: reply mf payload returned from firmware
4772 * scsi_status - SCSI Status code returned from target device
4773 * scsi_state - state info associated with SCSI_IO determined by ioc
4774 * ioc_status - ioc supplied status info
4777 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4778 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4782 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4783 MPI2_IOCSTATUS_MASK;
4784 u8 scsi_state = mpi_reply->SCSIState;
4785 u8 scsi_status = mpi_reply->SCSIStatus;
4786 char *desc_ioc_state = NULL;
4787 char *desc_scsi_status = NULL;
4788 char *desc_scsi_state = ioc->tmp_string;
4789 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4790 struct _sas_device *sas_device = NULL;
4791 struct _pcie_device *pcie_device = NULL;
4792 struct scsi_target *starget = scmd->device->sdev_target;
4793 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4794 char *device_str = NULL;
4798 if (ioc->hide_ir_msg)
4799 device_str = "WarpDrive";
4801 device_str = "volume";
4803 if (log_info == 0x31170000)
4806 switch (ioc_status) {
4807 case MPI2_IOCSTATUS_SUCCESS:
4808 desc_ioc_state = "success";
4810 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4811 desc_ioc_state = "invalid function";
4813 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4814 desc_ioc_state = "scsi recovered error";
4816 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4817 desc_ioc_state = "scsi invalid dev handle";
4819 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4820 desc_ioc_state = "scsi device not there";
4822 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4823 desc_ioc_state = "scsi data overrun";
4825 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4826 desc_ioc_state = "scsi data underrun";
4828 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4829 desc_ioc_state = "scsi io data error";
4831 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4832 desc_ioc_state = "scsi protocol error";
4834 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4835 desc_ioc_state = "scsi task terminated";
4837 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4838 desc_ioc_state = "scsi residual mismatch";
4840 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4841 desc_ioc_state = "scsi task mgmt failed";
4843 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4844 desc_ioc_state = "scsi ioc terminated";
4846 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4847 desc_ioc_state = "scsi ext terminated";
4849 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4850 desc_ioc_state = "eedp guard error";
4852 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4853 desc_ioc_state = "eedp ref tag error";
4855 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4856 desc_ioc_state = "eedp app tag error";
4858 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4859 desc_ioc_state = "insufficient power";
4862 desc_ioc_state = "unknown";
4866 switch (scsi_status) {
4867 case MPI2_SCSI_STATUS_GOOD:
4868 desc_scsi_status = "good";
4870 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4871 desc_scsi_status = "check condition";
4873 case MPI2_SCSI_STATUS_CONDITION_MET:
4874 desc_scsi_status = "condition met";
4876 case MPI2_SCSI_STATUS_BUSY:
4877 desc_scsi_status = "busy";
4879 case MPI2_SCSI_STATUS_INTERMEDIATE:
4880 desc_scsi_status = "intermediate";
4882 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4883 desc_scsi_status = "intermediate condmet";
4885 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4886 desc_scsi_status = "reservation conflict";
4888 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4889 desc_scsi_status = "command terminated";
4891 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4892 desc_scsi_status = "task set full";
4894 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4895 desc_scsi_status = "aca active";
4897 case MPI2_SCSI_STATUS_TASK_ABORTED:
4898 desc_scsi_status = "task aborted";
4901 desc_scsi_status = "unknown";
4905 desc_scsi_state[0] = '\0';
4907 desc_scsi_state = " ";
4908 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4909 strcat(desc_scsi_state, "response info ");
4910 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4911 strcat(desc_scsi_state, "state terminated ");
4912 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4913 strcat(desc_scsi_state, "no status ");
4914 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4915 strcat(desc_scsi_state, "autosense failed ");
4916 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4917 strcat(desc_scsi_state, "autosense valid ");
4919 scsi_print_command(scmd);
4921 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4922 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4923 device_str, (unsigned long long)priv_target->sas_address);
4924 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
4925 pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target);
4927 pr_info(MPT3SAS_FMT "\twwid(0x%016llx), port(%d)\n",
4929 (unsigned long long)pcie_device->wwid,
4930 pcie_device->port_num);
4931 if (pcie_device->enclosure_handle != 0)
4933 "\tenclosure logical id(0x%016llx), "
4934 "slot(%d)\n", ioc->name,
4935 (unsigned long long)
4936 pcie_device->enclosure_logical_id,
4938 if (pcie_device->connector_name[0])
4940 "\tenclosure level(0x%04x),"
4941 "connector name( %s)\n",
4942 ioc->name, pcie_device->enclosure_level,
4943 pcie_device->connector_name);
4944 pcie_device_put(pcie_device);
4947 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4950 "\tsas_address(0x%016llx), phy(%d)\n",
4951 ioc->name, (unsigned long long)
4952 sas_device->sas_address, sas_device->phy);
4954 _scsih_display_enclosure_chassis_info(ioc, sas_device,
4957 sas_device_put(sas_device);
4962 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4963 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4964 desc_ioc_state, ioc_status, smid);
4966 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4967 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4968 scsi_get_resid(scmd));
4970 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4971 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4972 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4974 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4975 ioc->name, desc_scsi_status,
4976 scsi_status, desc_scsi_state, scsi_state);
4978 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4979 struct sense_info data;
4980 _scsih_normalize_sense(scmd->sense_buffer, &data);
4982 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4983 ioc->name, data.skey,
4984 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4986 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4987 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4988 response_bytes = (u8 *)&response_info;
4989 _scsih_response_code(ioc, response_bytes[0]);
4994 * _scsih_turn_on_pfa_led - illuminate PFA LED
4995 * @ioc: per adapter object
4996 * @handle: device handle
5000 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5002 Mpi2SepReply_t mpi_reply;
5003 Mpi2SepRequest_t mpi_request;
5004 struct _sas_device *sas_device;
5006 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
5010 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
5011 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
5012 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
5013 mpi_request.SlotStatus =
5014 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
5015 mpi_request.DevHandle = cpu_to_le16(handle);
5016 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
5017 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5018 &mpi_request)) != 0) {
5019 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
5020 __FILE__, __LINE__, __func__);
5023 sas_device->pfa_led_on = 1;
5025 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5026 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5027 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5028 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
5029 le32_to_cpu(mpi_reply.IOCLogInfo)));
5033 sas_device_put(sas_device);
5037 * _scsih_turn_off_pfa_led - turn off Fault LED
5038 * @ioc: per adapter object
5039 * @sas_device: sas device whose PFA LED has to turned off
5043 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
5044 struct _sas_device *sas_device)
5046 Mpi2SepReply_t mpi_reply;
5047 Mpi2SepRequest_t mpi_request;
5049 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
5050 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
5051 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
5052 mpi_request.SlotStatus = 0;
5053 mpi_request.Slot = cpu_to_le16(sas_device->slot);
5054 mpi_request.DevHandle = 0;
5055 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
5056 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
5057 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5058 &mpi_request)) != 0) {
5059 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
5060 __FILE__, __LINE__, __func__);
5064 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5065 dewtprintk(ioc, printk(MPT3SAS_FMT
5066 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5067 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
5068 le32_to_cpu(mpi_reply.IOCLogInfo)));
5074 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5075 * @ioc: per adapter object
5076 * @handle: device handle
5077 * Context: interrupt.
5080 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5082 struct fw_event_work *fw_event;
5084 fw_event = alloc_fw_event_work(0);
5087 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
5088 fw_event->device_handle = handle;
5089 fw_event->ioc = ioc;
5090 _scsih_fw_event_add(ioc, fw_event);
5091 fw_event_work_put(fw_event);
5095 * _scsih_smart_predicted_fault - process smart errors
5096 * @ioc: per adapter object
5097 * @handle: device handle
5098 * Context: interrupt.
5101 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5103 struct scsi_target *starget;
5104 struct MPT3SAS_TARGET *sas_target_priv_data;
5105 Mpi2EventNotificationReply_t *event_reply;
5106 Mpi2EventDataSasDeviceStatusChange_t *event_data;
5107 struct _sas_device *sas_device;
5109 unsigned long flags;
5111 /* only handle non-raid devices */
5112 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5113 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
5117 starget = sas_device->starget;
5118 sas_target_priv_data = starget->hostdata;
5120 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
5121 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
5124 _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget);
5126 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5128 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
5129 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
5131 /* insert into event log */
5132 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
5133 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
5134 event_reply = kzalloc(sz, GFP_KERNEL);
5136 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5137 ioc->name, __FILE__, __LINE__, __func__);
5141 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
5142 event_reply->Event =
5143 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
5144 event_reply->MsgLength = sz/4;
5145 event_reply->EventDataLength =
5146 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
5147 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
5148 event_reply->EventData;
5149 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
5150 event_data->ASC = 0x5D;
5151 event_data->DevHandle = cpu_to_le16(handle);
5152 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
5153 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
5157 sas_device_put(sas_device);
5161 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5166 * _scsih_io_done - scsi request callback
5167 * @ioc: per adapter object
5168 * @smid: system request message index
5169 * @msix_index: MSIX table index supplied by the OS
5170 * @reply: reply message frame(lower 32bit addr)
5172 * Callback handler when using _scsih_qcmd.
5174 * Return: 1 meaning mf should be freed from _base_interrupt
5175 * 0 means the mf is freed from this function.
5178 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5180 Mpi25SCSIIORequest_t *mpi_request;
5181 Mpi2SCSIIOReply_t *mpi_reply;
5182 struct scsi_cmnd *scmd;
5183 struct scsiio_tracker *st;
5189 struct MPT3SAS_DEVICE *sas_device_priv_data;
5190 u32 response_code = 0;
5192 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5194 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
5198 _scsih_set_satl_pending(scmd, false);
5200 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5202 if (mpi_reply == NULL) {
5203 scmd->result = DID_OK << 16;
5207 sas_device_priv_data = scmd->device->hostdata;
5208 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
5209 sas_device_priv_data->sas_target->deleted) {
5210 scmd->result = DID_NO_CONNECT << 16;
5213 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5216 * WARPDRIVE: If direct_io is set then it is directIO,
5217 * the failed direct I/O should be redirected to volume
5219 st = scsi_cmd_priv(scmd);
5220 if (st->direct_io &&
5221 ((ioc_status & MPI2_IOCSTATUS_MASK)
5222 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
5224 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
5225 mpi_request->DevHandle =
5226 cpu_to_le16(sas_device_priv_data->sas_target->handle);
5227 ioc->put_smid_scsi_io(ioc, smid,
5228 sas_device_priv_data->sas_target->handle);
5231 /* turning off TLR */
5232 scsi_state = mpi_reply->SCSIState;
5233 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
5235 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
5236 if (!sas_device_priv_data->tlr_snoop_check) {
5237 sas_device_priv_data->tlr_snoop_check++;
5238 if ((!ioc->is_warpdrive &&
5239 !scsih_is_raid(&scmd->device->sdev_gendev) &&
5240 !scsih_is_nvme(&scmd->device->sdev_gendev))
5241 && sas_is_tlr_enabled(scmd->device) &&
5242 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
5243 sas_disable_tlr(scmd->device);
5244 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
5248 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
5249 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
5250 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5251 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5254 ioc_status &= MPI2_IOCSTATUS_MASK;
5255 scsi_status = mpi_reply->SCSIStatus;
5257 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
5258 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
5259 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
5260 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
5261 ioc_status = MPI2_IOCSTATUS_SUCCESS;
5264 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
5265 struct sense_info data;
5266 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
5268 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
5269 le32_to_cpu(mpi_reply->SenseCount));
5270 memcpy(scmd->sense_buffer, sense_data, sz);
5271 _scsih_normalize_sense(scmd->sense_buffer, &data);
5272 /* failure prediction threshold exceeded */
5273 if (data.asc == 0x5D)
5274 _scsih_smart_predicted_fault(ioc,
5275 le16_to_cpu(mpi_reply->DevHandle));
5276 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
5278 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
5279 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
5280 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
5281 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
5282 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
5284 switch (ioc_status) {
5285 case MPI2_IOCSTATUS_BUSY:
5286 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
5287 scmd->result = SAM_STAT_BUSY;
5290 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
5291 scmd->result = DID_NO_CONNECT << 16;
5294 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
5295 if (sas_device_priv_data->block) {
5296 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
5299 if (log_info == 0x31110630) {
5300 if (scmd->retries > 2) {
5301 scmd->result = DID_NO_CONNECT << 16;
5302 scsi_device_set_state(scmd->device,
5305 scmd->result = DID_SOFT_ERROR << 16;
5306 scmd->device->expecting_cc_ua = 1;
5309 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
5310 scmd->result = DID_RESET << 16;
5312 } else if ((scmd->device->channel == RAID_CHANNEL) &&
5313 (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
5314 MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
5315 scmd->result = DID_RESET << 16;
5318 scmd->result = DID_SOFT_ERROR << 16;
5320 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
5321 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
5322 scmd->result = DID_RESET << 16;
5325 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
5326 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
5327 scmd->result = DID_SOFT_ERROR << 16;
5329 scmd->result = (DID_OK << 16) | scsi_status;
5332 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
5333 scmd->result = (DID_OK << 16) | scsi_status;
5335 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
5338 if (xfer_cnt < scmd->underflow) {
5339 if (scsi_status == SAM_STAT_BUSY)
5340 scmd->result = SAM_STAT_BUSY;
5342 scmd->result = DID_SOFT_ERROR << 16;
5343 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5344 MPI2_SCSI_STATE_NO_SCSI_STATUS))
5345 scmd->result = DID_SOFT_ERROR << 16;
5346 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5347 scmd->result = DID_RESET << 16;
5348 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
5349 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
5350 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
5351 scmd->result = (DRIVER_SENSE << 24) |
5352 SAM_STAT_CHECK_CONDITION;
5353 scmd->sense_buffer[0] = 0x70;
5354 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
5355 scmd->sense_buffer[12] = 0x20;
5356 scmd->sense_buffer[13] = 0;
5360 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
5361 scsi_set_resid(scmd, 0);
5363 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
5364 case MPI2_IOCSTATUS_SUCCESS:
5365 scmd->result = (DID_OK << 16) | scsi_status;
5366 if (response_code ==
5367 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
5368 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5369 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
5370 scmd->result = DID_SOFT_ERROR << 16;
5371 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5372 scmd->result = DID_RESET << 16;
5375 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
5376 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
5377 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
5378 _scsih_eedp_error_handling(scmd, ioc_status);
5381 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
5382 case MPI2_IOCSTATUS_INVALID_FUNCTION:
5383 case MPI2_IOCSTATUS_INVALID_SGL:
5384 case MPI2_IOCSTATUS_INTERNAL_ERROR:
5385 case MPI2_IOCSTATUS_INVALID_FIELD:
5386 case MPI2_IOCSTATUS_INVALID_STATE:
5387 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
5388 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
5389 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
5391 scmd->result = DID_SOFT_ERROR << 16;
5396 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
5397 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
5401 scsi_dma_unmap(scmd);
5402 mpt3sas_base_free_smid(ioc, smid);
5403 scmd->scsi_done(scmd);
5408 * _scsih_sas_host_refresh - refreshing sas host object contents
5409 * @ioc: per adapter object
5412 * During port enable, fw will send topology events for every device. Its
5413 * possible that the handles may change from the previous setting, so this
5414 * code keeping handles updating if changed.
5417 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
5422 Mpi2ConfigReply_t mpi_reply;
5423 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5424 u16 attached_handle;
5427 dtmprintk(ioc, pr_info(MPT3SAS_FMT
5428 "updating handles for sas_host(0x%016llx)\n",
5429 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
5431 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
5432 * sizeof(Mpi2SasIOUnit0PhyData_t));
5433 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5434 if (!sas_iounit_pg0) {
5435 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5436 ioc->name, __FILE__, __LINE__, __func__);
5440 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5441 sas_iounit_pg0, sz)) != 0)
5443 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5444 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5446 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5447 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
5449 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5450 PhyData[0].ControllerDevHandle);
5451 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5452 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
5454 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5455 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
5456 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
5457 attached_handle, i, link_rate);
5460 kfree(sas_iounit_pg0);
5464 * _scsih_sas_host_add - create sas host object
5465 * @ioc: per adapter object
5467 * Creating host side data object, stored in ioc->sas_hba
5470 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
5473 Mpi2ConfigReply_t mpi_reply;
5474 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5475 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
5476 Mpi2SasPhyPage0_t phy_pg0;
5477 Mpi2SasDevicePage0_t sas_device_pg0;
5478 Mpi2SasEnclosurePage0_t enclosure_pg0;
5481 u8 device_missing_delay;
5484 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
5486 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5487 ioc->name, __FILE__, __LINE__, __func__);
5490 ioc->sas_hba.phy = kcalloc(num_phys,
5491 sizeof(struct _sas_phy), GFP_KERNEL);
5492 if (!ioc->sas_hba.phy) {
5493 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5494 ioc->name, __FILE__, __LINE__, __func__);
5497 ioc->sas_hba.num_phys = num_phys;
5499 /* sas_iounit page 0 */
5500 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
5501 sizeof(Mpi2SasIOUnit0PhyData_t));
5502 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5503 if (!sas_iounit_pg0) {
5504 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5505 ioc->name, __FILE__, __LINE__, __func__);
5508 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5509 sas_iounit_pg0, sz))) {
5510 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5511 ioc->name, __FILE__, __LINE__, __func__);
5514 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5515 MPI2_IOCSTATUS_MASK;
5516 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5517 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5518 ioc->name, __FILE__, __LINE__, __func__);
5522 /* sas_iounit page 1 */
5523 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
5524 sizeof(Mpi2SasIOUnit1PhyData_t));
5525 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
5526 if (!sas_iounit_pg1) {
5527 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5528 ioc->name, __FILE__, __LINE__, __func__);
5531 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
5532 sas_iounit_pg1, sz))) {
5533 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5534 ioc->name, __FILE__, __LINE__, __func__);
5537 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5538 MPI2_IOCSTATUS_MASK;
5539 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5540 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5541 ioc->name, __FILE__, __LINE__, __func__);
5545 ioc->io_missing_delay =
5546 sas_iounit_pg1->IODeviceMissingDelay;
5547 device_missing_delay =
5548 sas_iounit_pg1->ReportDeviceMissingDelay;
5549 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
5550 ioc->device_missing_delay = (device_missing_delay &
5551 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
5553 ioc->device_missing_delay = device_missing_delay &
5554 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
5556 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
5557 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5558 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5560 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5561 ioc->name, __FILE__, __LINE__, __func__);
5564 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5565 MPI2_IOCSTATUS_MASK;
5566 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5567 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5568 ioc->name, __FILE__, __LINE__, __func__);
5573 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5574 PhyData[0].ControllerDevHandle);
5575 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5576 ioc->sas_hba.phy[i].phy_id = i;
5577 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
5578 phy_pg0, ioc->sas_hba.parent_dev);
5580 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5581 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
5582 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5583 ioc->name, __FILE__, __LINE__, __func__);
5586 ioc->sas_hba.enclosure_handle =
5587 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5588 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5590 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5591 ioc->name, ioc->sas_hba.handle,
5592 (unsigned long long) ioc->sas_hba.sas_address,
5593 ioc->sas_hba.num_phys) ;
5595 if (ioc->sas_hba.enclosure_handle) {
5596 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5597 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5598 ioc->sas_hba.enclosure_handle)))
5599 ioc->sas_hba.enclosure_logical_id =
5600 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5604 kfree(sas_iounit_pg1);
5605 kfree(sas_iounit_pg0);
5609 * _scsih_expander_add - creating expander object
5610 * @ioc: per adapter object
5611 * @handle: expander handle
5613 * Creating expander object, stored in ioc->sas_expander_list.
5615 * Return: 0 for success, else error.
5618 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5620 struct _sas_node *sas_expander;
5621 struct _enclosure_node *enclosure_dev;
5622 Mpi2ConfigReply_t mpi_reply;
5623 Mpi2ExpanderPage0_t expander_pg0;
5624 Mpi2ExpanderPage1_t expander_pg1;
5627 u64 sas_address, sas_address_parent = 0;
5629 unsigned long flags;
5630 struct _sas_port *mpt3sas_port = NULL;
5637 if (ioc->shost_recovery || ioc->pci_error_recovery)
5640 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5641 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5642 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5643 ioc->name, __FILE__, __LINE__, __func__);
5647 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5648 MPI2_IOCSTATUS_MASK;
5649 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5650 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5651 ioc->name, __FILE__, __LINE__, __func__);
5655 /* handle out of order topology events */
5656 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5657 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5659 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5660 ioc->name, __FILE__, __LINE__, __func__);
5663 if (sas_address_parent != ioc->sas_hba.sas_address) {
5664 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5665 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5666 sas_address_parent);
5667 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5668 if (!sas_expander) {
5669 rc = _scsih_expander_add(ioc, parent_handle);
5675 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5676 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5677 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5679 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5684 sas_expander = kzalloc(sizeof(struct _sas_node),
5686 if (!sas_expander) {
5687 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5688 ioc->name, __FILE__, __LINE__, __func__);
5692 sas_expander->handle = handle;
5693 sas_expander->num_phys = expander_pg0.NumPhys;
5694 sas_expander->sas_address_parent = sas_address_parent;
5695 sas_expander->sas_address = sas_address;
5697 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5698 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5699 handle, parent_handle, (unsigned long long)
5700 sas_expander->sas_address, sas_expander->num_phys);
5702 if (!sas_expander->num_phys)
5704 sas_expander->phy = kcalloc(sas_expander->num_phys,
5705 sizeof(struct _sas_phy), GFP_KERNEL);
5706 if (!sas_expander->phy) {
5707 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5708 ioc->name, __FILE__, __LINE__, __func__);
5713 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5714 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5715 sas_address_parent);
5716 if (!mpt3sas_port) {
5717 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5718 ioc->name, __FILE__, __LINE__, __func__);
5722 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5724 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5725 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5726 &expander_pg1, i, handle))) {
5727 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5728 ioc->name, __FILE__, __LINE__, __func__);
5732 sas_expander->phy[i].handle = handle;
5733 sas_expander->phy[i].phy_id = i;
5735 if ((mpt3sas_transport_add_expander_phy(ioc,
5736 &sas_expander->phy[i], expander_pg1,
5737 sas_expander->parent_dev))) {
5738 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5739 ioc->name, __FILE__, __LINE__, __func__);
5745 if (sas_expander->enclosure_handle) {
5747 mpt3sas_scsih_enclosure_find_by_handle(ioc,
5748 sas_expander->enclosure_handle);
5750 sas_expander->enclosure_logical_id =
5751 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
5754 _scsih_expander_node_add(ioc, sas_expander);
5760 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5761 sas_address_parent);
5762 kfree(sas_expander);
5767 * mpt3sas_expander_remove - removing expander object
5768 * @ioc: per adapter object
5769 * @sas_address: expander sas_address
5772 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5774 struct _sas_node *sas_expander;
5775 unsigned long flags;
5777 if (ioc->shost_recovery)
5780 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5781 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5783 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5785 _scsih_expander_node_remove(ioc, sas_expander);
5789 * _scsih_done - internal SCSI_IO callback handler.
5790 * @ioc: per adapter object
5791 * @smid: system request message index
5792 * @msix_index: MSIX table index supplied by the OS
5793 * @reply: reply message frame(lower 32bit addr)
5795 * Callback handler when sending internal generated SCSI_IO.
5796 * The callback index passed is `ioc->scsih_cb_idx`
5798 * Return: 1 meaning mf should be freed from _base_interrupt
5799 * 0 means the mf is freed from this function.
5802 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5804 MPI2DefaultReply_t *mpi_reply;
5806 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5807 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5809 if (ioc->scsih_cmds.smid != smid)
5811 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5813 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5814 mpi_reply->MsgLength*4);
5815 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5817 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5818 complete(&ioc->scsih_cmds.done);
5825 #define MPT3_MAX_LUNS (255)
5829 * _scsih_check_access_status - check access flags
5830 * @ioc: per adapter object
5831 * @sas_address: sas address
5832 * @handle: sas device handle
5833 * @access_status: errors returned during discovery of the device
5835 * Return: 0 for success, else failure
5838 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5839 u16 handle, u8 access_status)
5844 switch (access_status) {
5845 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5846 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5849 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5850 desc = "sata capability failed";
5852 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5853 desc = "sata affiliation conflict";
5855 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5856 desc = "route not addressable";
5858 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5859 desc = "smp error not addressable";
5861 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5862 desc = "device blocked";
5864 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5865 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5866 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5867 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5868 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5869 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5870 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5871 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5872 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5873 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5874 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5875 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5876 desc = "sata initialization failed";
5887 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5888 ioc->name, desc, (unsigned long long)sas_address, handle);
5893 * _scsih_check_device - checking device responsiveness
5894 * @ioc: per adapter object
5895 * @parent_sas_address: sas address of parent expander or sas host
5896 * @handle: attached device handle
5897 * @phy_number: phy number
5898 * @link_rate: new link rate
5901 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5902 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5904 Mpi2ConfigReply_t mpi_reply;
5905 Mpi2SasDevicePage0_t sas_device_pg0;
5906 struct _sas_device *sas_device;
5907 struct _enclosure_node *enclosure_dev = NULL;
5909 unsigned long flags;
5911 struct scsi_target *starget;
5912 struct MPT3SAS_TARGET *sas_target_priv_data;
5915 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5916 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5919 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5920 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5923 /* wide port handling ~ we need only handle device once for the phy that
5924 * is matched in sas device page zero
5926 if (phy_number != sas_device_pg0.PhyNum)
5929 /* check if this is end device */
5930 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5931 if (!(_scsih_is_end_device(device_info)))
5934 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5935 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5936 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5942 if (unlikely(sas_device->handle != handle)) {
5943 starget = sas_device->starget;
5944 sas_target_priv_data = starget->hostdata;
5945 starget_printk(KERN_INFO, starget,
5946 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5947 sas_device->handle, handle);
5948 sas_target_priv_data->handle = handle;
5949 sas_device->handle = handle;
5950 if (le16_to_cpu(sas_device_pg0.Flags) &
5951 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5952 sas_device->enclosure_level =
5953 sas_device_pg0.EnclosureLevel;
5954 memcpy(sas_device->connector_name,
5955 sas_device_pg0.ConnectorName, 4);
5956 sas_device->connector_name[4] = '\0';
5958 sas_device->enclosure_level = 0;
5959 sas_device->connector_name[0] = '\0';
5962 sas_device->enclosure_handle =
5963 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5964 sas_device->is_chassis_slot_valid = 0;
5965 enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc,
5966 sas_device->enclosure_handle);
5967 if (enclosure_dev) {
5968 sas_device->enclosure_logical_id =
5969 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
5970 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
5971 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
5972 sas_device->is_chassis_slot_valid = 1;
5973 sas_device->chassis_slot =
5974 enclosure_dev->pg0.ChassisSlot;
5979 /* check if device is present */
5980 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5981 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5983 "device is not present handle(0x%04x), flags!!!\n",
5988 /* check if there were any issues with discovery */
5989 if (_scsih_check_access_status(ioc, sas_address, handle,
5990 sas_device_pg0.AccessStatus))
5993 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5994 _scsih_ublock_io_device(ioc, sas_address);
5997 sas_device_put(sas_device);
6001 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6003 sas_device_put(sas_device);
6007 * _scsih_add_device - creating sas device object
6008 * @ioc: per adapter object
6009 * @handle: sas device handle
6010 * @phy_num: phy number end device attached to
6011 * @is_pd: is this hidden raid component
6013 * Creating end device object, stored in ioc->sas_device_list.
6015 * Return: 0 for success, non-zero for failure.
6018 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
6021 Mpi2ConfigReply_t mpi_reply;
6022 Mpi2SasDevicePage0_t sas_device_pg0;
6023 struct _sas_device *sas_device;
6024 struct _enclosure_node *enclosure_dev = NULL;
6029 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6030 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6031 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6032 ioc->name, __FILE__, __LINE__, __func__);
6036 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6037 MPI2_IOCSTATUS_MASK;
6038 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6039 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6040 ioc->name, __FILE__, __LINE__, __func__);
6044 /* check if this is end device */
6045 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6046 if (!(_scsih_is_end_device(device_info)))
6048 set_bit(handle, ioc->pend_os_device_add);
6049 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6051 /* check if device is present */
6052 if (!(le16_to_cpu(sas_device_pg0.Flags) &
6053 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
6054 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
6059 /* check if there were any issues with discovery */
6060 if (_scsih_check_access_status(ioc, sas_address, handle,
6061 sas_device_pg0.AccessStatus))
6064 sas_device = mpt3sas_get_sdev_by_addr(ioc,
6067 clear_bit(handle, ioc->pend_os_device_add);
6068 sas_device_put(sas_device);
6072 if (sas_device_pg0.EnclosureHandle) {
6074 mpt3sas_scsih_enclosure_find_by_handle(ioc,
6075 le16_to_cpu(sas_device_pg0.EnclosureHandle));
6076 if (enclosure_dev == NULL)
6077 pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)"
6078 "doesn't match with enclosure device!\n",
6079 ioc->name, sas_device_pg0.EnclosureHandle);
6082 sas_device = kzalloc(sizeof(struct _sas_device),
6085 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6086 ioc->name, __FILE__, __LINE__, __func__);
6090 kref_init(&sas_device->refcount);
6091 sas_device->handle = handle;
6092 if (_scsih_get_sas_address(ioc,
6093 le16_to_cpu(sas_device_pg0.ParentDevHandle),
6094 &sas_device->sas_address_parent) != 0)
6095 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6096 ioc->name, __FILE__, __LINE__, __func__);
6097 sas_device->enclosure_handle =
6098 le16_to_cpu(sas_device_pg0.EnclosureHandle);
6099 if (sas_device->enclosure_handle != 0)
6101 le16_to_cpu(sas_device_pg0.Slot);
6102 sas_device->device_info = device_info;
6103 sas_device->sas_address = sas_address;
6104 sas_device->phy = sas_device_pg0.PhyNum;
6105 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
6106 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
6108 if (le16_to_cpu(sas_device_pg0.Flags)
6109 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6110 sas_device->enclosure_level =
6111 sas_device_pg0.EnclosureLevel;
6112 memcpy(sas_device->connector_name,
6113 sas_device_pg0.ConnectorName, 4);
6114 sas_device->connector_name[4] = '\0';
6116 sas_device->enclosure_level = 0;
6117 sas_device->connector_name[0] = '\0';
6119 /* get enclosure_logical_id & chassis_slot*/
6120 sas_device->is_chassis_slot_valid = 0;
6121 if (enclosure_dev) {
6122 sas_device->enclosure_logical_id =
6123 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6124 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
6125 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
6126 sas_device->is_chassis_slot_valid = 1;
6127 sas_device->chassis_slot =
6128 enclosure_dev->pg0.ChassisSlot;
6132 /* get device name */
6133 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
6135 if (ioc->wait_for_discovery_to_complete)
6136 _scsih_sas_device_init_add(ioc, sas_device);
6138 _scsih_sas_device_add(ioc, sas_device);
6140 sas_device_put(sas_device);
6145 * _scsih_remove_device - removing sas device object
6146 * @ioc: per adapter object
6147 * @sas_device: the sas_device object
6150 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
6151 struct _sas_device *sas_device)
6153 struct MPT3SAS_TARGET *sas_target_priv_data;
6155 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
6156 (sas_device->pfa_led_on)) {
6157 _scsih_turn_off_pfa_led(ioc, sas_device);
6158 sas_device->pfa_led_on = 0;
6161 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6162 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6163 ioc->name, __func__,
6164 sas_device->handle, (unsigned long long)
6165 sas_device->sas_address));
6167 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
6170 if (sas_device->starget && sas_device->starget->hostdata) {
6171 sas_target_priv_data = sas_device->starget->hostdata;
6172 sas_target_priv_data->deleted = 1;
6173 _scsih_ublock_io_device(ioc, sas_device->sas_address);
6174 sas_target_priv_data->handle =
6175 MPT3SAS_INVALID_DEVICE_HANDLE;
6178 if (!ioc->hide_drives)
6179 mpt3sas_transport_port_remove(ioc,
6180 sas_device->sas_address,
6181 sas_device->sas_address_parent);
6184 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6185 ioc->name, sas_device->handle,
6186 (unsigned long long) sas_device->sas_address);
6188 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
6190 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6191 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6192 ioc->name, __func__,
6193 sas_device->handle, (unsigned long long)
6194 sas_device->sas_address));
6195 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
6200 * _scsih_sas_topology_change_event_debug - debug for topology event
6201 * @ioc: per adapter object
6202 * @event_data: event data payload
6206 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6207 Mpi2EventDataSasTopologyChangeList_t *event_data)
6213 char *status_str = NULL;
6214 u8 link_rate, prev_link_rate;
6216 switch (event_data->ExpStatus) {
6217 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
6220 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
6221 status_str = "remove";
6223 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
6225 status_str = "responding";
6227 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
6228 status_str = "remove delay";
6231 status_str = "unknown status";
6234 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
6235 ioc->name, status_str);
6236 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6237 "start_phy(%02d), count(%d)\n",
6238 le16_to_cpu(event_data->ExpanderDevHandle),
6239 le16_to_cpu(event_data->EnclosureHandle),
6240 event_data->StartPhyNum, event_data->NumEntries);
6241 for (i = 0; i < event_data->NumEntries; i++) {
6242 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
6245 phy_number = event_data->StartPhyNum + i;
6246 reason_code = event_data->PHY[i].PhyStatus &
6247 MPI2_EVENT_SAS_TOPO_RC_MASK;
6248 switch (reason_code) {
6249 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
6250 status_str = "target add";
6252 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
6253 status_str = "target remove";
6255 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
6256 status_str = "delay target remove";
6258 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
6259 status_str = "link rate change";
6261 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
6262 status_str = "target responding";
6265 status_str = "unknown";
6268 link_rate = event_data->PHY[i].LinkRate >> 4;
6269 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
6270 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6271 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
6272 handle, status_str, link_rate, prev_link_rate);
6278 * _scsih_sas_topology_change_event - handle topology changes
6279 * @ioc: per adapter object
6280 * @fw_event: The fw_event_work object
6285 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
6286 struct fw_event_work *fw_event)
6289 u16 parent_handle, handle;
6291 u8 phy_number, max_phys;
6292 struct _sas_node *sas_expander;
6294 unsigned long flags;
6295 u8 link_rate, prev_link_rate;
6296 Mpi2EventDataSasTopologyChangeList_t *event_data =
6297 (Mpi2EventDataSasTopologyChangeList_t *)
6298 fw_event->event_data;
6300 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6301 _scsih_sas_topology_change_event_debug(ioc, event_data);
6303 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
6306 if (!ioc->sas_hba.num_phys)
6307 _scsih_sas_host_add(ioc);
6309 _scsih_sas_host_refresh(ioc);
6311 if (fw_event->ignore) {
6312 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6313 "ignoring expander event\n", ioc->name));
6317 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
6319 /* handle expander add */
6320 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
6321 if (_scsih_expander_add(ioc, parent_handle) != 0)
6324 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6325 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
6328 sas_address = sas_expander->sas_address;
6329 max_phys = sas_expander->num_phys;
6330 } else if (parent_handle < ioc->sas_hba.num_phys) {
6331 sas_address = ioc->sas_hba.sas_address;
6332 max_phys = ioc->sas_hba.num_phys;
6334 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6337 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6339 /* handle siblings events */
6340 for (i = 0; i < event_data->NumEntries; i++) {
6341 if (fw_event->ignore) {
6342 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6343 "ignoring expander event\n", ioc->name));
6346 if (ioc->remove_host || ioc->pci_error_recovery)
6348 phy_number = event_data->StartPhyNum + i;
6349 if (phy_number >= max_phys)
6351 reason_code = event_data->PHY[i].PhyStatus &
6352 MPI2_EVENT_SAS_TOPO_RC_MASK;
6353 if ((event_data->PHY[i].PhyStatus &
6354 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
6355 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
6357 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
6360 link_rate = event_data->PHY[i].LinkRate >> 4;
6361 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
6362 switch (reason_code) {
6363 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
6365 if (ioc->shost_recovery)
6368 if (link_rate == prev_link_rate)
6371 mpt3sas_transport_update_links(ioc, sas_address,
6372 handle, phy_number, link_rate);
6374 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
6377 _scsih_check_device(ioc, sas_address, handle,
6378 phy_number, link_rate);
6380 if (!test_bit(handle, ioc->pend_os_device_add))
6385 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
6387 if (ioc->shost_recovery)
6390 mpt3sas_transport_update_links(ioc, sas_address,
6391 handle, phy_number, link_rate);
6393 _scsih_add_device(ioc, handle, phy_number, 0);
6396 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
6398 _scsih_device_remove_by_handle(ioc, handle);
6403 /* handle expander removal */
6404 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
6406 mpt3sas_expander_remove(ioc, sas_address);
6412 * _scsih_sas_device_status_change_event_debug - debug for device event
6414 * @event_data: event data payload
6418 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6419 Mpi2EventDataSasDeviceStatusChange_t *event_data)
6421 char *reason_str = NULL;
6423 switch (event_data->ReasonCode) {
6424 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
6425 reason_str = "smart data";
6427 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
6428 reason_str = "unsupported device discovered";
6430 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
6431 reason_str = "internal device reset";
6433 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
6434 reason_str = "internal task abort";
6436 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
6437 reason_str = "internal task abort set";
6439 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
6440 reason_str = "internal clear task set";
6442 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
6443 reason_str = "internal query task";
6445 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
6446 reason_str = "sata init failure";
6448 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
6449 reason_str = "internal device reset complete";
6451 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
6452 reason_str = "internal task abort complete";
6454 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
6455 reason_str = "internal async notification";
6457 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
6458 reason_str = "expander reduced functionality";
6460 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
6461 reason_str = "expander reduced functionality complete";
6464 reason_str = "unknown reason";
6467 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
6468 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6469 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
6470 (unsigned long long)le64_to_cpu(event_data->SASAddress),
6471 le16_to_cpu(event_data->TaskTag));
6472 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
6473 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
6474 event_data->ASC, event_data->ASCQ);
6479 * _scsih_sas_device_status_change_event - handle device status change
6480 * @ioc: per adapter object
6481 * @fw_event: The fw_event_work object
6485 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
6486 struct fw_event_work *fw_event)
6488 struct MPT3SAS_TARGET *target_priv_data;
6489 struct _sas_device *sas_device;
6491 unsigned long flags;
6492 Mpi2EventDataSasDeviceStatusChange_t *event_data =
6493 (Mpi2EventDataSasDeviceStatusChange_t *)
6494 fw_event->event_data;
6496 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6497 _scsih_sas_device_status_change_event_debug(ioc,
6500 /* In MPI Revision K (0xC), the internal device reset complete was
6501 * implemented, so avoid setting tm_busy flag for older firmware.
6503 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
6506 if (event_data->ReasonCode !=
6507 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
6508 event_data->ReasonCode !=
6509 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
6512 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6513 sas_address = le64_to_cpu(event_data->SASAddress);
6514 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
6517 if (!sas_device || !sas_device->starget)
6520 target_priv_data = sas_device->starget->hostdata;
6521 if (!target_priv_data)
6524 if (event_data->ReasonCode ==
6525 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
6526 target_priv_data->tm_busy = 1;
6528 target_priv_data->tm_busy = 0;
6532 sas_device_put(sas_device);
6534 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6539 * _scsih_check_pcie_access_status - check access flags
6540 * @ioc: per adapter object
6542 * @handle: sas device handle
6543 * @access_status: errors returned during discovery of the device
6545 * Return: 0 for success, else failure
6548 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6549 u16 handle, u8 access_status)
6554 switch (access_status) {
6555 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS:
6556 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION:
6559 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED:
6560 desc = "PCIe device capability failed";
6562 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED:
6563 desc = "PCIe device blocked";
6565 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED:
6566 desc = "PCIe device mem space access failed";
6568 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE:
6569 desc = "PCIe device unsupported";
6571 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED:
6572 desc = "PCIe device MSIx Required";
6574 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX:
6575 desc = "PCIe device init fail max";
6577 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN:
6578 desc = "PCIe device status unknown";
6580 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT:
6581 desc = "nvme ready timeout";
6583 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED:
6584 desc = "nvme device configuration unsupported";
6586 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED:
6587 desc = "nvme identify failed";
6589 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED:
6590 desc = "nvme qconfig failed";
6592 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED:
6593 desc = "nvme qcreation failed";
6595 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED:
6596 desc = "nvme eventcfg failed";
6598 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED:
6599 desc = "nvme get feature stat failed";
6601 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT:
6602 desc = "nvme idle timeout";
6604 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS:
6605 desc = "nvme failure status";
6609 " NVMe discovery error(0x%02x): wwid(0x%016llx),"
6610 "handle(0x%04x)\n", ioc->name, access_status,
6611 (unsigned long long)wwid, handle);
6619 "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6621 (unsigned long long)wwid, handle);
6626 * _scsih_pcie_device_remove_from_sml - removing pcie device
6627 * from SML and free up associated memory
6628 * @ioc: per adapter object
6629 * @pcie_device: the pcie_device object
6632 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
6633 struct _pcie_device *pcie_device)
6635 struct MPT3SAS_TARGET *sas_target_priv_data;
6637 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6638 "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
6639 pcie_device->handle, (unsigned long long)
6640 pcie_device->wwid));
6641 if (pcie_device->enclosure_handle != 0)
6642 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6643 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6644 ioc->name, __func__,
6645 (unsigned long long)pcie_device->enclosure_logical_id,
6646 pcie_device->slot));
6647 if (pcie_device->connector_name[0] != '\0')
6648 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6649 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
6650 ioc->name, __func__,
6651 pcie_device->enclosure_level,
6652 pcie_device->connector_name));
6654 if (pcie_device->starget && pcie_device->starget->hostdata) {
6655 sas_target_priv_data = pcie_device->starget->hostdata;
6656 sas_target_priv_data->deleted = 1;
6657 _scsih_ublock_io_device(ioc, pcie_device->wwid);
6658 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
6662 "removing handle(0x%04x), wwid (0x%016llx)\n",
6663 ioc->name, pcie_device->handle,
6664 (unsigned long long) pcie_device->wwid);
6665 if (pcie_device->enclosure_handle != 0)
6667 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6669 (unsigned long long)pcie_device->enclosure_logical_id,
6671 if (pcie_device->connector_name[0] != '\0')
6673 "removing: enclosure level(0x%04x), connector name( %s)\n",
6674 ioc->name, pcie_device->enclosure_level,
6675 pcie_device->connector_name);
6677 if (pcie_device->starget)
6678 scsi_remove_target(&pcie_device->starget->dev);
6679 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6680 "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
6681 pcie_device->handle, (unsigned long long)
6682 pcie_device->wwid));
6683 if (pcie_device->enclosure_handle != 0)
6684 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6685 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6686 ioc->name, __func__,
6687 (unsigned long long)pcie_device->enclosure_logical_id,
6688 pcie_device->slot));
6689 if (pcie_device->connector_name[0] != '\0')
6690 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6691 "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6692 ioc->name, __func__, pcie_device->enclosure_level,
6693 pcie_device->connector_name));
6695 kfree(pcie_device->serial_number);
6700 * _scsih_pcie_check_device - checking device responsiveness
6701 * @ioc: per adapter object
6702 * @handle: attached device handle
6705 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6707 Mpi2ConfigReply_t mpi_reply;
6708 Mpi26PCIeDevicePage0_t pcie_device_pg0;
6710 struct _pcie_device *pcie_device;
6712 unsigned long flags;
6713 struct scsi_target *starget;
6714 struct MPT3SAS_TARGET *sas_target_priv_data;
6717 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
6718 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
6721 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6722 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6725 /* check if this is end device */
6726 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
6727 if (!(_scsih_is_nvme_device(device_info)))
6730 wwid = le64_to_cpu(pcie_device_pg0.WWID);
6731 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
6732 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
6735 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6739 if (unlikely(pcie_device->handle != handle)) {
6740 starget = pcie_device->starget;
6741 sas_target_priv_data = starget->hostdata;
6742 starget_printk(KERN_INFO, starget,
6743 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6744 pcie_device->handle, handle);
6745 sas_target_priv_data->handle = handle;
6746 pcie_device->handle = handle;
6748 if (le32_to_cpu(pcie_device_pg0.Flags) &
6749 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
6750 pcie_device->enclosure_level =
6751 pcie_device_pg0.EnclosureLevel;
6752 memcpy(&pcie_device->connector_name[0],
6753 &pcie_device_pg0.ConnectorName[0], 4);
6755 pcie_device->enclosure_level = 0;
6756 pcie_device->connector_name[0] = '\0';
6760 /* check if device is present */
6761 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
6762 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
6764 "device is not present handle(0x%04x), flags!!!\n",
6766 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6767 pcie_device_put(pcie_device);
6771 /* check if there were any issues with discovery */
6772 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
6773 pcie_device_pg0.AccessStatus)) {
6774 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6775 pcie_device_put(pcie_device);
6779 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6780 pcie_device_put(pcie_device);
6782 _scsih_ublock_io_device(ioc, wwid);
6788 * _scsih_pcie_add_device - creating pcie device object
6789 * @ioc: per adapter object
6790 * @handle: pcie device handle
6792 * Creating end device object, stored in ioc->pcie_device_list.
6794 * Return: 1 means queue the event later, 0 means complete the event
6797 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6799 Mpi26PCIeDevicePage0_t pcie_device_pg0;
6800 Mpi26PCIeDevicePage2_t pcie_device_pg2;
6801 Mpi2ConfigReply_t mpi_reply;
6802 struct _pcie_device *pcie_device;
6803 struct _enclosure_node *enclosure_dev;
6807 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
6808 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
6809 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6810 ioc->name, __FILE__, __LINE__, __func__);
6813 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6814 MPI2_IOCSTATUS_MASK;
6815 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6817 "failure at %s:%d/%s()!\n",
6818 ioc->name, __FILE__, __LINE__, __func__);
6822 set_bit(handle, ioc->pend_os_device_add);
6823 wwid = le64_to_cpu(pcie_device_pg0.WWID);
6825 /* check if device is present */
6826 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
6827 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
6829 "device is not present handle(0x04%x)!!!\n",
6834 /* check if there were any issues with discovery */
6835 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
6836 pcie_device_pg0.AccessStatus))
6839 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo))))
6842 pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid);
6844 clear_bit(handle, ioc->pend_os_device_add);
6845 pcie_device_put(pcie_device);
6849 pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL);
6851 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6852 ioc->name, __FILE__, __LINE__, __func__);
6856 kref_init(&pcie_device->refcount);
6857 pcie_device->id = ioc->pcie_target_id++;
6858 pcie_device->channel = PCIE_CHANNEL;
6859 pcie_device->handle = handle;
6860 pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
6861 pcie_device->wwid = wwid;
6862 pcie_device->port_num = pcie_device_pg0.PortNum;
6863 pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) &
6864 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
6866 pcie_device->enclosure_handle =
6867 le16_to_cpu(pcie_device_pg0.EnclosureHandle);
6868 if (pcie_device->enclosure_handle != 0)
6869 pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot);
6871 if (le32_to_cpu(pcie_device_pg0.Flags) &
6872 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
6873 pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel;
6874 memcpy(&pcie_device->connector_name[0],
6875 &pcie_device_pg0.ConnectorName[0], 4);
6877 pcie_device->enclosure_level = 0;
6878 pcie_device->connector_name[0] = '\0';
6881 /* get enclosure_logical_id */
6882 if (pcie_device->enclosure_handle) {
6884 mpt3sas_scsih_enclosure_find_by_handle(ioc,
6885 pcie_device->enclosure_handle);
6887 pcie_device->enclosure_logical_id =
6888 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6890 /* TODO -- Add device name once FW supports it */
6891 if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply,
6892 &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) {
6893 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6894 ioc->name, __FILE__, __LINE__, __func__);
6899 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6900 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6901 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6902 ioc->name, __FILE__, __LINE__, __func__);
6906 pcie_device->nvme_mdts =
6907 le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize);
6908 if (pcie_device_pg2.ControllerResetTO)
6909 pcie_device->reset_timeout =
6910 pcie_device_pg2.ControllerResetTO;
6912 pcie_device->reset_timeout = 30;
6914 if (ioc->wait_for_discovery_to_complete)
6915 _scsih_pcie_device_init_add(ioc, pcie_device);
6917 _scsih_pcie_device_add(ioc, pcie_device);
6919 pcie_device_put(pcie_device);
6924 * _scsih_pcie_topology_change_event_debug - debug for topology
6926 * @ioc: per adapter object
6927 * @event_data: event data payload
6931 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6932 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
6938 char *status_str = NULL;
6939 u8 link_rate, prev_link_rate;
6941 switch (event_data->SwitchStatus) {
6942 case MPI26_EVENT_PCIE_TOPO_SS_ADDED:
6945 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
6946 status_str = "remove";
6948 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING:
6950 status_str = "responding";
6952 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
6953 status_str = "remove delay";
6956 status_str = "unknown status";
6959 pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n",
6960 ioc->name, status_str);
6961 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
6962 "start_port(%02d), count(%d)\n",
6963 le16_to_cpu(event_data->SwitchDevHandle),
6964 le16_to_cpu(event_data->EnclosureHandle),
6965 event_data->StartPortNum, event_data->NumEntries);
6966 for (i = 0; i < event_data->NumEntries; i++) {
6968 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
6971 port_number = event_data->StartPortNum + i;
6972 reason_code = event_data->PortEntry[i].PortStatus;
6973 switch (reason_code) {
6974 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
6975 status_str = "target add";
6977 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
6978 status_str = "target remove";
6980 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
6981 status_str = "delay target remove";
6983 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
6984 status_str = "link rate change";
6986 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE:
6987 status_str = "target responding";
6990 status_str = "unknown";
6993 link_rate = event_data->PortEntry[i].CurrentPortInfo &
6994 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
6995 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo &
6996 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
6997 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
6998 " link rate: new(0x%02x), old(0x%02x)\n", port_number,
6999 handle, status_str, link_rate, prev_link_rate);
7004 * _scsih_pcie_topology_change_event - handle PCIe topology
7006 * @ioc: per adapter object
7007 * @fw_event: The fw_event_work object
7012 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
7013 struct fw_event_work *fw_event)
7018 u8 link_rate, prev_link_rate;
7019 unsigned long flags;
7021 Mpi26EventDataPCIeTopologyChangeList_t *event_data =
7022 (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data;
7023 struct _pcie_device *pcie_device;
7025 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7026 _scsih_pcie_topology_change_event_debug(ioc, event_data);
7028 if (ioc->shost_recovery || ioc->remove_host ||
7029 ioc->pci_error_recovery)
7032 if (fw_event->ignore) {
7033 dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n",
7038 /* handle siblings events */
7039 for (i = 0; i < event_data->NumEntries; i++) {
7040 if (fw_event->ignore) {
7041 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7042 "ignoring switch event\n", ioc->name));
7045 if (ioc->remove_host || ioc->pci_error_recovery)
7047 reason_code = event_data->PortEntry[i].PortStatus;
7049 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
7053 link_rate = event_data->PortEntry[i].CurrentPortInfo
7054 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
7055 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo
7056 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
7058 switch (reason_code) {
7059 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
7060 if (ioc->shost_recovery)
7062 if (link_rate == prev_link_rate)
7064 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
7067 _scsih_pcie_check_device(ioc, handle);
7069 /* This code after this point handles the test case
7070 * where a device has been added, however its returning
7071 * BUSY for sometime. Then before the Device Missing
7072 * Delay expires and the device becomes READY, the
7073 * device is removed and added back.
7075 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
7076 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
7077 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
7080 pcie_device_put(pcie_device);
7084 if (!test_bit(handle, ioc->pend_os_device_add))
7087 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7088 "handle(0x%04x) device not found: convert "
7089 "event to a device add\n", ioc->name, handle));
7090 event_data->PortEntry[i].PortStatus &= 0xF0;
7091 event_data->PortEntry[i].PortStatus |=
7092 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED;
7094 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
7095 if (ioc->shost_recovery)
7097 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
7100 rc = _scsih_pcie_add_device(ioc, handle);
7102 /* mark entry vacant */
7103 /* TODO This needs to be reviewed and fixed,
7104 * we dont have an entry
7105 * to make an event void like vacant
7107 event_data->PortEntry[i].PortStatus |=
7108 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE;
7111 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
7112 _scsih_pcie_device_remove_by_handle(ioc, handle);
7119 * _scsih_pcie_device_status_change_event_debug - debug for device event
7121 * @event_data: event data payload
7125 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7126 Mpi26EventDataPCIeDeviceStatusChange_t *event_data)
7128 char *reason_str = NULL;
7130 switch (event_data->ReasonCode) {
7131 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA:
7132 reason_str = "smart data";
7134 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED:
7135 reason_str = "unsupported device discovered";
7137 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET:
7138 reason_str = "internal device reset";
7140 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL:
7141 reason_str = "internal task abort";
7143 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
7144 reason_str = "internal task abort set";
7146 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
7147 reason_str = "internal clear task set";
7149 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL:
7150 reason_str = "internal query task";
7152 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE:
7153 reason_str = "device init failure";
7155 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
7156 reason_str = "internal device reset complete";
7158 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
7159 reason_str = "internal task abort complete";
7161 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION:
7162 reason_str = "internal async notification";
7164 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED:
7165 reason_str = "pcie hot reset failed";
7168 reason_str = "unknown reason";
7172 pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n"
7173 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7174 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
7175 (unsigned long long)le64_to_cpu(event_data->WWID),
7176 le16_to_cpu(event_data->TaskTag));
7177 if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA)
7178 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
7179 event_data->ASC, event_data->ASCQ);
7184 * _scsih_pcie_device_status_change_event - handle device status
7186 * @ioc: per adapter object
7187 * @fw_event: The fw_event_work object
7191 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7192 struct fw_event_work *fw_event)
7194 struct MPT3SAS_TARGET *target_priv_data;
7195 struct _pcie_device *pcie_device;
7197 unsigned long flags;
7198 Mpi26EventDataPCIeDeviceStatusChange_t *event_data =
7199 (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data;
7200 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7201 _scsih_pcie_device_status_change_event_debug(ioc,
7204 if (event_data->ReasonCode !=
7205 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET &&
7206 event_data->ReasonCode !=
7207 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
7210 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
7211 wwid = le64_to_cpu(event_data->WWID);
7212 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
7214 if (!pcie_device || !pcie_device->starget)
7217 target_priv_data = pcie_device->starget->hostdata;
7218 if (!target_priv_data)
7221 if (event_data->ReasonCode ==
7222 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET)
7223 target_priv_data->tm_busy = 1;
7225 target_priv_data->tm_busy = 0;
7228 pcie_device_put(pcie_device);
7230 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
7234 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7236 * @ioc: per adapter object
7237 * @event_data: event data payload
7241 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7242 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
7244 char *reason_str = NULL;
7246 switch (event_data->ReasonCode) {
7247 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
7248 reason_str = "enclosure add";
7250 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
7251 reason_str = "enclosure remove";
7254 reason_str = "unknown reason";
7258 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
7259 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
7260 " number slots(%d)\n", ioc->name, reason_str,
7261 le16_to_cpu(event_data->EnclosureHandle),
7262 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
7263 le16_to_cpu(event_data->StartSlot));
7267 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7268 * @ioc: per adapter object
7269 * @fw_event: The fw_event_work object
7273 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7274 struct fw_event_work *fw_event)
7276 Mpi2ConfigReply_t mpi_reply;
7277 struct _enclosure_node *enclosure_dev = NULL;
7278 Mpi2EventDataSasEnclDevStatusChange_t *event_data =
7279 (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data;
7281 u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle);
7283 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7284 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
7285 (Mpi2EventDataSasEnclDevStatusChange_t *)
7286 fw_event->event_data);
7287 if (ioc->shost_recovery)
7290 if (enclosure_handle)
7292 mpt3sas_scsih_enclosure_find_by_handle(ioc,
7294 switch (event_data->ReasonCode) {
7295 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
7296 if (!enclosure_dev) {
7298 kzalloc(sizeof(struct _enclosure_node),
7300 if (!enclosure_dev) {
7302 "failure at %s:%d/%s()!\n", ioc->name,
7303 __FILE__, __LINE__, __func__);
7306 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
7307 &enclosure_dev->pg0,
7308 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
7311 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
7312 MPI2_IOCSTATUS_MASK)) {
7313 kfree(enclosure_dev);
7317 list_add_tail(&enclosure_dev->list,
7318 &ioc->enclosure_list);
7321 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
7322 if (enclosure_dev) {
7323 list_del(&enclosure_dev->list);
7324 kfree(enclosure_dev);
7333 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7334 * @ioc: per adapter object
7335 * @fw_event: The fw_event_work object
7339 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
7340 struct fw_event_work *fw_event)
7342 struct scsi_cmnd *scmd;
7343 struct scsi_device *sdev;
7344 struct scsiio_tracker *st;
7347 struct MPT3SAS_DEVICE *sas_device_priv_data;
7348 u32 termination_count;
7350 Mpi2SCSITaskManagementReply_t *mpi_reply;
7351 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
7352 (Mpi2EventDataSasBroadcastPrimitive_t *)
7353 fw_event->event_data;
7355 unsigned long flags;
7358 u8 task_abort_retries;
7360 mutex_lock(&ioc->tm_cmds.mutex);
7362 "%s: enter: phy number(%d), width(%d)\n",
7363 ioc->name, __func__, event_data->PhyNum,
7364 event_data->PortWidth);
7366 _scsih_block_io_all_device(ioc);
7368 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7369 mpi_reply = ioc->tm_cmds.reply;
7370 broadcast_aen_retry:
7372 /* sanity checks for retrying this loop */
7373 if (max_retries++ == 5) {
7374 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
7375 ioc->name, __func__));
7377 } else if (max_retries > 1)
7378 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
7379 ioc->name, __func__, max_retries - 1));
7381 termination_count = 0;
7383 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
7384 if (ioc->shost_recovery)
7386 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
7389 st = scsi_cmd_priv(scmd);
7390 sdev = scmd->device;
7391 sas_device_priv_data = sdev->hostdata;
7392 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
7394 /* skip hidden raid components */
7395 if (sas_device_priv_data->sas_target->flags &
7396 MPT_TARGET_FLAGS_RAID_COMPONENT)
7399 if (sas_device_priv_data->sas_target->flags &
7400 MPT_TARGET_FLAGS_VOLUME)
7402 /* skip PCIe devices */
7403 if (sas_device_priv_data->sas_target->flags &
7404 MPT_TARGET_FLAGS_PCIE_DEVICE)
7407 handle = sas_device_priv_data->sas_target->handle;
7408 lun = sas_device_priv_data->lun;
7411 if (ioc->shost_recovery)
7414 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
7415 r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
7416 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
7417 st->msix_io, 30, 0);
7419 sdev_printk(KERN_WARNING, sdev,
7420 "mpt3sas_scsih_issue_tm: FAILED when sending "
7421 "QUERY_TASK: scmd(%p)\n", scmd);
7422 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7423 goto broadcast_aen_retry;
7425 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
7426 & MPI2_IOCSTATUS_MASK;
7427 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7428 sdev_printk(KERN_WARNING, sdev,
7429 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7431 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7432 goto broadcast_aen_retry;
7435 /* see if IO is still owned by IOC and target */
7436 if (mpi_reply->ResponseCode ==
7437 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
7438 mpi_reply->ResponseCode ==
7439 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
7440 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7443 task_abort_retries = 0;
7445 if (task_abort_retries++ == 60) {
7446 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7447 "%s: ABORT_TASK: giving up\n", ioc->name,
7449 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7450 goto broadcast_aen_retry;
7453 if (ioc->shost_recovery)
7456 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
7457 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid,
7458 st->msix_io, 30, 0);
7459 if (r == FAILED || st->cb_idx != 0xFF) {
7460 sdev_printk(KERN_WARNING, sdev,
7461 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7462 "scmd(%p)\n", scmd);
7466 if (task_abort_retries > 1)
7467 sdev_printk(KERN_WARNING, sdev,
7468 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7470 task_abort_retries - 1, scmd);
7472 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
7473 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7476 if (ioc->broadcast_aen_pending) {
7477 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7478 "%s: loop back due to pending AEN\n",
7479 ioc->name, __func__));
7480 ioc->broadcast_aen_pending = 0;
7481 goto broadcast_aen_retry;
7485 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
7488 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7489 "%s - exit, query_count = %d termination_count = %d\n",
7490 ioc->name, __func__, query_count, termination_count));
7492 ioc->broadcast_aen_busy = 0;
7493 if (!ioc->shost_recovery)
7494 _scsih_ublock_io_all_device(ioc);
7495 mutex_unlock(&ioc->tm_cmds.mutex);
7499 * _scsih_sas_discovery_event - handle discovery events
7500 * @ioc: per adapter object
7501 * @fw_event: The fw_event_work object
7505 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
7506 struct fw_event_work *fw_event)
7508 Mpi2EventDataSasDiscovery_t *event_data =
7509 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
7511 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
7512 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
7513 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
7515 if (event_data->DiscoveryStatus)
7516 pr_info("discovery_status(0x%08x)",
7517 le32_to_cpu(event_data->DiscoveryStatus));
7521 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
7522 !ioc->sas_hba.num_phys) {
7523 if (disable_discovery > 0 && ioc->shost_recovery) {
7524 /* Wait for the reset to complete */
7525 while (ioc->shost_recovery)
7528 _scsih_sas_host_add(ioc);
7533 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
7535 * @ioc: per adapter object
7536 * @fw_event: The fw_event_work object
7540 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc,
7541 struct fw_event_work *fw_event)
7543 Mpi25EventDataSasDeviceDiscoveryError_t *event_data =
7544 (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data;
7546 switch (event_data->ReasonCode) {
7547 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED:
7548 pr_warn(MPT3SAS_FMT "SMP command sent to the expander"
7549 "(handle:0x%04x, sas_address:0x%016llx,"
7550 "physical_port:0x%02x) has failed",
7551 ioc->name, le16_to_cpu(event_data->DevHandle),
7552 (unsigned long long)le64_to_cpu(event_data->SASAddress),
7553 event_data->PhysicalPort);
7555 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT:
7556 pr_warn(MPT3SAS_FMT "SMP command sent to the expander"
7557 "(handle:0x%04x, sas_address:0x%016llx,"
7558 "physical_port:0x%02x) has timed out",
7559 ioc->name, le16_to_cpu(event_data->DevHandle),
7560 (unsigned long long)le64_to_cpu(event_data->SASAddress),
7561 event_data->PhysicalPort);
7569 * _scsih_pcie_enumeration_event - handle enumeration events
7570 * @ioc: per adapter object
7571 * @fw_event: The fw_event_work object
7575 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc,
7576 struct fw_event_work *fw_event)
7578 Mpi26EventDataPCIeEnumeration_t *event_data =
7579 (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data;
7581 if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK))
7584 pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x",
7586 (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ?
7587 "started" : "completed",
7589 if (event_data->EnumerationStatus)
7590 pr_cont("enumeration_status(0x%08x)",
7591 le32_to_cpu(event_data->EnumerationStatus));
7596 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7597 * @ioc: per adapter object
7598 * @handle: device handle for physical disk
7599 * @phys_disk_num: physical disk number
7601 * Return: 0 for success, else failure.
7604 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
7606 Mpi2RaidActionRequest_t *mpi_request;
7607 Mpi2RaidActionReply_t *mpi_reply;
7614 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
7617 mutex_lock(&ioc->scsih_cmds.mutex);
7619 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7620 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7621 ioc->name, __func__);
7625 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7627 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7629 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7630 ioc->name, __func__);
7631 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7636 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7637 ioc->scsih_cmds.smid = smid;
7638 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7640 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7641 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
7642 mpi_request->PhysDiskNum = phys_disk_num;
7644 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
7645 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
7646 handle, phys_disk_num));
7648 init_completion(&ioc->scsih_cmds.done);
7649 mpt3sas_base_put_smid_default(ioc, smid);
7650 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7652 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7654 mpt3sas_base_check_cmd_timeout(ioc,
7655 ioc->scsih_cmds.status, mpi_request,
7656 sizeof(Mpi2RaidActionRequest_t)/4);
7661 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7663 mpi_reply = ioc->scsih_cmds.reply;
7664 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
7665 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
7666 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
7669 ioc_status &= MPI2_IOCSTATUS_MASK;
7670 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7671 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7672 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
7673 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
7677 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7678 "IR RAID_ACTION: completed successfully\n",
7683 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7684 mutex_unlock(&ioc->scsih_cmds.mutex);
7687 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
7692 * _scsih_reprobe_lun - reprobing lun
7693 * @sdev: scsi device struct
7694 * @no_uld_attach: sdev->no_uld_attach flag setting
7698 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
7700 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
7701 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
7702 sdev->no_uld_attach ? "hiding" : "exposing");
7703 WARN_ON(scsi_device_reprobe(sdev));
7707 * _scsih_sas_volume_add - add new volume
7708 * @ioc: per adapter object
7709 * @element: IR config element data
7713 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
7714 Mpi2EventIrConfigElement_t *element)
7716 struct _raid_device *raid_device;
7717 unsigned long flags;
7719 u16 handle = le16_to_cpu(element->VolDevHandle);
7722 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
7725 "failure at %s:%d/%s()!\n", ioc->name,
7726 __FILE__, __LINE__, __func__);
7730 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7731 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
7732 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7737 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
7740 "failure at %s:%d/%s()!\n", ioc->name,
7741 __FILE__, __LINE__, __func__);
7745 raid_device->id = ioc->sas_id++;
7746 raid_device->channel = RAID_CHANNEL;
7747 raid_device->handle = handle;
7748 raid_device->wwid = wwid;
7749 _scsih_raid_device_add(ioc, raid_device);
7750 if (!ioc->wait_for_discovery_to_complete) {
7751 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7752 raid_device->id, 0);
7754 _scsih_raid_device_remove(ioc, raid_device);
7756 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7757 _scsih_determine_boot_device(ioc, raid_device, 1);
7758 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7763 * _scsih_sas_volume_delete - delete volume
7764 * @ioc: per adapter object
7765 * @handle: volume device handle
7769 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
7771 struct _raid_device *raid_device;
7772 unsigned long flags;
7773 struct MPT3SAS_TARGET *sas_target_priv_data;
7774 struct scsi_target *starget = NULL;
7776 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7777 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
7779 if (raid_device->starget) {
7780 starget = raid_device->starget;
7781 sas_target_priv_data = starget->hostdata;
7782 sas_target_priv_data->deleted = 1;
7784 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7785 ioc->name, raid_device->handle,
7786 (unsigned long long) raid_device->wwid);
7787 list_del(&raid_device->list);
7790 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7792 scsi_remove_target(&starget->dev);
7796 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7797 * @ioc: per adapter object
7798 * @element: IR config element data
7802 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
7803 Mpi2EventIrConfigElement_t *element)
7805 struct _sas_device *sas_device;
7806 struct scsi_target *starget = NULL;
7807 struct MPT3SAS_TARGET *sas_target_priv_data;
7808 unsigned long flags;
7809 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7811 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7812 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
7814 sas_device->volume_handle = 0;
7815 sas_device->volume_wwid = 0;
7816 clear_bit(handle, ioc->pd_handles);
7817 if (sas_device->starget && sas_device->starget->hostdata) {
7818 starget = sas_device->starget;
7819 sas_target_priv_data = starget->hostdata;
7820 sas_target_priv_data->flags &=
7821 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
7824 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7828 /* exposing raid component */
7830 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
7832 sas_device_put(sas_device);
7836 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7837 * @ioc: per adapter object
7838 * @element: IR config element data
7842 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
7843 Mpi2EventIrConfigElement_t *element)
7845 struct _sas_device *sas_device;
7846 struct scsi_target *starget = NULL;
7847 struct MPT3SAS_TARGET *sas_target_priv_data;
7848 unsigned long flags;
7849 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7850 u16 volume_handle = 0;
7851 u64 volume_wwid = 0;
7853 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
7855 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
7858 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7859 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
7861 set_bit(handle, ioc->pd_handles);
7862 if (sas_device->starget && sas_device->starget->hostdata) {
7863 starget = sas_device->starget;
7864 sas_target_priv_data = starget->hostdata;
7865 sas_target_priv_data->flags |=
7866 MPT_TARGET_FLAGS_RAID_COMPONENT;
7867 sas_device->volume_handle = volume_handle;
7868 sas_device->volume_wwid = volume_wwid;
7871 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7875 /* hiding raid component */
7876 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7879 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
7881 sas_device_put(sas_device);
7885 * _scsih_sas_pd_delete - delete pd component
7886 * @ioc: per adapter object
7887 * @element: IR config element data
7891 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
7892 Mpi2EventIrConfigElement_t *element)
7894 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7896 _scsih_device_remove_by_handle(ioc, handle);
7900 * _scsih_sas_pd_add - remove pd component
7901 * @ioc: per adapter object
7902 * @element: IR config element data
7906 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
7907 Mpi2EventIrConfigElement_t *element)
7909 struct _sas_device *sas_device;
7910 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7911 Mpi2ConfigReply_t mpi_reply;
7912 Mpi2SasDevicePage0_t sas_device_pg0;
7917 set_bit(handle, ioc->pd_handles);
7919 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7921 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7922 sas_device_put(sas_device);
7926 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
7927 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
7928 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7929 ioc->name, __FILE__, __LINE__, __func__);
7933 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7934 MPI2_IOCSTATUS_MASK;
7935 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7936 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7937 ioc->name, __FILE__, __LINE__, __func__);
7941 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7942 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
7943 mpt3sas_transport_update_links(ioc, sas_address, handle,
7944 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7946 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7947 _scsih_add_device(ioc, handle, 0, 1);
7951 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7952 * @ioc: per adapter object
7953 * @event_data: event data payload
7957 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7958 Mpi2EventDataIrConfigChangeList_t *event_data)
7960 Mpi2EventIrConfigElement_t *element;
7963 char *reason_str = NULL, *element_str = NULL;
7965 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
7967 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
7968 ioc->name, (le32_to_cpu(event_data->Flags) &
7969 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
7970 "foreign" : "native", event_data->NumElements);
7971 for (i = 0; i < event_data->NumElements; i++, element++) {
7972 switch (element->ReasonCode) {
7973 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
7976 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
7977 reason_str = "remove";
7979 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
7980 reason_str = "no change";
7982 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
7983 reason_str = "hide";
7985 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
7986 reason_str = "unhide";
7988 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
7989 reason_str = "volume_created";
7991 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
7992 reason_str = "volume_deleted";
7994 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
7995 reason_str = "pd_created";
7997 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
7998 reason_str = "pd_deleted";
8001 reason_str = "unknown reason";
8004 element_type = le16_to_cpu(element->ElementFlags) &
8005 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
8006 switch (element_type) {
8007 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
8008 element_str = "volume";
8010 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
8011 element_str = "phys disk";
8013 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
8014 element_str = "hot spare";
8017 element_str = "unknown element";
8020 pr_info("\t(%s:%s), vol handle(0x%04x), " \
8021 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
8022 reason_str, le16_to_cpu(element->VolDevHandle),
8023 le16_to_cpu(element->PhysDiskDevHandle),
8024 element->PhysDiskNum);
8029 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8030 * @ioc: per adapter object
8031 * @fw_event: The fw_event_work object
8035 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
8036 struct fw_event_work *fw_event)
8038 Mpi2EventIrConfigElement_t *element;
8041 Mpi2EventDataIrConfigChangeList_t *event_data =
8042 (Mpi2EventDataIrConfigChangeList_t *)
8043 fw_event->event_data;
8045 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
8046 (!ioc->hide_ir_msg))
8047 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
8049 foreign_config = (le32_to_cpu(event_data->Flags) &
8050 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
8052 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
8053 if (ioc->shost_recovery &&
8054 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
8055 for (i = 0; i < event_data->NumElements; i++, element++) {
8056 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
8057 _scsih_ir_fastpath(ioc,
8058 le16_to_cpu(element->PhysDiskDevHandle),
8059 element->PhysDiskNum);
8064 for (i = 0; i < event_data->NumElements; i++, element++) {
8066 switch (element->ReasonCode) {
8067 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
8068 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
8069 if (!foreign_config)
8070 _scsih_sas_volume_add(ioc, element);
8072 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
8073 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
8074 if (!foreign_config)
8075 _scsih_sas_volume_delete(ioc,
8076 le16_to_cpu(element->VolDevHandle));
8078 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
8079 if (!ioc->is_warpdrive)
8080 _scsih_sas_pd_hide(ioc, element);
8082 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
8083 if (!ioc->is_warpdrive)
8084 _scsih_sas_pd_expose(ioc, element);
8086 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
8087 if (!ioc->is_warpdrive)
8088 _scsih_sas_pd_add(ioc, element);
8090 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
8091 if (!ioc->is_warpdrive)
8092 _scsih_sas_pd_delete(ioc, element);
8099 * _scsih_sas_ir_volume_event - IR volume event
8100 * @ioc: per adapter object
8101 * @fw_event: The fw_event_work object
8105 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
8106 struct fw_event_work *fw_event)
8109 unsigned long flags;
8110 struct _raid_device *raid_device;
8114 Mpi2EventDataIrVolume_t *event_data =
8115 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
8117 if (ioc->shost_recovery)
8120 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
8123 handle = le16_to_cpu(event_data->VolDevHandle);
8124 state = le32_to_cpu(event_data->NewValue);
8125 if (!ioc->hide_ir_msg)
8126 dewtprintk(ioc, pr_info(MPT3SAS_FMT
8127 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8128 ioc->name, __func__, handle,
8129 le32_to_cpu(event_data->PreviousValue), state));
8131 case MPI2_RAID_VOL_STATE_MISSING:
8132 case MPI2_RAID_VOL_STATE_FAILED:
8133 _scsih_sas_volume_delete(ioc, handle);
8136 case MPI2_RAID_VOL_STATE_ONLINE:
8137 case MPI2_RAID_VOL_STATE_DEGRADED:
8138 case MPI2_RAID_VOL_STATE_OPTIMAL:
8140 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8141 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
8142 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8147 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
8150 "failure at %s:%d/%s()!\n", ioc->name,
8151 __FILE__, __LINE__, __func__);
8155 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
8158 "failure at %s:%d/%s()!\n", ioc->name,
8159 __FILE__, __LINE__, __func__);
8163 raid_device->id = ioc->sas_id++;
8164 raid_device->channel = RAID_CHANNEL;
8165 raid_device->handle = handle;
8166 raid_device->wwid = wwid;
8167 _scsih_raid_device_add(ioc, raid_device);
8168 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8169 raid_device->id, 0);
8171 _scsih_raid_device_remove(ioc, raid_device);
8174 case MPI2_RAID_VOL_STATE_INITIALIZING:
8181 * _scsih_sas_ir_physical_disk_event - PD event
8182 * @ioc: per adapter object
8183 * @fw_event: The fw_event_work object
8187 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
8188 struct fw_event_work *fw_event)
8190 u16 handle, parent_handle;
8192 struct _sas_device *sas_device;
8193 Mpi2ConfigReply_t mpi_reply;
8194 Mpi2SasDevicePage0_t sas_device_pg0;
8196 Mpi2EventDataIrPhysicalDisk_t *event_data =
8197 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
8200 if (ioc->shost_recovery)
8203 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
8206 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
8207 state = le32_to_cpu(event_data->NewValue);
8209 if (!ioc->hide_ir_msg)
8210 dewtprintk(ioc, pr_info(MPT3SAS_FMT
8211 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8212 ioc->name, __func__, handle,
8213 le32_to_cpu(event_data->PreviousValue), state));
8216 case MPI2_RAID_PD_STATE_ONLINE:
8217 case MPI2_RAID_PD_STATE_DEGRADED:
8218 case MPI2_RAID_PD_STATE_REBUILDING:
8219 case MPI2_RAID_PD_STATE_OPTIMAL:
8220 case MPI2_RAID_PD_STATE_HOT_SPARE:
8222 if (!ioc->is_warpdrive)
8223 set_bit(handle, ioc->pd_handles);
8225 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
8227 sas_device_put(sas_device);
8231 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8232 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
8234 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8235 ioc->name, __FILE__, __LINE__, __func__);
8239 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8240 MPI2_IOCSTATUS_MASK;
8241 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8242 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8243 ioc->name, __FILE__, __LINE__, __func__);
8247 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
8248 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
8249 mpt3sas_transport_update_links(ioc, sas_address, handle,
8250 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
8252 _scsih_add_device(ioc, handle, 0, 1);
8256 case MPI2_RAID_PD_STATE_OFFLINE:
8257 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
8258 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
8265 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8266 * @ioc: per adapter object
8267 * @event_data: event data payload
8271 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
8272 Mpi2EventDataIrOperationStatus_t *event_data)
8274 char *reason_str = NULL;
8276 switch (event_data->RAIDOperation) {
8277 case MPI2_EVENT_IR_RAIDOP_RESYNC:
8278 reason_str = "resync";
8280 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
8281 reason_str = "online capacity expansion";
8283 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
8284 reason_str = "consistency check";
8286 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
8287 reason_str = "background init";
8289 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
8290 reason_str = "make data consistent";
8297 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
8298 "\thandle(0x%04x), percent complete(%d)\n",
8299 ioc->name, reason_str,
8300 le16_to_cpu(event_data->VolDevHandle),
8301 event_data->PercentComplete);
8305 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8306 * @ioc: per adapter object
8307 * @fw_event: The fw_event_work object
8311 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
8312 struct fw_event_work *fw_event)
8314 Mpi2EventDataIrOperationStatus_t *event_data =
8315 (Mpi2EventDataIrOperationStatus_t *)
8316 fw_event->event_data;
8317 static struct _raid_device *raid_device;
8318 unsigned long flags;
8321 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
8322 (!ioc->hide_ir_msg))
8323 _scsih_sas_ir_operation_status_event_debug(ioc,
8326 /* code added for raid transport support */
8327 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
8329 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8330 handle = le16_to_cpu(event_data->VolDevHandle);
8331 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
8333 raid_device->percent_complete =
8334 event_data->PercentComplete;
8335 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8340 * _scsih_prep_device_scan - initialize parameters prior to device scan
8341 * @ioc: per adapter object
8343 * Set the deleted flag prior to device scan. If the device is found during
8344 * the scan, then we clear the deleted flag.
8347 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
8349 struct MPT3SAS_DEVICE *sas_device_priv_data;
8350 struct scsi_device *sdev;
8352 shost_for_each_device(sdev, ioc->shost) {
8353 sas_device_priv_data = sdev->hostdata;
8354 if (sas_device_priv_data && sas_device_priv_data->sas_target)
8355 sas_device_priv_data->sas_target->deleted = 1;
8360 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8361 * @ioc: per adapter object
8362 * @sas_device_pg0: SAS Device page 0
8364 * After host reset, find out whether devices are still responding.
8365 * Used in _scsih_remove_unresponsive_sas_devices.
8368 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
8369 Mpi2SasDevicePage0_t *sas_device_pg0)
8371 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8372 struct scsi_target *starget;
8373 struct _sas_device *sas_device = NULL;
8374 struct _enclosure_node *enclosure_dev = NULL;
8375 unsigned long flags;
8377 if (sas_device_pg0->EnclosureHandle) {
8379 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8380 le16_to_cpu(sas_device_pg0->EnclosureHandle));
8381 if (enclosure_dev == NULL)
8382 pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)"
8383 "doesn't match with enclosure device!\n",
8384 ioc->name, sas_device_pg0->EnclosureHandle);
8386 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8387 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
8388 if ((sas_device->sas_address == le64_to_cpu(
8389 sas_device_pg0->SASAddress)) && (sas_device->slot ==
8390 le16_to_cpu(sas_device_pg0->Slot))) {
8391 sas_device->responding = 1;
8392 starget = sas_device->starget;
8393 if (starget && starget->hostdata) {
8394 sas_target_priv_data = starget->hostdata;
8395 sas_target_priv_data->tm_busy = 0;
8396 sas_target_priv_data->deleted = 0;
8398 sas_target_priv_data = NULL;
8400 starget_printk(KERN_INFO, starget,
8401 "handle(0x%04x), sas_addr(0x%016llx)\n",
8402 le16_to_cpu(sas_device_pg0->DevHandle),
8403 (unsigned long long)
8404 sas_device->sas_address);
8406 if (sas_device->enclosure_handle != 0)
8407 starget_printk(KERN_INFO, starget,
8408 "enclosure logical id(0x%016llx),"
8410 (unsigned long long)
8411 sas_device->enclosure_logical_id,
8414 if (le16_to_cpu(sas_device_pg0->Flags) &
8415 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
8416 sas_device->enclosure_level =
8417 sas_device_pg0->EnclosureLevel;
8418 memcpy(&sas_device->connector_name[0],
8419 &sas_device_pg0->ConnectorName[0], 4);
8421 sas_device->enclosure_level = 0;
8422 sas_device->connector_name[0] = '\0';
8425 sas_device->enclosure_handle =
8426 le16_to_cpu(sas_device_pg0->EnclosureHandle);
8427 sas_device->is_chassis_slot_valid = 0;
8428 if (enclosure_dev) {
8429 sas_device->enclosure_logical_id = le64_to_cpu(
8430 enclosure_dev->pg0.EnclosureLogicalID);
8431 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
8432 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
8433 sas_device->is_chassis_slot_valid = 1;
8434 sas_device->chassis_slot =
8435 enclosure_dev->pg0.ChassisSlot;
8439 if (sas_device->handle == le16_to_cpu(
8440 sas_device_pg0->DevHandle))
8442 pr_info("\thandle changed from(0x%04x)!!!\n",
8443 sas_device->handle);
8444 sas_device->handle = le16_to_cpu(
8445 sas_device_pg0->DevHandle);
8446 if (sas_target_priv_data)
8447 sas_target_priv_data->handle =
8448 le16_to_cpu(sas_device_pg0->DevHandle);
8453 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8457 * _scsih_create_enclosure_list_after_reset - Free Existing list,
8458 * And create enclosure list by scanning all Enclosure Page(0)s
8459 * @ioc: per adapter object
8462 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc)
8464 struct _enclosure_node *enclosure_dev;
8465 Mpi2ConfigReply_t mpi_reply;
8466 u16 enclosure_handle;
8469 /* Free existing enclosure list */
8470 mpt3sas_free_enclosure_list(ioc);
8472 /* Re constructing enclosure list after reset*/
8473 enclosure_handle = 0xFFFF;
8476 kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL);
8477 if (!enclosure_dev) {
8479 "failure at %s:%d/%s()!\n", ioc->name,
8480 __FILE__, __LINE__, __func__);
8483 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
8484 &enclosure_dev->pg0,
8485 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE,
8488 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
8489 MPI2_IOCSTATUS_MASK)) {
8490 kfree(enclosure_dev);
8493 list_add_tail(&enclosure_dev->list,
8494 &ioc->enclosure_list);
8496 le16_to_cpu(enclosure_dev->pg0.EnclosureHandle);
8501 * _scsih_search_responding_sas_devices -
8502 * @ioc: per adapter object
8504 * After host reset, find out whether devices are still responding.
8508 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
8510 Mpi2SasDevicePage0_t sas_device_pg0;
8511 Mpi2ConfigReply_t mpi_reply;
8516 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
8518 if (list_empty(&ioc->sas_device_list))
8522 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8523 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
8525 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8526 MPI2_IOCSTATUS_MASK;
8527 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8529 handle = le16_to_cpu(sas_device_pg0.DevHandle);
8530 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
8531 if (!(_scsih_is_end_device(device_info)))
8533 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
8537 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
8542 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8543 * @ioc: per adapter object
8544 * @pcie_device_pg0: PCIe Device page 0
8546 * After host reset, find out whether devices are still responding.
8547 * Used in _scsih_remove_unresponding_devices.
8550 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc,
8551 Mpi26PCIeDevicePage0_t *pcie_device_pg0)
8553 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8554 struct scsi_target *starget;
8555 struct _pcie_device *pcie_device;
8556 unsigned long flags;
8558 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8559 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
8560 if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID))
8561 && (pcie_device->slot == le16_to_cpu(
8562 pcie_device_pg0->Slot))) {
8563 pcie_device->responding = 1;
8564 starget = pcie_device->starget;
8565 if (starget && starget->hostdata) {
8566 sas_target_priv_data = starget->hostdata;
8567 sas_target_priv_data->tm_busy = 0;
8568 sas_target_priv_data->deleted = 0;
8570 sas_target_priv_data = NULL;
8572 starget_printk(KERN_INFO, starget,
8573 "handle(0x%04x), wwid(0x%016llx) ",
8574 pcie_device->handle,
8575 (unsigned long long)pcie_device->wwid);
8576 if (pcie_device->enclosure_handle != 0)
8577 starget_printk(KERN_INFO, starget,
8578 "enclosure logical id(0x%016llx), "
8580 (unsigned long long)
8581 pcie_device->enclosure_logical_id,
8585 if (((le32_to_cpu(pcie_device_pg0->Flags)) &
8586 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) &&
8587 (ioc->hba_mpi_version_belonged != MPI2_VERSION)) {
8588 pcie_device->enclosure_level =
8589 pcie_device_pg0->EnclosureLevel;
8590 memcpy(&pcie_device->connector_name[0],
8591 &pcie_device_pg0->ConnectorName[0], 4);
8593 pcie_device->enclosure_level = 0;
8594 pcie_device->connector_name[0] = '\0';
8597 if (pcie_device->handle == le16_to_cpu(
8598 pcie_device_pg0->DevHandle))
8600 pr_info("\thandle changed from(0x%04x)!!!\n",
8601 pcie_device->handle);
8602 pcie_device->handle = le16_to_cpu(
8603 pcie_device_pg0->DevHandle);
8604 if (sas_target_priv_data)
8605 sas_target_priv_data->handle =
8606 le16_to_cpu(pcie_device_pg0->DevHandle);
8612 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8616 * _scsih_search_responding_pcie_devices -
8617 * @ioc: per adapter object
8619 * After host reset, find out whether devices are still responding.
8623 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc)
8625 Mpi26PCIeDevicePage0_t pcie_device_pg0;
8626 Mpi2ConfigReply_t mpi_reply;
8631 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
8633 if (list_empty(&ioc->pcie_device_list))
8637 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
8638 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
8640 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8641 MPI2_IOCSTATUS_MASK;
8642 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8643 pr_info(MPT3SAS_FMT "\tbreak from %s: "
8644 "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc->name,
8645 __func__, ioc_status,
8646 le32_to_cpu(mpi_reply.IOCLogInfo));
8649 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
8650 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
8651 if (!(_scsih_is_nvme_device(device_info)))
8653 _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0);
8656 pr_info(MPT3SAS_FMT "search for PCIe end-devices: complete\n",
8661 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8662 * @ioc: per adapter object
8663 * @wwid: world wide identifier for raid volume
8664 * @handle: device handle
8666 * After host reset, find out whether devices are still responding.
8667 * Used in _scsih_remove_unresponsive_raid_devices.
8670 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
8673 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8674 struct scsi_target *starget;
8675 struct _raid_device *raid_device;
8676 unsigned long flags;
8678 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8679 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
8680 if (raid_device->wwid == wwid && raid_device->starget) {
8681 starget = raid_device->starget;
8682 if (starget && starget->hostdata) {
8683 sas_target_priv_data = starget->hostdata;
8684 sas_target_priv_data->deleted = 0;
8686 sas_target_priv_data = NULL;
8687 raid_device->responding = 1;
8688 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8689 starget_printk(KERN_INFO, raid_device->starget,
8690 "handle(0x%04x), wwid(0x%016llx)\n", handle,
8691 (unsigned long long)raid_device->wwid);
8694 * WARPDRIVE: The handles of the PDs might have changed
8695 * across the host reset so re-initialize the
8696 * required data for Direct IO
8698 mpt3sas_init_warpdrive_properties(ioc, raid_device);
8699 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8700 if (raid_device->handle == handle) {
8701 spin_unlock_irqrestore(&ioc->raid_device_lock,
8705 pr_info("\thandle changed from(0x%04x)!!!\n",
8706 raid_device->handle);
8707 raid_device->handle = handle;
8708 if (sas_target_priv_data)
8709 sas_target_priv_data->handle = handle;
8710 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8714 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8718 * _scsih_search_responding_raid_devices -
8719 * @ioc: per adapter object
8721 * After host reset, find out whether devices are still responding.
8725 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
8727 Mpi2RaidVolPage1_t volume_pg1;
8728 Mpi2RaidVolPage0_t volume_pg0;
8729 Mpi2RaidPhysDiskPage0_t pd_pg0;
8730 Mpi2ConfigReply_t mpi_reply;
8735 if (!ioc->ir_firmware)
8738 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
8741 if (list_empty(&ioc->raid_device_list))
8745 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
8746 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
8747 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8748 MPI2_IOCSTATUS_MASK;
8749 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8751 handle = le16_to_cpu(volume_pg1.DevHandle);
8753 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
8754 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
8755 sizeof(Mpi2RaidVolPage0_t)))
8758 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
8759 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
8760 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
8761 _scsih_mark_responding_raid_device(ioc,
8762 le64_to_cpu(volume_pg1.WWID), handle);
8765 /* refresh the pd_handles */
8766 if (!ioc->is_warpdrive) {
8767 phys_disk_num = 0xFF;
8768 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
8769 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
8770 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
8772 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8773 MPI2_IOCSTATUS_MASK;
8774 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8776 phys_disk_num = pd_pg0.PhysDiskNum;
8777 handle = le16_to_cpu(pd_pg0.DevHandle);
8778 set_bit(handle, ioc->pd_handles);
8782 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
8787 * _scsih_mark_responding_expander - mark a expander as responding
8788 * @ioc: per adapter object
8789 * @expander_pg0:SAS Expander Config Page0
8791 * After host reset, find out whether devices are still responding.
8792 * Used in _scsih_remove_unresponsive_expanders.
8795 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc,
8796 Mpi2ExpanderPage0_t *expander_pg0)
8798 struct _sas_node *sas_expander = NULL;
8799 unsigned long flags;
8801 struct _enclosure_node *enclosure_dev = NULL;
8802 u16 handle = le16_to_cpu(expander_pg0->DevHandle);
8803 u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle);
8804 u64 sas_address = le64_to_cpu(expander_pg0->SASAddress);
8806 if (enclosure_handle)
8808 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8811 spin_lock_irqsave(&ioc->sas_node_lock, flags);
8812 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
8813 if (sas_expander->sas_address != sas_address)
8815 sas_expander->responding = 1;
8817 if (enclosure_dev) {
8818 sas_expander->enclosure_logical_id =
8819 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
8820 sas_expander->enclosure_handle =
8821 le16_to_cpu(expander_pg0->EnclosureHandle);
8824 if (sas_expander->handle == handle)
8826 pr_info("\texpander(0x%016llx): handle changed" \
8827 " from(0x%04x) to (0x%04x)!!!\n",
8828 (unsigned long long)sas_expander->sas_address,
8829 sas_expander->handle, handle);
8830 sas_expander->handle = handle;
8831 for (i = 0 ; i < sas_expander->num_phys ; i++)
8832 sas_expander->phy[i].handle = handle;
8836 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
8840 * _scsih_search_responding_expanders -
8841 * @ioc: per adapter object
8843 * After host reset, find out whether devices are still responding.
8847 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
8849 Mpi2ExpanderPage0_t expander_pg0;
8850 Mpi2ConfigReply_t mpi_reply;
8855 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
8857 if (list_empty(&ioc->sas_expander_list))
8861 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
8862 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
8864 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8865 MPI2_IOCSTATUS_MASK;
8866 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8869 handle = le16_to_cpu(expander_pg0.DevHandle);
8870 sas_address = le64_to_cpu(expander_pg0.SASAddress);
8871 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8873 (unsigned long long)sas_address);
8874 _scsih_mark_responding_expander(ioc, &expander_pg0);
8878 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
8882 * _scsih_remove_unresponding_devices - removing unresponding devices
8883 * @ioc: per adapter object
8886 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc)
8888 struct _sas_device *sas_device, *sas_device_next;
8889 struct _sas_node *sas_expander, *sas_expander_next;
8890 struct _raid_device *raid_device, *raid_device_next;
8891 struct _pcie_device *pcie_device, *pcie_device_next;
8892 struct list_head tmp_list;
8893 unsigned long flags;
8896 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
8899 /* removing unresponding end devices */
8900 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
8903 * Iterate, pulling off devices marked as non-responding. We become the
8904 * owner for the reference the list had on any object we prune.
8906 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8907 list_for_each_entry_safe(sas_device, sas_device_next,
8908 &ioc->sas_device_list, list) {
8909 if (!sas_device->responding)
8910 list_move_tail(&sas_device->list, &head);
8912 sas_device->responding = 0;
8914 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8917 * Now, uninitialize and remove the unresponding devices we pruned.
8919 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
8920 _scsih_remove_device(ioc, sas_device);
8921 list_del_init(&sas_device->list);
8922 sas_device_put(sas_device);
8926 " Removing unresponding devices: pcie end-devices\n"
8928 INIT_LIST_HEAD(&head);
8929 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8930 list_for_each_entry_safe(pcie_device, pcie_device_next,
8931 &ioc->pcie_device_list, list) {
8932 if (!pcie_device->responding)
8933 list_move_tail(&pcie_device->list, &head);
8935 pcie_device->responding = 0;
8937 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8939 list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) {
8940 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
8941 list_del_init(&pcie_device->list);
8942 pcie_device_put(pcie_device);
8945 /* removing unresponding volumes */
8946 if (ioc->ir_firmware) {
8947 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
8949 list_for_each_entry_safe(raid_device, raid_device_next,
8950 &ioc->raid_device_list, list) {
8951 if (!raid_device->responding)
8952 _scsih_sas_volume_delete(ioc,
8953 raid_device->handle);
8955 raid_device->responding = 0;
8959 /* removing unresponding expanders */
8960 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
8962 spin_lock_irqsave(&ioc->sas_node_lock, flags);
8963 INIT_LIST_HEAD(&tmp_list);
8964 list_for_each_entry_safe(sas_expander, sas_expander_next,
8965 &ioc->sas_expander_list, list) {
8966 if (!sas_expander->responding)
8967 list_move_tail(&sas_expander->list, &tmp_list);
8969 sas_expander->responding = 0;
8971 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
8972 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
8974 _scsih_expander_node_remove(ioc, sas_expander);
8977 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
8980 /* unblock devices */
8981 _scsih_ublock_io_all_device(ioc);
8985 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
8986 struct _sas_node *sas_expander, u16 handle)
8988 Mpi2ExpanderPage1_t expander_pg1;
8989 Mpi2ConfigReply_t mpi_reply;
8992 for (i = 0 ; i < sas_expander->num_phys ; i++) {
8993 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
8994 &expander_pg1, i, handle))) {
8995 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8996 ioc->name, __FILE__, __LINE__, __func__);
9000 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
9001 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
9002 expander_pg1.NegotiatedLinkRate >> 4);
9007 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
9008 * @ioc: per adapter object
9011 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
9013 Mpi2ExpanderPage0_t expander_pg0;
9014 Mpi2SasDevicePage0_t sas_device_pg0;
9015 Mpi26PCIeDevicePage0_t pcie_device_pg0;
9016 Mpi2RaidVolPage1_t volume_pg1;
9017 Mpi2RaidVolPage0_t volume_pg0;
9018 Mpi2RaidPhysDiskPage0_t pd_pg0;
9019 Mpi2EventIrConfigElement_t element;
9020 Mpi2ConfigReply_t mpi_reply;
9023 u16 handle, parent_handle;
9025 struct _sas_device *sas_device;
9026 struct _pcie_device *pcie_device;
9027 struct _sas_node *expander_device;
9028 static struct _raid_device *raid_device;
9030 unsigned long flags;
9032 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
9034 _scsih_sas_host_refresh(ioc);
9036 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
9040 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
9041 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
9042 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9043 MPI2_IOCSTATUS_MASK;
9044 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9045 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
9046 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9047 ioc->name, ioc_status,
9048 le32_to_cpu(mpi_reply.IOCLogInfo));
9051 handle = le16_to_cpu(expander_pg0.DevHandle);
9052 spin_lock_irqsave(&ioc->sas_node_lock, flags);
9053 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
9054 ioc, le64_to_cpu(expander_pg0.SASAddress));
9055 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
9056 if (expander_device)
9057 _scsih_refresh_expander_links(ioc, expander_device,
9060 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
9061 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9062 handle, (unsigned long long)
9063 le64_to_cpu(expander_pg0.SASAddress));
9064 _scsih_expander_add(ioc, handle);
9065 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
9066 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9067 handle, (unsigned long long)
9068 le64_to_cpu(expander_pg0.SASAddress));
9072 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
9075 if (!ioc->ir_firmware)
9078 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
9081 phys_disk_num = 0xFF;
9082 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
9083 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
9085 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9086 MPI2_IOCSTATUS_MASK;
9087 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9088 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
9089 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9090 ioc->name, ioc_status,
9091 le32_to_cpu(mpi_reply.IOCLogInfo));
9094 phys_disk_num = pd_pg0.PhysDiskNum;
9095 handle = le16_to_cpu(pd_pg0.DevHandle);
9096 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
9098 sas_device_put(sas_device);
9101 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9102 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
9105 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9106 MPI2_IOCSTATUS_MASK;
9107 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9108 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
9109 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9110 ioc->name, ioc_status,
9111 le32_to_cpu(mpi_reply.IOCLogInfo));
9114 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9115 if (!_scsih_get_sas_address(ioc, parent_handle,
9117 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
9118 " handle (0x%04x), sas_addr(0x%016llx)\n",
9119 ioc->name, handle, (unsigned long long)
9120 le64_to_cpu(sas_device_pg0.SASAddress));
9121 mpt3sas_transport_update_links(ioc, sas_address,
9122 handle, sas_device_pg0.PhyNum,
9123 MPI2_SAS_NEG_LINK_RATE_1_5);
9124 set_bit(handle, ioc->pd_handles);
9126 /* This will retry adding the end device.
9127 * _scsih_add_device() will decide on retries and
9128 * return "1" when it should be retried
9130 while (_scsih_add_device(ioc, handle, retry_count++,
9134 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
9135 " handle (0x%04x), sas_addr(0x%016llx)\n",
9136 ioc->name, handle, (unsigned long long)
9137 le64_to_cpu(sas_device_pg0.SASAddress));
9141 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
9144 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
9148 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
9149 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
9150 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9151 MPI2_IOCSTATUS_MASK;
9152 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9153 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
9154 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9155 ioc->name, ioc_status,
9156 le32_to_cpu(mpi_reply.IOCLogInfo));
9159 handle = le16_to_cpu(volume_pg1.DevHandle);
9160 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9161 raid_device = _scsih_raid_device_find_by_wwid(ioc,
9162 le64_to_cpu(volume_pg1.WWID));
9163 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9166 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
9167 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
9168 sizeof(Mpi2RaidVolPage0_t)))
9170 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9171 MPI2_IOCSTATUS_MASK;
9172 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9173 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
9174 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9175 ioc->name, ioc_status,
9176 le32_to_cpu(mpi_reply.IOCLogInfo));
9179 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
9180 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
9181 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
9182 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
9183 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
9184 element.VolDevHandle = volume_pg1.DevHandle;
9186 "\tBEFORE adding volume: handle (0x%04x)\n",
9187 ioc->name, volume_pg1.DevHandle);
9188 _scsih_sas_volume_add(ioc, &element);
9190 "\tAFTER adding volume: handle (0x%04x)\n",
9191 ioc->name, volume_pg1.DevHandle);
9195 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
9200 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
9205 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9206 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9208 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9209 MPI2_IOCSTATUS_MASK;
9210 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9211 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
9212 " ioc_status(0x%04x), loginfo(0x%08x)\n",
9213 ioc->name, ioc_status,
9214 le32_to_cpu(mpi_reply.IOCLogInfo));
9217 handle = le16_to_cpu(sas_device_pg0.DevHandle);
9218 if (!(_scsih_is_end_device(
9219 le32_to_cpu(sas_device_pg0.DeviceInfo))))
9221 sas_device = mpt3sas_get_sdev_by_addr(ioc,
9222 le64_to_cpu(sas_device_pg0.SASAddress));
9224 sas_device_put(sas_device);
9227 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9228 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
9229 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
9230 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9231 handle, (unsigned long long)
9232 le64_to_cpu(sas_device_pg0.SASAddress));
9233 mpt3sas_transport_update_links(ioc, sas_address, handle,
9234 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
9236 /* This will retry adding the end device.
9237 * _scsih_add_device() will decide on retries and
9238 * return "1" when it should be retried
9240 while (_scsih_add_device(ioc, handle, retry_count++,
9244 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
9245 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9246 handle, (unsigned long long)
9247 le64_to_cpu(sas_device_pg0.SASAddress));
9250 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
9252 pr_info(MPT3SAS_FMT "\tscan devices: pcie end devices start\n",
9257 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
9258 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9260 ioc_status = le16_to_cpu(mpi_reply.IOCStatus)
9261 & MPI2_IOCSTATUS_MASK;
9262 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9263 pr_info(MPT3SAS_FMT "\tbreak from pcie end device"
9264 " scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9265 ioc->name, ioc_status,
9266 le32_to_cpu(mpi_reply.IOCLogInfo));
9269 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
9270 if (!(_scsih_is_nvme_device(
9271 le32_to_cpu(pcie_device_pg0.DeviceInfo))))
9273 pcie_device = mpt3sas_get_pdev_by_wwid(ioc,
9274 le64_to_cpu(pcie_device_pg0.WWID));
9276 pcie_device_put(pcie_device);
9280 parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle);
9281 _scsih_pcie_add_device(ioc, handle);
9283 pr_info(MPT3SAS_FMT "\tAFTER adding pcie end device: "
9284 "handle (0x%04x), wwid(0x%016llx)\n", ioc->name,
9286 (unsigned long long) le64_to_cpu(pcie_device_pg0.WWID));
9288 pr_info(MPT3SAS_FMT "\tpcie devices: pcie end devices complete\n",
9290 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
9294 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9295 * @ioc: per adapter object
9297 * The handler for doing any required cleanup or initialization.
9299 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
9301 dtmprintk(ioc, pr_info(MPT3SAS_FMT
9302 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
9306 * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
9307 * @ioc: per adapter object
9309 * The handler for doing any required cleanup or initialization.
9312 mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER *ioc)
9314 dtmprintk(ioc, pr_info(MPT3SAS_FMT
9315 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
9316 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
9317 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
9318 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
9319 complete(&ioc->scsih_cmds.done);
9321 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
9322 ioc->tm_cmds.status |= MPT3_CMD_RESET;
9323 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
9324 complete(&ioc->tm_cmds.done);
9327 memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
9328 memset(ioc->device_remove_in_progress, 0,
9329 ioc->device_remove_in_progress_sz);
9330 _scsih_fw_event_cleanup_queue(ioc);
9331 _scsih_flush_running_cmds(ioc);
9335 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9336 * @ioc: per adapter object
9338 * The handler for doing any required cleanup or initialization.
9341 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
9343 dtmprintk(ioc, pr_info(MPT3SAS_FMT
9344 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
9345 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
9346 !ioc->sas_hba.num_phys)) {
9347 _scsih_prep_device_scan(ioc);
9348 _scsih_create_enclosure_list_after_reset(ioc);
9349 _scsih_search_responding_sas_devices(ioc);
9350 _scsih_search_responding_pcie_devices(ioc);
9351 _scsih_search_responding_raid_devices(ioc);
9352 _scsih_search_responding_expanders(ioc);
9353 _scsih_error_recovery_delete_devices(ioc);
9358 * _mpt3sas_fw_work - delayed task for processing firmware events
9359 * @ioc: per adapter object
9360 * @fw_event: The fw_event_work object
9364 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
9366 _scsih_fw_event_del_from_list(ioc, fw_event);
9368 /* the queue is being flushed so ignore this event */
9369 if (ioc->remove_host || ioc->pci_error_recovery) {
9370 fw_event_work_put(fw_event);
9374 switch (fw_event->event) {
9375 case MPT3SAS_PROCESS_TRIGGER_DIAG:
9376 mpt3sas_process_trigger_data(ioc,
9377 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
9378 fw_event->event_data);
9380 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
9381 while (scsi_host_in_recovery(ioc->shost) ||
9382 ioc->shost_recovery) {
9384 * If we're unloading, bail. Otherwise, this can become
9387 if (ioc->remove_host)
9391 _scsih_remove_unresponding_devices(ioc);
9392 _scsih_scan_for_devices_after_reset(ioc);
9394 case MPT3SAS_PORT_ENABLE_COMPLETE:
9395 ioc->start_scan = 0;
9396 if (missing_delay[0] != -1 && missing_delay[1] != -1)
9397 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
9399 dewtprintk(ioc, pr_info(MPT3SAS_FMT
9400 "port enable: complete from worker thread\n",
9403 case MPT3SAS_TURN_ON_PFA_LED:
9404 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
9406 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
9407 _scsih_sas_topology_change_event(ioc, fw_event);
9409 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
9410 _scsih_sas_device_status_change_event(ioc, fw_event);
9412 case MPI2_EVENT_SAS_DISCOVERY:
9413 _scsih_sas_discovery_event(ioc, fw_event);
9415 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
9416 _scsih_sas_device_discovery_error_event(ioc, fw_event);
9418 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
9419 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
9421 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
9422 _scsih_sas_enclosure_dev_status_change_event(ioc,
9425 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
9426 _scsih_sas_ir_config_change_event(ioc, fw_event);
9428 case MPI2_EVENT_IR_VOLUME:
9429 _scsih_sas_ir_volume_event(ioc, fw_event);
9431 case MPI2_EVENT_IR_PHYSICAL_DISK:
9432 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
9434 case MPI2_EVENT_IR_OPERATION_STATUS:
9435 _scsih_sas_ir_operation_status_event(ioc, fw_event);
9437 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
9438 _scsih_pcie_device_status_change_event(ioc, fw_event);
9440 case MPI2_EVENT_PCIE_ENUMERATION:
9441 _scsih_pcie_enumeration_event(ioc, fw_event);
9443 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
9444 _scsih_pcie_topology_change_event(ioc, fw_event);
9449 fw_event_work_put(fw_event);
9453 * _firmware_event_work
9454 * @work: The fw_event_work object
9457 * wrappers for the work thread handling firmware events
9461 _firmware_event_work(struct work_struct *work)
9463 struct fw_event_work *fw_event = container_of(work,
9464 struct fw_event_work, work);
9466 _mpt3sas_fw_work(fw_event->ioc, fw_event);
9470 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9471 * @ioc: per adapter object
9472 * @msix_index: MSIX table index supplied by the OS
9473 * @reply: reply message frame(lower 32bit addr)
9474 * Context: interrupt.
9476 * This function merely adds a new work task into ioc->firmware_event_thread.
9477 * The tasks are worked from _firmware_event_work in user context.
9479 * Return: 1 meaning mf should be freed from _base_interrupt
9480 * 0 means the mf is freed from this function.
9483 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
9486 struct fw_event_work *fw_event;
9487 Mpi2EventNotificationReply_t *mpi_reply;
9490 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
9492 /* events turned off due to host reset */
9493 if (ioc->pci_error_recovery)
9496 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
9498 if (unlikely(!mpi_reply)) {
9499 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
9500 ioc->name, __FILE__, __LINE__, __func__);
9504 event = le16_to_cpu(mpi_reply->Event);
9506 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
9507 mpt3sas_trigger_event(ioc, event, 0);
9511 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
9513 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
9514 (Mpi2EventDataSasBroadcastPrimitive_t *)
9515 mpi_reply->EventData;
9517 if (baen_data->Primitive !=
9518 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
9521 if (ioc->broadcast_aen_busy) {
9522 ioc->broadcast_aen_pending++;
9525 ioc->broadcast_aen_busy = 1;
9529 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
9530 _scsih_check_topo_delete_events(ioc,
9531 (Mpi2EventDataSasTopologyChangeList_t *)
9532 mpi_reply->EventData);
9534 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
9535 _scsih_check_pcie_topo_remove_events(ioc,
9536 (Mpi26EventDataPCIeTopologyChangeList_t *)
9537 mpi_reply->EventData);
9539 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
9540 _scsih_check_ir_config_unhide_events(ioc,
9541 (Mpi2EventDataIrConfigChangeList_t *)
9542 mpi_reply->EventData);
9544 case MPI2_EVENT_IR_VOLUME:
9545 _scsih_check_volume_delete_events(ioc,
9546 (Mpi2EventDataIrVolume_t *)
9547 mpi_reply->EventData);
9549 case MPI2_EVENT_LOG_ENTRY_ADDED:
9551 Mpi2EventDataLogEntryAdded_t *log_entry;
9554 if (!ioc->is_warpdrive)
9557 log_entry = (Mpi2EventDataLogEntryAdded_t *)
9558 mpi_reply->EventData;
9559 log_code = (u32 *)log_entry->LogData;
9561 if (le16_to_cpu(log_entry->LogEntryQualifier)
9562 != MPT2_WARPDRIVE_LOGENTRY)
9565 switch (le32_to_cpu(*log_code)) {
9566 case MPT2_WARPDRIVE_LC_SSDT:
9567 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
9568 "IO Throttling has occurred in the WarpDrive "
9569 "subsystem. Check WarpDrive documentation for "
9570 "additional details.\n", ioc->name);
9572 case MPT2_WARPDRIVE_LC_SSDLW:
9573 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
9574 "Program/Erase Cycles for the WarpDrive subsystem "
9575 "in degraded range. Check WarpDrive documentation "
9576 "for additional details.\n", ioc->name);
9578 case MPT2_WARPDRIVE_LC_SSDLF:
9579 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
9580 "There are no Program/Erase Cycles for the "
9581 "WarpDrive subsystem. The storage device will be "
9582 "in read-only mode. Check WarpDrive documentation "
9583 "for additional details.\n", ioc->name);
9585 case MPT2_WARPDRIVE_LC_BRMF:
9586 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
9587 "The Backup Rail Monitor has failed on the "
9588 "WarpDrive subsystem. Check WarpDrive "
9589 "documentation for additional details.\n",
9596 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
9597 case MPI2_EVENT_IR_OPERATION_STATUS:
9598 case MPI2_EVENT_SAS_DISCOVERY:
9599 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
9600 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
9601 case MPI2_EVENT_IR_PHYSICAL_DISK:
9602 case MPI2_EVENT_PCIE_ENUMERATION:
9603 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
9606 case MPI2_EVENT_TEMP_THRESHOLD:
9607 _scsih_temp_threshold_events(ioc,
9608 (Mpi2EventDataTemperature_t *)
9609 mpi_reply->EventData);
9611 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
9612 ActiveCableEventData =
9613 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
9614 switch (ActiveCableEventData->ReasonCode) {
9615 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
9616 pr_notice(MPT3SAS_FMT
9617 "Currently an active cable with ReceptacleID %d\n",
9618 ioc->name, ActiveCableEventData->ReceptacleID);
9619 pr_notice("cannot be powered and devices connected\n");
9620 pr_notice("to this active cable will not be seen\n");
9621 pr_notice("This active cable requires %d mW of power\n",
9622 ActiveCableEventData->ActiveCablePowerRequirement);
9625 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
9626 pr_notice(MPT3SAS_FMT
9627 "Currently a cable with ReceptacleID %d\n",
9628 ioc->name, ActiveCableEventData->ReceptacleID);
9630 "is not running at optimal speed(12 Gb/s rate)\n");
9636 default: /* ignore the rest */
9640 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
9641 fw_event = alloc_fw_event_work(sz);
9643 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
9644 ioc->name, __FILE__, __LINE__, __func__);
9648 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
9649 fw_event->ioc = ioc;
9650 fw_event->VF_ID = mpi_reply->VF_ID;
9651 fw_event->VP_ID = mpi_reply->VP_ID;
9652 fw_event->event = event;
9653 _scsih_fw_event_add(ioc, fw_event);
9654 fw_event_work_put(fw_event);
9659 * _scsih_expander_node_remove - removing expander device from list.
9660 * @ioc: per adapter object
9661 * @sas_expander: the sas_device object
9663 * Removing object and freeing associated memory from the
9664 * ioc->sas_expander_list.
9667 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
9668 struct _sas_node *sas_expander)
9670 struct _sas_port *mpt3sas_port, *next;
9671 unsigned long flags;
9673 /* remove sibling ports attached to this expander */
9674 list_for_each_entry_safe(mpt3sas_port, next,
9675 &sas_expander->sas_port_list, port_list) {
9676 if (ioc->shost_recovery)
9678 if (mpt3sas_port->remote_identify.device_type ==
9680 mpt3sas_device_remove_by_sas_address(ioc,
9681 mpt3sas_port->remote_identify.sas_address);
9682 else if (mpt3sas_port->remote_identify.device_type ==
9683 SAS_EDGE_EXPANDER_DEVICE ||
9684 mpt3sas_port->remote_identify.device_type ==
9685 SAS_FANOUT_EXPANDER_DEVICE)
9686 mpt3sas_expander_remove(ioc,
9687 mpt3sas_port->remote_identify.sas_address);
9690 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
9691 sas_expander->sas_address_parent);
9694 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9696 sas_expander->handle, (unsigned long long)
9697 sas_expander->sas_address);
9699 spin_lock_irqsave(&ioc->sas_node_lock, flags);
9700 list_del(&sas_expander->list);
9701 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
9703 kfree(sas_expander->phy);
9704 kfree(sas_expander);
9708 * _scsih_ir_shutdown - IR shutdown notification
9709 * @ioc: per adapter object
9711 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9712 * the host system is shutting down.
9715 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
9717 Mpi2RaidActionRequest_t *mpi_request;
9718 Mpi2RaidActionReply_t *mpi_reply;
9721 /* is IR firmware build loaded ? */
9722 if (!ioc->ir_firmware)
9725 /* are there any volumes ? */
9726 if (list_empty(&ioc->raid_device_list))
9729 mutex_lock(&ioc->scsih_cmds.mutex);
9731 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
9732 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
9733 ioc->name, __func__);
9736 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
9738 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
9740 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
9741 ioc->name, __func__);
9742 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
9746 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
9747 ioc->scsih_cmds.smid = smid;
9748 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
9750 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
9751 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
9753 if (!ioc->hide_ir_msg)
9754 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
9755 init_completion(&ioc->scsih_cmds.done);
9756 mpt3sas_base_put_smid_default(ioc, smid);
9757 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
9759 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
9760 pr_err(MPT3SAS_FMT "%s: timeout\n",
9761 ioc->name, __func__);
9765 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
9766 mpi_reply = ioc->scsih_cmds.reply;
9767 if (!ioc->hide_ir_msg)
9768 pr_info(MPT3SAS_FMT "IR shutdown "
9769 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9770 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
9771 le32_to_cpu(mpi_reply->IOCLogInfo));
9775 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
9776 mutex_unlock(&ioc->scsih_cmds.mutex);
9780 * scsih_remove - detach and remove add host
9781 * @pdev: PCI device struct
9783 * Routine called when unloading the driver.
9785 static void scsih_remove(struct pci_dev *pdev)
9787 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9788 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9789 struct _sas_port *mpt3sas_port, *next_port;
9790 struct _raid_device *raid_device, *next;
9791 struct MPT3SAS_TARGET *sas_target_priv_data;
9792 struct _pcie_device *pcie_device, *pcienext;
9793 struct workqueue_struct *wq;
9794 unsigned long flags;
9796 ioc->remove_host = 1;
9798 mpt3sas_wait_for_commands_to_complete(ioc);
9799 _scsih_flush_running_cmds(ioc);
9801 _scsih_fw_event_cleanup_queue(ioc);
9803 spin_lock_irqsave(&ioc->fw_event_lock, flags);
9804 wq = ioc->firmware_event_thread;
9805 ioc->firmware_event_thread = NULL;
9806 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
9808 destroy_workqueue(wq);
9810 /* release all the volumes */
9811 _scsih_ir_shutdown(ioc);
9812 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
9814 if (raid_device->starget) {
9815 sas_target_priv_data =
9816 raid_device->starget->hostdata;
9817 sas_target_priv_data->deleted = 1;
9818 scsi_remove_target(&raid_device->starget->dev);
9820 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
9821 ioc->name, raid_device->handle,
9822 (unsigned long long) raid_device->wwid);
9823 _scsih_raid_device_remove(ioc, raid_device);
9825 list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list,
9827 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
9828 list_del_init(&pcie_device->list);
9829 pcie_device_put(pcie_device);
9832 /* free ports attached to the sas_host */
9833 list_for_each_entry_safe(mpt3sas_port, next_port,
9834 &ioc->sas_hba.sas_port_list, port_list) {
9835 if (mpt3sas_port->remote_identify.device_type ==
9837 mpt3sas_device_remove_by_sas_address(ioc,
9838 mpt3sas_port->remote_identify.sas_address);
9839 else if (mpt3sas_port->remote_identify.device_type ==
9840 SAS_EDGE_EXPANDER_DEVICE ||
9841 mpt3sas_port->remote_identify.device_type ==
9842 SAS_FANOUT_EXPANDER_DEVICE)
9843 mpt3sas_expander_remove(ioc,
9844 mpt3sas_port->remote_identify.sas_address);
9847 /* free phys attached to the sas_host */
9848 if (ioc->sas_hba.num_phys) {
9849 kfree(ioc->sas_hba.phy);
9850 ioc->sas_hba.phy = NULL;
9851 ioc->sas_hba.num_phys = 0;
9854 sas_remove_host(shost);
9855 mpt3sas_base_detach(ioc);
9856 spin_lock(&gioc_lock);
9857 list_del(&ioc->list);
9858 spin_unlock(&gioc_lock);
9859 scsi_host_put(shost);
9863 * scsih_shutdown - routine call during system shutdown
9864 * @pdev: PCI device struct
9867 scsih_shutdown(struct pci_dev *pdev)
9869 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9870 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9871 struct workqueue_struct *wq;
9872 unsigned long flags;
9874 ioc->remove_host = 1;
9876 mpt3sas_wait_for_commands_to_complete(ioc);
9877 _scsih_flush_running_cmds(ioc);
9879 _scsih_fw_event_cleanup_queue(ioc);
9881 spin_lock_irqsave(&ioc->fw_event_lock, flags);
9882 wq = ioc->firmware_event_thread;
9883 ioc->firmware_event_thread = NULL;
9884 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
9886 destroy_workqueue(wq);
9888 _scsih_ir_shutdown(ioc);
9889 mpt3sas_base_detach(ioc);
9894 * _scsih_probe_boot_devices - reports 1st device
9895 * @ioc: per adapter object
9897 * If specified in bios page 2, this routine reports the 1st
9898 * device scsi-ml or sas transport for persistent boot device
9899 * purposes. Please refer to function _scsih_determine_boot_device()
9902 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
9906 struct _sas_device *sas_device;
9907 struct _raid_device *raid_device;
9908 struct _pcie_device *pcie_device;
9910 u64 sas_address_parent;
9912 unsigned long flags;
9916 /* no Bios, return immediately */
9917 if (!ioc->bios_pg3.BiosVersion)
9921 if (ioc->req_boot_device.device) {
9922 device = ioc->req_boot_device.device;
9923 channel = ioc->req_boot_device.channel;
9924 } else if (ioc->req_alt_boot_device.device) {
9925 device = ioc->req_alt_boot_device.device;
9926 channel = ioc->req_alt_boot_device.channel;
9927 } else if (ioc->current_boot_device.device) {
9928 device = ioc->current_boot_device.device;
9929 channel = ioc->current_boot_device.channel;
9935 if (channel == RAID_CHANNEL) {
9936 raid_device = device;
9937 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9938 raid_device->id, 0);
9940 _scsih_raid_device_remove(ioc, raid_device);
9941 } else if (channel == PCIE_CHANNEL) {
9942 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
9943 pcie_device = device;
9944 tid = pcie_device->id;
9945 list_move_tail(&pcie_device->list, &ioc->pcie_device_list);
9946 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
9947 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0);
9949 _scsih_pcie_device_remove(ioc, pcie_device);
9951 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9952 sas_device = device;
9953 handle = sas_device->handle;
9954 sas_address_parent = sas_device->sas_address_parent;
9955 sas_address = sas_device->sas_address;
9956 list_move_tail(&sas_device->list, &ioc->sas_device_list);
9957 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9959 if (ioc->hide_drives)
9961 if (!mpt3sas_transport_port_add(ioc, handle,
9962 sas_address_parent)) {
9963 _scsih_sas_device_remove(ioc, sas_device);
9964 } else if (!sas_device->starget) {
9965 if (!ioc->is_driver_loading) {
9966 mpt3sas_transport_port_remove(ioc,
9968 sas_address_parent);
9969 _scsih_sas_device_remove(ioc, sas_device);
9976 * _scsih_probe_raid - reporting raid volumes to scsi-ml
9977 * @ioc: per adapter object
9979 * Called during initial loading of the driver.
9982 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
9984 struct _raid_device *raid_device, *raid_next;
9987 list_for_each_entry_safe(raid_device, raid_next,
9988 &ioc->raid_device_list, list) {
9989 if (raid_device->starget)
9991 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9992 raid_device->id, 0);
9994 _scsih_raid_device_remove(ioc, raid_device);
9998 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
10000 struct _sas_device *sas_device = NULL;
10001 unsigned long flags;
10003 spin_lock_irqsave(&ioc->sas_device_lock, flags);
10004 if (!list_empty(&ioc->sas_device_init_list)) {
10005 sas_device = list_first_entry(&ioc->sas_device_init_list,
10006 struct _sas_device, list);
10007 sas_device_get(sas_device);
10009 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
10014 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
10015 struct _sas_device *sas_device)
10017 unsigned long flags;
10019 spin_lock_irqsave(&ioc->sas_device_lock, flags);
10022 * Since we dropped the lock during the call to port_add(), we need to
10023 * be careful here that somebody else didn't move or delete this item
10024 * while we were busy with other things.
10026 * If it was on the list, we need a put() for the reference the list
10027 * had. Either way, we need a get() for the destination list.
10029 if (!list_empty(&sas_device->list)) {
10030 list_del_init(&sas_device->list);
10031 sas_device_put(sas_device);
10034 sas_device_get(sas_device);
10035 list_add_tail(&sas_device->list, &ioc->sas_device_list);
10037 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
10041 * _scsih_probe_sas - reporting sas devices to sas transport
10042 * @ioc: per adapter object
10044 * Called during initial loading of the driver.
10047 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
10049 struct _sas_device *sas_device;
10051 if (ioc->hide_drives)
10054 while ((sas_device = get_next_sas_device(ioc))) {
10055 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
10056 sas_device->sas_address_parent)) {
10057 _scsih_sas_device_remove(ioc, sas_device);
10058 sas_device_put(sas_device);
10060 } else if (!sas_device->starget) {
10062 * When asyn scanning is enabled, its not possible to
10063 * remove devices while scanning is turned on due to an
10064 * oops in scsi_sysfs_add_sdev()->add_device()->
10065 * sysfs_addrm_start()
10067 if (!ioc->is_driver_loading) {
10068 mpt3sas_transport_port_remove(ioc,
10069 sas_device->sas_address,
10070 sas_device->sas_address_parent);
10071 _scsih_sas_device_remove(ioc, sas_device);
10072 sas_device_put(sas_device);
10076 sas_device_make_active(ioc, sas_device);
10077 sas_device_put(sas_device);
10082 * get_next_pcie_device - Get the next pcie device
10083 * @ioc: per adapter object
10085 * Get the next pcie device from pcie_device_init_list list.
10087 * Return: pcie device structure if pcie_device_init_list list is not empty
10088 * otherwise returns NULL
10090 static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc)
10092 struct _pcie_device *pcie_device = NULL;
10093 unsigned long flags;
10095 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
10096 if (!list_empty(&ioc->pcie_device_init_list)) {
10097 pcie_device = list_first_entry(&ioc->pcie_device_init_list,
10098 struct _pcie_device, list);
10099 pcie_device_get(pcie_device);
10101 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
10103 return pcie_device;
10107 * pcie_device_make_active - Add pcie device to pcie_device_list list
10108 * @ioc: per adapter object
10109 * @pcie_device: pcie device object
10111 * Add the pcie device which has registered with SCSI Transport Later to
10112 * pcie_device_list list
10114 static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc,
10115 struct _pcie_device *pcie_device)
10117 unsigned long flags;
10119 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
10121 if (!list_empty(&pcie_device->list)) {
10122 list_del_init(&pcie_device->list);
10123 pcie_device_put(pcie_device);
10125 pcie_device_get(pcie_device);
10126 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
10128 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
10132 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10133 * @ioc: per adapter object
10135 * Called during initial loading of the driver.
10138 _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc)
10140 struct _pcie_device *pcie_device;
10143 /* PCIe Device List */
10144 while ((pcie_device = get_next_pcie_device(ioc))) {
10145 if (pcie_device->starget) {
10146 pcie_device_put(pcie_device);
10149 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL,
10150 pcie_device->id, 0);
10152 _scsih_pcie_device_remove(ioc, pcie_device);
10153 pcie_device_put(pcie_device);
10155 } else if (!pcie_device->starget) {
10157 * When async scanning is enabled, its not possible to
10158 * remove devices while scanning is turned on due to an
10159 * oops in scsi_sysfs_add_sdev()->add_device()->
10160 * sysfs_addrm_start()
10162 if (!ioc->is_driver_loading) {
10163 /* TODO-- Need to find out whether this condition will
10166 _scsih_pcie_device_remove(ioc, pcie_device);
10167 pcie_device_put(pcie_device);
10171 pcie_device_make_active(ioc, pcie_device);
10172 pcie_device_put(pcie_device);
10177 * _scsih_probe_devices - probing for devices
10178 * @ioc: per adapter object
10180 * Called during initial loading of the driver.
10183 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
10185 u16 volume_mapping_flags;
10187 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
10188 return; /* return when IOC doesn't support initiator mode */
10190 _scsih_probe_boot_devices(ioc);
10192 if (ioc->ir_firmware) {
10193 volume_mapping_flags =
10194 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
10195 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
10196 if (volume_mapping_flags ==
10197 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
10198 _scsih_probe_raid(ioc);
10199 _scsih_probe_sas(ioc);
10201 _scsih_probe_sas(ioc);
10202 _scsih_probe_raid(ioc);
10205 _scsih_probe_sas(ioc);
10206 _scsih_probe_pcie(ioc);
10211 * scsih_scan_start - scsi lld callback for .scan_start
10212 * @shost: SCSI host pointer
10214 * The shost has the ability to discover targets on its own instead
10215 * of scanning the entire bus. In our implemention, we will kick off
10216 * firmware discovery.
10219 scsih_scan_start(struct Scsi_Host *shost)
10221 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10223 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
10224 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
10226 if (disable_discovery > 0)
10229 ioc->start_scan = 1;
10230 rc = mpt3sas_port_enable(ioc);
10233 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
10237 * scsih_scan_finished - scsi lld callback for .scan_finished
10238 * @shost: SCSI host pointer
10239 * @time: elapsed time of the scan in jiffies
10241 * This function will be called periodicallyn until it returns 1 with the
10242 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10243 * we wait for firmware discovery to complete, then return 1.
10246 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
10248 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10250 if (disable_discovery > 0) {
10251 ioc->is_driver_loading = 0;
10252 ioc->wait_for_discovery_to_complete = 0;
10256 if (time >= (300 * HZ)) {
10257 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
10258 pr_info(MPT3SAS_FMT
10259 "port enable: FAILED with timeout (timeout=300s)\n",
10261 ioc->is_driver_loading = 0;
10265 if (ioc->start_scan)
10268 if (ioc->start_scan_failed) {
10269 pr_info(MPT3SAS_FMT
10270 "port enable: FAILED with (ioc_status=0x%08x)\n",
10271 ioc->name, ioc->start_scan_failed);
10272 ioc->is_driver_loading = 0;
10273 ioc->wait_for_discovery_to_complete = 0;
10274 ioc->remove_host = 1;
10278 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
10279 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
10281 if (ioc->wait_for_discovery_to_complete) {
10282 ioc->wait_for_discovery_to_complete = 0;
10283 _scsih_probe_devices(ioc);
10285 mpt3sas_base_start_watchdog(ioc);
10286 ioc->is_driver_loading = 0;
10290 /* shost template for SAS 2.0 HBA devices */
10291 static struct scsi_host_template mpt2sas_driver_template = {
10292 .module = THIS_MODULE,
10293 .name = "Fusion MPT SAS Host",
10294 .proc_name = MPT2SAS_DRIVER_NAME,
10295 .queuecommand = scsih_qcmd,
10296 .target_alloc = scsih_target_alloc,
10297 .slave_alloc = scsih_slave_alloc,
10298 .slave_configure = scsih_slave_configure,
10299 .target_destroy = scsih_target_destroy,
10300 .slave_destroy = scsih_slave_destroy,
10301 .scan_finished = scsih_scan_finished,
10302 .scan_start = scsih_scan_start,
10303 .change_queue_depth = scsih_change_queue_depth,
10304 .eh_abort_handler = scsih_abort,
10305 .eh_device_reset_handler = scsih_dev_reset,
10306 .eh_target_reset_handler = scsih_target_reset,
10307 .eh_host_reset_handler = scsih_host_reset,
10308 .bios_param = scsih_bios_param,
10311 .sg_tablesize = MPT2SAS_SG_DEPTH,
10312 .max_sectors = 32767,
10314 .use_clustering = ENABLE_CLUSTERING,
10315 .shost_attrs = mpt3sas_host_attrs,
10316 .sdev_attrs = mpt3sas_dev_attrs,
10317 .track_queue_depth = 1,
10318 .cmd_size = sizeof(struct scsiio_tracker),
10321 /* raid transport support for SAS 2.0 HBA devices */
10322 static struct raid_function_template mpt2sas_raid_functions = {
10323 .cookie = &mpt2sas_driver_template,
10324 .is_raid = scsih_is_raid,
10325 .get_resync = scsih_get_resync,
10326 .get_state = scsih_get_state,
10329 /* shost template for SAS 3.0 HBA devices */
10330 static struct scsi_host_template mpt3sas_driver_template = {
10331 .module = THIS_MODULE,
10332 .name = "Fusion MPT SAS Host",
10333 .proc_name = MPT3SAS_DRIVER_NAME,
10334 .queuecommand = scsih_qcmd,
10335 .target_alloc = scsih_target_alloc,
10336 .slave_alloc = scsih_slave_alloc,
10337 .slave_configure = scsih_slave_configure,
10338 .target_destroy = scsih_target_destroy,
10339 .slave_destroy = scsih_slave_destroy,
10340 .scan_finished = scsih_scan_finished,
10341 .scan_start = scsih_scan_start,
10342 .change_queue_depth = scsih_change_queue_depth,
10343 .eh_abort_handler = scsih_abort,
10344 .eh_device_reset_handler = scsih_dev_reset,
10345 .eh_target_reset_handler = scsih_target_reset,
10346 .eh_host_reset_handler = scsih_host_reset,
10347 .bios_param = scsih_bios_param,
10350 .sg_tablesize = MPT3SAS_SG_DEPTH,
10351 .max_sectors = 32767,
10353 .use_clustering = ENABLE_CLUSTERING,
10354 .shost_attrs = mpt3sas_host_attrs,
10355 .sdev_attrs = mpt3sas_dev_attrs,
10356 .track_queue_depth = 1,
10357 .cmd_size = sizeof(struct scsiio_tracker),
10360 /* raid transport support for SAS 3.0 HBA devices */
10361 static struct raid_function_template mpt3sas_raid_functions = {
10362 .cookie = &mpt3sas_driver_template,
10363 .is_raid = scsih_is_raid,
10364 .get_resync = scsih_get_resync,
10365 .get_state = scsih_get_state,
10369 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10370 * this device belongs to.
10371 * @pdev: PCI device struct
10373 * return MPI2_VERSION for SAS 2.0 HBA devices,
10374 * MPI25_VERSION for SAS 3.0 HBA devices, and
10375 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10378 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
10381 switch (pdev->device) {
10382 case MPI2_MFGPAGE_DEVID_SSS6200:
10383 case MPI2_MFGPAGE_DEVID_SAS2004:
10384 case MPI2_MFGPAGE_DEVID_SAS2008:
10385 case MPI2_MFGPAGE_DEVID_SAS2108_1:
10386 case MPI2_MFGPAGE_DEVID_SAS2108_2:
10387 case MPI2_MFGPAGE_DEVID_SAS2108_3:
10388 case MPI2_MFGPAGE_DEVID_SAS2116_1:
10389 case MPI2_MFGPAGE_DEVID_SAS2116_2:
10390 case MPI2_MFGPAGE_DEVID_SAS2208_1:
10391 case MPI2_MFGPAGE_DEVID_SAS2208_2:
10392 case MPI2_MFGPAGE_DEVID_SAS2208_3:
10393 case MPI2_MFGPAGE_DEVID_SAS2208_4:
10394 case MPI2_MFGPAGE_DEVID_SAS2208_5:
10395 case MPI2_MFGPAGE_DEVID_SAS2208_6:
10396 case MPI2_MFGPAGE_DEVID_SAS2308_1:
10397 case MPI2_MFGPAGE_DEVID_SAS2308_2:
10398 case MPI2_MFGPAGE_DEVID_SAS2308_3:
10399 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
10400 return MPI2_VERSION;
10401 case MPI25_MFGPAGE_DEVID_SAS3004:
10402 case MPI25_MFGPAGE_DEVID_SAS3008:
10403 case MPI25_MFGPAGE_DEVID_SAS3108_1:
10404 case MPI25_MFGPAGE_DEVID_SAS3108_2:
10405 case MPI25_MFGPAGE_DEVID_SAS3108_5:
10406 case MPI25_MFGPAGE_DEVID_SAS3108_6:
10407 return MPI25_VERSION;
10408 case MPI26_MFGPAGE_DEVID_SAS3216:
10409 case MPI26_MFGPAGE_DEVID_SAS3224:
10410 case MPI26_MFGPAGE_DEVID_SAS3316_1:
10411 case MPI26_MFGPAGE_DEVID_SAS3316_2:
10412 case MPI26_MFGPAGE_DEVID_SAS3316_3:
10413 case MPI26_MFGPAGE_DEVID_SAS3316_4:
10414 case MPI26_MFGPAGE_DEVID_SAS3324_1:
10415 case MPI26_MFGPAGE_DEVID_SAS3324_2:
10416 case MPI26_MFGPAGE_DEVID_SAS3324_3:
10417 case MPI26_MFGPAGE_DEVID_SAS3324_4:
10418 case MPI26_MFGPAGE_DEVID_SAS3508:
10419 case MPI26_MFGPAGE_DEVID_SAS3508_1:
10420 case MPI26_MFGPAGE_DEVID_SAS3408:
10421 case MPI26_MFGPAGE_DEVID_SAS3516:
10422 case MPI26_MFGPAGE_DEVID_SAS3516_1:
10423 case MPI26_MFGPAGE_DEVID_SAS3416:
10424 case MPI26_MFGPAGE_DEVID_SAS3616:
10425 return MPI26_VERSION;
10431 * _scsih_probe - attach and add scsi host
10432 * @pdev: PCI device struct
10433 * @id: pci device id
10435 * Return: 0 success, anything else error.
10438 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
10440 struct MPT3SAS_ADAPTER *ioc;
10441 struct Scsi_Host *shost = NULL;
10443 u16 hba_mpi_version;
10445 /* Determine in which MPI version class this pci device belongs */
10446 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
10447 if (hba_mpi_version == 0)
10450 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10451 * for other generation HBA's return with -ENODEV
10453 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
10456 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10457 * for other generation HBA's return with -ENODEV
10459 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
10460 || hba_mpi_version == MPI26_VERSION)))
10463 switch (hba_mpi_version) {
10465 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
10466 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
10467 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10468 shost = scsi_host_alloc(&mpt2sas_driver_template,
10469 sizeof(struct MPT3SAS_ADAPTER));
10472 ioc = shost_priv(shost);
10473 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
10474 ioc->hba_mpi_version_belonged = hba_mpi_version;
10475 ioc->id = mpt2_ids++;
10476 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
10477 switch (pdev->device) {
10478 case MPI2_MFGPAGE_DEVID_SSS6200:
10479 ioc->is_warpdrive = 1;
10480 ioc->hide_ir_msg = 1;
10482 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
10483 ioc->is_mcpu_endpoint = 1;
10486 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
10490 case MPI25_VERSION:
10491 case MPI26_VERSION:
10492 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10493 shost = scsi_host_alloc(&mpt3sas_driver_template,
10494 sizeof(struct MPT3SAS_ADAPTER));
10497 ioc = shost_priv(shost);
10498 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
10499 ioc->hba_mpi_version_belonged = hba_mpi_version;
10500 ioc->id = mpt3_ids++;
10501 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
10502 switch (pdev->device) {
10503 case MPI26_MFGPAGE_DEVID_SAS3508:
10504 case MPI26_MFGPAGE_DEVID_SAS3508_1:
10505 case MPI26_MFGPAGE_DEVID_SAS3408:
10506 case MPI26_MFGPAGE_DEVID_SAS3516:
10507 case MPI26_MFGPAGE_DEVID_SAS3516_1:
10508 case MPI26_MFGPAGE_DEVID_SAS3416:
10509 case MPI26_MFGPAGE_DEVID_SAS3616:
10510 ioc->is_gen35_ioc = 1;
10513 ioc->is_gen35_ioc = 0;
10515 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
10516 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
10517 (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
10518 ioc->combined_reply_queue = 1;
10519 if (ioc->is_gen35_ioc)
10520 ioc->combined_reply_index_count =
10521 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
10523 ioc->combined_reply_index_count =
10524 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
10531 INIT_LIST_HEAD(&ioc->list);
10532 spin_lock(&gioc_lock);
10533 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
10534 spin_unlock(&gioc_lock);
10535 ioc->shost = shost;
10537 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
10538 ioc->tm_cb_idx = tm_cb_idx;
10539 ioc->ctl_cb_idx = ctl_cb_idx;
10540 ioc->base_cb_idx = base_cb_idx;
10541 ioc->port_enable_cb_idx = port_enable_cb_idx;
10542 ioc->transport_cb_idx = transport_cb_idx;
10543 ioc->scsih_cb_idx = scsih_cb_idx;
10544 ioc->config_cb_idx = config_cb_idx;
10545 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
10546 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
10547 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
10548 ioc->logging_level = logging_level;
10549 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
10550 /* misc semaphores and spin locks */
10551 mutex_init(&ioc->reset_in_progress_mutex);
10552 /* initializing pci_access_mutex lock */
10553 mutex_init(&ioc->pci_access_mutex);
10554 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
10555 spin_lock_init(&ioc->scsi_lookup_lock);
10556 spin_lock_init(&ioc->sas_device_lock);
10557 spin_lock_init(&ioc->sas_node_lock);
10558 spin_lock_init(&ioc->fw_event_lock);
10559 spin_lock_init(&ioc->raid_device_lock);
10560 spin_lock_init(&ioc->pcie_device_lock);
10561 spin_lock_init(&ioc->diag_trigger_lock);
10563 INIT_LIST_HEAD(&ioc->sas_device_list);
10564 INIT_LIST_HEAD(&ioc->sas_device_init_list);
10565 INIT_LIST_HEAD(&ioc->sas_expander_list);
10566 INIT_LIST_HEAD(&ioc->enclosure_list);
10567 INIT_LIST_HEAD(&ioc->pcie_device_list);
10568 INIT_LIST_HEAD(&ioc->pcie_device_init_list);
10569 INIT_LIST_HEAD(&ioc->fw_event_list);
10570 INIT_LIST_HEAD(&ioc->raid_device_list);
10571 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
10572 INIT_LIST_HEAD(&ioc->delayed_tr_list);
10573 INIT_LIST_HEAD(&ioc->delayed_sc_list);
10574 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
10575 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
10576 INIT_LIST_HEAD(&ioc->reply_queue_list);
10578 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
10580 /* init shost parameters */
10581 shost->max_cmd_len = 32;
10582 shost->max_lun = max_lun;
10583 shost->transportt = mpt3sas_transport_template;
10584 shost->unique_id = ioc->id;
10586 if (ioc->is_mcpu_endpoint) {
10587 /* mCPU MPI support 64K max IO */
10588 shost->max_sectors = 128;
10589 pr_info(MPT3SAS_FMT
10590 "The max_sectors value is set to %d\n",
10591 ioc->name, shost->max_sectors);
10593 if (max_sectors != 0xFFFF) {
10594 if (max_sectors < 64) {
10595 shost->max_sectors = 64;
10596 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
10597 "for max_sectors, range is 64 to 32767. " \
10598 "Assigning value of 64.\n", \
10599 ioc->name, max_sectors);
10600 } else if (max_sectors > 32767) {
10601 shost->max_sectors = 32767;
10602 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
10603 "for max_sectors, range is 64 to 32767." \
10604 "Assigning default value of 32767.\n", \
10605 ioc->name, max_sectors);
10607 shost->max_sectors = max_sectors & 0xFFFE;
10608 pr_info(MPT3SAS_FMT
10609 "The max_sectors value is set to %d\n",
10610 ioc->name, shost->max_sectors);
10614 /* register EEDP capabilities with SCSI layer */
10616 scsi_host_set_prot(shost, prot_mask);
10618 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
10619 | SHOST_DIF_TYPE2_PROTECTION
10620 | SHOST_DIF_TYPE3_PROTECTION);
10622 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
10625 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
10626 "fw_event_%s%d", ioc->driver_name, ioc->id);
10627 ioc->firmware_event_thread = alloc_ordered_workqueue(
10628 ioc->firmware_event_name, 0);
10629 if (!ioc->firmware_event_thread) {
10630 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10631 ioc->name, __FILE__, __LINE__, __func__);
10633 goto out_thread_fail;
10636 ioc->is_driver_loading = 1;
10637 if ((mpt3sas_base_attach(ioc))) {
10638 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10639 ioc->name, __FILE__, __LINE__, __func__);
10641 goto out_attach_fail;
10644 if (ioc->is_warpdrive) {
10645 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
10646 ioc->hide_drives = 0;
10647 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
10648 ioc->hide_drives = 1;
10650 if (mpt3sas_get_num_volumes(ioc))
10651 ioc->hide_drives = 1;
10653 ioc->hide_drives = 0;
10656 ioc->hide_drives = 0;
10658 rv = scsi_add_host(shost, &pdev->dev);
10660 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10661 ioc->name, __FILE__, __LINE__, __func__);
10662 goto out_add_shost_fail;
10665 scsi_scan_host(shost);
10667 out_add_shost_fail:
10668 mpt3sas_base_detach(ioc);
10670 destroy_workqueue(ioc->firmware_event_thread);
10672 spin_lock(&gioc_lock);
10673 list_del(&ioc->list);
10674 spin_unlock(&gioc_lock);
10675 scsi_host_put(shost);
10681 * scsih_suspend - power management suspend main entry point
10682 * @pdev: PCI device struct
10683 * @state: PM state change to (usually PCI_D3)
10685 * Return: 0 success, anything else error.
10688 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
10690 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10691 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10692 pci_power_t device_state;
10694 mpt3sas_base_stop_watchdog(ioc);
10695 flush_scheduled_work();
10696 scsi_block_requests(shost);
10697 device_state = pci_choose_state(pdev, state);
10698 pr_info(MPT3SAS_FMT
10699 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10700 ioc->name, pdev, pci_name(pdev), device_state);
10702 pci_save_state(pdev);
10703 mpt3sas_base_free_resources(ioc);
10704 pci_set_power_state(pdev, device_state);
10709 * scsih_resume - power management resume main entry point
10710 * @pdev: PCI device struct
10712 * Return: 0 success, anything else error.
10715 scsih_resume(struct pci_dev *pdev)
10717 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10718 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10719 pci_power_t device_state = pdev->current_state;
10722 pr_info(MPT3SAS_FMT
10723 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10724 ioc->name, pdev, pci_name(pdev), device_state);
10726 pci_set_power_state(pdev, PCI_D0);
10727 pci_enable_wake(pdev, PCI_D0, 0);
10728 pci_restore_state(pdev);
10730 r = mpt3sas_base_map_resources(ioc);
10734 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
10735 scsi_unblock_requests(shost);
10736 mpt3sas_base_start_watchdog(ioc);
10739 #endif /* CONFIG_PM */
10742 * scsih_pci_error_detected - Called when a PCI error is detected.
10743 * @pdev: PCI device struct
10744 * @state: PCI channel state
10746 * Description: Called when a PCI error is detected.
10748 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
10750 static pci_ers_result_t
10751 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10753 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10754 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10756 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
10760 case pci_channel_io_normal:
10761 return PCI_ERS_RESULT_CAN_RECOVER;
10762 case pci_channel_io_frozen:
10763 /* Fatal error, prepare for slot reset */
10764 ioc->pci_error_recovery = 1;
10765 scsi_block_requests(ioc->shost);
10766 mpt3sas_base_stop_watchdog(ioc);
10767 mpt3sas_base_free_resources(ioc);
10768 return PCI_ERS_RESULT_NEED_RESET;
10769 case pci_channel_io_perm_failure:
10770 /* Permanent error, prepare for device removal */
10771 ioc->pci_error_recovery = 1;
10772 mpt3sas_base_stop_watchdog(ioc);
10773 _scsih_flush_running_cmds(ioc);
10774 return PCI_ERS_RESULT_DISCONNECT;
10776 return PCI_ERS_RESULT_NEED_RESET;
10780 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10781 * @pdev: PCI device struct
10783 * Description: This routine is called by the pci error recovery
10784 * code after the PCI slot has been reset, just before we
10785 * should resume normal operations.
10787 static pci_ers_result_t
10788 scsih_pci_slot_reset(struct pci_dev *pdev)
10790 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10791 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10794 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
10797 ioc->pci_error_recovery = 0;
10799 pci_restore_state(pdev);
10800 rc = mpt3sas_base_map_resources(ioc);
10802 return PCI_ERS_RESULT_DISCONNECT;
10804 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
10806 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
10807 (rc == 0) ? "success" : "failed");
10810 return PCI_ERS_RESULT_RECOVERED;
10812 return PCI_ERS_RESULT_DISCONNECT;
10816 * scsih_pci_resume() - resume normal ops after PCI reset
10817 * @pdev: pointer to PCI device
10819 * Called when the error recovery driver tells us that its
10820 * OK to resume normal operation. Use completion to allow
10821 * halted scsi ops to resume.
10824 scsih_pci_resume(struct pci_dev *pdev)
10826 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10827 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10829 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
10831 pci_cleanup_aer_uncorrect_error_status(pdev);
10832 mpt3sas_base_start_watchdog(ioc);
10833 scsi_unblock_requests(ioc->shost);
10837 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10838 * @pdev: pointer to PCI device
10840 static pci_ers_result_t
10841 scsih_pci_mmio_enabled(struct pci_dev *pdev)
10843 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10844 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10846 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
10849 /* TODO - dump whatever for debugging purposes */
10851 /* This called only if scsih_pci_error_detected returns
10852 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10853 * works, no need to reset slot.
10855 return PCI_ERS_RESULT_RECOVERED;
10859 * scsih__ncq_prio_supp - Check for NCQ command priority support
10860 * @sdev: scsi device struct
10862 * This is called when a user indicates they would like to enable
10863 * ncq command priorities. This works only on SATA devices.
10865 bool scsih_ncq_prio_supp(struct scsi_device *sdev)
10867 unsigned char *buf;
10868 bool ncq_prio_supp = false;
10870 if (!scsi_device_supports_vpd(sdev))
10871 return ncq_prio_supp;
10873 buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL);
10875 return ncq_prio_supp;
10877 if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN))
10878 ncq_prio_supp = (buf[213] >> 4) & 1;
10881 return ncq_prio_supp;
10884 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10886 static const struct pci_device_id mpt3sas_pci_table[] = {
10887 /* Spitfire ~ 2004 */
10888 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
10889 PCI_ANY_ID, PCI_ANY_ID },
10890 /* Falcon ~ 2008 */
10891 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
10892 PCI_ANY_ID, PCI_ANY_ID },
10893 /* Liberator ~ 2108 */
10894 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
10895 PCI_ANY_ID, PCI_ANY_ID },
10896 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
10897 PCI_ANY_ID, PCI_ANY_ID },
10898 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
10899 PCI_ANY_ID, PCI_ANY_ID },
10900 /* Meteor ~ 2116 */
10901 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
10902 PCI_ANY_ID, PCI_ANY_ID },
10903 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
10904 PCI_ANY_ID, PCI_ANY_ID },
10905 /* Thunderbolt ~ 2208 */
10906 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
10907 PCI_ANY_ID, PCI_ANY_ID },
10908 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
10909 PCI_ANY_ID, PCI_ANY_ID },
10910 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
10911 PCI_ANY_ID, PCI_ANY_ID },
10912 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
10913 PCI_ANY_ID, PCI_ANY_ID },
10914 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
10915 PCI_ANY_ID, PCI_ANY_ID },
10916 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
10917 PCI_ANY_ID, PCI_ANY_ID },
10918 /* Mustang ~ 2308 */
10919 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
10920 PCI_ANY_ID, PCI_ANY_ID },
10921 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
10922 PCI_ANY_ID, PCI_ANY_ID },
10923 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
10924 PCI_ANY_ID, PCI_ANY_ID },
10925 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP,
10926 PCI_ANY_ID, PCI_ANY_ID },
10928 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
10929 PCI_ANY_ID, PCI_ANY_ID },
10930 /* Fury ~ 3004 and 3008 */
10931 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
10932 PCI_ANY_ID, PCI_ANY_ID },
10933 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
10934 PCI_ANY_ID, PCI_ANY_ID },
10935 /* Invader ~ 3108 */
10936 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
10937 PCI_ANY_ID, PCI_ANY_ID },
10938 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
10939 PCI_ANY_ID, PCI_ANY_ID },
10940 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
10941 PCI_ANY_ID, PCI_ANY_ID },
10942 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
10943 PCI_ANY_ID, PCI_ANY_ID },
10944 /* Cutlass ~ 3216 and 3224 */
10945 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
10946 PCI_ANY_ID, PCI_ANY_ID },
10947 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
10948 PCI_ANY_ID, PCI_ANY_ID },
10949 /* Intruder ~ 3316 and 3324 */
10950 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
10951 PCI_ANY_ID, PCI_ANY_ID },
10952 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
10953 PCI_ANY_ID, PCI_ANY_ID },
10954 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
10955 PCI_ANY_ID, PCI_ANY_ID },
10956 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
10957 PCI_ANY_ID, PCI_ANY_ID },
10958 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
10959 PCI_ANY_ID, PCI_ANY_ID },
10960 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
10961 PCI_ANY_ID, PCI_ANY_ID },
10962 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
10963 PCI_ANY_ID, PCI_ANY_ID },
10964 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
10965 PCI_ANY_ID, PCI_ANY_ID },
10966 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
10967 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
10968 PCI_ANY_ID, PCI_ANY_ID },
10969 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
10970 PCI_ANY_ID, PCI_ANY_ID },
10971 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
10972 PCI_ANY_ID, PCI_ANY_ID },
10973 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
10974 PCI_ANY_ID, PCI_ANY_ID },
10975 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
10976 PCI_ANY_ID, PCI_ANY_ID },
10977 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
10978 PCI_ANY_ID, PCI_ANY_ID },
10979 /* Mercator ~ 3616*/
10980 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616,
10981 PCI_ANY_ID, PCI_ANY_ID },
10982 {0} /* Terminating entry */
10984 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
10986 static struct pci_error_handlers _mpt3sas_err_handler = {
10987 .error_detected = scsih_pci_error_detected,
10988 .mmio_enabled = scsih_pci_mmio_enabled,
10989 .slot_reset = scsih_pci_slot_reset,
10990 .resume = scsih_pci_resume,
10993 static struct pci_driver mpt3sas_driver = {
10994 .name = MPT3SAS_DRIVER_NAME,
10995 .id_table = mpt3sas_pci_table,
10996 .probe = _scsih_probe,
10997 .remove = scsih_remove,
10998 .shutdown = scsih_shutdown,
10999 .err_handler = &_mpt3sas_err_handler,
11001 .suspend = scsih_suspend,
11002 .resume = scsih_resume,
11007 * scsih_init - main entry point for this driver.
11009 * Return: 0 success, anything else error.
11017 mpt3sas_base_initialize_callback_handler();
11019 /* queuecommand callback hander */
11020 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
11022 /* task management callback handler */
11023 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
11025 /* base internal commands callback handler */
11026 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
11027 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
11028 mpt3sas_port_enable_done);
11030 /* transport internal commands callback handler */
11031 transport_cb_idx = mpt3sas_base_register_callback_handler(
11032 mpt3sas_transport_done);
11034 /* scsih internal commands callback handler */
11035 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
11037 /* configuration page API internal commands callback handler */
11038 config_cb_idx = mpt3sas_base_register_callback_handler(
11039 mpt3sas_config_done);
11041 /* ctl module callback handler */
11042 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
11044 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
11045 _scsih_tm_tr_complete);
11047 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
11048 _scsih_tm_volume_tr_complete);
11050 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
11051 _scsih_sas_control_complete);
11057 * scsih_exit - exit point for this driver (when it is a module).
11059 * Return: 0 success, anything else error.
11065 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
11066 mpt3sas_base_release_callback_handler(tm_cb_idx);
11067 mpt3sas_base_release_callback_handler(base_cb_idx);
11068 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
11069 mpt3sas_base_release_callback_handler(transport_cb_idx);
11070 mpt3sas_base_release_callback_handler(scsih_cb_idx);
11071 mpt3sas_base_release_callback_handler(config_cb_idx);
11072 mpt3sas_base_release_callback_handler(ctl_cb_idx);
11074 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
11075 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
11076 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
11078 /* raid transport support */
11079 if (hbas_to_enumerate != 1)
11080 raid_class_release(mpt3sas_raid_template);
11081 if (hbas_to_enumerate != 2)
11082 raid_class_release(mpt2sas_raid_template);
11083 sas_release_transport(mpt3sas_transport_template);
11087 * _mpt3sas_init - main entry point for this driver.
11089 * Return: 0 success, anything else error.
11092 _mpt3sas_init(void)
11096 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
11097 MPT3SAS_DRIVER_VERSION);
11099 mpt3sas_transport_template =
11100 sas_attach_transport(&mpt3sas_transport_functions);
11101 if (!mpt3sas_transport_template)
11104 /* No need attach mpt3sas raid functions template
11105 * if hbas_to_enumarate value is one.
11107 if (hbas_to_enumerate != 1) {
11108 mpt3sas_raid_template =
11109 raid_class_attach(&mpt3sas_raid_functions);
11110 if (!mpt3sas_raid_template) {
11111 sas_release_transport(mpt3sas_transport_template);
11116 /* No need to attach mpt2sas raid functions template
11117 * if hbas_to_enumarate value is two
11119 if (hbas_to_enumerate != 2) {
11120 mpt2sas_raid_template =
11121 raid_class_attach(&mpt2sas_raid_functions);
11122 if (!mpt2sas_raid_template) {
11123 sas_release_transport(mpt3sas_transport_template);
11128 error = scsih_init();
11134 mpt3sas_ctl_init(hbas_to_enumerate);
11136 error = pci_register_driver(&mpt3sas_driver);
11144 * _mpt3sas_exit - exit point for this driver (when it is a module).
11148 _mpt3sas_exit(void)
11150 pr_info("mpt3sas version %s unloading\n",
11151 MPT3SAS_DRIVER_VERSION);
11153 mpt3sas_ctl_exit(hbas_to_enumerate);
11155 pci_unregister_driver(&mpt3sas_driver);
11160 module_init(_mpt3sas_init);
11161 module_exit(_mpt3sas_exit);