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;
1477 Mpi25SCSIIORequest_t *mpi_request;
1480 smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
1481 u32 unique_tag = smid - 1;
1483 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1486 * If SCSI IO request is outstanding at driver level then
1487 * DevHandle filed must be non-zero. If DevHandle is zero
1488 * then it means that this smid is free at driver level,
1491 if (!mpi_request->DevHandle)
1494 scmd = scsi_host_find_tag(ioc->shost, unique_tag);
1496 st = scsi_cmd_priv(scmd);
1497 if (st->cb_idx == 0xFF || st->smid == 0)
1505 * scsih_change_queue_depth - setting device queue depth
1506 * @sdev: scsi device struct
1507 * @qdepth: requested queue depth
1509 * Return: queue depth.
1512 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1514 struct Scsi_Host *shost = sdev->host;
1516 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1517 struct MPT3SAS_DEVICE *sas_device_priv_data;
1518 struct MPT3SAS_TARGET *sas_target_priv_data;
1519 struct _sas_device *sas_device;
1520 unsigned long flags;
1522 max_depth = shost->can_queue;
1524 /* limit max device queue for SATA to 32 */
1525 sas_device_priv_data = sdev->hostdata;
1526 if (!sas_device_priv_data)
1528 sas_target_priv_data = sas_device_priv_data->sas_target;
1529 if (!sas_target_priv_data)
1531 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1534 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1535 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1537 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1538 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1540 sas_device_put(sas_device);
1542 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1546 if (!sdev->tagged_supported)
1548 if (qdepth > max_depth)
1550 return scsi_change_queue_depth(sdev, qdepth);
1554 * scsih_target_alloc - target add routine
1555 * @starget: scsi target struct
1557 * Return: 0 if ok. Any other return is assumed to be an error and
1558 * the device is ignored.
1561 scsih_target_alloc(struct scsi_target *starget)
1563 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1564 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1565 struct MPT3SAS_TARGET *sas_target_priv_data;
1566 struct _sas_device *sas_device;
1567 struct _raid_device *raid_device;
1568 struct _pcie_device *pcie_device;
1569 unsigned long flags;
1570 struct sas_rphy *rphy;
1572 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1574 if (!sas_target_priv_data)
1577 starget->hostdata = sas_target_priv_data;
1578 sas_target_priv_data->starget = starget;
1579 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1582 if (starget->channel == RAID_CHANNEL) {
1583 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1584 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1587 sas_target_priv_data->handle = raid_device->handle;
1588 sas_target_priv_data->sas_address = raid_device->wwid;
1589 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1590 if (ioc->is_warpdrive)
1591 sas_target_priv_data->raid_device = raid_device;
1592 raid_device->starget = starget;
1594 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1599 if (starget->channel == PCIE_CHANNEL) {
1600 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1601 pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id,
1604 sas_target_priv_data->handle = pcie_device->handle;
1605 sas_target_priv_data->sas_address = pcie_device->wwid;
1606 sas_target_priv_data->pcie_dev = pcie_device;
1607 pcie_device->starget = starget;
1608 pcie_device->id = starget->id;
1609 pcie_device->channel = starget->channel;
1610 sas_target_priv_data->flags |=
1611 MPT_TARGET_FLAGS_PCIE_DEVICE;
1612 if (pcie_device->fast_path)
1613 sas_target_priv_data->flags |=
1614 MPT_TARGET_FASTPATH_IO;
1616 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1620 /* sas/sata devices */
1621 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1622 rphy = dev_to_rphy(starget->dev.parent);
1623 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1624 rphy->identify.sas_address);
1627 sas_target_priv_data->handle = sas_device->handle;
1628 sas_target_priv_data->sas_address = sas_device->sas_address;
1629 sas_target_priv_data->sas_dev = sas_device;
1630 sas_device->starget = starget;
1631 sas_device->id = starget->id;
1632 sas_device->channel = starget->channel;
1633 if (test_bit(sas_device->handle, ioc->pd_handles))
1634 sas_target_priv_data->flags |=
1635 MPT_TARGET_FLAGS_RAID_COMPONENT;
1636 if (sas_device->fast_path)
1637 sas_target_priv_data->flags |=
1638 MPT_TARGET_FASTPATH_IO;
1640 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1646 * scsih_target_destroy - target destroy routine
1647 * @starget: scsi target struct
1650 scsih_target_destroy(struct scsi_target *starget)
1652 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1653 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1654 struct MPT3SAS_TARGET *sas_target_priv_data;
1655 struct _sas_device *sas_device;
1656 struct _raid_device *raid_device;
1657 struct _pcie_device *pcie_device;
1658 unsigned long flags;
1660 sas_target_priv_data = starget->hostdata;
1661 if (!sas_target_priv_data)
1664 if (starget->channel == RAID_CHANNEL) {
1665 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1666 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1669 raid_device->starget = NULL;
1670 raid_device->sdev = NULL;
1672 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1676 if (starget->channel == PCIE_CHANNEL) {
1677 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1678 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1679 sas_target_priv_data);
1680 if (pcie_device && (pcie_device->starget == starget) &&
1681 (pcie_device->id == starget->id) &&
1682 (pcie_device->channel == starget->channel))
1683 pcie_device->starget = NULL;
1687 * Corresponding get() is in _scsih_target_alloc()
1689 sas_target_priv_data->pcie_dev = NULL;
1690 pcie_device_put(pcie_device);
1691 pcie_device_put(pcie_device);
1693 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1697 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1698 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1699 if (sas_device && (sas_device->starget == starget) &&
1700 (sas_device->id == starget->id) &&
1701 (sas_device->channel == starget->channel))
1702 sas_device->starget = NULL;
1706 * Corresponding get() is in _scsih_target_alloc()
1708 sas_target_priv_data->sas_dev = NULL;
1709 sas_device_put(sas_device);
1711 sas_device_put(sas_device);
1713 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1716 kfree(sas_target_priv_data);
1717 starget->hostdata = NULL;
1721 * scsih_slave_alloc - device add routine
1722 * @sdev: scsi device struct
1724 * Return: 0 if ok. Any other return is assumed to be an error and
1725 * the device is ignored.
1728 scsih_slave_alloc(struct scsi_device *sdev)
1730 struct Scsi_Host *shost;
1731 struct MPT3SAS_ADAPTER *ioc;
1732 struct MPT3SAS_TARGET *sas_target_priv_data;
1733 struct MPT3SAS_DEVICE *sas_device_priv_data;
1734 struct scsi_target *starget;
1735 struct _raid_device *raid_device;
1736 struct _sas_device *sas_device;
1737 struct _pcie_device *pcie_device;
1738 unsigned long flags;
1740 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1742 if (!sas_device_priv_data)
1745 sas_device_priv_data->lun = sdev->lun;
1746 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1748 starget = scsi_target(sdev);
1749 sas_target_priv_data = starget->hostdata;
1750 sas_target_priv_data->num_luns++;
1751 sas_device_priv_data->sas_target = sas_target_priv_data;
1752 sdev->hostdata = sas_device_priv_data;
1753 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1754 sdev->no_uld_attach = 1;
1756 shost = dev_to_shost(&starget->dev);
1757 ioc = shost_priv(shost);
1758 if (starget->channel == RAID_CHANNEL) {
1759 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1760 raid_device = _scsih_raid_device_find_by_id(ioc,
1761 starget->id, starget->channel);
1763 raid_device->sdev = sdev; /* raid is single lun */
1764 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1766 if (starget->channel == PCIE_CHANNEL) {
1767 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1768 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
1769 sas_target_priv_data->sas_address);
1770 if (pcie_device && (pcie_device->starget == NULL)) {
1771 sdev_printk(KERN_INFO, sdev,
1772 "%s : pcie_device->starget set to starget @ %d\n",
1773 __func__, __LINE__);
1774 pcie_device->starget = starget;
1778 pcie_device_put(pcie_device);
1779 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1781 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1782 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1783 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1784 sas_target_priv_data->sas_address);
1785 if (sas_device && (sas_device->starget == NULL)) {
1786 sdev_printk(KERN_INFO, sdev,
1787 "%s : sas_device->starget set to starget @ %d\n",
1788 __func__, __LINE__);
1789 sas_device->starget = starget;
1793 sas_device_put(sas_device);
1795 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1802 * scsih_slave_destroy - device destroy routine
1803 * @sdev: scsi device struct
1806 scsih_slave_destroy(struct scsi_device *sdev)
1808 struct MPT3SAS_TARGET *sas_target_priv_data;
1809 struct scsi_target *starget;
1810 struct Scsi_Host *shost;
1811 struct MPT3SAS_ADAPTER *ioc;
1812 struct _sas_device *sas_device;
1813 struct _pcie_device *pcie_device;
1814 unsigned long flags;
1816 if (!sdev->hostdata)
1819 starget = scsi_target(sdev);
1820 sas_target_priv_data = starget->hostdata;
1821 sas_target_priv_data->num_luns--;
1823 shost = dev_to_shost(&starget->dev);
1824 ioc = shost_priv(shost);
1826 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
1827 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1828 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1829 sas_target_priv_data);
1830 if (pcie_device && !sas_target_priv_data->num_luns)
1831 pcie_device->starget = NULL;
1834 pcie_device_put(pcie_device);
1836 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1838 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1839 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1840 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1841 sas_target_priv_data);
1842 if (sas_device && !sas_target_priv_data->num_luns)
1843 sas_device->starget = NULL;
1846 sas_device_put(sas_device);
1847 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1850 kfree(sdev->hostdata);
1851 sdev->hostdata = NULL;
1855 * _scsih_display_sata_capabilities - sata capabilities
1856 * @ioc: per adapter object
1857 * @handle: device handle
1858 * @sdev: scsi device struct
1861 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1862 u16 handle, struct scsi_device *sdev)
1864 Mpi2ConfigReply_t mpi_reply;
1865 Mpi2SasDevicePage0_t sas_device_pg0;
1870 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1871 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1872 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1873 ioc->name, __FILE__, __LINE__, __func__);
1877 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1878 MPI2_IOCSTATUS_MASK;
1879 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1880 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1881 ioc->name, __FILE__, __LINE__, __func__);
1885 flags = le16_to_cpu(sas_device_pg0.Flags);
1886 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1888 sdev_printk(KERN_INFO, sdev,
1889 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1890 "sw_preserve(%s)\n",
1891 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1892 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1893 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1895 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1896 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1897 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1901 * raid transport support -
1902 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1903 * unloading the driver followed by a load - I believe that the subroutine
1904 * raid_class_release() is not cleaning up properly.
1908 * scsih_is_raid - return boolean indicating device is raid volume
1909 * @dev: the device struct object
1912 scsih_is_raid(struct device *dev)
1914 struct scsi_device *sdev = to_scsi_device(dev);
1915 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1917 if (ioc->is_warpdrive)
1919 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1923 scsih_is_nvme(struct device *dev)
1925 struct scsi_device *sdev = to_scsi_device(dev);
1927 return (sdev->channel == PCIE_CHANNEL) ? 1 : 0;
1931 * scsih_get_resync - get raid volume resync percent complete
1932 * @dev: the device struct object
1935 scsih_get_resync(struct device *dev)
1937 struct scsi_device *sdev = to_scsi_device(dev);
1938 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1939 static struct _raid_device *raid_device;
1940 unsigned long flags;
1941 Mpi2RaidVolPage0_t vol_pg0;
1942 Mpi2ConfigReply_t mpi_reply;
1943 u32 volume_status_flags;
1944 u8 percent_complete;
1947 percent_complete = 0;
1949 if (ioc->is_warpdrive)
1952 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1953 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1956 handle = raid_device->handle;
1957 percent_complete = raid_device->percent_complete;
1959 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1964 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1965 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1966 sizeof(Mpi2RaidVolPage0_t))) {
1967 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1968 ioc->name, __FILE__, __LINE__, __func__);
1969 percent_complete = 0;
1973 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1974 if (!(volume_status_flags &
1975 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1976 percent_complete = 0;
1980 switch (ioc->hba_mpi_version_belonged) {
1982 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1986 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1992 * scsih_get_state - get raid volume level
1993 * @dev: the device struct object
1996 scsih_get_state(struct device *dev)
1998 struct scsi_device *sdev = to_scsi_device(dev);
1999 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
2000 static struct _raid_device *raid_device;
2001 unsigned long flags;
2002 Mpi2RaidVolPage0_t vol_pg0;
2003 Mpi2ConfigReply_t mpi_reply;
2005 enum raid_state state = RAID_STATE_UNKNOWN;
2008 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2009 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
2012 handle = raid_device->handle;
2013 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2018 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
2019 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
2020 sizeof(Mpi2RaidVolPage0_t))) {
2021 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
2022 ioc->name, __FILE__, __LINE__, __func__);
2026 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
2027 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
2028 state = RAID_STATE_RESYNCING;
2032 switch (vol_pg0.VolumeState) {
2033 case MPI2_RAID_VOL_STATE_OPTIMAL:
2034 case MPI2_RAID_VOL_STATE_ONLINE:
2035 state = RAID_STATE_ACTIVE;
2037 case MPI2_RAID_VOL_STATE_DEGRADED:
2038 state = RAID_STATE_DEGRADED;
2040 case MPI2_RAID_VOL_STATE_FAILED:
2041 case MPI2_RAID_VOL_STATE_MISSING:
2042 state = RAID_STATE_OFFLINE;
2046 switch (ioc->hba_mpi_version_belonged) {
2048 raid_set_state(mpt2sas_raid_template, dev, state);
2052 raid_set_state(mpt3sas_raid_template, dev, state);
2058 * _scsih_set_level - set raid level
2060 * @sdev: scsi device struct
2061 * @volume_type: volume type
2064 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
2065 struct scsi_device *sdev, u8 volume_type)
2067 enum raid_level level = RAID_LEVEL_UNKNOWN;
2069 switch (volume_type) {
2070 case MPI2_RAID_VOL_TYPE_RAID0:
2071 level = RAID_LEVEL_0;
2073 case MPI2_RAID_VOL_TYPE_RAID10:
2074 level = RAID_LEVEL_10;
2076 case MPI2_RAID_VOL_TYPE_RAID1E:
2077 level = RAID_LEVEL_1E;
2079 case MPI2_RAID_VOL_TYPE_RAID1:
2080 level = RAID_LEVEL_1;
2084 switch (ioc->hba_mpi_version_belonged) {
2086 raid_set_level(mpt2sas_raid_template,
2087 &sdev->sdev_gendev, level);
2091 raid_set_level(mpt3sas_raid_template,
2092 &sdev->sdev_gendev, level);
2099 * _scsih_get_volume_capabilities - volume capabilities
2100 * @ioc: per adapter object
2101 * @raid_device: the raid_device object
2103 * Return: 0 for success, else 1
2106 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
2107 struct _raid_device *raid_device)
2109 Mpi2RaidVolPage0_t *vol_pg0;
2110 Mpi2RaidPhysDiskPage0_t pd_pg0;
2111 Mpi2SasDevicePage0_t sas_device_pg0;
2112 Mpi2ConfigReply_t mpi_reply;
2116 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
2117 &num_pds)) || !num_pds) {
2118 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2119 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2124 raid_device->num_pds = num_pds;
2125 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
2126 sizeof(Mpi2RaidVol0PhysDisk_t));
2127 vol_pg0 = kzalloc(sz, GFP_KERNEL);
2129 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2130 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2135 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
2136 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
2137 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2138 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2144 raid_device->volume_type = vol_pg0->VolumeType;
2146 /* figure out what the underlying devices are by
2147 * obtaining the device_info bits for the 1st device
2149 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
2150 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
2151 vol_pg0->PhysDisk[0].PhysDiskNum))) {
2152 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
2153 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
2154 le16_to_cpu(pd_pg0.DevHandle)))) {
2155 raid_device->device_info =
2156 le32_to_cpu(sas_device_pg0.DeviceInfo);
2165 * _scsih_enable_tlr - setting TLR flags
2166 * @ioc: per adapter object
2167 * @sdev: scsi device struct
2169 * Enabling Transaction Layer Retries for tape devices when
2170 * vpd page 0x90 is present
2174 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
2178 if (sdev->type != TYPE_TAPE)
2181 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2184 sas_enable_tlr(sdev);
2185 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2186 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2192 * scsih_slave_configure - device configure routine.
2193 * @sdev: scsi device struct
2195 * Return: 0 if ok. Any other return is assumed to be an error and
2196 * the device is ignored.
2199 scsih_slave_configure(struct scsi_device *sdev)
2201 struct Scsi_Host *shost = sdev->host;
2202 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2203 struct MPT3SAS_DEVICE *sas_device_priv_data;
2204 struct MPT3SAS_TARGET *sas_target_priv_data;
2205 struct _sas_device *sas_device;
2206 struct _pcie_device *pcie_device;
2207 struct _raid_device *raid_device;
2208 unsigned long flags;
2213 u16 handle, volume_handle = 0;
2214 u64 volume_wwid = 0;
2217 sas_device_priv_data = sdev->hostdata;
2218 sas_device_priv_data->configured_lun = 1;
2219 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2220 sas_target_priv_data = sas_device_priv_data->sas_target;
2221 handle = sas_target_priv_data->handle;
2223 /* raid volume handling */
2224 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2226 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2227 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
2228 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2230 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2231 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2232 __LINE__, __func__));
2236 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2237 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2238 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2239 __LINE__, __func__));
2244 * WARPDRIVE: Initialize the required data for Direct IO
2246 mpt3sas_init_warpdrive_properties(ioc, raid_device);
2248 /* RAID Queue Depth Support
2249 * IS volume = underlying qdepth of drive type, either
2250 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2251 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2253 if (raid_device->device_info &
2254 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2255 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2258 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2259 if (raid_device->device_info &
2260 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2266 switch (raid_device->volume_type) {
2267 case MPI2_RAID_VOL_TYPE_RAID0:
2270 case MPI2_RAID_VOL_TYPE_RAID1E:
2271 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2272 if (ioc->manu_pg10.OEMIdentifier &&
2273 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2274 MFG10_GF0_R10_DISPLAY) &&
2275 !(raid_device->num_pds % 2))
2280 case MPI2_RAID_VOL_TYPE_RAID1:
2281 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2284 case MPI2_RAID_VOL_TYPE_RAID10:
2285 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2288 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2290 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2295 if (!ioc->hide_ir_msg)
2296 sdev_printk(KERN_INFO, sdev,
2297 "%s: handle(0x%04x), wwid(0x%016llx),"
2298 " pd_count(%d), type(%s)\n",
2299 r_level, raid_device->handle,
2300 (unsigned long long)raid_device->wwid,
2301 raid_device->num_pds, ds);
2303 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
2304 blk_queue_max_hw_sectors(sdev->request_queue,
2305 MPT3SAS_RAID_MAX_SECTORS);
2306 sdev_printk(KERN_INFO, sdev,
2307 "Set queue's max_sector to: %u\n",
2308 MPT3SAS_RAID_MAX_SECTORS);
2311 scsih_change_queue_depth(sdev, qdepth);
2313 /* raid transport support */
2314 if (!ioc->is_warpdrive)
2315 _scsih_set_level(ioc, sdev, raid_device->volume_type);
2319 /* non-raid handling */
2320 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2321 if (mpt3sas_config_get_volume_handle(ioc, handle,
2323 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2324 "failure at %s:%d/%s()!\n", ioc->name,
2325 __FILE__, __LINE__, __func__));
2328 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
2329 volume_handle, &volume_wwid)) {
2330 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2331 "failure at %s:%d/%s()!\n", ioc->name,
2332 __FILE__, __LINE__, __func__));
2338 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2339 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2340 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
2341 sas_device_priv_data->sas_target->sas_address);
2343 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2344 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2345 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2346 __LINE__, __func__));
2350 qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
2352 sdev_printk(KERN_INFO, sdev,
2353 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2354 ds, handle, (unsigned long long)pcie_device->wwid,
2355 pcie_device->port_num);
2356 if (pcie_device->enclosure_handle != 0)
2357 sdev_printk(KERN_INFO, sdev,
2358 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2360 (unsigned long long)pcie_device->enclosure_logical_id,
2362 if (pcie_device->connector_name[0] != '\0')
2363 sdev_printk(KERN_INFO, sdev,
2364 "%s: enclosure level(0x%04x),"
2365 "connector name( %s)\n", ds,
2366 pcie_device->enclosure_level,
2367 pcie_device->connector_name);
2369 if (pcie_device->nvme_mdts)
2370 blk_queue_max_hw_sectors(sdev->request_queue,
2371 pcie_device->nvme_mdts/512);
2373 pcie_device_put(pcie_device);
2374 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2375 scsih_change_queue_depth(sdev, qdepth);
2376 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2377 ** merged and can eliminate holes created during merging
2380 blk_queue_flag_set(QUEUE_FLAG_NOMERGES,
2381 sdev->request_queue);
2382 blk_queue_virt_boundary(sdev->request_queue,
2383 ioc->page_size - 1);
2387 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2388 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
2389 sas_device_priv_data->sas_target->sas_address);
2391 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2392 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
2393 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2398 sas_device->volume_handle = volume_handle;
2399 sas_device->volume_wwid = volume_wwid;
2400 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2401 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2403 if (sas_device->device_info &
2404 MPI2_SAS_DEVICE_INFO_SEP) {
2405 sdev_printk(KERN_WARNING, sdev,
2406 "set ignore_delay_remove for handle(0x%04x)\n",
2407 sas_device_priv_data->sas_target->handle);
2408 sas_device_priv_data->ignore_delay_remove = 1;
2413 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2414 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2416 else if (sas_device->device_info &
2417 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2421 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
2422 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2423 ds, handle, (unsigned long long)sas_device->sas_address,
2424 sas_device->phy, (unsigned long long)sas_device->device_name);
2426 _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL);
2428 sas_device_put(sas_device);
2429 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2432 _scsih_display_sata_capabilities(ioc, handle, sdev);
2435 scsih_change_queue_depth(sdev, qdepth);
2438 sas_read_port_mode_page(sdev);
2439 _scsih_enable_tlr(ioc, sdev);
2446 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2447 * @sdev: scsi device struct
2448 * @bdev: pointer to block device context
2449 * @capacity: device size (in 512 byte sectors)
2450 * @params: three element array to place output:
2451 * params[0] number of heads (max 255)
2452 * params[1] number of sectors (max 63)
2453 * params[2] number of cylinders
2456 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2457 sector_t capacity, int params[])
2467 dummy = heads * sectors;
2468 cylinders = capacity;
2469 sector_div(cylinders, dummy);
2472 * Handle extended translation size for logical drives
2475 if ((ulong)capacity >= 0x200000) {
2478 dummy = heads * sectors;
2479 cylinders = capacity;
2480 sector_div(cylinders, dummy);
2485 params[1] = sectors;
2486 params[2] = cylinders;
2492 * _scsih_response_code - translation of device response code
2493 * @ioc: per adapter object
2494 * @response_code: response code returned by the device
2497 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2501 switch (response_code) {
2502 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2503 desc = "task management request completed";
2505 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2506 desc = "invalid frame";
2508 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2509 desc = "task management request not supported";
2511 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2512 desc = "task management request failed";
2514 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2515 desc = "task management request succeeded";
2517 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2518 desc = "invalid lun";
2521 desc = "overlapped tag attempted";
2523 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2524 desc = "task queued, however not sent to target";
2530 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2531 ioc->name, response_code, desc);
2535 * _scsih_tm_done - tm completion routine
2536 * @ioc: per adapter object
2537 * @smid: system request message index
2538 * @msix_index: MSIX table index supplied by the OS
2539 * @reply: reply message frame(lower 32bit addr)
2542 * The callback handler when using scsih_issue_tm.
2544 * Return: 1 meaning mf should be freed from _base_interrupt
2545 * 0 means the mf is freed from this function.
2548 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2550 MPI2DefaultReply_t *mpi_reply;
2552 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2554 if (ioc->tm_cmds.smid != smid)
2556 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2557 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2559 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2560 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2562 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2563 complete(&ioc->tm_cmds.done);
2568 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2569 * @ioc: per adapter object
2570 * @handle: device handle
2572 * During taskmangement request, we need to freeze the device queue.
2575 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2577 struct MPT3SAS_DEVICE *sas_device_priv_data;
2578 struct scsi_device *sdev;
2581 shost_for_each_device(sdev, ioc->shost) {
2584 sas_device_priv_data = sdev->hostdata;
2585 if (!sas_device_priv_data)
2587 if (sas_device_priv_data->sas_target->handle == handle) {
2588 sas_device_priv_data->sas_target->tm_busy = 1;
2590 ioc->ignore_loginfos = 1;
2596 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2597 * @ioc: per adapter object
2598 * @handle: device handle
2600 * During taskmangement request, we need to freeze the device queue.
2603 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2605 struct MPT3SAS_DEVICE *sas_device_priv_data;
2606 struct scsi_device *sdev;
2609 shost_for_each_device(sdev, ioc->shost) {
2612 sas_device_priv_data = sdev->hostdata;
2613 if (!sas_device_priv_data)
2615 if (sas_device_priv_data->sas_target->handle == handle) {
2616 sas_device_priv_data->sas_target->tm_busy = 0;
2618 ioc->ignore_loginfos = 0;
2624 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2625 * @ioc: per adapter struct
2626 * @handle: device handle
2628 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2629 * @smid_task: smid assigned to the task
2630 * @msix_task: MSIX table index supplied by the OS
2631 * @timeout: timeout in seconds
2632 * @tr_method: Target Reset Method
2635 * A generic API for sending task management requests to firmware.
2637 * The callback index is set inside `ioc->tm_cb_idx`.
2638 * The caller is responsible to check for outstanding commands.
2640 * Return: SUCCESS or FAILED.
2643 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun,
2644 u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method)
2646 Mpi2SCSITaskManagementRequest_t *mpi_request;
2647 Mpi2SCSITaskManagementReply_t *mpi_reply;
2652 lockdep_assert_held(&ioc->tm_cmds.mutex);
2654 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2655 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2656 __func__, ioc->name);
2660 if (ioc->shost_recovery || ioc->remove_host ||
2661 ioc->pci_error_recovery) {
2662 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2663 __func__, ioc->name);
2667 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2668 if (ioc_state & MPI2_DOORBELL_USED) {
2669 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2670 "unexpected doorbell active!\n", ioc->name));
2671 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2672 return (!rc) ? SUCCESS : FAILED;
2675 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2676 mpt3sas_base_fault_info(ioc, ioc_state &
2677 MPI2_DOORBELL_DATA_MASK);
2678 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2679 return (!rc) ? SUCCESS : FAILED;
2682 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2684 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2685 ioc->name, __func__);
2689 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2690 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
2691 ioc->name, handle, type, smid_task, timeout, tr_method));
2692 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2693 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2694 ioc->tm_cmds.smid = smid;
2695 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2696 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2697 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2698 mpi_request->DevHandle = cpu_to_le16(handle);
2699 mpi_request->TaskType = type;
2700 mpi_request->MsgFlags = tr_method;
2701 mpi_request->TaskMID = cpu_to_le16(smid_task);
2702 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2703 mpt3sas_scsih_set_tm_flag(ioc, handle);
2704 init_completion(&ioc->tm_cmds.done);
2705 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2706 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2707 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2708 if (mpt3sas_base_check_cmd_timeout(ioc,
2709 ioc->tm_cmds.status, mpi_request,
2710 sizeof(Mpi2SCSITaskManagementRequest_t)/4)) {
2711 rc = mpt3sas_base_hard_reset_handler(ioc,
2713 rc = (!rc) ? SUCCESS : FAILED;
2718 /* sync IRQs in case those were busy during flush. */
2719 mpt3sas_base_sync_reply_irqs(ioc);
2721 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2722 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2723 mpi_reply = ioc->tm_cmds.reply;
2724 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2725 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2726 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2727 le32_to_cpu(mpi_reply->IOCLogInfo),
2728 le32_to_cpu(mpi_reply->TerminationCount)));
2729 if (ioc->logging_level & MPT_DEBUG_TM) {
2730 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2731 if (mpi_reply->IOCStatus)
2732 _debug_dump_mf(mpi_request,
2733 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2739 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2740 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2744 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2745 u64 lun, u8 type, u16 smid_task, u16 msix_task,
2746 u8 timeout, u8 tr_method)
2750 mutex_lock(&ioc->tm_cmds.mutex);
2751 ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task,
2752 msix_task, timeout, tr_method);
2753 mutex_unlock(&ioc->tm_cmds.mutex);
2759 * _scsih_tm_display_info - displays info about the device
2760 * @ioc: per adapter struct
2761 * @scmd: pointer to scsi command object
2763 * Called by task management callback handlers.
2766 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2768 struct scsi_target *starget = scmd->device->sdev_target;
2769 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2770 struct _sas_device *sas_device = NULL;
2771 struct _pcie_device *pcie_device = NULL;
2772 unsigned long flags;
2773 char *device_str = NULL;
2777 if (ioc->hide_ir_msg)
2778 device_str = "WarpDrive";
2780 device_str = "volume";
2782 scsi_print_command(scmd);
2783 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2784 starget_printk(KERN_INFO, starget,
2785 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2786 device_str, priv_target->handle,
2787 device_str, (unsigned long long)priv_target->sas_address);
2789 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2790 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2791 pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target);
2793 starget_printk(KERN_INFO, starget,
2794 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2795 pcie_device->handle,
2796 (unsigned long long)pcie_device->wwid,
2797 pcie_device->port_num);
2798 if (pcie_device->enclosure_handle != 0)
2799 starget_printk(KERN_INFO, starget,
2800 "enclosure logical id(0x%016llx), slot(%d)\n",
2801 (unsigned long long)
2802 pcie_device->enclosure_logical_id,
2804 if (pcie_device->connector_name[0] != '\0')
2805 starget_printk(KERN_INFO, starget,
2806 "enclosure level(0x%04x), connector name( %s)\n",
2807 pcie_device->enclosure_level,
2808 pcie_device->connector_name);
2809 pcie_device_put(pcie_device);
2811 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2814 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2815 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2817 if (priv_target->flags &
2818 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2819 starget_printk(KERN_INFO, starget,
2820 "volume handle(0x%04x), "
2821 "volume wwid(0x%016llx)\n",
2822 sas_device->volume_handle,
2823 (unsigned long long)sas_device->volume_wwid);
2825 starget_printk(KERN_INFO, starget,
2826 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2828 (unsigned long long)sas_device->sas_address,
2831 _scsih_display_enclosure_chassis_info(NULL, sas_device,
2834 sas_device_put(sas_device);
2836 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2841 * scsih_abort - eh threads main abort routine
2842 * @scmd: pointer to scsi command object
2844 * Return: SUCCESS if command aborted else FAILED
2847 scsih_abort(struct scsi_cmnd *scmd)
2849 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2850 struct MPT3SAS_DEVICE *sas_device_priv_data;
2851 struct scsiio_tracker *st = scsi_cmd_priv(scmd);
2856 struct _pcie_device *pcie_device = NULL;
2857 sdev_printk(KERN_INFO, scmd->device,
2858 "attempting task abort! scmd(%p)\n", scmd);
2859 _scsih_tm_display_info(ioc, scmd);
2861 sas_device_priv_data = scmd->device->hostdata;
2862 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2864 sdev_printk(KERN_INFO, scmd->device,
2865 "device been deleted! scmd(%p)\n", scmd);
2866 scmd->result = DID_NO_CONNECT << 16;
2867 scmd->scsi_done(scmd);
2872 /* check for completed command */
2873 if (st == NULL || st->cb_idx == 0xFF) {
2874 scmd->result = DID_RESET << 16;
2879 /* for hidden raid components and volumes this is not supported */
2880 if (sas_device_priv_data->sas_target->flags &
2881 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2882 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2883 scmd->result = DID_RESET << 16;
2888 mpt3sas_halt_firmware(ioc);
2890 handle = sas_device_priv_data->sas_target->handle;
2891 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
2892 if (pcie_device && (!ioc->tm_custom_handling))
2893 timeout = ioc->nvme_abort_timeout;
2894 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
2895 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
2896 st->smid, st->msix_io, timeout, 0);
2897 /* Command must be cleared after abort */
2898 if (r == SUCCESS && st->cb_idx != 0xFF)
2901 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2902 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2904 pcie_device_put(pcie_device);
2909 * scsih_dev_reset - eh threads main device reset routine
2910 * @scmd: pointer to scsi command object
2912 * Return: SUCCESS if command aborted else FAILED
2915 scsih_dev_reset(struct scsi_cmnd *scmd)
2917 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2918 struct MPT3SAS_DEVICE *sas_device_priv_data;
2919 struct _sas_device *sas_device = NULL;
2920 struct _pcie_device *pcie_device = NULL;
2926 struct scsi_target *starget = scmd->device->sdev_target;
2927 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2929 sdev_printk(KERN_INFO, scmd->device,
2930 "attempting device reset! scmd(%p)\n", scmd);
2931 _scsih_tm_display_info(ioc, scmd);
2933 sas_device_priv_data = scmd->device->hostdata;
2934 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2936 sdev_printk(KERN_INFO, scmd->device,
2937 "device been deleted! scmd(%p)\n", scmd);
2938 scmd->result = DID_NO_CONNECT << 16;
2939 scmd->scsi_done(scmd);
2944 /* for hidden raid components obtain the volume_handle */
2946 if (sas_device_priv_data->sas_target->flags &
2947 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2948 sas_device = mpt3sas_get_sdev_from_target(ioc,
2951 handle = sas_device->volume_handle;
2953 handle = sas_device_priv_data->sas_target->handle;
2956 scmd->result = DID_RESET << 16;
2961 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
2963 if (pcie_device && (!ioc->tm_custom_handling)) {
2964 tr_timeout = pcie_device->reset_timeout;
2965 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
2967 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
2968 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
2969 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0,
2970 tr_timeout, tr_method);
2971 /* Check for busy commands after reset */
2972 if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
2975 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2976 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2979 sas_device_put(sas_device);
2981 pcie_device_put(pcie_device);
2987 * scsih_target_reset - eh threads main target reset routine
2988 * @scmd: pointer to scsi command object
2990 * Return: SUCCESS if command aborted else FAILED
2993 scsih_target_reset(struct scsi_cmnd *scmd)
2995 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2996 struct MPT3SAS_DEVICE *sas_device_priv_data;
2997 struct _sas_device *sas_device = NULL;
2998 struct _pcie_device *pcie_device = NULL;
3003 struct scsi_target *starget = scmd->device->sdev_target;
3004 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
3006 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
3008 _scsih_tm_display_info(ioc, scmd);
3010 sas_device_priv_data = scmd->device->hostdata;
3011 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
3013 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
3015 scmd->result = DID_NO_CONNECT << 16;
3016 scmd->scsi_done(scmd);
3021 /* for hidden raid components obtain the volume_handle */
3023 if (sas_device_priv_data->sas_target->flags &
3024 MPT_TARGET_FLAGS_RAID_COMPONENT) {
3025 sas_device = mpt3sas_get_sdev_from_target(ioc,
3028 handle = sas_device->volume_handle;
3030 handle = sas_device_priv_data->sas_target->handle;
3033 scmd->result = DID_RESET << 16;
3038 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
3040 if (pcie_device && (!ioc->tm_custom_handling)) {
3041 tr_timeout = pcie_device->reset_timeout;
3042 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3044 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3045 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0,
3046 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0,
3047 tr_timeout, tr_method);
3048 /* Check for busy commands after reset */
3049 if (r == SUCCESS && atomic_read(&starget->target_busy))
3052 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
3053 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3056 sas_device_put(sas_device);
3058 pcie_device_put(pcie_device);
3064 * scsih_host_reset - eh threads main host reset routine
3065 * @scmd: pointer to scsi command object
3067 * Return: SUCCESS if command aborted else FAILED
3070 scsih_host_reset(struct scsi_cmnd *scmd)
3072 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3075 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
3077 scsi_print_command(scmd);
3079 if (ioc->is_driver_loading || ioc->remove_host) {
3080 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
3086 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3087 r = (retval < 0) ? FAILED : SUCCESS;
3089 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
3090 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3096 * _scsih_fw_event_add - insert and queue up fw_event
3097 * @ioc: per adapter object
3098 * @fw_event: object describing the event
3099 * Context: This function will acquire ioc->fw_event_lock.
3101 * This adds the firmware event object into link list, then queues it up to
3102 * be processed from user context.
3105 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
3107 unsigned long flags;
3109 if (ioc->firmware_event_thread == NULL)
3112 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3113 fw_event_work_get(fw_event);
3114 INIT_LIST_HEAD(&fw_event->list);
3115 list_add_tail(&fw_event->list, &ioc->fw_event_list);
3116 INIT_WORK(&fw_event->work, _firmware_event_work);
3117 fw_event_work_get(fw_event);
3118 queue_work(ioc->firmware_event_thread, &fw_event->work);
3119 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3123 * _scsih_fw_event_del_from_list - delete fw_event from the list
3124 * @ioc: per adapter object
3125 * @fw_event: object describing the event
3126 * Context: This function will acquire ioc->fw_event_lock.
3128 * If the fw_event is on the fw_event_list, remove it and do a put.
3131 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
3134 unsigned long flags;
3136 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3137 if (!list_empty(&fw_event->list)) {
3138 list_del_init(&fw_event->list);
3139 fw_event_work_put(fw_event);
3141 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3146 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3147 * @ioc: per adapter object
3148 * @event_data: trigger event data
3151 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
3152 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
3154 struct fw_event_work *fw_event;
3157 if (ioc->is_driver_loading)
3159 sz = sizeof(*event_data);
3160 fw_event = alloc_fw_event_work(sz);
3163 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
3164 fw_event->ioc = ioc;
3165 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
3166 _scsih_fw_event_add(ioc, fw_event);
3167 fw_event_work_put(fw_event);
3171 * _scsih_error_recovery_delete_devices - remove devices not responding
3172 * @ioc: per adapter object
3175 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
3177 struct fw_event_work *fw_event;
3179 if (ioc->is_driver_loading)
3181 fw_event = alloc_fw_event_work(0);
3184 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
3185 fw_event->ioc = ioc;
3186 _scsih_fw_event_add(ioc, fw_event);
3187 fw_event_work_put(fw_event);
3191 * mpt3sas_port_enable_complete - port enable completed (fake event)
3192 * @ioc: per adapter object
3195 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
3197 struct fw_event_work *fw_event;
3199 fw_event = alloc_fw_event_work(0);
3202 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
3203 fw_event->ioc = ioc;
3204 _scsih_fw_event_add(ioc, fw_event);
3205 fw_event_work_put(fw_event);
3208 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
3210 unsigned long flags;
3211 struct fw_event_work *fw_event = NULL;
3213 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3214 if (!list_empty(&ioc->fw_event_list)) {
3215 fw_event = list_first_entry(&ioc->fw_event_list,
3216 struct fw_event_work, list);
3217 list_del_init(&fw_event->list);
3218 fw_event_work_put(fw_event);
3220 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3226 * _scsih_fw_event_cleanup_queue - cleanup event queue
3227 * @ioc: per adapter object
3229 * Walk the firmware event queue, either killing timers, or waiting
3230 * for outstanding events to complete
3233 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
3235 struct fw_event_work *fw_event;
3237 if (list_empty(&ioc->fw_event_list) ||
3238 !ioc->firmware_event_thread || in_interrupt())
3241 while ((fw_event = dequeue_next_fw_event(ioc))) {
3243 * Wait on the fw_event to complete. If this returns 1, then
3244 * the event was never executed, and we need a put for the
3245 * reference the work had on the fw_event.
3247 * If it did execute, we wait for it to finish, and the put will
3248 * happen from _firmware_event_work()
3250 if (cancel_work_sync(&fw_event->work))
3251 fw_event_work_put(fw_event);
3257 * _scsih_internal_device_block - block the sdev device
3258 * @sdev: per device object
3259 * @sas_device_priv_data : per device driver private data
3261 * make sure device is blocked without error, if not
3265 _scsih_internal_device_block(struct scsi_device *sdev,
3266 struct MPT3SAS_DEVICE *sas_device_priv_data)
3270 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
3271 sas_device_priv_data->sas_target->handle);
3272 sas_device_priv_data->block = 1;
3274 r = scsi_internal_device_block_nowait(sdev);
3276 sdev_printk(KERN_WARNING, sdev,
3277 "device_block failed with return(%d) for handle(0x%04x)\n",
3278 r, sas_device_priv_data->sas_target->handle);
3282 * _scsih_internal_device_unblock - unblock the sdev device
3283 * @sdev: per device object
3284 * @sas_device_priv_data : per device driver private data
3285 * make sure device is unblocked without error, if not retry
3286 * by blocking and then unblocking
3290 _scsih_internal_device_unblock(struct scsi_device *sdev,
3291 struct MPT3SAS_DEVICE *sas_device_priv_data)
3295 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
3296 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
3297 sas_device_priv_data->block = 0;
3298 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3300 /* The device has been set to SDEV_RUNNING by SD layer during
3301 * device addition but the request queue is still stopped by
3302 * our earlier block call. We need to perform a block again
3303 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3305 sdev_printk(KERN_WARNING, sdev,
3306 "device_unblock failed with return(%d) for handle(0x%04x) "
3307 "performing a block followed by an unblock\n",
3308 r, sas_device_priv_data->sas_target->handle);
3309 sas_device_priv_data->block = 1;
3310 r = scsi_internal_device_block_nowait(sdev);
3312 sdev_printk(KERN_WARNING, sdev, "retried device_block "
3313 "failed with return(%d) for handle(0x%04x)\n",
3314 r, sas_device_priv_data->sas_target->handle);
3316 sas_device_priv_data->block = 0;
3317 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3319 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
3320 " failed with return(%d) for handle(0x%04x)\n",
3321 r, sas_device_priv_data->sas_target->handle);
3326 * _scsih_ublock_io_all_device - unblock every device
3327 * @ioc: per adapter object
3329 * change the device state from block to running
3332 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3334 struct MPT3SAS_DEVICE *sas_device_priv_data;
3335 struct scsi_device *sdev;
3337 shost_for_each_device(sdev, ioc->shost) {
3338 sas_device_priv_data = sdev->hostdata;
3339 if (!sas_device_priv_data)
3341 if (!sas_device_priv_data->block)
3344 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3345 "device_running, handle(0x%04x)\n",
3346 sas_device_priv_data->sas_target->handle));
3347 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
3353 * _scsih_ublock_io_device - prepare device to be deleted
3354 * @ioc: per adapter object
3355 * @sas_address: sas address
3357 * unblock then put device in offline state
3360 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
3362 struct MPT3SAS_DEVICE *sas_device_priv_data;
3363 struct scsi_device *sdev;
3365 shost_for_each_device(sdev, ioc->shost) {
3366 sas_device_priv_data = sdev->hostdata;
3367 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
3369 if (sas_device_priv_data->sas_target->sas_address
3372 if (sas_device_priv_data->block)
3373 _scsih_internal_device_unblock(sdev,
3374 sas_device_priv_data);
3379 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3380 * @ioc: per adapter object
3382 * During device pull we need to appropriately set the sdev state.
3385 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3387 struct MPT3SAS_DEVICE *sas_device_priv_data;
3388 struct scsi_device *sdev;
3390 shost_for_each_device(sdev, ioc->shost) {
3391 sas_device_priv_data = sdev->hostdata;
3392 if (!sas_device_priv_data)
3394 if (sas_device_priv_data->block)
3396 if (sas_device_priv_data->ignore_delay_remove) {
3397 sdev_printk(KERN_INFO, sdev,
3398 "%s skip device_block for SES handle(0x%04x)\n",
3399 __func__, sas_device_priv_data->sas_target->handle);
3402 _scsih_internal_device_block(sdev, sas_device_priv_data);
3407 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3408 * @ioc: per adapter object
3409 * @handle: device handle
3411 * During device pull we need to appropriately set the sdev state.
3414 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3416 struct MPT3SAS_DEVICE *sas_device_priv_data;
3417 struct scsi_device *sdev;
3418 struct _sas_device *sas_device;
3420 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
3422 shost_for_each_device(sdev, ioc->shost) {
3423 sas_device_priv_data = sdev->hostdata;
3424 if (!sas_device_priv_data)
3426 if (sas_device_priv_data->sas_target->handle != handle)
3428 if (sas_device_priv_data->block)
3430 if (sas_device && sas_device->pend_sas_rphy_add)
3432 if (sas_device_priv_data->ignore_delay_remove) {
3433 sdev_printk(KERN_INFO, sdev,
3434 "%s skip device_block for SES handle(0x%04x)\n",
3435 __func__, sas_device_priv_data->sas_target->handle);
3438 _scsih_internal_device_block(sdev, sas_device_priv_data);
3442 sas_device_put(sas_device);
3446 * _scsih_block_io_to_children_attached_to_ex
3447 * @ioc: per adapter object
3448 * @sas_expander: the sas_device object
3450 * This routine set sdev state to SDEV_BLOCK for all devices
3451 * attached to this expander. This function called when expander is
3455 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3456 struct _sas_node *sas_expander)
3458 struct _sas_port *mpt3sas_port;
3459 struct _sas_device *sas_device;
3460 struct _sas_node *expander_sibling;
3461 unsigned long flags;
3466 list_for_each_entry(mpt3sas_port,
3467 &sas_expander->sas_port_list, port_list) {
3468 if (mpt3sas_port->remote_identify.device_type ==
3470 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3471 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3472 mpt3sas_port->remote_identify.sas_address);
3474 set_bit(sas_device->handle,
3475 ioc->blocking_handles);
3476 sas_device_put(sas_device);
3478 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3482 list_for_each_entry(mpt3sas_port,
3483 &sas_expander->sas_port_list, port_list) {
3485 if (mpt3sas_port->remote_identify.device_type ==
3486 SAS_EDGE_EXPANDER_DEVICE ||
3487 mpt3sas_port->remote_identify.device_type ==
3488 SAS_FANOUT_EXPANDER_DEVICE) {
3490 mpt3sas_scsih_expander_find_by_sas_address(
3491 ioc, mpt3sas_port->remote_identify.sas_address);
3492 _scsih_block_io_to_children_attached_to_ex(ioc,
3499 * _scsih_block_io_to_children_attached_directly
3500 * @ioc: per adapter object
3501 * @event_data: topology change event data
3503 * This routine set sdev state to SDEV_BLOCK for all devices
3504 * direct attached during device pull.
3507 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3508 Mpi2EventDataSasTopologyChangeList_t *event_data)
3514 for (i = 0; i < event_data->NumEntries; i++) {
3515 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3518 reason_code = event_data->PHY[i].PhyStatus &
3519 MPI2_EVENT_SAS_TOPO_RC_MASK;
3520 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3521 _scsih_block_io_device(ioc, handle);
3526 * _scsih_block_io_to_pcie_children_attached_directly
3527 * @ioc: per adapter object
3528 * @event_data: topology change event data
3530 * This routine set sdev state to SDEV_BLOCK for all devices
3531 * direct attached during device pull/reconnect.
3534 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3535 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
3541 for (i = 0; i < event_data->NumEntries; i++) {
3543 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
3546 reason_code = event_data->PortEntry[i].PortStatus;
3548 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING)
3549 _scsih_block_io_device(ioc, handle);
3553 * _scsih_tm_tr_send - send task management request
3554 * @ioc: per adapter object
3555 * @handle: device handle
3556 * Context: interrupt time.
3558 * This code is to initiate the device removal handshake protocol
3559 * with controller firmware. This function will issue target reset
3560 * using high priority request queue. It will send a sas iounit
3561 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3563 * This is designed to send muliple task management request at the same
3564 * time to the fifo. If the fifo is full, we will append the request,
3565 * and process it in a future completion.
3568 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3570 Mpi2SCSITaskManagementRequest_t *mpi_request;
3572 struct _sas_device *sas_device = NULL;
3573 struct _pcie_device *pcie_device = NULL;
3574 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3575 u64 sas_address = 0;
3576 unsigned long flags;
3577 struct _tr_list *delayed_tr;
3581 if (ioc->pci_error_recovery) {
3582 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3583 "%s: host in pci error recovery: handle(0x%04x)\n",
3584 __func__, ioc->name,
3588 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3589 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3590 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3591 "%s: host is not operational: handle(0x%04x)\n",
3592 __func__, ioc->name,
3597 /* if PD, then return */
3598 if (test_bit(handle, ioc->pd_handles))
3601 clear_bit(handle, ioc->pend_os_device_add);
3603 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3604 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3605 if (sas_device && sas_device->starget &&
3606 sas_device->starget->hostdata) {
3607 sas_target_priv_data = sas_device->starget->hostdata;
3608 sas_target_priv_data->deleted = 1;
3609 sas_address = sas_device->sas_address;
3611 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3613 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
3614 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
3615 if (pcie_device && pcie_device->starget &&
3616 pcie_device->starget->hostdata) {
3617 sas_target_priv_data = pcie_device->starget->hostdata;
3618 sas_target_priv_data->deleted = 1;
3619 sas_address = pcie_device->wwid;
3621 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
3622 if (pcie_device && (!ioc->tm_custom_handling))
3624 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3626 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3628 if (sas_target_priv_data) {
3629 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3630 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3632 (unsigned long long)sas_address));
3634 if (sas_device->enclosure_handle != 0)
3635 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3636 "setting delete flag:enclosure logical "
3637 "id(0x%016llx), slot(%d)\n", ioc->name,
3638 (unsigned long long)
3639 sas_device->enclosure_logical_id,
3641 if (sas_device->connector_name[0] != '\0')
3642 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3643 "setting delete flag: enclosure "
3644 "level(0x%04x), connector name( %s)\n",
3645 ioc->name, sas_device->enclosure_level,
3646 sas_device->connector_name));
3647 } else if (pcie_device) {
3648 if (pcie_device->enclosure_handle != 0)
3649 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3650 "setting delete flag: logical "
3651 "id(0x%016llx), slot(%d)\n", ioc->name,
3652 (unsigned long long)
3653 pcie_device->enclosure_logical_id,
3654 pcie_device->slot));
3655 if (pcie_device->connector_name[0] != '\0')
3656 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3657 "setting delete flag:, enclosure "
3659 "connector name( %s)\n", ioc->name,
3660 pcie_device->enclosure_level,
3661 pcie_device->connector_name));
3663 _scsih_ublock_io_device(ioc, sas_address);
3664 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3667 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3669 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3672 INIT_LIST_HEAD(&delayed_tr->list);
3673 delayed_tr->handle = handle;
3674 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3675 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3676 "DELAYED:tr:handle(0x%04x), (open)\n",
3677 ioc->name, handle));
3681 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3682 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3683 ioc->name, handle, smid,
3684 ioc->tm_tr_cb_idx));
3685 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3686 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3687 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3688 mpi_request->DevHandle = cpu_to_le16(handle);
3689 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3690 mpi_request->MsgFlags = tr_method;
3691 set_bit(handle, ioc->device_remove_in_progress);
3692 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3693 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3697 sas_device_put(sas_device);
3699 pcie_device_put(pcie_device);
3703 * _scsih_tm_tr_complete -
3704 * @ioc: per adapter object
3705 * @smid: system request message index
3706 * @msix_index: MSIX table index supplied by the OS
3707 * @reply: reply message frame(lower 32bit addr)
3708 * Context: interrupt time.
3710 * This is the target reset completion routine.
3711 * This code is part of the code to initiate the device removal
3712 * handshake protocol with controller firmware.
3713 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3715 * Return: 1 meaning mf should be freed from _base_interrupt
3716 * 0 means the mf is freed from this function.
3719 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3723 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3724 Mpi2SCSITaskManagementReply_t *mpi_reply =
3725 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3726 Mpi2SasIoUnitControlRequest_t *mpi_request;
3729 struct _sc_list *delayed_sc;
3731 if (ioc->pci_error_recovery) {
3732 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3733 "%s: host in pci error recovery\n", __func__,
3737 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3738 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3739 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3740 "%s: host is not operational\n", __func__, ioc->name));
3743 if (unlikely(!mpi_reply)) {
3744 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3745 ioc->name, __FILE__, __LINE__, __func__);
3748 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3749 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3750 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3751 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3752 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3754 le16_to_cpu(mpi_reply->DevHandle), smid));
3758 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3759 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3760 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3761 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3762 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3763 le32_to_cpu(mpi_reply->IOCLogInfo),
3764 le32_to_cpu(mpi_reply->TerminationCount)));
3766 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3767 if (!smid_sas_ctrl) {
3768 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3770 return _scsih_check_for_pending_tm(ioc, smid);
3771 INIT_LIST_HEAD(&delayed_sc->list);
3772 delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle);
3773 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3774 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3775 "DELAYED:sc:handle(0x%04x), (open)\n",
3776 ioc->name, handle));
3777 return _scsih_check_for_pending_tm(ioc, smid);
3780 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3781 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3782 ioc->name, handle, smid_sas_ctrl,
3783 ioc->tm_sas_control_cb_idx));
3784 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3785 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3786 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3787 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3788 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3789 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3791 return _scsih_check_for_pending_tm(ioc, smid);
3794 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3795 * issue to IOC or not.
3796 * @ioc: per adapter object
3797 * @scmd: pointer to scsi command object
3799 * Returns true if scmd can be issued to IOC otherwise returns false.
3801 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc,
3802 struct scsi_cmnd *scmd)
3805 if (ioc->pci_error_recovery)
3808 if (ioc->hba_mpi_version_belonged == MPI2_VERSION) {
3809 if (ioc->remove_host)
3815 if (ioc->remove_host) {
3817 switch (scmd->cmnd[0]) {
3818 case SYNCHRONIZE_CACHE:
3830 * _scsih_sas_control_complete - completion routine
3831 * @ioc: per adapter object
3832 * @smid: system request message index
3833 * @msix_index: MSIX table index supplied by the OS
3834 * @reply: reply message frame(lower 32bit addr)
3835 * Context: interrupt time.
3837 * This is the sas iounit control completion routine.
3838 * This code is part of the code to initiate the device removal
3839 * handshake protocol with controller firmware.
3841 * Return: 1 meaning mf should be freed from _base_interrupt
3842 * 0 means the mf is freed from this function.
3845 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3846 u8 msix_index, u32 reply)
3848 Mpi2SasIoUnitControlReply_t *mpi_reply =
3849 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3851 if (likely(mpi_reply)) {
3852 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3853 "sc_complete:handle(0x%04x), (open) "
3854 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3855 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3856 le16_to_cpu(mpi_reply->IOCStatus),
3857 le32_to_cpu(mpi_reply->IOCLogInfo)));
3858 if (le16_to_cpu(mpi_reply->IOCStatus) ==
3859 MPI2_IOCSTATUS_SUCCESS) {
3860 clear_bit(le16_to_cpu(mpi_reply->DevHandle),
3861 ioc->device_remove_in_progress);
3864 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3865 ioc->name, __FILE__, __LINE__, __func__);
3867 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3871 * _scsih_tm_tr_volume_send - send target reset request for volumes
3872 * @ioc: per adapter object
3873 * @handle: device handle
3874 * Context: interrupt time.
3876 * This is designed to send muliple task management request at the same
3877 * time to the fifo. If the fifo is full, we will append the request,
3878 * and process it in a future completion.
3881 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3883 Mpi2SCSITaskManagementRequest_t *mpi_request;
3885 struct _tr_list *delayed_tr;
3887 if (ioc->pci_error_recovery) {
3888 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3889 "%s: host reset in progress!\n",
3890 __func__, ioc->name));
3894 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3896 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3899 INIT_LIST_HEAD(&delayed_tr->list);
3900 delayed_tr->handle = handle;
3901 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3902 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3903 "DELAYED:tr:handle(0x%04x), (open)\n",
3904 ioc->name, handle));
3908 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3909 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3910 ioc->name, handle, smid,
3911 ioc->tm_tr_volume_cb_idx));
3912 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3913 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3914 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3915 mpi_request->DevHandle = cpu_to_le16(handle);
3916 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3917 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3921 * _scsih_tm_volume_tr_complete - target reset completion
3922 * @ioc: per adapter object
3923 * @smid: system request message index
3924 * @msix_index: MSIX table index supplied by the OS
3925 * @reply: reply message frame(lower 32bit addr)
3926 * Context: interrupt time.
3928 * Return: 1 meaning mf should be freed from _base_interrupt
3929 * 0 means the mf is freed from this function.
3932 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3933 u8 msix_index, u32 reply)
3936 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3937 Mpi2SCSITaskManagementReply_t *mpi_reply =
3938 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3940 if (ioc->shost_recovery || ioc->pci_error_recovery) {
3941 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3942 "%s: host reset in progress!\n",
3943 __func__, ioc->name));
3946 if (unlikely(!mpi_reply)) {
3947 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3948 ioc->name, __FILE__, __LINE__, __func__);
3952 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3953 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3954 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3955 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3956 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3958 le16_to_cpu(mpi_reply->DevHandle), smid));
3962 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3963 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3964 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3965 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3966 le32_to_cpu(mpi_reply->IOCLogInfo),
3967 le32_to_cpu(mpi_reply->TerminationCount)));
3969 return _scsih_check_for_pending_tm(ioc, smid);
3973 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3974 * @ioc: per adapter object
3975 * @smid: system request message index
3977 * @event_context: used to track events uniquely
3979 * Context - processed in interrupt context.
3982 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event,
3985 Mpi2EventAckRequest_t *ack_request;
3986 int i = smid - ioc->internal_smid;
3987 unsigned long flags;
3989 /* Without releasing the smid just update the
3990 * call back index and reuse the same smid for
3991 * processing this delayed request
3993 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3994 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3995 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3997 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3998 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3999 ioc->name, le16_to_cpu(event), smid,
4001 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
4002 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
4003 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
4004 ack_request->Event = event;
4005 ack_request->EventContext = event_context;
4006 ack_request->VF_ID = 0; /* TODO */
4007 ack_request->VP_ID = 0;
4008 mpt3sas_base_put_smid_default(ioc, smid);
4012 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
4013 * sas_io_unit_ctrl messages
4014 * @ioc: per adapter object
4015 * @smid: system request message index
4016 * @handle: device handle
4018 * Context - processed in interrupt context.
4021 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
4022 u16 smid, u16 handle)
4024 Mpi2SasIoUnitControlRequest_t *mpi_request;
4026 int i = smid - ioc->internal_smid;
4027 unsigned long flags;
4029 if (ioc->remove_host) {
4030 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4031 "%s: host has been removed\n",
4032 __func__, ioc->name));
4034 } else if (ioc->pci_error_recovery) {
4035 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4036 "%s: host in pci error recovery\n",
4037 __func__, ioc->name));
4040 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
4041 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
4042 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4043 "%s: host is not operational\n",
4044 __func__, ioc->name));
4048 /* Without releasing the smid just update the
4049 * call back index and reuse the same smid for
4050 * processing this delayed request
4052 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4053 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
4054 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4056 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4057 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4058 ioc->name, handle, smid,
4059 ioc->tm_sas_control_cb_idx));
4060 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4061 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
4062 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
4063 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
4064 mpi_request->DevHandle = cpu_to_le16(handle);
4065 mpt3sas_base_put_smid_default(ioc, smid);
4069 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4070 * @ioc: per adapter object
4071 * @smid: system request message index
4073 * Context: Executed in interrupt context
4075 * This will check delayed internal messages list, and process the
4078 * Return: 1 meaning mf should be freed from _base_interrupt
4079 * 0 means the mf is freed from this function.
4082 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4084 struct _sc_list *delayed_sc;
4085 struct _event_ack_list *delayed_event_ack;
4087 if (!list_empty(&ioc->delayed_event_ack_list)) {
4088 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
4089 struct _event_ack_list, list);
4090 _scsih_issue_delayed_event_ack(ioc, smid,
4091 delayed_event_ack->Event, delayed_event_ack->EventContext);
4092 list_del(&delayed_event_ack->list);
4093 kfree(delayed_event_ack);
4097 if (!list_empty(&ioc->delayed_sc_list)) {
4098 delayed_sc = list_entry(ioc->delayed_sc_list.next,
4099 struct _sc_list, list);
4100 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
4101 delayed_sc->handle);
4102 list_del(&delayed_sc->list);
4110 * _scsih_check_for_pending_tm - check for pending task management
4111 * @ioc: per adapter object
4112 * @smid: system request message index
4114 * This will check delayed target reset list, and feed the
4117 * Return: 1 meaning mf should be freed from _base_interrupt
4118 * 0 means the mf is freed from this function.
4121 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4123 struct _tr_list *delayed_tr;
4125 if (!list_empty(&ioc->delayed_tr_volume_list)) {
4126 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
4127 struct _tr_list, list);
4128 mpt3sas_base_free_smid(ioc, smid);
4129 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
4130 list_del(&delayed_tr->list);
4135 if (!list_empty(&ioc->delayed_tr_list)) {
4136 delayed_tr = list_entry(ioc->delayed_tr_list.next,
4137 struct _tr_list, list);
4138 mpt3sas_base_free_smid(ioc, smid);
4139 _scsih_tm_tr_send(ioc, delayed_tr->handle);
4140 list_del(&delayed_tr->list);
4149 * _scsih_check_topo_delete_events - sanity check on topo events
4150 * @ioc: per adapter object
4151 * @event_data: the event data payload
4153 * This routine added to better handle cable breaker.
4155 * This handles the case where driver receives multiple expander
4156 * add and delete events in a single shot. When there is a delete event
4157 * the routine will void any pending add events waiting in the event queue.
4160 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
4161 Mpi2EventDataSasTopologyChangeList_t *event_data)
4163 struct fw_event_work *fw_event;
4164 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
4165 u16 expander_handle;
4166 struct _sas_node *sas_expander;
4167 unsigned long flags;
4171 for (i = 0 ; i < event_data->NumEntries; i++) {
4172 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4175 reason_code = event_data->PHY[i].PhyStatus &
4176 MPI2_EVENT_SAS_TOPO_RC_MASK;
4177 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
4178 _scsih_tm_tr_send(ioc, handle);
4181 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
4182 if (expander_handle < ioc->sas_hba.num_phys) {
4183 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4186 if (event_data->ExpStatus ==
4187 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
4188 /* put expander attached devices into blocking state */
4189 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4190 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
4192 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
4193 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4195 handle = find_first_bit(ioc->blocking_handles,
4196 ioc->facts.MaxDevHandle);
4197 if (handle < ioc->facts.MaxDevHandle)
4198 _scsih_block_io_device(ioc, handle);
4199 } while (test_and_clear_bit(handle, ioc->blocking_handles));
4200 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
4201 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4203 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4206 /* mark ignore flag for pending events */
4207 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4208 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4209 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
4212 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
4213 fw_event->event_data;
4214 if (local_event_data->ExpStatus ==
4215 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4216 local_event_data->ExpStatus ==
4217 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4218 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
4220 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4221 "setting ignoring flag\n", ioc->name));
4222 fw_event->ignore = 1;
4226 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4230 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4232 * @ioc: per adapter object
4233 * @event_data: the event data payload
4235 * This handles the case where driver receives multiple switch
4236 * or device add and delete events in a single shot. When there
4237 * is a delete event the routine will void any pending add
4238 * events waiting in the event queue.
4241 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc,
4242 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
4244 struct fw_event_work *fw_event;
4245 Mpi26EventDataPCIeTopologyChangeList_t *local_event_data;
4246 unsigned long flags;
4248 u16 handle, switch_handle;
4250 for (i = 0; i < event_data->NumEntries; i++) {
4252 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
4255 reason_code = event_data->PortEntry[i].PortStatus;
4256 if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING)
4257 _scsih_tm_tr_send(ioc, handle);
4260 switch_handle = le16_to_cpu(event_data->SwitchDevHandle);
4261 if (!switch_handle) {
4262 _scsih_block_io_to_pcie_children_attached_directly(
4266 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4267 if ((event_data->SwitchStatus
4268 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) ||
4269 (event_data->SwitchStatus ==
4270 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING))
4271 _scsih_block_io_to_pcie_children_attached_directly(
4274 if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4277 /* mark ignore flag for pending events */
4278 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4279 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4280 if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
4284 (Mpi26EventDataPCIeTopologyChangeList_t *)
4285 fw_event->event_data;
4286 if (local_event_data->SwitchStatus ==
4287 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4288 local_event_data->SwitchStatus ==
4289 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4290 if (le16_to_cpu(local_event_data->SwitchDevHandle) ==
4292 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4293 "setting ignoring flag for switch event\n",
4295 fw_event->ignore = 1;
4299 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4303 * _scsih_set_volume_delete_flag - setting volume delete flag
4304 * @ioc: per adapter object
4305 * @handle: device handle
4307 * This returns nothing.
4310 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4312 struct _raid_device *raid_device;
4313 struct MPT3SAS_TARGET *sas_target_priv_data;
4314 unsigned long flags;
4316 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4317 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
4318 if (raid_device && raid_device->starget &&
4319 raid_device->starget->hostdata) {
4320 sas_target_priv_data =
4321 raid_device->starget->hostdata;
4322 sas_target_priv_data->deleted = 1;
4323 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4324 "setting delete flag: handle(0x%04x), "
4325 "wwid(0x%016llx)\n", ioc->name, handle,
4326 (unsigned long long) raid_device->wwid));
4328 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4332 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4333 * @handle: input handle
4334 * @a: handle for volume a
4335 * @b: handle for volume b
4337 * IR firmware only supports two raid volumes. The purpose of this
4338 * routine is to set the volume handle in either a or b. When the given
4339 * input handle is non-zero, or when a and b have not been set before.
4342 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
4344 if (!handle || handle == *a || handle == *b)
4353 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4354 * @ioc: per adapter object
4355 * @event_data: the event data payload
4356 * Context: interrupt time.
4358 * This routine will send target reset to volume, followed by target
4359 * resets to the PDs. This is called when a PD has been removed, or
4360 * volume has been deleted or removed. When the target reset is sent
4361 * to volume, the PD target resets need to be queued to start upon
4362 * completion of the volume target reset.
4365 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
4366 Mpi2EventDataIrConfigChangeList_t *event_data)
4368 Mpi2EventIrConfigElement_t *element;
4370 u16 handle, volume_handle, a, b;
4371 struct _tr_list *delayed_tr;
4376 if (ioc->is_warpdrive)
4379 /* Volume Resets for Deleted or Removed */
4380 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4381 for (i = 0; i < event_data->NumElements; i++, element++) {
4382 if (le32_to_cpu(event_data->Flags) &
4383 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4385 if (element->ReasonCode ==
4386 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
4387 element->ReasonCode ==
4388 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
4389 volume_handle = le16_to_cpu(element->VolDevHandle);
4390 _scsih_set_volume_delete_flag(ioc, volume_handle);
4391 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4395 /* Volume Resets for UNHIDE events */
4396 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4397 for (i = 0; i < event_data->NumElements; i++, element++) {
4398 if (le32_to_cpu(event_data->Flags) &
4399 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4401 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
4402 volume_handle = le16_to_cpu(element->VolDevHandle);
4403 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4408 _scsih_tm_tr_volume_send(ioc, a);
4410 _scsih_tm_tr_volume_send(ioc, b);
4412 /* PD target resets */
4413 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4414 for (i = 0; i < event_data->NumElements; i++, element++) {
4415 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
4417 handle = le16_to_cpu(element->PhysDiskDevHandle);
4418 volume_handle = le16_to_cpu(element->VolDevHandle);
4419 clear_bit(handle, ioc->pd_handles);
4421 _scsih_tm_tr_send(ioc, handle);
4422 else if (volume_handle == a || volume_handle == b) {
4423 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
4424 BUG_ON(!delayed_tr);
4425 INIT_LIST_HEAD(&delayed_tr->list);
4426 delayed_tr->handle = handle;
4427 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
4428 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4429 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
4432 _scsih_tm_tr_send(ioc, handle);
4438 * _scsih_check_volume_delete_events - set delete flag for volumes
4439 * @ioc: per adapter object
4440 * @event_data: the event data payload
4441 * Context: interrupt time.
4443 * This will handle the case when the cable connected to entire volume is
4444 * pulled. We will take care of setting the deleted flag so normal IO will
4448 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
4449 Mpi2EventDataIrVolume_t *event_data)
4453 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4455 state = le32_to_cpu(event_data->NewValue);
4456 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
4457 MPI2_RAID_VOL_STATE_FAILED)
4458 _scsih_set_volume_delete_flag(ioc,
4459 le16_to_cpu(event_data->VolDevHandle));
4463 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4464 * @ioc: per adapter object
4465 * @event_data: the temp threshold event data
4466 * Context: interrupt time.
4469 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
4470 Mpi2EventDataTemperature_t *event_data)
4472 if (ioc->temp_sensors_count >= event_data->SensorNum) {
4473 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
4474 " exceeded for Sensor: %d !!!\n", ioc->name,
4475 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
4476 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
4477 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
4478 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
4479 event_data->SensorNum);
4480 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
4481 ioc->name, event_data->CurrentTemperature);
4485 static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
4487 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
4489 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
4493 return test_and_set_bit(0, &priv->ata_command_pending);
4495 clear_bit(0, &priv->ata_command_pending);
4500 * _scsih_flush_running_cmds - completing outstanding commands.
4501 * @ioc: per adapter object
4503 * The flushing out of all pending scmd commands following host reset,
4504 * where all IO is dropped to the floor.
4507 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
4509 struct scsi_cmnd *scmd;
4510 struct scsiio_tracker *st;
4514 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
4515 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
4519 _scsih_set_satl_pending(scmd, false);
4520 st = scsi_cmd_priv(scmd);
4521 mpt3sas_base_clear_st(ioc, st);
4522 scsi_dma_unmap(scmd);
4523 if (ioc->pci_error_recovery || ioc->remove_host)
4524 scmd->result = DID_NO_CONNECT << 16;
4526 scmd->result = DID_RESET << 16;
4527 scmd->scsi_done(scmd);
4529 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
4534 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4535 * @ioc: per adapter object
4536 * @scmd: pointer to scsi command object
4537 * @mpi_request: pointer to the SCSI_IO request message frame
4539 * Supporting protection 1 and 3.
4542 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4543 Mpi25SCSIIORequest_t *mpi_request)
4546 unsigned char prot_op = scsi_get_prot_op(scmd);
4547 unsigned char prot_type = scsi_get_prot_type(scmd);
4548 Mpi25SCSIIORequest_t *mpi_request_3v =
4549 (Mpi25SCSIIORequest_t *)mpi_request;
4551 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
4554 if (prot_op == SCSI_PROT_READ_STRIP)
4555 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
4556 else if (prot_op == SCSI_PROT_WRITE_INSERT)
4557 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
4561 switch (prot_type) {
4562 case SCSI_PROT_DIF_TYPE1:
4563 case SCSI_PROT_DIF_TYPE2:
4566 * enable ref/guard checking
4567 * auto increment ref tag
4569 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
4570 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
4571 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4572 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
4573 cpu_to_be32(t10_pi_ref_tag(scmd->request));
4576 case SCSI_PROT_DIF_TYPE3:
4579 * enable guard checking
4581 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4586 mpi_request_3v->EEDPBlockSize =
4587 cpu_to_le16(scmd->device->sector_size);
4589 if (ioc->is_gen35_ioc)
4590 eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
4591 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
4595 * _scsih_eedp_error_handling - return sense code for EEDP errors
4596 * @scmd: pointer to scsi command object
4597 * @ioc_status: ioc status
4600 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4604 switch (ioc_status) {
4605 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4608 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4611 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4618 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4620 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4621 SAM_STAT_CHECK_CONDITION;
4625 * scsih_qcmd - main scsi request entry point
4626 * @shost: SCSI host pointer
4627 * @scmd: pointer to scsi command object
4629 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4631 * Return: 0 on success. If there's a failure, return either:
4632 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4633 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4636 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4638 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4639 struct MPT3SAS_DEVICE *sas_device_priv_data;
4640 struct MPT3SAS_TARGET *sas_target_priv_data;
4641 struct _raid_device *raid_device;
4642 struct request *rq = scmd->request;
4644 Mpi25SCSIIORequest_t *mpi_request;
4645 struct _pcie_device *pcie_device = NULL;
4650 if (ioc->logging_level & MPT_DEBUG_SCSI)
4651 scsi_print_command(scmd);
4653 sas_device_priv_data = scmd->device->hostdata;
4654 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4655 scmd->result = DID_NO_CONNECT << 16;
4656 scmd->scsi_done(scmd);
4660 if (!(_scsih_allow_scmd_to_device(ioc, scmd))) {
4661 scmd->result = DID_NO_CONNECT << 16;
4662 scmd->scsi_done(scmd);
4666 sas_target_priv_data = sas_device_priv_data->sas_target;
4668 /* invalid device handle */
4669 handle = sas_target_priv_data->handle;
4670 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4671 scmd->result = DID_NO_CONNECT << 16;
4672 scmd->scsi_done(scmd);
4677 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
4678 /* host recovery or link resets sent via IOCTLs */
4679 return SCSI_MLQUEUE_HOST_BUSY;
4680 } else if (sas_target_priv_data->deleted) {
4681 /* device has been deleted */
4682 scmd->result = DID_NO_CONNECT << 16;
4683 scmd->scsi_done(scmd);
4685 } else if (sas_target_priv_data->tm_busy ||
4686 sas_device_priv_data->block) {
4687 /* device busy with task management */
4688 return SCSI_MLQUEUE_DEVICE_BUSY;
4692 * Bug work around for firmware SATL handling. The loop
4693 * is based on atomic operations and ensures consistency
4694 * since we're lockless at this point
4697 if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
4698 scmd->result = SAM_STAT_BUSY;
4699 scmd->scsi_done(scmd);
4702 } while (_scsih_set_satl_pending(scmd, true));
4704 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4705 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4706 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4707 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4709 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4712 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4713 /* NCQ Prio supported, make sure control indicated high priority */
4714 if (sas_device_priv_data->ncq_prio_enable) {
4715 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
4716 if (class == IOPRIO_CLASS_RT)
4717 mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
4719 /* Make sure Device is not raid volume.
4720 * We do not expose raid functionality to upper layer for warpdrive.
4722 if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev))
4723 && !scsih_is_nvme(&scmd->device->sdev_gendev))
4724 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4725 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4727 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4729 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
4730 ioc->name, __func__);
4731 _scsih_set_satl_pending(scmd, false);
4734 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4735 memset(mpi_request, 0, ioc->request_sz);
4736 _scsih_setup_eedp(ioc, scmd, mpi_request);
4738 if (scmd->cmd_len == 32)
4739 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4740 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4741 if (sas_device_priv_data->sas_target->flags &
4742 MPT_TARGET_FLAGS_RAID_COMPONENT)
4743 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4745 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4746 mpi_request->DevHandle = cpu_to_le16(handle);
4747 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4748 mpi_request->Control = cpu_to_le32(mpi_control);
4749 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4750 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4751 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4752 mpi_request->SenseBufferLowAddress =
4753 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4754 mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4;
4755 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4757 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4759 if (mpi_request->DataLength) {
4760 pcie_device = sas_target_priv_data->pcie_dev;
4761 if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) {
4762 mpt3sas_base_free_smid(ioc, smid);
4763 _scsih_set_satl_pending(scmd, false);
4767 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4769 raid_device = sas_target_priv_data->raid_device;
4770 if (raid_device && raid_device->direct_io_enabled)
4771 mpt3sas_setup_direct_io(ioc, scmd,
4772 raid_device, mpi_request);
4774 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4775 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4776 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4777 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4778 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
4780 ioc->put_smid_scsi_io(ioc, smid,
4781 le16_to_cpu(mpi_request->DevHandle));
4783 mpt3sas_base_put_smid_default(ioc, smid);
4787 return SCSI_MLQUEUE_HOST_BUSY;
4791 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4792 * @sense_buffer: sense data returned by target
4793 * @data: normalized skey/asc/ascq
4796 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4798 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4799 /* descriptor format */
4800 data->skey = sense_buffer[1] & 0x0F;
4801 data->asc = sense_buffer[2];
4802 data->ascq = sense_buffer[3];
4805 data->skey = sense_buffer[2] & 0x0F;
4806 data->asc = sense_buffer[12];
4807 data->ascq = sense_buffer[13];
4812 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4813 * @ioc: per adapter object
4814 * @scmd: pointer to scsi command object
4815 * @mpi_reply: reply mf payload returned from firmware
4818 * scsi_status - SCSI Status code returned from target device
4819 * scsi_state - state info associated with SCSI_IO determined by ioc
4820 * ioc_status - ioc supplied status info
4823 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4824 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4828 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4829 MPI2_IOCSTATUS_MASK;
4830 u8 scsi_state = mpi_reply->SCSIState;
4831 u8 scsi_status = mpi_reply->SCSIStatus;
4832 char *desc_ioc_state = NULL;
4833 char *desc_scsi_status = NULL;
4834 char *desc_scsi_state = ioc->tmp_string;
4835 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4836 struct _sas_device *sas_device = NULL;
4837 struct _pcie_device *pcie_device = NULL;
4838 struct scsi_target *starget = scmd->device->sdev_target;
4839 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4840 char *device_str = NULL;
4844 if (ioc->hide_ir_msg)
4845 device_str = "WarpDrive";
4847 device_str = "volume";
4849 if (log_info == 0x31170000)
4852 switch (ioc_status) {
4853 case MPI2_IOCSTATUS_SUCCESS:
4854 desc_ioc_state = "success";
4856 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4857 desc_ioc_state = "invalid function";
4859 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4860 desc_ioc_state = "scsi recovered error";
4862 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4863 desc_ioc_state = "scsi invalid dev handle";
4865 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4866 desc_ioc_state = "scsi device not there";
4868 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4869 desc_ioc_state = "scsi data overrun";
4871 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4872 desc_ioc_state = "scsi data underrun";
4874 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4875 desc_ioc_state = "scsi io data error";
4877 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4878 desc_ioc_state = "scsi protocol error";
4880 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4881 desc_ioc_state = "scsi task terminated";
4883 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4884 desc_ioc_state = "scsi residual mismatch";
4886 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4887 desc_ioc_state = "scsi task mgmt failed";
4889 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4890 desc_ioc_state = "scsi ioc terminated";
4892 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4893 desc_ioc_state = "scsi ext terminated";
4895 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4896 desc_ioc_state = "eedp guard error";
4898 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4899 desc_ioc_state = "eedp ref tag error";
4901 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4902 desc_ioc_state = "eedp app tag error";
4904 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4905 desc_ioc_state = "insufficient power";
4908 desc_ioc_state = "unknown";
4912 switch (scsi_status) {
4913 case MPI2_SCSI_STATUS_GOOD:
4914 desc_scsi_status = "good";
4916 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4917 desc_scsi_status = "check condition";
4919 case MPI2_SCSI_STATUS_CONDITION_MET:
4920 desc_scsi_status = "condition met";
4922 case MPI2_SCSI_STATUS_BUSY:
4923 desc_scsi_status = "busy";
4925 case MPI2_SCSI_STATUS_INTERMEDIATE:
4926 desc_scsi_status = "intermediate";
4928 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4929 desc_scsi_status = "intermediate condmet";
4931 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4932 desc_scsi_status = "reservation conflict";
4934 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4935 desc_scsi_status = "command terminated";
4937 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4938 desc_scsi_status = "task set full";
4940 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4941 desc_scsi_status = "aca active";
4943 case MPI2_SCSI_STATUS_TASK_ABORTED:
4944 desc_scsi_status = "task aborted";
4947 desc_scsi_status = "unknown";
4951 desc_scsi_state[0] = '\0';
4953 desc_scsi_state = " ";
4954 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4955 strcat(desc_scsi_state, "response info ");
4956 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4957 strcat(desc_scsi_state, "state terminated ");
4958 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4959 strcat(desc_scsi_state, "no status ");
4960 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4961 strcat(desc_scsi_state, "autosense failed ");
4962 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4963 strcat(desc_scsi_state, "autosense valid ");
4965 scsi_print_command(scmd);
4967 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4968 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4969 device_str, (unsigned long long)priv_target->sas_address);
4970 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
4971 pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target);
4973 pr_info(MPT3SAS_FMT "\twwid(0x%016llx), port(%d)\n",
4975 (unsigned long long)pcie_device->wwid,
4976 pcie_device->port_num);
4977 if (pcie_device->enclosure_handle != 0)
4979 "\tenclosure logical id(0x%016llx), "
4980 "slot(%d)\n", ioc->name,
4981 (unsigned long long)
4982 pcie_device->enclosure_logical_id,
4984 if (pcie_device->connector_name[0])
4986 "\tenclosure level(0x%04x),"
4987 "connector name( %s)\n",
4988 ioc->name, pcie_device->enclosure_level,
4989 pcie_device->connector_name);
4990 pcie_device_put(pcie_device);
4993 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4996 "\tsas_address(0x%016llx), phy(%d)\n",
4997 ioc->name, (unsigned long long)
4998 sas_device->sas_address, sas_device->phy);
5000 _scsih_display_enclosure_chassis_info(ioc, sas_device,
5003 sas_device_put(sas_device);
5008 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
5009 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
5010 desc_ioc_state, ioc_status, smid);
5012 "\trequest_len(%d), underflow(%d), resid(%d)\n",
5013 ioc->name, scsi_bufflen(scmd), scmd->underflow,
5014 scsi_get_resid(scmd));
5016 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
5017 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
5018 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
5020 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
5021 ioc->name, desc_scsi_status,
5022 scsi_status, desc_scsi_state, scsi_state);
5024 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
5025 struct sense_info data;
5026 _scsih_normalize_sense(scmd->sense_buffer, &data);
5028 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
5029 ioc->name, data.skey,
5030 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
5032 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
5033 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
5034 response_bytes = (u8 *)&response_info;
5035 _scsih_response_code(ioc, response_bytes[0]);
5040 * _scsih_turn_on_pfa_led - illuminate PFA LED
5041 * @ioc: per adapter object
5042 * @handle: device handle
5046 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5048 Mpi2SepReply_t mpi_reply;
5049 Mpi2SepRequest_t mpi_request;
5050 struct _sas_device *sas_device;
5052 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
5056 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
5057 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
5058 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
5059 mpi_request.SlotStatus =
5060 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
5061 mpi_request.DevHandle = cpu_to_le16(handle);
5062 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
5063 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5064 &mpi_request)) != 0) {
5065 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
5066 __FILE__, __LINE__, __func__);
5069 sas_device->pfa_led_on = 1;
5071 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5072 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5073 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5074 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
5075 le32_to_cpu(mpi_reply.IOCLogInfo)));
5079 sas_device_put(sas_device);
5083 * _scsih_turn_off_pfa_led - turn off Fault LED
5084 * @ioc: per adapter object
5085 * @sas_device: sas device whose PFA LED has to turned off
5089 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
5090 struct _sas_device *sas_device)
5092 Mpi2SepReply_t mpi_reply;
5093 Mpi2SepRequest_t mpi_request;
5095 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
5096 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
5097 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
5098 mpi_request.SlotStatus = 0;
5099 mpi_request.Slot = cpu_to_le16(sas_device->slot);
5100 mpi_request.DevHandle = 0;
5101 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
5102 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
5103 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5104 &mpi_request)) != 0) {
5105 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
5106 __FILE__, __LINE__, __func__);
5110 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5111 dewtprintk(ioc, printk(MPT3SAS_FMT
5112 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5113 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
5114 le32_to_cpu(mpi_reply.IOCLogInfo)));
5120 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5121 * @ioc: per adapter object
5122 * @handle: device handle
5123 * Context: interrupt.
5126 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5128 struct fw_event_work *fw_event;
5130 fw_event = alloc_fw_event_work(0);
5133 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
5134 fw_event->device_handle = handle;
5135 fw_event->ioc = ioc;
5136 _scsih_fw_event_add(ioc, fw_event);
5137 fw_event_work_put(fw_event);
5141 * _scsih_smart_predicted_fault - process smart errors
5142 * @ioc: per adapter object
5143 * @handle: device handle
5144 * Context: interrupt.
5147 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5149 struct scsi_target *starget;
5150 struct MPT3SAS_TARGET *sas_target_priv_data;
5151 Mpi2EventNotificationReply_t *event_reply;
5152 Mpi2EventDataSasDeviceStatusChange_t *event_data;
5153 struct _sas_device *sas_device;
5155 unsigned long flags;
5157 /* only handle non-raid devices */
5158 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5159 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
5163 starget = sas_device->starget;
5164 sas_target_priv_data = starget->hostdata;
5166 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
5167 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
5170 _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget);
5172 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5174 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
5175 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
5177 /* insert into event log */
5178 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
5179 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
5180 event_reply = kzalloc(sz, GFP_KERNEL);
5182 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5183 ioc->name, __FILE__, __LINE__, __func__);
5187 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
5188 event_reply->Event =
5189 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
5190 event_reply->MsgLength = sz/4;
5191 event_reply->EventDataLength =
5192 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
5193 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
5194 event_reply->EventData;
5195 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
5196 event_data->ASC = 0x5D;
5197 event_data->DevHandle = cpu_to_le16(handle);
5198 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
5199 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
5203 sas_device_put(sas_device);
5207 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5212 * _scsih_io_done - scsi request callback
5213 * @ioc: per adapter object
5214 * @smid: system request message index
5215 * @msix_index: MSIX table index supplied by the OS
5216 * @reply: reply message frame(lower 32bit addr)
5218 * Callback handler when using _scsih_qcmd.
5220 * Return: 1 meaning mf should be freed from _base_interrupt
5221 * 0 means the mf is freed from this function.
5224 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5226 Mpi25SCSIIORequest_t *mpi_request;
5227 Mpi2SCSIIOReply_t *mpi_reply;
5228 struct scsi_cmnd *scmd;
5229 struct scsiio_tracker *st;
5235 struct MPT3SAS_DEVICE *sas_device_priv_data;
5236 u32 response_code = 0;
5238 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5240 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
5244 _scsih_set_satl_pending(scmd, false);
5246 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5248 if (mpi_reply == NULL) {
5249 scmd->result = DID_OK << 16;
5253 sas_device_priv_data = scmd->device->hostdata;
5254 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
5255 sas_device_priv_data->sas_target->deleted) {
5256 scmd->result = DID_NO_CONNECT << 16;
5259 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5262 * WARPDRIVE: If direct_io is set then it is directIO,
5263 * the failed direct I/O should be redirected to volume
5265 st = scsi_cmd_priv(scmd);
5266 if (st->direct_io &&
5267 ((ioc_status & MPI2_IOCSTATUS_MASK)
5268 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
5270 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
5271 mpi_request->DevHandle =
5272 cpu_to_le16(sas_device_priv_data->sas_target->handle);
5273 ioc->put_smid_scsi_io(ioc, smid,
5274 sas_device_priv_data->sas_target->handle);
5277 /* turning off TLR */
5278 scsi_state = mpi_reply->SCSIState;
5279 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
5281 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
5282 if (!sas_device_priv_data->tlr_snoop_check) {
5283 sas_device_priv_data->tlr_snoop_check++;
5284 if ((!ioc->is_warpdrive &&
5285 !scsih_is_raid(&scmd->device->sdev_gendev) &&
5286 !scsih_is_nvme(&scmd->device->sdev_gendev))
5287 && sas_is_tlr_enabled(scmd->device) &&
5288 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
5289 sas_disable_tlr(scmd->device);
5290 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
5294 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
5295 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
5296 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5297 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5300 ioc_status &= MPI2_IOCSTATUS_MASK;
5301 scsi_status = mpi_reply->SCSIStatus;
5303 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
5304 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
5305 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
5306 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
5307 ioc_status = MPI2_IOCSTATUS_SUCCESS;
5310 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
5311 struct sense_info data;
5312 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
5314 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
5315 le32_to_cpu(mpi_reply->SenseCount));
5316 memcpy(scmd->sense_buffer, sense_data, sz);
5317 _scsih_normalize_sense(scmd->sense_buffer, &data);
5318 /* failure prediction threshold exceeded */
5319 if (data.asc == 0x5D)
5320 _scsih_smart_predicted_fault(ioc,
5321 le16_to_cpu(mpi_reply->DevHandle));
5322 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
5324 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
5325 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
5326 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
5327 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
5328 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
5330 switch (ioc_status) {
5331 case MPI2_IOCSTATUS_BUSY:
5332 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
5333 scmd->result = SAM_STAT_BUSY;
5336 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
5337 scmd->result = DID_NO_CONNECT << 16;
5340 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
5341 if (sas_device_priv_data->block) {
5342 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
5345 if (log_info == 0x31110630) {
5346 if (scmd->retries > 2) {
5347 scmd->result = DID_NO_CONNECT << 16;
5348 scsi_device_set_state(scmd->device,
5351 scmd->result = DID_SOFT_ERROR << 16;
5352 scmd->device->expecting_cc_ua = 1;
5355 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
5356 scmd->result = DID_RESET << 16;
5358 } else if ((scmd->device->channel == RAID_CHANNEL) &&
5359 (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
5360 MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
5361 scmd->result = DID_RESET << 16;
5364 scmd->result = DID_SOFT_ERROR << 16;
5366 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
5367 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
5368 scmd->result = DID_RESET << 16;
5371 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
5372 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
5373 scmd->result = DID_SOFT_ERROR << 16;
5375 scmd->result = (DID_OK << 16) | scsi_status;
5378 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
5379 scmd->result = (DID_OK << 16) | scsi_status;
5381 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
5384 if (xfer_cnt < scmd->underflow) {
5385 if (scsi_status == SAM_STAT_BUSY)
5386 scmd->result = SAM_STAT_BUSY;
5388 scmd->result = DID_SOFT_ERROR << 16;
5389 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5390 MPI2_SCSI_STATE_NO_SCSI_STATUS))
5391 scmd->result = DID_SOFT_ERROR << 16;
5392 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5393 scmd->result = DID_RESET << 16;
5394 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
5395 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
5396 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
5397 scmd->result = (DRIVER_SENSE << 24) |
5398 SAM_STAT_CHECK_CONDITION;
5399 scmd->sense_buffer[0] = 0x70;
5400 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
5401 scmd->sense_buffer[12] = 0x20;
5402 scmd->sense_buffer[13] = 0;
5406 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
5407 scsi_set_resid(scmd, 0);
5409 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
5410 case MPI2_IOCSTATUS_SUCCESS:
5411 scmd->result = (DID_OK << 16) | scsi_status;
5412 if (response_code ==
5413 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
5414 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5415 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
5416 scmd->result = DID_SOFT_ERROR << 16;
5417 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5418 scmd->result = DID_RESET << 16;
5421 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
5422 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
5423 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
5424 _scsih_eedp_error_handling(scmd, ioc_status);
5427 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
5428 case MPI2_IOCSTATUS_INVALID_FUNCTION:
5429 case MPI2_IOCSTATUS_INVALID_SGL:
5430 case MPI2_IOCSTATUS_INTERNAL_ERROR:
5431 case MPI2_IOCSTATUS_INVALID_FIELD:
5432 case MPI2_IOCSTATUS_INVALID_STATE:
5433 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
5434 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
5435 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
5437 scmd->result = DID_SOFT_ERROR << 16;
5442 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
5443 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
5447 scsi_dma_unmap(scmd);
5448 mpt3sas_base_free_smid(ioc, smid);
5449 scmd->scsi_done(scmd);
5454 * _scsih_sas_host_refresh - refreshing sas host object contents
5455 * @ioc: per adapter object
5458 * During port enable, fw will send topology events for every device. Its
5459 * possible that the handles may change from the previous setting, so this
5460 * code keeping handles updating if changed.
5463 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
5468 Mpi2ConfigReply_t mpi_reply;
5469 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5470 u16 attached_handle;
5473 dtmprintk(ioc, pr_info(MPT3SAS_FMT
5474 "updating handles for sas_host(0x%016llx)\n",
5475 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
5477 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
5478 * sizeof(Mpi2SasIOUnit0PhyData_t));
5479 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5480 if (!sas_iounit_pg0) {
5481 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5482 ioc->name, __FILE__, __LINE__, __func__);
5486 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5487 sas_iounit_pg0, sz)) != 0)
5489 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5490 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5492 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5493 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
5495 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5496 PhyData[0].ControllerDevHandle);
5497 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5498 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
5500 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5501 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
5502 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
5503 attached_handle, i, link_rate);
5506 kfree(sas_iounit_pg0);
5510 * _scsih_sas_host_add - create sas host object
5511 * @ioc: per adapter object
5513 * Creating host side data object, stored in ioc->sas_hba
5516 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
5519 Mpi2ConfigReply_t mpi_reply;
5520 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5521 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
5522 Mpi2SasPhyPage0_t phy_pg0;
5523 Mpi2SasDevicePage0_t sas_device_pg0;
5524 Mpi2SasEnclosurePage0_t enclosure_pg0;
5527 u8 device_missing_delay;
5530 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
5532 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5533 ioc->name, __FILE__, __LINE__, __func__);
5536 ioc->sas_hba.phy = kcalloc(num_phys,
5537 sizeof(struct _sas_phy), GFP_KERNEL);
5538 if (!ioc->sas_hba.phy) {
5539 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5540 ioc->name, __FILE__, __LINE__, __func__);
5543 ioc->sas_hba.num_phys = num_phys;
5545 /* sas_iounit page 0 */
5546 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
5547 sizeof(Mpi2SasIOUnit0PhyData_t));
5548 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5549 if (!sas_iounit_pg0) {
5550 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5551 ioc->name, __FILE__, __LINE__, __func__);
5554 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5555 sas_iounit_pg0, sz))) {
5556 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5557 ioc->name, __FILE__, __LINE__, __func__);
5560 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5561 MPI2_IOCSTATUS_MASK;
5562 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5563 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5564 ioc->name, __FILE__, __LINE__, __func__);
5568 /* sas_iounit page 1 */
5569 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
5570 sizeof(Mpi2SasIOUnit1PhyData_t));
5571 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
5572 if (!sas_iounit_pg1) {
5573 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5574 ioc->name, __FILE__, __LINE__, __func__);
5577 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
5578 sas_iounit_pg1, sz))) {
5579 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5580 ioc->name, __FILE__, __LINE__, __func__);
5583 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5584 MPI2_IOCSTATUS_MASK;
5585 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5586 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5587 ioc->name, __FILE__, __LINE__, __func__);
5591 ioc->io_missing_delay =
5592 sas_iounit_pg1->IODeviceMissingDelay;
5593 device_missing_delay =
5594 sas_iounit_pg1->ReportDeviceMissingDelay;
5595 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
5596 ioc->device_missing_delay = (device_missing_delay &
5597 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
5599 ioc->device_missing_delay = device_missing_delay &
5600 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
5602 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
5603 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5604 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5606 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5607 ioc->name, __FILE__, __LINE__, __func__);
5610 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5611 MPI2_IOCSTATUS_MASK;
5612 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5613 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5614 ioc->name, __FILE__, __LINE__, __func__);
5619 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5620 PhyData[0].ControllerDevHandle);
5621 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5622 ioc->sas_hba.phy[i].phy_id = i;
5623 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
5624 phy_pg0, ioc->sas_hba.parent_dev);
5626 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5627 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
5628 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5629 ioc->name, __FILE__, __LINE__, __func__);
5632 ioc->sas_hba.enclosure_handle =
5633 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5634 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5636 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5637 ioc->name, ioc->sas_hba.handle,
5638 (unsigned long long) ioc->sas_hba.sas_address,
5639 ioc->sas_hba.num_phys) ;
5641 if (ioc->sas_hba.enclosure_handle) {
5642 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5643 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5644 ioc->sas_hba.enclosure_handle)))
5645 ioc->sas_hba.enclosure_logical_id =
5646 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5650 kfree(sas_iounit_pg1);
5651 kfree(sas_iounit_pg0);
5655 * _scsih_expander_add - creating expander object
5656 * @ioc: per adapter object
5657 * @handle: expander handle
5659 * Creating expander object, stored in ioc->sas_expander_list.
5661 * Return: 0 for success, else error.
5664 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5666 struct _sas_node *sas_expander;
5667 struct _enclosure_node *enclosure_dev;
5668 Mpi2ConfigReply_t mpi_reply;
5669 Mpi2ExpanderPage0_t expander_pg0;
5670 Mpi2ExpanderPage1_t expander_pg1;
5673 u64 sas_address, sas_address_parent = 0;
5675 unsigned long flags;
5676 struct _sas_port *mpt3sas_port = NULL;
5683 if (ioc->shost_recovery || ioc->pci_error_recovery)
5686 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5687 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5688 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5689 ioc->name, __FILE__, __LINE__, __func__);
5693 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5694 MPI2_IOCSTATUS_MASK;
5695 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5696 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5697 ioc->name, __FILE__, __LINE__, __func__);
5701 /* handle out of order topology events */
5702 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5703 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5705 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5706 ioc->name, __FILE__, __LINE__, __func__);
5709 if (sas_address_parent != ioc->sas_hba.sas_address) {
5710 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5711 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5712 sas_address_parent);
5713 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5714 if (!sas_expander) {
5715 rc = _scsih_expander_add(ioc, parent_handle);
5721 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5722 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5723 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5725 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5730 sas_expander = kzalloc(sizeof(struct _sas_node),
5732 if (!sas_expander) {
5733 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5734 ioc->name, __FILE__, __LINE__, __func__);
5738 sas_expander->handle = handle;
5739 sas_expander->num_phys = expander_pg0.NumPhys;
5740 sas_expander->sas_address_parent = sas_address_parent;
5741 sas_expander->sas_address = sas_address;
5743 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5744 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5745 handle, parent_handle, (unsigned long long)
5746 sas_expander->sas_address, sas_expander->num_phys);
5748 if (!sas_expander->num_phys) {
5752 sas_expander->phy = kcalloc(sas_expander->num_phys,
5753 sizeof(struct _sas_phy), GFP_KERNEL);
5754 if (!sas_expander->phy) {
5755 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5756 ioc->name, __FILE__, __LINE__, __func__);
5761 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5762 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5763 sas_address_parent);
5764 if (!mpt3sas_port) {
5765 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5766 ioc->name, __FILE__, __LINE__, __func__);
5770 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5772 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5773 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5774 &expander_pg1, i, handle))) {
5775 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5776 ioc->name, __FILE__, __LINE__, __func__);
5780 sas_expander->phy[i].handle = handle;
5781 sas_expander->phy[i].phy_id = i;
5783 if ((mpt3sas_transport_add_expander_phy(ioc,
5784 &sas_expander->phy[i], expander_pg1,
5785 sas_expander->parent_dev))) {
5786 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5787 ioc->name, __FILE__, __LINE__, __func__);
5793 if (sas_expander->enclosure_handle) {
5795 mpt3sas_scsih_enclosure_find_by_handle(ioc,
5796 sas_expander->enclosure_handle);
5798 sas_expander->enclosure_logical_id =
5799 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
5802 _scsih_expander_node_add(ioc, sas_expander);
5808 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5809 sas_address_parent);
5810 kfree(sas_expander);
5815 * mpt3sas_expander_remove - removing expander object
5816 * @ioc: per adapter object
5817 * @sas_address: expander sas_address
5820 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5822 struct _sas_node *sas_expander;
5823 unsigned long flags;
5825 if (ioc->shost_recovery)
5828 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5829 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5831 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5833 _scsih_expander_node_remove(ioc, sas_expander);
5837 * _scsih_done - internal SCSI_IO callback handler.
5838 * @ioc: per adapter object
5839 * @smid: system request message index
5840 * @msix_index: MSIX table index supplied by the OS
5841 * @reply: reply message frame(lower 32bit addr)
5843 * Callback handler when sending internal generated SCSI_IO.
5844 * The callback index passed is `ioc->scsih_cb_idx`
5846 * Return: 1 meaning mf should be freed from _base_interrupt
5847 * 0 means the mf is freed from this function.
5850 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5852 MPI2DefaultReply_t *mpi_reply;
5854 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5855 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5857 if (ioc->scsih_cmds.smid != smid)
5859 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5861 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5862 mpi_reply->MsgLength*4);
5863 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5865 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5866 complete(&ioc->scsih_cmds.done);
5873 #define MPT3_MAX_LUNS (255)
5877 * _scsih_check_access_status - check access flags
5878 * @ioc: per adapter object
5879 * @sas_address: sas address
5880 * @handle: sas device handle
5881 * @access_status: errors returned during discovery of the device
5883 * Return: 0 for success, else failure
5886 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5887 u16 handle, u8 access_status)
5892 switch (access_status) {
5893 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5894 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5897 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5898 desc = "sata capability failed";
5900 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5901 desc = "sata affiliation conflict";
5903 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5904 desc = "route not addressable";
5906 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5907 desc = "smp error not addressable";
5909 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5910 desc = "device blocked";
5912 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5913 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5914 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5915 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5916 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5917 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5918 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5919 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5920 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5921 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5922 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5923 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5924 desc = "sata initialization failed";
5935 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5936 ioc->name, desc, (unsigned long long)sas_address, handle);
5941 * _scsih_check_device - checking device responsiveness
5942 * @ioc: per adapter object
5943 * @parent_sas_address: sas address of parent expander or sas host
5944 * @handle: attached device handle
5945 * @phy_number: phy number
5946 * @link_rate: new link rate
5949 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5950 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5952 Mpi2ConfigReply_t mpi_reply;
5953 Mpi2SasDevicePage0_t sas_device_pg0;
5954 struct _sas_device *sas_device;
5955 struct _enclosure_node *enclosure_dev = NULL;
5957 unsigned long flags;
5959 struct scsi_target *starget;
5960 struct MPT3SAS_TARGET *sas_target_priv_data;
5963 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5964 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5967 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5968 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5971 /* wide port handling ~ we need only handle device once for the phy that
5972 * is matched in sas device page zero
5974 if (phy_number != sas_device_pg0.PhyNum)
5977 /* check if this is end device */
5978 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5979 if (!(_scsih_is_end_device(device_info)))
5982 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5983 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5984 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5990 if (unlikely(sas_device->handle != handle)) {
5991 starget = sas_device->starget;
5992 sas_target_priv_data = starget->hostdata;
5993 starget_printk(KERN_INFO, starget,
5994 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5995 sas_device->handle, handle);
5996 sas_target_priv_data->handle = handle;
5997 sas_device->handle = handle;
5998 if (le16_to_cpu(sas_device_pg0.Flags) &
5999 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6000 sas_device->enclosure_level =
6001 sas_device_pg0.EnclosureLevel;
6002 memcpy(sas_device->connector_name,
6003 sas_device_pg0.ConnectorName, 4);
6004 sas_device->connector_name[4] = '\0';
6006 sas_device->enclosure_level = 0;
6007 sas_device->connector_name[0] = '\0';
6010 sas_device->enclosure_handle =
6011 le16_to_cpu(sas_device_pg0.EnclosureHandle);
6012 sas_device->is_chassis_slot_valid = 0;
6013 enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc,
6014 sas_device->enclosure_handle);
6015 if (enclosure_dev) {
6016 sas_device->enclosure_logical_id =
6017 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6018 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
6019 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
6020 sas_device->is_chassis_slot_valid = 1;
6021 sas_device->chassis_slot =
6022 enclosure_dev->pg0.ChassisSlot;
6027 /* check if device is present */
6028 if (!(le16_to_cpu(sas_device_pg0.Flags) &
6029 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
6031 "device is not present handle(0x%04x), flags!!!\n",
6036 /* check if there were any issues with discovery */
6037 if (_scsih_check_access_status(ioc, sas_address, handle,
6038 sas_device_pg0.AccessStatus))
6041 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6042 _scsih_ublock_io_device(ioc, sas_address);
6045 sas_device_put(sas_device);
6049 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6051 sas_device_put(sas_device);
6055 * _scsih_add_device - creating sas device object
6056 * @ioc: per adapter object
6057 * @handle: sas device handle
6058 * @phy_num: phy number end device attached to
6059 * @is_pd: is this hidden raid component
6061 * Creating end device object, stored in ioc->sas_device_list.
6063 * Return: 0 for success, non-zero for failure.
6066 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
6069 Mpi2ConfigReply_t mpi_reply;
6070 Mpi2SasDevicePage0_t sas_device_pg0;
6071 struct _sas_device *sas_device;
6072 struct _enclosure_node *enclosure_dev = NULL;
6077 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6078 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6079 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6080 ioc->name, __FILE__, __LINE__, __func__);
6084 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6085 MPI2_IOCSTATUS_MASK;
6086 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6087 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6088 ioc->name, __FILE__, __LINE__, __func__);
6092 /* check if this is end device */
6093 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6094 if (!(_scsih_is_end_device(device_info)))
6096 set_bit(handle, ioc->pend_os_device_add);
6097 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6099 /* check if device is present */
6100 if (!(le16_to_cpu(sas_device_pg0.Flags) &
6101 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
6102 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
6107 /* check if there were any issues with discovery */
6108 if (_scsih_check_access_status(ioc, sas_address, handle,
6109 sas_device_pg0.AccessStatus))
6112 sas_device = mpt3sas_get_sdev_by_addr(ioc,
6115 clear_bit(handle, ioc->pend_os_device_add);
6116 sas_device_put(sas_device);
6120 if (sas_device_pg0.EnclosureHandle) {
6122 mpt3sas_scsih_enclosure_find_by_handle(ioc,
6123 le16_to_cpu(sas_device_pg0.EnclosureHandle));
6124 if (enclosure_dev == NULL)
6125 pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)"
6126 "doesn't match with enclosure device!\n",
6127 ioc->name, sas_device_pg0.EnclosureHandle);
6130 sas_device = kzalloc(sizeof(struct _sas_device),
6133 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6134 ioc->name, __FILE__, __LINE__, __func__);
6138 kref_init(&sas_device->refcount);
6139 sas_device->handle = handle;
6140 if (_scsih_get_sas_address(ioc,
6141 le16_to_cpu(sas_device_pg0.ParentDevHandle),
6142 &sas_device->sas_address_parent) != 0)
6143 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6144 ioc->name, __FILE__, __LINE__, __func__);
6145 sas_device->enclosure_handle =
6146 le16_to_cpu(sas_device_pg0.EnclosureHandle);
6147 if (sas_device->enclosure_handle != 0)
6149 le16_to_cpu(sas_device_pg0.Slot);
6150 sas_device->device_info = device_info;
6151 sas_device->sas_address = sas_address;
6152 sas_device->phy = sas_device_pg0.PhyNum;
6153 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
6154 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
6156 if (le16_to_cpu(sas_device_pg0.Flags)
6157 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6158 sas_device->enclosure_level =
6159 sas_device_pg0.EnclosureLevel;
6160 memcpy(sas_device->connector_name,
6161 sas_device_pg0.ConnectorName, 4);
6162 sas_device->connector_name[4] = '\0';
6164 sas_device->enclosure_level = 0;
6165 sas_device->connector_name[0] = '\0';
6167 /* get enclosure_logical_id & chassis_slot*/
6168 sas_device->is_chassis_slot_valid = 0;
6169 if (enclosure_dev) {
6170 sas_device->enclosure_logical_id =
6171 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6172 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
6173 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
6174 sas_device->is_chassis_slot_valid = 1;
6175 sas_device->chassis_slot =
6176 enclosure_dev->pg0.ChassisSlot;
6180 /* get device name */
6181 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
6183 if (ioc->wait_for_discovery_to_complete)
6184 _scsih_sas_device_init_add(ioc, sas_device);
6186 _scsih_sas_device_add(ioc, sas_device);
6188 sas_device_put(sas_device);
6193 * _scsih_remove_device - removing sas device object
6194 * @ioc: per adapter object
6195 * @sas_device: the sas_device object
6198 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
6199 struct _sas_device *sas_device)
6201 struct MPT3SAS_TARGET *sas_target_priv_data;
6203 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
6204 (sas_device->pfa_led_on)) {
6205 _scsih_turn_off_pfa_led(ioc, sas_device);
6206 sas_device->pfa_led_on = 0;
6209 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6210 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6211 ioc->name, __func__,
6212 sas_device->handle, (unsigned long long)
6213 sas_device->sas_address));
6215 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
6218 if (sas_device->starget && sas_device->starget->hostdata) {
6219 sas_target_priv_data = sas_device->starget->hostdata;
6220 sas_target_priv_data->deleted = 1;
6221 _scsih_ublock_io_device(ioc, sas_device->sas_address);
6222 sas_target_priv_data->handle =
6223 MPT3SAS_INVALID_DEVICE_HANDLE;
6226 if (!ioc->hide_drives)
6227 mpt3sas_transport_port_remove(ioc,
6228 sas_device->sas_address,
6229 sas_device->sas_address_parent);
6232 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6233 ioc->name, sas_device->handle,
6234 (unsigned long long) sas_device->sas_address);
6236 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
6238 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6239 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6240 ioc->name, __func__,
6241 sas_device->handle, (unsigned long long)
6242 sas_device->sas_address));
6243 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
6248 * _scsih_sas_topology_change_event_debug - debug for topology event
6249 * @ioc: per adapter object
6250 * @event_data: event data payload
6254 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6255 Mpi2EventDataSasTopologyChangeList_t *event_data)
6261 char *status_str = NULL;
6262 u8 link_rate, prev_link_rate;
6264 switch (event_data->ExpStatus) {
6265 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
6268 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
6269 status_str = "remove";
6271 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
6273 status_str = "responding";
6275 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
6276 status_str = "remove delay";
6279 status_str = "unknown status";
6282 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
6283 ioc->name, status_str);
6284 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6285 "start_phy(%02d), count(%d)\n",
6286 le16_to_cpu(event_data->ExpanderDevHandle),
6287 le16_to_cpu(event_data->EnclosureHandle),
6288 event_data->StartPhyNum, event_data->NumEntries);
6289 for (i = 0; i < event_data->NumEntries; i++) {
6290 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
6293 phy_number = event_data->StartPhyNum + i;
6294 reason_code = event_data->PHY[i].PhyStatus &
6295 MPI2_EVENT_SAS_TOPO_RC_MASK;
6296 switch (reason_code) {
6297 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
6298 status_str = "target add";
6300 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
6301 status_str = "target remove";
6303 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
6304 status_str = "delay target remove";
6306 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
6307 status_str = "link rate change";
6309 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
6310 status_str = "target responding";
6313 status_str = "unknown";
6316 link_rate = event_data->PHY[i].LinkRate >> 4;
6317 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
6318 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6319 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
6320 handle, status_str, link_rate, prev_link_rate);
6326 * _scsih_sas_topology_change_event - handle topology changes
6327 * @ioc: per adapter object
6328 * @fw_event: The fw_event_work object
6333 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
6334 struct fw_event_work *fw_event)
6337 u16 parent_handle, handle;
6339 u8 phy_number, max_phys;
6340 struct _sas_node *sas_expander;
6342 unsigned long flags;
6343 u8 link_rate, prev_link_rate;
6344 Mpi2EventDataSasTopologyChangeList_t *event_data =
6345 (Mpi2EventDataSasTopologyChangeList_t *)
6346 fw_event->event_data;
6348 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6349 _scsih_sas_topology_change_event_debug(ioc, event_data);
6351 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
6354 if (!ioc->sas_hba.num_phys)
6355 _scsih_sas_host_add(ioc);
6357 _scsih_sas_host_refresh(ioc);
6359 if (fw_event->ignore) {
6360 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6361 "ignoring expander event\n", ioc->name));
6365 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
6367 /* handle expander add */
6368 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
6369 if (_scsih_expander_add(ioc, parent_handle) != 0)
6372 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6373 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
6376 sas_address = sas_expander->sas_address;
6377 max_phys = sas_expander->num_phys;
6378 } else if (parent_handle < ioc->sas_hba.num_phys) {
6379 sas_address = ioc->sas_hba.sas_address;
6380 max_phys = ioc->sas_hba.num_phys;
6382 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6385 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6387 /* handle siblings events */
6388 for (i = 0; i < event_data->NumEntries; i++) {
6389 if (fw_event->ignore) {
6390 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6391 "ignoring expander event\n", ioc->name));
6394 if (ioc->remove_host || ioc->pci_error_recovery)
6396 phy_number = event_data->StartPhyNum + i;
6397 if (phy_number >= max_phys)
6399 reason_code = event_data->PHY[i].PhyStatus &
6400 MPI2_EVENT_SAS_TOPO_RC_MASK;
6401 if ((event_data->PHY[i].PhyStatus &
6402 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
6403 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
6405 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
6408 link_rate = event_data->PHY[i].LinkRate >> 4;
6409 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
6410 switch (reason_code) {
6411 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
6413 if (ioc->shost_recovery)
6416 if (link_rate == prev_link_rate)
6419 mpt3sas_transport_update_links(ioc, sas_address,
6420 handle, phy_number, link_rate);
6422 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
6425 _scsih_check_device(ioc, sas_address, handle,
6426 phy_number, link_rate);
6428 if (!test_bit(handle, ioc->pend_os_device_add))
6433 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
6435 if (ioc->shost_recovery)
6438 mpt3sas_transport_update_links(ioc, sas_address,
6439 handle, phy_number, link_rate);
6441 _scsih_add_device(ioc, handle, phy_number, 0);
6444 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
6446 _scsih_device_remove_by_handle(ioc, handle);
6451 /* handle expander removal */
6452 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
6454 mpt3sas_expander_remove(ioc, sas_address);
6460 * _scsih_sas_device_status_change_event_debug - debug for device event
6462 * @event_data: event data payload
6466 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6467 Mpi2EventDataSasDeviceStatusChange_t *event_data)
6469 char *reason_str = NULL;
6471 switch (event_data->ReasonCode) {
6472 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
6473 reason_str = "smart data";
6475 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
6476 reason_str = "unsupported device discovered";
6478 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
6479 reason_str = "internal device reset";
6481 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
6482 reason_str = "internal task abort";
6484 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
6485 reason_str = "internal task abort set";
6487 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
6488 reason_str = "internal clear task set";
6490 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
6491 reason_str = "internal query task";
6493 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
6494 reason_str = "sata init failure";
6496 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
6497 reason_str = "internal device reset complete";
6499 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
6500 reason_str = "internal task abort complete";
6502 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
6503 reason_str = "internal async notification";
6505 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
6506 reason_str = "expander reduced functionality";
6508 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
6509 reason_str = "expander reduced functionality complete";
6512 reason_str = "unknown reason";
6515 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
6516 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6517 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
6518 (unsigned long long)le64_to_cpu(event_data->SASAddress),
6519 le16_to_cpu(event_data->TaskTag));
6520 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
6521 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
6522 event_data->ASC, event_data->ASCQ);
6527 * _scsih_sas_device_status_change_event - handle device status change
6528 * @ioc: per adapter object
6529 * @fw_event: The fw_event_work object
6533 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
6534 struct fw_event_work *fw_event)
6536 struct MPT3SAS_TARGET *target_priv_data;
6537 struct _sas_device *sas_device;
6539 unsigned long flags;
6540 Mpi2EventDataSasDeviceStatusChange_t *event_data =
6541 (Mpi2EventDataSasDeviceStatusChange_t *)
6542 fw_event->event_data;
6544 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6545 _scsih_sas_device_status_change_event_debug(ioc,
6548 /* In MPI Revision K (0xC), the internal device reset complete was
6549 * implemented, so avoid setting tm_busy flag for older firmware.
6551 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
6554 if (event_data->ReasonCode !=
6555 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
6556 event_data->ReasonCode !=
6557 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
6560 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6561 sas_address = le64_to_cpu(event_data->SASAddress);
6562 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
6565 if (!sas_device || !sas_device->starget)
6568 target_priv_data = sas_device->starget->hostdata;
6569 if (!target_priv_data)
6572 if (event_data->ReasonCode ==
6573 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
6574 target_priv_data->tm_busy = 1;
6576 target_priv_data->tm_busy = 0;
6580 sas_device_put(sas_device);
6582 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6587 * _scsih_check_pcie_access_status - check access flags
6588 * @ioc: per adapter object
6590 * @handle: sas device handle
6591 * @access_status: errors returned during discovery of the device
6593 * Return: 0 for success, else failure
6596 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6597 u16 handle, u8 access_status)
6602 switch (access_status) {
6603 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS:
6604 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION:
6607 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED:
6608 desc = "PCIe device capability failed";
6610 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED:
6611 desc = "PCIe device blocked";
6613 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED:
6614 desc = "PCIe device mem space access failed";
6616 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE:
6617 desc = "PCIe device unsupported";
6619 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED:
6620 desc = "PCIe device MSIx Required";
6622 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX:
6623 desc = "PCIe device init fail max";
6625 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN:
6626 desc = "PCIe device status unknown";
6628 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT:
6629 desc = "nvme ready timeout";
6631 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED:
6632 desc = "nvme device configuration unsupported";
6634 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED:
6635 desc = "nvme identify failed";
6637 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED:
6638 desc = "nvme qconfig failed";
6640 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED:
6641 desc = "nvme qcreation failed";
6643 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED:
6644 desc = "nvme eventcfg failed";
6646 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED:
6647 desc = "nvme get feature stat failed";
6649 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT:
6650 desc = "nvme idle timeout";
6652 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS:
6653 desc = "nvme failure status";
6657 " NVMe discovery error(0x%02x): wwid(0x%016llx),"
6658 "handle(0x%04x)\n", ioc->name, access_status,
6659 (unsigned long long)wwid, handle);
6667 "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6669 (unsigned long long)wwid, handle);
6674 * _scsih_pcie_device_remove_from_sml - removing pcie device
6675 * from SML and free up associated memory
6676 * @ioc: per adapter object
6677 * @pcie_device: the pcie_device object
6680 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
6681 struct _pcie_device *pcie_device)
6683 struct MPT3SAS_TARGET *sas_target_priv_data;
6685 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6686 "%s: enter: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
6687 pcie_device->handle, (unsigned long long)
6688 pcie_device->wwid));
6689 if (pcie_device->enclosure_handle != 0)
6690 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6691 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6692 ioc->name, __func__,
6693 (unsigned long long)pcie_device->enclosure_logical_id,
6694 pcie_device->slot));
6695 if (pcie_device->connector_name[0] != '\0')
6696 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6697 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
6698 ioc->name, __func__,
6699 pcie_device->enclosure_level,
6700 pcie_device->connector_name));
6702 if (pcie_device->starget && pcie_device->starget->hostdata) {
6703 sas_target_priv_data = pcie_device->starget->hostdata;
6704 sas_target_priv_data->deleted = 1;
6705 _scsih_ublock_io_device(ioc, pcie_device->wwid);
6706 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
6710 "removing handle(0x%04x), wwid (0x%016llx)\n",
6711 ioc->name, pcie_device->handle,
6712 (unsigned long long) pcie_device->wwid);
6713 if (pcie_device->enclosure_handle != 0)
6715 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6717 (unsigned long long)pcie_device->enclosure_logical_id,
6719 if (pcie_device->connector_name[0] != '\0')
6721 "removing: enclosure level(0x%04x), connector name( %s)\n",
6722 ioc->name, pcie_device->enclosure_level,
6723 pcie_device->connector_name);
6725 if (pcie_device->starget)
6726 scsi_remove_target(&pcie_device->starget->dev);
6727 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6728 "%s: exit: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
6729 pcie_device->handle, (unsigned long long)
6730 pcie_device->wwid));
6731 if (pcie_device->enclosure_handle != 0)
6732 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6733 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6734 ioc->name, __func__,
6735 (unsigned long long)pcie_device->enclosure_logical_id,
6736 pcie_device->slot));
6737 if (pcie_device->connector_name[0] != '\0')
6738 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6739 "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6740 ioc->name, __func__, pcie_device->enclosure_level,
6741 pcie_device->connector_name));
6743 kfree(pcie_device->serial_number);
6748 * _scsih_pcie_check_device - checking device responsiveness
6749 * @ioc: per adapter object
6750 * @handle: attached device handle
6753 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6755 Mpi2ConfigReply_t mpi_reply;
6756 Mpi26PCIeDevicePage0_t pcie_device_pg0;
6758 struct _pcie_device *pcie_device;
6760 unsigned long flags;
6761 struct scsi_target *starget;
6762 struct MPT3SAS_TARGET *sas_target_priv_data;
6765 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
6766 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
6769 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6770 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6773 /* check if this is end device */
6774 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
6775 if (!(_scsih_is_nvme_device(device_info)))
6778 wwid = le64_to_cpu(pcie_device_pg0.WWID);
6779 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
6780 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
6783 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6787 if (unlikely(pcie_device->handle != handle)) {
6788 starget = pcie_device->starget;
6789 sas_target_priv_data = starget->hostdata;
6790 starget_printk(KERN_INFO, starget,
6791 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6792 pcie_device->handle, handle);
6793 sas_target_priv_data->handle = handle;
6794 pcie_device->handle = handle;
6796 if (le32_to_cpu(pcie_device_pg0.Flags) &
6797 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
6798 pcie_device->enclosure_level =
6799 pcie_device_pg0.EnclosureLevel;
6800 memcpy(&pcie_device->connector_name[0],
6801 &pcie_device_pg0.ConnectorName[0], 4);
6803 pcie_device->enclosure_level = 0;
6804 pcie_device->connector_name[0] = '\0';
6808 /* check if device is present */
6809 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
6810 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
6812 "device is not present handle(0x%04x), flags!!!\n",
6814 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6815 pcie_device_put(pcie_device);
6819 /* check if there were any issues with discovery */
6820 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
6821 pcie_device_pg0.AccessStatus)) {
6822 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6823 pcie_device_put(pcie_device);
6827 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6828 pcie_device_put(pcie_device);
6830 _scsih_ublock_io_device(ioc, wwid);
6836 * _scsih_pcie_add_device - creating pcie device object
6837 * @ioc: per adapter object
6838 * @handle: pcie device handle
6840 * Creating end device object, stored in ioc->pcie_device_list.
6842 * Return: 1 means queue the event later, 0 means complete the event
6845 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6847 Mpi26PCIeDevicePage0_t pcie_device_pg0;
6848 Mpi26PCIeDevicePage2_t pcie_device_pg2;
6849 Mpi2ConfigReply_t mpi_reply;
6850 struct _pcie_device *pcie_device;
6851 struct _enclosure_node *enclosure_dev;
6855 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
6856 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
6857 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6858 ioc->name, __FILE__, __LINE__, __func__);
6861 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6862 MPI2_IOCSTATUS_MASK;
6863 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6865 "failure at %s:%d/%s()!\n",
6866 ioc->name, __FILE__, __LINE__, __func__);
6870 set_bit(handle, ioc->pend_os_device_add);
6871 wwid = le64_to_cpu(pcie_device_pg0.WWID);
6873 /* check if device is present */
6874 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
6875 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
6877 "device is not present handle(0x04%x)!!!\n",
6882 /* check if there were any issues with discovery */
6883 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
6884 pcie_device_pg0.AccessStatus))
6887 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo))))
6890 pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid);
6892 clear_bit(handle, ioc->pend_os_device_add);
6893 pcie_device_put(pcie_device);
6897 pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL);
6899 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6900 ioc->name, __FILE__, __LINE__, __func__);
6904 kref_init(&pcie_device->refcount);
6905 pcie_device->id = ioc->pcie_target_id++;
6906 pcie_device->channel = PCIE_CHANNEL;
6907 pcie_device->handle = handle;
6908 pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
6909 pcie_device->wwid = wwid;
6910 pcie_device->port_num = pcie_device_pg0.PortNum;
6911 pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) &
6912 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
6914 pcie_device->enclosure_handle =
6915 le16_to_cpu(pcie_device_pg0.EnclosureHandle);
6916 if (pcie_device->enclosure_handle != 0)
6917 pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot);
6919 if (le32_to_cpu(pcie_device_pg0.Flags) &
6920 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
6921 pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel;
6922 memcpy(&pcie_device->connector_name[0],
6923 &pcie_device_pg0.ConnectorName[0], 4);
6925 pcie_device->enclosure_level = 0;
6926 pcie_device->connector_name[0] = '\0';
6929 /* get enclosure_logical_id */
6930 if (pcie_device->enclosure_handle) {
6932 mpt3sas_scsih_enclosure_find_by_handle(ioc,
6933 pcie_device->enclosure_handle);
6935 pcie_device->enclosure_logical_id =
6936 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6938 /* TODO -- Add device name once FW supports it */
6939 if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply,
6940 &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) {
6941 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6942 ioc->name, __FILE__, __LINE__, __func__);
6947 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6948 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6949 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6950 ioc->name, __FILE__, __LINE__, __func__);
6954 pcie_device->nvme_mdts =
6955 le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize);
6956 if (pcie_device_pg2.ControllerResetTO)
6957 pcie_device->reset_timeout =
6958 pcie_device_pg2.ControllerResetTO;
6960 pcie_device->reset_timeout = 30;
6962 if (ioc->wait_for_discovery_to_complete)
6963 _scsih_pcie_device_init_add(ioc, pcie_device);
6965 _scsih_pcie_device_add(ioc, pcie_device);
6967 pcie_device_put(pcie_device);
6972 * _scsih_pcie_topology_change_event_debug - debug for topology
6974 * @ioc: per adapter object
6975 * @event_data: event data payload
6979 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6980 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
6986 char *status_str = NULL;
6987 u8 link_rate, prev_link_rate;
6989 switch (event_data->SwitchStatus) {
6990 case MPI26_EVENT_PCIE_TOPO_SS_ADDED:
6993 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
6994 status_str = "remove";
6996 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING:
6998 status_str = "responding";
7000 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
7001 status_str = "remove delay";
7004 status_str = "unknown status";
7007 pr_info(MPT3SAS_FMT "pcie topology change: (%s)\n",
7008 ioc->name, status_str);
7009 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
7010 "start_port(%02d), count(%d)\n",
7011 le16_to_cpu(event_data->SwitchDevHandle),
7012 le16_to_cpu(event_data->EnclosureHandle),
7013 event_data->StartPortNum, event_data->NumEntries);
7014 for (i = 0; i < event_data->NumEntries; i++) {
7016 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
7019 port_number = event_data->StartPortNum + i;
7020 reason_code = event_data->PortEntry[i].PortStatus;
7021 switch (reason_code) {
7022 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
7023 status_str = "target add";
7025 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
7026 status_str = "target remove";
7028 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
7029 status_str = "delay target remove";
7031 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
7032 status_str = "link rate change";
7034 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE:
7035 status_str = "target responding";
7038 status_str = "unknown";
7041 link_rate = event_data->PortEntry[i].CurrentPortInfo &
7042 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
7043 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo &
7044 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
7045 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
7046 " link rate: new(0x%02x), old(0x%02x)\n", port_number,
7047 handle, status_str, link_rate, prev_link_rate);
7052 * _scsih_pcie_topology_change_event - handle PCIe topology
7054 * @ioc: per adapter object
7055 * @fw_event: The fw_event_work object
7060 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
7061 struct fw_event_work *fw_event)
7066 u8 link_rate, prev_link_rate;
7067 unsigned long flags;
7069 Mpi26EventDataPCIeTopologyChangeList_t *event_data =
7070 (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data;
7071 struct _pcie_device *pcie_device;
7073 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7074 _scsih_pcie_topology_change_event_debug(ioc, event_data);
7076 if (ioc->shost_recovery || ioc->remove_host ||
7077 ioc->pci_error_recovery)
7080 if (fw_event->ignore) {
7081 dewtprintk(ioc, pr_info(MPT3SAS_FMT "ignoring switch event\n",
7086 /* handle siblings events */
7087 for (i = 0; i < event_data->NumEntries; i++) {
7088 if (fw_event->ignore) {
7089 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7090 "ignoring switch event\n", ioc->name));
7093 if (ioc->remove_host || ioc->pci_error_recovery)
7095 reason_code = event_data->PortEntry[i].PortStatus;
7097 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
7101 link_rate = event_data->PortEntry[i].CurrentPortInfo
7102 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
7103 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo
7104 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
7106 switch (reason_code) {
7107 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
7108 if (ioc->shost_recovery)
7110 if (link_rate == prev_link_rate)
7112 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
7115 _scsih_pcie_check_device(ioc, handle);
7117 /* This code after this point handles the test case
7118 * where a device has been added, however its returning
7119 * BUSY for sometime. Then before the Device Missing
7120 * Delay expires and the device becomes READY, the
7121 * device is removed and added back.
7123 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
7124 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
7125 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
7128 pcie_device_put(pcie_device);
7132 if (!test_bit(handle, ioc->pend_os_device_add))
7135 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7136 "handle(0x%04x) device not found: convert "
7137 "event to a device add\n", ioc->name, handle));
7138 event_data->PortEntry[i].PortStatus &= 0xF0;
7139 event_data->PortEntry[i].PortStatus |=
7140 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED;
7142 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
7143 if (ioc->shost_recovery)
7145 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
7148 rc = _scsih_pcie_add_device(ioc, handle);
7150 /* mark entry vacant */
7151 /* TODO This needs to be reviewed and fixed,
7152 * we dont have an entry
7153 * to make an event void like vacant
7155 event_data->PortEntry[i].PortStatus |=
7156 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE;
7159 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
7160 _scsih_pcie_device_remove_by_handle(ioc, handle);
7167 * _scsih_pcie_device_status_change_event_debug - debug for device event
7169 * @event_data: event data payload
7173 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7174 Mpi26EventDataPCIeDeviceStatusChange_t *event_data)
7176 char *reason_str = NULL;
7178 switch (event_data->ReasonCode) {
7179 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA:
7180 reason_str = "smart data";
7182 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED:
7183 reason_str = "unsupported device discovered";
7185 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET:
7186 reason_str = "internal device reset";
7188 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL:
7189 reason_str = "internal task abort";
7191 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
7192 reason_str = "internal task abort set";
7194 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
7195 reason_str = "internal clear task set";
7197 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL:
7198 reason_str = "internal query task";
7200 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE:
7201 reason_str = "device init failure";
7203 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
7204 reason_str = "internal device reset complete";
7206 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
7207 reason_str = "internal task abort complete";
7209 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION:
7210 reason_str = "internal async notification";
7212 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED:
7213 reason_str = "pcie hot reset failed";
7216 reason_str = "unknown reason";
7220 pr_info(MPT3SAS_FMT "PCIE device status change: (%s)\n"
7221 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7222 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
7223 (unsigned long long)le64_to_cpu(event_data->WWID),
7224 le16_to_cpu(event_data->TaskTag));
7225 if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA)
7226 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
7227 event_data->ASC, event_data->ASCQ);
7232 * _scsih_pcie_device_status_change_event - handle device status
7234 * @ioc: per adapter object
7235 * @fw_event: The fw_event_work object
7239 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7240 struct fw_event_work *fw_event)
7242 struct MPT3SAS_TARGET *target_priv_data;
7243 struct _pcie_device *pcie_device;
7245 unsigned long flags;
7246 Mpi26EventDataPCIeDeviceStatusChange_t *event_data =
7247 (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data;
7248 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7249 _scsih_pcie_device_status_change_event_debug(ioc,
7252 if (event_data->ReasonCode !=
7253 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET &&
7254 event_data->ReasonCode !=
7255 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
7258 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
7259 wwid = le64_to_cpu(event_data->WWID);
7260 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
7262 if (!pcie_device || !pcie_device->starget)
7265 target_priv_data = pcie_device->starget->hostdata;
7266 if (!target_priv_data)
7269 if (event_data->ReasonCode ==
7270 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET)
7271 target_priv_data->tm_busy = 1;
7273 target_priv_data->tm_busy = 0;
7276 pcie_device_put(pcie_device);
7278 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
7282 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7284 * @ioc: per adapter object
7285 * @event_data: event data payload
7289 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7290 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
7292 char *reason_str = NULL;
7294 switch (event_data->ReasonCode) {
7295 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
7296 reason_str = "enclosure add";
7298 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
7299 reason_str = "enclosure remove";
7302 reason_str = "unknown reason";
7306 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
7307 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
7308 " number slots(%d)\n", ioc->name, reason_str,
7309 le16_to_cpu(event_data->EnclosureHandle),
7310 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
7311 le16_to_cpu(event_data->StartSlot));
7315 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7316 * @ioc: per adapter object
7317 * @fw_event: The fw_event_work object
7321 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7322 struct fw_event_work *fw_event)
7324 Mpi2ConfigReply_t mpi_reply;
7325 struct _enclosure_node *enclosure_dev = NULL;
7326 Mpi2EventDataSasEnclDevStatusChange_t *event_data =
7327 (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data;
7329 u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle);
7331 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7332 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
7333 (Mpi2EventDataSasEnclDevStatusChange_t *)
7334 fw_event->event_data);
7335 if (ioc->shost_recovery)
7338 if (enclosure_handle)
7340 mpt3sas_scsih_enclosure_find_by_handle(ioc,
7342 switch (event_data->ReasonCode) {
7343 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
7344 if (!enclosure_dev) {
7346 kzalloc(sizeof(struct _enclosure_node),
7348 if (!enclosure_dev) {
7350 "failure at %s:%d/%s()!\n", ioc->name,
7351 __FILE__, __LINE__, __func__);
7354 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
7355 &enclosure_dev->pg0,
7356 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
7359 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
7360 MPI2_IOCSTATUS_MASK)) {
7361 kfree(enclosure_dev);
7365 list_add_tail(&enclosure_dev->list,
7366 &ioc->enclosure_list);
7369 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
7370 if (enclosure_dev) {
7371 list_del(&enclosure_dev->list);
7372 kfree(enclosure_dev);
7381 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7382 * @ioc: per adapter object
7383 * @fw_event: The fw_event_work object
7387 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
7388 struct fw_event_work *fw_event)
7390 struct scsi_cmnd *scmd;
7391 struct scsi_device *sdev;
7392 struct scsiio_tracker *st;
7395 struct MPT3SAS_DEVICE *sas_device_priv_data;
7396 u32 termination_count;
7398 Mpi2SCSITaskManagementReply_t *mpi_reply;
7399 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
7400 (Mpi2EventDataSasBroadcastPrimitive_t *)
7401 fw_event->event_data;
7403 unsigned long flags;
7406 u8 task_abort_retries;
7408 mutex_lock(&ioc->tm_cmds.mutex);
7410 "%s: enter: phy number(%d), width(%d)\n",
7411 ioc->name, __func__, event_data->PhyNum,
7412 event_data->PortWidth);
7414 _scsih_block_io_all_device(ioc);
7416 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7417 mpi_reply = ioc->tm_cmds.reply;
7418 broadcast_aen_retry:
7420 /* sanity checks for retrying this loop */
7421 if (max_retries++ == 5) {
7422 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
7423 ioc->name, __func__));
7425 } else if (max_retries > 1)
7426 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
7427 ioc->name, __func__, max_retries - 1));
7429 termination_count = 0;
7431 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
7432 if (ioc->shost_recovery)
7434 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
7437 st = scsi_cmd_priv(scmd);
7438 sdev = scmd->device;
7439 sas_device_priv_data = sdev->hostdata;
7440 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
7442 /* skip hidden raid components */
7443 if (sas_device_priv_data->sas_target->flags &
7444 MPT_TARGET_FLAGS_RAID_COMPONENT)
7447 if (sas_device_priv_data->sas_target->flags &
7448 MPT_TARGET_FLAGS_VOLUME)
7450 /* skip PCIe devices */
7451 if (sas_device_priv_data->sas_target->flags &
7452 MPT_TARGET_FLAGS_PCIE_DEVICE)
7455 handle = sas_device_priv_data->sas_target->handle;
7456 lun = sas_device_priv_data->lun;
7459 if (ioc->shost_recovery)
7462 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
7463 r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
7464 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
7465 st->msix_io, 30, 0);
7467 sdev_printk(KERN_WARNING, sdev,
7468 "mpt3sas_scsih_issue_tm: FAILED when sending "
7469 "QUERY_TASK: scmd(%p)\n", scmd);
7470 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7471 goto broadcast_aen_retry;
7473 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
7474 & MPI2_IOCSTATUS_MASK;
7475 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7476 sdev_printk(KERN_WARNING, sdev,
7477 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7479 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7480 goto broadcast_aen_retry;
7483 /* see if IO is still owned by IOC and target */
7484 if (mpi_reply->ResponseCode ==
7485 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
7486 mpi_reply->ResponseCode ==
7487 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
7488 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7491 task_abort_retries = 0;
7493 if (task_abort_retries++ == 60) {
7494 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7495 "%s: ABORT_TASK: giving up\n", ioc->name,
7497 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7498 goto broadcast_aen_retry;
7501 if (ioc->shost_recovery)
7504 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
7505 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid,
7506 st->msix_io, 30, 0);
7507 if (r == FAILED || st->cb_idx != 0xFF) {
7508 sdev_printk(KERN_WARNING, sdev,
7509 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7510 "scmd(%p)\n", scmd);
7514 if (task_abort_retries > 1)
7515 sdev_printk(KERN_WARNING, sdev,
7516 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7518 task_abort_retries - 1, scmd);
7520 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
7521 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7524 if (ioc->broadcast_aen_pending) {
7525 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7526 "%s: loop back due to pending AEN\n",
7527 ioc->name, __func__));
7528 ioc->broadcast_aen_pending = 0;
7529 goto broadcast_aen_retry;
7533 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
7536 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7537 "%s - exit, query_count = %d termination_count = %d\n",
7538 ioc->name, __func__, query_count, termination_count));
7540 ioc->broadcast_aen_busy = 0;
7541 if (!ioc->shost_recovery)
7542 _scsih_ublock_io_all_device(ioc);
7543 mutex_unlock(&ioc->tm_cmds.mutex);
7547 * _scsih_sas_discovery_event - handle discovery events
7548 * @ioc: per adapter object
7549 * @fw_event: The fw_event_work object
7553 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
7554 struct fw_event_work *fw_event)
7556 Mpi2EventDataSasDiscovery_t *event_data =
7557 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
7559 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
7560 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
7561 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
7563 if (event_data->DiscoveryStatus)
7564 pr_info("discovery_status(0x%08x)",
7565 le32_to_cpu(event_data->DiscoveryStatus));
7569 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
7570 !ioc->sas_hba.num_phys) {
7571 if (disable_discovery > 0 && ioc->shost_recovery) {
7572 /* Wait for the reset to complete */
7573 while (ioc->shost_recovery)
7576 _scsih_sas_host_add(ioc);
7581 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
7583 * @ioc: per adapter object
7584 * @fw_event: The fw_event_work object
7588 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc,
7589 struct fw_event_work *fw_event)
7591 Mpi25EventDataSasDeviceDiscoveryError_t *event_data =
7592 (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data;
7594 switch (event_data->ReasonCode) {
7595 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED:
7596 pr_warn(MPT3SAS_FMT "SMP command sent to the expander"
7597 "(handle:0x%04x, sas_address:0x%016llx,"
7598 "physical_port:0x%02x) has failed",
7599 ioc->name, le16_to_cpu(event_data->DevHandle),
7600 (unsigned long long)le64_to_cpu(event_data->SASAddress),
7601 event_data->PhysicalPort);
7603 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT:
7604 pr_warn(MPT3SAS_FMT "SMP command sent to the expander"
7605 "(handle:0x%04x, sas_address:0x%016llx,"
7606 "physical_port:0x%02x) has timed out",
7607 ioc->name, le16_to_cpu(event_data->DevHandle),
7608 (unsigned long long)le64_to_cpu(event_data->SASAddress),
7609 event_data->PhysicalPort);
7617 * _scsih_pcie_enumeration_event - handle enumeration events
7618 * @ioc: per adapter object
7619 * @fw_event: The fw_event_work object
7623 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc,
7624 struct fw_event_work *fw_event)
7626 Mpi26EventDataPCIeEnumeration_t *event_data =
7627 (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data;
7629 if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK))
7632 pr_info(MPT3SAS_FMT "pcie enumeration event: (%s) Flag 0x%02x",
7634 (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ?
7635 "started" : "completed",
7637 if (event_data->EnumerationStatus)
7638 pr_cont("enumeration_status(0x%08x)",
7639 le32_to_cpu(event_data->EnumerationStatus));
7644 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7645 * @ioc: per adapter object
7646 * @handle: device handle for physical disk
7647 * @phys_disk_num: physical disk number
7649 * Return: 0 for success, else failure.
7652 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
7654 Mpi2RaidActionRequest_t *mpi_request;
7655 Mpi2RaidActionReply_t *mpi_reply;
7662 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
7665 mutex_lock(&ioc->scsih_cmds.mutex);
7667 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7668 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7669 ioc->name, __func__);
7673 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7675 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7677 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7678 ioc->name, __func__);
7679 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7684 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7685 ioc->scsih_cmds.smid = smid;
7686 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7688 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7689 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
7690 mpi_request->PhysDiskNum = phys_disk_num;
7692 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
7693 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
7694 handle, phys_disk_num));
7696 init_completion(&ioc->scsih_cmds.done);
7697 mpt3sas_base_put_smid_default(ioc, smid);
7698 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7700 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7702 mpt3sas_base_check_cmd_timeout(ioc,
7703 ioc->scsih_cmds.status, mpi_request,
7704 sizeof(Mpi2RaidActionRequest_t)/4);
7709 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7711 mpi_reply = ioc->scsih_cmds.reply;
7712 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
7713 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
7714 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
7717 ioc_status &= MPI2_IOCSTATUS_MASK;
7718 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7719 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7720 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
7721 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
7725 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7726 "IR RAID_ACTION: completed successfully\n",
7731 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7732 mutex_unlock(&ioc->scsih_cmds.mutex);
7735 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
7740 * _scsih_reprobe_lun - reprobing lun
7741 * @sdev: scsi device struct
7742 * @no_uld_attach: sdev->no_uld_attach flag setting
7746 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
7748 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
7749 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
7750 sdev->no_uld_attach ? "hiding" : "exposing");
7751 WARN_ON(scsi_device_reprobe(sdev));
7755 * _scsih_sas_volume_add - add new volume
7756 * @ioc: per adapter object
7757 * @element: IR config element data
7761 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
7762 Mpi2EventIrConfigElement_t *element)
7764 struct _raid_device *raid_device;
7765 unsigned long flags;
7767 u16 handle = le16_to_cpu(element->VolDevHandle);
7770 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
7773 "failure at %s:%d/%s()!\n", ioc->name,
7774 __FILE__, __LINE__, __func__);
7778 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7779 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
7780 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7785 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
7788 "failure at %s:%d/%s()!\n", ioc->name,
7789 __FILE__, __LINE__, __func__);
7793 raid_device->id = ioc->sas_id++;
7794 raid_device->channel = RAID_CHANNEL;
7795 raid_device->handle = handle;
7796 raid_device->wwid = wwid;
7797 _scsih_raid_device_add(ioc, raid_device);
7798 if (!ioc->wait_for_discovery_to_complete) {
7799 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7800 raid_device->id, 0);
7802 _scsih_raid_device_remove(ioc, raid_device);
7804 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7805 _scsih_determine_boot_device(ioc, raid_device, 1);
7806 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7811 * _scsih_sas_volume_delete - delete volume
7812 * @ioc: per adapter object
7813 * @handle: volume device handle
7817 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
7819 struct _raid_device *raid_device;
7820 unsigned long flags;
7821 struct MPT3SAS_TARGET *sas_target_priv_data;
7822 struct scsi_target *starget = NULL;
7824 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7825 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
7827 if (raid_device->starget) {
7828 starget = raid_device->starget;
7829 sas_target_priv_data = starget->hostdata;
7830 sas_target_priv_data->deleted = 1;
7832 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7833 ioc->name, raid_device->handle,
7834 (unsigned long long) raid_device->wwid);
7835 list_del(&raid_device->list);
7838 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7840 scsi_remove_target(&starget->dev);
7844 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7845 * @ioc: per adapter object
7846 * @element: IR config element data
7850 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
7851 Mpi2EventIrConfigElement_t *element)
7853 struct _sas_device *sas_device;
7854 struct scsi_target *starget = NULL;
7855 struct MPT3SAS_TARGET *sas_target_priv_data;
7856 unsigned long flags;
7857 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7859 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7860 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
7862 sas_device->volume_handle = 0;
7863 sas_device->volume_wwid = 0;
7864 clear_bit(handle, ioc->pd_handles);
7865 if (sas_device->starget && sas_device->starget->hostdata) {
7866 starget = sas_device->starget;
7867 sas_target_priv_data = starget->hostdata;
7868 sas_target_priv_data->flags &=
7869 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
7872 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7876 /* exposing raid component */
7878 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
7880 sas_device_put(sas_device);
7884 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7885 * @ioc: per adapter object
7886 * @element: IR config element data
7890 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
7891 Mpi2EventIrConfigElement_t *element)
7893 struct _sas_device *sas_device;
7894 struct scsi_target *starget = NULL;
7895 struct MPT3SAS_TARGET *sas_target_priv_data;
7896 unsigned long flags;
7897 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7898 u16 volume_handle = 0;
7899 u64 volume_wwid = 0;
7901 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
7903 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
7906 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7907 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
7909 set_bit(handle, ioc->pd_handles);
7910 if (sas_device->starget && sas_device->starget->hostdata) {
7911 starget = sas_device->starget;
7912 sas_target_priv_data = starget->hostdata;
7913 sas_target_priv_data->flags |=
7914 MPT_TARGET_FLAGS_RAID_COMPONENT;
7915 sas_device->volume_handle = volume_handle;
7916 sas_device->volume_wwid = volume_wwid;
7919 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7923 /* hiding raid component */
7924 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7927 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
7929 sas_device_put(sas_device);
7933 * _scsih_sas_pd_delete - delete pd component
7934 * @ioc: per adapter object
7935 * @element: IR config element data
7939 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
7940 Mpi2EventIrConfigElement_t *element)
7942 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7944 _scsih_device_remove_by_handle(ioc, handle);
7948 * _scsih_sas_pd_add - remove pd component
7949 * @ioc: per adapter object
7950 * @element: IR config element data
7954 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
7955 Mpi2EventIrConfigElement_t *element)
7957 struct _sas_device *sas_device;
7958 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7959 Mpi2ConfigReply_t mpi_reply;
7960 Mpi2SasDevicePage0_t sas_device_pg0;
7965 set_bit(handle, ioc->pd_handles);
7967 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7969 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7970 sas_device_put(sas_device);
7974 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
7975 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
7976 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7977 ioc->name, __FILE__, __LINE__, __func__);
7981 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7982 MPI2_IOCSTATUS_MASK;
7983 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7984 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7985 ioc->name, __FILE__, __LINE__, __func__);
7989 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7990 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
7991 mpt3sas_transport_update_links(ioc, sas_address, handle,
7992 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7994 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7995 _scsih_add_device(ioc, handle, 0, 1);
7999 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
8000 * @ioc: per adapter object
8001 * @event_data: event data payload
8005 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
8006 Mpi2EventDataIrConfigChangeList_t *event_data)
8008 Mpi2EventIrConfigElement_t *element;
8011 char *reason_str = NULL, *element_str = NULL;
8013 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
8015 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
8016 ioc->name, (le32_to_cpu(event_data->Flags) &
8017 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
8018 "foreign" : "native", event_data->NumElements);
8019 for (i = 0; i < event_data->NumElements; i++, element++) {
8020 switch (element->ReasonCode) {
8021 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
8024 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
8025 reason_str = "remove";
8027 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
8028 reason_str = "no change";
8030 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
8031 reason_str = "hide";
8033 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
8034 reason_str = "unhide";
8036 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
8037 reason_str = "volume_created";
8039 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
8040 reason_str = "volume_deleted";
8042 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
8043 reason_str = "pd_created";
8045 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
8046 reason_str = "pd_deleted";
8049 reason_str = "unknown reason";
8052 element_type = le16_to_cpu(element->ElementFlags) &
8053 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
8054 switch (element_type) {
8055 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
8056 element_str = "volume";
8058 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
8059 element_str = "phys disk";
8061 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
8062 element_str = "hot spare";
8065 element_str = "unknown element";
8068 pr_info("\t(%s:%s), vol handle(0x%04x), " \
8069 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
8070 reason_str, le16_to_cpu(element->VolDevHandle),
8071 le16_to_cpu(element->PhysDiskDevHandle),
8072 element->PhysDiskNum);
8077 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8078 * @ioc: per adapter object
8079 * @fw_event: The fw_event_work object
8083 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
8084 struct fw_event_work *fw_event)
8086 Mpi2EventIrConfigElement_t *element;
8089 Mpi2EventDataIrConfigChangeList_t *event_data =
8090 (Mpi2EventDataIrConfigChangeList_t *)
8091 fw_event->event_data;
8093 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
8094 (!ioc->hide_ir_msg))
8095 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
8097 foreign_config = (le32_to_cpu(event_data->Flags) &
8098 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
8100 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
8101 if (ioc->shost_recovery &&
8102 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
8103 for (i = 0; i < event_data->NumElements; i++, element++) {
8104 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
8105 _scsih_ir_fastpath(ioc,
8106 le16_to_cpu(element->PhysDiskDevHandle),
8107 element->PhysDiskNum);
8112 for (i = 0; i < event_data->NumElements; i++, element++) {
8114 switch (element->ReasonCode) {
8115 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
8116 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
8117 if (!foreign_config)
8118 _scsih_sas_volume_add(ioc, element);
8120 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
8121 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
8122 if (!foreign_config)
8123 _scsih_sas_volume_delete(ioc,
8124 le16_to_cpu(element->VolDevHandle));
8126 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
8127 if (!ioc->is_warpdrive)
8128 _scsih_sas_pd_hide(ioc, element);
8130 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
8131 if (!ioc->is_warpdrive)
8132 _scsih_sas_pd_expose(ioc, element);
8134 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
8135 if (!ioc->is_warpdrive)
8136 _scsih_sas_pd_add(ioc, element);
8138 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
8139 if (!ioc->is_warpdrive)
8140 _scsih_sas_pd_delete(ioc, element);
8147 * _scsih_sas_ir_volume_event - IR volume event
8148 * @ioc: per adapter object
8149 * @fw_event: The fw_event_work object
8153 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
8154 struct fw_event_work *fw_event)
8157 unsigned long flags;
8158 struct _raid_device *raid_device;
8162 Mpi2EventDataIrVolume_t *event_data =
8163 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
8165 if (ioc->shost_recovery)
8168 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
8171 handle = le16_to_cpu(event_data->VolDevHandle);
8172 state = le32_to_cpu(event_data->NewValue);
8173 if (!ioc->hide_ir_msg)
8174 dewtprintk(ioc, pr_info(MPT3SAS_FMT
8175 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8176 ioc->name, __func__, handle,
8177 le32_to_cpu(event_data->PreviousValue), state));
8179 case MPI2_RAID_VOL_STATE_MISSING:
8180 case MPI2_RAID_VOL_STATE_FAILED:
8181 _scsih_sas_volume_delete(ioc, handle);
8184 case MPI2_RAID_VOL_STATE_ONLINE:
8185 case MPI2_RAID_VOL_STATE_DEGRADED:
8186 case MPI2_RAID_VOL_STATE_OPTIMAL:
8188 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8189 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
8190 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8195 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
8198 "failure at %s:%d/%s()!\n", ioc->name,
8199 __FILE__, __LINE__, __func__);
8203 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
8206 "failure at %s:%d/%s()!\n", ioc->name,
8207 __FILE__, __LINE__, __func__);
8211 raid_device->id = ioc->sas_id++;
8212 raid_device->channel = RAID_CHANNEL;
8213 raid_device->handle = handle;
8214 raid_device->wwid = wwid;
8215 _scsih_raid_device_add(ioc, raid_device);
8216 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8217 raid_device->id, 0);
8219 _scsih_raid_device_remove(ioc, raid_device);
8222 case MPI2_RAID_VOL_STATE_INITIALIZING:
8229 * _scsih_sas_ir_physical_disk_event - PD event
8230 * @ioc: per adapter object
8231 * @fw_event: The fw_event_work object
8235 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
8236 struct fw_event_work *fw_event)
8238 u16 handle, parent_handle;
8240 struct _sas_device *sas_device;
8241 Mpi2ConfigReply_t mpi_reply;
8242 Mpi2SasDevicePage0_t sas_device_pg0;
8244 Mpi2EventDataIrPhysicalDisk_t *event_data =
8245 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
8248 if (ioc->shost_recovery)
8251 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
8254 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
8255 state = le32_to_cpu(event_data->NewValue);
8257 if (!ioc->hide_ir_msg)
8258 dewtprintk(ioc, pr_info(MPT3SAS_FMT
8259 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8260 ioc->name, __func__, handle,
8261 le32_to_cpu(event_data->PreviousValue), state));
8264 case MPI2_RAID_PD_STATE_ONLINE:
8265 case MPI2_RAID_PD_STATE_DEGRADED:
8266 case MPI2_RAID_PD_STATE_REBUILDING:
8267 case MPI2_RAID_PD_STATE_OPTIMAL:
8268 case MPI2_RAID_PD_STATE_HOT_SPARE:
8270 if (!ioc->is_warpdrive)
8271 set_bit(handle, ioc->pd_handles);
8273 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
8275 sas_device_put(sas_device);
8279 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8280 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
8282 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8283 ioc->name, __FILE__, __LINE__, __func__);
8287 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8288 MPI2_IOCSTATUS_MASK;
8289 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8290 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8291 ioc->name, __FILE__, __LINE__, __func__);
8295 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
8296 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
8297 mpt3sas_transport_update_links(ioc, sas_address, handle,
8298 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
8300 _scsih_add_device(ioc, handle, 0, 1);
8304 case MPI2_RAID_PD_STATE_OFFLINE:
8305 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
8306 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
8313 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8314 * @ioc: per adapter object
8315 * @event_data: event data payload
8319 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
8320 Mpi2EventDataIrOperationStatus_t *event_data)
8322 char *reason_str = NULL;
8324 switch (event_data->RAIDOperation) {
8325 case MPI2_EVENT_IR_RAIDOP_RESYNC:
8326 reason_str = "resync";
8328 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
8329 reason_str = "online capacity expansion";
8331 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
8332 reason_str = "consistency check";
8334 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
8335 reason_str = "background init";
8337 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
8338 reason_str = "make data consistent";
8345 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
8346 "\thandle(0x%04x), percent complete(%d)\n",
8347 ioc->name, reason_str,
8348 le16_to_cpu(event_data->VolDevHandle),
8349 event_data->PercentComplete);
8353 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8354 * @ioc: per adapter object
8355 * @fw_event: The fw_event_work object
8359 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
8360 struct fw_event_work *fw_event)
8362 Mpi2EventDataIrOperationStatus_t *event_data =
8363 (Mpi2EventDataIrOperationStatus_t *)
8364 fw_event->event_data;
8365 static struct _raid_device *raid_device;
8366 unsigned long flags;
8369 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
8370 (!ioc->hide_ir_msg))
8371 _scsih_sas_ir_operation_status_event_debug(ioc,
8374 /* code added for raid transport support */
8375 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
8377 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8378 handle = le16_to_cpu(event_data->VolDevHandle);
8379 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
8381 raid_device->percent_complete =
8382 event_data->PercentComplete;
8383 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8388 * _scsih_prep_device_scan - initialize parameters prior to device scan
8389 * @ioc: per adapter object
8391 * Set the deleted flag prior to device scan. If the device is found during
8392 * the scan, then we clear the deleted flag.
8395 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
8397 struct MPT3SAS_DEVICE *sas_device_priv_data;
8398 struct scsi_device *sdev;
8400 shost_for_each_device(sdev, ioc->shost) {
8401 sas_device_priv_data = sdev->hostdata;
8402 if (sas_device_priv_data && sas_device_priv_data->sas_target)
8403 sas_device_priv_data->sas_target->deleted = 1;
8408 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8409 * @ioc: per adapter object
8410 * @sas_device_pg0: SAS Device page 0
8412 * After host reset, find out whether devices are still responding.
8413 * Used in _scsih_remove_unresponsive_sas_devices.
8416 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
8417 Mpi2SasDevicePage0_t *sas_device_pg0)
8419 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8420 struct scsi_target *starget;
8421 struct _sas_device *sas_device = NULL;
8422 struct _enclosure_node *enclosure_dev = NULL;
8423 unsigned long flags;
8425 if (sas_device_pg0->EnclosureHandle) {
8427 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8428 le16_to_cpu(sas_device_pg0->EnclosureHandle));
8429 if (enclosure_dev == NULL)
8430 pr_info(MPT3SAS_FMT "Enclosure handle(0x%04x)"
8431 "doesn't match with enclosure device!\n",
8432 ioc->name, sas_device_pg0->EnclosureHandle);
8434 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8435 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
8436 if ((sas_device->sas_address == le64_to_cpu(
8437 sas_device_pg0->SASAddress)) && (sas_device->slot ==
8438 le16_to_cpu(sas_device_pg0->Slot))) {
8439 sas_device->responding = 1;
8440 starget = sas_device->starget;
8441 if (starget && starget->hostdata) {
8442 sas_target_priv_data = starget->hostdata;
8443 sas_target_priv_data->tm_busy = 0;
8444 sas_target_priv_data->deleted = 0;
8446 sas_target_priv_data = NULL;
8448 starget_printk(KERN_INFO, starget,
8449 "handle(0x%04x), sas_addr(0x%016llx)\n",
8450 le16_to_cpu(sas_device_pg0->DevHandle),
8451 (unsigned long long)
8452 sas_device->sas_address);
8454 if (sas_device->enclosure_handle != 0)
8455 starget_printk(KERN_INFO, starget,
8456 "enclosure logical id(0x%016llx),"
8458 (unsigned long long)
8459 sas_device->enclosure_logical_id,
8462 if (le16_to_cpu(sas_device_pg0->Flags) &
8463 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
8464 sas_device->enclosure_level =
8465 sas_device_pg0->EnclosureLevel;
8466 memcpy(&sas_device->connector_name[0],
8467 &sas_device_pg0->ConnectorName[0], 4);
8469 sas_device->enclosure_level = 0;
8470 sas_device->connector_name[0] = '\0';
8473 sas_device->enclosure_handle =
8474 le16_to_cpu(sas_device_pg0->EnclosureHandle);
8475 sas_device->is_chassis_slot_valid = 0;
8476 if (enclosure_dev) {
8477 sas_device->enclosure_logical_id = le64_to_cpu(
8478 enclosure_dev->pg0.EnclosureLogicalID);
8479 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
8480 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
8481 sas_device->is_chassis_slot_valid = 1;
8482 sas_device->chassis_slot =
8483 enclosure_dev->pg0.ChassisSlot;
8487 if (sas_device->handle == le16_to_cpu(
8488 sas_device_pg0->DevHandle))
8490 pr_info("\thandle changed from(0x%04x)!!!\n",
8491 sas_device->handle);
8492 sas_device->handle = le16_to_cpu(
8493 sas_device_pg0->DevHandle);
8494 if (sas_target_priv_data)
8495 sas_target_priv_data->handle =
8496 le16_to_cpu(sas_device_pg0->DevHandle);
8501 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8505 * _scsih_create_enclosure_list_after_reset - Free Existing list,
8506 * And create enclosure list by scanning all Enclosure Page(0)s
8507 * @ioc: per adapter object
8510 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc)
8512 struct _enclosure_node *enclosure_dev;
8513 Mpi2ConfigReply_t mpi_reply;
8514 u16 enclosure_handle;
8517 /* Free existing enclosure list */
8518 mpt3sas_free_enclosure_list(ioc);
8520 /* Re constructing enclosure list after reset*/
8521 enclosure_handle = 0xFFFF;
8524 kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL);
8525 if (!enclosure_dev) {
8527 "failure at %s:%d/%s()!\n", ioc->name,
8528 __FILE__, __LINE__, __func__);
8531 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
8532 &enclosure_dev->pg0,
8533 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE,
8536 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
8537 MPI2_IOCSTATUS_MASK)) {
8538 kfree(enclosure_dev);
8541 list_add_tail(&enclosure_dev->list,
8542 &ioc->enclosure_list);
8544 le16_to_cpu(enclosure_dev->pg0.EnclosureHandle);
8549 * _scsih_search_responding_sas_devices -
8550 * @ioc: per adapter object
8552 * After host reset, find out whether devices are still responding.
8556 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
8558 Mpi2SasDevicePage0_t sas_device_pg0;
8559 Mpi2ConfigReply_t mpi_reply;
8564 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
8566 if (list_empty(&ioc->sas_device_list))
8570 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8571 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
8573 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8574 MPI2_IOCSTATUS_MASK;
8575 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8577 handle = le16_to_cpu(sas_device_pg0.DevHandle);
8578 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
8579 if (!(_scsih_is_end_device(device_info)))
8581 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
8585 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
8590 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8591 * @ioc: per adapter object
8592 * @pcie_device_pg0: PCIe Device page 0
8594 * After host reset, find out whether devices are still responding.
8595 * Used in _scsih_remove_unresponding_devices.
8598 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc,
8599 Mpi26PCIeDevicePage0_t *pcie_device_pg0)
8601 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8602 struct scsi_target *starget;
8603 struct _pcie_device *pcie_device;
8604 unsigned long flags;
8606 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8607 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
8608 if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID))
8609 && (pcie_device->slot == le16_to_cpu(
8610 pcie_device_pg0->Slot))) {
8611 pcie_device->responding = 1;
8612 starget = pcie_device->starget;
8613 if (starget && starget->hostdata) {
8614 sas_target_priv_data = starget->hostdata;
8615 sas_target_priv_data->tm_busy = 0;
8616 sas_target_priv_data->deleted = 0;
8618 sas_target_priv_data = NULL;
8620 starget_printk(KERN_INFO, starget,
8621 "handle(0x%04x), wwid(0x%016llx) ",
8622 pcie_device->handle,
8623 (unsigned long long)pcie_device->wwid);
8624 if (pcie_device->enclosure_handle != 0)
8625 starget_printk(KERN_INFO, starget,
8626 "enclosure logical id(0x%016llx), "
8628 (unsigned long long)
8629 pcie_device->enclosure_logical_id,
8633 if (((le32_to_cpu(pcie_device_pg0->Flags)) &
8634 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) &&
8635 (ioc->hba_mpi_version_belonged != MPI2_VERSION)) {
8636 pcie_device->enclosure_level =
8637 pcie_device_pg0->EnclosureLevel;
8638 memcpy(&pcie_device->connector_name[0],
8639 &pcie_device_pg0->ConnectorName[0], 4);
8641 pcie_device->enclosure_level = 0;
8642 pcie_device->connector_name[0] = '\0';
8645 if (pcie_device->handle == le16_to_cpu(
8646 pcie_device_pg0->DevHandle))
8648 pr_info("\thandle changed from(0x%04x)!!!\n",
8649 pcie_device->handle);
8650 pcie_device->handle = le16_to_cpu(
8651 pcie_device_pg0->DevHandle);
8652 if (sas_target_priv_data)
8653 sas_target_priv_data->handle =
8654 le16_to_cpu(pcie_device_pg0->DevHandle);
8660 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8664 * _scsih_search_responding_pcie_devices -
8665 * @ioc: per adapter object
8667 * After host reset, find out whether devices are still responding.
8671 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc)
8673 Mpi26PCIeDevicePage0_t pcie_device_pg0;
8674 Mpi2ConfigReply_t mpi_reply;
8679 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
8681 if (list_empty(&ioc->pcie_device_list))
8685 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
8686 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
8688 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8689 MPI2_IOCSTATUS_MASK;
8690 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8691 pr_info(MPT3SAS_FMT "\tbreak from %s: "
8692 "ioc_status(0x%04x), loginfo(0x%08x)\n", ioc->name,
8693 __func__, ioc_status,
8694 le32_to_cpu(mpi_reply.IOCLogInfo));
8697 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
8698 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
8699 if (!(_scsih_is_nvme_device(device_info)))
8701 _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0);
8704 pr_info(MPT3SAS_FMT "search for PCIe end-devices: complete\n",
8709 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8710 * @ioc: per adapter object
8711 * @wwid: world wide identifier for raid volume
8712 * @handle: device handle
8714 * After host reset, find out whether devices are still responding.
8715 * Used in _scsih_remove_unresponsive_raid_devices.
8718 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
8721 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8722 struct scsi_target *starget;
8723 struct _raid_device *raid_device;
8724 unsigned long flags;
8726 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8727 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
8728 if (raid_device->wwid == wwid && raid_device->starget) {
8729 starget = raid_device->starget;
8730 if (starget && starget->hostdata) {
8731 sas_target_priv_data = starget->hostdata;
8732 sas_target_priv_data->deleted = 0;
8734 sas_target_priv_data = NULL;
8735 raid_device->responding = 1;
8736 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8737 starget_printk(KERN_INFO, raid_device->starget,
8738 "handle(0x%04x), wwid(0x%016llx)\n", handle,
8739 (unsigned long long)raid_device->wwid);
8742 * WARPDRIVE: The handles of the PDs might have changed
8743 * across the host reset so re-initialize the
8744 * required data for Direct IO
8746 mpt3sas_init_warpdrive_properties(ioc, raid_device);
8747 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8748 if (raid_device->handle == handle) {
8749 spin_unlock_irqrestore(&ioc->raid_device_lock,
8753 pr_info("\thandle changed from(0x%04x)!!!\n",
8754 raid_device->handle);
8755 raid_device->handle = handle;
8756 if (sas_target_priv_data)
8757 sas_target_priv_data->handle = handle;
8758 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8762 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8766 * _scsih_search_responding_raid_devices -
8767 * @ioc: per adapter object
8769 * After host reset, find out whether devices are still responding.
8773 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
8775 Mpi2RaidVolPage1_t volume_pg1;
8776 Mpi2RaidVolPage0_t volume_pg0;
8777 Mpi2RaidPhysDiskPage0_t pd_pg0;
8778 Mpi2ConfigReply_t mpi_reply;
8783 if (!ioc->ir_firmware)
8786 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
8789 if (list_empty(&ioc->raid_device_list))
8793 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
8794 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
8795 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8796 MPI2_IOCSTATUS_MASK;
8797 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8799 handle = le16_to_cpu(volume_pg1.DevHandle);
8801 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
8802 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
8803 sizeof(Mpi2RaidVolPage0_t)))
8806 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
8807 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
8808 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
8809 _scsih_mark_responding_raid_device(ioc,
8810 le64_to_cpu(volume_pg1.WWID), handle);
8813 /* refresh the pd_handles */
8814 if (!ioc->is_warpdrive) {
8815 phys_disk_num = 0xFF;
8816 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
8817 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
8818 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
8820 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8821 MPI2_IOCSTATUS_MASK;
8822 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8824 phys_disk_num = pd_pg0.PhysDiskNum;
8825 handle = le16_to_cpu(pd_pg0.DevHandle);
8826 set_bit(handle, ioc->pd_handles);
8830 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
8835 * _scsih_mark_responding_expander - mark a expander as responding
8836 * @ioc: per adapter object
8837 * @expander_pg0:SAS Expander Config Page0
8839 * After host reset, find out whether devices are still responding.
8840 * Used in _scsih_remove_unresponsive_expanders.
8843 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc,
8844 Mpi2ExpanderPage0_t *expander_pg0)
8846 struct _sas_node *sas_expander = NULL;
8847 unsigned long flags;
8849 struct _enclosure_node *enclosure_dev = NULL;
8850 u16 handle = le16_to_cpu(expander_pg0->DevHandle);
8851 u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle);
8852 u64 sas_address = le64_to_cpu(expander_pg0->SASAddress);
8854 if (enclosure_handle)
8856 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8859 spin_lock_irqsave(&ioc->sas_node_lock, flags);
8860 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
8861 if (sas_expander->sas_address != sas_address)
8863 sas_expander->responding = 1;
8865 if (enclosure_dev) {
8866 sas_expander->enclosure_logical_id =
8867 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
8868 sas_expander->enclosure_handle =
8869 le16_to_cpu(expander_pg0->EnclosureHandle);
8872 if (sas_expander->handle == handle)
8874 pr_info("\texpander(0x%016llx): handle changed" \
8875 " from(0x%04x) to (0x%04x)!!!\n",
8876 (unsigned long long)sas_expander->sas_address,
8877 sas_expander->handle, handle);
8878 sas_expander->handle = handle;
8879 for (i = 0 ; i < sas_expander->num_phys ; i++)
8880 sas_expander->phy[i].handle = handle;
8884 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
8888 * _scsih_search_responding_expanders -
8889 * @ioc: per adapter object
8891 * After host reset, find out whether devices are still responding.
8895 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
8897 Mpi2ExpanderPage0_t expander_pg0;
8898 Mpi2ConfigReply_t mpi_reply;
8903 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
8905 if (list_empty(&ioc->sas_expander_list))
8909 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
8910 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
8912 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8913 MPI2_IOCSTATUS_MASK;
8914 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8917 handle = le16_to_cpu(expander_pg0.DevHandle);
8918 sas_address = le64_to_cpu(expander_pg0.SASAddress);
8919 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8921 (unsigned long long)sas_address);
8922 _scsih_mark_responding_expander(ioc, &expander_pg0);
8926 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
8930 * _scsih_remove_unresponding_devices - removing unresponding devices
8931 * @ioc: per adapter object
8934 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc)
8936 struct _sas_device *sas_device, *sas_device_next;
8937 struct _sas_node *sas_expander, *sas_expander_next;
8938 struct _raid_device *raid_device, *raid_device_next;
8939 struct _pcie_device *pcie_device, *pcie_device_next;
8940 struct list_head tmp_list;
8941 unsigned long flags;
8944 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
8947 /* removing unresponding end devices */
8948 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
8951 * Iterate, pulling off devices marked as non-responding. We become the
8952 * owner for the reference the list had on any object we prune.
8954 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8955 list_for_each_entry_safe(sas_device, sas_device_next,
8956 &ioc->sas_device_list, list) {
8957 if (!sas_device->responding)
8958 list_move_tail(&sas_device->list, &head);
8960 sas_device->responding = 0;
8962 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8965 * Now, uninitialize and remove the unresponding devices we pruned.
8967 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
8968 _scsih_remove_device(ioc, sas_device);
8969 list_del_init(&sas_device->list);
8970 sas_device_put(sas_device);
8974 " Removing unresponding devices: pcie end-devices\n"
8976 INIT_LIST_HEAD(&head);
8977 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8978 list_for_each_entry_safe(pcie_device, pcie_device_next,
8979 &ioc->pcie_device_list, list) {
8980 if (!pcie_device->responding)
8981 list_move_tail(&pcie_device->list, &head);
8983 pcie_device->responding = 0;
8985 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8987 list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) {
8988 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
8989 list_del_init(&pcie_device->list);
8990 pcie_device_put(pcie_device);
8993 /* removing unresponding volumes */
8994 if (ioc->ir_firmware) {
8995 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
8997 list_for_each_entry_safe(raid_device, raid_device_next,
8998 &ioc->raid_device_list, list) {
8999 if (!raid_device->responding)
9000 _scsih_sas_volume_delete(ioc,
9001 raid_device->handle);
9003 raid_device->responding = 0;
9007 /* removing unresponding expanders */
9008 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
9010 spin_lock_irqsave(&ioc->sas_node_lock, flags);
9011 INIT_LIST_HEAD(&tmp_list);
9012 list_for_each_entry_safe(sas_expander, sas_expander_next,
9013 &ioc->sas_expander_list, list) {
9014 if (!sas_expander->responding)
9015 list_move_tail(&sas_expander->list, &tmp_list);
9017 sas_expander->responding = 0;
9019 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
9020 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
9022 _scsih_expander_node_remove(ioc, sas_expander);
9025 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
9028 /* unblock devices */
9029 _scsih_ublock_io_all_device(ioc);
9033 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
9034 struct _sas_node *sas_expander, u16 handle)
9036 Mpi2ExpanderPage1_t expander_pg1;
9037 Mpi2ConfigReply_t mpi_reply;
9040 for (i = 0 ; i < sas_expander->num_phys ; i++) {
9041 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
9042 &expander_pg1, i, handle))) {
9043 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
9044 ioc->name, __FILE__, __LINE__, __func__);
9048 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
9049 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
9050 expander_pg1.NegotiatedLinkRate >> 4);
9055 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
9056 * @ioc: per adapter object
9059 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
9061 Mpi2ExpanderPage0_t expander_pg0;
9062 Mpi2SasDevicePage0_t sas_device_pg0;
9063 Mpi26PCIeDevicePage0_t pcie_device_pg0;
9064 Mpi2RaidVolPage1_t volume_pg1;
9065 Mpi2RaidVolPage0_t volume_pg0;
9066 Mpi2RaidPhysDiskPage0_t pd_pg0;
9067 Mpi2EventIrConfigElement_t element;
9068 Mpi2ConfigReply_t mpi_reply;
9071 u16 handle, parent_handle;
9073 struct _sas_device *sas_device;
9074 struct _pcie_device *pcie_device;
9075 struct _sas_node *expander_device;
9076 static struct _raid_device *raid_device;
9078 unsigned long flags;
9080 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
9082 _scsih_sas_host_refresh(ioc);
9084 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
9088 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
9089 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
9090 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9091 MPI2_IOCSTATUS_MASK;
9092 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9093 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
9094 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9095 ioc->name, ioc_status,
9096 le32_to_cpu(mpi_reply.IOCLogInfo));
9099 handle = le16_to_cpu(expander_pg0.DevHandle);
9100 spin_lock_irqsave(&ioc->sas_node_lock, flags);
9101 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
9102 ioc, le64_to_cpu(expander_pg0.SASAddress));
9103 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
9104 if (expander_device)
9105 _scsih_refresh_expander_links(ioc, expander_device,
9108 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
9109 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9110 handle, (unsigned long long)
9111 le64_to_cpu(expander_pg0.SASAddress));
9112 _scsih_expander_add(ioc, handle);
9113 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
9114 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9115 handle, (unsigned long long)
9116 le64_to_cpu(expander_pg0.SASAddress));
9120 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
9123 if (!ioc->ir_firmware)
9126 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
9129 phys_disk_num = 0xFF;
9130 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
9131 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
9133 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9134 MPI2_IOCSTATUS_MASK;
9135 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9136 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
9137 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9138 ioc->name, ioc_status,
9139 le32_to_cpu(mpi_reply.IOCLogInfo));
9142 phys_disk_num = pd_pg0.PhysDiskNum;
9143 handle = le16_to_cpu(pd_pg0.DevHandle);
9144 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
9146 sas_device_put(sas_device);
9149 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9150 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
9153 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9154 MPI2_IOCSTATUS_MASK;
9155 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9156 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
9157 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9158 ioc->name, ioc_status,
9159 le32_to_cpu(mpi_reply.IOCLogInfo));
9162 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9163 if (!_scsih_get_sas_address(ioc, parent_handle,
9165 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
9166 " handle (0x%04x), sas_addr(0x%016llx)\n",
9167 ioc->name, handle, (unsigned long long)
9168 le64_to_cpu(sas_device_pg0.SASAddress));
9169 mpt3sas_transport_update_links(ioc, sas_address,
9170 handle, sas_device_pg0.PhyNum,
9171 MPI2_SAS_NEG_LINK_RATE_1_5);
9172 set_bit(handle, ioc->pd_handles);
9174 /* This will retry adding the end device.
9175 * _scsih_add_device() will decide on retries and
9176 * return "1" when it should be retried
9178 while (_scsih_add_device(ioc, handle, retry_count++,
9182 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
9183 " handle (0x%04x), sas_addr(0x%016llx)\n",
9184 ioc->name, handle, (unsigned long long)
9185 le64_to_cpu(sas_device_pg0.SASAddress));
9189 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
9192 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
9196 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
9197 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
9198 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9199 MPI2_IOCSTATUS_MASK;
9200 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9201 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
9202 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9203 ioc->name, ioc_status,
9204 le32_to_cpu(mpi_reply.IOCLogInfo));
9207 handle = le16_to_cpu(volume_pg1.DevHandle);
9208 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9209 raid_device = _scsih_raid_device_find_by_wwid(ioc,
9210 le64_to_cpu(volume_pg1.WWID));
9211 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9214 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
9215 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
9216 sizeof(Mpi2RaidVolPage0_t)))
9218 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9219 MPI2_IOCSTATUS_MASK;
9220 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9221 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
9222 "ioc_status(0x%04x), loginfo(0x%08x)\n",
9223 ioc->name, ioc_status,
9224 le32_to_cpu(mpi_reply.IOCLogInfo));
9227 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
9228 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
9229 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
9230 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
9231 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
9232 element.VolDevHandle = volume_pg1.DevHandle;
9234 "\tBEFORE adding volume: handle (0x%04x)\n",
9235 ioc->name, volume_pg1.DevHandle);
9236 _scsih_sas_volume_add(ioc, &element);
9238 "\tAFTER adding volume: handle (0x%04x)\n",
9239 ioc->name, volume_pg1.DevHandle);
9243 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
9248 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
9253 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9254 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9256 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9257 MPI2_IOCSTATUS_MASK;
9258 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9259 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
9260 " ioc_status(0x%04x), loginfo(0x%08x)\n",
9261 ioc->name, ioc_status,
9262 le32_to_cpu(mpi_reply.IOCLogInfo));
9265 handle = le16_to_cpu(sas_device_pg0.DevHandle);
9266 if (!(_scsih_is_end_device(
9267 le32_to_cpu(sas_device_pg0.DeviceInfo))))
9269 sas_device = mpt3sas_get_sdev_by_addr(ioc,
9270 le64_to_cpu(sas_device_pg0.SASAddress));
9272 sas_device_put(sas_device);
9275 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9276 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
9277 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
9278 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9279 handle, (unsigned long long)
9280 le64_to_cpu(sas_device_pg0.SASAddress));
9281 mpt3sas_transport_update_links(ioc, sas_address, handle,
9282 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
9284 /* This will retry adding the end device.
9285 * _scsih_add_device() will decide on retries and
9286 * return "1" when it should be retried
9288 while (_scsih_add_device(ioc, handle, retry_count++,
9292 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
9293 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
9294 handle, (unsigned long long)
9295 le64_to_cpu(sas_device_pg0.SASAddress));
9298 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
9300 pr_info(MPT3SAS_FMT "\tscan devices: pcie end devices start\n",
9305 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
9306 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9308 ioc_status = le16_to_cpu(mpi_reply.IOCStatus)
9309 & MPI2_IOCSTATUS_MASK;
9310 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9311 pr_info(MPT3SAS_FMT "\tbreak from pcie end device"
9312 " scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9313 ioc->name, ioc_status,
9314 le32_to_cpu(mpi_reply.IOCLogInfo));
9317 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
9318 if (!(_scsih_is_nvme_device(
9319 le32_to_cpu(pcie_device_pg0.DeviceInfo))))
9321 pcie_device = mpt3sas_get_pdev_by_wwid(ioc,
9322 le64_to_cpu(pcie_device_pg0.WWID));
9324 pcie_device_put(pcie_device);
9328 parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle);
9329 _scsih_pcie_add_device(ioc, handle);
9331 pr_info(MPT3SAS_FMT "\tAFTER adding pcie end device: "
9332 "handle (0x%04x), wwid(0x%016llx)\n", ioc->name,
9334 (unsigned long long) le64_to_cpu(pcie_device_pg0.WWID));
9336 pr_info(MPT3SAS_FMT "\tpcie devices: pcie end devices complete\n",
9338 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
9342 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9343 * @ioc: per adapter object
9345 * The handler for doing any required cleanup or initialization.
9347 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
9349 dtmprintk(ioc, pr_info(MPT3SAS_FMT
9350 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
9354 * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
9355 * @ioc: per adapter object
9357 * The handler for doing any required cleanup or initialization.
9360 mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER *ioc)
9362 dtmprintk(ioc, pr_info(MPT3SAS_FMT
9363 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
9364 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
9365 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
9366 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
9367 complete(&ioc->scsih_cmds.done);
9369 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
9370 ioc->tm_cmds.status |= MPT3_CMD_RESET;
9371 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
9372 complete(&ioc->tm_cmds.done);
9375 memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
9376 memset(ioc->device_remove_in_progress, 0,
9377 ioc->device_remove_in_progress_sz);
9378 _scsih_fw_event_cleanup_queue(ioc);
9379 _scsih_flush_running_cmds(ioc);
9383 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9384 * @ioc: per adapter object
9386 * The handler for doing any required cleanup or initialization.
9389 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
9391 dtmprintk(ioc, pr_info(MPT3SAS_FMT
9392 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
9393 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
9394 !ioc->sas_hba.num_phys)) {
9395 _scsih_prep_device_scan(ioc);
9396 _scsih_create_enclosure_list_after_reset(ioc);
9397 _scsih_search_responding_sas_devices(ioc);
9398 _scsih_search_responding_pcie_devices(ioc);
9399 _scsih_search_responding_raid_devices(ioc);
9400 _scsih_search_responding_expanders(ioc);
9401 _scsih_error_recovery_delete_devices(ioc);
9406 * _mpt3sas_fw_work - delayed task for processing firmware events
9407 * @ioc: per adapter object
9408 * @fw_event: The fw_event_work object
9412 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
9414 _scsih_fw_event_del_from_list(ioc, fw_event);
9416 /* the queue is being flushed so ignore this event */
9417 if (ioc->remove_host || ioc->pci_error_recovery) {
9418 fw_event_work_put(fw_event);
9422 switch (fw_event->event) {
9423 case MPT3SAS_PROCESS_TRIGGER_DIAG:
9424 mpt3sas_process_trigger_data(ioc,
9425 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
9426 fw_event->event_data);
9428 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
9429 while (scsi_host_in_recovery(ioc->shost) ||
9430 ioc->shost_recovery) {
9432 * If we're unloading, bail. Otherwise, this can become
9435 if (ioc->remove_host)
9439 _scsih_remove_unresponding_devices(ioc);
9440 _scsih_scan_for_devices_after_reset(ioc);
9442 case MPT3SAS_PORT_ENABLE_COMPLETE:
9443 ioc->start_scan = 0;
9444 if (missing_delay[0] != -1 && missing_delay[1] != -1)
9445 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
9447 dewtprintk(ioc, pr_info(MPT3SAS_FMT
9448 "port enable: complete from worker thread\n",
9451 case MPT3SAS_TURN_ON_PFA_LED:
9452 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
9454 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
9455 _scsih_sas_topology_change_event(ioc, fw_event);
9457 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
9458 _scsih_sas_device_status_change_event(ioc, fw_event);
9460 case MPI2_EVENT_SAS_DISCOVERY:
9461 _scsih_sas_discovery_event(ioc, fw_event);
9463 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
9464 _scsih_sas_device_discovery_error_event(ioc, fw_event);
9466 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
9467 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
9469 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
9470 _scsih_sas_enclosure_dev_status_change_event(ioc,
9473 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
9474 _scsih_sas_ir_config_change_event(ioc, fw_event);
9476 case MPI2_EVENT_IR_VOLUME:
9477 _scsih_sas_ir_volume_event(ioc, fw_event);
9479 case MPI2_EVENT_IR_PHYSICAL_DISK:
9480 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
9482 case MPI2_EVENT_IR_OPERATION_STATUS:
9483 _scsih_sas_ir_operation_status_event(ioc, fw_event);
9485 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
9486 _scsih_pcie_device_status_change_event(ioc, fw_event);
9488 case MPI2_EVENT_PCIE_ENUMERATION:
9489 _scsih_pcie_enumeration_event(ioc, fw_event);
9491 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
9492 _scsih_pcie_topology_change_event(ioc, fw_event);
9497 fw_event_work_put(fw_event);
9501 * _firmware_event_work
9502 * @work: The fw_event_work object
9505 * wrappers for the work thread handling firmware events
9509 _firmware_event_work(struct work_struct *work)
9511 struct fw_event_work *fw_event = container_of(work,
9512 struct fw_event_work, work);
9514 _mpt3sas_fw_work(fw_event->ioc, fw_event);
9518 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9519 * @ioc: per adapter object
9520 * @msix_index: MSIX table index supplied by the OS
9521 * @reply: reply message frame(lower 32bit addr)
9522 * Context: interrupt.
9524 * This function merely adds a new work task into ioc->firmware_event_thread.
9525 * The tasks are worked from _firmware_event_work in user context.
9527 * Return: 1 meaning mf should be freed from _base_interrupt
9528 * 0 means the mf is freed from this function.
9531 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
9534 struct fw_event_work *fw_event;
9535 Mpi2EventNotificationReply_t *mpi_reply;
9538 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
9540 /* events turned off due to host reset */
9541 if (ioc->pci_error_recovery)
9544 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
9546 if (unlikely(!mpi_reply)) {
9547 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
9548 ioc->name, __FILE__, __LINE__, __func__);
9552 event = le16_to_cpu(mpi_reply->Event);
9554 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
9555 mpt3sas_trigger_event(ioc, event, 0);
9559 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
9561 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
9562 (Mpi2EventDataSasBroadcastPrimitive_t *)
9563 mpi_reply->EventData;
9565 if (baen_data->Primitive !=
9566 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
9569 if (ioc->broadcast_aen_busy) {
9570 ioc->broadcast_aen_pending++;
9573 ioc->broadcast_aen_busy = 1;
9577 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
9578 _scsih_check_topo_delete_events(ioc,
9579 (Mpi2EventDataSasTopologyChangeList_t *)
9580 mpi_reply->EventData);
9582 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
9583 _scsih_check_pcie_topo_remove_events(ioc,
9584 (Mpi26EventDataPCIeTopologyChangeList_t *)
9585 mpi_reply->EventData);
9587 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
9588 _scsih_check_ir_config_unhide_events(ioc,
9589 (Mpi2EventDataIrConfigChangeList_t *)
9590 mpi_reply->EventData);
9592 case MPI2_EVENT_IR_VOLUME:
9593 _scsih_check_volume_delete_events(ioc,
9594 (Mpi2EventDataIrVolume_t *)
9595 mpi_reply->EventData);
9597 case MPI2_EVENT_LOG_ENTRY_ADDED:
9599 Mpi2EventDataLogEntryAdded_t *log_entry;
9602 if (!ioc->is_warpdrive)
9605 log_entry = (Mpi2EventDataLogEntryAdded_t *)
9606 mpi_reply->EventData;
9607 log_code = (u32 *)log_entry->LogData;
9609 if (le16_to_cpu(log_entry->LogEntryQualifier)
9610 != MPT2_WARPDRIVE_LOGENTRY)
9613 switch (le32_to_cpu(*log_code)) {
9614 case MPT2_WARPDRIVE_LC_SSDT:
9615 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
9616 "IO Throttling has occurred in the WarpDrive "
9617 "subsystem. Check WarpDrive documentation for "
9618 "additional details.\n", ioc->name);
9620 case MPT2_WARPDRIVE_LC_SSDLW:
9621 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
9622 "Program/Erase Cycles for the WarpDrive subsystem "
9623 "in degraded range. Check WarpDrive documentation "
9624 "for additional details.\n", ioc->name);
9626 case MPT2_WARPDRIVE_LC_SSDLF:
9627 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
9628 "There are no Program/Erase Cycles for the "
9629 "WarpDrive subsystem. The storage device will be "
9630 "in read-only mode. Check WarpDrive documentation "
9631 "for additional details.\n", ioc->name);
9633 case MPT2_WARPDRIVE_LC_BRMF:
9634 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
9635 "The Backup Rail Monitor has failed on the "
9636 "WarpDrive subsystem. Check WarpDrive "
9637 "documentation for additional details.\n",
9644 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
9645 case MPI2_EVENT_IR_OPERATION_STATUS:
9646 case MPI2_EVENT_SAS_DISCOVERY:
9647 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
9648 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
9649 case MPI2_EVENT_IR_PHYSICAL_DISK:
9650 case MPI2_EVENT_PCIE_ENUMERATION:
9651 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
9654 case MPI2_EVENT_TEMP_THRESHOLD:
9655 _scsih_temp_threshold_events(ioc,
9656 (Mpi2EventDataTemperature_t *)
9657 mpi_reply->EventData);
9659 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
9660 ActiveCableEventData =
9661 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
9662 switch (ActiveCableEventData->ReasonCode) {
9663 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
9664 pr_notice(MPT3SAS_FMT
9665 "Currently an active cable with ReceptacleID %d\n",
9666 ioc->name, ActiveCableEventData->ReceptacleID);
9667 pr_notice("cannot be powered and devices connected\n");
9668 pr_notice("to this active cable will not be seen\n");
9669 pr_notice("This active cable requires %d mW of power\n",
9670 ActiveCableEventData->ActiveCablePowerRequirement);
9673 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
9674 pr_notice(MPT3SAS_FMT
9675 "Currently a cable with ReceptacleID %d\n",
9676 ioc->name, ActiveCableEventData->ReceptacleID);
9678 "is not running at optimal speed(12 Gb/s rate)\n");
9684 default: /* ignore the rest */
9688 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
9689 fw_event = alloc_fw_event_work(sz);
9691 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
9692 ioc->name, __FILE__, __LINE__, __func__);
9696 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
9697 fw_event->ioc = ioc;
9698 fw_event->VF_ID = mpi_reply->VF_ID;
9699 fw_event->VP_ID = mpi_reply->VP_ID;
9700 fw_event->event = event;
9701 _scsih_fw_event_add(ioc, fw_event);
9702 fw_event_work_put(fw_event);
9707 * _scsih_expander_node_remove - removing expander device from list.
9708 * @ioc: per adapter object
9709 * @sas_expander: the sas_device object
9711 * Removing object and freeing associated memory from the
9712 * ioc->sas_expander_list.
9715 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
9716 struct _sas_node *sas_expander)
9718 struct _sas_port *mpt3sas_port, *next;
9719 unsigned long flags;
9721 /* remove sibling ports attached to this expander */
9722 list_for_each_entry_safe(mpt3sas_port, next,
9723 &sas_expander->sas_port_list, port_list) {
9724 if (ioc->shost_recovery)
9726 if (mpt3sas_port->remote_identify.device_type ==
9728 mpt3sas_device_remove_by_sas_address(ioc,
9729 mpt3sas_port->remote_identify.sas_address);
9730 else if (mpt3sas_port->remote_identify.device_type ==
9731 SAS_EDGE_EXPANDER_DEVICE ||
9732 mpt3sas_port->remote_identify.device_type ==
9733 SAS_FANOUT_EXPANDER_DEVICE)
9734 mpt3sas_expander_remove(ioc,
9735 mpt3sas_port->remote_identify.sas_address);
9738 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
9739 sas_expander->sas_address_parent);
9742 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9744 sas_expander->handle, (unsigned long long)
9745 sas_expander->sas_address);
9747 spin_lock_irqsave(&ioc->sas_node_lock, flags);
9748 list_del(&sas_expander->list);
9749 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
9751 kfree(sas_expander->phy);
9752 kfree(sas_expander);
9756 * _scsih_ir_shutdown - IR shutdown notification
9757 * @ioc: per adapter object
9759 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9760 * the host system is shutting down.
9763 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
9765 Mpi2RaidActionRequest_t *mpi_request;
9766 Mpi2RaidActionReply_t *mpi_reply;
9769 /* is IR firmware build loaded ? */
9770 if (!ioc->ir_firmware)
9773 /* are there any volumes ? */
9774 if (list_empty(&ioc->raid_device_list))
9777 mutex_lock(&ioc->scsih_cmds.mutex);
9779 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
9780 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
9781 ioc->name, __func__);
9784 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
9786 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
9788 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
9789 ioc->name, __func__);
9790 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
9794 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
9795 ioc->scsih_cmds.smid = smid;
9796 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
9798 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
9799 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
9801 if (!ioc->hide_ir_msg)
9802 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
9803 init_completion(&ioc->scsih_cmds.done);
9804 mpt3sas_base_put_smid_default(ioc, smid);
9805 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
9807 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
9808 pr_err(MPT3SAS_FMT "%s: timeout\n",
9809 ioc->name, __func__);
9813 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
9814 mpi_reply = ioc->scsih_cmds.reply;
9815 if (!ioc->hide_ir_msg)
9816 pr_info(MPT3SAS_FMT "IR shutdown "
9817 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9818 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
9819 le32_to_cpu(mpi_reply->IOCLogInfo));
9823 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
9824 mutex_unlock(&ioc->scsih_cmds.mutex);
9828 * scsih_remove - detach and remove add host
9829 * @pdev: PCI device struct
9831 * Routine called when unloading the driver.
9833 static void scsih_remove(struct pci_dev *pdev)
9835 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9836 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9837 struct _sas_port *mpt3sas_port, *next_port;
9838 struct _raid_device *raid_device, *next;
9839 struct MPT3SAS_TARGET *sas_target_priv_data;
9840 struct _pcie_device *pcie_device, *pcienext;
9841 struct workqueue_struct *wq;
9842 unsigned long flags;
9844 ioc->remove_host = 1;
9846 if (!pci_device_is_present(pdev))
9847 _scsih_flush_running_cmds(ioc);
9849 _scsih_fw_event_cleanup_queue(ioc);
9851 spin_lock_irqsave(&ioc->fw_event_lock, flags);
9852 wq = ioc->firmware_event_thread;
9853 ioc->firmware_event_thread = NULL;
9854 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
9856 destroy_workqueue(wq);
9858 /* release all the volumes */
9859 _scsih_ir_shutdown(ioc);
9860 sas_remove_host(shost);
9861 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
9863 if (raid_device->starget) {
9864 sas_target_priv_data =
9865 raid_device->starget->hostdata;
9866 sas_target_priv_data->deleted = 1;
9867 scsi_remove_target(&raid_device->starget->dev);
9869 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
9870 ioc->name, raid_device->handle,
9871 (unsigned long long) raid_device->wwid);
9872 _scsih_raid_device_remove(ioc, raid_device);
9874 list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list,
9876 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
9877 list_del_init(&pcie_device->list);
9878 pcie_device_put(pcie_device);
9881 /* free ports attached to the sas_host */
9882 list_for_each_entry_safe(mpt3sas_port, next_port,
9883 &ioc->sas_hba.sas_port_list, port_list) {
9884 if (mpt3sas_port->remote_identify.device_type ==
9886 mpt3sas_device_remove_by_sas_address(ioc,
9887 mpt3sas_port->remote_identify.sas_address);
9888 else if (mpt3sas_port->remote_identify.device_type ==
9889 SAS_EDGE_EXPANDER_DEVICE ||
9890 mpt3sas_port->remote_identify.device_type ==
9891 SAS_FANOUT_EXPANDER_DEVICE)
9892 mpt3sas_expander_remove(ioc,
9893 mpt3sas_port->remote_identify.sas_address);
9896 /* free phys attached to the sas_host */
9897 if (ioc->sas_hba.num_phys) {
9898 kfree(ioc->sas_hba.phy);
9899 ioc->sas_hba.phy = NULL;
9900 ioc->sas_hba.num_phys = 0;
9903 mpt3sas_base_detach(ioc);
9904 spin_lock(&gioc_lock);
9905 list_del(&ioc->list);
9906 spin_unlock(&gioc_lock);
9907 scsi_host_put(shost);
9911 * scsih_shutdown - routine call during system shutdown
9912 * @pdev: PCI device struct
9915 scsih_shutdown(struct pci_dev *pdev)
9917 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9918 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9919 struct workqueue_struct *wq;
9920 unsigned long flags;
9922 ioc->remove_host = 1;
9924 if (!pci_device_is_present(pdev))
9925 _scsih_flush_running_cmds(ioc);
9927 _scsih_fw_event_cleanup_queue(ioc);
9929 spin_lock_irqsave(&ioc->fw_event_lock, flags);
9930 wq = ioc->firmware_event_thread;
9931 ioc->firmware_event_thread = NULL;
9932 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
9934 destroy_workqueue(wq);
9936 _scsih_ir_shutdown(ioc);
9937 mpt3sas_base_detach(ioc);
9942 * _scsih_probe_boot_devices - reports 1st device
9943 * @ioc: per adapter object
9945 * If specified in bios page 2, this routine reports the 1st
9946 * device scsi-ml or sas transport for persistent boot device
9947 * purposes. Please refer to function _scsih_determine_boot_device()
9950 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
9954 struct _sas_device *sas_device;
9955 struct _raid_device *raid_device;
9956 struct _pcie_device *pcie_device;
9958 u64 sas_address_parent;
9960 unsigned long flags;
9964 /* no Bios, return immediately */
9965 if (!ioc->bios_pg3.BiosVersion)
9969 if (ioc->req_boot_device.device) {
9970 device = ioc->req_boot_device.device;
9971 channel = ioc->req_boot_device.channel;
9972 } else if (ioc->req_alt_boot_device.device) {
9973 device = ioc->req_alt_boot_device.device;
9974 channel = ioc->req_alt_boot_device.channel;
9975 } else if (ioc->current_boot_device.device) {
9976 device = ioc->current_boot_device.device;
9977 channel = ioc->current_boot_device.channel;
9983 if (channel == RAID_CHANNEL) {
9984 raid_device = device;
9985 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9986 raid_device->id, 0);
9988 _scsih_raid_device_remove(ioc, raid_device);
9989 } else if (channel == PCIE_CHANNEL) {
9990 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
9991 pcie_device = device;
9992 tid = pcie_device->id;
9993 list_move_tail(&pcie_device->list, &ioc->pcie_device_list);
9994 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
9995 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0);
9997 _scsih_pcie_device_remove(ioc, pcie_device);
9999 spin_lock_irqsave(&ioc->sas_device_lock, flags);
10000 sas_device = device;
10001 handle = sas_device->handle;
10002 sas_address_parent = sas_device->sas_address_parent;
10003 sas_address = sas_device->sas_address;
10004 list_move_tail(&sas_device->list, &ioc->sas_device_list);
10005 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
10007 if (ioc->hide_drives)
10009 if (!mpt3sas_transport_port_add(ioc, handle,
10010 sas_address_parent)) {
10011 _scsih_sas_device_remove(ioc, sas_device);
10012 } else if (!sas_device->starget) {
10013 if (!ioc->is_driver_loading) {
10014 mpt3sas_transport_port_remove(ioc,
10016 sas_address_parent);
10017 _scsih_sas_device_remove(ioc, sas_device);
10024 * _scsih_probe_raid - reporting raid volumes to scsi-ml
10025 * @ioc: per adapter object
10027 * Called during initial loading of the driver.
10030 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
10032 struct _raid_device *raid_device, *raid_next;
10035 list_for_each_entry_safe(raid_device, raid_next,
10036 &ioc->raid_device_list, list) {
10037 if (raid_device->starget)
10039 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
10040 raid_device->id, 0);
10042 _scsih_raid_device_remove(ioc, raid_device);
10046 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
10048 struct _sas_device *sas_device = NULL;
10049 unsigned long flags;
10051 spin_lock_irqsave(&ioc->sas_device_lock, flags);
10052 if (!list_empty(&ioc->sas_device_init_list)) {
10053 sas_device = list_first_entry(&ioc->sas_device_init_list,
10054 struct _sas_device, list);
10055 sas_device_get(sas_device);
10057 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
10062 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
10063 struct _sas_device *sas_device)
10065 unsigned long flags;
10067 spin_lock_irqsave(&ioc->sas_device_lock, flags);
10070 * Since we dropped the lock during the call to port_add(), we need to
10071 * be careful here that somebody else didn't move or delete this item
10072 * while we were busy with other things.
10074 * If it was on the list, we need a put() for the reference the list
10075 * had. Either way, we need a get() for the destination list.
10077 if (!list_empty(&sas_device->list)) {
10078 list_del_init(&sas_device->list);
10079 sas_device_put(sas_device);
10082 sas_device_get(sas_device);
10083 list_add_tail(&sas_device->list, &ioc->sas_device_list);
10085 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
10089 * _scsih_probe_sas - reporting sas devices to sas transport
10090 * @ioc: per adapter object
10092 * Called during initial loading of the driver.
10095 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
10097 struct _sas_device *sas_device;
10099 if (ioc->hide_drives)
10102 while ((sas_device = get_next_sas_device(ioc))) {
10103 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
10104 sas_device->sas_address_parent)) {
10105 _scsih_sas_device_remove(ioc, sas_device);
10106 sas_device_put(sas_device);
10108 } else if (!sas_device->starget) {
10110 * When asyn scanning is enabled, its not possible to
10111 * remove devices while scanning is turned on due to an
10112 * oops in scsi_sysfs_add_sdev()->add_device()->
10113 * sysfs_addrm_start()
10115 if (!ioc->is_driver_loading) {
10116 mpt3sas_transport_port_remove(ioc,
10117 sas_device->sas_address,
10118 sas_device->sas_address_parent);
10119 _scsih_sas_device_remove(ioc, sas_device);
10120 sas_device_put(sas_device);
10124 sas_device_make_active(ioc, sas_device);
10125 sas_device_put(sas_device);
10130 * get_next_pcie_device - Get the next pcie device
10131 * @ioc: per adapter object
10133 * Get the next pcie device from pcie_device_init_list list.
10135 * Return: pcie device structure if pcie_device_init_list list is not empty
10136 * otherwise returns NULL
10138 static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc)
10140 struct _pcie_device *pcie_device = NULL;
10141 unsigned long flags;
10143 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
10144 if (!list_empty(&ioc->pcie_device_init_list)) {
10145 pcie_device = list_first_entry(&ioc->pcie_device_init_list,
10146 struct _pcie_device, list);
10147 pcie_device_get(pcie_device);
10149 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
10151 return pcie_device;
10155 * pcie_device_make_active - Add pcie device to pcie_device_list list
10156 * @ioc: per adapter object
10157 * @pcie_device: pcie device object
10159 * Add the pcie device which has registered with SCSI Transport Later to
10160 * pcie_device_list list
10162 static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc,
10163 struct _pcie_device *pcie_device)
10165 unsigned long flags;
10167 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
10169 if (!list_empty(&pcie_device->list)) {
10170 list_del_init(&pcie_device->list);
10171 pcie_device_put(pcie_device);
10173 pcie_device_get(pcie_device);
10174 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
10176 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
10180 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10181 * @ioc: per adapter object
10183 * Called during initial loading of the driver.
10186 _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc)
10188 struct _pcie_device *pcie_device;
10191 /* PCIe Device List */
10192 while ((pcie_device = get_next_pcie_device(ioc))) {
10193 if (pcie_device->starget) {
10194 pcie_device_put(pcie_device);
10197 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL,
10198 pcie_device->id, 0);
10200 _scsih_pcie_device_remove(ioc, pcie_device);
10201 pcie_device_put(pcie_device);
10203 } else if (!pcie_device->starget) {
10205 * When async scanning is enabled, its not possible to
10206 * remove devices while scanning is turned on due to an
10207 * oops in scsi_sysfs_add_sdev()->add_device()->
10208 * sysfs_addrm_start()
10210 if (!ioc->is_driver_loading) {
10211 /* TODO-- Need to find out whether this condition will
10214 _scsih_pcie_device_remove(ioc, pcie_device);
10215 pcie_device_put(pcie_device);
10219 pcie_device_make_active(ioc, pcie_device);
10220 pcie_device_put(pcie_device);
10225 * _scsih_probe_devices - probing for devices
10226 * @ioc: per adapter object
10228 * Called during initial loading of the driver.
10231 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
10233 u16 volume_mapping_flags;
10235 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
10236 return; /* return when IOC doesn't support initiator mode */
10238 _scsih_probe_boot_devices(ioc);
10240 if (ioc->ir_firmware) {
10241 volume_mapping_flags =
10242 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
10243 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
10244 if (volume_mapping_flags ==
10245 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
10246 _scsih_probe_raid(ioc);
10247 _scsih_probe_sas(ioc);
10249 _scsih_probe_sas(ioc);
10250 _scsih_probe_raid(ioc);
10253 _scsih_probe_sas(ioc);
10254 _scsih_probe_pcie(ioc);
10259 * scsih_scan_start - scsi lld callback for .scan_start
10260 * @shost: SCSI host pointer
10262 * The shost has the ability to discover targets on its own instead
10263 * of scanning the entire bus. In our implemention, we will kick off
10264 * firmware discovery.
10267 scsih_scan_start(struct Scsi_Host *shost)
10269 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10271 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
10272 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
10274 if (disable_discovery > 0)
10277 ioc->start_scan = 1;
10278 rc = mpt3sas_port_enable(ioc);
10281 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
10285 * scsih_scan_finished - scsi lld callback for .scan_finished
10286 * @shost: SCSI host pointer
10287 * @time: elapsed time of the scan in jiffies
10289 * This function will be called periodicallyn until it returns 1 with the
10290 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10291 * we wait for firmware discovery to complete, then return 1.
10294 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
10296 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10298 if (disable_discovery > 0) {
10299 ioc->is_driver_loading = 0;
10300 ioc->wait_for_discovery_to_complete = 0;
10304 if (time >= (300 * HZ)) {
10305 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
10306 pr_info(MPT3SAS_FMT
10307 "port enable: FAILED with timeout (timeout=300s)\n",
10309 ioc->is_driver_loading = 0;
10313 if (ioc->start_scan)
10316 if (ioc->start_scan_failed) {
10317 pr_info(MPT3SAS_FMT
10318 "port enable: FAILED with (ioc_status=0x%08x)\n",
10319 ioc->name, ioc->start_scan_failed);
10320 ioc->is_driver_loading = 0;
10321 ioc->wait_for_discovery_to_complete = 0;
10322 ioc->remove_host = 1;
10326 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
10327 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
10329 if (ioc->wait_for_discovery_to_complete) {
10330 ioc->wait_for_discovery_to_complete = 0;
10331 _scsih_probe_devices(ioc);
10333 mpt3sas_base_start_watchdog(ioc);
10334 ioc->is_driver_loading = 0;
10338 /* shost template for SAS 2.0 HBA devices */
10339 static struct scsi_host_template mpt2sas_driver_template = {
10340 .module = THIS_MODULE,
10341 .name = "Fusion MPT SAS Host",
10342 .proc_name = MPT2SAS_DRIVER_NAME,
10343 .queuecommand = scsih_qcmd,
10344 .target_alloc = scsih_target_alloc,
10345 .slave_alloc = scsih_slave_alloc,
10346 .slave_configure = scsih_slave_configure,
10347 .target_destroy = scsih_target_destroy,
10348 .slave_destroy = scsih_slave_destroy,
10349 .scan_finished = scsih_scan_finished,
10350 .scan_start = scsih_scan_start,
10351 .change_queue_depth = scsih_change_queue_depth,
10352 .eh_abort_handler = scsih_abort,
10353 .eh_device_reset_handler = scsih_dev_reset,
10354 .eh_target_reset_handler = scsih_target_reset,
10355 .eh_host_reset_handler = scsih_host_reset,
10356 .bios_param = scsih_bios_param,
10359 .sg_tablesize = MPT2SAS_SG_DEPTH,
10360 .max_sectors = 32767,
10362 .use_clustering = ENABLE_CLUSTERING,
10363 .shost_attrs = mpt3sas_host_attrs,
10364 .sdev_attrs = mpt3sas_dev_attrs,
10365 .track_queue_depth = 1,
10366 .cmd_size = sizeof(struct scsiio_tracker),
10369 /* raid transport support for SAS 2.0 HBA devices */
10370 static struct raid_function_template mpt2sas_raid_functions = {
10371 .cookie = &mpt2sas_driver_template,
10372 .is_raid = scsih_is_raid,
10373 .get_resync = scsih_get_resync,
10374 .get_state = scsih_get_state,
10377 /* shost template for SAS 3.0 HBA devices */
10378 static struct scsi_host_template mpt3sas_driver_template = {
10379 .module = THIS_MODULE,
10380 .name = "Fusion MPT SAS Host",
10381 .proc_name = MPT3SAS_DRIVER_NAME,
10382 .queuecommand = scsih_qcmd,
10383 .target_alloc = scsih_target_alloc,
10384 .slave_alloc = scsih_slave_alloc,
10385 .slave_configure = scsih_slave_configure,
10386 .target_destroy = scsih_target_destroy,
10387 .slave_destroy = scsih_slave_destroy,
10388 .scan_finished = scsih_scan_finished,
10389 .scan_start = scsih_scan_start,
10390 .change_queue_depth = scsih_change_queue_depth,
10391 .eh_abort_handler = scsih_abort,
10392 .eh_device_reset_handler = scsih_dev_reset,
10393 .eh_target_reset_handler = scsih_target_reset,
10394 .eh_host_reset_handler = scsih_host_reset,
10395 .bios_param = scsih_bios_param,
10398 .sg_tablesize = MPT3SAS_SG_DEPTH,
10399 .max_sectors = 32767,
10401 .use_clustering = ENABLE_CLUSTERING,
10402 .shost_attrs = mpt3sas_host_attrs,
10403 .sdev_attrs = mpt3sas_dev_attrs,
10404 .track_queue_depth = 1,
10405 .cmd_size = sizeof(struct scsiio_tracker),
10408 /* raid transport support for SAS 3.0 HBA devices */
10409 static struct raid_function_template mpt3sas_raid_functions = {
10410 .cookie = &mpt3sas_driver_template,
10411 .is_raid = scsih_is_raid,
10412 .get_resync = scsih_get_resync,
10413 .get_state = scsih_get_state,
10417 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10418 * this device belongs to.
10419 * @pdev: PCI device struct
10421 * return MPI2_VERSION for SAS 2.0 HBA devices,
10422 * MPI25_VERSION for SAS 3.0 HBA devices, and
10423 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10426 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
10429 switch (pdev->device) {
10430 case MPI2_MFGPAGE_DEVID_SSS6200:
10431 case MPI2_MFGPAGE_DEVID_SAS2004:
10432 case MPI2_MFGPAGE_DEVID_SAS2008:
10433 case MPI2_MFGPAGE_DEVID_SAS2108_1:
10434 case MPI2_MFGPAGE_DEVID_SAS2108_2:
10435 case MPI2_MFGPAGE_DEVID_SAS2108_3:
10436 case MPI2_MFGPAGE_DEVID_SAS2116_1:
10437 case MPI2_MFGPAGE_DEVID_SAS2116_2:
10438 case MPI2_MFGPAGE_DEVID_SAS2208_1:
10439 case MPI2_MFGPAGE_DEVID_SAS2208_2:
10440 case MPI2_MFGPAGE_DEVID_SAS2208_3:
10441 case MPI2_MFGPAGE_DEVID_SAS2208_4:
10442 case MPI2_MFGPAGE_DEVID_SAS2208_5:
10443 case MPI2_MFGPAGE_DEVID_SAS2208_6:
10444 case MPI2_MFGPAGE_DEVID_SAS2308_1:
10445 case MPI2_MFGPAGE_DEVID_SAS2308_2:
10446 case MPI2_MFGPAGE_DEVID_SAS2308_3:
10447 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
10448 return MPI2_VERSION;
10449 case MPI25_MFGPAGE_DEVID_SAS3004:
10450 case MPI25_MFGPAGE_DEVID_SAS3008:
10451 case MPI25_MFGPAGE_DEVID_SAS3108_1:
10452 case MPI25_MFGPAGE_DEVID_SAS3108_2:
10453 case MPI25_MFGPAGE_DEVID_SAS3108_5:
10454 case MPI25_MFGPAGE_DEVID_SAS3108_6:
10455 return MPI25_VERSION;
10456 case MPI26_MFGPAGE_DEVID_SAS3216:
10457 case MPI26_MFGPAGE_DEVID_SAS3224:
10458 case MPI26_MFGPAGE_DEVID_SAS3316_1:
10459 case MPI26_MFGPAGE_DEVID_SAS3316_2:
10460 case MPI26_MFGPAGE_DEVID_SAS3316_3:
10461 case MPI26_MFGPAGE_DEVID_SAS3316_4:
10462 case MPI26_MFGPAGE_DEVID_SAS3324_1:
10463 case MPI26_MFGPAGE_DEVID_SAS3324_2:
10464 case MPI26_MFGPAGE_DEVID_SAS3324_3:
10465 case MPI26_MFGPAGE_DEVID_SAS3324_4:
10466 case MPI26_MFGPAGE_DEVID_SAS3508:
10467 case MPI26_MFGPAGE_DEVID_SAS3508_1:
10468 case MPI26_MFGPAGE_DEVID_SAS3408:
10469 case MPI26_MFGPAGE_DEVID_SAS3516:
10470 case MPI26_MFGPAGE_DEVID_SAS3516_1:
10471 case MPI26_MFGPAGE_DEVID_SAS3416:
10472 case MPI26_MFGPAGE_DEVID_SAS3616:
10473 return MPI26_VERSION;
10479 * _scsih_probe - attach and add scsi host
10480 * @pdev: PCI device struct
10481 * @id: pci device id
10483 * Return: 0 success, anything else error.
10486 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
10488 struct MPT3SAS_ADAPTER *ioc;
10489 struct Scsi_Host *shost = NULL;
10491 u16 hba_mpi_version;
10493 /* Determine in which MPI version class this pci device belongs */
10494 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
10495 if (hba_mpi_version == 0)
10498 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10499 * for other generation HBA's return with -ENODEV
10501 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
10504 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10505 * for other generation HBA's return with -ENODEV
10507 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
10508 || hba_mpi_version == MPI26_VERSION)))
10511 switch (hba_mpi_version) {
10513 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
10514 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
10515 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10516 shost = scsi_host_alloc(&mpt2sas_driver_template,
10517 sizeof(struct MPT3SAS_ADAPTER));
10520 ioc = shost_priv(shost);
10521 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
10522 ioc->hba_mpi_version_belonged = hba_mpi_version;
10523 ioc->id = mpt2_ids++;
10524 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
10525 switch (pdev->device) {
10526 case MPI2_MFGPAGE_DEVID_SSS6200:
10527 ioc->is_warpdrive = 1;
10528 ioc->hide_ir_msg = 1;
10530 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
10531 ioc->is_mcpu_endpoint = 1;
10534 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
10538 case MPI25_VERSION:
10539 case MPI26_VERSION:
10540 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10541 shost = scsi_host_alloc(&mpt3sas_driver_template,
10542 sizeof(struct MPT3SAS_ADAPTER));
10545 ioc = shost_priv(shost);
10546 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
10547 ioc->hba_mpi_version_belonged = hba_mpi_version;
10548 ioc->id = mpt3_ids++;
10549 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
10550 switch (pdev->device) {
10551 case MPI26_MFGPAGE_DEVID_SAS3508:
10552 case MPI26_MFGPAGE_DEVID_SAS3508_1:
10553 case MPI26_MFGPAGE_DEVID_SAS3408:
10554 case MPI26_MFGPAGE_DEVID_SAS3516:
10555 case MPI26_MFGPAGE_DEVID_SAS3516_1:
10556 case MPI26_MFGPAGE_DEVID_SAS3416:
10557 case MPI26_MFGPAGE_DEVID_SAS3616:
10558 ioc->is_gen35_ioc = 1;
10561 ioc->is_gen35_ioc = 0;
10563 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
10564 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
10565 (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
10566 ioc->combined_reply_queue = 1;
10567 if (ioc->is_gen35_ioc)
10568 ioc->combined_reply_index_count =
10569 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
10571 ioc->combined_reply_index_count =
10572 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
10579 INIT_LIST_HEAD(&ioc->list);
10580 spin_lock(&gioc_lock);
10581 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
10582 spin_unlock(&gioc_lock);
10583 ioc->shost = shost;
10585 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
10586 ioc->tm_cb_idx = tm_cb_idx;
10587 ioc->ctl_cb_idx = ctl_cb_idx;
10588 ioc->base_cb_idx = base_cb_idx;
10589 ioc->port_enable_cb_idx = port_enable_cb_idx;
10590 ioc->transport_cb_idx = transport_cb_idx;
10591 ioc->scsih_cb_idx = scsih_cb_idx;
10592 ioc->config_cb_idx = config_cb_idx;
10593 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
10594 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
10595 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
10596 ioc->logging_level = logging_level;
10597 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
10598 /* misc semaphores and spin locks */
10599 mutex_init(&ioc->reset_in_progress_mutex);
10600 /* initializing pci_access_mutex lock */
10601 mutex_init(&ioc->pci_access_mutex);
10602 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
10603 spin_lock_init(&ioc->scsi_lookup_lock);
10604 spin_lock_init(&ioc->sas_device_lock);
10605 spin_lock_init(&ioc->sas_node_lock);
10606 spin_lock_init(&ioc->fw_event_lock);
10607 spin_lock_init(&ioc->raid_device_lock);
10608 spin_lock_init(&ioc->pcie_device_lock);
10609 spin_lock_init(&ioc->diag_trigger_lock);
10611 INIT_LIST_HEAD(&ioc->sas_device_list);
10612 INIT_LIST_HEAD(&ioc->sas_device_init_list);
10613 INIT_LIST_HEAD(&ioc->sas_expander_list);
10614 INIT_LIST_HEAD(&ioc->enclosure_list);
10615 INIT_LIST_HEAD(&ioc->pcie_device_list);
10616 INIT_LIST_HEAD(&ioc->pcie_device_init_list);
10617 INIT_LIST_HEAD(&ioc->fw_event_list);
10618 INIT_LIST_HEAD(&ioc->raid_device_list);
10619 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
10620 INIT_LIST_HEAD(&ioc->delayed_tr_list);
10621 INIT_LIST_HEAD(&ioc->delayed_sc_list);
10622 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
10623 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
10624 INIT_LIST_HEAD(&ioc->reply_queue_list);
10626 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
10628 /* init shost parameters */
10629 shost->max_cmd_len = 32;
10630 shost->max_lun = max_lun;
10631 shost->transportt = mpt3sas_transport_template;
10632 shost->unique_id = ioc->id;
10634 if (ioc->is_mcpu_endpoint) {
10635 /* mCPU MPI support 64K max IO */
10636 shost->max_sectors = 128;
10637 pr_info(MPT3SAS_FMT
10638 "The max_sectors value is set to %d\n",
10639 ioc->name, shost->max_sectors);
10641 if (max_sectors != 0xFFFF) {
10642 if (max_sectors < 64) {
10643 shost->max_sectors = 64;
10644 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
10645 "for max_sectors, range is 64 to 32767. " \
10646 "Assigning value of 64.\n", \
10647 ioc->name, max_sectors);
10648 } else if (max_sectors > 32767) {
10649 shost->max_sectors = 32767;
10650 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
10651 "for max_sectors, range is 64 to 32767." \
10652 "Assigning default value of 32767.\n", \
10653 ioc->name, max_sectors);
10655 shost->max_sectors = max_sectors & 0xFFFE;
10656 pr_info(MPT3SAS_FMT
10657 "The max_sectors value is set to %d\n",
10658 ioc->name, shost->max_sectors);
10662 /* register EEDP capabilities with SCSI layer */
10664 scsi_host_set_prot(shost, prot_mask);
10666 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
10667 | SHOST_DIF_TYPE2_PROTECTION
10668 | SHOST_DIF_TYPE3_PROTECTION);
10670 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
10673 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
10674 "fw_event_%s%d", ioc->driver_name, ioc->id);
10675 ioc->firmware_event_thread = alloc_ordered_workqueue(
10676 ioc->firmware_event_name, 0);
10677 if (!ioc->firmware_event_thread) {
10678 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10679 ioc->name, __FILE__, __LINE__, __func__);
10681 goto out_thread_fail;
10684 ioc->is_driver_loading = 1;
10685 if ((mpt3sas_base_attach(ioc))) {
10686 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10687 ioc->name, __FILE__, __LINE__, __func__);
10689 goto out_attach_fail;
10692 if (ioc->is_warpdrive) {
10693 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
10694 ioc->hide_drives = 0;
10695 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
10696 ioc->hide_drives = 1;
10698 if (mpt3sas_get_num_volumes(ioc))
10699 ioc->hide_drives = 1;
10701 ioc->hide_drives = 0;
10704 ioc->hide_drives = 0;
10706 rv = scsi_add_host(shost, &pdev->dev);
10708 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
10709 ioc->name, __FILE__, __LINE__, __func__);
10710 goto out_add_shost_fail;
10713 scsi_scan_host(shost);
10715 out_add_shost_fail:
10716 mpt3sas_base_detach(ioc);
10718 destroy_workqueue(ioc->firmware_event_thread);
10720 spin_lock(&gioc_lock);
10721 list_del(&ioc->list);
10722 spin_unlock(&gioc_lock);
10723 scsi_host_put(shost);
10729 * scsih_suspend - power management suspend main entry point
10730 * @pdev: PCI device struct
10731 * @state: PM state change to (usually PCI_D3)
10733 * Return: 0 success, anything else error.
10736 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
10738 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10739 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10740 pci_power_t device_state;
10742 mpt3sas_base_stop_watchdog(ioc);
10743 flush_scheduled_work();
10744 scsi_block_requests(shost);
10745 device_state = pci_choose_state(pdev, state);
10746 pr_info(MPT3SAS_FMT
10747 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10748 ioc->name, pdev, pci_name(pdev), device_state);
10750 pci_save_state(pdev);
10751 mpt3sas_base_free_resources(ioc);
10752 pci_set_power_state(pdev, device_state);
10757 * scsih_resume - power management resume main entry point
10758 * @pdev: PCI device struct
10760 * Return: 0 success, anything else error.
10763 scsih_resume(struct pci_dev *pdev)
10765 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10766 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10767 pci_power_t device_state = pdev->current_state;
10770 pr_info(MPT3SAS_FMT
10771 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10772 ioc->name, pdev, pci_name(pdev), device_state);
10774 pci_set_power_state(pdev, PCI_D0);
10775 pci_enable_wake(pdev, PCI_D0, 0);
10776 pci_restore_state(pdev);
10778 r = mpt3sas_base_map_resources(ioc);
10782 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
10783 scsi_unblock_requests(shost);
10784 mpt3sas_base_start_watchdog(ioc);
10787 #endif /* CONFIG_PM */
10790 * scsih_pci_error_detected - Called when a PCI error is detected.
10791 * @pdev: PCI device struct
10792 * @state: PCI channel state
10794 * Description: Called when a PCI error is detected.
10796 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
10798 static pci_ers_result_t
10799 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10801 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10802 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10804 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
10808 case pci_channel_io_normal:
10809 return PCI_ERS_RESULT_CAN_RECOVER;
10810 case pci_channel_io_frozen:
10811 /* Fatal error, prepare for slot reset */
10812 ioc->pci_error_recovery = 1;
10813 scsi_block_requests(ioc->shost);
10814 mpt3sas_base_stop_watchdog(ioc);
10815 mpt3sas_base_free_resources(ioc);
10816 return PCI_ERS_RESULT_NEED_RESET;
10817 case pci_channel_io_perm_failure:
10818 /* Permanent error, prepare for device removal */
10819 ioc->pci_error_recovery = 1;
10820 mpt3sas_base_stop_watchdog(ioc);
10821 _scsih_flush_running_cmds(ioc);
10822 return PCI_ERS_RESULT_DISCONNECT;
10824 return PCI_ERS_RESULT_NEED_RESET;
10828 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10829 * @pdev: PCI device struct
10831 * Description: This routine is called by the pci error recovery
10832 * code after the PCI slot has been reset, just before we
10833 * should resume normal operations.
10835 static pci_ers_result_t
10836 scsih_pci_slot_reset(struct pci_dev *pdev)
10838 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10839 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10842 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
10845 ioc->pci_error_recovery = 0;
10847 pci_restore_state(pdev);
10848 rc = mpt3sas_base_map_resources(ioc);
10850 return PCI_ERS_RESULT_DISCONNECT;
10852 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
10854 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
10855 (rc == 0) ? "success" : "failed");
10858 return PCI_ERS_RESULT_RECOVERED;
10860 return PCI_ERS_RESULT_DISCONNECT;
10864 * scsih_pci_resume() - resume normal ops after PCI reset
10865 * @pdev: pointer to PCI device
10867 * Called when the error recovery driver tells us that its
10868 * OK to resume normal operation. Use completion to allow
10869 * halted scsi ops to resume.
10872 scsih_pci_resume(struct pci_dev *pdev)
10874 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10875 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10877 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
10879 pci_cleanup_aer_uncorrect_error_status(pdev);
10880 mpt3sas_base_start_watchdog(ioc);
10881 scsi_unblock_requests(ioc->shost);
10885 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10886 * @pdev: pointer to PCI device
10888 static pci_ers_result_t
10889 scsih_pci_mmio_enabled(struct pci_dev *pdev)
10891 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10892 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10894 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
10897 /* TODO - dump whatever for debugging purposes */
10899 /* This called only if scsih_pci_error_detected returns
10900 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10901 * works, no need to reset slot.
10903 return PCI_ERS_RESULT_RECOVERED;
10907 * scsih__ncq_prio_supp - Check for NCQ command priority support
10908 * @sdev: scsi device struct
10910 * This is called when a user indicates they would like to enable
10911 * ncq command priorities. This works only on SATA devices.
10913 bool scsih_ncq_prio_supp(struct scsi_device *sdev)
10915 unsigned char *buf;
10916 bool ncq_prio_supp = false;
10918 if (!scsi_device_supports_vpd(sdev))
10919 return ncq_prio_supp;
10921 buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL);
10923 return ncq_prio_supp;
10925 if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN))
10926 ncq_prio_supp = (buf[213] >> 4) & 1;
10929 return ncq_prio_supp;
10932 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10934 static const struct pci_device_id mpt3sas_pci_table[] = {
10935 /* Spitfire ~ 2004 */
10936 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
10937 PCI_ANY_ID, PCI_ANY_ID },
10938 /* Falcon ~ 2008 */
10939 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
10940 PCI_ANY_ID, PCI_ANY_ID },
10941 /* Liberator ~ 2108 */
10942 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
10943 PCI_ANY_ID, PCI_ANY_ID },
10944 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
10945 PCI_ANY_ID, PCI_ANY_ID },
10946 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
10947 PCI_ANY_ID, PCI_ANY_ID },
10948 /* Meteor ~ 2116 */
10949 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
10950 PCI_ANY_ID, PCI_ANY_ID },
10951 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
10952 PCI_ANY_ID, PCI_ANY_ID },
10953 /* Thunderbolt ~ 2208 */
10954 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
10955 PCI_ANY_ID, PCI_ANY_ID },
10956 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
10957 PCI_ANY_ID, PCI_ANY_ID },
10958 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
10959 PCI_ANY_ID, PCI_ANY_ID },
10960 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
10961 PCI_ANY_ID, PCI_ANY_ID },
10962 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
10963 PCI_ANY_ID, PCI_ANY_ID },
10964 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
10965 PCI_ANY_ID, PCI_ANY_ID },
10966 /* Mustang ~ 2308 */
10967 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
10968 PCI_ANY_ID, PCI_ANY_ID },
10969 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
10970 PCI_ANY_ID, PCI_ANY_ID },
10971 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
10972 PCI_ANY_ID, PCI_ANY_ID },
10973 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP,
10974 PCI_ANY_ID, PCI_ANY_ID },
10976 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
10977 PCI_ANY_ID, PCI_ANY_ID },
10978 /* Fury ~ 3004 and 3008 */
10979 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
10980 PCI_ANY_ID, PCI_ANY_ID },
10981 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
10982 PCI_ANY_ID, PCI_ANY_ID },
10983 /* Invader ~ 3108 */
10984 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
10985 PCI_ANY_ID, PCI_ANY_ID },
10986 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
10987 PCI_ANY_ID, PCI_ANY_ID },
10988 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
10989 PCI_ANY_ID, PCI_ANY_ID },
10990 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
10991 PCI_ANY_ID, PCI_ANY_ID },
10992 /* Cutlass ~ 3216 and 3224 */
10993 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
10994 PCI_ANY_ID, PCI_ANY_ID },
10995 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
10996 PCI_ANY_ID, PCI_ANY_ID },
10997 /* Intruder ~ 3316 and 3324 */
10998 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
10999 PCI_ANY_ID, PCI_ANY_ID },
11000 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
11001 PCI_ANY_ID, PCI_ANY_ID },
11002 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
11003 PCI_ANY_ID, PCI_ANY_ID },
11004 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
11005 PCI_ANY_ID, PCI_ANY_ID },
11006 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
11007 PCI_ANY_ID, PCI_ANY_ID },
11008 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
11009 PCI_ANY_ID, PCI_ANY_ID },
11010 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
11011 PCI_ANY_ID, PCI_ANY_ID },
11012 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
11013 PCI_ANY_ID, PCI_ANY_ID },
11014 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
11015 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
11016 PCI_ANY_ID, PCI_ANY_ID },
11017 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
11018 PCI_ANY_ID, PCI_ANY_ID },
11019 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
11020 PCI_ANY_ID, PCI_ANY_ID },
11021 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
11022 PCI_ANY_ID, PCI_ANY_ID },
11023 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
11024 PCI_ANY_ID, PCI_ANY_ID },
11025 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
11026 PCI_ANY_ID, PCI_ANY_ID },
11027 /* Mercator ~ 3616*/
11028 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616,
11029 PCI_ANY_ID, PCI_ANY_ID },
11030 {0} /* Terminating entry */
11032 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
11034 static struct pci_error_handlers _mpt3sas_err_handler = {
11035 .error_detected = scsih_pci_error_detected,
11036 .mmio_enabled = scsih_pci_mmio_enabled,
11037 .slot_reset = scsih_pci_slot_reset,
11038 .resume = scsih_pci_resume,
11041 static struct pci_driver mpt3sas_driver = {
11042 .name = MPT3SAS_DRIVER_NAME,
11043 .id_table = mpt3sas_pci_table,
11044 .probe = _scsih_probe,
11045 .remove = scsih_remove,
11046 .shutdown = scsih_shutdown,
11047 .err_handler = &_mpt3sas_err_handler,
11049 .suspend = scsih_suspend,
11050 .resume = scsih_resume,
11055 * scsih_init - main entry point for this driver.
11057 * Return: 0 success, anything else error.
11065 mpt3sas_base_initialize_callback_handler();
11067 /* queuecommand callback hander */
11068 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
11070 /* task management callback handler */
11071 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
11073 /* base internal commands callback handler */
11074 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
11075 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
11076 mpt3sas_port_enable_done);
11078 /* transport internal commands callback handler */
11079 transport_cb_idx = mpt3sas_base_register_callback_handler(
11080 mpt3sas_transport_done);
11082 /* scsih internal commands callback handler */
11083 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
11085 /* configuration page API internal commands callback handler */
11086 config_cb_idx = mpt3sas_base_register_callback_handler(
11087 mpt3sas_config_done);
11089 /* ctl module callback handler */
11090 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
11092 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
11093 _scsih_tm_tr_complete);
11095 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
11096 _scsih_tm_volume_tr_complete);
11098 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
11099 _scsih_sas_control_complete);
11105 * scsih_exit - exit point for this driver (when it is a module).
11107 * Return: 0 success, anything else error.
11113 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
11114 mpt3sas_base_release_callback_handler(tm_cb_idx);
11115 mpt3sas_base_release_callback_handler(base_cb_idx);
11116 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
11117 mpt3sas_base_release_callback_handler(transport_cb_idx);
11118 mpt3sas_base_release_callback_handler(scsih_cb_idx);
11119 mpt3sas_base_release_callback_handler(config_cb_idx);
11120 mpt3sas_base_release_callback_handler(ctl_cb_idx);
11122 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
11123 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
11124 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
11126 /* raid transport support */
11127 if (hbas_to_enumerate != 1)
11128 raid_class_release(mpt3sas_raid_template);
11129 if (hbas_to_enumerate != 2)
11130 raid_class_release(mpt2sas_raid_template);
11131 sas_release_transport(mpt3sas_transport_template);
11135 * _mpt3sas_init - main entry point for this driver.
11137 * Return: 0 success, anything else error.
11140 _mpt3sas_init(void)
11144 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
11145 MPT3SAS_DRIVER_VERSION);
11147 mpt3sas_transport_template =
11148 sas_attach_transport(&mpt3sas_transport_functions);
11149 if (!mpt3sas_transport_template)
11152 /* No need attach mpt3sas raid functions template
11153 * if hbas_to_enumarate value is one.
11155 if (hbas_to_enumerate != 1) {
11156 mpt3sas_raid_template =
11157 raid_class_attach(&mpt3sas_raid_functions);
11158 if (!mpt3sas_raid_template) {
11159 sas_release_transport(mpt3sas_transport_template);
11164 /* No need to attach mpt2sas raid functions template
11165 * if hbas_to_enumarate value is two
11167 if (hbas_to_enumerate != 2) {
11168 mpt2sas_raid_template =
11169 raid_class_attach(&mpt2sas_raid_functions);
11170 if (!mpt2sas_raid_template) {
11171 sas_release_transport(mpt3sas_transport_template);
11176 error = scsih_init();
11182 mpt3sas_ctl_init(hbas_to_enumerate);
11184 error = pci_register_driver(&mpt3sas_driver);
11192 * _mpt3sas_exit - exit point for this driver (when it is a module).
11196 _mpt3sas_exit(void)
11198 pr_info("mpt3sas version %s unloading\n",
11199 MPT3SAS_DRIVER_VERSION);
11201 mpt3sas_ctl_exit(hbas_to_enumerate);
11203 pci_unregister_driver(&mpt3sas_driver);
11208 module_init(_mpt3sas_init);
11209 module_exit(_mpt3sas_exit);