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 ioc_err(ioc, "failure at %s:%d/%s()!\n",
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 */
445 ioc_err(ioc, "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
446 handle, ioc_status, __FILE__, __LINE__, __func__);
451 * _scsih_determine_boot_device - determine boot device.
452 * @ioc: per adapter object
453 * @device: sas_device or pcie_device object
454 * @channel: SAS or PCIe channel
456 * Determines whether this device should be first reported device to
457 * to scsi-ml or sas transport, this purpose is for persistent boot device.
458 * There are primary, alternate, and current entries in bios page 2. The order
459 * priority is primary, alternate, then current. This routine saves
460 * the corresponding device object.
461 * The saved data to be used later in _scsih_probe_boot_devices().
464 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device,
467 struct _sas_device *sas_device;
468 struct _pcie_device *pcie_device;
469 struct _raid_device *raid_device;
472 u64 enclosure_logical_id;
475 /* only process this function when driver loads */
476 if (!ioc->is_driver_loading)
479 /* no Bios, return immediately */
480 if (!ioc->bios_pg3.BiosVersion)
483 if (channel == RAID_CHANNEL) {
484 raid_device = device;
485 sas_address = raid_device->wwid;
487 enclosure_logical_id = 0;
489 } else if (channel == PCIE_CHANNEL) {
490 pcie_device = device;
491 sas_address = pcie_device->wwid;
493 enclosure_logical_id = 0;
497 sas_address = sas_device->sas_address;
498 device_name = sas_device->device_name;
499 enclosure_logical_id = sas_device->enclosure_logical_id;
500 slot = sas_device->slot;
503 if (!ioc->req_boot_device.device) {
504 if (_scsih_is_boot_device(sas_address, device_name,
505 enclosure_logical_id, slot,
506 (ioc->bios_pg2.ReqBootDeviceForm &
507 MPI2_BIOSPAGE2_FORM_MASK),
508 &ioc->bios_pg2.RequestedBootDevice)) {
510 ioc_info(ioc, "%s: req_boot_device(0x%016llx)\n",
511 __func__, (u64)sas_address));
512 ioc->req_boot_device.device = device;
513 ioc->req_boot_device.channel = channel;
517 if (!ioc->req_alt_boot_device.device) {
518 if (_scsih_is_boot_device(sas_address, device_name,
519 enclosure_logical_id, slot,
520 (ioc->bios_pg2.ReqAltBootDeviceForm &
521 MPI2_BIOSPAGE2_FORM_MASK),
522 &ioc->bios_pg2.RequestedAltBootDevice)) {
524 ioc_info(ioc, "%s: req_alt_boot_device(0x%016llx)\n",
525 __func__, (u64)sas_address));
526 ioc->req_alt_boot_device.device = device;
527 ioc->req_alt_boot_device.channel = channel;
531 if (!ioc->current_boot_device.device) {
532 if (_scsih_is_boot_device(sas_address, device_name,
533 enclosure_logical_id, slot,
534 (ioc->bios_pg2.CurrentBootDeviceForm &
535 MPI2_BIOSPAGE2_FORM_MASK),
536 &ioc->bios_pg2.CurrentBootDevice)) {
538 ioc_info(ioc, "%s: current_boot_device(0x%016llx)\n",
539 __func__, (u64)sas_address));
540 ioc->current_boot_device.device = device;
541 ioc->current_boot_device.channel = channel;
546 static struct _sas_device *
547 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
548 struct MPT3SAS_TARGET *tgt_priv)
550 struct _sas_device *ret;
552 assert_spin_locked(&ioc->sas_device_lock);
554 ret = tgt_priv->sas_dev;
561 static struct _sas_device *
562 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
563 struct MPT3SAS_TARGET *tgt_priv)
565 struct _sas_device *ret;
568 spin_lock_irqsave(&ioc->sas_device_lock, flags);
569 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
570 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
575 static struct _pcie_device *
576 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
577 struct MPT3SAS_TARGET *tgt_priv)
579 struct _pcie_device *ret;
581 assert_spin_locked(&ioc->pcie_device_lock);
583 ret = tgt_priv->pcie_dev;
585 pcie_device_get(ret);
591 * mpt3sas_get_pdev_from_target - pcie device search
592 * @ioc: per adapter object
593 * @tgt_priv: starget private object
595 * Context: This function will acquire ioc->pcie_device_lock and will release
596 * before returning the pcie_device object.
598 * This searches for pcie_device from target, then return pcie_device object.
600 static struct _pcie_device *
601 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
602 struct MPT3SAS_TARGET *tgt_priv)
604 struct _pcie_device *ret;
607 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
608 ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv);
609 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
615 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
618 struct _sas_device *sas_device;
620 assert_spin_locked(&ioc->sas_device_lock);
622 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
623 if (sas_device->sas_address == sas_address)
626 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
627 if (sas_device->sas_address == sas_address)
633 sas_device_get(sas_device);
638 * mpt3sas_get_sdev_by_addr - sas device search
639 * @ioc: per adapter object
640 * @sas_address: sas address
641 * Context: Calling function should acquire ioc->sas_device_lock
643 * This searches for sas_device based on sas_address, then return sas_device
647 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
650 struct _sas_device *sas_device;
653 spin_lock_irqsave(&ioc->sas_device_lock, flags);
654 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
656 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
661 static struct _sas_device *
662 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
664 struct _sas_device *sas_device;
666 assert_spin_locked(&ioc->sas_device_lock);
668 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
669 if (sas_device->handle == handle)
672 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
673 if (sas_device->handle == handle)
679 sas_device_get(sas_device);
684 * mpt3sas_get_sdev_by_handle - sas device search
685 * @ioc: per adapter object
686 * @handle: sas device handle (assigned by firmware)
687 * Context: Calling function should acquire ioc->sas_device_lock
689 * This searches for sas_device based on sas_address, then return sas_device
693 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
695 struct _sas_device *sas_device;
698 spin_lock_irqsave(&ioc->sas_device_lock, flags);
699 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
700 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
706 * _scsih_display_enclosure_chassis_info - display device location info
707 * @ioc: per adapter object
708 * @sas_device: per sas device object
709 * @sdev: scsi device struct
710 * @starget: scsi target struct
713 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc,
714 struct _sas_device *sas_device, struct scsi_device *sdev,
715 struct scsi_target *starget)
718 if (sas_device->enclosure_handle != 0)
719 sdev_printk(KERN_INFO, sdev,
720 "enclosure logical id (0x%016llx), slot(%d) \n",
722 sas_device->enclosure_logical_id,
724 if (sas_device->connector_name[0] != '\0')
725 sdev_printk(KERN_INFO, sdev,
726 "enclosure level(0x%04x), connector name( %s)\n",
727 sas_device->enclosure_level,
728 sas_device->connector_name);
729 if (sas_device->is_chassis_slot_valid)
730 sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n",
731 sas_device->chassis_slot);
732 } else if (starget) {
733 if (sas_device->enclosure_handle != 0)
734 starget_printk(KERN_INFO, starget,
735 "enclosure logical id(0x%016llx), slot(%d) \n",
737 sas_device->enclosure_logical_id,
739 if (sas_device->connector_name[0] != '\0')
740 starget_printk(KERN_INFO, starget,
741 "enclosure level(0x%04x), connector name( %s)\n",
742 sas_device->enclosure_level,
743 sas_device->connector_name);
744 if (sas_device->is_chassis_slot_valid)
745 starget_printk(KERN_INFO, starget,
746 "chassis slot(0x%04x)\n",
747 sas_device->chassis_slot);
749 if (sas_device->enclosure_handle != 0)
750 ioc_info(ioc, "enclosure logical id(0x%016llx), slot(%d)\n",
751 (u64)sas_device->enclosure_logical_id,
753 if (sas_device->connector_name[0] != '\0')
754 ioc_info(ioc, "enclosure level(0x%04x), connector name( %s)\n",
755 sas_device->enclosure_level,
756 sas_device->connector_name);
757 if (sas_device->is_chassis_slot_valid)
758 ioc_info(ioc, "chassis slot(0x%04x)\n",
759 sas_device->chassis_slot);
764 * _scsih_sas_device_remove - remove sas_device from list.
765 * @ioc: per adapter object
766 * @sas_device: the sas_device object
767 * Context: This function will acquire ioc->sas_device_lock.
769 * If sas_device is on the list, remove it and decrement its reference count.
772 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
773 struct _sas_device *sas_device)
779 ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
780 sas_device->handle, (u64)sas_device->sas_address);
782 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
785 * The lock serializes access to the list, but we still need to verify
786 * that nobody removed the entry while we were waiting on the lock.
788 spin_lock_irqsave(&ioc->sas_device_lock, flags);
789 if (!list_empty(&sas_device->list)) {
790 list_del_init(&sas_device->list);
791 sas_device_put(sas_device);
793 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
797 * _scsih_device_remove_by_handle - removing device object by handle
798 * @ioc: per adapter object
799 * @handle: device handle
802 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
804 struct _sas_device *sas_device;
807 if (ioc->shost_recovery)
810 spin_lock_irqsave(&ioc->sas_device_lock, flags);
811 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
813 list_del_init(&sas_device->list);
814 sas_device_put(sas_device);
816 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
818 _scsih_remove_device(ioc, sas_device);
819 sas_device_put(sas_device);
824 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
825 * @ioc: per adapter object
826 * @sas_address: device sas_address
829 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
832 struct _sas_device *sas_device;
835 if (ioc->shost_recovery)
838 spin_lock_irqsave(&ioc->sas_device_lock, flags);
839 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
841 list_del_init(&sas_device->list);
842 sas_device_put(sas_device);
844 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
846 _scsih_remove_device(ioc, sas_device);
847 sas_device_put(sas_device);
852 * _scsih_sas_device_add - insert sas_device to the list.
853 * @ioc: per adapter object
854 * @sas_device: the sas_device object
855 * Context: This function will acquire ioc->sas_device_lock.
857 * Adding new object to the ioc->sas_device_list.
860 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
861 struct _sas_device *sas_device)
866 ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
867 __func__, sas_device->handle,
868 (u64)sas_device->sas_address));
870 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
873 spin_lock_irqsave(&ioc->sas_device_lock, flags);
874 sas_device_get(sas_device);
875 list_add_tail(&sas_device->list, &ioc->sas_device_list);
876 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
878 if (ioc->hide_drives) {
879 clear_bit(sas_device->handle, ioc->pend_os_device_add);
883 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
884 sas_device->sas_address_parent)) {
885 _scsih_sas_device_remove(ioc, sas_device);
886 } else if (!sas_device->starget) {
888 * When asyn scanning is enabled, its not possible to remove
889 * devices while scanning is turned on due to an oops in
890 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
892 if (!ioc->is_driver_loading) {
893 mpt3sas_transport_port_remove(ioc,
894 sas_device->sas_address,
895 sas_device->sas_address_parent);
896 _scsih_sas_device_remove(ioc, sas_device);
899 clear_bit(sas_device->handle, ioc->pend_os_device_add);
903 * _scsih_sas_device_init_add - insert sas_device to the list.
904 * @ioc: per adapter object
905 * @sas_device: the sas_device object
906 * Context: This function will acquire ioc->sas_device_lock.
908 * Adding new object at driver load time to the ioc->sas_device_init_list.
911 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
912 struct _sas_device *sas_device)
917 ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
918 __func__, sas_device->handle,
919 (u64)sas_device->sas_address));
921 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
924 spin_lock_irqsave(&ioc->sas_device_lock, flags);
925 sas_device_get(sas_device);
926 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
927 _scsih_determine_boot_device(ioc, sas_device, 0);
928 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
932 static struct _pcie_device *
933 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
935 struct _pcie_device *pcie_device;
937 assert_spin_locked(&ioc->pcie_device_lock);
939 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
940 if (pcie_device->wwid == wwid)
943 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
944 if (pcie_device->wwid == wwid)
950 pcie_device_get(pcie_device);
956 * mpt3sas_get_pdev_by_wwid - pcie device search
957 * @ioc: per adapter object
960 * Context: This function will acquire ioc->pcie_device_lock and will release
961 * before returning the pcie_device object.
963 * This searches for pcie_device based on wwid, then return pcie_device object.
965 static struct _pcie_device *
966 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
968 struct _pcie_device *pcie_device;
971 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
972 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
973 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
979 static struct _pcie_device *
980 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id,
983 struct _pcie_device *pcie_device;
985 assert_spin_locked(&ioc->pcie_device_lock);
987 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
988 if (pcie_device->id == id && pcie_device->channel == channel)
991 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
992 if (pcie_device->id == id && pcie_device->channel == channel)
998 pcie_device_get(pcie_device);
1002 static struct _pcie_device *
1003 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1005 struct _pcie_device *pcie_device;
1007 assert_spin_locked(&ioc->pcie_device_lock);
1009 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
1010 if (pcie_device->handle == handle)
1013 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
1014 if (pcie_device->handle == handle)
1020 pcie_device_get(pcie_device);
1026 * mpt3sas_get_pdev_by_handle - pcie device search
1027 * @ioc: per adapter object
1028 * @handle: Firmware device handle
1030 * Context: This function will acquire ioc->pcie_device_lock and will release
1031 * before returning the pcie_device object.
1033 * This searches for pcie_device based on handle, then return pcie_device
1036 struct _pcie_device *
1037 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1039 struct _pcie_device *pcie_device;
1040 unsigned long flags;
1042 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1043 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
1044 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1050 * _scsih_pcie_device_remove - remove pcie_device from list.
1051 * @ioc: per adapter object
1052 * @pcie_device: the pcie_device object
1053 * Context: This function will acquire ioc->pcie_device_lock.
1055 * If pcie_device is on the list, remove it and decrement its reference count.
1058 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc,
1059 struct _pcie_device *pcie_device)
1061 unsigned long flags;
1062 int was_on_pcie_device_list = 0;
1066 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
1067 pcie_device->handle, (u64)pcie_device->wwid);
1068 if (pcie_device->enclosure_handle != 0)
1069 ioc_info(ioc, "removing enclosure logical id(0x%016llx), slot(%d)\n",
1070 (u64)pcie_device->enclosure_logical_id,
1072 if (pcie_device->connector_name[0] != '\0')
1073 ioc_info(ioc, "removing enclosure level(0x%04x), connector name( %s)\n",
1074 pcie_device->enclosure_level,
1075 pcie_device->connector_name);
1077 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1078 if (!list_empty(&pcie_device->list)) {
1079 list_del_init(&pcie_device->list);
1080 was_on_pcie_device_list = 1;
1082 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1083 if (was_on_pcie_device_list) {
1084 kfree(pcie_device->serial_number);
1085 pcie_device_put(pcie_device);
1091 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1092 * @ioc: per adapter object
1093 * @handle: device handle
1096 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1098 struct _pcie_device *pcie_device;
1099 unsigned long flags;
1100 int was_on_pcie_device_list = 0;
1102 if (ioc->shost_recovery)
1105 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1106 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
1108 if (!list_empty(&pcie_device->list)) {
1109 list_del_init(&pcie_device->list);
1110 was_on_pcie_device_list = 1;
1111 pcie_device_put(pcie_device);
1114 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1115 if (was_on_pcie_device_list) {
1116 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
1117 pcie_device_put(pcie_device);
1122 * _scsih_pcie_device_add - add pcie_device object
1123 * @ioc: per adapter object
1124 * @pcie_device: pcie_device object
1126 * This is added to the pcie_device_list link list.
1129 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc,
1130 struct _pcie_device *pcie_device)
1132 unsigned long flags;
1135 ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1137 pcie_device->handle, (u64)pcie_device->wwid));
1138 if (pcie_device->enclosure_handle != 0)
1140 ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1142 (u64)pcie_device->enclosure_logical_id,
1143 pcie_device->slot));
1144 if (pcie_device->connector_name[0] != '\0')
1146 ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n",
1147 __func__, pcie_device->enclosure_level,
1148 pcie_device->connector_name));
1150 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1151 pcie_device_get(pcie_device);
1152 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
1153 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1155 if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) {
1156 _scsih_pcie_device_remove(ioc, pcie_device);
1157 } else if (!pcie_device->starget) {
1158 if (!ioc->is_driver_loading) {
1159 /*TODO-- Need to find out whether this condition will occur or not*/
1160 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1163 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1167 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1168 * @ioc: per adapter object
1169 * @pcie_device: the pcie_device object
1170 * Context: This function will acquire ioc->pcie_device_lock.
1172 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1175 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc,
1176 struct _pcie_device *pcie_device)
1178 unsigned long flags;
1181 ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1183 pcie_device->handle, (u64)pcie_device->wwid));
1184 if (pcie_device->enclosure_handle != 0)
1186 ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1188 (u64)pcie_device->enclosure_logical_id,
1189 pcie_device->slot));
1190 if (pcie_device->connector_name[0] != '\0')
1192 ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n",
1193 __func__, pcie_device->enclosure_level,
1194 pcie_device->connector_name));
1196 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1197 pcie_device_get(pcie_device);
1198 list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list);
1199 _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL);
1200 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1203 * _scsih_raid_device_find_by_id - raid device search
1204 * @ioc: per adapter object
1205 * @id: sas device target id
1206 * @channel: sas device channel
1207 * Context: Calling function should acquire ioc->raid_device_lock
1209 * This searches for raid_device based on target id, then return raid_device
1212 static struct _raid_device *
1213 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
1215 struct _raid_device *raid_device, *r;
1218 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1219 if (raid_device->id == id && raid_device->channel == channel) {
1230 * mpt3sas_raid_device_find_by_handle - raid device search
1231 * @ioc: per adapter object
1232 * @handle: sas device handle (assigned by firmware)
1233 * Context: Calling function should acquire ioc->raid_device_lock
1235 * This searches for raid_device based on handle, then return raid_device
1238 struct _raid_device *
1239 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1241 struct _raid_device *raid_device, *r;
1244 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1245 if (raid_device->handle != handle)
1256 * _scsih_raid_device_find_by_wwid - raid device search
1257 * @ioc: per adapter object
1259 * Context: Calling function should acquire ioc->raid_device_lock
1261 * This searches for raid_device based on wwid, then return raid_device
1264 static struct _raid_device *
1265 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
1267 struct _raid_device *raid_device, *r;
1270 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1271 if (raid_device->wwid != wwid)
1282 * _scsih_raid_device_add - add raid_device object
1283 * @ioc: per adapter object
1284 * @raid_device: raid_device object
1286 * This is added to the raid_device_list link list.
1289 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
1290 struct _raid_device *raid_device)
1292 unsigned long flags;
1295 ioc_info(ioc, "%s: handle(0x%04x), wwid(0x%016llx)\n",
1297 raid_device->handle, (u64)raid_device->wwid));
1299 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1300 list_add_tail(&raid_device->list, &ioc->raid_device_list);
1301 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1305 * _scsih_raid_device_remove - delete raid_device object
1306 * @ioc: per adapter object
1307 * @raid_device: raid_device object
1311 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
1312 struct _raid_device *raid_device)
1314 unsigned long flags;
1316 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1317 list_del(&raid_device->list);
1319 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1323 * mpt3sas_scsih_expander_find_by_handle - expander device search
1324 * @ioc: per adapter object
1325 * @handle: expander handle (assigned by firmware)
1326 * Context: Calling function should acquire ioc->sas_device_lock
1328 * This searches for expander device based on handle, then returns the
1332 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1334 struct _sas_node *sas_expander, *r;
1337 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1338 if (sas_expander->handle != handle)
1348 * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
1349 * @ioc: per adapter object
1350 * @handle: enclosure handle (assigned by firmware)
1351 * Context: Calling function should acquire ioc->sas_device_lock
1353 * This searches for enclosure device based on handle, then returns the
1356 static struct _enclosure_node *
1357 mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1359 struct _enclosure_node *enclosure_dev, *r;
1362 list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) {
1363 if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle)
1372 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1373 * @ioc: per adapter object
1374 * @sas_address: sas address
1375 * Context: Calling function should acquire ioc->sas_node_lock.
1377 * This searches for expander device based on sas_address, then returns the
1381 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1384 struct _sas_node *sas_expander, *r;
1387 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1388 if (sas_expander->sas_address != sas_address)
1398 * _scsih_expander_node_add - insert expander device to the list.
1399 * @ioc: per adapter object
1400 * @sas_expander: the sas_device object
1401 * Context: This function will acquire ioc->sas_node_lock.
1403 * Adding new object to the ioc->sas_expander_list.
1406 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1407 struct _sas_node *sas_expander)
1409 unsigned long flags;
1411 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1412 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1413 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1417 * _scsih_is_end_device - determines if device is an end device
1418 * @device_info: bitfield providing information about the device.
1421 * Return: 1 if end device.
1424 _scsih_is_end_device(u32 device_info)
1426 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1427 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1428 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1429 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1436 * _scsih_is_nvme_device - determines if device is an nvme device
1437 * @device_info: bitfield providing information about the device.
1440 * Return: 1 if nvme device.
1443 _scsih_is_nvme_device(u32 device_info)
1445 if ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE)
1446 == MPI26_PCIE_DEVINFO_NVME)
1453 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1454 * @ioc: per adapter object
1455 * @smid: system request message index
1457 * Return: the smid stored scmd pointer.
1458 * Then will dereference the stored scmd pointer.
1461 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1463 struct scsi_cmnd *scmd = NULL;
1464 struct scsiio_tracker *st;
1467 smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
1468 u32 unique_tag = smid - 1;
1470 scmd = scsi_host_find_tag(ioc->shost, unique_tag);
1472 st = scsi_cmd_priv(scmd);
1473 if (st->cb_idx == 0xFF || st->smid == 0)
1481 * scsih_change_queue_depth - setting device queue depth
1482 * @sdev: scsi device struct
1483 * @qdepth: requested queue depth
1485 * Return: queue depth.
1488 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1490 struct Scsi_Host *shost = sdev->host;
1492 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1493 struct MPT3SAS_DEVICE *sas_device_priv_data;
1494 struct MPT3SAS_TARGET *sas_target_priv_data;
1495 struct _sas_device *sas_device;
1496 unsigned long flags;
1498 max_depth = shost->can_queue;
1500 /* limit max device queue for SATA to 32 */
1501 sas_device_priv_data = sdev->hostdata;
1502 if (!sas_device_priv_data)
1504 sas_target_priv_data = sas_device_priv_data->sas_target;
1505 if (!sas_target_priv_data)
1507 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1510 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1511 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1513 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1514 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1516 sas_device_put(sas_device);
1518 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1522 if (!sdev->tagged_supported)
1524 if (qdepth > max_depth)
1526 return scsi_change_queue_depth(sdev, qdepth);
1530 * scsih_target_alloc - target add routine
1531 * @starget: scsi target struct
1533 * Return: 0 if ok. Any other return is assumed to be an error and
1534 * the device is ignored.
1537 scsih_target_alloc(struct scsi_target *starget)
1539 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1540 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1541 struct MPT3SAS_TARGET *sas_target_priv_data;
1542 struct _sas_device *sas_device;
1543 struct _raid_device *raid_device;
1544 struct _pcie_device *pcie_device;
1545 unsigned long flags;
1546 struct sas_rphy *rphy;
1548 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1550 if (!sas_target_priv_data)
1553 starget->hostdata = sas_target_priv_data;
1554 sas_target_priv_data->starget = starget;
1555 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1558 if (starget->channel == RAID_CHANNEL) {
1559 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1560 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1563 sas_target_priv_data->handle = raid_device->handle;
1564 sas_target_priv_data->sas_address = raid_device->wwid;
1565 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1566 if (ioc->is_warpdrive)
1567 sas_target_priv_data->raid_device = raid_device;
1568 raid_device->starget = starget;
1570 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1575 if (starget->channel == PCIE_CHANNEL) {
1576 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1577 pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id,
1580 sas_target_priv_data->handle = pcie_device->handle;
1581 sas_target_priv_data->sas_address = pcie_device->wwid;
1582 sas_target_priv_data->pcie_dev = pcie_device;
1583 pcie_device->starget = starget;
1584 pcie_device->id = starget->id;
1585 pcie_device->channel = starget->channel;
1586 sas_target_priv_data->flags |=
1587 MPT_TARGET_FLAGS_PCIE_DEVICE;
1588 if (pcie_device->fast_path)
1589 sas_target_priv_data->flags |=
1590 MPT_TARGET_FASTPATH_IO;
1592 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1596 /* sas/sata devices */
1597 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1598 rphy = dev_to_rphy(starget->dev.parent);
1599 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1600 rphy->identify.sas_address);
1603 sas_target_priv_data->handle = sas_device->handle;
1604 sas_target_priv_data->sas_address = sas_device->sas_address;
1605 sas_target_priv_data->sas_dev = sas_device;
1606 sas_device->starget = starget;
1607 sas_device->id = starget->id;
1608 sas_device->channel = starget->channel;
1609 if (test_bit(sas_device->handle, ioc->pd_handles))
1610 sas_target_priv_data->flags |=
1611 MPT_TARGET_FLAGS_RAID_COMPONENT;
1612 if (sas_device->fast_path)
1613 sas_target_priv_data->flags |=
1614 MPT_TARGET_FASTPATH_IO;
1616 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1622 * scsih_target_destroy - target destroy routine
1623 * @starget: scsi target struct
1626 scsih_target_destroy(struct scsi_target *starget)
1628 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1629 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1630 struct MPT3SAS_TARGET *sas_target_priv_data;
1631 struct _sas_device *sas_device;
1632 struct _raid_device *raid_device;
1633 struct _pcie_device *pcie_device;
1634 unsigned long flags;
1636 sas_target_priv_data = starget->hostdata;
1637 if (!sas_target_priv_data)
1640 if (starget->channel == RAID_CHANNEL) {
1641 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1642 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1645 raid_device->starget = NULL;
1646 raid_device->sdev = NULL;
1648 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1652 if (starget->channel == PCIE_CHANNEL) {
1653 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1654 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1655 sas_target_priv_data);
1656 if (pcie_device && (pcie_device->starget == starget) &&
1657 (pcie_device->id == starget->id) &&
1658 (pcie_device->channel == starget->channel))
1659 pcie_device->starget = NULL;
1663 * Corresponding get() is in _scsih_target_alloc()
1665 sas_target_priv_data->pcie_dev = NULL;
1666 pcie_device_put(pcie_device);
1667 pcie_device_put(pcie_device);
1669 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1673 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1674 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1675 if (sas_device && (sas_device->starget == starget) &&
1676 (sas_device->id == starget->id) &&
1677 (sas_device->channel == starget->channel))
1678 sas_device->starget = NULL;
1682 * Corresponding get() is in _scsih_target_alloc()
1684 sas_target_priv_data->sas_dev = NULL;
1685 sas_device_put(sas_device);
1687 sas_device_put(sas_device);
1689 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1692 kfree(sas_target_priv_data);
1693 starget->hostdata = NULL;
1697 * scsih_slave_alloc - device add routine
1698 * @sdev: scsi device struct
1700 * Return: 0 if ok. Any other return is assumed to be an error and
1701 * the device is ignored.
1704 scsih_slave_alloc(struct scsi_device *sdev)
1706 struct Scsi_Host *shost;
1707 struct MPT3SAS_ADAPTER *ioc;
1708 struct MPT3SAS_TARGET *sas_target_priv_data;
1709 struct MPT3SAS_DEVICE *sas_device_priv_data;
1710 struct scsi_target *starget;
1711 struct _raid_device *raid_device;
1712 struct _sas_device *sas_device;
1713 struct _pcie_device *pcie_device;
1714 unsigned long flags;
1716 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1718 if (!sas_device_priv_data)
1721 sas_device_priv_data->lun = sdev->lun;
1722 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1724 starget = scsi_target(sdev);
1725 sas_target_priv_data = starget->hostdata;
1726 sas_target_priv_data->num_luns++;
1727 sas_device_priv_data->sas_target = sas_target_priv_data;
1728 sdev->hostdata = sas_device_priv_data;
1729 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1730 sdev->no_uld_attach = 1;
1732 shost = dev_to_shost(&starget->dev);
1733 ioc = shost_priv(shost);
1734 if (starget->channel == RAID_CHANNEL) {
1735 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1736 raid_device = _scsih_raid_device_find_by_id(ioc,
1737 starget->id, starget->channel);
1739 raid_device->sdev = sdev; /* raid is single lun */
1740 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1742 if (starget->channel == PCIE_CHANNEL) {
1743 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1744 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
1745 sas_target_priv_data->sas_address);
1746 if (pcie_device && (pcie_device->starget == NULL)) {
1747 sdev_printk(KERN_INFO, sdev,
1748 "%s : pcie_device->starget set to starget @ %d\n",
1749 __func__, __LINE__);
1750 pcie_device->starget = starget;
1754 pcie_device_put(pcie_device);
1755 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1757 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1758 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1759 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1760 sas_target_priv_data->sas_address);
1761 if (sas_device && (sas_device->starget == NULL)) {
1762 sdev_printk(KERN_INFO, sdev,
1763 "%s : sas_device->starget set to starget @ %d\n",
1764 __func__, __LINE__);
1765 sas_device->starget = starget;
1769 sas_device_put(sas_device);
1771 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1778 * scsih_slave_destroy - device destroy routine
1779 * @sdev: scsi device struct
1782 scsih_slave_destroy(struct scsi_device *sdev)
1784 struct MPT3SAS_TARGET *sas_target_priv_data;
1785 struct scsi_target *starget;
1786 struct Scsi_Host *shost;
1787 struct MPT3SAS_ADAPTER *ioc;
1788 struct _sas_device *sas_device;
1789 struct _pcie_device *pcie_device;
1790 unsigned long flags;
1792 if (!sdev->hostdata)
1795 starget = scsi_target(sdev);
1796 sas_target_priv_data = starget->hostdata;
1797 sas_target_priv_data->num_luns--;
1799 shost = dev_to_shost(&starget->dev);
1800 ioc = shost_priv(shost);
1802 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
1803 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1804 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1805 sas_target_priv_data);
1806 if (pcie_device && !sas_target_priv_data->num_luns)
1807 pcie_device->starget = NULL;
1810 pcie_device_put(pcie_device);
1812 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1814 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1815 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1816 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1817 sas_target_priv_data);
1818 if (sas_device && !sas_target_priv_data->num_luns)
1819 sas_device->starget = NULL;
1822 sas_device_put(sas_device);
1823 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1826 kfree(sdev->hostdata);
1827 sdev->hostdata = NULL;
1831 * _scsih_display_sata_capabilities - sata capabilities
1832 * @ioc: per adapter object
1833 * @handle: device handle
1834 * @sdev: scsi device struct
1837 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1838 u16 handle, struct scsi_device *sdev)
1840 Mpi2ConfigReply_t mpi_reply;
1841 Mpi2SasDevicePage0_t sas_device_pg0;
1846 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1847 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1848 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1849 __FILE__, __LINE__, __func__);
1853 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1854 MPI2_IOCSTATUS_MASK;
1855 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1856 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1857 __FILE__, __LINE__, __func__);
1861 flags = le16_to_cpu(sas_device_pg0.Flags);
1862 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1864 sdev_printk(KERN_INFO, sdev,
1865 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1866 "sw_preserve(%s)\n",
1867 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1868 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1869 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1871 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1872 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1873 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1877 * raid transport support -
1878 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1879 * unloading the driver followed by a load - I believe that the subroutine
1880 * raid_class_release() is not cleaning up properly.
1884 * scsih_is_raid - return boolean indicating device is raid volume
1885 * @dev: the device struct object
1888 scsih_is_raid(struct device *dev)
1890 struct scsi_device *sdev = to_scsi_device(dev);
1891 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1893 if (ioc->is_warpdrive)
1895 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1899 scsih_is_nvme(struct device *dev)
1901 struct scsi_device *sdev = to_scsi_device(dev);
1903 return (sdev->channel == PCIE_CHANNEL) ? 1 : 0;
1907 * scsih_get_resync - get raid volume resync percent complete
1908 * @dev: the device struct object
1911 scsih_get_resync(struct device *dev)
1913 struct scsi_device *sdev = to_scsi_device(dev);
1914 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1915 static struct _raid_device *raid_device;
1916 unsigned long flags;
1917 Mpi2RaidVolPage0_t vol_pg0;
1918 Mpi2ConfigReply_t mpi_reply;
1919 u32 volume_status_flags;
1920 u8 percent_complete;
1923 percent_complete = 0;
1925 if (ioc->is_warpdrive)
1928 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1929 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1932 handle = raid_device->handle;
1933 percent_complete = raid_device->percent_complete;
1935 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1940 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1941 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1942 sizeof(Mpi2RaidVolPage0_t))) {
1943 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1944 __FILE__, __LINE__, __func__);
1945 percent_complete = 0;
1949 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1950 if (!(volume_status_flags &
1951 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1952 percent_complete = 0;
1956 switch (ioc->hba_mpi_version_belonged) {
1958 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1962 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1968 * scsih_get_state - get raid volume level
1969 * @dev: the device struct object
1972 scsih_get_state(struct device *dev)
1974 struct scsi_device *sdev = to_scsi_device(dev);
1975 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1976 static struct _raid_device *raid_device;
1977 unsigned long flags;
1978 Mpi2RaidVolPage0_t vol_pg0;
1979 Mpi2ConfigReply_t mpi_reply;
1981 enum raid_state state = RAID_STATE_UNKNOWN;
1984 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1985 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1988 handle = raid_device->handle;
1989 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1994 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1995 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1996 sizeof(Mpi2RaidVolPage0_t))) {
1997 ioc_err(ioc, "failure at %s:%d/%s()!\n",
1998 __FILE__, __LINE__, __func__);
2002 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
2003 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
2004 state = RAID_STATE_RESYNCING;
2008 switch (vol_pg0.VolumeState) {
2009 case MPI2_RAID_VOL_STATE_OPTIMAL:
2010 case MPI2_RAID_VOL_STATE_ONLINE:
2011 state = RAID_STATE_ACTIVE;
2013 case MPI2_RAID_VOL_STATE_DEGRADED:
2014 state = RAID_STATE_DEGRADED;
2016 case MPI2_RAID_VOL_STATE_FAILED:
2017 case MPI2_RAID_VOL_STATE_MISSING:
2018 state = RAID_STATE_OFFLINE;
2022 switch (ioc->hba_mpi_version_belonged) {
2024 raid_set_state(mpt2sas_raid_template, dev, state);
2028 raid_set_state(mpt3sas_raid_template, dev, state);
2034 * _scsih_set_level - set raid level
2036 * @sdev: scsi device struct
2037 * @volume_type: volume type
2040 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
2041 struct scsi_device *sdev, u8 volume_type)
2043 enum raid_level level = RAID_LEVEL_UNKNOWN;
2045 switch (volume_type) {
2046 case MPI2_RAID_VOL_TYPE_RAID0:
2047 level = RAID_LEVEL_0;
2049 case MPI2_RAID_VOL_TYPE_RAID10:
2050 level = RAID_LEVEL_10;
2052 case MPI2_RAID_VOL_TYPE_RAID1E:
2053 level = RAID_LEVEL_1E;
2055 case MPI2_RAID_VOL_TYPE_RAID1:
2056 level = RAID_LEVEL_1;
2060 switch (ioc->hba_mpi_version_belonged) {
2062 raid_set_level(mpt2sas_raid_template,
2063 &sdev->sdev_gendev, level);
2067 raid_set_level(mpt3sas_raid_template,
2068 &sdev->sdev_gendev, level);
2075 * _scsih_get_volume_capabilities - volume capabilities
2076 * @ioc: per adapter object
2077 * @raid_device: the raid_device object
2079 * Return: 0 for success, else 1
2082 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
2083 struct _raid_device *raid_device)
2085 Mpi2RaidVolPage0_t *vol_pg0;
2086 Mpi2RaidPhysDiskPage0_t pd_pg0;
2087 Mpi2SasDevicePage0_t sas_device_pg0;
2088 Mpi2ConfigReply_t mpi_reply;
2092 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
2093 &num_pds)) || !num_pds) {
2095 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2096 __FILE__, __LINE__, __func__));
2100 raid_device->num_pds = num_pds;
2101 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
2102 sizeof(Mpi2RaidVol0PhysDisk_t));
2103 vol_pg0 = kzalloc(sz, GFP_KERNEL);
2106 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2107 __FILE__, __LINE__, __func__));
2111 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
2112 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
2114 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2115 __FILE__, __LINE__, __func__));
2120 raid_device->volume_type = vol_pg0->VolumeType;
2122 /* figure out what the underlying devices are by
2123 * obtaining the device_info bits for the 1st device
2125 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
2126 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
2127 vol_pg0->PhysDisk[0].PhysDiskNum))) {
2128 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
2129 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
2130 le16_to_cpu(pd_pg0.DevHandle)))) {
2131 raid_device->device_info =
2132 le32_to_cpu(sas_device_pg0.DeviceInfo);
2141 * _scsih_enable_tlr - setting TLR flags
2142 * @ioc: per adapter object
2143 * @sdev: scsi device struct
2145 * Enabling Transaction Layer Retries for tape devices when
2146 * vpd page 0x90 is present
2150 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
2154 if (sdev->type != TYPE_TAPE)
2157 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2160 sas_enable_tlr(sdev);
2161 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2162 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2168 * scsih_slave_configure - device configure routine.
2169 * @sdev: scsi device struct
2171 * Return: 0 if ok. Any other return is assumed to be an error and
2172 * the device is ignored.
2175 scsih_slave_configure(struct scsi_device *sdev)
2177 struct Scsi_Host *shost = sdev->host;
2178 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2179 struct MPT3SAS_DEVICE *sas_device_priv_data;
2180 struct MPT3SAS_TARGET *sas_target_priv_data;
2181 struct _sas_device *sas_device;
2182 struct _pcie_device *pcie_device;
2183 struct _raid_device *raid_device;
2184 unsigned long flags;
2189 u16 handle, volume_handle = 0;
2190 u64 volume_wwid = 0;
2193 sas_device_priv_data = sdev->hostdata;
2194 sas_device_priv_data->configured_lun = 1;
2195 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2196 sas_target_priv_data = sas_device_priv_data->sas_target;
2197 handle = sas_target_priv_data->handle;
2199 /* raid volume handling */
2200 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2202 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2203 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
2204 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2207 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2208 __FILE__, __LINE__, __func__));
2212 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2214 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2215 __FILE__, __LINE__, __func__));
2220 * WARPDRIVE: Initialize the required data for Direct IO
2222 mpt3sas_init_warpdrive_properties(ioc, raid_device);
2224 /* RAID Queue Depth Support
2225 * IS volume = underlying qdepth of drive type, either
2226 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2227 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2229 if (raid_device->device_info &
2230 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2231 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2234 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2235 if (raid_device->device_info &
2236 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2242 switch (raid_device->volume_type) {
2243 case MPI2_RAID_VOL_TYPE_RAID0:
2246 case MPI2_RAID_VOL_TYPE_RAID1E:
2247 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2248 if (ioc->manu_pg10.OEMIdentifier &&
2249 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2250 MFG10_GF0_R10_DISPLAY) &&
2251 !(raid_device->num_pds % 2))
2256 case MPI2_RAID_VOL_TYPE_RAID1:
2257 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2260 case MPI2_RAID_VOL_TYPE_RAID10:
2261 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2264 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2266 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2271 if (!ioc->hide_ir_msg)
2272 sdev_printk(KERN_INFO, sdev,
2273 "%s: handle(0x%04x), wwid(0x%016llx),"
2274 " pd_count(%d), type(%s)\n",
2275 r_level, raid_device->handle,
2276 (unsigned long long)raid_device->wwid,
2277 raid_device->num_pds, ds);
2279 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
2280 blk_queue_max_hw_sectors(sdev->request_queue,
2281 MPT3SAS_RAID_MAX_SECTORS);
2282 sdev_printk(KERN_INFO, sdev,
2283 "Set queue's max_sector to: %u\n",
2284 MPT3SAS_RAID_MAX_SECTORS);
2287 scsih_change_queue_depth(sdev, qdepth);
2289 /* raid transport support */
2290 if (!ioc->is_warpdrive)
2291 _scsih_set_level(ioc, sdev, raid_device->volume_type);
2295 /* non-raid handling */
2296 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2297 if (mpt3sas_config_get_volume_handle(ioc, handle,
2300 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2301 __FILE__, __LINE__, __func__));
2304 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
2305 volume_handle, &volume_wwid)) {
2307 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2308 __FILE__, __LINE__, __func__));
2314 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2315 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2316 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
2317 sas_device_priv_data->sas_target->sas_address);
2319 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2321 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2322 __FILE__, __LINE__, __func__));
2326 qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
2328 sdev_printk(KERN_INFO, sdev,
2329 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2330 ds, handle, (unsigned long long)pcie_device->wwid,
2331 pcie_device->port_num);
2332 if (pcie_device->enclosure_handle != 0)
2333 sdev_printk(KERN_INFO, sdev,
2334 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2336 (unsigned long long)pcie_device->enclosure_logical_id,
2338 if (pcie_device->connector_name[0] != '\0')
2339 sdev_printk(KERN_INFO, sdev,
2340 "%s: enclosure level(0x%04x),"
2341 "connector name( %s)\n", ds,
2342 pcie_device->enclosure_level,
2343 pcie_device->connector_name);
2345 if (pcie_device->nvme_mdts)
2346 blk_queue_max_hw_sectors(sdev->request_queue,
2347 pcie_device->nvme_mdts/512);
2349 pcie_device_put(pcie_device);
2350 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2351 scsih_change_queue_depth(sdev, qdepth);
2352 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2353 ** merged and can eliminate holes created during merging
2356 blk_queue_flag_set(QUEUE_FLAG_NOMERGES,
2357 sdev->request_queue);
2358 blk_queue_virt_boundary(sdev->request_queue,
2359 ioc->page_size - 1);
2363 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2364 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
2365 sas_device_priv_data->sas_target->sas_address);
2367 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2369 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2370 __FILE__, __LINE__, __func__));
2374 sas_device->volume_handle = volume_handle;
2375 sas_device->volume_wwid = volume_wwid;
2376 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2377 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2379 if (sas_device->device_info &
2380 MPI2_SAS_DEVICE_INFO_SEP) {
2381 sdev_printk(KERN_WARNING, sdev,
2382 "set ignore_delay_remove for handle(0x%04x)\n",
2383 sas_device_priv_data->sas_target->handle);
2384 sas_device_priv_data->ignore_delay_remove = 1;
2389 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2390 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2392 else if (sas_device->device_info &
2393 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2397 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
2398 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2399 ds, handle, (unsigned long long)sas_device->sas_address,
2400 sas_device->phy, (unsigned long long)sas_device->device_name);
2402 _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL);
2404 sas_device_put(sas_device);
2405 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2408 _scsih_display_sata_capabilities(ioc, handle, sdev);
2411 scsih_change_queue_depth(sdev, qdepth);
2414 sas_read_port_mode_page(sdev);
2415 _scsih_enable_tlr(ioc, sdev);
2422 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2423 * @sdev: scsi device struct
2424 * @bdev: pointer to block device context
2425 * @capacity: device size (in 512 byte sectors)
2426 * @params: three element array to place output:
2427 * params[0] number of heads (max 255)
2428 * params[1] number of sectors (max 63)
2429 * params[2] number of cylinders
2432 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2433 sector_t capacity, int params[])
2443 dummy = heads * sectors;
2444 cylinders = capacity;
2445 sector_div(cylinders, dummy);
2448 * Handle extended translation size for logical drives
2451 if ((ulong)capacity >= 0x200000) {
2454 dummy = heads * sectors;
2455 cylinders = capacity;
2456 sector_div(cylinders, dummy);
2461 params[1] = sectors;
2462 params[2] = cylinders;
2468 * _scsih_response_code - translation of device response code
2469 * @ioc: per adapter object
2470 * @response_code: response code returned by the device
2473 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2477 switch (response_code) {
2478 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2479 desc = "task management request completed";
2481 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2482 desc = "invalid frame";
2484 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2485 desc = "task management request not supported";
2487 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2488 desc = "task management request failed";
2490 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2491 desc = "task management request succeeded";
2493 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2494 desc = "invalid lun";
2497 desc = "overlapped tag attempted";
2499 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2500 desc = "task queued, however not sent to target";
2506 ioc_warn(ioc, "response_code(0x%01x): %s\n", response_code, desc);
2510 * _scsih_tm_done - tm completion routine
2511 * @ioc: per adapter object
2512 * @smid: system request message index
2513 * @msix_index: MSIX table index supplied by the OS
2514 * @reply: reply message frame(lower 32bit addr)
2517 * The callback handler when using scsih_issue_tm.
2519 * Return: 1 meaning mf should be freed from _base_interrupt
2520 * 0 means the mf is freed from this function.
2523 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2525 MPI2DefaultReply_t *mpi_reply;
2527 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2529 if (ioc->tm_cmds.smid != smid)
2531 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2532 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2534 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2535 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2537 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2538 complete(&ioc->tm_cmds.done);
2543 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2544 * @ioc: per adapter object
2545 * @handle: device handle
2547 * During taskmangement request, we need to freeze the device queue.
2550 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2552 struct MPT3SAS_DEVICE *sas_device_priv_data;
2553 struct scsi_device *sdev;
2556 shost_for_each_device(sdev, ioc->shost) {
2559 sas_device_priv_data = sdev->hostdata;
2560 if (!sas_device_priv_data)
2562 if (sas_device_priv_data->sas_target->handle == handle) {
2563 sas_device_priv_data->sas_target->tm_busy = 1;
2565 ioc->ignore_loginfos = 1;
2571 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2572 * @ioc: per adapter object
2573 * @handle: device handle
2575 * During taskmangement request, we need to freeze the device queue.
2578 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2580 struct MPT3SAS_DEVICE *sas_device_priv_data;
2581 struct scsi_device *sdev;
2584 shost_for_each_device(sdev, ioc->shost) {
2587 sas_device_priv_data = sdev->hostdata;
2588 if (!sas_device_priv_data)
2590 if (sas_device_priv_data->sas_target->handle == handle) {
2591 sas_device_priv_data->sas_target->tm_busy = 0;
2593 ioc->ignore_loginfos = 0;
2599 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2600 * @ioc: per adapter struct
2601 * @handle: device handle
2603 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2604 * @smid_task: smid assigned to the task
2605 * @msix_task: MSIX table index supplied by the OS
2606 * @timeout: timeout in seconds
2607 * @tr_method: Target Reset Method
2610 * A generic API for sending task management requests to firmware.
2612 * The callback index is set inside `ioc->tm_cb_idx`.
2613 * The caller is responsible to check for outstanding commands.
2615 * Return: SUCCESS or FAILED.
2618 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, u64 lun,
2619 u8 type, u16 smid_task, u16 msix_task, u8 timeout, u8 tr_method)
2621 Mpi2SCSITaskManagementRequest_t *mpi_request;
2622 Mpi2SCSITaskManagementReply_t *mpi_reply;
2627 lockdep_assert_held(&ioc->tm_cmds.mutex);
2629 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2630 ioc_info(ioc, "%s: tm_cmd busy!!!\n", __func__);
2634 if (ioc->shost_recovery || ioc->remove_host ||
2635 ioc->pci_error_recovery) {
2636 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
2640 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2641 if (ioc_state & MPI2_DOORBELL_USED) {
2642 dhsprintk(ioc, ioc_info(ioc, "unexpected doorbell active!\n"));
2643 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2644 return (!rc) ? SUCCESS : FAILED;
2647 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2648 mpt3sas_base_fault_info(ioc, ioc_state &
2649 MPI2_DOORBELL_DATA_MASK);
2650 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2651 return (!rc) ? SUCCESS : FAILED;
2654 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2656 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
2661 ioc_info(ioc, "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
2662 handle, type, smid_task, timeout, tr_method));
2663 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2664 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2665 ioc->tm_cmds.smid = smid;
2666 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2667 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2668 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2669 mpi_request->DevHandle = cpu_to_le16(handle);
2670 mpi_request->TaskType = type;
2671 mpi_request->MsgFlags = tr_method;
2672 mpi_request->TaskMID = cpu_to_le16(smid_task);
2673 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2674 mpt3sas_scsih_set_tm_flag(ioc, handle);
2675 init_completion(&ioc->tm_cmds.done);
2676 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2677 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2678 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2679 if (mpt3sas_base_check_cmd_timeout(ioc,
2680 ioc->tm_cmds.status, mpi_request,
2681 sizeof(Mpi2SCSITaskManagementRequest_t)/4)) {
2682 rc = mpt3sas_base_hard_reset_handler(ioc,
2684 rc = (!rc) ? SUCCESS : FAILED;
2689 /* sync IRQs in case those were busy during flush. */
2690 mpt3sas_base_sync_reply_irqs(ioc);
2692 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2693 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2694 mpi_reply = ioc->tm_cmds.reply;
2696 ioc_info(ioc, "complete tm: ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2697 le16_to_cpu(mpi_reply->IOCStatus),
2698 le32_to_cpu(mpi_reply->IOCLogInfo),
2699 le32_to_cpu(mpi_reply->TerminationCount)));
2700 if (ioc->logging_level & MPT_DEBUG_TM) {
2701 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2702 if (mpi_reply->IOCStatus)
2703 _debug_dump_mf(mpi_request,
2704 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2710 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2711 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2715 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2716 u64 lun, u8 type, u16 smid_task, u16 msix_task,
2717 u8 timeout, u8 tr_method)
2721 mutex_lock(&ioc->tm_cmds.mutex);
2722 ret = mpt3sas_scsih_issue_tm(ioc, handle, lun, type, smid_task,
2723 msix_task, timeout, tr_method);
2724 mutex_unlock(&ioc->tm_cmds.mutex);
2730 * _scsih_tm_display_info - displays info about the device
2731 * @ioc: per adapter struct
2732 * @scmd: pointer to scsi command object
2734 * Called by task management callback handlers.
2737 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2739 struct scsi_target *starget = scmd->device->sdev_target;
2740 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2741 struct _sas_device *sas_device = NULL;
2742 struct _pcie_device *pcie_device = NULL;
2743 unsigned long flags;
2744 char *device_str = NULL;
2748 if (ioc->hide_ir_msg)
2749 device_str = "WarpDrive";
2751 device_str = "volume";
2753 scsi_print_command(scmd);
2754 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2755 starget_printk(KERN_INFO, starget,
2756 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2757 device_str, priv_target->handle,
2758 device_str, (unsigned long long)priv_target->sas_address);
2760 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2761 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2762 pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target);
2764 starget_printk(KERN_INFO, starget,
2765 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2766 pcie_device->handle,
2767 (unsigned long long)pcie_device->wwid,
2768 pcie_device->port_num);
2769 if (pcie_device->enclosure_handle != 0)
2770 starget_printk(KERN_INFO, starget,
2771 "enclosure logical id(0x%016llx), slot(%d)\n",
2772 (unsigned long long)
2773 pcie_device->enclosure_logical_id,
2775 if (pcie_device->connector_name[0] != '\0')
2776 starget_printk(KERN_INFO, starget,
2777 "enclosure level(0x%04x), connector name( %s)\n",
2778 pcie_device->enclosure_level,
2779 pcie_device->connector_name);
2780 pcie_device_put(pcie_device);
2782 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2785 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2786 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2788 if (priv_target->flags &
2789 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2790 starget_printk(KERN_INFO, starget,
2791 "volume handle(0x%04x), "
2792 "volume wwid(0x%016llx)\n",
2793 sas_device->volume_handle,
2794 (unsigned long long)sas_device->volume_wwid);
2796 starget_printk(KERN_INFO, starget,
2797 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2799 (unsigned long long)sas_device->sas_address,
2802 _scsih_display_enclosure_chassis_info(NULL, sas_device,
2805 sas_device_put(sas_device);
2807 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2812 * scsih_abort - eh threads main abort routine
2813 * @scmd: pointer to scsi command object
2815 * Return: SUCCESS if command aborted else FAILED
2818 scsih_abort(struct scsi_cmnd *scmd)
2820 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2821 struct MPT3SAS_DEVICE *sas_device_priv_data;
2822 struct scsiio_tracker *st = scsi_cmd_priv(scmd);
2827 struct _pcie_device *pcie_device = NULL;
2828 sdev_printk(KERN_INFO, scmd->device,
2829 "attempting task abort! scmd(%p)\n", scmd);
2830 _scsih_tm_display_info(ioc, scmd);
2832 sas_device_priv_data = scmd->device->hostdata;
2833 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2835 sdev_printk(KERN_INFO, scmd->device,
2836 "device been deleted! scmd(%p)\n", scmd);
2837 scmd->result = DID_NO_CONNECT << 16;
2838 scmd->scsi_done(scmd);
2843 /* check for completed command */
2844 if (st == NULL || st->cb_idx == 0xFF) {
2845 scmd->result = DID_RESET << 16;
2850 /* for hidden raid components and volumes this is not supported */
2851 if (sas_device_priv_data->sas_target->flags &
2852 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2853 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2854 scmd->result = DID_RESET << 16;
2859 mpt3sas_halt_firmware(ioc);
2861 handle = sas_device_priv_data->sas_target->handle;
2862 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
2863 if (pcie_device && (!ioc->tm_custom_handling))
2864 timeout = ioc->nvme_abort_timeout;
2865 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
2866 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
2867 st->smid, st->msix_io, timeout, 0);
2868 /* Command must be cleared after abort */
2869 if (r == SUCCESS && st->cb_idx != 0xFF)
2872 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2873 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2875 pcie_device_put(pcie_device);
2880 * scsih_dev_reset - eh threads main device reset routine
2881 * @scmd: pointer to scsi command object
2883 * Return: SUCCESS if command aborted else FAILED
2886 scsih_dev_reset(struct scsi_cmnd *scmd)
2888 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2889 struct MPT3SAS_DEVICE *sas_device_priv_data;
2890 struct _sas_device *sas_device = NULL;
2891 struct _pcie_device *pcie_device = NULL;
2897 struct scsi_target *starget = scmd->device->sdev_target;
2898 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2900 sdev_printk(KERN_INFO, scmd->device,
2901 "attempting device reset! scmd(%p)\n", scmd);
2902 _scsih_tm_display_info(ioc, scmd);
2904 sas_device_priv_data = scmd->device->hostdata;
2905 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2907 sdev_printk(KERN_INFO, scmd->device,
2908 "device been deleted! scmd(%p)\n", scmd);
2909 scmd->result = DID_NO_CONNECT << 16;
2910 scmd->scsi_done(scmd);
2915 /* for hidden raid components obtain the volume_handle */
2917 if (sas_device_priv_data->sas_target->flags &
2918 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2919 sas_device = mpt3sas_get_sdev_from_target(ioc,
2922 handle = sas_device->volume_handle;
2924 handle = sas_device_priv_data->sas_target->handle;
2927 scmd->result = DID_RESET << 16;
2932 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
2934 if (pcie_device && (!ioc->tm_custom_handling)) {
2935 tr_timeout = pcie_device->reset_timeout;
2936 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
2938 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
2939 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->lun,
2940 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0,
2941 tr_timeout, tr_method);
2942 /* Check for busy commands after reset */
2943 if (r == SUCCESS && atomic_read(&scmd->device->device_busy))
2946 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2947 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2950 sas_device_put(sas_device);
2952 pcie_device_put(pcie_device);
2958 * scsih_target_reset - eh threads main target reset routine
2959 * @scmd: pointer to scsi command object
2961 * Return: SUCCESS if command aborted else FAILED
2964 scsih_target_reset(struct scsi_cmnd *scmd)
2966 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2967 struct MPT3SAS_DEVICE *sas_device_priv_data;
2968 struct _sas_device *sas_device = NULL;
2969 struct _pcie_device *pcie_device = NULL;
2974 struct scsi_target *starget = scmd->device->sdev_target;
2975 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2977 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2979 _scsih_tm_display_info(ioc, scmd);
2981 sas_device_priv_data = scmd->device->hostdata;
2982 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
2984 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2986 scmd->result = DID_NO_CONNECT << 16;
2987 scmd->scsi_done(scmd);
2992 /* for hidden raid components obtain the volume_handle */
2994 if (sas_device_priv_data->sas_target->flags &
2995 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2996 sas_device = mpt3sas_get_sdev_from_target(ioc,
2999 handle = sas_device->volume_handle;
3001 handle = sas_device_priv_data->sas_target->handle;
3004 scmd->result = DID_RESET << 16;
3009 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
3011 if (pcie_device && (!ioc->tm_custom_handling)) {
3012 tr_timeout = pcie_device->reset_timeout;
3013 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3015 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3016 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, 0,
3017 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0,
3018 tr_timeout, tr_method);
3019 /* Check for busy commands after reset */
3020 if (r == SUCCESS && atomic_read(&starget->target_busy))
3023 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
3024 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3027 sas_device_put(sas_device);
3029 pcie_device_put(pcie_device);
3035 * scsih_host_reset - eh threads main host reset routine
3036 * @scmd: pointer to scsi command object
3038 * Return: SUCCESS if command aborted else FAILED
3041 scsih_host_reset(struct scsi_cmnd *scmd)
3043 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3046 ioc_info(ioc, "attempting host reset! scmd(%p)\n", scmd);
3047 scsi_print_command(scmd);
3049 if (ioc->is_driver_loading || ioc->remove_host) {
3050 ioc_info(ioc, "Blocking the host reset\n");
3055 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3056 r = (retval < 0) ? FAILED : SUCCESS;
3058 ioc_info(ioc, "host reset: %s scmd(%p)\n",
3059 r == SUCCESS ? "SUCCESS" : "FAILED", scmd);
3065 * _scsih_fw_event_add - insert and queue up fw_event
3066 * @ioc: per adapter object
3067 * @fw_event: object describing the event
3068 * Context: This function will acquire ioc->fw_event_lock.
3070 * This adds the firmware event object into link list, then queues it up to
3071 * be processed from user context.
3074 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
3076 unsigned long flags;
3078 if (ioc->firmware_event_thread == NULL)
3081 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3082 fw_event_work_get(fw_event);
3083 INIT_LIST_HEAD(&fw_event->list);
3084 list_add_tail(&fw_event->list, &ioc->fw_event_list);
3085 INIT_WORK(&fw_event->work, _firmware_event_work);
3086 fw_event_work_get(fw_event);
3087 queue_work(ioc->firmware_event_thread, &fw_event->work);
3088 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3092 * _scsih_fw_event_del_from_list - delete fw_event from the list
3093 * @ioc: per adapter object
3094 * @fw_event: object describing the event
3095 * Context: This function will acquire ioc->fw_event_lock.
3097 * If the fw_event is on the fw_event_list, remove it and do a put.
3100 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
3103 unsigned long flags;
3105 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3106 if (!list_empty(&fw_event->list)) {
3107 list_del_init(&fw_event->list);
3108 fw_event_work_put(fw_event);
3110 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3115 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3116 * @ioc: per adapter object
3117 * @event_data: trigger event data
3120 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
3121 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
3123 struct fw_event_work *fw_event;
3126 if (ioc->is_driver_loading)
3128 sz = sizeof(*event_data);
3129 fw_event = alloc_fw_event_work(sz);
3132 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
3133 fw_event->ioc = ioc;
3134 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
3135 _scsih_fw_event_add(ioc, fw_event);
3136 fw_event_work_put(fw_event);
3140 * _scsih_error_recovery_delete_devices - remove devices not responding
3141 * @ioc: per adapter object
3144 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
3146 struct fw_event_work *fw_event;
3148 if (ioc->is_driver_loading)
3150 fw_event = alloc_fw_event_work(0);
3153 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
3154 fw_event->ioc = ioc;
3155 _scsih_fw_event_add(ioc, fw_event);
3156 fw_event_work_put(fw_event);
3160 * mpt3sas_port_enable_complete - port enable completed (fake event)
3161 * @ioc: per adapter object
3164 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
3166 struct fw_event_work *fw_event;
3168 fw_event = alloc_fw_event_work(0);
3171 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
3172 fw_event->ioc = ioc;
3173 _scsih_fw_event_add(ioc, fw_event);
3174 fw_event_work_put(fw_event);
3177 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
3179 unsigned long flags;
3180 struct fw_event_work *fw_event = NULL;
3182 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3183 if (!list_empty(&ioc->fw_event_list)) {
3184 fw_event = list_first_entry(&ioc->fw_event_list,
3185 struct fw_event_work, list);
3186 list_del_init(&fw_event->list);
3188 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3194 * _scsih_fw_event_cleanup_queue - cleanup event queue
3195 * @ioc: per adapter object
3197 * Walk the firmware event queue, either killing timers, or waiting
3198 * for outstanding events to complete
3201 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
3203 struct fw_event_work *fw_event;
3205 if (list_empty(&ioc->fw_event_list) ||
3206 !ioc->firmware_event_thread || in_interrupt())
3209 while ((fw_event = dequeue_next_fw_event(ioc))) {
3211 * Wait on the fw_event to complete. If this returns 1, then
3212 * the event was never executed, and we need a put for the
3213 * reference the work had on the fw_event.
3215 * If it did execute, we wait for it to finish, and the put will
3216 * happen from _firmware_event_work()
3218 if (cancel_work_sync(&fw_event->work))
3219 fw_event_work_put(fw_event);
3221 fw_event_work_put(fw_event);
3226 * _scsih_internal_device_block - block the sdev device
3227 * @sdev: per device object
3228 * @sas_device_priv_data : per device driver private data
3230 * make sure device is blocked without error, if not
3234 _scsih_internal_device_block(struct scsi_device *sdev,
3235 struct MPT3SAS_DEVICE *sas_device_priv_data)
3239 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
3240 sas_device_priv_data->sas_target->handle);
3241 sas_device_priv_data->block = 1;
3243 r = scsi_internal_device_block_nowait(sdev);
3245 sdev_printk(KERN_WARNING, sdev,
3246 "device_block failed with return(%d) for handle(0x%04x)\n",
3247 r, sas_device_priv_data->sas_target->handle);
3251 * _scsih_internal_device_unblock - unblock the sdev device
3252 * @sdev: per device object
3253 * @sas_device_priv_data : per device driver private data
3254 * make sure device is unblocked without error, if not retry
3255 * by blocking and then unblocking
3259 _scsih_internal_device_unblock(struct scsi_device *sdev,
3260 struct MPT3SAS_DEVICE *sas_device_priv_data)
3264 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
3265 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
3266 sas_device_priv_data->block = 0;
3267 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3269 /* The device has been set to SDEV_RUNNING by SD layer during
3270 * device addition but the request queue is still stopped by
3271 * our earlier block call. We need to perform a block again
3272 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3274 sdev_printk(KERN_WARNING, sdev,
3275 "device_unblock failed with return(%d) for handle(0x%04x) "
3276 "performing a block followed by an unblock\n",
3277 r, sas_device_priv_data->sas_target->handle);
3278 sas_device_priv_data->block = 1;
3279 r = scsi_internal_device_block_nowait(sdev);
3281 sdev_printk(KERN_WARNING, sdev, "retried device_block "
3282 "failed with return(%d) for handle(0x%04x)\n",
3283 r, sas_device_priv_data->sas_target->handle);
3285 sas_device_priv_data->block = 0;
3286 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3288 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
3289 " failed with return(%d) for handle(0x%04x)\n",
3290 r, sas_device_priv_data->sas_target->handle);
3295 * _scsih_ublock_io_all_device - unblock every device
3296 * @ioc: per adapter object
3298 * change the device state from block to running
3301 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3303 struct MPT3SAS_DEVICE *sas_device_priv_data;
3304 struct scsi_device *sdev;
3306 shost_for_each_device(sdev, ioc->shost) {
3307 sas_device_priv_data = sdev->hostdata;
3308 if (!sas_device_priv_data)
3310 if (!sas_device_priv_data->block)
3313 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3314 "device_running, handle(0x%04x)\n",
3315 sas_device_priv_data->sas_target->handle));
3316 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
3322 * _scsih_ublock_io_device - prepare device to be deleted
3323 * @ioc: per adapter object
3324 * @sas_address: sas address
3326 * unblock then put device in offline state
3329 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
3331 struct MPT3SAS_DEVICE *sas_device_priv_data;
3332 struct scsi_device *sdev;
3334 shost_for_each_device(sdev, ioc->shost) {
3335 sas_device_priv_data = sdev->hostdata;
3336 if (!sas_device_priv_data)
3338 if (sas_device_priv_data->sas_target->sas_address
3341 if (sas_device_priv_data->block)
3342 _scsih_internal_device_unblock(sdev,
3343 sas_device_priv_data);
3348 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3349 * @ioc: per adapter object
3351 * During device pull we need to appropriately set the sdev state.
3354 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3356 struct MPT3SAS_DEVICE *sas_device_priv_data;
3357 struct scsi_device *sdev;
3359 shost_for_each_device(sdev, ioc->shost) {
3360 sas_device_priv_data = sdev->hostdata;
3361 if (!sas_device_priv_data)
3363 if (sas_device_priv_data->block)
3365 if (sas_device_priv_data->ignore_delay_remove) {
3366 sdev_printk(KERN_INFO, sdev,
3367 "%s skip device_block for SES handle(0x%04x)\n",
3368 __func__, sas_device_priv_data->sas_target->handle);
3371 _scsih_internal_device_block(sdev, sas_device_priv_data);
3376 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3377 * @ioc: per adapter object
3378 * @handle: device handle
3380 * During device pull we need to appropriately set the sdev state.
3383 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3385 struct MPT3SAS_DEVICE *sas_device_priv_data;
3386 struct scsi_device *sdev;
3387 struct _sas_device *sas_device;
3389 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
3391 shost_for_each_device(sdev, ioc->shost) {
3392 sas_device_priv_data = sdev->hostdata;
3393 if (!sas_device_priv_data)
3395 if (sas_device_priv_data->sas_target->handle != handle)
3397 if (sas_device_priv_data->block)
3399 if (sas_device && sas_device->pend_sas_rphy_add)
3401 if (sas_device_priv_data->ignore_delay_remove) {
3402 sdev_printk(KERN_INFO, sdev,
3403 "%s skip device_block for SES handle(0x%04x)\n",
3404 __func__, sas_device_priv_data->sas_target->handle);
3407 _scsih_internal_device_block(sdev, sas_device_priv_data);
3411 sas_device_put(sas_device);
3415 * _scsih_block_io_to_children_attached_to_ex
3416 * @ioc: per adapter object
3417 * @sas_expander: the sas_device object
3419 * This routine set sdev state to SDEV_BLOCK for all devices
3420 * attached to this expander. This function called when expander is
3424 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3425 struct _sas_node *sas_expander)
3427 struct _sas_port *mpt3sas_port;
3428 struct _sas_device *sas_device;
3429 struct _sas_node *expander_sibling;
3430 unsigned long flags;
3435 list_for_each_entry(mpt3sas_port,
3436 &sas_expander->sas_port_list, port_list) {
3437 if (mpt3sas_port->remote_identify.device_type ==
3439 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3440 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3441 mpt3sas_port->remote_identify.sas_address);
3443 set_bit(sas_device->handle,
3444 ioc->blocking_handles);
3445 sas_device_put(sas_device);
3447 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3451 list_for_each_entry(mpt3sas_port,
3452 &sas_expander->sas_port_list, port_list) {
3454 if (mpt3sas_port->remote_identify.device_type ==
3455 SAS_EDGE_EXPANDER_DEVICE ||
3456 mpt3sas_port->remote_identify.device_type ==
3457 SAS_FANOUT_EXPANDER_DEVICE) {
3459 mpt3sas_scsih_expander_find_by_sas_address(
3460 ioc, mpt3sas_port->remote_identify.sas_address);
3461 _scsih_block_io_to_children_attached_to_ex(ioc,
3468 * _scsih_block_io_to_children_attached_directly
3469 * @ioc: per adapter object
3470 * @event_data: topology change event data
3472 * This routine set sdev state to SDEV_BLOCK for all devices
3473 * direct attached during device pull.
3476 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3477 Mpi2EventDataSasTopologyChangeList_t *event_data)
3483 for (i = 0; i < event_data->NumEntries; i++) {
3484 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3487 reason_code = event_data->PHY[i].PhyStatus &
3488 MPI2_EVENT_SAS_TOPO_RC_MASK;
3489 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3490 _scsih_block_io_device(ioc, handle);
3495 * _scsih_block_io_to_pcie_children_attached_directly
3496 * @ioc: per adapter object
3497 * @event_data: topology change event data
3499 * This routine set sdev state to SDEV_BLOCK for all devices
3500 * direct attached during device pull/reconnect.
3503 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3504 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
3510 for (i = 0; i < event_data->NumEntries; i++) {
3512 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
3515 reason_code = event_data->PortEntry[i].PortStatus;
3517 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING)
3518 _scsih_block_io_device(ioc, handle);
3522 * _scsih_tm_tr_send - send task management request
3523 * @ioc: per adapter object
3524 * @handle: device handle
3525 * Context: interrupt time.
3527 * This code is to initiate the device removal handshake protocol
3528 * with controller firmware. This function will issue target reset
3529 * using high priority request queue. It will send a sas iounit
3530 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3532 * This is designed to send muliple task management request at the same
3533 * time to the fifo. If the fifo is full, we will append the request,
3534 * and process it in a future completion.
3537 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3539 Mpi2SCSITaskManagementRequest_t *mpi_request;
3541 struct _sas_device *sas_device = NULL;
3542 struct _pcie_device *pcie_device = NULL;
3543 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3544 u64 sas_address = 0;
3545 unsigned long flags;
3546 struct _tr_list *delayed_tr;
3550 if (ioc->pci_error_recovery) {
3552 ioc_info(ioc, "%s: host in pci error recovery: handle(0x%04x)\n",
3556 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3557 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3559 ioc_info(ioc, "%s: host is not operational: handle(0x%04x)\n",
3564 /* if PD, then return */
3565 if (test_bit(handle, ioc->pd_handles))
3568 clear_bit(handle, ioc->pend_os_device_add);
3570 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3571 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3572 if (sas_device && sas_device->starget &&
3573 sas_device->starget->hostdata) {
3574 sas_target_priv_data = sas_device->starget->hostdata;
3575 sas_target_priv_data->deleted = 1;
3576 sas_address = sas_device->sas_address;
3578 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3580 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
3581 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
3582 if (pcie_device && pcie_device->starget &&
3583 pcie_device->starget->hostdata) {
3584 sas_target_priv_data = pcie_device->starget->hostdata;
3585 sas_target_priv_data->deleted = 1;
3586 sas_address = pcie_device->wwid;
3588 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
3589 if (pcie_device && (!ioc->tm_custom_handling))
3591 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3593 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3595 if (sas_target_priv_data) {
3597 ioc_info(ioc, "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3598 handle, (u64)sas_address));
3600 if (sas_device->enclosure_handle != 0)
3602 ioc_info(ioc, "setting delete flag:enclosure logical id(0x%016llx), slot(%d)\n",
3603 (u64)sas_device->enclosure_logical_id,
3605 if (sas_device->connector_name[0] != '\0')
3607 ioc_info(ioc, "setting delete flag: enclosure level(0x%04x), connector name( %s)\n",
3608 sas_device->enclosure_level,
3609 sas_device->connector_name));
3610 } else if (pcie_device) {
3611 if (pcie_device->enclosure_handle != 0)
3613 ioc_info(ioc, "setting delete flag: logical id(0x%016llx), slot(%d)\n",
3614 (u64)pcie_device->enclosure_logical_id,
3615 pcie_device->slot));
3616 if (pcie_device->connector_name[0] != '\0')
3618 ioc_info(ioc, "setting delete flag:, enclosure level(0x%04x), connector name( %s)\n",
3619 pcie_device->enclosure_level,
3620 pcie_device->connector_name));
3622 _scsih_ublock_io_device(ioc, sas_address);
3623 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3626 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3628 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3631 INIT_LIST_HEAD(&delayed_tr->list);
3632 delayed_tr->handle = handle;
3633 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3635 ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n",
3641 ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3642 handle, smid, ioc->tm_tr_cb_idx));
3643 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3644 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3645 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3646 mpi_request->DevHandle = cpu_to_le16(handle);
3647 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3648 mpi_request->MsgFlags = tr_method;
3649 set_bit(handle, ioc->device_remove_in_progress);
3650 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3651 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3655 sas_device_put(sas_device);
3657 pcie_device_put(pcie_device);
3661 * _scsih_tm_tr_complete -
3662 * @ioc: per adapter object
3663 * @smid: system request message index
3664 * @msix_index: MSIX table index supplied by the OS
3665 * @reply: reply message frame(lower 32bit addr)
3666 * Context: interrupt time.
3668 * This is the target reset completion routine.
3669 * This code is part of the code to initiate the device removal
3670 * handshake protocol with controller firmware.
3671 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3673 * Return: 1 meaning mf should be freed from _base_interrupt
3674 * 0 means the mf is freed from this function.
3677 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3681 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3682 Mpi2SCSITaskManagementReply_t *mpi_reply =
3683 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3684 Mpi2SasIoUnitControlRequest_t *mpi_request;
3687 struct _sc_list *delayed_sc;
3689 if (ioc->pci_error_recovery) {
3691 ioc_info(ioc, "%s: host in pci error recovery\n",
3695 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3696 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3698 ioc_info(ioc, "%s: host is not operational\n",
3702 if (unlikely(!mpi_reply)) {
3703 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
3704 __FILE__, __LINE__, __func__);
3707 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3708 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3709 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3711 ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3713 le16_to_cpu(mpi_reply->DevHandle), smid));
3717 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3719 ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
3720 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3721 le32_to_cpu(mpi_reply->IOCLogInfo),
3722 le32_to_cpu(mpi_reply->TerminationCount)));
3724 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3725 if (!smid_sas_ctrl) {
3726 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3728 return _scsih_check_for_pending_tm(ioc, smid);
3729 INIT_LIST_HEAD(&delayed_sc->list);
3730 delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle);
3731 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3733 ioc_info(ioc, "DELAYED:sc:handle(0x%04x), (open)\n",
3735 return _scsih_check_for_pending_tm(ioc, smid);
3739 ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3740 handle, smid_sas_ctrl, ioc->tm_sas_control_cb_idx));
3741 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3742 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3743 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3744 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3745 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3746 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3748 return _scsih_check_for_pending_tm(ioc, smid);
3753 * _scsih_sas_control_complete - completion routine
3754 * @ioc: per adapter object
3755 * @smid: system request message index
3756 * @msix_index: MSIX table index supplied by the OS
3757 * @reply: reply message frame(lower 32bit addr)
3758 * Context: interrupt time.
3760 * This is the sas iounit control completion routine.
3761 * This code is part of the code to initiate the device removal
3762 * handshake protocol with controller firmware.
3764 * Return: 1 meaning mf should be freed from _base_interrupt
3765 * 0 means the mf is freed from this function.
3768 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3769 u8 msix_index, u32 reply)
3771 Mpi2SasIoUnitControlReply_t *mpi_reply =
3772 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3774 if (likely(mpi_reply)) {
3776 ioc_info(ioc, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3777 le16_to_cpu(mpi_reply->DevHandle), smid,
3778 le16_to_cpu(mpi_reply->IOCStatus),
3779 le32_to_cpu(mpi_reply->IOCLogInfo)));
3780 if (le16_to_cpu(mpi_reply->IOCStatus) ==
3781 MPI2_IOCSTATUS_SUCCESS) {
3782 clear_bit(le16_to_cpu(mpi_reply->DevHandle),
3783 ioc->device_remove_in_progress);
3786 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
3787 __FILE__, __LINE__, __func__);
3789 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3793 * _scsih_tm_tr_volume_send - send target reset request for volumes
3794 * @ioc: per adapter object
3795 * @handle: device handle
3796 * Context: interrupt time.
3798 * This is designed to send muliple task management request at the same
3799 * time to the fifo. If the fifo is full, we will append the request,
3800 * and process it in a future completion.
3803 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3805 Mpi2SCSITaskManagementRequest_t *mpi_request;
3807 struct _tr_list *delayed_tr;
3809 if (ioc->pci_error_recovery) {
3811 ioc_info(ioc, "%s: host reset in progress!\n",
3816 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3818 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3821 INIT_LIST_HEAD(&delayed_tr->list);
3822 delayed_tr->handle = handle;
3823 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3825 ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n",
3831 ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3832 handle, smid, ioc->tm_tr_volume_cb_idx));
3833 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3834 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3835 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3836 mpi_request->DevHandle = cpu_to_le16(handle);
3837 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3838 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3842 * _scsih_tm_volume_tr_complete - target reset completion
3843 * @ioc: per adapter object
3844 * @smid: system request message index
3845 * @msix_index: MSIX table index supplied by the OS
3846 * @reply: reply message frame(lower 32bit addr)
3847 * Context: interrupt time.
3849 * Return: 1 meaning mf should be freed from _base_interrupt
3850 * 0 means the mf is freed from this function.
3853 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3854 u8 msix_index, u32 reply)
3857 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3858 Mpi2SCSITaskManagementReply_t *mpi_reply =
3859 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3861 if (ioc->shost_recovery || ioc->pci_error_recovery) {
3863 ioc_info(ioc, "%s: host reset in progress!\n",
3867 if (unlikely(!mpi_reply)) {
3868 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
3869 __FILE__, __LINE__, __func__);
3873 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3874 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3875 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3877 ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3878 handle, le16_to_cpu(mpi_reply->DevHandle),
3884 ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
3885 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3886 le32_to_cpu(mpi_reply->IOCLogInfo),
3887 le32_to_cpu(mpi_reply->TerminationCount)));
3889 return _scsih_check_for_pending_tm(ioc, smid);
3893 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3894 * @ioc: per adapter object
3895 * @smid: system request message index
3897 * @event_context: used to track events uniquely
3899 * Context - processed in interrupt context.
3902 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event,
3905 Mpi2EventAckRequest_t *ack_request;
3906 int i = smid - ioc->internal_smid;
3907 unsigned long flags;
3909 /* Without releasing the smid just update the
3910 * call back index and reuse the same smid for
3911 * processing this delayed request
3913 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3914 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3915 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3918 ioc_info(ioc, "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3919 le16_to_cpu(event), smid, ioc->base_cb_idx));
3920 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
3921 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
3922 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
3923 ack_request->Event = event;
3924 ack_request->EventContext = event_context;
3925 ack_request->VF_ID = 0; /* TODO */
3926 ack_request->VP_ID = 0;
3927 mpt3sas_base_put_smid_default(ioc, smid);
3931 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3932 * sas_io_unit_ctrl messages
3933 * @ioc: per adapter object
3934 * @smid: system request message index
3935 * @handle: device handle
3937 * Context - processed in interrupt context.
3940 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
3941 u16 smid, u16 handle)
3943 Mpi2SasIoUnitControlRequest_t *mpi_request;
3945 int i = smid - ioc->internal_smid;
3946 unsigned long flags;
3948 if (ioc->remove_host) {
3950 ioc_info(ioc, "%s: host has been removed\n",
3953 } else if (ioc->pci_error_recovery) {
3955 ioc_info(ioc, "%s: host in pci error recovery\n",
3959 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3960 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3962 ioc_info(ioc, "%s: host is not operational\n",
3967 /* Without releasing the smid just update the
3968 * call back index and reuse the same smid for
3969 * processing this delayed request
3971 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3972 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
3973 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3976 ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3977 handle, smid, ioc->tm_sas_control_cb_idx));
3978 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3979 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3980 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3981 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3982 mpi_request->DevHandle = cpu_to_le16(handle);
3983 mpt3sas_base_put_smid_default(ioc, smid);
3987 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3988 * @ioc: per adapter object
3989 * @smid: system request message index
3991 * Context: Executed in interrupt context
3993 * This will check delayed internal messages list, and process the
3996 * Return: 1 meaning mf should be freed from _base_interrupt
3997 * 0 means the mf is freed from this function.
4000 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4002 struct _sc_list *delayed_sc;
4003 struct _event_ack_list *delayed_event_ack;
4005 if (!list_empty(&ioc->delayed_event_ack_list)) {
4006 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
4007 struct _event_ack_list, list);
4008 _scsih_issue_delayed_event_ack(ioc, smid,
4009 delayed_event_ack->Event, delayed_event_ack->EventContext);
4010 list_del(&delayed_event_ack->list);
4011 kfree(delayed_event_ack);
4015 if (!list_empty(&ioc->delayed_sc_list)) {
4016 delayed_sc = list_entry(ioc->delayed_sc_list.next,
4017 struct _sc_list, list);
4018 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
4019 delayed_sc->handle);
4020 list_del(&delayed_sc->list);
4028 * _scsih_check_for_pending_tm - check for pending task management
4029 * @ioc: per adapter object
4030 * @smid: system request message index
4032 * This will check delayed target reset list, and feed the
4035 * Return: 1 meaning mf should be freed from _base_interrupt
4036 * 0 means the mf is freed from this function.
4039 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4041 struct _tr_list *delayed_tr;
4043 if (!list_empty(&ioc->delayed_tr_volume_list)) {
4044 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
4045 struct _tr_list, list);
4046 mpt3sas_base_free_smid(ioc, smid);
4047 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
4048 list_del(&delayed_tr->list);
4053 if (!list_empty(&ioc->delayed_tr_list)) {
4054 delayed_tr = list_entry(ioc->delayed_tr_list.next,
4055 struct _tr_list, list);
4056 mpt3sas_base_free_smid(ioc, smid);
4057 _scsih_tm_tr_send(ioc, delayed_tr->handle);
4058 list_del(&delayed_tr->list);
4067 * _scsih_check_topo_delete_events - sanity check on topo events
4068 * @ioc: per adapter object
4069 * @event_data: the event data payload
4071 * This routine added to better handle cable breaker.
4073 * This handles the case where driver receives multiple expander
4074 * add and delete events in a single shot. When there is a delete event
4075 * the routine will void any pending add events waiting in the event queue.
4078 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
4079 Mpi2EventDataSasTopologyChangeList_t *event_data)
4081 struct fw_event_work *fw_event;
4082 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
4083 u16 expander_handle;
4084 struct _sas_node *sas_expander;
4085 unsigned long flags;
4089 for (i = 0 ; i < event_data->NumEntries; i++) {
4090 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4093 reason_code = event_data->PHY[i].PhyStatus &
4094 MPI2_EVENT_SAS_TOPO_RC_MASK;
4095 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
4096 _scsih_tm_tr_send(ioc, handle);
4099 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
4100 if (expander_handle < ioc->sas_hba.num_phys) {
4101 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4104 if (event_data->ExpStatus ==
4105 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
4106 /* put expander attached devices into blocking state */
4107 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4108 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
4110 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
4111 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4113 handle = find_first_bit(ioc->blocking_handles,
4114 ioc->facts.MaxDevHandle);
4115 if (handle < ioc->facts.MaxDevHandle)
4116 _scsih_block_io_device(ioc, handle);
4117 } while (test_and_clear_bit(handle, ioc->blocking_handles));
4118 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
4119 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4121 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4124 /* mark ignore flag for pending events */
4125 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4126 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4127 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
4130 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
4131 fw_event->event_data;
4132 if (local_event_data->ExpStatus ==
4133 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4134 local_event_data->ExpStatus ==
4135 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4136 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
4139 ioc_info(ioc, "setting ignoring flag\n"));
4140 fw_event->ignore = 1;
4144 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4148 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4150 * @ioc: per adapter object
4151 * @event_data: the event data payload
4153 * This handles the case where driver receives multiple switch
4154 * or device add and delete events in a single shot. When there
4155 * is a delete event the routine will void any pending add
4156 * events waiting in the event queue.
4159 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc,
4160 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
4162 struct fw_event_work *fw_event;
4163 Mpi26EventDataPCIeTopologyChangeList_t *local_event_data;
4164 unsigned long flags;
4166 u16 handle, switch_handle;
4168 for (i = 0; i < event_data->NumEntries; i++) {
4170 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
4173 reason_code = event_data->PortEntry[i].PortStatus;
4174 if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING)
4175 _scsih_tm_tr_send(ioc, handle);
4178 switch_handle = le16_to_cpu(event_data->SwitchDevHandle);
4179 if (!switch_handle) {
4180 _scsih_block_io_to_pcie_children_attached_directly(
4184 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4185 if ((event_data->SwitchStatus
4186 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) ||
4187 (event_data->SwitchStatus ==
4188 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING))
4189 _scsih_block_io_to_pcie_children_attached_directly(
4192 if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4195 /* mark ignore flag for pending events */
4196 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4197 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4198 if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
4202 (Mpi26EventDataPCIeTopologyChangeList_t *)
4203 fw_event->event_data;
4204 if (local_event_data->SwitchStatus ==
4205 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4206 local_event_data->SwitchStatus ==
4207 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4208 if (le16_to_cpu(local_event_data->SwitchDevHandle) ==
4211 ioc_info(ioc, "setting ignoring flag for switch event\n"));
4212 fw_event->ignore = 1;
4216 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4220 * _scsih_set_volume_delete_flag - setting volume delete flag
4221 * @ioc: per adapter object
4222 * @handle: device handle
4224 * This returns nothing.
4227 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4229 struct _raid_device *raid_device;
4230 struct MPT3SAS_TARGET *sas_target_priv_data;
4231 unsigned long flags;
4233 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4234 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
4235 if (raid_device && raid_device->starget &&
4236 raid_device->starget->hostdata) {
4237 sas_target_priv_data =
4238 raid_device->starget->hostdata;
4239 sas_target_priv_data->deleted = 1;
4241 ioc_info(ioc, "setting delete flag: handle(0x%04x), wwid(0x%016llx)\n",
4242 handle, (u64)raid_device->wwid));
4244 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4248 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4249 * @handle: input handle
4250 * @a: handle for volume a
4251 * @b: handle for volume b
4253 * IR firmware only supports two raid volumes. The purpose of this
4254 * routine is to set the volume handle in either a or b. When the given
4255 * input handle is non-zero, or when a and b have not been set before.
4258 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
4260 if (!handle || handle == *a || handle == *b)
4269 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4270 * @ioc: per adapter object
4271 * @event_data: the event data payload
4272 * Context: interrupt time.
4274 * This routine will send target reset to volume, followed by target
4275 * resets to the PDs. This is called when a PD has been removed, or
4276 * volume has been deleted or removed. When the target reset is sent
4277 * to volume, the PD target resets need to be queued to start upon
4278 * completion of the volume target reset.
4281 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
4282 Mpi2EventDataIrConfigChangeList_t *event_data)
4284 Mpi2EventIrConfigElement_t *element;
4286 u16 handle, volume_handle, a, b;
4287 struct _tr_list *delayed_tr;
4292 if (ioc->is_warpdrive)
4295 /* Volume Resets for Deleted or Removed */
4296 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4297 for (i = 0; i < event_data->NumElements; i++, element++) {
4298 if (le32_to_cpu(event_data->Flags) &
4299 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4301 if (element->ReasonCode ==
4302 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
4303 element->ReasonCode ==
4304 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
4305 volume_handle = le16_to_cpu(element->VolDevHandle);
4306 _scsih_set_volume_delete_flag(ioc, volume_handle);
4307 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4311 /* Volume Resets for UNHIDE events */
4312 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4313 for (i = 0; i < event_data->NumElements; i++, element++) {
4314 if (le32_to_cpu(event_data->Flags) &
4315 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4317 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
4318 volume_handle = le16_to_cpu(element->VolDevHandle);
4319 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4324 _scsih_tm_tr_volume_send(ioc, a);
4326 _scsih_tm_tr_volume_send(ioc, b);
4328 /* PD target resets */
4329 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4330 for (i = 0; i < event_data->NumElements; i++, element++) {
4331 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
4333 handle = le16_to_cpu(element->PhysDiskDevHandle);
4334 volume_handle = le16_to_cpu(element->VolDevHandle);
4335 clear_bit(handle, ioc->pd_handles);
4337 _scsih_tm_tr_send(ioc, handle);
4338 else if (volume_handle == a || volume_handle == b) {
4339 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
4340 BUG_ON(!delayed_tr);
4341 INIT_LIST_HEAD(&delayed_tr->list);
4342 delayed_tr->handle = handle;
4343 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
4345 ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n",
4348 _scsih_tm_tr_send(ioc, handle);
4354 * _scsih_check_volume_delete_events - set delete flag for volumes
4355 * @ioc: per adapter object
4356 * @event_data: the event data payload
4357 * Context: interrupt time.
4359 * This will handle the case when the cable connected to entire volume is
4360 * pulled. We will take care of setting the deleted flag so normal IO will
4364 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
4365 Mpi2EventDataIrVolume_t *event_data)
4369 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4371 state = le32_to_cpu(event_data->NewValue);
4372 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
4373 MPI2_RAID_VOL_STATE_FAILED)
4374 _scsih_set_volume_delete_flag(ioc,
4375 le16_to_cpu(event_data->VolDevHandle));
4379 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4380 * @ioc: per adapter object
4381 * @event_data: the temp threshold event data
4382 * Context: interrupt time.
4385 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
4386 Mpi2EventDataTemperature_t *event_data)
4388 if (ioc->temp_sensors_count >= event_data->SensorNum) {
4389 ioc_err(ioc, "Temperature Threshold flags %s%s%s%s exceeded for Sensor: %d !!!\n",
4390 le16_to_cpu(event_data->Status) & 0x1 ? "0 " : " ",
4391 le16_to_cpu(event_data->Status) & 0x2 ? "1 " : " ",
4392 le16_to_cpu(event_data->Status) & 0x4 ? "2 " : " ",
4393 le16_to_cpu(event_data->Status) & 0x8 ? "3 " : " ",
4394 event_data->SensorNum);
4395 ioc_err(ioc, "Current Temp In Celsius: %d\n",
4396 event_data->CurrentTemperature);
4400 static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
4402 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
4404 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
4408 return test_and_set_bit(0, &priv->ata_command_pending);
4410 clear_bit(0, &priv->ata_command_pending);
4415 * _scsih_flush_running_cmds - completing outstanding commands.
4416 * @ioc: per adapter object
4418 * The flushing out of all pending scmd commands following host reset,
4419 * where all IO is dropped to the floor.
4422 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
4424 struct scsi_cmnd *scmd;
4425 struct scsiio_tracker *st;
4429 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
4430 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
4434 _scsih_set_satl_pending(scmd, false);
4435 st = scsi_cmd_priv(scmd);
4436 mpt3sas_base_clear_st(ioc, st);
4437 scsi_dma_unmap(scmd);
4438 if (ioc->pci_error_recovery || ioc->remove_host)
4439 scmd->result = DID_NO_CONNECT << 16;
4441 scmd->result = DID_RESET << 16;
4442 scmd->scsi_done(scmd);
4444 dtmprintk(ioc, ioc_info(ioc, "completing %d cmds\n", count));
4448 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4449 * @ioc: per adapter object
4450 * @scmd: pointer to scsi command object
4451 * @mpi_request: pointer to the SCSI_IO request message frame
4453 * Supporting protection 1 and 3.
4456 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4457 Mpi25SCSIIORequest_t *mpi_request)
4460 unsigned char prot_op = scsi_get_prot_op(scmd);
4461 unsigned char prot_type = scsi_get_prot_type(scmd);
4462 Mpi25SCSIIORequest_t *mpi_request_3v =
4463 (Mpi25SCSIIORequest_t *)mpi_request;
4465 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
4468 if (prot_op == SCSI_PROT_READ_STRIP)
4469 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
4470 else if (prot_op == SCSI_PROT_WRITE_INSERT)
4471 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
4475 switch (prot_type) {
4476 case SCSI_PROT_DIF_TYPE1:
4477 case SCSI_PROT_DIF_TYPE2:
4480 * enable ref/guard checking
4481 * auto increment ref tag
4483 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
4484 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
4485 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4486 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
4487 cpu_to_be32(t10_pi_ref_tag(scmd->request));
4490 case SCSI_PROT_DIF_TYPE3:
4493 * enable guard checking
4495 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4500 mpi_request_3v->EEDPBlockSize =
4501 cpu_to_le16(scmd->device->sector_size);
4503 if (ioc->is_gen35_ioc)
4504 eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
4505 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
4509 * _scsih_eedp_error_handling - return sense code for EEDP errors
4510 * @scmd: pointer to scsi command object
4511 * @ioc_status: ioc status
4514 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4518 switch (ioc_status) {
4519 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4522 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4525 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4532 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4534 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4535 SAM_STAT_CHECK_CONDITION;
4539 * scsih_qcmd - main scsi request entry point
4540 * @shost: SCSI host pointer
4541 * @scmd: pointer to scsi command object
4543 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4545 * Return: 0 on success. If there's a failure, return either:
4546 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4547 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4550 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4552 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4553 struct MPT3SAS_DEVICE *sas_device_priv_data;
4554 struct MPT3SAS_TARGET *sas_target_priv_data;
4555 struct _raid_device *raid_device;
4556 struct request *rq = scmd->request;
4558 Mpi25SCSIIORequest_t *mpi_request;
4559 struct _pcie_device *pcie_device = NULL;
4564 if (ioc->logging_level & MPT_DEBUG_SCSI)
4565 scsi_print_command(scmd);
4567 sas_device_priv_data = scmd->device->hostdata;
4568 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4569 scmd->result = DID_NO_CONNECT << 16;
4570 scmd->scsi_done(scmd);
4574 if (ioc->pci_error_recovery || ioc->remove_host) {
4575 scmd->result = DID_NO_CONNECT << 16;
4576 scmd->scsi_done(scmd);
4580 sas_target_priv_data = sas_device_priv_data->sas_target;
4582 /* invalid device handle */
4583 handle = sas_target_priv_data->handle;
4584 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4585 scmd->result = DID_NO_CONNECT << 16;
4586 scmd->scsi_done(scmd);
4591 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
4592 /* host recovery or link resets sent via IOCTLs */
4593 return SCSI_MLQUEUE_HOST_BUSY;
4594 } else if (sas_target_priv_data->deleted) {
4595 /* device has been deleted */
4596 scmd->result = DID_NO_CONNECT << 16;
4597 scmd->scsi_done(scmd);
4599 } else if (sas_target_priv_data->tm_busy ||
4600 sas_device_priv_data->block) {
4601 /* device busy with task management */
4602 return SCSI_MLQUEUE_DEVICE_BUSY;
4606 * Bug work around for firmware SATL handling. The loop
4607 * is based on atomic operations and ensures consistency
4608 * since we're lockless at this point
4611 if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
4612 scmd->result = SAM_STAT_BUSY;
4613 scmd->scsi_done(scmd);
4616 } while (_scsih_set_satl_pending(scmd, true));
4618 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4619 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4620 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4621 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4623 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4626 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4627 /* NCQ Prio supported, make sure control indicated high priority */
4628 if (sas_device_priv_data->ncq_prio_enable) {
4629 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
4630 if (class == IOPRIO_CLASS_RT)
4631 mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
4633 /* Make sure Device is not raid volume.
4634 * We do not expose raid functionality to upper layer for warpdrive.
4636 if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev))
4637 && !scsih_is_nvme(&scmd->device->sdev_gendev))
4638 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4639 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4641 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4643 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
4644 _scsih_set_satl_pending(scmd, false);
4647 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4648 memset(mpi_request, 0, ioc->request_sz);
4649 _scsih_setup_eedp(ioc, scmd, mpi_request);
4651 if (scmd->cmd_len == 32)
4652 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4653 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4654 if (sas_device_priv_data->sas_target->flags &
4655 MPT_TARGET_FLAGS_RAID_COMPONENT)
4656 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4658 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4659 mpi_request->DevHandle = cpu_to_le16(handle);
4660 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4661 mpi_request->Control = cpu_to_le32(mpi_control);
4662 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4663 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4664 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4665 mpi_request->SenseBufferLowAddress =
4666 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4667 mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4;
4668 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4670 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4672 if (mpi_request->DataLength) {
4673 pcie_device = sas_target_priv_data->pcie_dev;
4674 if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) {
4675 mpt3sas_base_free_smid(ioc, smid);
4676 _scsih_set_satl_pending(scmd, false);
4680 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4682 raid_device = sas_target_priv_data->raid_device;
4683 if (raid_device && raid_device->direct_io_enabled)
4684 mpt3sas_setup_direct_io(ioc, scmd,
4685 raid_device, mpi_request);
4687 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4688 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4689 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4690 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4691 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
4693 ioc->put_smid_scsi_io(ioc, smid,
4694 le16_to_cpu(mpi_request->DevHandle));
4696 mpt3sas_base_put_smid_default(ioc, smid);
4700 return SCSI_MLQUEUE_HOST_BUSY;
4704 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4705 * @sense_buffer: sense data returned by target
4706 * @data: normalized skey/asc/ascq
4709 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4711 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4712 /* descriptor format */
4713 data->skey = sense_buffer[1] & 0x0F;
4714 data->asc = sense_buffer[2];
4715 data->ascq = sense_buffer[3];
4718 data->skey = sense_buffer[2] & 0x0F;
4719 data->asc = sense_buffer[12];
4720 data->ascq = sense_buffer[13];
4725 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4726 * @ioc: per adapter object
4727 * @scmd: pointer to scsi command object
4728 * @mpi_reply: reply mf payload returned from firmware
4731 * scsi_status - SCSI Status code returned from target device
4732 * scsi_state - state info associated with SCSI_IO determined by ioc
4733 * ioc_status - ioc supplied status info
4736 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4737 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4741 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4742 MPI2_IOCSTATUS_MASK;
4743 u8 scsi_state = mpi_reply->SCSIState;
4744 u8 scsi_status = mpi_reply->SCSIStatus;
4745 char *desc_ioc_state = NULL;
4746 char *desc_scsi_status = NULL;
4747 char *desc_scsi_state = ioc->tmp_string;
4748 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4749 struct _sas_device *sas_device = NULL;
4750 struct _pcie_device *pcie_device = NULL;
4751 struct scsi_target *starget = scmd->device->sdev_target;
4752 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4753 char *device_str = NULL;
4757 if (ioc->hide_ir_msg)
4758 device_str = "WarpDrive";
4760 device_str = "volume";
4762 if (log_info == 0x31170000)
4765 switch (ioc_status) {
4766 case MPI2_IOCSTATUS_SUCCESS:
4767 desc_ioc_state = "success";
4769 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4770 desc_ioc_state = "invalid function";
4772 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4773 desc_ioc_state = "scsi recovered error";
4775 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4776 desc_ioc_state = "scsi invalid dev handle";
4778 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4779 desc_ioc_state = "scsi device not there";
4781 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4782 desc_ioc_state = "scsi data overrun";
4784 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4785 desc_ioc_state = "scsi data underrun";
4787 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4788 desc_ioc_state = "scsi io data error";
4790 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4791 desc_ioc_state = "scsi protocol error";
4793 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4794 desc_ioc_state = "scsi task terminated";
4796 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4797 desc_ioc_state = "scsi residual mismatch";
4799 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4800 desc_ioc_state = "scsi task mgmt failed";
4802 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4803 desc_ioc_state = "scsi ioc terminated";
4805 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4806 desc_ioc_state = "scsi ext terminated";
4808 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4809 desc_ioc_state = "eedp guard error";
4811 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4812 desc_ioc_state = "eedp ref tag error";
4814 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4815 desc_ioc_state = "eedp app tag error";
4817 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4818 desc_ioc_state = "insufficient power";
4821 desc_ioc_state = "unknown";
4825 switch (scsi_status) {
4826 case MPI2_SCSI_STATUS_GOOD:
4827 desc_scsi_status = "good";
4829 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4830 desc_scsi_status = "check condition";
4832 case MPI2_SCSI_STATUS_CONDITION_MET:
4833 desc_scsi_status = "condition met";
4835 case MPI2_SCSI_STATUS_BUSY:
4836 desc_scsi_status = "busy";
4838 case MPI2_SCSI_STATUS_INTERMEDIATE:
4839 desc_scsi_status = "intermediate";
4841 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4842 desc_scsi_status = "intermediate condmet";
4844 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4845 desc_scsi_status = "reservation conflict";
4847 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4848 desc_scsi_status = "command terminated";
4850 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4851 desc_scsi_status = "task set full";
4853 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4854 desc_scsi_status = "aca active";
4856 case MPI2_SCSI_STATUS_TASK_ABORTED:
4857 desc_scsi_status = "task aborted";
4860 desc_scsi_status = "unknown";
4864 desc_scsi_state[0] = '\0';
4866 desc_scsi_state = " ";
4867 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4868 strcat(desc_scsi_state, "response info ");
4869 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4870 strcat(desc_scsi_state, "state terminated ");
4871 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4872 strcat(desc_scsi_state, "no status ");
4873 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4874 strcat(desc_scsi_state, "autosense failed ");
4875 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4876 strcat(desc_scsi_state, "autosense valid ");
4878 scsi_print_command(scmd);
4880 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4881 ioc_warn(ioc, "\t%s wwid(0x%016llx)\n",
4882 device_str, (u64)priv_target->sas_address);
4883 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
4884 pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target);
4886 ioc_info(ioc, "\twwid(0x%016llx), port(%d)\n",
4887 (u64)pcie_device->wwid, pcie_device->port_num);
4888 if (pcie_device->enclosure_handle != 0)
4889 ioc_info(ioc, "\tenclosure logical id(0x%016llx), slot(%d)\n",
4890 (u64)pcie_device->enclosure_logical_id,
4892 if (pcie_device->connector_name[0])
4893 ioc_info(ioc, "\tenclosure level(0x%04x), connector name( %s)\n",
4894 pcie_device->enclosure_level,
4895 pcie_device->connector_name);
4896 pcie_device_put(pcie_device);
4899 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4901 ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n",
4902 (u64)sas_device->sas_address, sas_device->phy);
4904 _scsih_display_enclosure_chassis_info(ioc, sas_device,
4907 sas_device_put(sas_device);
4911 ioc_warn(ioc, "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4912 le16_to_cpu(mpi_reply->DevHandle),
4913 desc_ioc_state, ioc_status, smid);
4914 ioc_warn(ioc, "\trequest_len(%d), underflow(%d), resid(%d)\n",
4915 scsi_bufflen(scmd), scmd->underflow, scsi_get_resid(scmd));
4916 ioc_warn(ioc, "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4917 le16_to_cpu(mpi_reply->TaskTag),
4918 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4919 ioc_warn(ioc, "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4920 desc_scsi_status, scsi_status, desc_scsi_state, scsi_state);
4922 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4923 struct sense_info data;
4924 _scsih_normalize_sense(scmd->sense_buffer, &data);
4925 ioc_warn(ioc, "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4926 data.skey, data.asc, data.ascq,
4927 le32_to_cpu(mpi_reply->SenseCount));
4929 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4930 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4931 response_bytes = (u8 *)&response_info;
4932 _scsih_response_code(ioc, response_bytes[0]);
4937 * _scsih_turn_on_pfa_led - illuminate PFA LED
4938 * @ioc: per adapter object
4939 * @handle: device handle
4943 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4945 Mpi2SepReply_t mpi_reply;
4946 Mpi2SepRequest_t mpi_request;
4947 struct _sas_device *sas_device;
4949 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4953 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4954 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4955 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4956 mpi_request.SlotStatus =
4957 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4958 mpi_request.DevHandle = cpu_to_le16(handle);
4959 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4960 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4961 &mpi_request)) != 0) {
4962 ioc_err(ioc, "failure at %s:%d/%s()!\n",
4963 __FILE__, __LINE__, __func__);
4966 sas_device->pfa_led_on = 1;
4968 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4970 ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4971 le16_to_cpu(mpi_reply.IOCStatus),
4972 le32_to_cpu(mpi_reply.IOCLogInfo)));
4976 sas_device_put(sas_device);
4980 * _scsih_turn_off_pfa_led - turn off Fault LED
4981 * @ioc: per adapter object
4982 * @sas_device: sas device whose PFA LED has to turned off
4986 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4987 struct _sas_device *sas_device)
4989 Mpi2SepReply_t mpi_reply;
4990 Mpi2SepRequest_t mpi_request;
4992 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4993 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4994 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4995 mpi_request.SlotStatus = 0;
4996 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4997 mpi_request.DevHandle = 0;
4998 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4999 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
5000 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5001 &mpi_request)) != 0) {
5002 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5003 __FILE__, __LINE__, __func__);
5007 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5009 ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5010 le16_to_cpu(mpi_reply.IOCStatus),
5011 le32_to_cpu(mpi_reply.IOCLogInfo)));
5017 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5018 * @ioc: per adapter object
5019 * @handle: device handle
5020 * Context: interrupt.
5023 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5025 struct fw_event_work *fw_event;
5027 fw_event = alloc_fw_event_work(0);
5030 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
5031 fw_event->device_handle = handle;
5032 fw_event->ioc = ioc;
5033 _scsih_fw_event_add(ioc, fw_event);
5034 fw_event_work_put(fw_event);
5038 * _scsih_smart_predicted_fault - process smart errors
5039 * @ioc: per adapter object
5040 * @handle: device handle
5041 * Context: interrupt.
5044 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5046 struct scsi_target *starget;
5047 struct MPT3SAS_TARGET *sas_target_priv_data;
5048 Mpi2EventNotificationReply_t *event_reply;
5049 Mpi2EventDataSasDeviceStatusChange_t *event_data;
5050 struct _sas_device *sas_device;
5052 unsigned long flags;
5054 /* only handle non-raid devices */
5055 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5056 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
5060 starget = sas_device->starget;
5061 sas_target_priv_data = starget->hostdata;
5063 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
5064 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
5067 _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget);
5069 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5071 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
5072 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
5074 /* insert into event log */
5075 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
5076 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
5077 event_reply = kzalloc(sz, GFP_KERNEL);
5079 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5080 __FILE__, __LINE__, __func__);
5084 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
5085 event_reply->Event =
5086 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
5087 event_reply->MsgLength = sz/4;
5088 event_reply->EventDataLength =
5089 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
5090 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
5091 event_reply->EventData;
5092 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
5093 event_data->ASC = 0x5D;
5094 event_data->DevHandle = cpu_to_le16(handle);
5095 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
5096 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
5100 sas_device_put(sas_device);
5104 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5109 * _scsih_io_done - scsi request callback
5110 * @ioc: per adapter object
5111 * @smid: system request message index
5112 * @msix_index: MSIX table index supplied by the OS
5113 * @reply: reply message frame(lower 32bit addr)
5115 * Callback handler when using _scsih_qcmd.
5117 * Return: 1 meaning mf should be freed from _base_interrupt
5118 * 0 means the mf is freed from this function.
5121 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5123 Mpi25SCSIIORequest_t *mpi_request;
5124 Mpi2SCSIIOReply_t *mpi_reply;
5125 struct scsi_cmnd *scmd;
5126 struct scsiio_tracker *st;
5132 struct MPT3SAS_DEVICE *sas_device_priv_data;
5133 u32 response_code = 0;
5135 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5137 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
5141 _scsih_set_satl_pending(scmd, false);
5143 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5145 if (mpi_reply == NULL) {
5146 scmd->result = DID_OK << 16;
5150 sas_device_priv_data = scmd->device->hostdata;
5151 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
5152 sas_device_priv_data->sas_target->deleted) {
5153 scmd->result = DID_NO_CONNECT << 16;
5156 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5159 * WARPDRIVE: If direct_io is set then it is directIO,
5160 * the failed direct I/O should be redirected to volume
5162 st = scsi_cmd_priv(scmd);
5163 if (st->direct_io &&
5164 ((ioc_status & MPI2_IOCSTATUS_MASK)
5165 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
5167 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
5168 mpi_request->DevHandle =
5169 cpu_to_le16(sas_device_priv_data->sas_target->handle);
5170 ioc->put_smid_scsi_io(ioc, smid,
5171 sas_device_priv_data->sas_target->handle);
5174 /* turning off TLR */
5175 scsi_state = mpi_reply->SCSIState;
5176 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
5178 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
5179 if (!sas_device_priv_data->tlr_snoop_check) {
5180 sas_device_priv_data->tlr_snoop_check++;
5181 if ((!ioc->is_warpdrive &&
5182 !scsih_is_raid(&scmd->device->sdev_gendev) &&
5183 !scsih_is_nvme(&scmd->device->sdev_gendev))
5184 && sas_is_tlr_enabled(scmd->device) &&
5185 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
5186 sas_disable_tlr(scmd->device);
5187 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
5191 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
5192 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
5193 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5194 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5197 ioc_status &= MPI2_IOCSTATUS_MASK;
5198 scsi_status = mpi_reply->SCSIStatus;
5200 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
5201 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
5202 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
5203 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
5204 ioc_status = MPI2_IOCSTATUS_SUCCESS;
5207 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
5208 struct sense_info data;
5209 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
5211 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
5212 le32_to_cpu(mpi_reply->SenseCount));
5213 memcpy(scmd->sense_buffer, sense_data, sz);
5214 _scsih_normalize_sense(scmd->sense_buffer, &data);
5215 /* failure prediction threshold exceeded */
5216 if (data.asc == 0x5D)
5217 _scsih_smart_predicted_fault(ioc,
5218 le16_to_cpu(mpi_reply->DevHandle));
5219 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
5221 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
5222 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
5223 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
5224 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
5225 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
5227 switch (ioc_status) {
5228 case MPI2_IOCSTATUS_BUSY:
5229 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
5230 scmd->result = SAM_STAT_BUSY;
5233 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
5234 scmd->result = DID_NO_CONNECT << 16;
5237 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
5238 if (sas_device_priv_data->block) {
5239 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
5242 if (log_info == 0x31110630) {
5243 if (scmd->retries > 2) {
5244 scmd->result = DID_NO_CONNECT << 16;
5245 scsi_device_set_state(scmd->device,
5248 scmd->result = DID_SOFT_ERROR << 16;
5249 scmd->device->expecting_cc_ua = 1;
5252 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
5253 scmd->result = DID_RESET << 16;
5255 } else if ((scmd->device->channel == RAID_CHANNEL) &&
5256 (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
5257 MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
5258 scmd->result = DID_RESET << 16;
5261 scmd->result = DID_SOFT_ERROR << 16;
5263 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
5264 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
5265 scmd->result = DID_RESET << 16;
5268 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
5269 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
5270 scmd->result = DID_SOFT_ERROR << 16;
5272 scmd->result = (DID_OK << 16) | scsi_status;
5275 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
5276 scmd->result = (DID_OK << 16) | scsi_status;
5278 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
5281 if (xfer_cnt < scmd->underflow) {
5282 if (scsi_status == SAM_STAT_BUSY)
5283 scmd->result = SAM_STAT_BUSY;
5285 scmd->result = DID_SOFT_ERROR << 16;
5286 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5287 MPI2_SCSI_STATE_NO_SCSI_STATUS))
5288 scmd->result = DID_SOFT_ERROR << 16;
5289 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5290 scmd->result = DID_RESET << 16;
5291 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
5292 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
5293 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
5294 scmd->result = (DRIVER_SENSE << 24) |
5295 SAM_STAT_CHECK_CONDITION;
5296 scmd->sense_buffer[0] = 0x70;
5297 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
5298 scmd->sense_buffer[12] = 0x20;
5299 scmd->sense_buffer[13] = 0;
5303 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
5304 scsi_set_resid(scmd, 0);
5306 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
5307 case MPI2_IOCSTATUS_SUCCESS:
5308 scmd->result = (DID_OK << 16) | scsi_status;
5309 if (response_code ==
5310 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
5311 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5312 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
5313 scmd->result = DID_SOFT_ERROR << 16;
5314 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5315 scmd->result = DID_RESET << 16;
5318 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
5319 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
5320 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
5321 _scsih_eedp_error_handling(scmd, ioc_status);
5324 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
5325 case MPI2_IOCSTATUS_INVALID_FUNCTION:
5326 case MPI2_IOCSTATUS_INVALID_SGL:
5327 case MPI2_IOCSTATUS_INTERNAL_ERROR:
5328 case MPI2_IOCSTATUS_INVALID_FIELD:
5329 case MPI2_IOCSTATUS_INVALID_STATE:
5330 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
5331 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
5332 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
5334 scmd->result = DID_SOFT_ERROR << 16;
5339 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
5340 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
5344 scsi_dma_unmap(scmd);
5345 mpt3sas_base_free_smid(ioc, smid);
5346 scmd->scsi_done(scmd);
5351 * _scsih_sas_host_refresh - refreshing sas host object contents
5352 * @ioc: per adapter object
5355 * During port enable, fw will send topology events for every device. Its
5356 * possible that the handles may change from the previous setting, so this
5357 * code keeping handles updating if changed.
5360 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
5365 Mpi2ConfigReply_t mpi_reply;
5366 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5367 u16 attached_handle;
5371 ioc_info(ioc, "updating handles for sas_host(0x%016llx)\n",
5372 (u64)ioc->sas_hba.sas_address));
5374 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
5375 * sizeof(Mpi2SasIOUnit0PhyData_t));
5376 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5377 if (!sas_iounit_pg0) {
5378 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5379 __FILE__, __LINE__, __func__);
5383 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5384 sas_iounit_pg0, sz)) != 0)
5386 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5387 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5389 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5390 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
5392 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5393 PhyData[0].ControllerDevHandle);
5394 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5395 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
5397 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5398 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
5399 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
5400 attached_handle, i, link_rate);
5403 kfree(sas_iounit_pg0);
5407 * _scsih_sas_host_add - create sas host object
5408 * @ioc: per adapter object
5410 * Creating host side data object, stored in ioc->sas_hba
5413 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
5416 Mpi2ConfigReply_t mpi_reply;
5417 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5418 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
5419 Mpi2SasPhyPage0_t phy_pg0;
5420 Mpi2SasDevicePage0_t sas_device_pg0;
5421 Mpi2SasEnclosurePage0_t enclosure_pg0;
5424 u8 device_missing_delay;
5427 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
5429 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5430 __FILE__, __LINE__, __func__);
5433 ioc->sas_hba.phy = kcalloc(num_phys,
5434 sizeof(struct _sas_phy), GFP_KERNEL);
5435 if (!ioc->sas_hba.phy) {
5436 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5437 __FILE__, __LINE__, __func__);
5440 ioc->sas_hba.num_phys = num_phys;
5442 /* sas_iounit page 0 */
5443 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
5444 sizeof(Mpi2SasIOUnit0PhyData_t));
5445 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5446 if (!sas_iounit_pg0) {
5447 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5448 __FILE__, __LINE__, __func__);
5451 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5452 sas_iounit_pg0, sz))) {
5453 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5454 __FILE__, __LINE__, __func__);
5457 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5458 MPI2_IOCSTATUS_MASK;
5459 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5460 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5461 __FILE__, __LINE__, __func__);
5465 /* sas_iounit page 1 */
5466 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
5467 sizeof(Mpi2SasIOUnit1PhyData_t));
5468 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
5469 if (!sas_iounit_pg1) {
5470 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5471 __FILE__, __LINE__, __func__);
5474 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
5475 sas_iounit_pg1, sz))) {
5476 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5477 __FILE__, __LINE__, __func__);
5480 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5481 MPI2_IOCSTATUS_MASK;
5482 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5483 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5484 __FILE__, __LINE__, __func__);
5488 ioc->io_missing_delay =
5489 sas_iounit_pg1->IODeviceMissingDelay;
5490 device_missing_delay =
5491 sas_iounit_pg1->ReportDeviceMissingDelay;
5492 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
5493 ioc->device_missing_delay = (device_missing_delay &
5494 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
5496 ioc->device_missing_delay = device_missing_delay &
5497 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
5499 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
5500 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5501 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5503 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5504 __FILE__, __LINE__, __func__);
5507 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5508 MPI2_IOCSTATUS_MASK;
5509 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5510 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5511 __FILE__, __LINE__, __func__);
5516 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5517 PhyData[0].ControllerDevHandle);
5518 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5519 ioc->sas_hba.phy[i].phy_id = i;
5520 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
5521 phy_pg0, ioc->sas_hba.parent_dev);
5523 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5524 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
5525 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5526 __FILE__, __LINE__, __func__);
5529 ioc->sas_hba.enclosure_handle =
5530 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5531 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5532 ioc_info(ioc, "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5533 ioc->sas_hba.handle,
5534 (u64)ioc->sas_hba.sas_address,
5535 ioc->sas_hba.num_phys);
5537 if (ioc->sas_hba.enclosure_handle) {
5538 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5539 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5540 ioc->sas_hba.enclosure_handle)))
5541 ioc->sas_hba.enclosure_logical_id =
5542 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5546 kfree(sas_iounit_pg1);
5547 kfree(sas_iounit_pg0);
5551 * _scsih_expander_add - creating expander object
5552 * @ioc: per adapter object
5553 * @handle: expander handle
5555 * Creating expander object, stored in ioc->sas_expander_list.
5557 * Return: 0 for success, else error.
5560 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5562 struct _sas_node *sas_expander;
5563 struct _enclosure_node *enclosure_dev;
5564 Mpi2ConfigReply_t mpi_reply;
5565 Mpi2ExpanderPage0_t expander_pg0;
5566 Mpi2ExpanderPage1_t expander_pg1;
5569 u64 sas_address, sas_address_parent = 0;
5571 unsigned long flags;
5572 struct _sas_port *mpt3sas_port = NULL;
5579 if (ioc->shost_recovery || ioc->pci_error_recovery)
5582 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5583 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5584 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5585 __FILE__, __LINE__, __func__);
5589 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5590 MPI2_IOCSTATUS_MASK;
5591 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5592 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5593 __FILE__, __LINE__, __func__);
5597 /* handle out of order topology events */
5598 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5599 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5601 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5602 __FILE__, __LINE__, __func__);
5605 if (sas_address_parent != ioc->sas_hba.sas_address) {
5606 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5607 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5608 sas_address_parent);
5609 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5610 if (!sas_expander) {
5611 rc = _scsih_expander_add(ioc, parent_handle);
5617 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5618 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5619 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5621 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5626 sas_expander = kzalloc(sizeof(struct _sas_node),
5628 if (!sas_expander) {
5629 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5630 __FILE__, __LINE__, __func__);
5634 sas_expander->handle = handle;
5635 sas_expander->num_phys = expander_pg0.NumPhys;
5636 sas_expander->sas_address_parent = sas_address_parent;
5637 sas_expander->sas_address = sas_address;
5639 ioc_info(ioc, "expander_add: handle(0x%04x), parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5640 handle, parent_handle,
5641 (u64)sas_expander->sas_address, sas_expander->num_phys);
5643 if (!sas_expander->num_phys)
5645 sas_expander->phy = kcalloc(sas_expander->num_phys,
5646 sizeof(struct _sas_phy), GFP_KERNEL);
5647 if (!sas_expander->phy) {
5648 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5649 __FILE__, __LINE__, __func__);
5654 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5655 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5656 sas_address_parent);
5657 if (!mpt3sas_port) {
5658 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5659 __FILE__, __LINE__, __func__);
5663 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5665 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5666 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5667 &expander_pg1, i, handle))) {
5668 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5669 __FILE__, __LINE__, __func__);
5673 sas_expander->phy[i].handle = handle;
5674 sas_expander->phy[i].phy_id = i;
5676 if ((mpt3sas_transport_add_expander_phy(ioc,
5677 &sas_expander->phy[i], expander_pg1,
5678 sas_expander->parent_dev))) {
5679 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5680 __FILE__, __LINE__, __func__);
5686 if (sas_expander->enclosure_handle) {
5688 mpt3sas_scsih_enclosure_find_by_handle(ioc,
5689 sas_expander->enclosure_handle);
5691 sas_expander->enclosure_logical_id =
5692 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
5695 _scsih_expander_node_add(ioc, sas_expander);
5701 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5702 sas_address_parent);
5703 kfree(sas_expander);
5708 * mpt3sas_expander_remove - removing expander object
5709 * @ioc: per adapter object
5710 * @sas_address: expander sas_address
5713 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5715 struct _sas_node *sas_expander;
5716 unsigned long flags;
5718 if (ioc->shost_recovery)
5721 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5722 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5724 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5726 _scsih_expander_node_remove(ioc, sas_expander);
5730 * _scsih_done - internal SCSI_IO callback handler.
5731 * @ioc: per adapter object
5732 * @smid: system request message index
5733 * @msix_index: MSIX table index supplied by the OS
5734 * @reply: reply message frame(lower 32bit addr)
5736 * Callback handler when sending internal generated SCSI_IO.
5737 * The callback index passed is `ioc->scsih_cb_idx`
5739 * Return: 1 meaning mf should be freed from _base_interrupt
5740 * 0 means the mf is freed from this function.
5743 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5745 MPI2DefaultReply_t *mpi_reply;
5747 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5748 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5750 if (ioc->scsih_cmds.smid != smid)
5752 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5754 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5755 mpi_reply->MsgLength*4);
5756 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5758 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5759 complete(&ioc->scsih_cmds.done);
5766 #define MPT3_MAX_LUNS (255)
5770 * _scsih_check_access_status - check access flags
5771 * @ioc: per adapter object
5772 * @sas_address: sas address
5773 * @handle: sas device handle
5774 * @access_status: errors returned during discovery of the device
5776 * Return: 0 for success, else failure
5779 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5780 u16 handle, u8 access_status)
5785 switch (access_status) {
5786 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5787 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5790 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5791 desc = "sata capability failed";
5793 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5794 desc = "sata affiliation conflict";
5796 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5797 desc = "route not addressable";
5799 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5800 desc = "smp error not addressable";
5802 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5803 desc = "device blocked";
5805 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5806 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5807 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5808 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5809 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5810 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5811 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5812 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5813 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5814 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5815 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5816 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5817 desc = "sata initialization failed";
5827 ioc_err(ioc, "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5828 desc, (u64)sas_address, handle);
5833 * _scsih_check_device - checking device responsiveness
5834 * @ioc: per adapter object
5835 * @parent_sas_address: sas address of parent expander or sas host
5836 * @handle: attached device handle
5837 * @phy_number: phy number
5838 * @link_rate: new link rate
5841 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5842 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5844 Mpi2ConfigReply_t mpi_reply;
5845 Mpi2SasDevicePage0_t sas_device_pg0;
5846 struct _sas_device *sas_device;
5847 struct _enclosure_node *enclosure_dev = NULL;
5849 unsigned long flags;
5851 struct scsi_target *starget;
5852 struct MPT3SAS_TARGET *sas_target_priv_data;
5855 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5856 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5859 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5860 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5863 /* wide port handling ~ we need only handle device once for the phy that
5864 * is matched in sas device page zero
5866 if (phy_number != sas_device_pg0.PhyNum)
5869 /* check if this is end device */
5870 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5871 if (!(_scsih_is_end_device(device_info)))
5874 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5875 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5876 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5882 if (unlikely(sas_device->handle != handle)) {
5883 starget = sas_device->starget;
5884 sas_target_priv_data = starget->hostdata;
5885 starget_printk(KERN_INFO, starget,
5886 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5887 sas_device->handle, handle);
5888 sas_target_priv_data->handle = handle;
5889 sas_device->handle = handle;
5890 if (le16_to_cpu(sas_device_pg0.Flags) &
5891 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5892 sas_device->enclosure_level =
5893 sas_device_pg0.EnclosureLevel;
5894 memcpy(sas_device->connector_name,
5895 sas_device_pg0.ConnectorName, 4);
5896 sas_device->connector_name[4] = '\0';
5898 sas_device->enclosure_level = 0;
5899 sas_device->connector_name[0] = '\0';
5902 sas_device->enclosure_handle =
5903 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5904 sas_device->is_chassis_slot_valid = 0;
5905 enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc,
5906 sas_device->enclosure_handle);
5907 if (enclosure_dev) {
5908 sas_device->enclosure_logical_id =
5909 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
5910 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
5911 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
5912 sas_device->is_chassis_slot_valid = 1;
5913 sas_device->chassis_slot =
5914 enclosure_dev->pg0.ChassisSlot;
5919 /* check if device is present */
5920 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5921 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5922 ioc_err(ioc, "device is not present handle(0x%04x), flags!!!\n",
5927 /* check if there were any issues with discovery */
5928 if (_scsih_check_access_status(ioc, sas_address, handle,
5929 sas_device_pg0.AccessStatus))
5932 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5933 _scsih_ublock_io_device(ioc, sas_address);
5936 sas_device_put(sas_device);
5940 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5942 sas_device_put(sas_device);
5946 * _scsih_add_device - creating sas device object
5947 * @ioc: per adapter object
5948 * @handle: sas device handle
5949 * @phy_num: phy number end device attached to
5950 * @is_pd: is this hidden raid component
5952 * Creating end device object, stored in ioc->sas_device_list.
5954 * Return: 0 for success, non-zero for failure.
5957 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5960 Mpi2ConfigReply_t mpi_reply;
5961 Mpi2SasDevicePage0_t sas_device_pg0;
5962 struct _sas_device *sas_device;
5963 struct _enclosure_node *enclosure_dev = NULL;
5968 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5969 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5970 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5971 __FILE__, __LINE__, __func__);
5975 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5976 MPI2_IOCSTATUS_MASK;
5977 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5978 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5979 __FILE__, __LINE__, __func__);
5983 /* check if this is end device */
5984 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5985 if (!(_scsih_is_end_device(device_info)))
5987 set_bit(handle, ioc->pend_os_device_add);
5988 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5990 /* check if device is present */
5991 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5992 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5993 ioc_err(ioc, "device is not present handle(0x04%x)!!!\n",
5998 /* check if there were any issues with discovery */
5999 if (_scsih_check_access_status(ioc, sas_address, handle,
6000 sas_device_pg0.AccessStatus))
6003 sas_device = mpt3sas_get_sdev_by_addr(ioc,
6006 clear_bit(handle, ioc->pend_os_device_add);
6007 sas_device_put(sas_device);
6011 if (sas_device_pg0.EnclosureHandle) {
6013 mpt3sas_scsih_enclosure_find_by_handle(ioc,
6014 le16_to_cpu(sas_device_pg0.EnclosureHandle));
6015 if (enclosure_dev == NULL)
6016 ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
6017 sas_device_pg0.EnclosureHandle);
6020 sas_device = kzalloc(sizeof(struct _sas_device),
6023 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6024 __FILE__, __LINE__, __func__);
6028 kref_init(&sas_device->refcount);
6029 sas_device->handle = handle;
6030 if (_scsih_get_sas_address(ioc,
6031 le16_to_cpu(sas_device_pg0.ParentDevHandle),
6032 &sas_device->sas_address_parent) != 0)
6033 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6034 __FILE__, __LINE__, __func__);
6035 sas_device->enclosure_handle =
6036 le16_to_cpu(sas_device_pg0.EnclosureHandle);
6037 if (sas_device->enclosure_handle != 0)
6039 le16_to_cpu(sas_device_pg0.Slot);
6040 sas_device->device_info = device_info;
6041 sas_device->sas_address = sas_address;
6042 sas_device->phy = sas_device_pg0.PhyNum;
6043 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
6044 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
6046 if (le16_to_cpu(sas_device_pg0.Flags)
6047 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6048 sas_device->enclosure_level =
6049 sas_device_pg0.EnclosureLevel;
6050 memcpy(sas_device->connector_name,
6051 sas_device_pg0.ConnectorName, 4);
6052 sas_device->connector_name[4] = '\0';
6054 sas_device->enclosure_level = 0;
6055 sas_device->connector_name[0] = '\0';
6057 /* get enclosure_logical_id & chassis_slot*/
6058 sas_device->is_chassis_slot_valid = 0;
6059 if (enclosure_dev) {
6060 sas_device->enclosure_logical_id =
6061 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6062 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
6063 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
6064 sas_device->is_chassis_slot_valid = 1;
6065 sas_device->chassis_slot =
6066 enclosure_dev->pg0.ChassisSlot;
6070 /* get device name */
6071 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
6073 if (ioc->wait_for_discovery_to_complete)
6074 _scsih_sas_device_init_add(ioc, sas_device);
6076 _scsih_sas_device_add(ioc, sas_device);
6078 sas_device_put(sas_device);
6083 * _scsih_remove_device - removing sas device object
6084 * @ioc: per adapter object
6085 * @sas_device: the sas_device object
6088 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
6089 struct _sas_device *sas_device)
6091 struct MPT3SAS_TARGET *sas_target_priv_data;
6093 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
6094 (sas_device->pfa_led_on)) {
6095 _scsih_turn_off_pfa_led(ioc, sas_device);
6096 sas_device->pfa_led_on = 0;
6100 ioc_info(ioc, "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6102 sas_device->handle, (u64)sas_device->sas_address));
6104 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
6107 if (sas_device->starget && sas_device->starget->hostdata) {
6108 sas_target_priv_data = sas_device->starget->hostdata;
6109 sas_target_priv_data->deleted = 1;
6110 _scsih_ublock_io_device(ioc, sas_device->sas_address);
6111 sas_target_priv_data->handle =
6112 MPT3SAS_INVALID_DEVICE_HANDLE;
6115 if (!ioc->hide_drives)
6116 mpt3sas_transport_port_remove(ioc,
6117 sas_device->sas_address,
6118 sas_device->sas_address_parent);
6120 ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6121 sas_device->handle, (u64)sas_device->sas_address);
6123 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
6126 ioc_info(ioc, "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6128 sas_device->handle, (u64)sas_device->sas_address));
6129 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
6134 * _scsih_sas_topology_change_event_debug - debug for topology event
6135 * @ioc: per adapter object
6136 * @event_data: event data payload
6140 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6141 Mpi2EventDataSasTopologyChangeList_t *event_data)
6147 char *status_str = NULL;
6148 u8 link_rate, prev_link_rate;
6150 switch (event_data->ExpStatus) {
6151 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
6154 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
6155 status_str = "remove";
6157 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
6159 status_str = "responding";
6161 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
6162 status_str = "remove delay";
6165 status_str = "unknown status";
6168 ioc_info(ioc, "sas topology change: (%s)\n", status_str);
6169 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6170 "start_phy(%02d), count(%d)\n",
6171 le16_to_cpu(event_data->ExpanderDevHandle),
6172 le16_to_cpu(event_data->EnclosureHandle),
6173 event_data->StartPhyNum, event_data->NumEntries);
6174 for (i = 0; i < event_data->NumEntries; i++) {
6175 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
6178 phy_number = event_data->StartPhyNum + i;
6179 reason_code = event_data->PHY[i].PhyStatus &
6180 MPI2_EVENT_SAS_TOPO_RC_MASK;
6181 switch (reason_code) {
6182 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
6183 status_str = "target add";
6185 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
6186 status_str = "target remove";
6188 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
6189 status_str = "delay target remove";
6191 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
6192 status_str = "link rate change";
6194 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
6195 status_str = "target responding";
6198 status_str = "unknown";
6201 link_rate = event_data->PHY[i].LinkRate >> 4;
6202 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
6203 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6204 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
6205 handle, status_str, link_rate, prev_link_rate);
6211 * _scsih_sas_topology_change_event - handle topology changes
6212 * @ioc: per adapter object
6213 * @fw_event: The fw_event_work object
6218 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
6219 struct fw_event_work *fw_event)
6222 u16 parent_handle, handle;
6224 u8 phy_number, max_phys;
6225 struct _sas_node *sas_expander;
6227 unsigned long flags;
6228 u8 link_rate, prev_link_rate;
6229 Mpi2EventDataSasTopologyChangeList_t *event_data =
6230 (Mpi2EventDataSasTopologyChangeList_t *)
6231 fw_event->event_data;
6233 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6234 _scsih_sas_topology_change_event_debug(ioc, event_data);
6236 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
6239 if (!ioc->sas_hba.num_phys)
6240 _scsih_sas_host_add(ioc);
6242 _scsih_sas_host_refresh(ioc);
6244 if (fw_event->ignore) {
6245 dewtprintk(ioc, ioc_info(ioc, "ignoring expander event\n"));
6249 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
6251 /* handle expander add */
6252 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
6253 if (_scsih_expander_add(ioc, parent_handle) != 0)
6256 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6257 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
6260 sas_address = sas_expander->sas_address;
6261 max_phys = sas_expander->num_phys;
6262 } else if (parent_handle < ioc->sas_hba.num_phys) {
6263 sas_address = ioc->sas_hba.sas_address;
6264 max_phys = ioc->sas_hba.num_phys;
6266 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6269 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6271 /* handle siblings events */
6272 for (i = 0; i < event_data->NumEntries; i++) {
6273 if (fw_event->ignore) {
6275 ioc_info(ioc, "ignoring expander event\n"));
6278 if (ioc->remove_host || ioc->pci_error_recovery)
6280 phy_number = event_data->StartPhyNum + i;
6281 if (phy_number >= max_phys)
6283 reason_code = event_data->PHY[i].PhyStatus &
6284 MPI2_EVENT_SAS_TOPO_RC_MASK;
6285 if ((event_data->PHY[i].PhyStatus &
6286 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
6287 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
6289 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
6292 link_rate = event_data->PHY[i].LinkRate >> 4;
6293 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
6294 switch (reason_code) {
6295 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
6297 if (ioc->shost_recovery)
6300 if (link_rate == prev_link_rate)
6303 mpt3sas_transport_update_links(ioc, sas_address,
6304 handle, phy_number, link_rate);
6306 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
6309 _scsih_check_device(ioc, sas_address, handle,
6310 phy_number, link_rate);
6312 if (!test_bit(handle, ioc->pend_os_device_add))
6317 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
6319 if (ioc->shost_recovery)
6322 mpt3sas_transport_update_links(ioc, sas_address,
6323 handle, phy_number, link_rate);
6325 _scsih_add_device(ioc, handle, phy_number, 0);
6328 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
6330 _scsih_device_remove_by_handle(ioc, handle);
6335 /* handle expander removal */
6336 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
6338 mpt3sas_expander_remove(ioc, sas_address);
6344 * _scsih_sas_device_status_change_event_debug - debug for device event
6346 * @event_data: event data payload
6350 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6351 Mpi2EventDataSasDeviceStatusChange_t *event_data)
6353 char *reason_str = NULL;
6355 switch (event_data->ReasonCode) {
6356 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
6357 reason_str = "smart data";
6359 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
6360 reason_str = "unsupported device discovered";
6362 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
6363 reason_str = "internal device reset";
6365 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
6366 reason_str = "internal task abort";
6368 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
6369 reason_str = "internal task abort set";
6371 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
6372 reason_str = "internal clear task set";
6374 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
6375 reason_str = "internal query task";
6377 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
6378 reason_str = "sata init failure";
6380 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
6381 reason_str = "internal device reset complete";
6383 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
6384 reason_str = "internal task abort complete";
6386 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
6387 reason_str = "internal async notification";
6389 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
6390 reason_str = "expander reduced functionality";
6392 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
6393 reason_str = "expander reduced functionality complete";
6396 reason_str = "unknown reason";
6399 ioc_info(ioc, "device status change: (%s)\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6400 reason_str, le16_to_cpu(event_data->DevHandle),
6401 (u64)le64_to_cpu(event_data->SASAddress),
6402 le16_to_cpu(event_data->TaskTag));
6403 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
6404 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
6405 event_data->ASC, event_data->ASCQ);
6410 * _scsih_sas_device_status_change_event - handle device status change
6411 * @ioc: per adapter object
6412 * @fw_event: The fw_event_work object
6416 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
6417 struct fw_event_work *fw_event)
6419 struct MPT3SAS_TARGET *target_priv_data;
6420 struct _sas_device *sas_device;
6422 unsigned long flags;
6423 Mpi2EventDataSasDeviceStatusChange_t *event_data =
6424 (Mpi2EventDataSasDeviceStatusChange_t *)
6425 fw_event->event_data;
6427 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6428 _scsih_sas_device_status_change_event_debug(ioc,
6431 /* In MPI Revision K (0xC), the internal device reset complete was
6432 * implemented, so avoid setting tm_busy flag for older firmware.
6434 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
6437 if (event_data->ReasonCode !=
6438 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
6439 event_data->ReasonCode !=
6440 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
6443 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6444 sas_address = le64_to_cpu(event_data->SASAddress);
6445 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
6448 if (!sas_device || !sas_device->starget)
6451 target_priv_data = sas_device->starget->hostdata;
6452 if (!target_priv_data)
6455 if (event_data->ReasonCode ==
6456 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
6457 target_priv_data->tm_busy = 1;
6459 target_priv_data->tm_busy = 0;
6463 sas_device_put(sas_device);
6465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6470 * _scsih_check_pcie_access_status - check access flags
6471 * @ioc: per adapter object
6473 * @handle: sas device handle
6474 * @access_status: errors returned during discovery of the device
6476 * Return: 0 for success, else failure
6479 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6480 u16 handle, u8 access_status)
6485 switch (access_status) {
6486 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS:
6487 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION:
6490 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED:
6491 desc = "PCIe device capability failed";
6493 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED:
6494 desc = "PCIe device blocked";
6496 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED:
6497 desc = "PCIe device mem space access failed";
6499 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE:
6500 desc = "PCIe device unsupported";
6502 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED:
6503 desc = "PCIe device MSIx Required";
6505 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX:
6506 desc = "PCIe device init fail max";
6508 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN:
6509 desc = "PCIe device status unknown";
6511 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT:
6512 desc = "nvme ready timeout";
6514 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED:
6515 desc = "nvme device configuration unsupported";
6517 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED:
6518 desc = "nvme identify failed";
6520 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED:
6521 desc = "nvme qconfig failed";
6523 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED:
6524 desc = "nvme qcreation failed";
6526 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED:
6527 desc = "nvme eventcfg failed";
6529 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED:
6530 desc = "nvme get feature stat failed";
6532 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT:
6533 desc = "nvme idle timeout";
6535 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS:
6536 desc = "nvme failure status";
6539 ioc_err(ioc, "NVMe discovery error(0x%02x): wwid(0x%016llx), handle(0x%04x)\n",
6540 access_status, (u64)wwid, handle);
6547 ioc_info(ioc, "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6548 desc, (u64)wwid, handle);
6553 * _scsih_pcie_device_remove_from_sml - removing pcie device
6554 * from SML and free up associated memory
6555 * @ioc: per adapter object
6556 * @pcie_device: the pcie_device object
6559 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
6560 struct _pcie_device *pcie_device)
6562 struct MPT3SAS_TARGET *sas_target_priv_data;
6565 ioc_info(ioc, "%s: enter: handle(0x%04x), wwid(0x%016llx)\n",
6567 pcie_device->handle, (u64)pcie_device->wwid));
6568 if (pcie_device->enclosure_handle != 0)
6570 ioc_info(ioc, "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6572 (u64)pcie_device->enclosure_logical_id,
6573 pcie_device->slot));
6574 if (pcie_device->connector_name[0] != '\0')
6576 ioc_info(ioc, "%s: enter: enclosure level(0x%04x), connector name(%s)\n",
6578 pcie_device->enclosure_level,
6579 pcie_device->connector_name));
6581 if (pcie_device->starget && pcie_device->starget->hostdata) {
6582 sas_target_priv_data = pcie_device->starget->hostdata;
6583 sas_target_priv_data->deleted = 1;
6584 _scsih_ublock_io_device(ioc, pcie_device->wwid);
6585 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
6588 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
6589 pcie_device->handle, (u64)pcie_device->wwid);
6590 if (pcie_device->enclosure_handle != 0)
6591 ioc_info(ioc, "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6592 (u64)pcie_device->enclosure_logical_id,
6594 if (pcie_device->connector_name[0] != '\0')
6595 ioc_info(ioc, "removing: enclosure level(0x%04x), connector name( %s)\n",
6596 pcie_device->enclosure_level,
6597 pcie_device->connector_name);
6599 if (pcie_device->starget)
6600 scsi_remove_target(&pcie_device->starget->dev);
6602 ioc_info(ioc, "%s: exit: handle(0x%04x), wwid(0x%016llx)\n",
6604 pcie_device->handle, (u64)pcie_device->wwid));
6605 if (pcie_device->enclosure_handle != 0)
6607 ioc_info(ioc, "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6609 (u64)pcie_device->enclosure_logical_id,
6610 pcie_device->slot));
6611 if (pcie_device->connector_name[0] != '\0')
6613 ioc_info(ioc, "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6615 pcie_device->enclosure_level,
6616 pcie_device->connector_name));
6618 kfree(pcie_device->serial_number);
6623 * _scsih_pcie_check_device - checking device responsiveness
6624 * @ioc: per adapter object
6625 * @handle: attached device handle
6628 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6630 Mpi2ConfigReply_t mpi_reply;
6631 Mpi26PCIeDevicePage0_t pcie_device_pg0;
6633 struct _pcie_device *pcie_device;
6635 unsigned long flags;
6636 struct scsi_target *starget;
6637 struct MPT3SAS_TARGET *sas_target_priv_data;
6640 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
6641 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
6644 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6645 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6648 /* check if this is end device */
6649 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
6650 if (!(_scsih_is_nvme_device(device_info)))
6653 wwid = le64_to_cpu(pcie_device_pg0.WWID);
6654 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
6655 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
6658 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6662 if (unlikely(pcie_device->handle != handle)) {
6663 starget = pcie_device->starget;
6664 sas_target_priv_data = starget->hostdata;
6665 starget_printk(KERN_INFO, starget,
6666 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6667 pcie_device->handle, handle);
6668 sas_target_priv_data->handle = handle;
6669 pcie_device->handle = handle;
6671 if (le32_to_cpu(pcie_device_pg0.Flags) &
6672 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
6673 pcie_device->enclosure_level =
6674 pcie_device_pg0.EnclosureLevel;
6675 memcpy(&pcie_device->connector_name[0],
6676 &pcie_device_pg0.ConnectorName[0], 4);
6678 pcie_device->enclosure_level = 0;
6679 pcie_device->connector_name[0] = '\0';
6683 /* check if device is present */
6684 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
6685 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
6686 ioc_info(ioc, "device is not present handle(0x%04x), flags!!!\n",
6688 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6689 pcie_device_put(pcie_device);
6693 /* check if there were any issues with discovery */
6694 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
6695 pcie_device_pg0.AccessStatus)) {
6696 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6697 pcie_device_put(pcie_device);
6701 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6702 pcie_device_put(pcie_device);
6704 _scsih_ublock_io_device(ioc, wwid);
6710 * _scsih_pcie_add_device - creating pcie device object
6711 * @ioc: per adapter object
6712 * @handle: pcie device handle
6714 * Creating end device object, stored in ioc->pcie_device_list.
6716 * Return: 1 means queue the event later, 0 means complete the event
6719 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6721 Mpi26PCIeDevicePage0_t pcie_device_pg0;
6722 Mpi26PCIeDevicePage2_t pcie_device_pg2;
6723 Mpi2ConfigReply_t mpi_reply;
6724 struct _pcie_device *pcie_device;
6725 struct _enclosure_node *enclosure_dev;
6729 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
6730 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
6731 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6732 __FILE__, __LINE__, __func__);
6735 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6736 MPI2_IOCSTATUS_MASK;
6737 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6738 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6739 __FILE__, __LINE__, __func__);
6743 set_bit(handle, ioc->pend_os_device_add);
6744 wwid = le64_to_cpu(pcie_device_pg0.WWID);
6746 /* check if device is present */
6747 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
6748 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
6749 ioc_err(ioc, "device is not present handle(0x04%x)!!!\n",
6754 /* check if there were any issues with discovery */
6755 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
6756 pcie_device_pg0.AccessStatus))
6759 if (!(_scsih_is_nvme_device(le32_to_cpu(pcie_device_pg0.DeviceInfo))))
6762 pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid);
6764 clear_bit(handle, ioc->pend_os_device_add);
6765 pcie_device_put(pcie_device);
6769 pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL);
6771 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6772 __FILE__, __LINE__, __func__);
6776 kref_init(&pcie_device->refcount);
6777 pcie_device->id = ioc->pcie_target_id++;
6778 pcie_device->channel = PCIE_CHANNEL;
6779 pcie_device->handle = handle;
6780 pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
6781 pcie_device->wwid = wwid;
6782 pcie_device->port_num = pcie_device_pg0.PortNum;
6783 pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) &
6784 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
6786 pcie_device->enclosure_handle =
6787 le16_to_cpu(pcie_device_pg0.EnclosureHandle);
6788 if (pcie_device->enclosure_handle != 0)
6789 pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot);
6791 if (le32_to_cpu(pcie_device_pg0.Flags) &
6792 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
6793 pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel;
6794 memcpy(&pcie_device->connector_name[0],
6795 &pcie_device_pg0.ConnectorName[0], 4);
6797 pcie_device->enclosure_level = 0;
6798 pcie_device->connector_name[0] = '\0';
6801 /* get enclosure_logical_id */
6802 if (pcie_device->enclosure_handle) {
6804 mpt3sas_scsih_enclosure_find_by_handle(ioc,
6805 pcie_device->enclosure_handle);
6807 pcie_device->enclosure_logical_id =
6808 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
6810 /* TODO -- Add device name once FW supports it */
6811 if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply,
6812 &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)) {
6813 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6814 __FILE__, __LINE__, __func__);
6819 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6820 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6821 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6822 __FILE__, __LINE__, __func__);
6826 pcie_device->nvme_mdts =
6827 le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize);
6828 if (pcie_device_pg2.ControllerResetTO)
6829 pcie_device->reset_timeout =
6830 pcie_device_pg2.ControllerResetTO;
6832 pcie_device->reset_timeout = 30;
6834 if (ioc->wait_for_discovery_to_complete)
6835 _scsih_pcie_device_init_add(ioc, pcie_device);
6837 _scsih_pcie_device_add(ioc, pcie_device);
6839 pcie_device_put(pcie_device);
6844 * _scsih_pcie_topology_change_event_debug - debug for topology
6846 * @ioc: per adapter object
6847 * @event_data: event data payload
6851 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6852 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
6858 char *status_str = NULL;
6859 u8 link_rate, prev_link_rate;
6861 switch (event_data->SwitchStatus) {
6862 case MPI26_EVENT_PCIE_TOPO_SS_ADDED:
6865 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
6866 status_str = "remove";
6868 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING:
6870 status_str = "responding";
6872 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
6873 status_str = "remove delay";
6876 status_str = "unknown status";
6879 ioc_info(ioc, "pcie topology change: (%s)\n", status_str);
6880 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
6881 "start_port(%02d), count(%d)\n",
6882 le16_to_cpu(event_data->SwitchDevHandle),
6883 le16_to_cpu(event_data->EnclosureHandle),
6884 event_data->StartPortNum, event_data->NumEntries);
6885 for (i = 0; i < event_data->NumEntries; i++) {
6887 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
6890 port_number = event_data->StartPortNum + i;
6891 reason_code = event_data->PortEntry[i].PortStatus;
6892 switch (reason_code) {
6893 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
6894 status_str = "target add";
6896 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
6897 status_str = "target remove";
6899 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
6900 status_str = "delay target remove";
6902 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
6903 status_str = "link rate change";
6905 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE:
6906 status_str = "target responding";
6909 status_str = "unknown";
6912 link_rate = event_data->PortEntry[i].CurrentPortInfo &
6913 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
6914 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo &
6915 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
6916 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
6917 " link rate: new(0x%02x), old(0x%02x)\n", port_number,
6918 handle, status_str, link_rate, prev_link_rate);
6923 * _scsih_pcie_topology_change_event - handle PCIe topology
6925 * @ioc: per adapter object
6926 * @fw_event: The fw_event_work object
6931 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
6932 struct fw_event_work *fw_event)
6937 u8 link_rate, prev_link_rate;
6938 unsigned long flags;
6940 Mpi26EventDataPCIeTopologyChangeList_t *event_data =
6941 (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data;
6942 struct _pcie_device *pcie_device;
6944 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6945 _scsih_pcie_topology_change_event_debug(ioc, event_data);
6947 if (ioc->shost_recovery || ioc->remove_host ||
6948 ioc->pci_error_recovery)
6951 if (fw_event->ignore) {
6952 dewtprintk(ioc, ioc_info(ioc, "ignoring switch event\n"));
6956 /* handle siblings events */
6957 for (i = 0; i < event_data->NumEntries; i++) {
6958 if (fw_event->ignore) {
6960 ioc_info(ioc, "ignoring switch event\n"));
6963 if (ioc->remove_host || ioc->pci_error_recovery)
6965 reason_code = event_data->PortEntry[i].PortStatus;
6967 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
6971 link_rate = event_data->PortEntry[i].CurrentPortInfo
6972 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
6973 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo
6974 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
6976 switch (reason_code) {
6977 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
6978 if (ioc->shost_recovery)
6980 if (link_rate == prev_link_rate)
6982 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
6985 _scsih_pcie_check_device(ioc, handle);
6987 /* This code after this point handles the test case
6988 * where a device has been added, however its returning
6989 * BUSY for sometime. Then before the Device Missing
6990 * Delay expires and the device becomes READY, the
6991 * device is removed and added back.
6993 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
6994 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
6995 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
6998 pcie_device_put(pcie_device);
7002 if (!test_bit(handle, ioc->pend_os_device_add))
7006 ioc_info(ioc, "handle(0x%04x) device not found: convert event to a device add\n",
7008 event_data->PortEntry[i].PortStatus &= 0xF0;
7009 event_data->PortEntry[i].PortStatus |=
7010 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED;
7012 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
7013 if (ioc->shost_recovery)
7015 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
7018 rc = _scsih_pcie_add_device(ioc, handle);
7020 /* mark entry vacant */
7021 /* TODO This needs to be reviewed and fixed,
7022 * we dont have an entry
7023 * to make an event void like vacant
7025 event_data->PortEntry[i].PortStatus |=
7026 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE;
7029 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
7030 _scsih_pcie_device_remove_by_handle(ioc, handle);
7037 * _scsih_pcie_device_status_change_event_debug - debug for device event
7039 * @event_data: event data payload
7043 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7044 Mpi26EventDataPCIeDeviceStatusChange_t *event_data)
7046 char *reason_str = NULL;
7048 switch (event_data->ReasonCode) {
7049 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA:
7050 reason_str = "smart data";
7052 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED:
7053 reason_str = "unsupported device discovered";
7055 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET:
7056 reason_str = "internal device reset";
7058 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL:
7059 reason_str = "internal task abort";
7061 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
7062 reason_str = "internal task abort set";
7064 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
7065 reason_str = "internal clear task set";
7067 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL:
7068 reason_str = "internal query task";
7070 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE:
7071 reason_str = "device init failure";
7073 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
7074 reason_str = "internal device reset complete";
7076 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
7077 reason_str = "internal task abort complete";
7079 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION:
7080 reason_str = "internal async notification";
7082 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED:
7083 reason_str = "pcie hot reset failed";
7086 reason_str = "unknown reason";
7090 ioc_info(ioc, "PCIE device status change: (%s)\n"
7091 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7092 reason_str, le16_to_cpu(event_data->DevHandle),
7093 (u64)le64_to_cpu(event_data->WWID),
7094 le16_to_cpu(event_data->TaskTag));
7095 if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA)
7096 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
7097 event_data->ASC, event_data->ASCQ);
7102 * _scsih_pcie_device_status_change_event - handle device status
7104 * @ioc: per adapter object
7105 * @fw_event: The fw_event_work object
7109 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7110 struct fw_event_work *fw_event)
7112 struct MPT3SAS_TARGET *target_priv_data;
7113 struct _pcie_device *pcie_device;
7115 unsigned long flags;
7116 Mpi26EventDataPCIeDeviceStatusChange_t *event_data =
7117 (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data;
7118 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7119 _scsih_pcie_device_status_change_event_debug(ioc,
7122 if (event_data->ReasonCode !=
7123 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET &&
7124 event_data->ReasonCode !=
7125 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
7128 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
7129 wwid = le64_to_cpu(event_data->WWID);
7130 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
7132 if (!pcie_device || !pcie_device->starget)
7135 target_priv_data = pcie_device->starget->hostdata;
7136 if (!target_priv_data)
7139 if (event_data->ReasonCode ==
7140 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET)
7141 target_priv_data->tm_busy = 1;
7143 target_priv_data->tm_busy = 0;
7146 pcie_device_put(pcie_device);
7148 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
7152 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7154 * @ioc: per adapter object
7155 * @event_data: event data payload
7159 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7160 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
7162 char *reason_str = NULL;
7164 switch (event_data->ReasonCode) {
7165 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
7166 reason_str = "enclosure add";
7168 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
7169 reason_str = "enclosure remove";
7172 reason_str = "unknown reason";
7176 ioc_info(ioc, "enclosure status change: (%s)\n"
7177 "\thandle(0x%04x), enclosure logical id(0x%016llx) number slots(%d)\n",
7179 le16_to_cpu(event_data->EnclosureHandle),
7180 (u64)le64_to_cpu(event_data->EnclosureLogicalID),
7181 le16_to_cpu(event_data->StartSlot));
7185 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7186 * @ioc: per adapter object
7187 * @fw_event: The fw_event_work object
7191 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7192 struct fw_event_work *fw_event)
7194 Mpi2ConfigReply_t mpi_reply;
7195 struct _enclosure_node *enclosure_dev = NULL;
7196 Mpi2EventDataSasEnclDevStatusChange_t *event_data =
7197 (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data;
7199 u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle);
7201 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7202 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
7203 (Mpi2EventDataSasEnclDevStatusChange_t *)
7204 fw_event->event_data);
7205 if (ioc->shost_recovery)
7208 if (enclosure_handle)
7210 mpt3sas_scsih_enclosure_find_by_handle(ioc,
7212 switch (event_data->ReasonCode) {
7213 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
7214 if (!enclosure_dev) {
7216 kzalloc(sizeof(struct _enclosure_node),
7218 if (!enclosure_dev) {
7219 ioc_info(ioc, "failure at %s:%d/%s()!\n",
7220 __FILE__, __LINE__, __func__);
7223 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
7224 &enclosure_dev->pg0,
7225 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
7228 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
7229 MPI2_IOCSTATUS_MASK)) {
7230 kfree(enclosure_dev);
7234 list_add_tail(&enclosure_dev->list,
7235 &ioc->enclosure_list);
7238 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
7239 if (enclosure_dev) {
7240 list_del(&enclosure_dev->list);
7241 kfree(enclosure_dev);
7250 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7251 * @ioc: per adapter object
7252 * @fw_event: The fw_event_work object
7256 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
7257 struct fw_event_work *fw_event)
7259 struct scsi_cmnd *scmd;
7260 struct scsi_device *sdev;
7261 struct scsiio_tracker *st;
7264 struct MPT3SAS_DEVICE *sas_device_priv_data;
7265 u32 termination_count;
7267 Mpi2SCSITaskManagementReply_t *mpi_reply;
7268 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
7269 (Mpi2EventDataSasBroadcastPrimitive_t *)
7270 fw_event->event_data;
7272 unsigned long flags;
7275 u8 task_abort_retries;
7277 mutex_lock(&ioc->tm_cmds.mutex);
7278 ioc_info(ioc, "%s: enter: phy number(%d), width(%d)\n",
7279 __func__, event_data->PhyNum, event_data->PortWidth);
7281 _scsih_block_io_all_device(ioc);
7283 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7284 mpi_reply = ioc->tm_cmds.reply;
7285 broadcast_aen_retry:
7287 /* sanity checks for retrying this loop */
7288 if (max_retries++ == 5) {
7289 dewtprintk(ioc, ioc_info(ioc, "%s: giving up\n", __func__));
7291 } else if (max_retries > 1)
7293 ioc_info(ioc, "%s: %d retry\n",
7294 __func__, max_retries - 1));
7296 termination_count = 0;
7298 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
7299 if (ioc->shost_recovery)
7301 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
7304 st = scsi_cmd_priv(scmd);
7305 sdev = scmd->device;
7306 sas_device_priv_data = sdev->hostdata;
7307 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
7309 /* skip hidden raid components */
7310 if (sas_device_priv_data->sas_target->flags &
7311 MPT_TARGET_FLAGS_RAID_COMPONENT)
7314 if (sas_device_priv_data->sas_target->flags &
7315 MPT_TARGET_FLAGS_VOLUME)
7317 /* skip PCIe devices */
7318 if (sas_device_priv_data->sas_target->flags &
7319 MPT_TARGET_FLAGS_PCIE_DEVICE)
7322 handle = sas_device_priv_data->sas_target->handle;
7323 lun = sas_device_priv_data->lun;
7326 if (ioc->shost_recovery)
7329 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
7330 r = mpt3sas_scsih_issue_tm(ioc, handle, lun,
7331 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
7332 st->msix_io, 30, 0);
7334 sdev_printk(KERN_WARNING, sdev,
7335 "mpt3sas_scsih_issue_tm: FAILED when sending "
7336 "QUERY_TASK: scmd(%p)\n", scmd);
7337 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7338 goto broadcast_aen_retry;
7340 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
7341 & MPI2_IOCSTATUS_MASK;
7342 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7343 sdev_printk(KERN_WARNING, sdev,
7344 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7346 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7347 goto broadcast_aen_retry;
7350 /* see if IO is still owned by IOC and target */
7351 if (mpi_reply->ResponseCode ==
7352 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
7353 mpi_reply->ResponseCode ==
7354 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
7355 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7358 task_abort_retries = 0;
7360 if (task_abort_retries++ == 60) {
7362 ioc_info(ioc, "%s: ABORT_TASK: giving up\n",
7364 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7365 goto broadcast_aen_retry;
7368 if (ioc->shost_recovery)
7371 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->lun,
7372 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, st->smid,
7373 st->msix_io, 30, 0);
7374 if (r == FAILED || st->cb_idx != 0xFF) {
7375 sdev_printk(KERN_WARNING, sdev,
7376 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7377 "scmd(%p)\n", scmd);
7381 if (task_abort_retries > 1)
7382 sdev_printk(KERN_WARNING, sdev,
7383 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7385 task_abort_retries - 1, scmd);
7387 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
7388 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
7391 if (ioc->broadcast_aen_pending) {
7394 "%s: loop back due to pending AEN\n",
7396 ioc->broadcast_aen_pending = 0;
7397 goto broadcast_aen_retry;
7401 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
7405 ioc_info(ioc, "%s - exit, query_count = %d termination_count = %d\n",
7406 __func__, query_count, termination_count));
7408 ioc->broadcast_aen_busy = 0;
7409 if (!ioc->shost_recovery)
7410 _scsih_ublock_io_all_device(ioc);
7411 mutex_unlock(&ioc->tm_cmds.mutex);
7415 * _scsih_sas_discovery_event - handle discovery events
7416 * @ioc: per adapter object
7417 * @fw_event: The fw_event_work object
7421 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
7422 struct fw_event_work *fw_event)
7424 Mpi2EventDataSasDiscovery_t *event_data =
7425 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
7427 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
7428 ioc_info(ioc, "discovery event: (%s)",
7429 event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED ?
7431 if (event_data->DiscoveryStatus)
7432 pr_cont("discovery_status(0x%08x)",
7433 le32_to_cpu(event_data->DiscoveryStatus));
7437 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
7438 !ioc->sas_hba.num_phys) {
7439 if (disable_discovery > 0 && ioc->shost_recovery) {
7440 /* Wait for the reset to complete */
7441 while (ioc->shost_recovery)
7444 _scsih_sas_host_add(ioc);
7449 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
7451 * @ioc: per adapter object
7452 * @fw_event: The fw_event_work object
7456 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc,
7457 struct fw_event_work *fw_event)
7459 Mpi25EventDataSasDeviceDiscoveryError_t *event_data =
7460 (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data;
7462 switch (event_data->ReasonCode) {
7463 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED:
7464 ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has failed\n",
7465 le16_to_cpu(event_data->DevHandle),
7466 (u64)le64_to_cpu(event_data->SASAddress),
7467 event_data->PhysicalPort);
7469 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT:
7470 ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has timed out\n",
7471 le16_to_cpu(event_data->DevHandle),
7472 (u64)le64_to_cpu(event_data->SASAddress),
7473 event_data->PhysicalPort);
7481 * _scsih_pcie_enumeration_event - handle enumeration events
7482 * @ioc: per adapter object
7483 * @fw_event: The fw_event_work object
7487 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc,
7488 struct fw_event_work *fw_event)
7490 Mpi26EventDataPCIeEnumeration_t *event_data =
7491 (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data;
7493 if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK))
7496 ioc_info(ioc, "pcie enumeration event: (%s) Flag 0x%02x",
7497 (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ?
7498 "started" : "completed",
7500 if (event_data->EnumerationStatus)
7501 pr_cont("enumeration_status(0x%08x)",
7502 le32_to_cpu(event_data->EnumerationStatus));
7507 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7508 * @ioc: per adapter object
7509 * @handle: device handle for physical disk
7510 * @phys_disk_num: physical disk number
7512 * Return: 0 for success, else failure.
7515 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
7517 Mpi2RaidActionRequest_t *mpi_request;
7518 Mpi2RaidActionReply_t *mpi_reply;
7525 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
7528 mutex_lock(&ioc->scsih_cmds.mutex);
7530 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7531 ioc_err(ioc, "%s: scsih_cmd in use\n", __func__);
7535 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7537 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7539 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
7540 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7545 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7546 ioc->scsih_cmds.smid = smid;
7547 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7549 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7550 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
7551 mpi_request->PhysDiskNum = phys_disk_num;
7554 ioc_info(ioc, "IR RAID_ACTION: turning fast path on for handle(0x%04x), phys_disk_num (0x%02x)\n",
7555 handle, phys_disk_num));
7557 init_completion(&ioc->scsih_cmds.done);
7558 mpt3sas_base_put_smid_default(ioc, smid);
7559 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7561 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7563 mpt3sas_base_check_cmd_timeout(ioc,
7564 ioc->scsih_cmds.status, mpi_request,
7565 sizeof(Mpi2RaidActionRequest_t)/4);
7570 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7572 mpi_reply = ioc->scsih_cmds.reply;
7573 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
7574 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
7575 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
7578 ioc_status &= MPI2_IOCSTATUS_MASK;
7579 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7581 ioc_info(ioc, "IR RAID_ACTION: failed: ioc_status(0x%04x), loginfo(0x%08x)!!!\n",
7582 ioc_status, log_info));
7586 ioc_info(ioc, "IR RAID_ACTION: completed successfully\n"));
7590 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7591 mutex_unlock(&ioc->scsih_cmds.mutex);
7594 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
7599 * _scsih_reprobe_lun - reprobing lun
7600 * @sdev: scsi device struct
7601 * @no_uld_attach: sdev->no_uld_attach flag setting
7605 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
7607 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
7608 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
7609 sdev->no_uld_attach ? "hiding" : "exposing");
7610 WARN_ON(scsi_device_reprobe(sdev));
7614 * _scsih_sas_volume_add - add new volume
7615 * @ioc: per adapter object
7616 * @element: IR config element data
7620 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
7621 Mpi2EventIrConfigElement_t *element)
7623 struct _raid_device *raid_device;
7624 unsigned long flags;
7626 u16 handle = le16_to_cpu(element->VolDevHandle);
7629 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
7631 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7632 __FILE__, __LINE__, __func__);
7636 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7637 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
7638 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7643 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
7645 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7646 __FILE__, __LINE__, __func__);
7650 raid_device->id = ioc->sas_id++;
7651 raid_device->channel = RAID_CHANNEL;
7652 raid_device->handle = handle;
7653 raid_device->wwid = wwid;
7654 _scsih_raid_device_add(ioc, raid_device);
7655 if (!ioc->wait_for_discovery_to_complete) {
7656 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7657 raid_device->id, 0);
7659 _scsih_raid_device_remove(ioc, raid_device);
7661 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7662 _scsih_determine_boot_device(ioc, raid_device, 1);
7663 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7668 * _scsih_sas_volume_delete - delete volume
7669 * @ioc: per adapter object
7670 * @handle: volume device handle
7674 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
7676 struct _raid_device *raid_device;
7677 unsigned long flags;
7678 struct MPT3SAS_TARGET *sas_target_priv_data;
7679 struct scsi_target *starget = NULL;
7681 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7682 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
7684 if (raid_device->starget) {
7685 starget = raid_device->starget;
7686 sas_target_priv_data = starget->hostdata;
7687 sas_target_priv_data->deleted = 1;
7689 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
7690 raid_device->handle, (u64)raid_device->wwid);
7691 list_del(&raid_device->list);
7694 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7696 scsi_remove_target(&starget->dev);
7700 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7701 * @ioc: per adapter object
7702 * @element: IR config element data
7706 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
7707 Mpi2EventIrConfigElement_t *element)
7709 struct _sas_device *sas_device;
7710 struct scsi_target *starget = NULL;
7711 struct MPT3SAS_TARGET *sas_target_priv_data;
7712 unsigned long flags;
7713 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7715 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7716 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
7718 sas_device->volume_handle = 0;
7719 sas_device->volume_wwid = 0;
7720 clear_bit(handle, ioc->pd_handles);
7721 if (sas_device->starget && sas_device->starget->hostdata) {
7722 starget = sas_device->starget;
7723 sas_target_priv_data = starget->hostdata;
7724 sas_target_priv_data->flags &=
7725 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
7728 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7732 /* exposing raid component */
7734 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
7736 sas_device_put(sas_device);
7740 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7741 * @ioc: per adapter object
7742 * @element: IR config element data
7746 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
7747 Mpi2EventIrConfigElement_t *element)
7749 struct _sas_device *sas_device;
7750 struct scsi_target *starget = NULL;
7751 struct MPT3SAS_TARGET *sas_target_priv_data;
7752 unsigned long flags;
7753 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7754 u16 volume_handle = 0;
7755 u64 volume_wwid = 0;
7757 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
7759 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
7762 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7763 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
7765 set_bit(handle, ioc->pd_handles);
7766 if (sas_device->starget && sas_device->starget->hostdata) {
7767 starget = sas_device->starget;
7768 sas_target_priv_data = starget->hostdata;
7769 sas_target_priv_data->flags |=
7770 MPT_TARGET_FLAGS_RAID_COMPONENT;
7771 sas_device->volume_handle = volume_handle;
7772 sas_device->volume_wwid = volume_wwid;
7775 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7779 /* hiding raid component */
7780 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7783 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
7785 sas_device_put(sas_device);
7789 * _scsih_sas_pd_delete - delete pd component
7790 * @ioc: per adapter object
7791 * @element: IR config element data
7795 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
7796 Mpi2EventIrConfigElement_t *element)
7798 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7800 _scsih_device_remove_by_handle(ioc, handle);
7804 * _scsih_sas_pd_add - remove pd component
7805 * @ioc: per adapter object
7806 * @element: IR config element data
7810 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
7811 Mpi2EventIrConfigElement_t *element)
7813 struct _sas_device *sas_device;
7814 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
7815 Mpi2ConfigReply_t mpi_reply;
7816 Mpi2SasDevicePage0_t sas_device_pg0;
7821 set_bit(handle, ioc->pd_handles);
7823 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7825 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7826 sas_device_put(sas_device);
7830 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
7831 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
7832 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7833 __FILE__, __LINE__, __func__);
7837 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7838 MPI2_IOCSTATUS_MASK;
7839 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7840 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7841 __FILE__, __LINE__, __func__);
7845 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7846 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
7847 mpt3sas_transport_update_links(ioc, sas_address, handle,
7848 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7850 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
7851 _scsih_add_device(ioc, handle, 0, 1);
7855 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7856 * @ioc: per adapter object
7857 * @event_data: event data payload
7861 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7862 Mpi2EventDataIrConfigChangeList_t *event_data)
7864 Mpi2EventIrConfigElement_t *element;
7867 char *reason_str = NULL, *element_str = NULL;
7869 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
7871 ioc_info(ioc, "raid config change: (%s), elements(%d)\n",
7872 le32_to_cpu(event_data->Flags) & MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG ?
7873 "foreign" : "native",
7874 event_data->NumElements);
7875 for (i = 0; i < event_data->NumElements; i++, element++) {
7876 switch (element->ReasonCode) {
7877 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
7880 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
7881 reason_str = "remove";
7883 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
7884 reason_str = "no change";
7886 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
7887 reason_str = "hide";
7889 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
7890 reason_str = "unhide";
7892 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
7893 reason_str = "volume_created";
7895 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
7896 reason_str = "volume_deleted";
7898 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
7899 reason_str = "pd_created";
7901 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
7902 reason_str = "pd_deleted";
7905 reason_str = "unknown reason";
7908 element_type = le16_to_cpu(element->ElementFlags) &
7909 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
7910 switch (element_type) {
7911 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
7912 element_str = "volume";
7914 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
7915 element_str = "phys disk";
7917 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
7918 element_str = "hot spare";
7921 element_str = "unknown element";
7924 pr_info("\t(%s:%s), vol handle(0x%04x), " \
7925 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
7926 reason_str, le16_to_cpu(element->VolDevHandle),
7927 le16_to_cpu(element->PhysDiskDevHandle),
7928 element->PhysDiskNum);
7933 * _scsih_sas_ir_config_change_event - handle ir configuration change events
7934 * @ioc: per adapter object
7935 * @fw_event: The fw_event_work object
7939 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
7940 struct fw_event_work *fw_event)
7942 Mpi2EventIrConfigElement_t *element;
7945 Mpi2EventDataIrConfigChangeList_t *event_data =
7946 (Mpi2EventDataIrConfigChangeList_t *)
7947 fw_event->event_data;
7949 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
7950 (!ioc->hide_ir_msg))
7951 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
7953 foreign_config = (le32_to_cpu(event_data->Flags) &
7954 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
7956 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
7957 if (ioc->shost_recovery &&
7958 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
7959 for (i = 0; i < event_data->NumElements; i++, element++) {
7960 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
7961 _scsih_ir_fastpath(ioc,
7962 le16_to_cpu(element->PhysDiskDevHandle),
7963 element->PhysDiskNum);
7968 for (i = 0; i < event_data->NumElements; i++, element++) {
7970 switch (element->ReasonCode) {
7971 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
7972 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
7973 if (!foreign_config)
7974 _scsih_sas_volume_add(ioc, element);
7976 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
7977 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
7978 if (!foreign_config)
7979 _scsih_sas_volume_delete(ioc,
7980 le16_to_cpu(element->VolDevHandle));
7982 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
7983 if (!ioc->is_warpdrive)
7984 _scsih_sas_pd_hide(ioc, element);
7986 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
7987 if (!ioc->is_warpdrive)
7988 _scsih_sas_pd_expose(ioc, element);
7990 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
7991 if (!ioc->is_warpdrive)
7992 _scsih_sas_pd_add(ioc, element);
7994 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
7995 if (!ioc->is_warpdrive)
7996 _scsih_sas_pd_delete(ioc, element);
8003 * _scsih_sas_ir_volume_event - IR volume event
8004 * @ioc: per adapter object
8005 * @fw_event: The fw_event_work object
8009 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
8010 struct fw_event_work *fw_event)
8013 unsigned long flags;
8014 struct _raid_device *raid_device;
8018 Mpi2EventDataIrVolume_t *event_data =
8019 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
8021 if (ioc->shost_recovery)
8024 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
8027 handle = le16_to_cpu(event_data->VolDevHandle);
8028 state = le32_to_cpu(event_data->NewValue);
8029 if (!ioc->hide_ir_msg)
8031 ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8033 le32_to_cpu(event_data->PreviousValue),
8036 case MPI2_RAID_VOL_STATE_MISSING:
8037 case MPI2_RAID_VOL_STATE_FAILED:
8038 _scsih_sas_volume_delete(ioc, handle);
8041 case MPI2_RAID_VOL_STATE_ONLINE:
8042 case MPI2_RAID_VOL_STATE_DEGRADED:
8043 case MPI2_RAID_VOL_STATE_OPTIMAL:
8045 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8046 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
8047 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8052 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
8054 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8055 __FILE__, __LINE__, __func__);
8059 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
8061 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8062 __FILE__, __LINE__, __func__);
8066 raid_device->id = ioc->sas_id++;
8067 raid_device->channel = RAID_CHANNEL;
8068 raid_device->handle = handle;
8069 raid_device->wwid = wwid;
8070 _scsih_raid_device_add(ioc, raid_device);
8071 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8072 raid_device->id, 0);
8074 _scsih_raid_device_remove(ioc, raid_device);
8077 case MPI2_RAID_VOL_STATE_INITIALIZING:
8084 * _scsih_sas_ir_physical_disk_event - PD event
8085 * @ioc: per adapter object
8086 * @fw_event: The fw_event_work object
8090 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
8091 struct fw_event_work *fw_event)
8093 u16 handle, parent_handle;
8095 struct _sas_device *sas_device;
8096 Mpi2ConfigReply_t mpi_reply;
8097 Mpi2SasDevicePage0_t sas_device_pg0;
8099 Mpi2EventDataIrPhysicalDisk_t *event_data =
8100 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
8103 if (ioc->shost_recovery)
8106 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
8109 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
8110 state = le32_to_cpu(event_data->NewValue);
8112 if (!ioc->hide_ir_msg)
8114 ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8116 le32_to_cpu(event_data->PreviousValue),
8120 case MPI2_RAID_PD_STATE_ONLINE:
8121 case MPI2_RAID_PD_STATE_DEGRADED:
8122 case MPI2_RAID_PD_STATE_REBUILDING:
8123 case MPI2_RAID_PD_STATE_OPTIMAL:
8124 case MPI2_RAID_PD_STATE_HOT_SPARE:
8126 if (!ioc->is_warpdrive)
8127 set_bit(handle, ioc->pd_handles);
8129 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
8131 sas_device_put(sas_device);
8135 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8136 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
8138 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8139 __FILE__, __LINE__, __func__);
8143 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8144 MPI2_IOCSTATUS_MASK;
8145 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8146 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8147 __FILE__, __LINE__, __func__);
8151 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
8152 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
8153 mpt3sas_transport_update_links(ioc, sas_address, handle,
8154 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
8156 _scsih_add_device(ioc, handle, 0, 1);
8160 case MPI2_RAID_PD_STATE_OFFLINE:
8161 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
8162 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
8169 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8170 * @ioc: per adapter object
8171 * @event_data: event data payload
8175 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
8176 Mpi2EventDataIrOperationStatus_t *event_data)
8178 char *reason_str = NULL;
8180 switch (event_data->RAIDOperation) {
8181 case MPI2_EVENT_IR_RAIDOP_RESYNC:
8182 reason_str = "resync";
8184 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
8185 reason_str = "online capacity expansion";
8187 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
8188 reason_str = "consistency check";
8190 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
8191 reason_str = "background init";
8193 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
8194 reason_str = "make data consistent";
8201 ioc_info(ioc, "raid operational status: (%s)\thandle(0x%04x), percent complete(%d)\n",
8203 le16_to_cpu(event_data->VolDevHandle),
8204 event_data->PercentComplete);
8208 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8209 * @ioc: per adapter object
8210 * @fw_event: The fw_event_work object
8214 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
8215 struct fw_event_work *fw_event)
8217 Mpi2EventDataIrOperationStatus_t *event_data =
8218 (Mpi2EventDataIrOperationStatus_t *)
8219 fw_event->event_data;
8220 static struct _raid_device *raid_device;
8221 unsigned long flags;
8224 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
8225 (!ioc->hide_ir_msg))
8226 _scsih_sas_ir_operation_status_event_debug(ioc,
8229 /* code added for raid transport support */
8230 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
8232 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8233 handle = le16_to_cpu(event_data->VolDevHandle);
8234 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
8236 raid_device->percent_complete =
8237 event_data->PercentComplete;
8238 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8243 * _scsih_prep_device_scan - initialize parameters prior to device scan
8244 * @ioc: per adapter object
8246 * Set the deleted flag prior to device scan. If the device is found during
8247 * the scan, then we clear the deleted flag.
8250 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
8252 struct MPT3SAS_DEVICE *sas_device_priv_data;
8253 struct scsi_device *sdev;
8255 shost_for_each_device(sdev, ioc->shost) {
8256 sas_device_priv_data = sdev->hostdata;
8257 if (sas_device_priv_data && sas_device_priv_data->sas_target)
8258 sas_device_priv_data->sas_target->deleted = 1;
8263 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8264 * @ioc: per adapter object
8265 * @sas_device_pg0: SAS Device page 0
8267 * After host reset, find out whether devices are still responding.
8268 * Used in _scsih_remove_unresponsive_sas_devices.
8271 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
8272 Mpi2SasDevicePage0_t *sas_device_pg0)
8274 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8275 struct scsi_target *starget;
8276 struct _sas_device *sas_device = NULL;
8277 struct _enclosure_node *enclosure_dev = NULL;
8278 unsigned long flags;
8280 if (sas_device_pg0->EnclosureHandle) {
8282 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8283 le16_to_cpu(sas_device_pg0->EnclosureHandle));
8284 if (enclosure_dev == NULL)
8285 ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
8286 sas_device_pg0->EnclosureHandle);
8288 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8289 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
8290 if ((sas_device->sas_address == le64_to_cpu(
8291 sas_device_pg0->SASAddress)) && (sas_device->slot ==
8292 le16_to_cpu(sas_device_pg0->Slot))) {
8293 sas_device->responding = 1;
8294 starget = sas_device->starget;
8295 if (starget && starget->hostdata) {
8296 sas_target_priv_data = starget->hostdata;
8297 sas_target_priv_data->tm_busy = 0;
8298 sas_target_priv_data->deleted = 0;
8300 sas_target_priv_data = NULL;
8302 starget_printk(KERN_INFO, starget,
8303 "handle(0x%04x), sas_addr(0x%016llx)\n",
8304 le16_to_cpu(sas_device_pg0->DevHandle),
8305 (unsigned long long)
8306 sas_device->sas_address);
8308 if (sas_device->enclosure_handle != 0)
8309 starget_printk(KERN_INFO, starget,
8310 "enclosure logical id(0x%016llx),"
8312 (unsigned long long)
8313 sas_device->enclosure_logical_id,
8316 if (le16_to_cpu(sas_device_pg0->Flags) &
8317 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
8318 sas_device->enclosure_level =
8319 sas_device_pg0->EnclosureLevel;
8320 memcpy(&sas_device->connector_name[0],
8321 &sas_device_pg0->ConnectorName[0], 4);
8323 sas_device->enclosure_level = 0;
8324 sas_device->connector_name[0] = '\0';
8327 sas_device->enclosure_handle =
8328 le16_to_cpu(sas_device_pg0->EnclosureHandle);
8329 sas_device->is_chassis_slot_valid = 0;
8330 if (enclosure_dev) {
8331 sas_device->enclosure_logical_id = le64_to_cpu(
8332 enclosure_dev->pg0.EnclosureLogicalID);
8333 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
8334 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
8335 sas_device->is_chassis_slot_valid = 1;
8336 sas_device->chassis_slot =
8337 enclosure_dev->pg0.ChassisSlot;
8341 if (sas_device->handle == le16_to_cpu(
8342 sas_device_pg0->DevHandle))
8344 pr_info("\thandle changed from(0x%04x)!!!\n",
8345 sas_device->handle);
8346 sas_device->handle = le16_to_cpu(
8347 sas_device_pg0->DevHandle);
8348 if (sas_target_priv_data)
8349 sas_target_priv_data->handle =
8350 le16_to_cpu(sas_device_pg0->DevHandle);
8355 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8359 * _scsih_create_enclosure_list_after_reset - Free Existing list,
8360 * And create enclosure list by scanning all Enclosure Page(0)s
8361 * @ioc: per adapter object
8364 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc)
8366 struct _enclosure_node *enclosure_dev;
8367 Mpi2ConfigReply_t mpi_reply;
8368 u16 enclosure_handle;
8371 /* Free existing enclosure list */
8372 mpt3sas_free_enclosure_list(ioc);
8374 /* Re constructing enclosure list after reset*/
8375 enclosure_handle = 0xFFFF;
8378 kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL);
8379 if (!enclosure_dev) {
8380 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8381 __FILE__, __LINE__, __func__);
8384 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
8385 &enclosure_dev->pg0,
8386 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE,
8389 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
8390 MPI2_IOCSTATUS_MASK)) {
8391 kfree(enclosure_dev);
8394 list_add_tail(&enclosure_dev->list,
8395 &ioc->enclosure_list);
8397 le16_to_cpu(enclosure_dev->pg0.EnclosureHandle);
8402 * _scsih_search_responding_sas_devices -
8403 * @ioc: per adapter object
8405 * After host reset, find out whether devices are still responding.
8409 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
8411 Mpi2SasDevicePage0_t sas_device_pg0;
8412 Mpi2ConfigReply_t mpi_reply;
8417 ioc_info(ioc, "search for end-devices: start\n");
8419 if (list_empty(&ioc->sas_device_list))
8423 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8424 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
8426 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8427 MPI2_IOCSTATUS_MASK;
8428 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8430 handle = le16_to_cpu(sas_device_pg0.DevHandle);
8431 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
8432 if (!(_scsih_is_end_device(device_info)))
8434 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
8438 ioc_info(ioc, "search for end-devices: complete\n");
8442 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8443 * @ioc: per adapter object
8444 * @pcie_device_pg0: PCIe Device page 0
8446 * After host reset, find out whether devices are still responding.
8447 * Used in _scsih_remove_unresponding_devices.
8450 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc,
8451 Mpi26PCIeDevicePage0_t *pcie_device_pg0)
8453 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8454 struct scsi_target *starget;
8455 struct _pcie_device *pcie_device;
8456 unsigned long flags;
8458 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8459 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
8460 if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID))
8461 && (pcie_device->slot == le16_to_cpu(
8462 pcie_device_pg0->Slot))) {
8463 pcie_device->responding = 1;
8464 starget = pcie_device->starget;
8465 if (starget && starget->hostdata) {
8466 sas_target_priv_data = starget->hostdata;
8467 sas_target_priv_data->tm_busy = 0;
8468 sas_target_priv_data->deleted = 0;
8470 sas_target_priv_data = NULL;
8472 starget_printk(KERN_INFO, starget,
8473 "handle(0x%04x), wwid(0x%016llx) ",
8474 pcie_device->handle,
8475 (unsigned long long)pcie_device->wwid);
8476 if (pcie_device->enclosure_handle != 0)
8477 starget_printk(KERN_INFO, starget,
8478 "enclosure logical id(0x%016llx), "
8480 (unsigned long long)
8481 pcie_device->enclosure_logical_id,
8485 if (((le32_to_cpu(pcie_device_pg0->Flags)) &
8486 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) &&
8487 (ioc->hba_mpi_version_belonged != MPI2_VERSION)) {
8488 pcie_device->enclosure_level =
8489 pcie_device_pg0->EnclosureLevel;
8490 memcpy(&pcie_device->connector_name[0],
8491 &pcie_device_pg0->ConnectorName[0], 4);
8493 pcie_device->enclosure_level = 0;
8494 pcie_device->connector_name[0] = '\0';
8497 if (pcie_device->handle == le16_to_cpu(
8498 pcie_device_pg0->DevHandle))
8500 pr_info("\thandle changed from(0x%04x)!!!\n",
8501 pcie_device->handle);
8502 pcie_device->handle = le16_to_cpu(
8503 pcie_device_pg0->DevHandle);
8504 if (sas_target_priv_data)
8505 sas_target_priv_data->handle =
8506 le16_to_cpu(pcie_device_pg0->DevHandle);
8512 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8516 * _scsih_search_responding_pcie_devices -
8517 * @ioc: per adapter object
8519 * After host reset, find out whether devices are still responding.
8523 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc)
8525 Mpi26PCIeDevicePage0_t pcie_device_pg0;
8526 Mpi2ConfigReply_t mpi_reply;
8531 ioc_info(ioc, "search for end-devices: start\n");
8533 if (list_empty(&ioc->pcie_device_list))
8537 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
8538 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
8540 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8541 MPI2_IOCSTATUS_MASK;
8542 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8543 ioc_info(ioc, "\tbreak from %s: ioc_status(0x%04x), loginfo(0x%08x)\n",
8544 __func__, ioc_status,
8545 le32_to_cpu(mpi_reply.IOCLogInfo));
8548 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
8549 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
8550 if (!(_scsih_is_nvme_device(device_info)))
8552 _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0);
8555 ioc_info(ioc, "search for PCIe end-devices: complete\n");
8559 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8560 * @ioc: per adapter object
8561 * @wwid: world wide identifier for raid volume
8562 * @handle: device handle
8564 * After host reset, find out whether devices are still responding.
8565 * Used in _scsih_remove_unresponsive_raid_devices.
8568 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
8571 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
8572 struct scsi_target *starget;
8573 struct _raid_device *raid_device;
8574 unsigned long flags;
8576 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8577 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
8578 if (raid_device->wwid == wwid && raid_device->starget) {
8579 starget = raid_device->starget;
8580 if (starget && starget->hostdata) {
8581 sas_target_priv_data = starget->hostdata;
8582 sas_target_priv_data->deleted = 0;
8584 sas_target_priv_data = NULL;
8585 raid_device->responding = 1;
8586 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8587 starget_printk(KERN_INFO, raid_device->starget,
8588 "handle(0x%04x), wwid(0x%016llx)\n", handle,
8589 (unsigned long long)raid_device->wwid);
8592 * WARPDRIVE: The handles of the PDs might have changed
8593 * across the host reset so re-initialize the
8594 * required data for Direct IO
8596 mpt3sas_init_warpdrive_properties(ioc, raid_device);
8597 spin_lock_irqsave(&ioc->raid_device_lock, flags);
8598 if (raid_device->handle == handle) {
8599 spin_unlock_irqrestore(&ioc->raid_device_lock,
8603 pr_info("\thandle changed from(0x%04x)!!!\n",
8604 raid_device->handle);
8605 raid_device->handle = handle;
8606 if (sas_target_priv_data)
8607 sas_target_priv_data->handle = handle;
8608 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8612 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
8616 * _scsih_search_responding_raid_devices -
8617 * @ioc: per adapter object
8619 * After host reset, find out whether devices are still responding.
8623 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
8625 Mpi2RaidVolPage1_t volume_pg1;
8626 Mpi2RaidVolPage0_t volume_pg0;
8627 Mpi2RaidPhysDiskPage0_t pd_pg0;
8628 Mpi2ConfigReply_t mpi_reply;
8633 if (!ioc->ir_firmware)
8636 ioc_info(ioc, "search for raid volumes: start\n");
8638 if (list_empty(&ioc->raid_device_list))
8642 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
8643 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
8644 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8645 MPI2_IOCSTATUS_MASK;
8646 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8648 handle = le16_to_cpu(volume_pg1.DevHandle);
8650 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
8651 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
8652 sizeof(Mpi2RaidVolPage0_t)))
8655 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
8656 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
8657 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
8658 _scsih_mark_responding_raid_device(ioc,
8659 le64_to_cpu(volume_pg1.WWID), handle);
8662 /* refresh the pd_handles */
8663 if (!ioc->is_warpdrive) {
8664 phys_disk_num = 0xFF;
8665 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
8666 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
8667 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
8669 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8670 MPI2_IOCSTATUS_MASK;
8671 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8673 phys_disk_num = pd_pg0.PhysDiskNum;
8674 handle = le16_to_cpu(pd_pg0.DevHandle);
8675 set_bit(handle, ioc->pd_handles);
8679 ioc_info(ioc, "search for responding raid volumes: complete\n");
8683 * _scsih_mark_responding_expander - mark a expander as responding
8684 * @ioc: per adapter object
8685 * @expander_pg0:SAS Expander Config Page0
8687 * After host reset, find out whether devices are still responding.
8688 * Used in _scsih_remove_unresponsive_expanders.
8691 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc,
8692 Mpi2ExpanderPage0_t *expander_pg0)
8694 struct _sas_node *sas_expander = NULL;
8695 unsigned long flags;
8697 struct _enclosure_node *enclosure_dev = NULL;
8698 u16 handle = le16_to_cpu(expander_pg0->DevHandle);
8699 u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle);
8700 u64 sas_address = le64_to_cpu(expander_pg0->SASAddress);
8702 if (enclosure_handle)
8704 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8707 spin_lock_irqsave(&ioc->sas_node_lock, flags);
8708 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
8709 if (sas_expander->sas_address != sas_address)
8711 sas_expander->responding = 1;
8713 if (enclosure_dev) {
8714 sas_expander->enclosure_logical_id =
8715 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
8716 sas_expander->enclosure_handle =
8717 le16_to_cpu(expander_pg0->EnclosureHandle);
8720 if (sas_expander->handle == handle)
8722 pr_info("\texpander(0x%016llx): handle changed" \
8723 " from(0x%04x) to (0x%04x)!!!\n",
8724 (unsigned long long)sas_expander->sas_address,
8725 sas_expander->handle, handle);
8726 sas_expander->handle = handle;
8727 for (i = 0 ; i < sas_expander->num_phys ; i++)
8728 sas_expander->phy[i].handle = handle;
8732 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
8736 * _scsih_search_responding_expanders -
8737 * @ioc: per adapter object
8739 * After host reset, find out whether devices are still responding.
8743 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
8745 Mpi2ExpanderPage0_t expander_pg0;
8746 Mpi2ConfigReply_t mpi_reply;
8751 ioc_info(ioc, "search for expanders: start\n");
8753 if (list_empty(&ioc->sas_expander_list))
8757 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
8758 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
8760 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8761 MPI2_IOCSTATUS_MASK;
8762 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8765 handle = le16_to_cpu(expander_pg0.DevHandle);
8766 sas_address = le64_to_cpu(expander_pg0.SASAddress);
8767 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8769 (unsigned long long)sas_address);
8770 _scsih_mark_responding_expander(ioc, &expander_pg0);
8774 ioc_info(ioc, "search for expanders: complete\n");
8778 * _scsih_remove_unresponding_devices - removing unresponding devices
8779 * @ioc: per adapter object
8782 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc)
8784 struct _sas_device *sas_device, *sas_device_next;
8785 struct _sas_node *sas_expander, *sas_expander_next;
8786 struct _raid_device *raid_device, *raid_device_next;
8787 struct _pcie_device *pcie_device, *pcie_device_next;
8788 struct list_head tmp_list;
8789 unsigned long flags;
8792 ioc_info(ioc, "removing unresponding devices: start\n");
8794 /* removing unresponding end devices */
8795 ioc_info(ioc, "removing unresponding devices: end-devices\n");
8797 * Iterate, pulling off devices marked as non-responding. We become the
8798 * owner for the reference the list had on any object we prune.
8800 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8801 list_for_each_entry_safe(sas_device, sas_device_next,
8802 &ioc->sas_device_list, list) {
8803 if (!sas_device->responding)
8804 list_move_tail(&sas_device->list, &head);
8806 sas_device->responding = 0;
8808 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8811 * Now, uninitialize and remove the unresponding devices we pruned.
8813 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
8814 _scsih_remove_device(ioc, sas_device);
8815 list_del_init(&sas_device->list);
8816 sas_device_put(sas_device);
8819 ioc_info(ioc, "Removing unresponding devices: pcie end-devices\n");
8820 INIT_LIST_HEAD(&head);
8821 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8822 list_for_each_entry_safe(pcie_device, pcie_device_next,
8823 &ioc->pcie_device_list, list) {
8824 if (!pcie_device->responding)
8825 list_move_tail(&pcie_device->list, &head);
8827 pcie_device->responding = 0;
8829 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8831 list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) {
8832 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
8833 list_del_init(&pcie_device->list);
8834 pcie_device_put(pcie_device);
8837 /* removing unresponding volumes */
8838 if (ioc->ir_firmware) {
8839 ioc_info(ioc, "removing unresponding devices: volumes\n");
8840 list_for_each_entry_safe(raid_device, raid_device_next,
8841 &ioc->raid_device_list, list) {
8842 if (!raid_device->responding)
8843 _scsih_sas_volume_delete(ioc,
8844 raid_device->handle);
8846 raid_device->responding = 0;
8850 /* removing unresponding expanders */
8851 ioc_info(ioc, "removing unresponding devices: expanders\n");
8852 spin_lock_irqsave(&ioc->sas_node_lock, flags);
8853 INIT_LIST_HEAD(&tmp_list);
8854 list_for_each_entry_safe(sas_expander, sas_expander_next,
8855 &ioc->sas_expander_list, list) {
8856 if (!sas_expander->responding)
8857 list_move_tail(&sas_expander->list, &tmp_list);
8859 sas_expander->responding = 0;
8861 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
8862 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
8864 _scsih_expander_node_remove(ioc, sas_expander);
8867 ioc_info(ioc, "removing unresponding devices: complete\n");
8869 /* unblock devices */
8870 _scsih_ublock_io_all_device(ioc);
8874 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
8875 struct _sas_node *sas_expander, u16 handle)
8877 Mpi2ExpanderPage1_t expander_pg1;
8878 Mpi2ConfigReply_t mpi_reply;
8881 for (i = 0 ; i < sas_expander->num_phys ; i++) {
8882 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
8883 &expander_pg1, i, handle))) {
8884 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8885 __FILE__, __LINE__, __func__);
8889 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
8890 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
8891 expander_pg1.NegotiatedLinkRate >> 4);
8896 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
8897 * @ioc: per adapter object
8900 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
8902 Mpi2ExpanderPage0_t expander_pg0;
8903 Mpi2SasDevicePage0_t sas_device_pg0;
8904 Mpi26PCIeDevicePage0_t pcie_device_pg0;
8905 Mpi2RaidVolPage1_t volume_pg1;
8906 Mpi2RaidVolPage0_t volume_pg0;
8907 Mpi2RaidPhysDiskPage0_t pd_pg0;
8908 Mpi2EventIrConfigElement_t element;
8909 Mpi2ConfigReply_t mpi_reply;
8912 u16 handle, parent_handle;
8914 struct _sas_device *sas_device;
8915 struct _pcie_device *pcie_device;
8916 struct _sas_node *expander_device;
8917 static struct _raid_device *raid_device;
8919 unsigned long flags;
8921 ioc_info(ioc, "scan devices: start\n");
8923 _scsih_sas_host_refresh(ioc);
8925 ioc_info(ioc, "\tscan devices: expanders start\n");
8929 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
8930 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
8931 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8932 MPI2_IOCSTATUS_MASK;
8933 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8934 ioc_info(ioc, "\tbreak from expander scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
8935 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
8938 handle = le16_to_cpu(expander_pg0.DevHandle);
8939 spin_lock_irqsave(&ioc->sas_node_lock, flags);
8940 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
8941 ioc, le64_to_cpu(expander_pg0.SASAddress));
8942 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
8943 if (expander_device)
8944 _scsih_refresh_expander_links(ioc, expander_device,
8947 ioc_info(ioc, "\tBEFORE adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
8949 (u64)le64_to_cpu(expander_pg0.SASAddress));
8950 _scsih_expander_add(ioc, handle);
8951 ioc_info(ioc, "\tAFTER adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
8953 (u64)le64_to_cpu(expander_pg0.SASAddress));
8957 ioc_info(ioc, "\tscan devices: expanders complete\n");
8959 if (!ioc->ir_firmware)
8962 ioc_info(ioc, "\tscan devices: phys disk start\n");
8965 phys_disk_num = 0xFF;
8966 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
8967 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
8969 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8970 MPI2_IOCSTATUS_MASK;
8971 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8972 ioc_info(ioc, "\tbreak from phys disk scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
8973 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
8976 phys_disk_num = pd_pg0.PhysDiskNum;
8977 handle = le16_to_cpu(pd_pg0.DevHandle);
8978 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
8980 sas_device_put(sas_device);
8983 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
8984 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
8987 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8988 MPI2_IOCSTATUS_MASK;
8989 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8990 ioc_info(ioc, "\tbreak from phys disk scan ioc_status(0x%04x), loginfo(0x%08x)\n",
8991 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
8994 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
8995 if (!_scsih_get_sas_address(ioc, parent_handle,
8997 ioc_info(ioc, "\tBEFORE adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
8999 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
9000 mpt3sas_transport_update_links(ioc, sas_address,
9001 handle, sas_device_pg0.PhyNum,
9002 MPI2_SAS_NEG_LINK_RATE_1_5);
9003 set_bit(handle, ioc->pd_handles);
9005 /* This will retry adding the end device.
9006 * _scsih_add_device() will decide on retries and
9007 * return "1" when it should be retried
9009 while (_scsih_add_device(ioc, handle, retry_count++,
9013 ioc_info(ioc, "\tAFTER adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
9015 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
9019 ioc_info(ioc, "\tscan devices: phys disk complete\n");
9021 ioc_info(ioc, "\tscan devices: volumes start\n");
9025 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
9026 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
9027 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9028 MPI2_IOCSTATUS_MASK;
9029 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9030 ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9031 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
9034 handle = le16_to_cpu(volume_pg1.DevHandle);
9035 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9036 raid_device = _scsih_raid_device_find_by_wwid(ioc,
9037 le64_to_cpu(volume_pg1.WWID));
9038 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9041 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
9042 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
9043 sizeof(Mpi2RaidVolPage0_t)))
9045 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9046 MPI2_IOCSTATUS_MASK;
9047 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9048 ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9049 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
9052 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
9053 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
9054 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
9055 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
9056 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
9057 element.VolDevHandle = volume_pg1.DevHandle;
9058 ioc_info(ioc, "\tBEFORE adding volume: handle (0x%04x)\n",
9059 volume_pg1.DevHandle);
9060 _scsih_sas_volume_add(ioc, &element);
9061 ioc_info(ioc, "\tAFTER adding volume: handle (0x%04x)\n",
9062 volume_pg1.DevHandle);
9066 ioc_info(ioc, "\tscan devices: volumes complete\n");
9070 ioc_info(ioc, "\tscan devices: end devices start\n");
9074 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9075 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9077 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9078 MPI2_IOCSTATUS_MASK;
9079 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9080 ioc_info(ioc, "\tbreak from end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9081 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
9084 handle = le16_to_cpu(sas_device_pg0.DevHandle);
9085 if (!(_scsih_is_end_device(
9086 le32_to_cpu(sas_device_pg0.DeviceInfo))))
9088 sas_device = mpt3sas_get_sdev_by_addr(ioc,
9089 le64_to_cpu(sas_device_pg0.SASAddress));
9091 sas_device_put(sas_device);
9094 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9095 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
9096 ioc_info(ioc, "\tBEFORE adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
9098 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
9099 mpt3sas_transport_update_links(ioc, sas_address, handle,
9100 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
9102 /* This will retry adding the end device.
9103 * _scsih_add_device() will decide on retries and
9104 * return "1" when it should be retried
9106 while (_scsih_add_device(ioc, handle, retry_count++,
9110 ioc_info(ioc, "\tAFTER adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
9112 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
9115 ioc_info(ioc, "\tscan devices: end devices complete\n");
9116 ioc_info(ioc, "\tscan devices: pcie end devices start\n");
9120 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
9121 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9123 ioc_status = le16_to_cpu(mpi_reply.IOCStatus)
9124 & MPI2_IOCSTATUS_MASK;
9125 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9126 ioc_info(ioc, "\tbreak from pcie end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9127 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
9130 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
9131 if (!(_scsih_is_nvme_device(
9132 le32_to_cpu(pcie_device_pg0.DeviceInfo))))
9134 pcie_device = mpt3sas_get_pdev_by_wwid(ioc,
9135 le64_to_cpu(pcie_device_pg0.WWID));
9137 pcie_device_put(pcie_device);
9141 parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle);
9142 _scsih_pcie_add_device(ioc, handle);
9144 ioc_info(ioc, "\tAFTER adding pcie end device: handle (0x%04x), wwid(0x%016llx)\n",
9145 handle, (u64)le64_to_cpu(pcie_device_pg0.WWID));
9147 ioc_info(ioc, "\tpcie devices: pcie end devices complete\n");
9148 ioc_info(ioc, "scan devices: complete\n");
9152 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9153 * @ioc: per adapter object
9155 * The handler for doing any required cleanup or initialization.
9157 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
9159 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__));
9163 * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
9164 * @ioc: per adapter object
9166 * The handler for doing any required cleanup or initialization.
9169 mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER *ioc)
9171 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_AFTER_RESET\n", __func__));
9172 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
9173 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
9174 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
9175 complete(&ioc->scsih_cmds.done);
9177 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
9178 ioc->tm_cmds.status |= MPT3_CMD_RESET;
9179 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
9180 complete(&ioc->tm_cmds.done);
9183 memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
9184 memset(ioc->device_remove_in_progress, 0,
9185 ioc->device_remove_in_progress_sz);
9186 _scsih_fw_event_cleanup_queue(ioc);
9187 _scsih_flush_running_cmds(ioc);
9191 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9192 * @ioc: per adapter object
9194 * The handler for doing any required cleanup or initialization.
9197 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
9199 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__));
9200 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
9201 !ioc->sas_hba.num_phys)) {
9202 _scsih_prep_device_scan(ioc);
9203 _scsih_create_enclosure_list_after_reset(ioc);
9204 _scsih_search_responding_sas_devices(ioc);
9205 _scsih_search_responding_pcie_devices(ioc);
9206 _scsih_search_responding_raid_devices(ioc);
9207 _scsih_search_responding_expanders(ioc);
9208 _scsih_error_recovery_delete_devices(ioc);
9213 * _mpt3sas_fw_work - delayed task for processing firmware events
9214 * @ioc: per adapter object
9215 * @fw_event: The fw_event_work object
9219 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
9221 _scsih_fw_event_del_from_list(ioc, fw_event);
9223 /* the queue is being flushed so ignore this event */
9224 if (ioc->remove_host || ioc->pci_error_recovery) {
9225 fw_event_work_put(fw_event);
9229 switch (fw_event->event) {
9230 case MPT3SAS_PROCESS_TRIGGER_DIAG:
9231 mpt3sas_process_trigger_data(ioc,
9232 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
9233 fw_event->event_data);
9235 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
9236 while (scsi_host_in_recovery(ioc->shost) ||
9237 ioc->shost_recovery) {
9239 * If we're unloading, bail. Otherwise, this can become
9242 if (ioc->remove_host)
9246 _scsih_remove_unresponding_devices(ioc);
9247 _scsih_scan_for_devices_after_reset(ioc);
9249 case MPT3SAS_PORT_ENABLE_COMPLETE:
9250 ioc->start_scan = 0;
9251 if (missing_delay[0] != -1 && missing_delay[1] != -1)
9252 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
9255 ioc_info(ioc, "port enable: complete from worker thread\n"));
9257 case MPT3SAS_TURN_ON_PFA_LED:
9258 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
9260 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
9261 _scsih_sas_topology_change_event(ioc, fw_event);
9263 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
9264 _scsih_sas_device_status_change_event(ioc, fw_event);
9266 case MPI2_EVENT_SAS_DISCOVERY:
9267 _scsih_sas_discovery_event(ioc, fw_event);
9269 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
9270 _scsih_sas_device_discovery_error_event(ioc, fw_event);
9272 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
9273 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
9275 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
9276 _scsih_sas_enclosure_dev_status_change_event(ioc,
9279 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
9280 _scsih_sas_ir_config_change_event(ioc, fw_event);
9282 case MPI2_EVENT_IR_VOLUME:
9283 _scsih_sas_ir_volume_event(ioc, fw_event);
9285 case MPI2_EVENT_IR_PHYSICAL_DISK:
9286 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
9288 case MPI2_EVENT_IR_OPERATION_STATUS:
9289 _scsih_sas_ir_operation_status_event(ioc, fw_event);
9291 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
9292 _scsih_pcie_device_status_change_event(ioc, fw_event);
9294 case MPI2_EVENT_PCIE_ENUMERATION:
9295 _scsih_pcie_enumeration_event(ioc, fw_event);
9297 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
9298 _scsih_pcie_topology_change_event(ioc, fw_event);
9303 fw_event_work_put(fw_event);
9307 * _firmware_event_work
9308 * @work: The fw_event_work object
9311 * wrappers for the work thread handling firmware events
9315 _firmware_event_work(struct work_struct *work)
9317 struct fw_event_work *fw_event = container_of(work,
9318 struct fw_event_work, work);
9320 _mpt3sas_fw_work(fw_event->ioc, fw_event);
9324 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9325 * @ioc: per adapter object
9326 * @msix_index: MSIX table index supplied by the OS
9327 * @reply: reply message frame(lower 32bit addr)
9328 * Context: interrupt.
9330 * This function merely adds a new work task into ioc->firmware_event_thread.
9331 * The tasks are worked from _firmware_event_work in user context.
9333 * Return: 1 meaning mf should be freed from _base_interrupt
9334 * 0 means the mf is freed from this function.
9337 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
9340 struct fw_event_work *fw_event;
9341 Mpi2EventNotificationReply_t *mpi_reply;
9344 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
9346 /* events turned off due to host reset */
9347 if (ioc->pci_error_recovery)
9350 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
9352 if (unlikely(!mpi_reply)) {
9353 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
9354 __FILE__, __LINE__, __func__);
9358 event = le16_to_cpu(mpi_reply->Event);
9360 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
9361 mpt3sas_trigger_event(ioc, event, 0);
9365 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
9367 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
9368 (Mpi2EventDataSasBroadcastPrimitive_t *)
9369 mpi_reply->EventData;
9371 if (baen_data->Primitive !=
9372 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
9375 if (ioc->broadcast_aen_busy) {
9376 ioc->broadcast_aen_pending++;
9379 ioc->broadcast_aen_busy = 1;
9383 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
9384 _scsih_check_topo_delete_events(ioc,
9385 (Mpi2EventDataSasTopologyChangeList_t *)
9386 mpi_reply->EventData);
9388 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
9389 _scsih_check_pcie_topo_remove_events(ioc,
9390 (Mpi26EventDataPCIeTopologyChangeList_t *)
9391 mpi_reply->EventData);
9393 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
9394 _scsih_check_ir_config_unhide_events(ioc,
9395 (Mpi2EventDataIrConfigChangeList_t *)
9396 mpi_reply->EventData);
9398 case MPI2_EVENT_IR_VOLUME:
9399 _scsih_check_volume_delete_events(ioc,
9400 (Mpi2EventDataIrVolume_t *)
9401 mpi_reply->EventData);
9403 case MPI2_EVENT_LOG_ENTRY_ADDED:
9405 Mpi2EventDataLogEntryAdded_t *log_entry;
9408 if (!ioc->is_warpdrive)
9411 log_entry = (Mpi2EventDataLogEntryAdded_t *)
9412 mpi_reply->EventData;
9413 log_code = (u32 *)log_entry->LogData;
9415 if (le16_to_cpu(log_entry->LogEntryQualifier)
9416 != MPT2_WARPDRIVE_LOGENTRY)
9419 switch (le32_to_cpu(*log_code)) {
9420 case MPT2_WARPDRIVE_LC_SSDT:
9421 ioc_warn(ioc, "WarpDrive Warning: IO Throttling has occurred in the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
9423 case MPT2_WARPDRIVE_LC_SSDLW:
9424 ioc_warn(ioc, "WarpDrive Warning: Program/Erase Cycles for the WarpDrive subsystem in degraded range. Check WarpDrive documentation for additional details.\n");
9426 case MPT2_WARPDRIVE_LC_SSDLF:
9427 ioc_err(ioc, "WarpDrive Fatal Error: There are no Program/Erase Cycles for the WarpDrive subsystem. The storage device will be in read-only mode. Check WarpDrive documentation for additional details.\n");
9429 case MPT2_WARPDRIVE_LC_BRMF:
9430 ioc_err(ioc, "WarpDrive Fatal Error: The Backup Rail Monitor has failed on the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
9436 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
9437 case MPI2_EVENT_IR_OPERATION_STATUS:
9438 case MPI2_EVENT_SAS_DISCOVERY:
9439 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
9440 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
9441 case MPI2_EVENT_IR_PHYSICAL_DISK:
9442 case MPI2_EVENT_PCIE_ENUMERATION:
9443 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
9446 case MPI2_EVENT_TEMP_THRESHOLD:
9447 _scsih_temp_threshold_events(ioc,
9448 (Mpi2EventDataTemperature_t *)
9449 mpi_reply->EventData);
9451 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
9452 ActiveCableEventData =
9453 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
9454 switch (ActiveCableEventData->ReasonCode) {
9455 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
9456 ioc_notice(ioc, "Currently an active cable with ReceptacleID %d\n",
9457 ActiveCableEventData->ReceptacleID);
9458 pr_notice("cannot be powered and devices connected\n");
9459 pr_notice("to this active cable will not be seen\n");
9460 pr_notice("This active cable requires %d mW of power\n",
9461 ActiveCableEventData->ActiveCablePowerRequirement);
9464 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
9465 ioc_notice(ioc, "Currently a cable with ReceptacleID %d\n",
9466 ActiveCableEventData->ReceptacleID);
9468 "is not running at optimal speed(12 Gb/s rate)\n");
9474 default: /* ignore the rest */
9478 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
9479 fw_event = alloc_fw_event_work(sz);
9481 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9482 __FILE__, __LINE__, __func__);
9486 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
9487 fw_event->ioc = ioc;
9488 fw_event->VF_ID = mpi_reply->VF_ID;
9489 fw_event->VP_ID = mpi_reply->VP_ID;
9490 fw_event->event = event;
9491 _scsih_fw_event_add(ioc, fw_event);
9492 fw_event_work_put(fw_event);
9497 * _scsih_expander_node_remove - removing expander device from list.
9498 * @ioc: per adapter object
9499 * @sas_expander: the sas_device object
9501 * Removing object and freeing associated memory from the
9502 * ioc->sas_expander_list.
9505 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
9506 struct _sas_node *sas_expander)
9508 struct _sas_port *mpt3sas_port, *next;
9509 unsigned long flags;
9511 /* remove sibling ports attached to this expander */
9512 list_for_each_entry_safe(mpt3sas_port, next,
9513 &sas_expander->sas_port_list, port_list) {
9514 if (ioc->shost_recovery)
9516 if (mpt3sas_port->remote_identify.device_type ==
9518 mpt3sas_device_remove_by_sas_address(ioc,
9519 mpt3sas_port->remote_identify.sas_address);
9520 else if (mpt3sas_port->remote_identify.device_type ==
9521 SAS_EDGE_EXPANDER_DEVICE ||
9522 mpt3sas_port->remote_identify.device_type ==
9523 SAS_FANOUT_EXPANDER_DEVICE)
9524 mpt3sas_expander_remove(ioc,
9525 mpt3sas_port->remote_identify.sas_address);
9528 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
9529 sas_expander->sas_address_parent);
9531 ioc_info(ioc, "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9532 sas_expander->handle, (unsigned long long)
9533 sas_expander->sas_address);
9535 spin_lock_irqsave(&ioc->sas_node_lock, flags);
9536 list_del(&sas_expander->list);
9537 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
9539 kfree(sas_expander->phy);
9540 kfree(sas_expander);
9544 * _scsih_ir_shutdown - IR shutdown notification
9545 * @ioc: per adapter object
9547 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9548 * the host system is shutting down.
9551 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
9553 Mpi2RaidActionRequest_t *mpi_request;
9554 Mpi2RaidActionReply_t *mpi_reply;
9557 /* is IR firmware build loaded ? */
9558 if (!ioc->ir_firmware)
9561 /* are there any volumes ? */
9562 if (list_empty(&ioc->raid_device_list))
9565 mutex_lock(&ioc->scsih_cmds.mutex);
9567 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
9568 ioc_err(ioc, "%s: scsih_cmd in use\n", __func__);
9571 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
9573 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
9575 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
9576 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
9580 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
9581 ioc->scsih_cmds.smid = smid;
9582 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
9584 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
9585 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
9587 if (!ioc->hide_ir_msg)
9588 ioc_info(ioc, "IR shutdown (sending)\n");
9589 init_completion(&ioc->scsih_cmds.done);
9590 mpt3sas_base_put_smid_default(ioc, smid);
9591 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
9593 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
9594 ioc_err(ioc, "%s: timeout\n", __func__);
9598 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
9599 mpi_reply = ioc->scsih_cmds.reply;
9600 if (!ioc->hide_ir_msg)
9601 ioc_info(ioc, "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9602 le16_to_cpu(mpi_reply->IOCStatus),
9603 le32_to_cpu(mpi_reply->IOCLogInfo));
9607 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
9608 mutex_unlock(&ioc->scsih_cmds.mutex);
9612 * scsih_remove - detach and remove add host
9613 * @pdev: PCI device struct
9615 * Routine called when unloading the driver.
9617 static void scsih_remove(struct pci_dev *pdev)
9619 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9620 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9621 struct _sas_port *mpt3sas_port, *next_port;
9622 struct _raid_device *raid_device, *next;
9623 struct MPT3SAS_TARGET *sas_target_priv_data;
9624 struct _pcie_device *pcie_device, *pcienext;
9625 struct workqueue_struct *wq;
9626 unsigned long flags;
9628 ioc->remove_host = 1;
9630 mpt3sas_wait_for_commands_to_complete(ioc);
9631 _scsih_flush_running_cmds(ioc);
9633 _scsih_fw_event_cleanup_queue(ioc);
9635 spin_lock_irqsave(&ioc->fw_event_lock, flags);
9636 wq = ioc->firmware_event_thread;
9637 ioc->firmware_event_thread = NULL;
9638 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
9640 destroy_workqueue(wq);
9642 /* release all the volumes */
9643 _scsih_ir_shutdown(ioc);
9644 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
9646 if (raid_device->starget) {
9647 sas_target_priv_data =
9648 raid_device->starget->hostdata;
9649 sas_target_priv_data->deleted = 1;
9650 scsi_remove_target(&raid_device->starget->dev);
9652 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
9653 raid_device->handle, (u64)raid_device->wwid);
9654 _scsih_raid_device_remove(ioc, raid_device);
9656 list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list,
9658 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
9659 list_del_init(&pcie_device->list);
9660 pcie_device_put(pcie_device);
9663 /* free ports attached to the sas_host */
9664 list_for_each_entry_safe(mpt3sas_port, next_port,
9665 &ioc->sas_hba.sas_port_list, port_list) {
9666 if (mpt3sas_port->remote_identify.device_type ==
9668 mpt3sas_device_remove_by_sas_address(ioc,
9669 mpt3sas_port->remote_identify.sas_address);
9670 else if (mpt3sas_port->remote_identify.device_type ==
9671 SAS_EDGE_EXPANDER_DEVICE ||
9672 mpt3sas_port->remote_identify.device_type ==
9673 SAS_FANOUT_EXPANDER_DEVICE)
9674 mpt3sas_expander_remove(ioc,
9675 mpt3sas_port->remote_identify.sas_address);
9678 /* free phys attached to the sas_host */
9679 if (ioc->sas_hba.num_phys) {
9680 kfree(ioc->sas_hba.phy);
9681 ioc->sas_hba.phy = NULL;
9682 ioc->sas_hba.num_phys = 0;
9685 sas_remove_host(shost);
9686 mpt3sas_base_detach(ioc);
9687 spin_lock(&gioc_lock);
9688 list_del(&ioc->list);
9689 spin_unlock(&gioc_lock);
9690 scsi_host_put(shost);
9694 * scsih_shutdown - routine call during system shutdown
9695 * @pdev: PCI device struct
9698 scsih_shutdown(struct pci_dev *pdev)
9700 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9701 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9702 struct workqueue_struct *wq;
9703 unsigned long flags;
9705 ioc->remove_host = 1;
9707 mpt3sas_wait_for_commands_to_complete(ioc);
9708 _scsih_flush_running_cmds(ioc);
9710 _scsih_fw_event_cleanup_queue(ioc);
9712 spin_lock_irqsave(&ioc->fw_event_lock, flags);
9713 wq = ioc->firmware_event_thread;
9714 ioc->firmware_event_thread = NULL;
9715 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
9717 destroy_workqueue(wq);
9719 _scsih_ir_shutdown(ioc);
9720 mpt3sas_base_detach(ioc);
9725 * _scsih_probe_boot_devices - reports 1st device
9726 * @ioc: per adapter object
9728 * If specified in bios page 2, this routine reports the 1st
9729 * device scsi-ml or sas transport for persistent boot device
9730 * purposes. Please refer to function _scsih_determine_boot_device()
9733 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
9737 struct _sas_device *sas_device;
9738 struct _raid_device *raid_device;
9739 struct _pcie_device *pcie_device;
9741 u64 sas_address_parent;
9743 unsigned long flags;
9747 /* no Bios, return immediately */
9748 if (!ioc->bios_pg3.BiosVersion)
9752 if (ioc->req_boot_device.device) {
9753 device = ioc->req_boot_device.device;
9754 channel = ioc->req_boot_device.channel;
9755 } else if (ioc->req_alt_boot_device.device) {
9756 device = ioc->req_alt_boot_device.device;
9757 channel = ioc->req_alt_boot_device.channel;
9758 } else if (ioc->current_boot_device.device) {
9759 device = ioc->current_boot_device.device;
9760 channel = ioc->current_boot_device.channel;
9766 if (channel == RAID_CHANNEL) {
9767 raid_device = device;
9768 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9769 raid_device->id, 0);
9771 _scsih_raid_device_remove(ioc, raid_device);
9772 } else if (channel == PCIE_CHANNEL) {
9773 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
9774 pcie_device = device;
9775 tid = pcie_device->id;
9776 list_move_tail(&pcie_device->list, &ioc->pcie_device_list);
9777 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
9778 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0);
9780 _scsih_pcie_device_remove(ioc, pcie_device);
9782 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9783 sas_device = device;
9784 handle = sas_device->handle;
9785 sas_address_parent = sas_device->sas_address_parent;
9786 sas_address = sas_device->sas_address;
9787 list_move_tail(&sas_device->list, &ioc->sas_device_list);
9788 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9790 if (ioc->hide_drives)
9792 if (!mpt3sas_transport_port_add(ioc, handle,
9793 sas_address_parent)) {
9794 _scsih_sas_device_remove(ioc, sas_device);
9795 } else if (!sas_device->starget) {
9796 if (!ioc->is_driver_loading) {
9797 mpt3sas_transport_port_remove(ioc,
9799 sas_address_parent);
9800 _scsih_sas_device_remove(ioc, sas_device);
9807 * _scsih_probe_raid - reporting raid volumes to scsi-ml
9808 * @ioc: per adapter object
9810 * Called during initial loading of the driver.
9813 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
9815 struct _raid_device *raid_device, *raid_next;
9818 list_for_each_entry_safe(raid_device, raid_next,
9819 &ioc->raid_device_list, list) {
9820 if (raid_device->starget)
9822 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9823 raid_device->id, 0);
9825 _scsih_raid_device_remove(ioc, raid_device);
9829 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
9831 struct _sas_device *sas_device = NULL;
9832 unsigned long flags;
9834 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9835 if (!list_empty(&ioc->sas_device_init_list)) {
9836 sas_device = list_first_entry(&ioc->sas_device_init_list,
9837 struct _sas_device, list);
9838 sas_device_get(sas_device);
9840 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9845 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
9846 struct _sas_device *sas_device)
9848 unsigned long flags;
9850 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9853 * Since we dropped the lock during the call to port_add(), we need to
9854 * be careful here that somebody else didn't move or delete this item
9855 * while we were busy with other things.
9857 * If it was on the list, we need a put() for the reference the list
9858 * had. Either way, we need a get() for the destination list.
9860 if (!list_empty(&sas_device->list)) {
9861 list_del_init(&sas_device->list);
9862 sas_device_put(sas_device);
9865 sas_device_get(sas_device);
9866 list_add_tail(&sas_device->list, &ioc->sas_device_list);
9868 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9872 * _scsih_probe_sas - reporting sas devices to sas transport
9873 * @ioc: per adapter object
9875 * Called during initial loading of the driver.
9878 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
9880 struct _sas_device *sas_device;
9882 if (ioc->hide_drives)
9885 while ((sas_device = get_next_sas_device(ioc))) {
9886 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
9887 sas_device->sas_address_parent)) {
9888 _scsih_sas_device_remove(ioc, sas_device);
9889 sas_device_put(sas_device);
9891 } else if (!sas_device->starget) {
9893 * When asyn scanning is enabled, its not possible to
9894 * remove devices while scanning is turned on due to an
9895 * oops in scsi_sysfs_add_sdev()->add_device()->
9896 * sysfs_addrm_start()
9898 if (!ioc->is_driver_loading) {
9899 mpt3sas_transport_port_remove(ioc,
9900 sas_device->sas_address,
9901 sas_device->sas_address_parent);
9902 _scsih_sas_device_remove(ioc, sas_device);
9903 sas_device_put(sas_device);
9907 sas_device_make_active(ioc, sas_device);
9908 sas_device_put(sas_device);
9913 * get_next_pcie_device - Get the next pcie device
9914 * @ioc: per adapter object
9916 * Get the next pcie device from pcie_device_init_list list.
9918 * Return: pcie device structure if pcie_device_init_list list is not empty
9919 * otherwise returns NULL
9921 static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc)
9923 struct _pcie_device *pcie_device = NULL;
9924 unsigned long flags;
9926 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
9927 if (!list_empty(&ioc->pcie_device_init_list)) {
9928 pcie_device = list_first_entry(&ioc->pcie_device_init_list,
9929 struct _pcie_device, list);
9930 pcie_device_get(pcie_device);
9932 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
9938 * pcie_device_make_active - Add pcie device to pcie_device_list list
9939 * @ioc: per adapter object
9940 * @pcie_device: pcie device object
9942 * Add the pcie device which has registered with SCSI Transport Later to
9943 * pcie_device_list list
9945 static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc,
9946 struct _pcie_device *pcie_device)
9948 unsigned long flags;
9950 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
9952 if (!list_empty(&pcie_device->list)) {
9953 list_del_init(&pcie_device->list);
9954 pcie_device_put(pcie_device);
9956 pcie_device_get(pcie_device);
9957 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
9959 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
9963 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
9964 * @ioc: per adapter object
9966 * Called during initial loading of the driver.
9969 _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc)
9971 struct _pcie_device *pcie_device;
9974 /* PCIe Device List */
9975 while ((pcie_device = get_next_pcie_device(ioc))) {
9976 if (pcie_device->starget) {
9977 pcie_device_put(pcie_device);
9980 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL,
9981 pcie_device->id, 0);
9983 _scsih_pcie_device_remove(ioc, pcie_device);
9984 pcie_device_put(pcie_device);
9986 } else if (!pcie_device->starget) {
9988 * When async scanning is enabled, its not possible to
9989 * remove devices while scanning is turned on due to an
9990 * oops in scsi_sysfs_add_sdev()->add_device()->
9991 * sysfs_addrm_start()
9993 if (!ioc->is_driver_loading) {
9994 /* TODO-- Need to find out whether this condition will
9997 _scsih_pcie_device_remove(ioc, pcie_device);
9998 pcie_device_put(pcie_device);
10002 pcie_device_make_active(ioc, pcie_device);
10003 pcie_device_put(pcie_device);
10008 * _scsih_probe_devices - probing for devices
10009 * @ioc: per adapter object
10011 * Called during initial loading of the driver.
10014 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
10016 u16 volume_mapping_flags;
10018 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
10019 return; /* return when IOC doesn't support initiator mode */
10021 _scsih_probe_boot_devices(ioc);
10023 if (ioc->ir_firmware) {
10024 volume_mapping_flags =
10025 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
10026 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
10027 if (volume_mapping_flags ==
10028 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
10029 _scsih_probe_raid(ioc);
10030 _scsih_probe_sas(ioc);
10032 _scsih_probe_sas(ioc);
10033 _scsih_probe_raid(ioc);
10036 _scsih_probe_sas(ioc);
10037 _scsih_probe_pcie(ioc);
10042 * scsih_scan_start - scsi lld callback for .scan_start
10043 * @shost: SCSI host pointer
10045 * The shost has the ability to discover targets on its own instead
10046 * of scanning the entire bus. In our implemention, we will kick off
10047 * firmware discovery.
10050 scsih_scan_start(struct Scsi_Host *shost)
10052 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10054 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
10055 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
10057 if (disable_discovery > 0)
10060 ioc->start_scan = 1;
10061 rc = mpt3sas_port_enable(ioc);
10064 ioc_info(ioc, "port enable: FAILED\n");
10068 * scsih_scan_finished - scsi lld callback for .scan_finished
10069 * @shost: SCSI host pointer
10070 * @time: elapsed time of the scan in jiffies
10072 * This function will be called periodicallyn until it returns 1 with the
10073 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10074 * we wait for firmware discovery to complete, then return 1.
10077 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
10079 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10081 if (disable_discovery > 0) {
10082 ioc->is_driver_loading = 0;
10083 ioc->wait_for_discovery_to_complete = 0;
10087 if (time >= (300 * HZ)) {
10088 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
10089 ioc_info(ioc, "port enable: FAILED with timeout (timeout=300s)\n");
10090 ioc->is_driver_loading = 0;
10094 if (ioc->start_scan)
10097 if (ioc->start_scan_failed) {
10098 ioc_info(ioc, "port enable: FAILED with (ioc_status=0x%08x)\n",
10099 ioc->start_scan_failed);
10100 ioc->is_driver_loading = 0;
10101 ioc->wait_for_discovery_to_complete = 0;
10102 ioc->remove_host = 1;
10106 ioc_info(ioc, "port enable: SUCCESS\n");
10107 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
10109 if (ioc->wait_for_discovery_to_complete) {
10110 ioc->wait_for_discovery_to_complete = 0;
10111 _scsih_probe_devices(ioc);
10113 mpt3sas_base_start_watchdog(ioc);
10114 ioc->is_driver_loading = 0;
10118 /* shost template for SAS 2.0 HBA devices */
10119 static struct scsi_host_template mpt2sas_driver_template = {
10120 .module = THIS_MODULE,
10121 .name = "Fusion MPT SAS Host",
10122 .proc_name = MPT2SAS_DRIVER_NAME,
10123 .queuecommand = scsih_qcmd,
10124 .target_alloc = scsih_target_alloc,
10125 .slave_alloc = scsih_slave_alloc,
10126 .slave_configure = scsih_slave_configure,
10127 .target_destroy = scsih_target_destroy,
10128 .slave_destroy = scsih_slave_destroy,
10129 .scan_finished = scsih_scan_finished,
10130 .scan_start = scsih_scan_start,
10131 .change_queue_depth = scsih_change_queue_depth,
10132 .eh_abort_handler = scsih_abort,
10133 .eh_device_reset_handler = scsih_dev_reset,
10134 .eh_target_reset_handler = scsih_target_reset,
10135 .eh_host_reset_handler = scsih_host_reset,
10136 .bios_param = scsih_bios_param,
10139 .sg_tablesize = MPT2SAS_SG_DEPTH,
10140 .max_sectors = 32767,
10142 .use_clustering = ENABLE_CLUSTERING,
10143 .shost_attrs = mpt3sas_host_attrs,
10144 .sdev_attrs = mpt3sas_dev_attrs,
10145 .track_queue_depth = 1,
10146 .cmd_size = sizeof(struct scsiio_tracker),
10149 /* raid transport support for SAS 2.0 HBA devices */
10150 static struct raid_function_template mpt2sas_raid_functions = {
10151 .cookie = &mpt2sas_driver_template,
10152 .is_raid = scsih_is_raid,
10153 .get_resync = scsih_get_resync,
10154 .get_state = scsih_get_state,
10157 /* shost template for SAS 3.0 HBA devices */
10158 static struct scsi_host_template mpt3sas_driver_template = {
10159 .module = THIS_MODULE,
10160 .name = "Fusion MPT SAS Host",
10161 .proc_name = MPT3SAS_DRIVER_NAME,
10162 .queuecommand = scsih_qcmd,
10163 .target_alloc = scsih_target_alloc,
10164 .slave_alloc = scsih_slave_alloc,
10165 .slave_configure = scsih_slave_configure,
10166 .target_destroy = scsih_target_destroy,
10167 .slave_destroy = scsih_slave_destroy,
10168 .scan_finished = scsih_scan_finished,
10169 .scan_start = scsih_scan_start,
10170 .change_queue_depth = scsih_change_queue_depth,
10171 .eh_abort_handler = scsih_abort,
10172 .eh_device_reset_handler = scsih_dev_reset,
10173 .eh_target_reset_handler = scsih_target_reset,
10174 .eh_host_reset_handler = scsih_host_reset,
10175 .bios_param = scsih_bios_param,
10178 .sg_tablesize = MPT3SAS_SG_DEPTH,
10179 .max_sectors = 32767,
10181 .use_clustering = ENABLE_CLUSTERING,
10182 .shost_attrs = mpt3sas_host_attrs,
10183 .sdev_attrs = mpt3sas_dev_attrs,
10184 .track_queue_depth = 1,
10185 .cmd_size = sizeof(struct scsiio_tracker),
10188 /* raid transport support for SAS 3.0 HBA devices */
10189 static struct raid_function_template mpt3sas_raid_functions = {
10190 .cookie = &mpt3sas_driver_template,
10191 .is_raid = scsih_is_raid,
10192 .get_resync = scsih_get_resync,
10193 .get_state = scsih_get_state,
10197 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10198 * this device belongs to.
10199 * @pdev: PCI device struct
10201 * return MPI2_VERSION for SAS 2.0 HBA devices,
10202 * MPI25_VERSION for SAS 3.0 HBA devices, and
10203 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10206 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
10209 switch (pdev->device) {
10210 case MPI2_MFGPAGE_DEVID_SSS6200:
10211 case MPI2_MFGPAGE_DEVID_SAS2004:
10212 case MPI2_MFGPAGE_DEVID_SAS2008:
10213 case MPI2_MFGPAGE_DEVID_SAS2108_1:
10214 case MPI2_MFGPAGE_DEVID_SAS2108_2:
10215 case MPI2_MFGPAGE_DEVID_SAS2108_3:
10216 case MPI2_MFGPAGE_DEVID_SAS2116_1:
10217 case MPI2_MFGPAGE_DEVID_SAS2116_2:
10218 case MPI2_MFGPAGE_DEVID_SAS2208_1:
10219 case MPI2_MFGPAGE_DEVID_SAS2208_2:
10220 case MPI2_MFGPAGE_DEVID_SAS2208_3:
10221 case MPI2_MFGPAGE_DEVID_SAS2208_4:
10222 case MPI2_MFGPAGE_DEVID_SAS2208_5:
10223 case MPI2_MFGPAGE_DEVID_SAS2208_6:
10224 case MPI2_MFGPAGE_DEVID_SAS2308_1:
10225 case MPI2_MFGPAGE_DEVID_SAS2308_2:
10226 case MPI2_MFGPAGE_DEVID_SAS2308_3:
10227 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
10228 return MPI2_VERSION;
10229 case MPI25_MFGPAGE_DEVID_SAS3004:
10230 case MPI25_MFGPAGE_DEVID_SAS3008:
10231 case MPI25_MFGPAGE_DEVID_SAS3108_1:
10232 case MPI25_MFGPAGE_DEVID_SAS3108_2:
10233 case MPI25_MFGPAGE_DEVID_SAS3108_5:
10234 case MPI25_MFGPAGE_DEVID_SAS3108_6:
10235 return MPI25_VERSION;
10236 case MPI26_MFGPAGE_DEVID_SAS3216:
10237 case MPI26_MFGPAGE_DEVID_SAS3224:
10238 case MPI26_MFGPAGE_DEVID_SAS3316_1:
10239 case MPI26_MFGPAGE_DEVID_SAS3316_2:
10240 case MPI26_MFGPAGE_DEVID_SAS3316_3:
10241 case MPI26_MFGPAGE_DEVID_SAS3316_4:
10242 case MPI26_MFGPAGE_DEVID_SAS3324_1:
10243 case MPI26_MFGPAGE_DEVID_SAS3324_2:
10244 case MPI26_MFGPAGE_DEVID_SAS3324_3:
10245 case MPI26_MFGPAGE_DEVID_SAS3324_4:
10246 case MPI26_MFGPAGE_DEVID_SAS3508:
10247 case MPI26_MFGPAGE_DEVID_SAS3508_1:
10248 case MPI26_MFGPAGE_DEVID_SAS3408:
10249 case MPI26_MFGPAGE_DEVID_SAS3516:
10250 case MPI26_MFGPAGE_DEVID_SAS3516_1:
10251 case MPI26_MFGPAGE_DEVID_SAS3416:
10252 case MPI26_MFGPAGE_DEVID_SAS3616:
10253 return MPI26_VERSION;
10259 * _scsih_probe - attach and add scsi host
10260 * @pdev: PCI device struct
10261 * @id: pci device id
10263 * Return: 0 success, anything else error.
10266 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
10268 struct MPT3SAS_ADAPTER *ioc;
10269 struct Scsi_Host *shost = NULL;
10271 u16 hba_mpi_version;
10273 /* Determine in which MPI version class this pci device belongs */
10274 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
10275 if (hba_mpi_version == 0)
10278 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10279 * for other generation HBA's return with -ENODEV
10281 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
10284 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10285 * for other generation HBA's return with -ENODEV
10287 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
10288 || hba_mpi_version == MPI26_VERSION)))
10291 switch (hba_mpi_version) {
10293 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
10294 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
10295 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10296 shost = scsi_host_alloc(&mpt2sas_driver_template,
10297 sizeof(struct MPT3SAS_ADAPTER));
10300 ioc = shost_priv(shost);
10301 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
10302 ioc->hba_mpi_version_belonged = hba_mpi_version;
10303 ioc->id = mpt2_ids++;
10304 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
10305 switch (pdev->device) {
10306 case MPI2_MFGPAGE_DEVID_SSS6200:
10307 ioc->is_warpdrive = 1;
10308 ioc->hide_ir_msg = 1;
10310 case MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP:
10311 ioc->is_mcpu_endpoint = 1;
10314 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
10318 case MPI25_VERSION:
10319 case MPI26_VERSION:
10320 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10321 shost = scsi_host_alloc(&mpt3sas_driver_template,
10322 sizeof(struct MPT3SAS_ADAPTER));
10325 ioc = shost_priv(shost);
10326 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
10327 ioc->hba_mpi_version_belonged = hba_mpi_version;
10328 ioc->id = mpt3_ids++;
10329 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
10330 switch (pdev->device) {
10331 case MPI26_MFGPAGE_DEVID_SAS3508:
10332 case MPI26_MFGPAGE_DEVID_SAS3508_1:
10333 case MPI26_MFGPAGE_DEVID_SAS3408:
10334 case MPI26_MFGPAGE_DEVID_SAS3516:
10335 case MPI26_MFGPAGE_DEVID_SAS3516_1:
10336 case MPI26_MFGPAGE_DEVID_SAS3416:
10337 case MPI26_MFGPAGE_DEVID_SAS3616:
10338 ioc->is_gen35_ioc = 1;
10341 ioc->is_gen35_ioc = 0;
10343 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
10344 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
10345 (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
10346 ioc->combined_reply_queue = 1;
10347 if (ioc->is_gen35_ioc)
10348 ioc->combined_reply_index_count =
10349 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
10351 ioc->combined_reply_index_count =
10352 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
10359 INIT_LIST_HEAD(&ioc->list);
10360 spin_lock(&gioc_lock);
10361 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
10362 spin_unlock(&gioc_lock);
10363 ioc->shost = shost;
10365 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
10366 ioc->tm_cb_idx = tm_cb_idx;
10367 ioc->ctl_cb_idx = ctl_cb_idx;
10368 ioc->base_cb_idx = base_cb_idx;
10369 ioc->port_enable_cb_idx = port_enable_cb_idx;
10370 ioc->transport_cb_idx = transport_cb_idx;
10371 ioc->scsih_cb_idx = scsih_cb_idx;
10372 ioc->config_cb_idx = config_cb_idx;
10373 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
10374 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
10375 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
10376 ioc->logging_level = logging_level;
10377 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
10378 /* misc semaphores and spin locks */
10379 mutex_init(&ioc->reset_in_progress_mutex);
10380 /* initializing pci_access_mutex lock */
10381 mutex_init(&ioc->pci_access_mutex);
10382 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
10383 spin_lock_init(&ioc->scsi_lookup_lock);
10384 spin_lock_init(&ioc->sas_device_lock);
10385 spin_lock_init(&ioc->sas_node_lock);
10386 spin_lock_init(&ioc->fw_event_lock);
10387 spin_lock_init(&ioc->raid_device_lock);
10388 spin_lock_init(&ioc->pcie_device_lock);
10389 spin_lock_init(&ioc->diag_trigger_lock);
10391 INIT_LIST_HEAD(&ioc->sas_device_list);
10392 INIT_LIST_HEAD(&ioc->sas_device_init_list);
10393 INIT_LIST_HEAD(&ioc->sas_expander_list);
10394 INIT_LIST_HEAD(&ioc->enclosure_list);
10395 INIT_LIST_HEAD(&ioc->pcie_device_list);
10396 INIT_LIST_HEAD(&ioc->pcie_device_init_list);
10397 INIT_LIST_HEAD(&ioc->fw_event_list);
10398 INIT_LIST_HEAD(&ioc->raid_device_list);
10399 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
10400 INIT_LIST_HEAD(&ioc->delayed_tr_list);
10401 INIT_LIST_HEAD(&ioc->delayed_sc_list);
10402 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
10403 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
10404 INIT_LIST_HEAD(&ioc->reply_queue_list);
10406 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
10408 /* init shost parameters */
10409 shost->max_cmd_len = 32;
10410 shost->max_lun = max_lun;
10411 shost->transportt = mpt3sas_transport_template;
10412 shost->unique_id = ioc->id;
10414 if (ioc->is_mcpu_endpoint) {
10415 /* mCPU MPI support 64K max IO */
10416 shost->max_sectors = 128;
10417 ioc_info(ioc, "The max_sectors value is set to %d\n",
10418 shost->max_sectors);
10420 if (max_sectors != 0xFFFF) {
10421 if (max_sectors < 64) {
10422 shost->max_sectors = 64;
10423 ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767. Assigning value of 64.\n",
10425 } else if (max_sectors > 32767) {
10426 shost->max_sectors = 32767;
10427 ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767.Assigning default value of 32767.\n",
10430 shost->max_sectors = max_sectors & 0xFFFE;
10431 ioc_info(ioc, "The max_sectors value is set to %d\n",
10432 shost->max_sectors);
10436 /* register EEDP capabilities with SCSI layer */
10438 scsi_host_set_prot(shost, prot_mask);
10440 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
10441 | SHOST_DIF_TYPE2_PROTECTION
10442 | SHOST_DIF_TYPE3_PROTECTION);
10444 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
10447 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
10448 "fw_event_%s%d", ioc->driver_name, ioc->id);
10449 ioc->firmware_event_thread = alloc_ordered_workqueue(
10450 ioc->firmware_event_name, 0);
10451 if (!ioc->firmware_event_thread) {
10452 ioc_err(ioc, "failure at %s:%d/%s()!\n",
10453 __FILE__, __LINE__, __func__);
10455 goto out_thread_fail;
10458 ioc->is_driver_loading = 1;
10459 if ((mpt3sas_base_attach(ioc))) {
10460 ioc_err(ioc, "failure at %s:%d/%s()!\n",
10461 __FILE__, __LINE__, __func__);
10463 goto out_attach_fail;
10466 if (ioc->is_warpdrive) {
10467 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
10468 ioc->hide_drives = 0;
10469 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
10470 ioc->hide_drives = 1;
10472 if (mpt3sas_get_num_volumes(ioc))
10473 ioc->hide_drives = 1;
10475 ioc->hide_drives = 0;
10478 ioc->hide_drives = 0;
10480 rv = scsi_add_host(shost, &pdev->dev);
10482 ioc_err(ioc, "failure at %s:%d/%s()!\n",
10483 __FILE__, __LINE__, __func__);
10484 goto out_add_shost_fail;
10487 scsi_scan_host(shost);
10489 out_add_shost_fail:
10490 mpt3sas_base_detach(ioc);
10492 destroy_workqueue(ioc->firmware_event_thread);
10494 spin_lock(&gioc_lock);
10495 list_del(&ioc->list);
10496 spin_unlock(&gioc_lock);
10497 scsi_host_put(shost);
10503 * scsih_suspend - power management suspend main entry point
10504 * @pdev: PCI device struct
10505 * @state: PM state change to (usually PCI_D3)
10507 * Return: 0 success, anything else error.
10510 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
10512 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10513 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10514 pci_power_t device_state;
10516 mpt3sas_base_stop_watchdog(ioc);
10517 flush_scheduled_work();
10518 scsi_block_requests(shost);
10519 device_state = pci_choose_state(pdev, state);
10520 ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10521 pdev, pci_name(pdev), device_state);
10523 pci_save_state(pdev);
10524 mpt3sas_base_free_resources(ioc);
10525 pci_set_power_state(pdev, device_state);
10530 * scsih_resume - power management resume main entry point
10531 * @pdev: PCI device struct
10533 * Return: 0 success, anything else error.
10536 scsih_resume(struct pci_dev *pdev)
10538 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10539 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10540 pci_power_t device_state = pdev->current_state;
10543 ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10544 pdev, pci_name(pdev), device_state);
10546 pci_set_power_state(pdev, PCI_D0);
10547 pci_enable_wake(pdev, PCI_D0, 0);
10548 pci_restore_state(pdev);
10550 r = mpt3sas_base_map_resources(ioc);
10554 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
10555 scsi_unblock_requests(shost);
10556 mpt3sas_base_start_watchdog(ioc);
10559 #endif /* CONFIG_PM */
10562 * scsih_pci_error_detected - Called when a PCI error is detected.
10563 * @pdev: PCI device struct
10564 * @state: PCI channel state
10566 * Description: Called when a PCI error is detected.
10568 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
10570 static pci_ers_result_t
10571 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
10573 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10574 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10576 ioc_info(ioc, "PCI error: detected callback, state(%d)!!\n", state);
10579 case pci_channel_io_normal:
10580 return PCI_ERS_RESULT_CAN_RECOVER;
10581 case pci_channel_io_frozen:
10582 /* Fatal error, prepare for slot reset */
10583 ioc->pci_error_recovery = 1;
10584 scsi_block_requests(ioc->shost);
10585 mpt3sas_base_stop_watchdog(ioc);
10586 mpt3sas_base_free_resources(ioc);
10587 return PCI_ERS_RESULT_NEED_RESET;
10588 case pci_channel_io_perm_failure:
10589 /* Permanent error, prepare for device removal */
10590 ioc->pci_error_recovery = 1;
10591 mpt3sas_base_stop_watchdog(ioc);
10592 _scsih_flush_running_cmds(ioc);
10593 return PCI_ERS_RESULT_DISCONNECT;
10595 return PCI_ERS_RESULT_NEED_RESET;
10599 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10600 * @pdev: PCI device struct
10602 * Description: This routine is called by the pci error recovery
10603 * code after the PCI slot has been reset, just before we
10604 * should resume normal operations.
10606 static pci_ers_result_t
10607 scsih_pci_slot_reset(struct pci_dev *pdev)
10609 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10610 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10613 ioc_info(ioc, "PCI error: slot reset callback!!\n");
10615 ioc->pci_error_recovery = 0;
10617 pci_restore_state(pdev);
10618 rc = mpt3sas_base_map_resources(ioc);
10620 return PCI_ERS_RESULT_DISCONNECT;
10622 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
10624 ioc_warn(ioc, "hard reset: %s\n",
10625 (rc == 0) ? "success" : "failed");
10628 return PCI_ERS_RESULT_RECOVERED;
10630 return PCI_ERS_RESULT_DISCONNECT;
10634 * scsih_pci_resume() - resume normal ops after PCI reset
10635 * @pdev: pointer to PCI device
10637 * Called when the error recovery driver tells us that its
10638 * OK to resume normal operation. Use completion to allow
10639 * halted scsi ops to resume.
10642 scsih_pci_resume(struct pci_dev *pdev)
10644 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10645 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10647 ioc_info(ioc, "PCI error: resume callback!!\n");
10649 pci_cleanup_aer_uncorrect_error_status(pdev);
10650 mpt3sas_base_start_watchdog(ioc);
10651 scsi_unblock_requests(ioc->shost);
10655 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10656 * @pdev: pointer to PCI device
10658 static pci_ers_result_t
10659 scsih_pci_mmio_enabled(struct pci_dev *pdev)
10661 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10662 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
10664 ioc_info(ioc, "PCI error: mmio enabled callback!!\n");
10666 /* TODO - dump whatever for debugging purposes */
10668 /* This called only if scsih_pci_error_detected returns
10669 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10670 * works, no need to reset slot.
10672 return PCI_ERS_RESULT_RECOVERED;
10676 * scsih__ncq_prio_supp - Check for NCQ command priority support
10677 * @sdev: scsi device struct
10679 * This is called when a user indicates they would like to enable
10680 * ncq command priorities. This works only on SATA devices.
10682 bool scsih_ncq_prio_supp(struct scsi_device *sdev)
10684 unsigned char *buf;
10685 bool ncq_prio_supp = false;
10687 if (!scsi_device_supports_vpd(sdev))
10688 return ncq_prio_supp;
10690 buf = kmalloc(SCSI_VPD_PG_LEN, GFP_KERNEL);
10692 return ncq_prio_supp;
10694 if (!scsi_get_vpd_page(sdev, 0x89, buf, SCSI_VPD_PG_LEN))
10695 ncq_prio_supp = (buf[213] >> 4) & 1;
10698 return ncq_prio_supp;
10701 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10703 static const struct pci_device_id mpt3sas_pci_table[] = {
10704 /* Spitfire ~ 2004 */
10705 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
10706 PCI_ANY_ID, PCI_ANY_ID },
10707 /* Falcon ~ 2008 */
10708 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
10709 PCI_ANY_ID, PCI_ANY_ID },
10710 /* Liberator ~ 2108 */
10711 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
10712 PCI_ANY_ID, PCI_ANY_ID },
10713 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
10714 PCI_ANY_ID, PCI_ANY_ID },
10715 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
10716 PCI_ANY_ID, PCI_ANY_ID },
10717 /* Meteor ~ 2116 */
10718 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
10719 PCI_ANY_ID, PCI_ANY_ID },
10720 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
10721 PCI_ANY_ID, PCI_ANY_ID },
10722 /* Thunderbolt ~ 2208 */
10723 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
10724 PCI_ANY_ID, PCI_ANY_ID },
10725 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
10726 PCI_ANY_ID, PCI_ANY_ID },
10727 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
10728 PCI_ANY_ID, PCI_ANY_ID },
10729 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
10730 PCI_ANY_ID, PCI_ANY_ID },
10731 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
10732 PCI_ANY_ID, PCI_ANY_ID },
10733 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
10734 PCI_ANY_ID, PCI_ANY_ID },
10735 /* Mustang ~ 2308 */
10736 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
10737 PCI_ANY_ID, PCI_ANY_ID },
10738 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
10739 PCI_ANY_ID, PCI_ANY_ID },
10740 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
10741 PCI_ANY_ID, PCI_ANY_ID },
10742 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_MPI_EP,
10743 PCI_ANY_ID, PCI_ANY_ID },
10745 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
10746 PCI_ANY_ID, PCI_ANY_ID },
10747 /* Fury ~ 3004 and 3008 */
10748 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
10749 PCI_ANY_ID, PCI_ANY_ID },
10750 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
10751 PCI_ANY_ID, PCI_ANY_ID },
10752 /* Invader ~ 3108 */
10753 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
10754 PCI_ANY_ID, PCI_ANY_ID },
10755 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
10756 PCI_ANY_ID, PCI_ANY_ID },
10757 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
10758 PCI_ANY_ID, PCI_ANY_ID },
10759 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
10760 PCI_ANY_ID, PCI_ANY_ID },
10761 /* Cutlass ~ 3216 and 3224 */
10762 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
10763 PCI_ANY_ID, PCI_ANY_ID },
10764 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
10765 PCI_ANY_ID, PCI_ANY_ID },
10766 /* Intruder ~ 3316 and 3324 */
10767 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
10768 PCI_ANY_ID, PCI_ANY_ID },
10769 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
10770 PCI_ANY_ID, PCI_ANY_ID },
10771 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
10772 PCI_ANY_ID, PCI_ANY_ID },
10773 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
10774 PCI_ANY_ID, PCI_ANY_ID },
10775 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
10776 PCI_ANY_ID, PCI_ANY_ID },
10777 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
10778 PCI_ANY_ID, PCI_ANY_ID },
10779 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
10780 PCI_ANY_ID, PCI_ANY_ID },
10781 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
10782 PCI_ANY_ID, PCI_ANY_ID },
10783 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
10784 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
10785 PCI_ANY_ID, PCI_ANY_ID },
10786 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
10787 PCI_ANY_ID, PCI_ANY_ID },
10788 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
10789 PCI_ANY_ID, PCI_ANY_ID },
10790 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
10791 PCI_ANY_ID, PCI_ANY_ID },
10792 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
10793 PCI_ANY_ID, PCI_ANY_ID },
10794 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
10795 PCI_ANY_ID, PCI_ANY_ID },
10796 /* Mercator ~ 3616*/
10797 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616,
10798 PCI_ANY_ID, PCI_ANY_ID },
10799 {0} /* Terminating entry */
10801 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
10803 static struct pci_error_handlers _mpt3sas_err_handler = {
10804 .error_detected = scsih_pci_error_detected,
10805 .mmio_enabled = scsih_pci_mmio_enabled,
10806 .slot_reset = scsih_pci_slot_reset,
10807 .resume = scsih_pci_resume,
10810 static struct pci_driver mpt3sas_driver = {
10811 .name = MPT3SAS_DRIVER_NAME,
10812 .id_table = mpt3sas_pci_table,
10813 .probe = _scsih_probe,
10814 .remove = scsih_remove,
10815 .shutdown = scsih_shutdown,
10816 .err_handler = &_mpt3sas_err_handler,
10818 .suspend = scsih_suspend,
10819 .resume = scsih_resume,
10824 * scsih_init - main entry point for this driver.
10826 * Return: 0 success, anything else error.
10834 mpt3sas_base_initialize_callback_handler();
10836 /* queuecommand callback hander */
10837 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
10839 /* task management callback handler */
10840 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
10842 /* base internal commands callback handler */
10843 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
10844 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
10845 mpt3sas_port_enable_done);
10847 /* transport internal commands callback handler */
10848 transport_cb_idx = mpt3sas_base_register_callback_handler(
10849 mpt3sas_transport_done);
10851 /* scsih internal commands callback handler */
10852 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
10854 /* configuration page API internal commands callback handler */
10855 config_cb_idx = mpt3sas_base_register_callback_handler(
10856 mpt3sas_config_done);
10858 /* ctl module callback handler */
10859 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
10861 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
10862 _scsih_tm_tr_complete);
10864 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
10865 _scsih_tm_volume_tr_complete);
10867 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
10868 _scsih_sas_control_complete);
10874 * scsih_exit - exit point for this driver (when it is a module).
10876 * Return: 0 success, anything else error.
10882 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
10883 mpt3sas_base_release_callback_handler(tm_cb_idx);
10884 mpt3sas_base_release_callback_handler(base_cb_idx);
10885 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
10886 mpt3sas_base_release_callback_handler(transport_cb_idx);
10887 mpt3sas_base_release_callback_handler(scsih_cb_idx);
10888 mpt3sas_base_release_callback_handler(config_cb_idx);
10889 mpt3sas_base_release_callback_handler(ctl_cb_idx);
10891 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
10892 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
10893 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
10895 /* raid transport support */
10896 if (hbas_to_enumerate != 1)
10897 raid_class_release(mpt3sas_raid_template);
10898 if (hbas_to_enumerate != 2)
10899 raid_class_release(mpt2sas_raid_template);
10900 sas_release_transport(mpt3sas_transport_template);
10904 * _mpt3sas_init - main entry point for this driver.
10906 * Return: 0 success, anything else error.
10909 _mpt3sas_init(void)
10913 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
10914 MPT3SAS_DRIVER_VERSION);
10916 mpt3sas_transport_template =
10917 sas_attach_transport(&mpt3sas_transport_functions);
10918 if (!mpt3sas_transport_template)
10921 /* No need attach mpt3sas raid functions template
10922 * if hbas_to_enumarate value is one.
10924 if (hbas_to_enumerate != 1) {
10925 mpt3sas_raid_template =
10926 raid_class_attach(&mpt3sas_raid_functions);
10927 if (!mpt3sas_raid_template) {
10928 sas_release_transport(mpt3sas_transport_template);
10933 /* No need to attach mpt2sas raid functions template
10934 * if hbas_to_enumarate value is two
10936 if (hbas_to_enumerate != 2) {
10937 mpt2sas_raid_template =
10938 raid_class_attach(&mpt2sas_raid_functions);
10939 if (!mpt2sas_raid_template) {
10940 sas_release_transport(mpt3sas_transport_template);
10945 error = scsih_init();
10951 mpt3sas_ctl_init(hbas_to_enumerate);
10953 error = pci_register_driver(&mpt3sas_driver);
10961 * _mpt3sas_exit - exit point for this driver (when it is a module).
10965 _mpt3sas_exit(void)
10967 pr_info("mpt3sas version %s unloading\n",
10968 MPT3SAS_DRIVER_VERSION);
10970 mpt3sas_ctl_exit(hbas_to_enumerate);
10972 pci_unregister_driver(&mpt3sas_driver);
10977 module_init(_mpt3sas_init);
10978 module_exit(_mpt3sas_exit);