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
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/raid_class.h>
56 #include <linux/unaligned.h>
58 #include "mpt3sas_base.h"
60 #define RAID_CHANNEL 1
62 #define PCIE_CHANNEL 2
65 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
66 struct _sas_node *sas_expander);
67 static void _firmware_event_work(struct work_struct *work);
69 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
70 struct _sas_device *sas_device);
71 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
72 u8 retry_count, u8 is_pd);
73 static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle);
74 static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
75 struct _pcie_device *pcie_device);
77 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle);
78 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
79 static void _scsih_complete_devices_scanning(struct MPT3SAS_ADAPTER *ioc);
81 /* global parameters */
82 LIST_HEAD(mpt3sas_ioc_list);
83 /* global ioc lock for list operations */
84 DEFINE_SPINLOCK(gioc_lock);
86 MODULE_AUTHOR(MPT3SAS_AUTHOR);
87 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
90 MODULE_ALIAS("mpt2sas");
92 /* local parameters */
93 static u8 scsi_io_cb_idx = -1;
94 static u8 tm_cb_idx = -1;
95 static u8 ctl_cb_idx = -1;
96 static u8 base_cb_idx = -1;
97 static u8 port_enable_cb_idx = -1;
98 static u8 transport_cb_idx = -1;
99 static u8 scsih_cb_idx = -1;
100 static u8 config_cb_idx = -1;
104 static u8 tm_tr_cb_idx = -1 ;
105 static u8 tm_tr_volume_cb_idx = -1 ;
106 static u8 tm_sas_control_cb_idx = -1;
108 /* command line options */
109 static u32 logging_level;
110 MODULE_PARM_DESC(logging_level,
111 " bits for enabling additional logging info (default=0)");
114 static ushort max_sectors = 0xFFFF;
115 module_param(max_sectors, ushort, 0444);
116 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
119 static int missing_delay[2] = {-1, -1};
120 module_param_array(missing_delay, int, NULL, 0444);
121 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
123 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
124 #define MPT3SAS_MAX_LUN (16895)
125 static u64 max_lun = MPT3SAS_MAX_LUN;
126 module_param(max_lun, ullong, 0444);
127 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
129 static ushort hbas_to_enumerate;
130 module_param(hbas_to_enumerate, ushort, 0444);
131 MODULE_PARM_DESC(hbas_to_enumerate,
132 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
133 1 - enumerates only SAS 2.0 generation HBAs\n \
134 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
136 /* diag_buffer_enable is bitwise
138 * bit 1 set = SNAPSHOT
139 * bit 2 set = EXTENDED
141 * Either bit can be set, or both
143 static int diag_buffer_enable = -1;
144 module_param(diag_buffer_enable, int, 0444);
145 MODULE_PARM_DESC(diag_buffer_enable,
146 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
147 static int disable_discovery = -1;
148 module_param(disable_discovery, int, 0444);
149 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
152 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
153 static int prot_mask = -1;
154 module_param(prot_mask, int, 0444);
155 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
157 static bool enable_sdev_max_qd;
158 module_param(enable_sdev_max_qd, bool, 0444);
159 MODULE_PARM_DESC(enable_sdev_max_qd,
160 "Enable sdev max qd as can_queue, def=disabled(0)");
162 static int multipath_on_hba = -1;
163 module_param(multipath_on_hba, int, 0);
164 MODULE_PARM_DESC(multipath_on_hba,
165 "Multipath support to add same target device\n\t\t"
166 "as many times as it is visible to HBA from various paths\n\t\t"
168 "\t SAS 2.0 & SAS 3.0 HBA - This will be disabled,\n\t\t"
169 "\t SAS 3.5 HBA - This will be enabled)");
171 static int host_tagset_enable = 1;
172 module_param(host_tagset_enable, int, 0444);
173 MODULE_PARM_DESC(host_tagset_enable,
174 "Shared host tagset enable/disable Default: enable(1)");
176 /* raid transport support */
177 static struct raid_template *mpt3sas_raid_template;
178 static struct raid_template *mpt2sas_raid_template;
182 * struct sense_info - common structure for obtaining sense keys
184 * @asc: additional sense code
185 * @ascq: additional sense code qualifier
193 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
194 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
195 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
196 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
197 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
199 * struct fw_event_work - firmware event struct
200 * @list: link list framework
201 * @work: work object (ioc->fault_reset_work_q)
202 * @ioc: per adapter object
203 * @device_handle: device handle
204 * @VF_ID: virtual function id
205 * @VP_ID: virtual port id
206 * @ignore: flag meaning this event has been marked to ignore
207 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
208 * @refcount: kref for this event
209 * @event_data: reply event data payload follows
211 * This object stored on ioc->fw_event_list.
213 struct fw_event_work {
214 struct list_head list;
215 struct work_struct work;
217 struct MPT3SAS_ADAPTER *ioc;
223 struct kref refcount;
224 char event_data[] __aligned(4);
227 static void fw_event_work_free(struct kref *r)
229 kfree(container_of(r, struct fw_event_work, refcount));
232 static void fw_event_work_get(struct fw_event_work *fw_work)
234 kref_get(&fw_work->refcount);
237 static void fw_event_work_put(struct fw_event_work *fw_work)
239 kref_put(&fw_work->refcount, fw_event_work_free);
242 static struct fw_event_work *alloc_fw_event_work(int len)
244 struct fw_event_work *fw_event;
246 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
250 kref_init(&fw_event->refcount);
255 * struct _scsi_io_transfer - scsi io transfer
256 * @handle: sas device handle (assigned by firmware)
257 * @is_raid: flag set for hidden raid components
258 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
259 * @data_length: data transfer length
260 * @data_dma: dma pointer to data
263 * @cdb_length: cdb length
265 * @timeout: timeout for this command
266 * @VF_ID: virtual function id
267 * @VP_ID: virtual port id
268 * @valid_reply: flag set for reply message
269 * @sense_length: sense length
270 * @ioc_status: ioc status
271 * @scsi_state: scsi state
272 * @scsi_status: scsi staus
273 * @log_info: log information
274 * @transfer_length: data length transfer when there is a reply message
276 * Used for sending internal scsi commands to devices within this module.
277 * Refer to _scsi_send_scsi_io().
279 struct _scsi_io_transfer {
282 enum dma_data_direction dir;
285 u8 sense[SCSI_SENSE_BUFFERSIZE];
293 /* the following bits are only valid when 'valid_reply = 1' */
303 * _scsih_set_debug_level - global setting of ioc->logging_level.
304 * @val: value of the parameter to be set
305 * @kp: pointer to kernel_param structure
307 * Note: The logging levels are defined in mpt3sas_debug.h.
310 _scsih_set_debug_level(const char *val, const struct kernel_param *kp)
312 int ret = param_set_int(val, kp);
313 struct MPT3SAS_ADAPTER *ioc;
318 pr_info("setting logging_level(0x%08x)\n", logging_level);
319 spin_lock(&gioc_lock);
320 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
321 ioc->logging_level = logging_level;
322 spin_unlock(&gioc_lock);
325 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
326 &logging_level, 0644);
329 * _scsih_srch_boot_sas_address - search based on sas_address
330 * @sas_address: sas address
331 * @boot_device: boot device object from bios page 2
333 * Return: 1 when there's a match, 0 means no match.
336 _scsih_srch_boot_sas_address(u64 sas_address,
337 Mpi2BootDeviceSasWwid_t *boot_device)
339 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
343 * _scsih_srch_boot_device_name - search based on device name
344 * @device_name: device name specified in INDENTIFY fram
345 * @boot_device: boot device object from bios page 2
347 * Return: 1 when there's a match, 0 means no match.
350 _scsih_srch_boot_device_name(u64 device_name,
351 Mpi2BootDeviceDeviceName_t *boot_device)
353 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
357 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
358 * @enclosure_logical_id: enclosure logical id
359 * @slot_number: slot number
360 * @boot_device: boot device object from bios page 2
362 * Return: 1 when there's a match, 0 means no match.
365 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
366 Mpi2BootDeviceEnclosureSlot_t *boot_device)
368 return (enclosure_logical_id == le64_to_cpu(boot_device->
369 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
370 SlotNumber)) ? 1 : 0;
374 * mpt3sas_get_port_by_id - get hba port entry corresponding to provided
375 * port number from port list
376 * @ioc: per adapter object
377 * @port_id: port number
378 * @bypass_dirty_port_flag: when set look the matching hba port entry even
379 * if hba port entry is marked as dirty.
381 * Search for hba port entry corresponding to provided port number,
382 * if available return port object otherwise return NULL.
385 mpt3sas_get_port_by_id(struct MPT3SAS_ADAPTER *ioc,
386 u8 port_id, u8 bypass_dirty_port_flag)
388 struct hba_port *port, *port_next;
391 * When multipath_on_hba is disabled then
392 * search the hba_port entry using default
395 if (!ioc->multipath_on_hba)
396 port_id = MULTIPATH_DISABLED_PORT_ID;
398 list_for_each_entry_safe(port, port_next,
399 &ioc->port_table_list, list) {
400 if (port->port_id != port_id)
402 if (bypass_dirty_port_flag)
404 if (port->flags & HBA_PORT_FLAG_DIRTY_PORT)
410 * Allocate hba_port object for default port id (i.e. 255)
411 * when multipath_on_hba is disabled for the HBA.
412 * And add this object to port_table_list.
414 if (!ioc->multipath_on_hba) {
415 port = kzalloc(sizeof(struct hba_port), GFP_ATOMIC);
419 port->port_id = port_id;
421 "hba_port entry: %p, port: %d is added to hba_port list\n",
422 port, port->port_id);
423 list_add_tail(&port->list,
424 &ioc->port_table_list);
431 * mpt3sas_get_vphy_by_phy - get virtual_phy object corresponding to phy number
432 * @ioc: per adapter object
433 * @port: hba_port object
436 * Return virtual_phy object corresponding to phy number.
439 mpt3sas_get_vphy_by_phy(struct MPT3SAS_ADAPTER *ioc,
440 struct hba_port *port, u32 phy)
442 struct virtual_phy *vphy, *vphy_next;
444 if (!port->vphys_mask)
447 list_for_each_entry_safe(vphy, vphy_next, &port->vphys_list, list) {
448 if (vphy->phy_mask & (1 << phy))
455 * _scsih_is_boot_device - search for matching boot device.
456 * @sas_address: sas address
457 * @device_name: device name specified in INDENTIFY fram
458 * @enclosure_logical_id: enclosure logical id
460 * @form: specifies boot device form
461 * @boot_device: boot device object from bios page 2
463 * Return: 1 when there's a match, 0 means no match.
466 _scsih_is_boot_device(u64 sas_address, u64 device_name,
467 u64 enclosure_logical_id, u16 slot, u8 form,
468 Mpi2BiosPage2BootDevice_t *boot_device)
473 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
476 rc = _scsih_srch_boot_sas_address(
477 sas_address, &boot_device->SasWwid);
479 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
480 if (!enclosure_logical_id)
482 rc = _scsih_srch_boot_encl_slot(
483 enclosure_logical_id,
484 slot, &boot_device->EnclosureSlot);
486 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
489 rc = _scsih_srch_boot_device_name(
490 device_name, &boot_device->DeviceName);
492 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
500 * _scsih_get_sas_address - set the sas_address for given device handle
502 * @handle: device handle
503 * @sas_address: sas address
505 * Return: 0 success, non-zero when failure
508 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
511 Mpi2SasDevicePage0_t sas_device_pg0;
512 Mpi2ConfigReply_t mpi_reply;
517 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
518 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
519 ioc_err(ioc, "failure at %s:%d/%s()!\n",
520 __FILE__, __LINE__, __func__);
524 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
525 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
526 /* For HBA, vSES doesn't return HBA SAS address. Instead return
527 * vSES's sas address.
529 if ((handle <= ioc->sas_hba.num_phys) &&
530 (!(le32_to_cpu(sas_device_pg0.DeviceInfo) &
531 MPI2_SAS_DEVICE_INFO_SEP)))
532 *sas_address = ioc->sas_hba.sas_address;
534 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
538 /* we hit this because the given parent handle doesn't exist */
539 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
542 /* else error case */
543 ioc_err(ioc, "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
544 handle, ioc_status, __FILE__, __LINE__, __func__);
549 * _scsih_determine_boot_device - determine boot device.
550 * @ioc: per adapter object
551 * @device: sas_device or pcie_device object
552 * @channel: SAS or PCIe channel
554 * Determines whether this device should be first reported device to
555 * to scsi-ml or sas transport, this purpose is for persistent boot device.
556 * There are primary, alternate, and current entries in bios page 2. The order
557 * priority is primary, alternate, then current. This routine saves
558 * the corresponding device object.
559 * The saved data to be used later in _scsih_probe_boot_devices().
562 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc, void *device,
565 struct _sas_device *sas_device;
566 struct _pcie_device *pcie_device;
567 struct _raid_device *raid_device;
570 u64 enclosure_logical_id;
573 /* only process this function when driver loads */
574 if (!ioc->is_driver_loading)
577 /* no Bios, return immediately */
578 if (!ioc->bios_pg3.BiosVersion)
581 if (channel == RAID_CHANNEL) {
582 raid_device = device;
583 sas_address = raid_device->wwid;
585 enclosure_logical_id = 0;
587 } else if (channel == PCIE_CHANNEL) {
588 pcie_device = device;
589 sas_address = pcie_device->wwid;
591 enclosure_logical_id = 0;
595 sas_address = sas_device->sas_address;
596 device_name = sas_device->device_name;
597 enclosure_logical_id = sas_device->enclosure_logical_id;
598 slot = sas_device->slot;
601 if (!ioc->req_boot_device.device) {
602 if (_scsih_is_boot_device(sas_address, device_name,
603 enclosure_logical_id, slot,
604 (ioc->bios_pg2.ReqBootDeviceForm &
605 MPI2_BIOSPAGE2_FORM_MASK),
606 &ioc->bios_pg2.RequestedBootDevice)) {
608 ioc_info(ioc, "%s: req_boot_device(0x%016llx)\n",
609 __func__, (u64)sas_address));
610 ioc->req_boot_device.device = device;
611 ioc->req_boot_device.channel = channel;
615 if (!ioc->req_alt_boot_device.device) {
616 if (_scsih_is_boot_device(sas_address, device_name,
617 enclosure_logical_id, slot,
618 (ioc->bios_pg2.ReqAltBootDeviceForm &
619 MPI2_BIOSPAGE2_FORM_MASK),
620 &ioc->bios_pg2.RequestedAltBootDevice)) {
622 ioc_info(ioc, "%s: req_alt_boot_device(0x%016llx)\n",
623 __func__, (u64)sas_address));
624 ioc->req_alt_boot_device.device = device;
625 ioc->req_alt_boot_device.channel = channel;
629 if (!ioc->current_boot_device.device) {
630 if (_scsih_is_boot_device(sas_address, device_name,
631 enclosure_logical_id, slot,
632 (ioc->bios_pg2.CurrentBootDeviceForm &
633 MPI2_BIOSPAGE2_FORM_MASK),
634 &ioc->bios_pg2.CurrentBootDevice)) {
636 ioc_info(ioc, "%s: current_boot_device(0x%016llx)\n",
637 __func__, (u64)sas_address));
638 ioc->current_boot_device.device = device;
639 ioc->current_boot_device.channel = channel;
644 static struct _sas_device *
645 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
646 struct MPT3SAS_TARGET *tgt_priv)
648 struct _sas_device *ret;
650 assert_spin_locked(&ioc->sas_device_lock);
652 ret = tgt_priv->sas_dev;
659 static struct _sas_device *
660 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
661 struct MPT3SAS_TARGET *tgt_priv)
663 struct _sas_device *ret;
666 spin_lock_irqsave(&ioc->sas_device_lock, flags);
667 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
668 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
673 static struct _pcie_device *
674 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
675 struct MPT3SAS_TARGET *tgt_priv)
677 struct _pcie_device *ret;
679 assert_spin_locked(&ioc->pcie_device_lock);
681 ret = tgt_priv->pcie_dev;
683 pcie_device_get(ret);
689 * mpt3sas_get_pdev_from_target - pcie device search
690 * @ioc: per adapter object
691 * @tgt_priv: starget private object
693 * Context: This function will acquire ioc->pcie_device_lock and will release
694 * before returning the pcie_device object.
696 * This searches for pcie_device from target, then return pcie_device object.
698 static struct _pcie_device *
699 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc,
700 struct MPT3SAS_TARGET *tgt_priv)
702 struct _pcie_device *ret;
705 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
706 ret = __mpt3sas_get_pdev_from_target(ioc, tgt_priv);
707 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
714 * __mpt3sas_get_sdev_by_rphy - sas device search
715 * @ioc: per adapter object
716 * @rphy: sas_rphy pointer
718 * Context: This function will acquire ioc->sas_device_lock and will release
719 * before returning the sas_device object.
721 * This searches for sas_device from rphy object
722 * then return sas_device object.
725 __mpt3sas_get_sdev_by_rphy(struct MPT3SAS_ADAPTER *ioc,
726 struct sas_rphy *rphy)
728 struct _sas_device *sas_device;
730 assert_spin_locked(&ioc->sas_device_lock);
732 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
733 if (sas_device->rphy != rphy)
735 sas_device_get(sas_device);
740 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) {
741 if (sas_device->rphy != rphy)
743 sas_device_get(sas_device);
751 * __mpt3sas_get_sdev_by_addr - get _sas_device object corresponding to provided
752 * sas address from sas_device_list list
753 * @ioc: per adapter object
754 * @sas_address: device sas address
757 * Search for _sas_device object corresponding to provided sas address,
758 * if available return _sas_device object address otherwise return NULL.
761 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
762 u64 sas_address, struct hba_port *port)
764 struct _sas_device *sas_device;
769 assert_spin_locked(&ioc->sas_device_lock);
771 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
772 if (sas_device->sas_address != sas_address)
774 if (sas_device->port != port)
776 sas_device_get(sas_device);
780 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) {
781 if (sas_device->sas_address != sas_address)
783 if (sas_device->port != port)
785 sas_device_get(sas_device);
793 * mpt3sas_get_sdev_by_addr - sas device search
794 * @ioc: per adapter object
795 * @sas_address: sas address
796 * @port: hba port entry
797 * Context: Calling function should acquire ioc->sas_device_lock
799 * This searches for sas_device based on sas_address & port number,
800 * then return sas_device object.
803 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
804 u64 sas_address, struct hba_port *port)
806 struct _sas_device *sas_device;
809 spin_lock_irqsave(&ioc->sas_device_lock, flags);
810 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
812 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
817 static struct _sas_device *
818 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
820 struct _sas_device *sas_device;
822 assert_spin_locked(&ioc->sas_device_lock);
824 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
825 if (sas_device->handle == handle)
828 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
829 if (sas_device->handle == handle)
835 sas_device_get(sas_device);
840 * mpt3sas_get_sdev_by_handle - sas device search
841 * @ioc: per adapter object
842 * @handle: sas device handle (assigned by firmware)
843 * Context: Calling function should acquire ioc->sas_device_lock
845 * This searches for sas_device based on sas_address, then return sas_device
849 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
851 struct _sas_device *sas_device;
854 spin_lock_irqsave(&ioc->sas_device_lock, flags);
855 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
856 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
862 * _scsih_display_enclosure_chassis_info - display device location info
863 * @ioc: per adapter object
864 * @sas_device: per sas device object
865 * @sdev: scsi device struct
866 * @starget: scsi target struct
869 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER *ioc,
870 struct _sas_device *sas_device, struct scsi_device *sdev,
871 struct scsi_target *starget)
874 if (sas_device->enclosure_handle != 0)
875 sdev_printk(KERN_INFO, sdev,
876 "enclosure logical id (0x%016llx), slot(%d) \n",
878 sas_device->enclosure_logical_id,
880 if (sas_device->connector_name[0] != '\0')
881 sdev_printk(KERN_INFO, sdev,
882 "enclosure level(0x%04x), connector name( %s)\n",
883 sas_device->enclosure_level,
884 sas_device->connector_name);
885 if (sas_device->is_chassis_slot_valid)
886 sdev_printk(KERN_INFO, sdev, "chassis slot(0x%04x)\n",
887 sas_device->chassis_slot);
888 } else if (starget) {
889 if (sas_device->enclosure_handle != 0)
890 starget_printk(KERN_INFO, starget,
891 "enclosure logical id(0x%016llx), slot(%d) \n",
893 sas_device->enclosure_logical_id,
895 if (sas_device->connector_name[0] != '\0')
896 starget_printk(KERN_INFO, starget,
897 "enclosure level(0x%04x), connector name( %s)\n",
898 sas_device->enclosure_level,
899 sas_device->connector_name);
900 if (sas_device->is_chassis_slot_valid)
901 starget_printk(KERN_INFO, starget,
902 "chassis slot(0x%04x)\n",
903 sas_device->chassis_slot);
905 if (sas_device->enclosure_handle != 0)
906 ioc_info(ioc, "enclosure logical id(0x%016llx), slot(%d)\n",
907 (u64)sas_device->enclosure_logical_id,
909 if (sas_device->connector_name[0] != '\0')
910 ioc_info(ioc, "enclosure level(0x%04x), connector name( %s)\n",
911 sas_device->enclosure_level,
912 sas_device->connector_name);
913 if (sas_device->is_chassis_slot_valid)
914 ioc_info(ioc, "chassis slot(0x%04x)\n",
915 sas_device->chassis_slot);
920 * _scsih_sas_device_remove - remove sas_device from list.
921 * @ioc: per adapter object
922 * @sas_device: the sas_device object
923 * Context: This function will acquire ioc->sas_device_lock.
925 * If sas_device is on the list, remove it and decrement its reference count.
928 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
929 struct _sas_device *sas_device)
935 ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
936 sas_device->handle, (u64)sas_device->sas_address);
938 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
941 * The lock serializes access to the list, but we still need to verify
942 * that nobody removed the entry while we were waiting on the lock.
944 spin_lock_irqsave(&ioc->sas_device_lock, flags);
945 if (!list_empty(&sas_device->list)) {
946 list_del_init(&sas_device->list);
947 sas_device_put(sas_device);
949 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
953 * _scsih_device_remove_by_handle - removing device object by handle
954 * @ioc: per adapter object
955 * @handle: device handle
958 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
960 struct _sas_device *sas_device;
963 if (ioc->shost_recovery)
966 spin_lock_irqsave(&ioc->sas_device_lock, flags);
967 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
969 list_del_init(&sas_device->list);
970 sas_device_put(sas_device);
972 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
974 _scsih_remove_device(ioc, sas_device);
975 sas_device_put(sas_device);
980 * mpt3sas_device_remove_by_sas_address - removing device object by
981 * sas address & port number
982 * @ioc: per adapter object
983 * @sas_address: device sas_address
984 * @port: hba port entry
989 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
990 u64 sas_address, struct hba_port *port)
992 struct _sas_device *sas_device;
995 if (ioc->shost_recovery)
998 spin_lock_irqsave(&ioc->sas_device_lock, flags);
999 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address, port);
1001 list_del_init(&sas_device->list);
1002 sas_device_put(sas_device);
1004 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1006 _scsih_remove_device(ioc, sas_device);
1007 sas_device_put(sas_device);
1012 * _scsih_sas_device_add - insert sas_device to the list.
1013 * @ioc: per adapter object
1014 * @sas_device: the sas_device object
1015 * Context: This function will acquire ioc->sas_device_lock.
1017 * Adding new object to the ioc->sas_device_list.
1020 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
1021 struct _sas_device *sas_device)
1023 unsigned long flags;
1026 ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
1027 __func__, sas_device->handle,
1028 (u64)sas_device->sas_address));
1030 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
1033 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1034 sas_device_get(sas_device);
1035 list_add_tail(&sas_device->list, &ioc->sas_device_list);
1036 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1038 if (ioc->hide_drives) {
1039 clear_bit(sas_device->handle, ioc->pend_os_device_add);
1043 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
1044 sas_device->sas_address_parent, sas_device->port)) {
1045 _scsih_sas_device_remove(ioc, sas_device);
1046 } else if (!sas_device->starget) {
1048 * When asyn scanning is enabled, its not possible to remove
1049 * devices while scanning is turned on due to an oops in
1050 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
1052 if (!ioc->is_driver_loading) {
1053 mpt3sas_transport_port_remove(ioc,
1054 sas_device->sas_address,
1055 sas_device->sas_address_parent,
1057 _scsih_sas_device_remove(ioc, sas_device);
1060 clear_bit(sas_device->handle, ioc->pend_os_device_add);
1064 * _scsih_sas_device_init_add - insert sas_device to the list.
1065 * @ioc: per adapter object
1066 * @sas_device: the sas_device object
1067 * Context: This function will acquire ioc->sas_device_lock.
1069 * Adding new object at driver load time to the ioc->sas_device_init_list.
1072 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
1073 struct _sas_device *sas_device)
1075 unsigned long flags;
1078 ioc_info(ioc, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
1079 __func__, sas_device->handle,
1080 (u64)sas_device->sas_address));
1082 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
1085 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1086 sas_device_get(sas_device);
1087 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
1088 _scsih_determine_boot_device(ioc, sas_device, 0);
1089 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1093 static struct _pcie_device *
1094 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
1096 struct _pcie_device *pcie_device;
1098 assert_spin_locked(&ioc->pcie_device_lock);
1100 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
1101 if (pcie_device->wwid == wwid)
1104 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
1105 if (pcie_device->wwid == wwid)
1111 pcie_device_get(pcie_device);
1117 * mpt3sas_get_pdev_by_wwid - pcie device search
1118 * @ioc: per adapter object
1121 * Context: This function will acquire ioc->pcie_device_lock and will release
1122 * before returning the pcie_device object.
1124 * This searches for pcie_device based on wwid, then return pcie_device object.
1126 static struct _pcie_device *
1127 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
1129 struct _pcie_device *pcie_device;
1130 unsigned long flags;
1132 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1133 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
1134 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1140 static struct _pcie_device *
1141 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER *ioc, int id,
1144 struct _pcie_device *pcie_device;
1146 assert_spin_locked(&ioc->pcie_device_lock);
1148 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
1149 if (pcie_device->id == id && pcie_device->channel == channel)
1152 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
1153 if (pcie_device->id == id && pcie_device->channel == channel)
1159 pcie_device_get(pcie_device);
1163 static struct _pcie_device *
1164 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1166 struct _pcie_device *pcie_device;
1168 assert_spin_locked(&ioc->pcie_device_lock);
1170 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list)
1171 if (pcie_device->handle == handle)
1174 list_for_each_entry(pcie_device, &ioc->pcie_device_init_list, list)
1175 if (pcie_device->handle == handle)
1181 pcie_device_get(pcie_device);
1187 * mpt3sas_get_pdev_by_handle - pcie device search
1188 * @ioc: per adapter object
1189 * @handle: Firmware device handle
1191 * Context: This function will acquire ioc->pcie_device_lock and will release
1192 * before returning the pcie_device object.
1194 * This searches for pcie_device based on handle, then return pcie_device
1197 struct _pcie_device *
1198 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1200 struct _pcie_device *pcie_device;
1201 unsigned long flags;
1203 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1204 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
1205 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1211 * _scsih_set_nvme_max_shutdown_latency - Update max_shutdown_latency.
1212 * @ioc: per adapter object
1213 * Context: This function will acquire ioc->pcie_device_lock
1215 * Update ioc->max_shutdown_latency to that NVMe drives RTD3 Entry Latency
1216 * which has reported maximum among all available NVMe drives.
1217 * Minimum max_shutdown_latency will be six seconds.
1220 _scsih_set_nvme_max_shutdown_latency(struct MPT3SAS_ADAPTER *ioc)
1222 struct _pcie_device *pcie_device;
1223 unsigned long flags;
1224 u16 shutdown_latency = IO_UNIT_CONTROL_SHUTDOWN_TIMEOUT;
1226 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1227 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
1228 if (pcie_device->shutdown_latency) {
1229 if (shutdown_latency < pcie_device->shutdown_latency)
1231 pcie_device->shutdown_latency;
1234 ioc->max_shutdown_latency = shutdown_latency;
1235 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1239 * _scsih_pcie_device_remove - remove pcie_device from list.
1240 * @ioc: per adapter object
1241 * @pcie_device: the pcie_device object
1242 * Context: This function will acquire ioc->pcie_device_lock.
1244 * If pcie_device is on the list, remove it and decrement its reference count.
1247 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER *ioc,
1248 struct _pcie_device *pcie_device)
1250 unsigned long flags;
1251 int was_on_pcie_device_list = 0;
1252 u8 update_latency = 0;
1256 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
1257 pcie_device->handle, (u64)pcie_device->wwid);
1258 if (pcie_device->enclosure_handle != 0)
1259 ioc_info(ioc, "removing enclosure logical id(0x%016llx), slot(%d)\n",
1260 (u64)pcie_device->enclosure_logical_id,
1262 if (pcie_device->connector_name[0] != '\0')
1263 ioc_info(ioc, "removing enclosure level(0x%04x), connector name( %s)\n",
1264 pcie_device->enclosure_level,
1265 pcie_device->connector_name);
1267 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1268 if (!list_empty(&pcie_device->list)) {
1269 list_del_init(&pcie_device->list);
1270 was_on_pcie_device_list = 1;
1272 if (pcie_device->shutdown_latency == ioc->max_shutdown_latency)
1274 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1275 if (was_on_pcie_device_list) {
1276 kfree(pcie_device->serial_number);
1277 pcie_device_put(pcie_device);
1281 * This device's RTD3 Entry Latency matches IOC's
1282 * max_shutdown_latency. Recalculate IOC's max_shutdown_latency
1283 * from the available drives as current drive is getting removed.
1286 _scsih_set_nvme_max_shutdown_latency(ioc);
1291 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1292 * @ioc: per adapter object
1293 * @handle: device handle
1296 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1298 struct _pcie_device *pcie_device;
1299 unsigned long flags;
1300 int was_on_pcie_device_list = 0;
1301 u8 update_latency = 0;
1303 if (ioc->shost_recovery)
1306 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1307 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
1309 if (!list_empty(&pcie_device->list)) {
1310 list_del_init(&pcie_device->list);
1311 was_on_pcie_device_list = 1;
1312 pcie_device_put(pcie_device);
1314 if (pcie_device->shutdown_latency == ioc->max_shutdown_latency)
1317 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1318 if (was_on_pcie_device_list) {
1319 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
1320 pcie_device_put(pcie_device);
1324 * This device's RTD3 Entry Latency matches IOC's
1325 * max_shutdown_latency. Recalculate IOC's max_shutdown_latency
1326 * from the available drives as current drive is getting removed.
1329 _scsih_set_nvme_max_shutdown_latency(ioc);
1333 * _scsih_pcie_device_add - add pcie_device object
1334 * @ioc: per adapter object
1335 * @pcie_device: pcie_device object
1337 * This is added to the pcie_device_list link list.
1340 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER *ioc,
1341 struct _pcie_device *pcie_device)
1343 unsigned long flags;
1346 ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1348 pcie_device->handle, (u64)pcie_device->wwid));
1349 if (pcie_device->enclosure_handle != 0)
1351 ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1353 (u64)pcie_device->enclosure_logical_id,
1354 pcie_device->slot));
1355 if (pcie_device->connector_name[0] != '\0')
1357 ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n",
1358 __func__, pcie_device->enclosure_level,
1359 pcie_device->connector_name));
1361 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1362 pcie_device_get(pcie_device);
1363 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
1364 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1366 if (pcie_device->access_status ==
1367 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) {
1368 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1371 if (scsi_add_device(ioc->shost, PCIE_CHANNEL, pcie_device->id, 0)) {
1372 _scsih_pcie_device_remove(ioc, pcie_device);
1373 } else if (!pcie_device->starget) {
1374 if (!ioc->is_driver_loading) {
1375 /*TODO-- Need to find out whether this condition will occur or not*/
1376 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1379 clear_bit(pcie_device->handle, ioc->pend_os_device_add);
1383 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1384 * @ioc: per adapter object
1385 * @pcie_device: the pcie_device object
1386 * Context: This function will acquire ioc->pcie_device_lock.
1388 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1391 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER *ioc,
1392 struct _pcie_device *pcie_device)
1394 unsigned long flags;
1397 ioc_info(ioc, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1399 pcie_device->handle, (u64)pcie_device->wwid));
1400 if (pcie_device->enclosure_handle != 0)
1402 ioc_info(ioc, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1404 (u64)pcie_device->enclosure_logical_id,
1405 pcie_device->slot));
1406 if (pcie_device->connector_name[0] != '\0')
1408 ioc_info(ioc, "%s: enclosure level(0x%04x), connector name( %s)\n",
1409 __func__, pcie_device->enclosure_level,
1410 pcie_device->connector_name));
1412 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1413 pcie_device_get(pcie_device);
1414 list_add_tail(&pcie_device->list, &ioc->pcie_device_init_list);
1415 if (pcie_device->access_status !=
1416 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED)
1417 _scsih_determine_boot_device(ioc, pcie_device, PCIE_CHANNEL);
1418 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1421 * _scsih_raid_device_find_by_id - raid device search
1422 * @ioc: per adapter object
1423 * @id: sas device target id
1424 * @channel: sas device channel
1425 * Context: Calling function should acquire ioc->raid_device_lock
1427 * This searches for raid_device based on target id, then return raid_device
1430 static struct _raid_device *
1431 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
1433 struct _raid_device *raid_device, *r;
1436 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1437 if (raid_device->id == id && raid_device->channel == channel) {
1448 * mpt3sas_raid_device_find_by_handle - raid device search
1449 * @ioc: per adapter object
1450 * @handle: sas device handle (assigned by firmware)
1451 * Context: Calling function should acquire ioc->raid_device_lock
1453 * This searches for raid_device based on handle, then return raid_device
1456 struct _raid_device *
1457 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1459 struct _raid_device *raid_device, *r;
1462 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1463 if (raid_device->handle != handle)
1474 * _scsih_raid_device_find_by_wwid - raid device search
1475 * @ioc: per adapter object
1477 * Context: Calling function should acquire ioc->raid_device_lock
1479 * This searches for raid_device based on wwid, then return raid_device
1482 static struct _raid_device *
1483 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
1485 struct _raid_device *raid_device, *r;
1488 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1489 if (raid_device->wwid != wwid)
1500 * _scsih_raid_device_add - add raid_device object
1501 * @ioc: per adapter object
1502 * @raid_device: raid_device object
1504 * This is added to the raid_device_list link list.
1507 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
1508 struct _raid_device *raid_device)
1510 unsigned long flags;
1513 ioc_info(ioc, "%s: handle(0x%04x), wwid(0x%016llx)\n",
1515 raid_device->handle, (u64)raid_device->wwid));
1517 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1518 list_add_tail(&raid_device->list, &ioc->raid_device_list);
1519 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1523 * _scsih_raid_device_remove - delete raid_device object
1524 * @ioc: per adapter object
1525 * @raid_device: raid_device object
1529 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
1530 struct _raid_device *raid_device)
1532 unsigned long flags;
1534 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1535 list_del(&raid_device->list);
1537 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1541 * mpt3sas_scsih_expander_find_by_handle - expander device search
1542 * @ioc: per adapter object
1543 * @handle: expander handle (assigned by firmware)
1544 * Context: Calling function should acquire ioc->sas_device_lock
1546 * This searches for expander device based on handle, then returns the
1550 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1552 struct _sas_node *sas_expander, *r;
1555 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1556 if (sas_expander->handle != handle)
1566 * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
1567 * @ioc: per adapter object
1568 * @handle: enclosure handle (assigned by firmware)
1569 * Context: Calling function should acquire ioc->sas_device_lock
1571 * This searches for enclosure device based on handle, then returns the
1574 static struct _enclosure_node *
1575 mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
1577 struct _enclosure_node *enclosure_dev, *r;
1580 list_for_each_entry(enclosure_dev, &ioc->enclosure_list, list) {
1581 if (le16_to_cpu(enclosure_dev->pg0.EnclosureHandle) != handle)
1590 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1591 * @ioc: per adapter object
1592 * @sas_address: sas address
1593 * @port: hba port entry
1594 * Context: Calling function should acquire ioc->sas_node_lock.
1596 * This searches for expander device based on sas_address & port number,
1597 * then returns the sas_node object.
1600 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1601 u64 sas_address, struct hba_port *port)
1603 struct _sas_node *sas_expander, *r = NULL;
1608 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1609 if (sas_expander->sas_address != sas_address)
1611 if (sas_expander->port != port)
1621 * _scsih_expander_node_add - insert expander device to the list.
1622 * @ioc: per adapter object
1623 * @sas_expander: the sas_device object
1624 * Context: This function will acquire ioc->sas_node_lock.
1626 * Adding new object to the ioc->sas_expander_list.
1629 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1630 struct _sas_node *sas_expander)
1632 unsigned long flags;
1634 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1635 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1636 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1640 * _scsih_is_end_device - determines if device is an end device
1641 * @device_info: bitfield providing information about the device.
1644 * Return: 1 if end device.
1647 _scsih_is_end_device(u32 device_info)
1649 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1650 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1651 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1652 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1659 * _scsih_is_nvme_pciescsi_device - determines if
1660 * device is an pcie nvme/scsi device
1661 * @device_info: bitfield providing information about the device.
1664 * Returns 1 if device is pcie device type nvme/scsi.
1667 _scsih_is_nvme_pciescsi_device(u32 device_info)
1669 if (((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE)
1670 == MPI26_PCIE_DEVINFO_NVME) ||
1671 ((device_info & MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE)
1672 == MPI26_PCIE_DEVINFO_SCSI))
1679 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1680 * @ioc: per adapter object
1683 * Context: This function will acquire ioc->scsi_lookup_lock.
1685 * This will search for a matching channel:id in the scsi_lookup array,
1686 * returning 1 if found.
1689 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1693 struct scsi_cmnd *scmd;
1696 smid <= ioc->shost->can_queue; smid++) {
1697 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
1700 if (scmd->device->id == id &&
1701 scmd->device->channel == channel)
1708 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1709 * @ioc: per adapter object
1713 * Context: This function will acquire ioc->scsi_lookup_lock.
1715 * This will search for a matching channel:id:lun in the scsi_lookup array,
1716 * returning 1 if found.
1719 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1720 unsigned int lun, int channel)
1723 struct scsi_cmnd *scmd;
1725 for (smid = 1; smid <= ioc->shost->can_queue; smid++) {
1727 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
1730 if (scmd->device->id == id &&
1731 scmd->device->channel == channel &&
1732 scmd->device->lun == lun)
1739 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1740 * @ioc: per adapter object
1741 * @smid: system request message index
1743 * Return: the smid stored scmd pointer.
1744 * Then will dereference the stored scmd pointer.
1747 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1749 struct scsi_cmnd *scmd = NULL;
1750 struct scsiio_tracker *st;
1751 Mpi25SCSIIORequest_t *mpi_request;
1755 smid <= ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT) {
1757 ioc->io_queue_num[tag] << BLK_MQ_UNIQUE_TAG_BITS | tag;
1759 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1762 * If SCSI IO request is outstanding at driver level then
1763 * DevHandle filed must be non-zero. If DevHandle is zero
1764 * then it means that this smid is free at driver level,
1767 if (!mpi_request->DevHandle)
1770 scmd = scsi_host_find_tag(ioc->shost, unique_tag);
1772 st = scsi_cmd_priv(scmd);
1773 if (st->cb_idx == 0xFF || st->smid == 0)
1781 * scsih_change_queue_depth - setting device queue depth
1782 * @sdev: scsi device struct
1783 * @qdepth: requested queue depth
1785 * Return: queue depth.
1788 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1790 struct Scsi_Host *shost = sdev->host;
1792 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1793 struct MPT3SAS_DEVICE *sas_device_priv_data;
1794 struct MPT3SAS_TARGET *sas_target_priv_data;
1795 struct _sas_device *sas_device;
1796 unsigned long flags;
1798 max_depth = shost->can_queue;
1801 * limit max device queue for SATA to 32 if enable_sdev_max_qd
1804 if (ioc->enable_sdev_max_qd || ioc->is_gen35_ioc)
1807 sas_device_priv_data = sdev->hostdata;
1808 if (!sas_device_priv_data)
1810 sas_target_priv_data = sas_device_priv_data->sas_target;
1811 if (!sas_target_priv_data)
1813 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1816 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1817 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1819 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1820 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1822 sas_device_put(sas_device);
1824 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1828 if (!sdev->tagged_supported)
1830 if (qdepth > max_depth)
1832 scsi_change_queue_depth(sdev, qdepth);
1833 sdev_printk(KERN_INFO, sdev,
1834 "qdepth(%d), tagged(%d), scsi_level(%d), cmd_que(%d)\n",
1835 sdev->queue_depth, sdev->tagged_supported,
1836 sdev->scsi_level, ((sdev->inquiry[7] & 2) >> 1));
1837 return sdev->queue_depth;
1841 * mpt3sas_scsih_change_queue_depth - setting device queue depth
1842 * @sdev: scsi device struct
1843 * @qdepth: requested queue depth
1848 mpt3sas_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1850 struct Scsi_Host *shost = sdev->host;
1851 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1853 if (ioc->enable_sdev_max_qd)
1854 qdepth = shost->can_queue;
1856 scsih_change_queue_depth(sdev, qdepth);
1860 * scsih_target_alloc - target add routine
1861 * @starget: scsi target struct
1863 * Return: 0 if ok. Any other return is assumed to be an error and
1864 * the device is ignored.
1867 scsih_target_alloc(struct scsi_target *starget)
1869 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1870 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1871 struct MPT3SAS_TARGET *sas_target_priv_data;
1872 struct _sas_device *sas_device;
1873 struct _raid_device *raid_device;
1874 struct _pcie_device *pcie_device;
1875 unsigned long flags;
1876 struct sas_rphy *rphy;
1878 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1880 if (!sas_target_priv_data)
1883 starget->hostdata = sas_target_priv_data;
1884 sas_target_priv_data->starget = starget;
1885 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1888 if (starget->channel == RAID_CHANNEL) {
1889 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1890 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1893 sas_target_priv_data->handle = raid_device->handle;
1894 sas_target_priv_data->sas_address = raid_device->wwid;
1895 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1896 if (ioc->is_warpdrive)
1897 sas_target_priv_data->raid_device = raid_device;
1898 raid_device->starget = starget;
1900 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1905 if (starget->channel == PCIE_CHANNEL) {
1906 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1907 pcie_device = __mpt3sas_get_pdev_by_idchannel(ioc, starget->id,
1910 sas_target_priv_data->handle = pcie_device->handle;
1911 sas_target_priv_data->sas_address = pcie_device->wwid;
1912 sas_target_priv_data->port = NULL;
1913 sas_target_priv_data->pcie_dev = pcie_device;
1914 pcie_device->starget = starget;
1915 pcie_device->id = starget->id;
1916 pcie_device->channel = starget->channel;
1917 sas_target_priv_data->flags |=
1918 MPT_TARGET_FLAGS_PCIE_DEVICE;
1919 if (pcie_device->fast_path)
1920 sas_target_priv_data->flags |=
1921 MPT_TARGET_FASTPATH_IO;
1923 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1927 /* sas/sata devices */
1928 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1929 rphy = dev_to_rphy(starget->dev.parent);
1930 sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy);
1933 sas_target_priv_data->handle = sas_device->handle;
1934 sas_target_priv_data->sas_address = sas_device->sas_address;
1935 sas_target_priv_data->port = sas_device->port;
1936 sas_target_priv_data->sas_dev = sas_device;
1937 sas_device->starget = starget;
1938 sas_device->id = starget->id;
1939 sas_device->channel = starget->channel;
1940 if (test_bit(sas_device->handle, ioc->pd_handles))
1941 sas_target_priv_data->flags |=
1942 MPT_TARGET_FLAGS_RAID_COMPONENT;
1943 if (sas_device->fast_path)
1944 sas_target_priv_data->flags |=
1945 MPT_TARGET_FASTPATH_IO;
1947 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1953 * scsih_target_destroy - target destroy routine
1954 * @starget: scsi target struct
1957 scsih_target_destroy(struct scsi_target *starget)
1959 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1960 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1961 struct MPT3SAS_TARGET *sas_target_priv_data;
1962 struct _sas_device *sas_device;
1963 struct _raid_device *raid_device;
1964 struct _pcie_device *pcie_device;
1965 unsigned long flags;
1967 sas_target_priv_data = starget->hostdata;
1968 if (!sas_target_priv_data)
1971 if (starget->channel == RAID_CHANNEL) {
1972 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1973 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1976 raid_device->starget = NULL;
1977 raid_device->sdev = NULL;
1979 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1983 if (starget->channel == PCIE_CHANNEL) {
1984 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1985 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
1986 sas_target_priv_data);
1987 if (pcie_device && (pcie_device->starget == starget) &&
1988 (pcie_device->id == starget->id) &&
1989 (pcie_device->channel == starget->channel))
1990 pcie_device->starget = NULL;
1994 * Corresponding get() is in _scsih_target_alloc()
1996 sas_target_priv_data->pcie_dev = NULL;
1997 pcie_device_put(pcie_device);
1998 pcie_device_put(pcie_device);
2000 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2004 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2005 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
2006 if (sas_device && (sas_device->starget == starget) &&
2007 (sas_device->id == starget->id) &&
2008 (sas_device->channel == starget->channel))
2009 sas_device->starget = NULL;
2013 * Corresponding get() is in _scsih_target_alloc()
2015 sas_target_priv_data->sas_dev = NULL;
2016 sas_device_put(sas_device);
2018 sas_device_put(sas_device);
2020 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2023 kfree(sas_target_priv_data);
2024 starget->hostdata = NULL;
2028 * scsih_sdev_init - device add routine
2029 * @sdev: scsi device struct
2031 * Return: 0 if ok. Any other return is assumed to be an error and
2032 * the device is ignored.
2035 scsih_sdev_init(struct scsi_device *sdev)
2037 struct Scsi_Host *shost;
2038 struct MPT3SAS_ADAPTER *ioc;
2039 struct MPT3SAS_TARGET *sas_target_priv_data;
2040 struct MPT3SAS_DEVICE *sas_device_priv_data;
2041 struct scsi_target *starget;
2042 struct _raid_device *raid_device;
2043 struct _sas_device *sas_device;
2044 struct _pcie_device *pcie_device;
2045 unsigned long flags;
2047 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
2049 if (!sas_device_priv_data)
2052 sas_device_priv_data->lun = sdev->lun;
2053 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
2055 starget = scsi_target(sdev);
2056 sas_target_priv_data = starget->hostdata;
2057 sas_target_priv_data->num_luns++;
2058 sas_device_priv_data->sas_target = sas_target_priv_data;
2059 sdev->hostdata = sas_device_priv_data;
2060 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
2061 sdev->no_uld_attach = 1;
2063 shost = dev_to_shost(&starget->dev);
2064 ioc = shost_priv(shost);
2065 if (starget->channel == RAID_CHANNEL) {
2066 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2067 raid_device = _scsih_raid_device_find_by_id(ioc,
2068 starget->id, starget->channel);
2070 raid_device->sdev = sdev; /* raid is single lun */
2071 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2073 if (starget->channel == PCIE_CHANNEL) {
2074 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2075 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
2076 sas_target_priv_data->sas_address);
2077 if (pcie_device && (pcie_device->starget == NULL)) {
2078 sdev_printk(KERN_INFO, sdev,
2079 "%s : pcie_device->starget set to starget @ %d\n",
2080 __func__, __LINE__);
2081 pcie_device->starget = starget;
2085 pcie_device_put(pcie_device);
2086 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2088 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
2089 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2090 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
2091 sas_target_priv_data->sas_address,
2092 sas_target_priv_data->port);
2093 if (sas_device && (sas_device->starget == NULL)) {
2094 sdev_printk(KERN_INFO, sdev,
2095 "%s : sas_device->starget set to starget @ %d\n",
2096 __func__, __LINE__);
2097 sas_device->starget = starget;
2101 sas_device_put(sas_device);
2103 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2110 * scsih_sdev_destroy - device destroy routine
2111 * @sdev: scsi device struct
2114 scsih_sdev_destroy(struct scsi_device *sdev)
2116 struct MPT3SAS_TARGET *sas_target_priv_data;
2117 struct scsi_target *starget;
2118 struct Scsi_Host *shost;
2119 struct MPT3SAS_ADAPTER *ioc;
2120 struct _sas_device *sas_device;
2121 struct _pcie_device *pcie_device;
2122 unsigned long flags;
2124 if (!sdev->hostdata)
2127 starget = scsi_target(sdev);
2128 sas_target_priv_data = starget->hostdata;
2129 sas_target_priv_data->num_luns--;
2131 shost = dev_to_shost(&starget->dev);
2132 ioc = shost_priv(shost);
2134 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2135 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2136 pcie_device = __mpt3sas_get_pdev_from_target(ioc,
2137 sas_target_priv_data);
2138 if (pcie_device && !sas_target_priv_data->num_luns)
2139 pcie_device->starget = NULL;
2142 pcie_device_put(pcie_device);
2144 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2146 } else if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
2147 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2148 sas_device = __mpt3sas_get_sdev_from_target(ioc,
2149 sas_target_priv_data);
2150 if (sas_device && !sas_target_priv_data->num_luns)
2151 sas_device->starget = NULL;
2154 sas_device_put(sas_device);
2155 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2158 kfree(sdev->hostdata);
2159 sdev->hostdata = NULL;
2163 * _scsih_display_sata_capabilities - sata capabilities
2164 * @ioc: per adapter object
2165 * @handle: device handle
2166 * @sdev: scsi device struct
2169 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
2170 u16 handle, struct scsi_device *sdev)
2172 Mpi2ConfigReply_t mpi_reply;
2173 Mpi2SasDevicePage0_t sas_device_pg0;
2178 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
2179 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
2180 ioc_err(ioc, "failure at %s:%d/%s()!\n",
2181 __FILE__, __LINE__, __func__);
2185 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2186 MPI2_IOCSTATUS_MASK;
2187 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2188 ioc_err(ioc, "failure at %s:%d/%s()!\n",
2189 __FILE__, __LINE__, __func__);
2193 flags = le16_to_cpu(sas_device_pg0.Flags);
2194 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
2196 sdev_printk(KERN_INFO, sdev,
2197 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
2198 "sw_preserve(%s)\n",
2199 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
2200 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
2201 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
2203 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
2204 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
2205 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
2209 * raid transport support -
2210 * Enabled for SLES11 and newer, in older kernels the driver will panic when
2211 * unloading the driver followed by a load - I believe that the subroutine
2212 * raid_class_release() is not cleaning up properly.
2216 * scsih_is_raid - return boolean indicating device is raid volume
2217 * @dev: the device struct object
2220 scsih_is_raid(struct device *dev)
2222 struct scsi_device *sdev = to_scsi_device(dev);
2223 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
2225 if (ioc->is_warpdrive)
2227 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
2231 scsih_is_nvme(struct device *dev)
2233 struct scsi_device *sdev = to_scsi_device(dev);
2235 return (sdev->channel == PCIE_CHANNEL) ? 1 : 0;
2239 * scsih_get_resync - get raid volume resync percent complete
2240 * @dev: the device struct object
2243 scsih_get_resync(struct device *dev)
2245 struct scsi_device *sdev = to_scsi_device(dev);
2246 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
2247 static struct _raid_device *raid_device;
2248 unsigned long flags;
2249 Mpi2RaidVolPage0_t vol_pg0;
2250 Mpi2ConfigReply_t mpi_reply;
2251 u32 volume_status_flags;
2252 u8 percent_complete;
2255 percent_complete = 0;
2257 if (ioc->is_warpdrive)
2260 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2261 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
2264 handle = raid_device->handle;
2265 percent_complete = raid_device->percent_complete;
2267 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2272 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
2273 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
2274 sizeof(Mpi2RaidVolPage0_t))) {
2275 ioc_err(ioc, "failure at %s:%d/%s()!\n",
2276 __FILE__, __LINE__, __func__);
2277 percent_complete = 0;
2281 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
2282 if (!(volume_status_flags &
2283 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
2284 percent_complete = 0;
2288 switch (ioc->hba_mpi_version_belonged) {
2290 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
2294 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
2300 * scsih_get_state - get raid volume level
2301 * @dev: the device struct object
2304 scsih_get_state(struct device *dev)
2306 struct scsi_device *sdev = to_scsi_device(dev);
2307 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
2308 static struct _raid_device *raid_device;
2309 unsigned long flags;
2310 Mpi2RaidVolPage0_t vol_pg0;
2311 Mpi2ConfigReply_t mpi_reply;
2313 enum raid_state state = RAID_STATE_UNKNOWN;
2316 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2317 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
2320 handle = raid_device->handle;
2321 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2326 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
2327 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
2328 sizeof(Mpi2RaidVolPage0_t))) {
2329 ioc_err(ioc, "failure at %s:%d/%s()!\n",
2330 __FILE__, __LINE__, __func__);
2334 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
2335 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
2336 state = RAID_STATE_RESYNCING;
2340 switch (vol_pg0.VolumeState) {
2341 case MPI2_RAID_VOL_STATE_OPTIMAL:
2342 case MPI2_RAID_VOL_STATE_ONLINE:
2343 state = RAID_STATE_ACTIVE;
2345 case MPI2_RAID_VOL_STATE_DEGRADED:
2346 state = RAID_STATE_DEGRADED;
2348 case MPI2_RAID_VOL_STATE_FAILED:
2349 case MPI2_RAID_VOL_STATE_MISSING:
2350 state = RAID_STATE_OFFLINE;
2354 switch (ioc->hba_mpi_version_belonged) {
2356 raid_set_state(mpt2sas_raid_template, dev, state);
2360 raid_set_state(mpt3sas_raid_template, dev, state);
2366 * _scsih_set_level - set raid level
2368 * @sdev: scsi device struct
2369 * @volume_type: volume type
2372 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
2373 struct scsi_device *sdev, u8 volume_type)
2375 enum raid_level level = RAID_LEVEL_UNKNOWN;
2377 switch (volume_type) {
2378 case MPI2_RAID_VOL_TYPE_RAID0:
2379 level = RAID_LEVEL_0;
2381 case MPI2_RAID_VOL_TYPE_RAID10:
2382 level = RAID_LEVEL_10;
2384 case MPI2_RAID_VOL_TYPE_RAID1E:
2385 level = RAID_LEVEL_1E;
2387 case MPI2_RAID_VOL_TYPE_RAID1:
2388 level = RAID_LEVEL_1;
2392 switch (ioc->hba_mpi_version_belonged) {
2394 raid_set_level(mpt2sas_raid_template,
2395 &sdev->sdev_gendev, level);
2399 raid_set_level(mpt3sas_raid_template,
2400 &sdev->sdev_gendev, level);
2407 * _scsih_get_volume_capabilities - volume capabilities
2408 * @ioc: per adapter object
2409 * @raid_device: the raid_device object
2411 * Return: 0 for success, else 1
2414 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
2415 struct _raid_device *raid_device)
2417 Mpi2RaidVolPage0_t *vol_pg0;
2418 Mpi2RaidPhysDiskPage0_t pd_pg0;
2419 Mpi2SasDevicePage0_t sas_device_pg0;
2420 Mpi2ConfigReply_t mpi_reply;
2424 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
2425 &num_pds)) || !num_pds) {
2427 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2428 __FILE__, __LINE__, __func__));
2432 raid_device->num_pds = num_pds;
2433 sz = struct_size(vol_pg0, PhysDisk, num_pds);
2434 vol_pg0 = kzalloc(sz, GFP_KERNEL);
2437 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2438 __FILE__, __LINE__, __func__));
2442 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
2443 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
2445 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2446 __FILE__, __LINE__, __func__));
2451 raid_device->volume_type = vol_pg0->VolumeType;
2453 /* figure out what the underlying devices are by
2454 * obtaining the device_info bits for the 1st device
2456 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
2457 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
2458 vol_pg0->PhysDisk[0].PhysDiskNum))) {
2459 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
2460 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
2461 le16_to_cpu(pd_pg0.DevHandle)))) {
2462 raid_device->device_info =
2463 le32_to_cpu(sas_device_pg0.DeviceInfo);
2472 * _scsih_enable_tlr - setting TLR flags
2473 * @ioc: per adapter object
2474 * @sdev: scsi device struct
2476 * Enabling Transaction Layer Retries for tape devices when
2477 * vpd page 0x90 is present
2481 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
2485 if (sdev->type != TYPE_TAPE)
2488 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2491 sas_enable_tlr(sdev);
2492 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2493 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2499 * scsih_sdev_configure - device configure routine.
2500 * @sdev: scsi device struct
2501 * @lim: queue limits
2503 * Return: 0 if ok. Any other return is assumed to be an error and
2504 * the device is ignored.
2507 scsih_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim)
2509 struct Scsi_Host *shost = sdev->host;
2510 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2511 struct MPT3SAS_DEVICE *sas_device_priv_data;
2512 struct MPT3SAS_TARGET *sas_target_priv_data;
2513 struct _sas_device *sas_device;
2514 struct _pcie_device *pcie_device;
2515 struct _raid_device *raid_device;
2516 unsigned long flags;
2521 u16 handle, volume_handle = 0;
2522 u64 volume_wwid = 0;
2525 sas_device_priv_data = sdev->hostdata;
2526 sas_device_priv_data->configured_lun = 1;
2527 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2528 sas_target_priv_data = sas_device_priv_data->sas_target;
2529 handle = sas_target_priv_data->handle;
2531 /* raid volume handling */
2532 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2534 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2535 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
2536 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2539 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2540 __FILE__, __LINE__, __func__));
2544 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2546 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2547 __FILE__, __LINE__, __func__));
2552 * WARPDRIVE: Initialize the required data for Direct IO
2554 mpt3sas_init_warpdrive_properties(ioc, raid_device);
2556 /* RAID Queue Depth Support
2557 * IS volume = underlying qdepth of drive type, either
2558 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2559 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2561 if (raid_device->device_info &
2562 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2563 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
2566 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
2567 if (raid_device->device_info &
2568 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2574 switch (raid_device->volume_type) {
2575 case MPI2_RAID_VOL_TYPE_RAID0:
2578 case MPI2_RAID_VOL_TYPE_RAID1E:
2579 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2580 if (ioc->manu_pg10.OEMIdentifier &&
2581 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2582 MFG10_GF0_R10_DISPLAY) &&
2583 !(raid_device->num_pds % 2))
2588 case MPI2_RAID_VOL_TYPE_RAID1:
2589 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2592 case MPI2_RAID_VOL_TYPE_RAID10:
2593 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2596 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2598 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
2603 if (!ioc->hide_ir_msg)
2604 sdev_printk(KERN_INFO, sdev,
2605 "%s: handle(0x%04x), wwid(0x%016llx),"
2606 " pd_count(%d), type(%s)\n",
2607 r_level, raid_device->handle,
2608 (unsigned long long)raid_device->wwid,
2609 raid_device->num_pds, ds);
2611 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
2612 lim->max_hw_sectors = MPT3SAS_RAID_MAX_SECTORS;
2613 sdev_printk(KERN_INFO, sdev,
2614 "Set queue's max_sector to: %u\n",
2615 MPT3SAS_RAID_MAX_SECTORS);
2618 mpt3sas_scsih_change_queue_depth(sdev, qdepth);
2620 /* raid transport support */
2621 if (!ioc->is_warpdrive)
2622 _scsih_set_level(ioc, sdev, raid_device->volume_type);
2626 /* non-raid handling */
2627 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2628 if (mpt3sas_config_get_volume_handle(ioc, handle,
2631 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2632 __FILE__, __LINE__, __func__));
2635 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
2636 volume_handle, &volume_wwid)) {
2638 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2639 __FILE__, __LINE__, __func__));
2645 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
2646 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
2647 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc,
2648 sas_device_priv_data->sas_target->sas_address);
2650 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2652 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2653 __FILE__, __LINE__, __func__));
2657 qdepth = ioc->max_nvme_qd;
2659 sdev_printk(KERN_INFO, sdev,
2660 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2661 ds, handle, (unsigned long long)pcie_device->wwid,
2662 pcie_device->port_num);
2663 if (pcie_device->enclosure_handle != 0)
2664 sdev_printk(KERN_INFO, sdev,
2665 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2667 (unsigned long long)pcie_device->enclosure_logical_id,
2669 if (pcie_device->connector_name[0] != '\0')
2670 sdev_printk(KERN_INFO, sdev,
2671 "%s: enclosure level(0x%04x),"
2672 "connector name( %s)\n", ds,
2673 pcie_device->enclosure_level,
2674 pcie_device->connector_name);
2676 if (pcie_device->nvme_mdts)
2677 lim->max_hw_sectors = pcie_device->nvme_mdts / 512;
2679 pcie_device_put(pcie_device);
2680 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
2681 mpt3sas_scsih_change_queue_depth(sdev, qdepth);
2682 lim->virt_boundary_mask = ioc->page_size - 1;
2686 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2687 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
2688 sas_device_priv_data->sas_target->sas_address,
2689 sas_device_priv_data->sas_target->port);
2691 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2693 ioc_warn(ioc, "failure at %s:%d/%s()!\n",
2694 __FILE__, __LINE__, __func__));
2698 sas_device->volume_handle = volume_handle;
2699 sas_device->volume_wwid = volume_wwid;
2700 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2701 qdepth = (sas_device->port_type > 1) ?
2702 ioc->max_wideport_qd : ioc->max_narrowport_qd;
2704 if (sas_device->device_info &
2705 MPI2_SAS_DEVICE_INFO_SEP) {
2706 sdev_printk(KERN_WARNING, sdev,
2707 "set ignore_delay_remove for handle(0x%04x)\n",
2708 sas_device_priv_data->sas_target->handle);
2709 sas_device_priv_data->ignore_delay_remove = 1;
2714 qdepth = ioc->max_sata_qd;
2715 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2717 else if (sas_device->device_info &
2718 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2722 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
2723 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2724 ds, handle, (unsigned long long)sas_device->sas_address,
2725 sas_device->phy, (unsigned long long)sas_device->device_name);
2727 _scsih_display_enclosure_chassis_info(NULL, sas_device, sdev, NULL);
2729 sas_device_put(sas_device);
2730 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2733 _scsih_display_sata_capabilities(ioc, handle, sdev);
2736 mpt3sas_scsih_change_queue_depth(sdev, qdepth);
2739 sas_read_port_mode_page(sdev);
2740 _scsih_enable_tlr(ioc, sdev);
2747 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2748 * @sdev: scsi device struct
2749 * @bdev: pointer to block device context
2750 * @capacity: device size (in 512 byte sectors)
2751 * @params: three element array to place output:
2752 * params[0] number of heads (max 255)
2753 * params[1] number of sectors (max 63)
2754 * params[2] number of cylinders
2757 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2758 sector_t capacity, int params[])
2768 dummy = heads * sectors;
2769 cylinders = capacity;
2770 sector_div(cylinders, dummy);
2773 * Handle extended translation size for logical drives
2776 if ((ulong)capacity >= 0x200000) {
2779 dummy = heads * sectors;
2780 cylinders = capacity;
2781 sector_div(cylinders, dummy);
2786 params[1] = sectors;
2787 params[2] = cylinders;
2793 * _scsih_response_code - translation of device response code
2794 * @ioc: per adapter object
2795 * @response_code: response code returned by the device
2798 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2802 switch (response_code) {
2803 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2804 desc = "task management request completed";
2806 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2807 desc = "invalid frame";
2809 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2810 desc = "task management request not supported";
2812 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2813 desc = "task management request failed";
2815 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2816 desc = "task management request succeeded";
2818 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2819 desc = "invalid lun";
2822 desc = "overlapped tag attempted";
2824 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2825 desc = "task queued, however not sent to target";
2831 ioc_warn(ioc, "response_code(0x%01x): %s\n", response_code, desc);
2835 * _scsih_tm_done - tm completion routine
2836 * @ioc: per adapter object
2837 * @smid: system request message index
2838 * @msix_index: MSIX table index supplied by the OS
2839 * @reply: reply message frame(lower 32bit addr)
2842 * The callback handler when using scsih_issue_tm.
2844 * Return: 1 meaning mf should be freed from _base_interrupt
2845 * 0 means the mf is freed from this function.
2848 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2850 MPI2DefaultReply_t *mpi_reply;
2852 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2854 if (ioc->tm_cmds.smid != smid)
2856 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2857 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2859 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2860 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2862 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2863 complete(&ioc->tm_cmds.done);
2868 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2869 * @ioc: per adapter object
2870 * @handle: device handle
2872 * During taskmangement request, we need to freeze the device queue.
2875 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2877 struct MPT3SAS_DEVICE *sas_device_priv_data;
2878 struct scsi_device *sdev;
2881 shost_for_each_device(sdev, ioc->shost) {
2884 sas_device_priv_data = sdev->hostdata;
2885 if (!sas_device_priv_data)
2887 if (sas_device_priv_data->sas_target->handle == handle) {
2888 sas_device_priv_data->sas_target->tm_busy = 1;
2890 ioc->ignore_loginfos = 1;
2896 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2897 * @ioc: per adapter object
2898 * @handle: device handle
2900 * During taskmangement request, we need to freeze the device queue.
2903 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2905 struct MPT3SAS_DEVICE *sas_device_priv_data;
2906 struct scsi_device *sdev;
2909 shost_for_each_device(sdev, ioc->shost) {
2912 sas_device_priv_data = sdev->hostdata;
2913 if (!sas_device_priv_data)
2915 if (sas_device_priv_data->sas_target->handle == handle) {
2916 sas_device_priv_data->sas_target->tm_busy = 0;
2918 ioc->ignore_loginfos = 0;
2924 * scsih_tm_cmd_map_status - map the target reset & LUN reset TM status
2925 * @ioc: per adapter object
2926 * @channel: the channel assigned by the OS
2927 * @id: the id assigned by the OS
2929 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2930 * @smid_task: smid assigned to the task
2932 * Look whether TM has aborted the timed out SCSI command, if
2933 * TM has aborted the IO then return SUCCESS else return FAILED.
2936 scsih_tm_cmd_map_status(struct MPT3SAS_ADAPTER *ioc, uint channel,
2937 uint id, uint lun, u8 type, u16 smid_task)
2940 if (smid_task <= ioc->shost->can_queue) {
2942 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2943 if (!(_scsih_scsi_lookup_find_by_target(ioc,
2947 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2948 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2949 if (!(_scsih_scsi_lookup_find_by_lun(ioc, id,
2956 } else if (smid_task == ioc->scsih_cmds.smid) {
2957 if ((ioc->scsih_cmds.status & MPT3_CMD_COMPLETE) ||
2958 (ioc->scsih_cmds.status & MPT3_CMD_NOT_USED))
2960 } else if (smid_task == ioc->ctl_cmds.smid) {
2961 if ((ioc->ctl_cmds.status & MPT3_CMD_COMPLETE) ||
2962 (ioc->ctl_cmds.status & MPT3_CMD_NOT_USED))
2970 * scsih_tm_post_processing - post processing of target & LUN reset
2971 * @ioc: per adapter object
2972 * @handle: device handle
2973 * @channel: the channel assigned by the OS
2974 * @id: the id assigned by the OS
2976 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2977 * @smid_task: smid assigned to the task
2979 * Post processing of target & LUN reset. Due to interrupt latency
2980 * issue it possible that interrupt for aborted IO might not be
2981 * received yet. So before returning failure status, poll the
2982 * reply descriptor pools for the reply of timed out SCSI command.
2983 * Return FAILED status if reply for timed out is not received
2984 * otherwise return SUCCESS.
2987 scsih_tm_post_processing(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2988 uint channel, uint id, uint lun, u8 type, u16 smid_task)
2992 rc = scsih_tm_cmd_map_status(ioc, channel, id, lun, type, smid_task);
2997 "Poll ReplyDescriptor queues for completion of"
2998 " smid(%d), task_type(0x%02x), handle(0x%04x)\n",
2999 smid_task, type, handle);
3002 * Due to interrupt latency issues, driver may receive interrupt for
3003 * TM first and then for aborted SCSI IO command. So, poll all the
3004 * ReplyDescriptor pools before returning the FAILED status to SML.
3006 mpt3sas_base_mask_interrupts(ioc);
3007 mpt3sas_base_sync_reply_irqs(ioc, 1);
3008 mpt3sas_base_unmask_interrupts(ioc);
3010 return scsih_tm_cmd_map_status(ioc, channel, id, lun, type, smid_task);
3014 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
3015 * @ioc: per adapter struct
3016 * @handle: device handle
3017 * @channel: the channel assigned by the OS
3018 * @id: the id assigned by the OS
3020 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
3021 * @smid_task: smid assigned to the task
3022 * @msix_task: MSIX table index supplied by the OS
3023 * @timeout: timeout in seconds
3024 * @tr_method: Target Reset Method
3027 * A generic API for sending task management requests to firmware.
3029 * The callback index is set inside `ioc->tm_cb_idx`.
3030 * The caller is responsible to check for outstanding commands.
3032 * Return: SUCCESS or FAILED.
3035 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
3036 uint id, u64 lun, u8 type, u16 smid_task, u16 msix_task,
3037 u8 timeout, u8 tr_method)
3039 Mpi2SCSITaskManagementRequest_t *mpi_request;
3040 Mpi2SCSITaskManagementReply_t *mpi_reply;
3041 Mpi25SCSIIORequest_t *request;
3047 lockdep_assert_held(&ioc->tm_cmds.mutex);
3049 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
3050 ioc_info(ioc, "%s: tm_cmd busy!!!\n", __func__);
3054 if (ioc->shost_recovery || ioc->remove_host ||
3055 ioc->pci_error_recovery) {
3056 ioc_info(ioc, "%s: host reset in progress!\n", __func__);
3060 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
3061 if (ioc_state & MPI2_DOORBELL_USED) {
3062 dhsprintk(ioc, ioc_info(ioc, "unexpected doorbell active!\n"));
3063 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3064 return (!rc) ? SUCCESS : FAILED;
3067 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
3068 mpt3sas_print_fault_code(ioc, ioc_state &
3069 MPI2_DOORBELL_DATA_MASK);
3070 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3071 return (!rc) ? SUCCESS : FAILED;
3072 } else if ((ioc_state & MPI2_IOC_STATE_MASK) ==
3073 MPI2_IOC_STATE_COREDUMP) {
3074 mpt3sas_print_coredump_info(ioc, ioc_state &
3075 MPI2_DOORBELL_DATA_MASK);
3076 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3077 return (!rc) ? SUCCESS : FAILED;
3080 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
3082 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
3087 ioc_info(ioc, "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
3088 handle, type, smid_task, timeout, tr_method));
3089 ioc->tm_cmds.status = MPT3_CMD_PENDING;
3090 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3091 ioc->tm_cmds.smid = smid;
3092 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3093 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
3094 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3095 mpi_request->DevHandle = cpu_to_le16(handle);
3096 mpi_request->TaskType = type;
3097 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
3098 type == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
3099 mpi_request->MsgFlags = tr_method;
3100 mpi_request->TaskMID = cpu_to_le16(smid_task);
3101 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
3102 mpt3sas_scsih_set_tm_flag(ioc, handle);
3103 init_completion(&ioc->tm_cmds.done);
3104 ioc->put_smid_hi_priority(ioc, smid, msix_task);
3105 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
3106 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
3107 mpt3sas_check_cmd_timeout(ioc,
3108 ioc->tm_cmds.status, mpi_request,
3109 sizeof(Mpi2SCSITaskManagementRequest_t)/4, issue_reset);
3111 rc = mpt3sas_base_hard_reset_handler(ioc,
3113 rc = (!rc) ? SUCCESS : FAILED;
3118 /* sync IRQs in case those were busy during flush. */
3119 mpt3sas_base_sync_reply_irqs(ioc, 0);
3121 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
3122 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3123 mpi_reply = ioc->tm_cmds.reply;
3125 ioc_info(ioc, "complete tm: ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
3126 le16_to_cpu(mpi_reply->IOCStatus),
3127 le32_to_cpu(mpi_reply->IOCLogInfo),
3128 le32_to_cpu(mpi_reply->TerminationCount)));
3129 if (ioc->logging_level & MPT_DEBUG_TM) {
3130 _scsih_response_code(ioc, mpi_reply->ResponseCode);
3131 if (mpi_reply->IOCStatus)
3132 _debug_dump_mf(mpi_request,
3133 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
3138 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
3141 * If DevHandle filed in smid_task's entry of request pool
3142 * doesn't match with device handle on which this task abort
3143 * TM is received then it means that TM has successfully
3144 * aborted the timed out command. Since smid_task's entry in
3145 * request pool will be memset to zero once the timed out
3146 * command is returned to the SML. If the command is not
3147 * aborted then smid_task’s entry won’t be cleared and it
3148 * will have same DevHandle value on which this task abort TM
3149 * is received and driver will return the TM status as FAILED.
3151 request = mpt3sas_base_get_msg_frame(ioc, smid_task);
3152 if (le16_to_cpu(request->DevHandle) != handle)
3155 ioc_info(ioc, "Task abort tm failed: handle(0x%04x),"
3156 "timeout(%d) tr_method(0x%x) smid(%d) msix_index(%d)\n",
3157 handle, timeout, tr_method, smid_task, msix_task);
3161 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
3162 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
3163 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
3164 rc = scsih_tm_post_processing(ioc, handle, channel, id, lun,
3167 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
3176 mpt3sas_scsih_clear_tm_flag(ioc, handle);
3177 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
3181 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
3182 uint channel, uint id, u64 lun, u8 type, u16 smid_task,
3183 u16 msix_task, u8 timeout, u8 tr_method)
3187 mutex_lock(&ioc->tm_cmds.mutex);
3188 ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type,
3189 smid_task, msix_task, timeout, tr_method);
3190 mutex_unlock(&ioc->tm_cmds.mutex);
3196 * _scsih_tm_display_info - displays info about the device
3197 * @ioc: per adapter struct
3198 * @scmd: pointer to scsi command object
3200 * Called by task management callback handlers.
3203 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
3205 struct scsi_target *starget = scmd->device->sdev_target;
3206 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
3207 struct _sas_device *sas_device = NULL;
3208 struct _pcie_device *pcie_device = NULL;
3209 unsigned long flags;
3210 char *device_str = NULL;
3214 if (ioc->hide_ir_msg)
3215 device_str = "WarpDrive";
3217 device_str = "volume";
3219 scsi_print_command(scmd);
3220 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3221 starget_printk(KERN_INFO, starget,
3222 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
3223 device_str, priv_target->handle,
3224 device_str, (unsigned long long)priv_target->sas_address);
3226 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
3227 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
3228 pcie_device = __mpt3sas_get_pdev_from_target(ioc, priv_target);
3230 starget_printk(KERN_INFO, starget,
3231 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
3232 pcie_device->handle,
3233 (unsigned long long)pcie_device->wwid,
3234 pcie_device->port_num);
3235 if (pcie_device->enclosure_handle != 0)
3236 starget_printk(KERN_INFO, starget,
3237 "enclosure logical id(0x%016llx), slot(%d)\n",
3238 (unsigned long long)
3239 pcie_device->enclosure_logical_id,
3241 if (pcie_device->connector_name[0] != '\0')
3242 starget_printk(KERN_INFO, starget,
3243 "enclosure level(0x%04x), connector name( %s)\n",
3244 pcie_device->enclosure_level,
3245 pcie_device->connector_name);
3246 pcie_device_put(pcie_device);
3248 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
3251 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3252 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
3254 if (priv_target->flags &
3255 MPT_TARGET_FLAGS_RAID_COMPONENT) {
3256 starget_printk(KERN_INFO, starget,
3257 "volume handle(0x%04x), "
3258 "volume wwid(0x%016llx)\n",
3259 sas_device->volume_handle,
3260 (unsigned long long)sas_device->volume_wwid);
3262 starget_printk(KERN_INFO, starget,
3263 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
3265 (unsigned long long)sas_device->sas_address,
3268 _scsih_display_enclosure_chassis_info(NULL, sas_device,
3271 sas_device_put(sas_device);
3273 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3278 * scsih_abort - eh threads main abort routine
3279 * @scmd: pointer to scsi command object
3281 * Return: SUCCESS if command aborted else FAILED
3284 scsih_abort(struct scsi_cmnd *scmd)
3286 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3287 struct MPT3SAS_DEVICE *sas_device_priv_data;
3288 struct scsiio_tracker *st = scsi_cmd_priv(scmd);
3293 struct _pcie_device *pcie_device = NULL;
3294 sdev_printk(KERN_INFO, scmd->device, "attempting task abort!"
3295 "scmd(0x%p), outstanding for %u ms & timeout %u ms\n",
3296 scmd, jiffies_to_msecs(jiffies - scmd->jiffies_at_alloc),
3297 (scsi_cmd_to_rq(scmd)->timeout / HZ) * 1000);
3298 _scsih_tm_display_info(ioc, scmd);
3300 sas_device_priv_data = scmd->device->hostdata;
3301 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
3303 sdev_printk(KERN_INFO, scmd->device,
3304 "device been deleted! scmd(0x%p)\n", scmd);
3305 scmd->result = DID_NO_CONNECT << 16;
3311 /* check for completed command */
3312 if (st == NULL || st->cb_idx == 0xFF) {
3313 sdev_printk(KERN_INFO, scmd->device, "No reference found at "
3314 "driver, assuming scmd(0x%p) might have completed\n", scmd);
3315 scmd->result = DID_RESET << 16;
3320 /* for hidden raid components and volumes this is not supported */
3321 if (sas_device_priv_data->sas_target->flags &
3322 MPT_TARGET_FLAGS_RAID_COMPONENT ||
3323 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
3324 scmd->result = DID_RESET << 16;
3329 mpt3sas_halt_firmware(ioc);
3331 handle = sas_device_priv_data->sas_target->handle;
3332 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
3333 if (pcie_device && (!ioc->tm_custom_handling) &&
3334 (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info))))
3335 timeout = ioc->nvme_abort_timeout;
3336 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
3337 scmd->device->id, scmd->device->lun,
3338 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
3339 st->smid, st->msix_io, timeout, 0);
3340 /* Command must be cleared after abort */
3341 if (r == SUCCESS && st->cb_idx != 0xFF)
3344 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(0x%p)\n",
3345 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3347 pcie_device_put(pcie_device);
3352 * scsih_dev_reset - eh threads main device reset routine
3353 * @scmd: pointer to scsi command object
3355 * Return: SUCCESS if command aborted else FAILED
3358 scsih_dev_reset(struct scsi_cmnd *scmd)
3360 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3361 struct MPT3SAS_DEVICE *sas_device_priv_data;
3362 struct _sas_device *sas_device = NULL;
3363 struct _pcie_device *pcie_device = NULL;
3369 struct scsi_target *starget = scmd->device->sdev_target;
3370 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
3372 sdev_printk(KERN_INFO, scmd->device,
3373 "attempting device reset! scmd(0x%p)\n", scmd);
3374 _scsih_tm_display_info(ioc, scmd);
3376 sas_device_priv_data = scmd->device->hostdata;
3377 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
3379 sdev_printk(KERN_INFO, scmd->device,
3380 "device been deleted! scmd(0x%p)\n", scmd);
3381 scmd->result = DID_NO_CONNECT << 16;
3387 /* for hidden raid components obtain the volume_handle */
3389 if (sas_device_priv_data->sas_target->flags &
3390 MPT_TARGET_FLAGS_RAID_COMPONENT) {
3391 sas_device = mpt3sas_get_sdev_from_target(ioc,
3394 handle = sas_device->volume_handle;
3396 handle = sas_device_priv_data->sas_target->handle;
3399 scmd->result = DID_RESET << 16;
3404 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
3406 if (pcie_device && (!ioc->tm_custom_handling) &&
3407 (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) {
3408 tr_timeout = pcie_device->reset_timeout;
3409 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3411 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3413 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
3414 scmd->device->id, scmd->device->lun,
3415 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 0,
3416 tr_timeout, tr_method);
3417 /* Check for busy commands after reset */
3418 if (r == SUCCESS && scsi_device_busy(scmd->device))
3421 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(0x%p)\n",
3422 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3425 sas_device_put(sas_device);
3427 pcie_device_put(pcie_device);
3433 * scsih_target_reset - eh threads main target reset routine
3434 * @scmd: pointer to scsi command object
3436 * Return: SUCCESS if command aborted else FAILED
3439 scsih_target_reset(struct scsi_cmnd *scmd)
3441 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3442 struct MPT3SAS_DEVICE *sas_device_priv_data;
3443 struct _sas_device *sas_device = NULL;
3444 struct _pcie_device *pcie_device = NULL;
3449 struct scsi_target *starget = scmd->device->sdev_target;
3450 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
3452 starget_printk(KERN_INFO, starget,
3453 "attempting target reset! scmd(0x%p)\n", scmd);
3454 _scsih_tm_display_info(ioc, scmd);
3456 sas_device_priv_data = scmd->device->hostdata;
3457 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
3459 starget_printk(KERN_INFO, starget,
3460 "target been deleted! scmd(0x%p)\n", scmd);
3461 scmd->result = DID_NO_CONNECT << 16;
3467 /* for hidden raid components obtain the volume_handle */
3469 if (sas_device_priv_data->sas_target->flags &
3470 MPT_TARGET_FLAGS_RAID_COMPONENT) {
3471 sas_device = mpt3sas_get_sdev_from_target(ioc,
3474 handle = sas_device->volume_handle;
3476 handle = sas_device_priv_data->sas_target->handle;
3479 scmd->result = DID_RESET << 16;
3484 pcie_device = mpt3sas_get_pdev_by_handle(ioc, handle);
3486 if (pcie_device && (!ioc->tm_custom_handling) &&
3487 (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device->device_info)))) {
3488 tr_timeout = pcie_device->reset_timeout;
3489 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
3491 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
3492 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
3493 scmd->device->id, 0,
3494 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 0,
3495 tr_timeout, tr_method);
3496 /* Check for busy commands after reset */
3497 if (r == SUCCESS && atomic_read(&starget->target_busy))
3500 starget_printk(KERN_INFO, starget, "target reset: %s scmd(0x%p)\n",
3501 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
3504 sas_device_put(sas_device);
3506 pcie_device_put(pcie_device);
3512 * scsih_host_reset - eh threads main host reset routine
3513 * @scmd: pointer to scsi command object
3515 * Return: SUCCESS if command aborted else FAILED
3518 scsih_host_reset(struct scsi_cmnd *scmd)
3520 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3523 ioc_info(ioc, "attempting host reset! scmd(0x%p)\n", scmd);
3524 scsi_print_command(scmd);
3526 if (ioc->is_driver_loading || ioc->remove_host) {
3527 ioc_info(ioc, "Blocking the host reset\n");
3532 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
3533 r = (retval < 0) ? FAILED : SUCCESS;
3535 ioc_info(ioc, "host reset: %s scmd(0x%p)\n",
3536 r == SUCCESS ? "SUCCESS" : "FAILED", scmd);
3542 * _scsih_fw_event_add - insert and queue up fw_event
3543 * @ioc: per adapter object
3544 * @fw_event: object describing the event
3545 * Context: This function will acquire ioc->fw_event_lock.
3547 * This adds the firmware event object into link list, then queues it up to
3548 * be processed from user context.
3551 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
3553 unsigned long flags;
3555 if (ioc->firmware_event_thread == NULL)
3558 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3559 fw_event_work_get(fw_event);
3560 INIT_LIST_HEAD(&fw_event->list);
3561 list_add_tail(&fw_event->list, &ioc->fw_event_list);
3562 INIT_WORK(&fw_event->work, _firmware_event_work);
3563 fw_event_work_get(fw_event);
3564 queue_work(ioc->firmware_event_thread, &fw_event->work);
3565 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3569 * _scsih_fw_event_del_from_list - delete fw_event from the list
3570 * @ioc: per adapter object
3571 * @fw_event: object describing the event
3572 * Context: This function will acquire ioc->fw_event_lock.
3574 * If the fw_event is on the fw_event_list, remove it and do a put.
3577 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
3580 unsigned long flags;
3582 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3583 if (!list_empty(&fw_event->list)) {
3584 list_del_init(&fw_event->list);
3585 fw_event_work_put(fw_event);
3587 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3592 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3593 * @ioc: per adapter object
3594 * @event_data: trigger event data
3597 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
3598 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
3600 struct fw_event_work *fw_event;
3603 if (ioc->is_driver_loading)
3605 sz = sizeof(*event_data);
3606 fw_event = alloc_fw_event_work(sz);
3609 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
3610 fw_event->ioc = ioc;
3611 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
3612 _scsih_fw_event_add(ioc, fw_event);
3613 fw_event_work_put(fw_event);
3617 * _scsih_error_recovery_delete_devices - remove devices not responding
3618 * @ioc: per adapter object
3621 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
3623 struct fw_event_work *fw_event;
3625 fw_event = alloc_fw_event_work(0);
3628 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
3629 fw_event->ioc = ioc;
3630 _scsih_fw_event_add(ioc, fw_event);
3631 fw_event_work_put(fw_event);
3635 * mpt3sas_port_enable_complete - port enable completed (fake event)
3636 * @ioc: per adapter object
3639 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
3641 struct fw_event_work *fw_event;
3643 fw_event = alloc_fw_event_work(0);
3646 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
3647 fw_event->ioc = ioc;
3648 _scsih_fw_event_add(ioc, fw_event);
3649 fw_event_work_put(fw_event);
3652 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
3654 unsigned long flags;
3655 struct fw_event_work *fw_event = NULL;
3657 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3658 if (!list_empty(&ioc->fw_event_list)) {
3659 fw_event = list_first_entry(&ioc->fw_event_list,
3660 struct fw_event_work, list);
3661 list_del_init(&fw_event->list);
3662 fw_event_work_put(fw_event);
3664 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3670 * _scsih_fw_event_cleanup_queue - cleanup event queue
3671 * @ioc: per adapter object
3673 * Walk the firmware event queue, either killing timers, or waiting
3674 * for outstanding events to complete
3676 * Context: task, can sleep
3679 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
3681 struct fw_event_work *fw_event;
3683 if ((list_empty(&ioc->fw_event_list) && !ioc->current_event) ||
3684 !ioc->firmware_event_thread)
3687 * Set current running event as ignore, so that
3688 * current running event will exit quickly.
3689 * As diag reset has occurred it is of no use
3690 * to process remaining stale event data entries.
3692 if (ioc->shost_recovery && ioc->current_event)
3693 ioc->current_event->ignore = 1;
3695 ioc->fw_events_cleanup = 1;
3696 while ((fw_event = dequeue_next_fw_event(ioc)) ||
3697 (fw_event = ioc->current_event)) {
3700 * Don't call cancel_work_sync() for current_event
3701 * other than MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
3702 * otherwise we may observe deadlock if current
3703 * hard reset issued as part of processing the current_event.
3705 * Orginal logic of cleaning the current_event is added
3706 * for handling the back to back host reset issued by the user.
3707 * i.e. during back to back host reset, driver use to process
3708 * the two instances of MPT3SAS_REMOVE_UNRESPONDING_DEVICES
3709 * event back to back and this made the drives to unregister
3710 * the devices from SML.
3713 if (fw_event == ioc->current_event &&
3714 ioc->current_event->event !=
3715 MPT3SAS_REMOVE_UNRESPONDING_DEVICES) {
3716 ioc->current_event = NULL;
3721 * Driver has to clear ioc->start_scan flag when
3722 * it is cleaning up MPT3SAS_PORT_ENABLE_COMPLETE,
3723 * otherwise scsi_scan_host() API waits for the
3724 * 5 minute timer to expire. If we exit from
3725 * scsi_scan_host() early then we can issue the
3726 * new port enable request as part of current diag reset.
3728 if (fw_event->event == MPT3SAS_PORT_ENABLE_COMPLETE) {
3729 ioc->port_enable_cmds.status |= MPT3_CMD_RESET;
3730 ioc->start_scan = 0;
3734 * Wait on the fw_event to complete. If this returns 1, then
3735 * the event was never executed, and we need a put for the
3736 * reference the work had on the fw_event.
3738 * If it did execute, we wait for it to finish, and the put will
3739 * happen from _firmware_event_work()
3741 if (cancel_work_sync(&fw_event->work))
3742 fw_event_work_put(fw_event);
3745 ioc->fw_events_cleanup = 0;
3749 * _scsih_internal_device_block - block the sdev device
3750 * @sdev: per device object
3751 * @sas_device_priv_data : per device driver private data
3753 * make sure device is blocked without error, if not
3757 _scsih_internal_device_block(struct scsi_device *sdev,
3758 struct MPT3SAS_DEVICE *sas_device_priv_data)
3762 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
3763 sas_device_priv_data->sas_target->handle);
3764 sas_device_priv_data->block = 1;
3766 r = scsi_internal_device_block_nowait(sdev);
3768 sdev_printk(KERN_WARNING, sdev,
3769 "device_block failed with return(%d) for handle(0x%04x)\n",
3770 r, sas_device_priv_data->sas_target->handle);
3774 * _scsih_internal_device_unblock - unblock the sdev device
3775 * @sdev: per device object
3776 * @sas_device_priv_data : per device driver private data
3777 * make sure device is unblocked without error, if not retry
3778 * by blocking and then unblocking
3782 _scsih_internal_device_unblock(struct scsi_device *sdev,
3783 struct MPT3SAS_DEVICE *sas_device_priv_data)
3787 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
3788 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
3789 sas_device_priv_data->block = 0;
3790 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3792 /* The device has been set to SDEV_RUNNING by SD layer during
3793 * device addition but the request queue is still stopped by
3794 * our earlier block call. We need to perform a block again
3795 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3797 sdev_printk(KERN_WARNING, sdev,
3798 "device_unblock failed with return(%d) for handle(0x%04x) "
3799 "performing a block followed by an unblock\n",
3800 r, sas_device_priv_data->sas_target->handle);
3801 sas_device_priv_data->block = 1;
3802 r = scsi_internal_device_block_nowait(sdev);
3804 sdev_printk(KERN_WARNING, sdev, "retried device_block "
3805 "failed with return(%d) for handle(0x%04x)\n",
3806 r, sas_device_priv_data->sas_target->handle);
3808 sas_device_priv_data->block = 0;
3809 r = scsi_internal_device_unblock_nowait(sdev, SDEV_RUNNING);
3811 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
3812 " failed with return(%d) for handle(0x%04x)\n",
3813 r, sas_device_priv_data->sas_target->handle);
3818 * _scsih_ublock_io_all_device - unblock every device
3819 * @ioc: per adapter object
3821 * change the device state from block to running
3824 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3826 struct MPT3SAS_DEVICE *sas_device_priv_data;
3827 struct scsi_device *sdev;
3829 shost_for_each_device(sdev, ioc->shost) {
3830 sas_device_priv_data = sdev->hostdata;
3831 if (!sas_device_priv_data)
3833 if (!sas_device_priv_data->block)
3836 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3837 "device_running, handle(0x%04x)\n",
3838 sas_device_priv_data->sas_target->handle));
3839 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
3845 * _scsih_ublock_io_device - prepare device to be deleted
3846 * @ioc: per adapter object
3847 * @sas_address: sas address
3848 * @port: hba port entry
3850 * unblock then put device in offline state
3853 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc,
3854 u64 sas_address, struct hba_port *port)
3856 struct MPT3SAS_DEVICE *sas_device_priv_data;
3857 struct scsi_device *sdev;
3859 shost_for_each_device(sdev, ioc->shost) {
3860 sas_device_priv_data = sdev->hostdata;
3861 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
3863 if (sas_device_priv_data->sas_target->sas_address
3866 if (sas_device_priv_data->sas_target->port != port)
3868 if (sas_device_priv_data->block)
3869 _scsih_internal_device_unblock(sdev,
3870 sas_device_priv_data);
3875 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3876 * @ioc: per adapter object
3878 * During device pull we need to appropriately set the sdev state.
3881 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
3883 struct MPT3SAS_DEVICE *sas_device_priv_data;
3884 struct scsi_device *sdev;
3886 shost_for_each_device(sdev, ioc->shost) {
3887 sas_device_priv_data = sdev->hostdata;
3888 if (!sas_device_priv_data)
3890 if (sas_device_priv_data->block)
3892 if (sas_device_priv_data->ignore_delay_remove) {
3893 sdev_printk(KERN_INFO, sdev,
3894 "%s skip device_block for SES handle(0x%04x)\n",
3895 __func__, sas_device_priv_data->sas_target->handle);
3898 _scsih_internal_device_block(sdev, sas_device_priv_data);
3903 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3904 * @ioc: per adapter object
3905 * @handle: device handle
3907 * During device pull we need to appropriately set the sdev state.
3910 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3912 struct MPT3SAS_DEVICE *sas_device_priv_data;
3913 struct scsi_device *sdev;
3914 struct _sas_device *sas_device;
3916 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
3918 shost_for_each_device(sdev, ioc->shost) {
3919 sas_device_priv_data = sdev->hostdata;
3920 if (!sas_device_priv_data)
3922 if (sas_device_priv_data->sas_target->handle != handle)
3924 if (sas_device_priv_data->block)
3926 if (sas_device && sas_device->pend_sas_rphy_add)
3928 if (sas_device_priv_data->ignore_delay_remove) {
3929 sdev_printk(KERN_INFO, sdev,
3930 "%s skip device_block for SES handle(0x%04x)\n",
3931 __func__, sas_device_priv_data->sas_target->handle);
3934 _scsih_internal_device_block(sdev, sas_device_priv_data);
3938 sas_device_put(sas_device);
3942 * _scsih_block_io_to_children_attached_to_ex
3943 * @ioc: per adapter object
3944 * @sas_expander: the sas_device object
3946 * This routine set sdev state to SDEV_BLOCK for all devices
3947 * attached to this expander. This function called when expander is
3951 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3952 struct _sas_node *sas_expander)
3954 struct _sas_port *mpt3sas_port;
3955 struct _sas_device *sas_device;
3956 struct _sas_node *expander_sibling;
3957 unsigned long flags;
3962 list_for_each_entry(mpt3sas_port,
3963 &sas_expander->sas_port_list, port_list) {
3964 if (mpt3sas_port->remote_identify.device_type ==
3966 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3967 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3968 mpt3sas_port->remote_identify.sas_address,
3969 mpt3sas_port->hba_port);
3971 set_bit(sas_device->handle,
3972 ioc->blocking_handles);
3973 sas_device_put(sas_device);
3975 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3979 list_for_each_entry(mpt3sas_port,
3980 &sas_expander->sas_port_list, port_list) {
3982 if (mpt3sas_port->remote_identify.device_type ==
3983 SAS_EDGE_EXPANDER_DEVICE ||
3984 mpt3sas_port->remote_identify.device_type ==
3985 SAS_FANOUT_EXPANDER_DEVICE) {
3987 mpt3sas_scsih_expander_find_by_sas_address(
3988 ioc, mpt3sas_port->remote_identify.sas_address,
3989 mpt3sas_port->hba_port);
3990 _scsih_block_io_to_children_attached_to_ex(ioc,
3997 * _scsih_block_io_to_children_attached_directly
3998 * @ioc: per adapter object
3999 * @event_data: topology change event data
4001 * This routine set sdev state to SDEV_BLOCK for all devices
4002 * direct attached during device pull.
4005 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
4006 Mpi2EventDataSasTopologyChangeList_t *event_data)
4012 for (i = 0; i < event_data->NumEntries; i++) {
4013 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4016 reason_code = event_data->PHY[i].PhyStatus &
4017 MPI2_EVENT_SAS_TOPO_RC_MASK;
4018 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
4019 _scsih_block_io_device(ioc, handle);
4024 * _scsih_block_io_to_pcie_children_attached_directly
4025 * @ioc: per adapter object
4026 * @event_data: topology change event data
4028 * This routine set sdev state to SDEV_BLOCK for all devices
4029 * direct attached during device pull/reconnect.
4032 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
4033 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
4039 for (i = 0; i < event_data->NumEntries; i++) {
4041 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
4044 reason_code = event_data->PortEntry[i].PortStatus;
4046 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING)
4047 _scsih_block_io_device(ioc, handle);
4051 * _scsih_tm_tr_send - send task management request
4052 * @ioc: per adapter object
4053 * @handle: device handle
4054 * Context: interrupt time.
4056 * This code is to initiate the device removal handshake protocol
4057 * with controller firmware. This function will issue target reset
4058 * using high priority request queue. It will send a sas iounit
4059 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
4061 * This is designed to send muliple task management request at the same
4062 * time to the fifo. If the fifo is full, we will append the request,
4063 * and process it in a future completion.
4066 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4068 Mpi2SCSITaskManagementRequest_t *mpi_request;
4070 struct _sas_device *sas_device = NULL;
4071 struct _pcie_device *pcie_device = NULL;
4072 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
4073 u64 sas_address = 0;
4074 unsigned long flags;
4075 struct _tr_list *delayed_tr;
4078 struct hba_port *port = NULL;
4080 if (ioc->pci_error_recovery) {
4082 ioc_info(ioc, "%s: host in pci error recovery: handle(0x%04x)\n",
4086 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
4087 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
4089 ioc_info(ioc, "%s: host is not operational: handle(0x%04x)\n",
4094 /* if PD, then return */
4095 if (test_bit(handle, ioc->pd_handles))
4098 clear_bit(handle, ioc->pend_os_device_add);
4100 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4101 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4102 if (sas_device && sas_device->starget &&
4103 sas_device->starget->hostdata) {
4104 sas_target_priv_data = sas_device->starget->hostdata;
4105 sas_target_priv_data->deleted = 1;
4106 sas_address = sas_device->sas_address;
4107 port = sas_device->port;
4109 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4111 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
4112 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
4113 if (pcie_device && pcie_device->starget &&
4114 pcie_device->starget->hostdata) {
4115 sas_target_priv_data = pcie_device->starget->hostdata;
4116 sas_target_priv_data->deleted = 1;
4117 sas_address = pcie_device->wwid;
4119 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
4120 if (pcie_device && (!ioc->tm_custom_handling) &&
4121 (!(mpt3sas_scsih_is_pcie_scsi_device(
4122 pcie_device->device_info))))
4124 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
4126 tr_method = MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET;
4128 if (sas_target_priv_data) {
4130 ioc_info(ioc, "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
4131 handle, (u64)sas_address));
4133 if (sas_device->enclosure_handle != 0)
4135 ioc_info(ioc, "setting delete flag:enclosure logical id(0x%016llx), slot(%d)\n",
4136 (u64)sas_device->enclosure_logical_id,
4138 if (sas_device->connector_name[0] != '\0')
4140 ioc_info(ioc, "setting delete flag: enclosure level(0x%04x), connector name( %s)\n",
4141 sas_device->enclosure_level,
4142 sas_device->connector_name));
4143 } else if (pcie_device) {
4144 if (pcie_device->enclosure_handle != 0)
4146 ioc_info(ioc, "setting delete flag: logical id(0x%016llx), slot(%d)\n",
4147 (u64)pcie_device->enclosure_logical_id,
4148 pcie_device->slot));
4149 if (pcie_device->connector_name[0] != '\0')
4151 ioc_info(ioc, "setting delete flag:, enclosure level(0x%04x), connector name( %s)\n",
4152 pcie_device->enclosure_level,
4153 pcie_device->connector_name));
4155 _scsih_ublock_io_device(ioc, sas_address, port);
4156 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
4159 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
4161 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
4164 INIT_LIST_HEAD(&delayed_tr->list);
4165 delayed_tr->handle = handle;
4166 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
4168 ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n",
4174 ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4175 handle, smid, ioc->tm_tr_cb_idx));
4176 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4177 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
4178 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
4179 mpi_request->DevHandle = cpu_to_le16(handle);
4180 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
4181 mpi_request->MsgFlags = tr_method;
4182 set_bit(handle, ioc->device_remove_in_progress);
4183 ioc->put_smid_hi_priority(ioc, smid, 0);
4184 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
4188 sas_device_put(sas_device);
4190 pcie_device_put(pcie_device);
4194 * _scsih_tm_tr_complete -
4195 * @ioc: per adapter object
4196 * @smid: system request message index
4197 * @msix_index: MSIX table index supplied by the OS
4198 * @reply: reply message frame(lower 32bit addr)
4199 * Context: interrupt time.
4201 * This is the target reset completion routine.
4202 * This code is part of the code to initiate the device removal
4203 * handshake protocol with controller firmware.
4204 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
4206 * Return: 1 meaning mf should be freed from _base_interrupt
4207 * 0 means the mf is freed from this function.
4210 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
4214 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
4215 Mpi2SCSITaskManagementReply_t *mpi_reply =
4216 mpt3sas_base_get_reply_virt_addr(ioc, reply);
4217 Mpi2SasIoUnitControlRequest_t *mpi_request;
4220 struct _sc_list *delayed_sc;
4222 if (ioc->pci_error_recovery) {
4224 ioc_info(ioc, "%s: host in pci error recovery\n",
4228 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
4229 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
4231 ioc_info(ioc, "%s: host is not operational\n",
4235 if (unlikely(!mpi_reply)) {
4236 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
4237 __FILE__, __LINE__, __func__);
4240 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
4241 handle = le16_to_cpu(mpi_request_tm->DevHandle);
4242 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
4244 ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
4246 le16_to_cpu(mpi_reply->DevHandle), smid));
4250 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
4252 ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
4253 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
4254 le32_to_cpu(mpi_reply->IOCLogInfo),
4255 le32_to_cpu(mpi_reply->TerminationCount)));
4257 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
4258 if (!smid_sas_ctrl) {
4259 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
4261 return _scsih_check_for_pending_tm(ioc, smid);
4262 INIT_LIST_HEAD(&delayed_sc->list);
4263 delayed_sc->handle = le16_to_cpu(mpi_request_tm->DevHandle);
4264 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
4266 ioc_info(ioc, "DELAYED:sc:handle(0x%04x), (open)\n",
4268 return _scsih_check_for_pending_tm(ioc, smid);
4272 ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4273 handle, smid_sas_ctrl, ioc->tm_sas_control_cb_idx));
4274 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
4275 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
4276 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
4277 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
4278 mpi_request->DevHandle = mpi_request_tm->DevHandle;
4279 ioc->put_smid_default(ioc, smid_sas_ctrl);
4281 return _scsih_check_for_pending_tm(ioc, smid);
4284 /** _scsih_allow_scmd_to_device - check whether scmd needs to
4285 * issue to IOC or not.
4286 * @ioc: per adapter object
4287 * @scmd: pointer to scsi command object
4289 * Returns true if scmd can be issued to IOC otherwise returns false.
4291 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc,
4292 struct scsi_cmnd *scmd)
4295 if (ioc->pci_error_recovery)
4298 if (ioc->hba_mpi_version_belonged == MPI2_VERSION) {
4299 if (ioc->remove_host)
4305 if (ioc->remove_host) {
4307 switch (scmd->cmnd[0]) {
4308 case SYNCHRONIZE_CACHE:
4320 * _scsih_sas_control_complete - completion routine
4321 * @ioc: per adapter object
4322 * @smid: system request message index
4323 * @msix_index: MSIX table index supplied by the OS
4324 * @reply: reply message frame(lower 32bit addr)
4325 * Context: interrupt time.
4327 * This is the sas iounit control completion routine.
4328 * This code is part of the code to initiate the device removal
4329 * handshake protocol with controller firmware.
4331 * Return: 1 meaning mf should be freed from _base_interrupt
4332 * 0 means the mf is freed from this function.
4335 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
4336 u8 msix_index, u32 reply)
4338 Mpi2SasIoUnitControlReply_t *mpi_reply =
4339 mpt3sas_base_get_reply_virt_addr(ioc, reply);
4341 if (likely(mpi_reply)) {
4343 ioc_info(ioc, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
4344 le16_to_cpu(mpi_reply->DevHandle), smid,
4345 le16_to_cpu(mpi_reply->IOCStatus),
4346 le32_to_cpu(mpi_reply->IOCLogInfo)));
4347 if (le16_to_cpu(mpi_reply->IOCStatus) ==
4348 MPI2_IOCSTATUS_SUCCESS) {
4349 clear_bit(le16_to_cpu(mpi_reply->DevHandle),
4350 ioc->device_remove_in_progress);
4353 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
4354 __FILE__, __LINE__, __func__);
4356 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
4360 * _scsih_tm_tr_volume_send - send target reset request for volumes
4361 * @ioc: per adapter object
4362 * @handle: device handle
4363 * Context: interrupt time.
4365 * This is designed to send muliple task management request at the same
4366 * time to the fifo. If the fifo is full, we will append the request,
4367 * and process it in a future completion.
4370 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4372 Mpi2SCSITaskManagementRequest_t *mpi_request;
4374 struct _tr_list *delayed_tr;
4376 if (ioc->pci_error_recovery) {
4378 ioc_info(ioc, "%s: host reset in progress!\n",
4383 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
4385 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
4388 INIT_LIST_HEAD(&delayed_tr->list);
4389 delayed_tr->handle = handle;
4390 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
4392 ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n",
4398 ioc_info(ioc, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4399 handle, smid, ioc->tm_tr_volume_cb_idx));
4400 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4401 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
4402 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
4403 mpi_request->DevHandle = cpu_to_le16(handle);
4404 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
4405 ioc->put_smid_hi_priority(ioc, smid, 0);
4409 * _scsih_tm_volume_tr_complete - target reset completion
4410 * @ioc: per adapter object
4411 * @smid: system request message index
4412 * @msix_index: MSIX table index supplied by the OS
4413 * @reply: reply message frame(lower 32bit addr)
4414 * Context: interrupt time.
4416 * Return: 1 meaning mf should be freed from _base_interrupt
4417 * 0 means the mf is freed from this function.
4420 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
4421 u8 msix_index, u32 reply)
4424 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
4425 Mpi2SCSITaskManagementReply_t *mpi_reply =
4426 mpt3sas_base_get_reply_virt_addr(ioc, reply);
4428 if (ioc->shost_recovery || ioc->pci_error_recovery) {
4430 ioc_info(ioc, "%s: host reset in progress!\n",
4434 if (unlikely(!mpi_reply)) {
4435 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
4436 __FILE__, __LINE__, __func__);
4440 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
4441 handle = le16_to_cpu(mpi_request_tm->DevHandle);
4442 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
4444 ioc_err(ioc, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
4445 handle, le16_to_cpu(mpi_reply->DevHandle),
4451 ioc_info(ioc, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
4452 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
4453 le32_to_cpu(mpi_reply->IOCLogInfo),
4454 le32_to_cpu(mpi_reply->TerminationCount)));
4456 return _scsih_check_for_pending_tm(ioc, smid);
4460 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
4461 * @ioc: per adapter object
4462 * @smid: system request message index
4464 * @event_context: used to track events uniquely
4466 * Context - processed in interrupt context.
4469 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, U16 event,
4472 Mpi2EventAckRequest_t *ack_request;
4473 int i = smid - ioc->internal_smid;
4474 unsigned long flags;
4476 /* Without releasing the smid just update the
4477 * call back index and reuse the same smid for
4478 * processing this delayed request
4480 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4481 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
4482 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4485 ioc_info(ioc, "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
4486 le16_to_cpu(event), smid, ioc->base_cb_idx));
4487 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
4488 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
4489 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
4490 ack_request->Event = event;
4491 ack_request->EventContext = event_context;
4492 ack_request->VF_ID = 0; /* TODO */
4493 ack_request->VP_ID = 0;
4494 ioc->put_smid_default(ioc, smid);
4498 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
4499 * sas_io_unit_ctrl messages
4500 * @ioc: per adapter object
4501 * @smid: system request message index
4502 * @handle: device handle
4504 * Context - processed in interrupt context.
4507 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
4508 u16 smid, u16 handle)
4510 Mpi2SasIoUnitControlRequest_t *mpi_request;
4512 int i = smid - ioc->internal_smid;
4513 unsigned long flags;
4515 if (ioc->remove_host) {
4517 ioc_info(ioc, "%s: host has been removed\n",
4520 } else if (ioc->pci_error_recovery) {
4522 ioc_info(ioc, "%s: host in pci error recovery\n",
4526 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
4527 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
4529 ioc_info(ioc, "%s: host is not operational\n",
4534 /* Without releasing the smid just update the
4535 * call back index and reuse the same smid for
4536 * processing this delayed request
4538 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4539 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
4540 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4543 ioc_info(ioc, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4544 handle, smid, ioc->tm_sas_control_cb_idx));
4545 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4546 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
4547 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
4548 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
4549 mpi_request->DevHandle = cpu_to_le16(handle);
4550 ioc->put_smid_default(ioc, smid);
4554 * mpt3sas_check_for_pending_internal_cmds - check for pending internal messages
4555 * @ioc: per adapter object
4556 * @smid: system request message index
4558 * Context: Executed in interrupt context
4560 * This will check delayed internal messages list, and process the
4563 * Return: 1 meaning mf should be freed from _base_interrupt
4564 * 0 means the mf is freed from this function.
4567 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4569 struct _sc_list *delayed_sc;
4570 struct _event_ack_list *delayed_event_ack;
4572 if (!list_empty(&ioc->delayed_event_ack_list)) {
4573 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
4574 struct _event_ack_list, list);
4575 _scsih_issue_delayed_event_ack(ioc, smid,
4576 delayed_event_ack->Event, delayed_event_ack->EventContext);
4577 list_del(&delayed_event_ack->list);
4578 kfree(delayed_event_ack);
4582 if (!list_empty(&ioc->delayed_sc_list)) {
4583 delayed_sc = list_entry(ioc->delayed_sc_list.next,
4584 struct _sc_list, list);
4585 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
4586 delayed_sc->handle);
4587 list_del(&delayed_sc->list);
4595 * _scsih_check_for_pending_tm - check for pending task management
4596 * @ioc: per adapter object
4597 * @smid: system request message index
4599 * This will check delayed target reset list, and feed the
4602 * Return: 1 meaning mf should be freed from _base_interrupt
4603 * 0 means the mf is freed from this function.
4606 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
4608 struct _tr_list *delayed_tr;
4610 if (!list_empty(&ioc->delayed_tr_volume_list)) {
4611 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
4612 struct _tr_list, list);
4613 mpt3sas_base_free_smid(ioc, smid);
4614 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
4615 list_del(&delayed_tr->list);
4620 if (!list_empty(&ioc->delayed_tr_list)) {
4621 delayed_tr = list_entry(ioc->delayed_tr_list.next,
4622 struct _tr_list, list);
4623 mpt3sas_base_free_smid(ioc, smid);
4624 _scsih_tm_tr_send(ioc, delayed_tr->handle);
4625 list_del(&delayed_tr->list);
4634 * _scsih_check_topo_delete_events - sanity check on topo events
4635 * @ioc: per adapter object
4636 * @event_data: the event data payload
4638 * This routine added to better handle cable breaker.
4640 * This handles the case where driver receives multiple expander
4641 * add and delete events in a single shot. When there is a delete event
4642 * the routine will void any pending add events waiting in the event queue.
4645 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
4646 Mpi2EventDataSasTopologyChangeList_t *event_data)
4648 struct fw_event_work *fw_event;
4649 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
4650 u16 expander_handle;
4651 struct _sas_node *sas_expander;
4652 unsigned long flags;
4656 for (i = 0 ; i < event_data->NumEntries; i++) {
4657 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4660 reason_code = event_data->PHY[i].PhyStatus &
4661 MPI2_EVENT_SAS_TOPO_RC_MASK;
4662 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
4663 _scsih_tm_tr_send(ioc, handle);
4666 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
4667 if (expander_handle < ioc->sas_hba.num_phys) {
4668 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4671 if (event_data->ExpStatus ==
4672 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
4673 /* put expander attached devices into blocking state */
4674 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4675 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
4677 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
4678 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4680 handle = find_first_bit(ioc->blocking_handles,
4681 ioc->facts.MaxDevHandle);
4682 if (handle < ioc->facts.MaxDevHandle)
4683 _scsih_block_io_device(ioc, handle);
4684 } while (test_and_clear_bit(handle, ioc->blocking_handles));
4685 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
4686 _scsih_block_io_to_children_attached_directly(ioc, event_data);
4688 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4691 /* mark ignore flag for pending events */
4692 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4693 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4694 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
4697 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
4698 fw_event->event_data;
4699 if (local_event_data->ExpStatus ==
4700 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4701 local_event_data->ExpStatus ==
4702 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4703 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
4706 ioc_info(ioc, "setting ignoring flag\n"));
4707 fw_event->ignore = 1;
4711 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4715 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4717 * @ioc: per adapter object
4718 * @event_data: the event data payload
4720 * This handles the case where driver receives multiple switch
4721 * or device add and delete events in a single shot. When there
4722 * is a delete event the routine will void any pending add
4723 * events waiting in the event queue.
4726 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER *ioc,
4727 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
4729 struct fw_event_work *fw_event;
4730 Mpi26EventDataPCIeTopologyChangeList_t *local_event_data;
4731 unsigned long flags;
4733 u16 handle, switch_handle;
4735 for (i = 0; i < event_data->NumEntries; i++) {
4737 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
4740 reason_code = event_data->PortEntry[i].PortStatus;
4741 if (reason_code == MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING)
4742 _scsih_tm_tr_send(ioc, handle);
4745 switch_handle = le16_to_cpu(event_data->SwitchDevHandle);
4746 if (!switch_handle) {
4747 _scsih_block_io_to_pcie_children_attached_directly(
4751 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4752 if ((event_data->SwitchStatus
4753 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING) ||
4754 (event_data->SwitchStatus ==
4755 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING))
4756 _scsih_block_io_to_pcie_children_attached_directly(
4759 if (event_data->SwitchStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4762 /* mark ignore flag for pending events */
4763 spin_lock_irqsave(&ioc->fw_event_lock, flags);
4764 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
4765 if (fw_event->event != MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST ||
4769 (Mpi26EventDataPCIeTopologyChangeList_t *)
4770 fw_event->event_data;
4771 if (local_event_data->SwitchStatus ==
4772 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
4773 local_event_data->SwitchStatus ==
4774 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
4775 if (le16_to_cpu(local_event_data->SwitchDevHandle) ==
4778 ioc_info(ioc, "setting ignoring flag for switch event\n"));
4779 fw_event->ignore = 1;
4783 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
4787 * _scsih_set_volume_delete_flag - setting volume delete flag
4788 * @ioc: per adapter object
4789 * @handle: device handle
4791 * This returns nothing.
4794 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4796 struct _raid_device *raid_device;
4797 struct MPT3SAS_TARGET *sas_target_priv_data;
4798 unsigned long flags;
4800 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4801 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
4802 if (raid_device && raid_device->starget &&
4803 raid_device->starget->hostdata) {
4804 sas_target_priv_data =
4805 raid_device->starget->hostdata;
4806 sas_target_priv_data->deleted = 1;
4808 ioc_info(ioc, "setting delete flag: handle(0x%04x), wwid(0x%016llx)\n",
4809 handle, (u64)raid_device->wwid));
4811 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4815 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4816 * @handle: input handle
4817 * @a: handle for volume a
4818 * @b: handle for volume b
4820 * IR firmware only supports two raid volumes. The purpose of this
4821 * routine is to set the volume handle in either a or b. When the given
4822 * input handle is non-zero, or when a and b have not been set before.
4825 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
4827 if (!handle || handle == *a || handle == *b)
4836 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4837 * @ioc: per adapter object
4838 * @event_data: the event data payload
4839 * Context: interrupt time.
4841 * This routine will send target reset to volume, followed by target
4842 * resets to the PDs. This is called when a PD has been removed, or
4843 * volume has been deleted or removed. When the target reset is sent
4844 * to volume, the PD target resets need to be queued to start upon
4845 * completion of the volume target reset.
4848 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
4849 Mpi2EventDataIrConfigChangeList_t *event_data)
4851 Mpi2EventIrConfigElement_t *element;
4853 u16 handle, volume_handle, a, b;
4854 struct _tr_list *delayed_tr;
4859 if (ioc->is_warpdrive)
4862 /* Volume Resets for Deleted or Removed */
4863 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4864 for (i = 0; i < event_data->NumElements; i++, element++) {
4865 if (le32_to_cpu(event_data->Flags) &
4866 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4868 if (element->ReasonCode ==
4869 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
4870 element->ReasonCode ==
4871 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
4872 volume_handle = le16_to_cpu(element->VolDevHandle);
4873 _scsih_set_volume_delete_flag(ioc, volume_handle);
4874 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4878 /* Volume Resets for UNHIDE events */
4879 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4880 for (i = 0; i < event_data->NumElements; i++, element++) {
4881 if (le32_to_cpu(event_data->Flags) &
4882 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
4884 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
4885 volume_handle = le16_to_cpu(element->VolDevHandle);
4886 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
4891 _scsih_tm_tr_volume_send(ioc, a);
4893 _scsih_tm_tr_volume_send(ioc, b);
4895 /* PD target resets */
4896 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4897 for (i = 0; i < event_data->NumElements; i++, element++) {
4898 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
4900 handle = le16_to_cpu(element->PhysDiskDevHandle);
4901 volume_handle = le16_to_cpu(element->VolDevHandle);
4902 clear_bit(handle, ioc->pd_handles);
4904 _scsih_tm_tr_send(ioc, handle);
4905 else if (volume_handle == a || volume_handle == b) {
4906 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
4907 BUG_ON(!delayed_tr);
4908 INIT_LIST_HEAD(&delayed_tr->list);
4909 delayed_tr->handle = handle;
4910 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
4912 ioc_info(ioc, "DELAYED:tr:handle(0x%04x), (open)\n",
4915 _scsih_tm_tr_send(ioc, handle);
4921 * _scsih_check_volume_delete_events - set delete flag for volumes
4922 * @ioc: per adapter object
4923 * @event_data: the event data payload
4924 * Context: interrupt time.
4926 * This will handle the case when the cable connected to entire volume is
4927 * pulled. We will take care of setting the deleted flag so normal IO will
4931 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
4932 Mpi2EventDataIrVolume_t *event_data)
4936 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4938 state = le32_to_cpu(event_data->NewValue);
4939 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
4940 MPI2_RAID_VOL_STATE_FAILED)
4941 _scsih_set_volume_delete_flag(ioc,
4942 le16_to_cpu(event_data->VolDevHandle));
4946 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4947 * @ioc: per adapter object
4948 * @event_data: the temp threshold event data
4949 * Context: interrupt time.
4952 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
4953 Mpi2EventDataTemperature_t *event_data)
4956 if (ioc->temp_sensors_count >= event_data->SensorNum) {
4957 ioc_err(ioc, "Temperature Threshold flags %s%s%s%s exceeded for Sensor: %d !!!\n",
4958 le16_to_cpu(event_data->Status) & 0x1 ? "0 " : " ",
4959 le16_to_cpu(event_data->Status) & 0x2 ? "1 " : " ",
4960 le16_to_cpu(event_data->Status) & 0x4 ? "2 " : " ",
4961 le16_to_cpu(event_data->Status) & 0x8 ? "3 " : " ",
4962 event_data->SensorNum);
4963 ioc_err(ioc, "Current Temp In Celsius: %d\n",
4964 event_data->CurrentTemperature);
4965 if (ioc->hba_mpi_version_belonged != MPI2_VERSION) {
4966 doorbell = mpt3sas_base_get_iocstate(ioc, 0);
4967 if ((doorbell & MPI2_IOC_STATE_MASK) ==
4968 MPI2_IOC_STATE_FAULT) {
4969 mpt3sas_print_fault_code(ioc,
4970 doorbell & MPI2_DOORBELL_DATA_MASK);
4971 } else if ((doorbell & MPI2_IOC_STATE_MASK) ==
4972 MPI2_IOC_STATE_COREDUMP) {
4973 mpt3sas_print_coredump_info(ioc,
4974 doorbell & MPI2_DOORBELL_DATA_MASK);
4980 static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
4982 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
4984 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
4988 return test_and_set_bit(0, &priv->ata_command_pending);
4990 clear_bit(0, &priv->ata_command_pending);
4995 * _scsih_flush_running_cmds - completing outstanding commands.
4996 * @ioc: per adapter object
4998 * The flushing out of all pending scmd commands following host reset,
4999 * where all IO is dropped to the floor.
5002 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
5004 struct scsi_cmnd *scmd;
5005 struct scsiio_tracker *st;
5009 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5010 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
5014 _scsih_set_satl_pending(scmd, false);
5015 st = scsi_cmd_priv(scmd);
5016 mpt3sas_base_clear_st(ioc, st);
5017 scsi_dma_unmap(scmd);
5018 if (ioc->pci_error_recovery || ioc->remove_host)
5019 scmd->result = DID_NO_CONNECT << 16;
5021 scmd->result = DID_RESET << 16;
5024 dtmprintk(ioc, ioc_info(ioc, "completing %d cmds\n", count));
5028 * _scsih_setup_eedp - setup MPI request for EEDP transfer
5029 * @ioc: per adapter object
5030 * @scmd: pointer to scsi command object
5031 * @mpi_request: pointer to the SCSI_IO request message frame
5033 * Supporting protection 1 and 3.
5036 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
5037 Mpi25SCSIIORequest_t *mpi_request)
5040 Mpi25SCSIIORequest_t *mpi_request_3v =
5041 (Mpi25SCSIIORequest_t *)mpi_request;
5043 switch (scsi_get_prot_op(scmd)) {
5044 case SCSI_PROT_READ_STRIP:
5045 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
5047 case SCSI_PROT_WRITE_INSERT:
5048 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
5054 if (scmd->prot_flags & SCSI_PROT_GUARD_CHECK)
5055 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
5057 if (scmd->prot_flags & SCSI_PROT_REF_CHECK)
5058 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG;
5060 if (scmd->prot_flags & SCSI_PROT_REF_INCREMENT) {
5061 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG;
5063 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
5064 cpu_to_be32(scsi_prot_ref_tag(scmd));
5067 mpi_request_3v->EEDPBlockSize = cpu_to_le16(scsi_prot_interval(scmd));
5069 if (ioc->is_gen35_ioc)
5070 eedp_flags |= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE;
5071 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
5075 * _scsih_eedp_error_handling - return sense code for EEDP errors
5076 * @scmd: pointer to scsi command object
5077 * @ioc_status: ioc status
5080 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
5084 switch (ioc_status) {
5085 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
5088 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
5091 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
5098 scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x10, ascq);
5099 set_host_byte(scmd, DID_ABORT);
5103 * scsih_qcmd - main scsi request entry point
5104 * @shost: SCSI host pointer
5105 * @scmd: pointer to scsi command object
5107 * The callback index is set inside `ioc->scsi_io_cb_idx`.
5109 * Return: 0 on success. If there's a failure, return either:
5110 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
5111 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
5114 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
5116 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
5117 struct MPT3SAS_DEVICE *sas_device_priv_data;
5118 struct MPT3SAS_TARGET *sas_target_priv_data;
5119 struct _raid_device *raid_device;
5120 struct request *rq = scsi_cmd_to_rq(scmd);
5122 Mpi25SCSIIORequest_t *mpi_request;
5123 struct _pcie_device *pcie_device = NULL;
5128 if (ioc->logging_level & MPT_DEBUG_SCSI)
5129 scsi_print_command(scmd);
5131 sas_device_priv_data = scmd->device->hostdata;
5132 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
5133 scmd->result = DID_NO_CONNECT << 16;
5138 if (!(_scsih_allow_scmd_to_device(ioc, scmd))) {
5139 scmd->result = DID_NO_CONNECT << 16;
5144 sas_target_priv_data = sas_device_priv_data->sas_target;
5146 /* invalid device handle */
5147 handle = sas_target_priv_data->handle;
5150 * Avoid error handling escallation when device is disconnected
5152 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE || sas_device_priv_data->block) {
5153 if (scmd->device->host->shost_state == SHOST_RECOVERY &&
5154 scmd->cmnd[0] == TEST_UNIT_READY) {
5155 scsi_build_sense(scmd, 0, UNIT_ATTENTION, 0x29, 0x07);
5161 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
5162 scmd->result = DID_NO_CONNECT << 16;
5168 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress) {
5169 /* host recovery or link resets sent via IOCTLs */
5170 return SCSI_MLQUEUE_HOST_BUSY;
5171 } else if (sas_target_priv_data->deleted) {
5172 /* device has been deleted */
5173 scmd->result = DID_NO_CONNECT << 16;
5176 } else if (sas_target_priv_data->tm_busy ||
5177 sas_device_priv_data->block) {
5178 /* device busy with task management */
5179 return SCSI_MLQUEUE_DEVICE_BUSY;
5183 * Bug work around for firmware SATL handling. The loop
5184 * is based on atomic operations and ensures consistency
5185 * since we're lockless at this point
5188 if (test_bit(0, &sas_device_priv_data->ata_command_pending))
5189 return SCSI_MLQUEUE_DEVICE_BUSY;
5190 } while (_scsih_set_satl_pending(scmd, true));
5192 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
5193 mpi_control = MPI2_SCSIIO_CONTROL_READ;
5194 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
5195 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
5197 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
5200 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
5201 /* NCQ Prio supported, make sure control indicated high priority */
5202 if (sas_device_priv_data->ncq_prio_enable) {
5203 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
5204 if (class == IOPRIO_CLASS_RT)
5205 mpi_control |= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT;
5207 /* Make sure Device is not raid volume.
5208 * We do not expose raid functionality to upper layer for warpdrive.
5210 if (((!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev))
5211 && !scsih_is_nvme(&scmd->device->sdev_gendev))
5212 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
5213 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
5215 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
5217 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
5218 _scsih_set_satl_pending(scmd, false);
5221 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5222 memset(mpi_request, 0, ioc->request_sz);
5223 _scsih_setup_eedp(ioc, scmd, mpi_request);
5225 if (scmd->cmd_len == 32)
5226 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
5227 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
5228 if (sas_device_priv_data->sas_target->flags &
5229 MPT_TARGET_FLAGS_RAID_COMPONENT)
5230 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
5232 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
5233 mpi_request->DevHandle = cpu_to_le16(handle);
5234 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
5235 mpi_request->Control = cpu_to_le32(mpi_control);
5236 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
5237 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
5238 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
5239 mpi_request->SenseBufferLowAddress =
5240 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
5241 mpi_request->SGLOffset0 = offsetof(Mpi25SCSIIORequest_t, SGL) / 4;
5242 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
5244 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
5246 if (mpi_request->DataLength) {
5247 pcie_device = sas_target_priv_data->pcie_dev;
5248 if (ioc->build_sg_scmd(ioc, scmd, smid, pcie_device)) {
5249 mpt3sas_base_free_smid(ioc, smid);
5250 _scsih_set_satl_pending(scmd, false);
5254 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
5256 raid_device = sas_target_priv_data->raid_device;
5257 if (raid_device && raid_device->direct_io_enabled)
5258 mpt3sas_setup_direct_io(ioc, scmd,
5259 raid_device, mpi_request);
5261 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
5262 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
5263 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
5264 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
5265 ioc->put_smid_fast_path(ioc, smid, handle);
5267 ioc->put_smid_scsi_io(ioc, smid,
5268 le16_to_cpu(mpi_request->DevHandle));
5270 ioc->put_smid_default(ioc, smid);
5274 return SCSI_MLQUEUE_HOST_BUSY;
5278 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
5279 * @sense_buffer: sense data returned by target
5280 * @data: normalized skey/asc/ascq
5283 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
5285 if ((sense_buffer[0] & 0x7F) >= 0x72) {
5286 /* descriptor format */
5287 data->skey = sense_buffer[1] & 0x0F;
5288 data->asc = sense_buffer[2];
5289 data->ascq = sense_buffer[3];
5292 data->skey = sense_buffer[2] & 0x0F;
5293 data->asc = sense_buffer[12];
5294 data->ascq = sense_buffer[13];
5299 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
5300 * @ioc: per adapter object
5301 * @scmd: pointer to scsi command object
5302 * @mpi_reply: reply mf payload returned from firmware
5305 * scsi_status - SCSI Status code returned from target device
5306 * scsi_state - state info associated with SCSI_IO determined by ioc
5307 * ioc_status - ioc supplied status info
5310 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
5311 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
5315 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
5316 MPI2_IOCSTATUS_MASK;
5317 u8 scsi_state = mpi_reply->SCSIState;
5318 u8 scsi_status = mpi_reply->SCSIStatus;
5319 char *desc_ioc_state = NULL;
5320 char *desc_scsi_status = NULL;
5321 char *desc_scsi_state = ioc->tmp_string;
5322 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5323 struct _sas_device *sas_device = NULL;
5324 struct _pcie_device *pcie_device = NULL;
5325 struct scsi_target *starget = scmd->device->sdev_target;
5326 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
5327 char *device_str = NULL;
5331 if (ioc->hide_ir_msg)
5332 device_str = "WarpDrive";
5334 device_str = "volume";
5336 if (log_info == 0x31170000)
5339 switch (ioc_status) {
5340 case MPI2_IOCSTATUS_SUCCESS:
5341 desc_ioc_state = "success";
5343 case MPI2_IOCSTATUS_INVALID_FUNCTION:
5344 desc_ioc_state = "invalid function";
5346 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
5347 desc_ioc_state = "scsi recovered error";
5349 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
5350 desc_ioc_state = "scsi invalid dev handle";
5352 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
5353 desc_ioc_state = "scsi device not there";
5355 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
5356 desc_ioc_state = "scsi data overrun";
5358 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
5359 desc_ioc_state = "scsi data underrun";
5361 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
5362 desc_ioc_state = "scsi io data error";
5364 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
5365 desc_ioc_state = "scsi protocol error";
5367 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
5368 desc_ioc_state = "scsi task terminated";
5370 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
5371 desc_ioc_state = "scsi residual mismatch";
5373 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
5374 desc_ioc_state = "scsi task mgmt failed";
5376 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
5377 desc_ioc_state = "scsi ioc terminated";
5379 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
5380 desc_ioc_state = "scsi ext terminated";
5382 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
5383 desc_ioc_state = "eedp guard error";
5385 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
5386 desc_ioc_state = "eedp ref tag error";
5388 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
5389 desc_ioc_state = "eedp app tag error";
5391 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
5392 desc_ioc_state = "insufficient power";
5395 desc_ioc_state = "unknown";
5399 switch (scsi_status) {
5400 case MPI2_SCSI_STATUS_GOOD:
5401 desc_scsi_status = "good";
5403 case MPI2_SCSI_STATUS_CHECK_CONDITION:
5404 desc_scsi_status = "check condition";
5406 case MPI2_SCSI_STATUS_CONDITION_MET:
5407 desc_scsi_status = "condition met";
5409 case MPI2_SCSI_STATUS_BUSY:
5410 desc_scsi_status = "busy";
5412 case MPI2_SCSI_STATUS_INTERMEDIATE:
5413 desc_scsi_status = "intermediate";
5415 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
5416 desc_scsi_status = "intermediate condmet";
5418 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
5419 desc_scsi_status = "reservation conflict";
5421 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
5422 desc_scsi_status = "command terminated";
5424 case MPI2_SCSI_STATUS_TASK_SET_FULL:
5425 desc_scsi_status = "task set full";
5427 case MPI2_SCSI_STATUS_ACA_ACTIVE:
5428 desc_scsi_status = "aca active";
5430 case MPI2_SCSI_STATUS_TASK_ABORTED:
5431 desc_scsi_status = "task aborted";
5434 desc_scsi_status = "unknown";
5438 desc_scsi_state[0] = '\0';
5440 desc_scsi_state = " ";
5441 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
5442 strcat(desc_scsi_state, "response info ");
5443 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5444 strcat(desc_scsi_state, "state terminated ");
5445 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
5446 strcat(desc_scsi_state, "no status ");
5447 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
5448 strcat(desc_scsi_state, "autosense failed ");
5449 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
5450 strcat(desc_scsi_state, "autosense valid ");
5452 scsi_print_command(scmd);
5454 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
5455 ioc_warn(ioc, "\t%s wwid(0x%016llx)\n",
5456 device_str, (u64)priv_target->sas_address);
5457 } else if (priv_target->flags & MPT_TARGET_FLAGS_PCIE_DEVICE) {
5458 pcie_device = mpt3sas_get_pdev_from_target(ioc, priv_target);
5460 ioc_info(ioc, "\twwid(0x%016llx), port(%d)\n",
5461 (u64)pcie_device->wwid, pcie_device->port_num);
5462 if (pcie_device->enclosure_handle != 0)
5463 ioc_info(ioc, "\tenclosure logical id(0x%016llx), slot(%d)\n",
5464 (u64)pcie_device->enclosure_logical_id,
5466 if (pcie_device->connector_name[0])
5467 ioc_info(ioc, "\tenclosure level(0x%04x), connector name( %s)\n",
5468 pcie_device->enclosure_level,
5469 pcie_device->connector_name);
5470 pcie_device_put(pcie_device);
5473 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
5475 ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n",
5476 (u64)sas_device->sas_address, sas_device->phy);
5478 _scsih_display_enclosure_chassis_info(ioc, sas_device,
5481 sas_device_put(sas_device);
5485 ioc_warn(ioc, "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
5486 le16_to_cpu(mpi_reply->DevHandle),
5487 desc_ioc_state, ioc_status, smid);
5488 ioc_warn(ioc, "\trequest_len(%d), underflow(%d), resid(%d)\n",
5489 scsi_bufflen(scmd), scmd->underflow, scsi_get_resid(scmd));
5490 ioc_warn(ioc, "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
5491 le16_to_cpu(mpi_reply->TaskTag),
5492 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
5493 ioc_warn(ioc, "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
5494 desc_scsi_status, scsi_status, desc_scsi_state, scsi_state);
5496 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
5497 struct sense_info data;
5498 _scsih_normalize_sense(scmd->sense_buffer, &data);
5499 ioc_warn(ioc, "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
5500 data.skey, data.asc, data.ascq,
5501 le32_to_cpu(mpi_reply->SenseCount));
5503 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
5504 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
5505 response_bytes = (u8 *)&response_info;
5506 _scsih_response_code(ioc, response_bytes[0]);
5511 * _scsih_turn_on_pfa_led - illuminate PFA LED
5512 * @ioc: per adapter object
5513 * @handle: device handle
5517 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5519 Mpi2SepReply_t mpi_reply;
5520 Mpi2SepRequest_t mpi_request;
5521 struct _sas_device *sas_device;
5523 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
5527 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
5528 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
5529 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
5530 mpi_request.SlotStatus =
5531 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
5532 mpi_request.DevHandle = cpu_to_le16(handle);
5533 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
5534 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5535 &mpi_request)) != 0) {
5536 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5537 __FILE__, __LINE__, __func__);
5540 sas_device->pfa_led_on = 1;
5542 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5544 ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5545 le16_to_cpu(mpi_reply.IOCStatus),
5546 le32_to_cpu(mpi_reply.IOCLogInfo)));
5550 sas_device_put(sas_device);
5554 * _scsih_turn_off_pfa_led - turn off Fault LED
5555 * @ioc: per adapter object
5556 * @sas_device: sas device whose PFA LED has to turned off
5560 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
5561 struct _sas_device *sas_device)
5563 Mpi2SepReply_t mpi_reply;
5564 Mpi2SepRequest_t mpi_request;
5566 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
5567 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
5568 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
5569 mpi_request.SlotStatus = 0;
5570 mpi_request.Slot = cpu_to_le16(sas_device->slot);
5571 mpi_request.DevHandle = 0;
5572 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
5573 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
5574 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
5575 &mpi_request)) != 0) {
5576 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5577 __FILE__, __LINE__, __func__);
5581 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
5583 ioc_info(ioc, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5584 le16_to_cpu(mpi_reply.IOCStatus),
5585 le32_to_cpu(mpi_reply.IOCLogInfo)));
5591 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5592 * @ioc: per adapter object
5593 * @handle: device handle
5594 * Context: interrupt.
5597 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5599 struct fw_event_work *fw_event;
5601 fw_event = alloc_fw_event_work(0);
5604 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
5605 fw_event->device_handle = handle;
5606 fw_event->ioc = ioc;
5607 _scsih_fw_event_add(ioc, fw_event);
5608 fw_event_work_put(fw_event);
5612 * _scsih_smart_predicted_fault - process smart errors
5613 * @ioc: per adapter object
5614 * @handle: device handle
5615 * Context: interrupt.
5618 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5620 struct scsi_target *starget;
5621 struct MPT3SAS_TARGET *sas_target_priv_data;
5622 Mpi2EventNotificationReply_t *event_reply;
5623 Mpi2EventDataSasDeviceStatusChange_t *event_data;
5624 struct _sas_device *sas_device;
5626 unsigned long flags;
5628 /* only handle non-raid devices */
5629 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5630 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
5634 starget = sas_device->starget;
5635 sas_target_priv_data = starget->hostdata;
5637 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
5638 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
5641 _scsih_display_enclosure_chassis_info(NULL, sas_device, NULL, starget);
5643 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5645 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
5646 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
5648 /* insert into event log */
5649 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
5650 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
5651 event_reply = kzalloc(sz, GFP_ATOMIC);
5653 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5654 __FILE__, __LINE__, __func__);
5658 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
5659 event_reply->Event =
5660 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
5661 event_reply->MsgLength = sz/4;
5662 event_reply->EventDataLength =
5663 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
5664 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
5665 event_reply->EventData;
5666 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
5667 event_data->ASC = 0x5D;
5668 event_data->DevHandle = cpu_to_le16(handle);
5669 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
5670 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
5674 sas_device_put(sas_device);
5678 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5683 * _scsih_io_done - scsi request callback
5684 * @ioc: per adapter object
5685 * @smid: system request message index
5686 * @msix_index: MSIX table index supplied by the OS
5687 * @reply: reply message frame(lower 32bit addr)
5689 * Callback handler when using _scsih_qcmd.
5691 * Return: 1 meaning mf should be freed from _base_interrupt
5692 * 0 means the mf is freed from this function.
5695 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5697 Mpi25SCSIIORequest_t *mpi_request;
5698 Mpi2SCSIIOReply_t *mpi_reply;
5699 struct scsi_cmnd *scmd;
5700 struct scsiio_tracker *st;
5706 struct MPT3SAS_DEVICE *sas_device_priv_data;
5707 u32 response_code = 0;
5709 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5711 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
5715 _scsih_set_satl_pending(scmd, false);
5717 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
5719 if (mpi_reply == NULL) {
5720 scmd->result = DID_OK << 16;
5724 sas_device_priv_data = scmd->device->hostdata;
5725 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
5726 sas_device_priv_data->sas_target->deleted) {
5727 scmd->result = DID_NO_CONNECT << 16;
5730 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
5733 * WARPDRIVE: If direct_io is set then it is directIO,
5734 * the failed direct I/O should be redirected to volume
5736 st = scsi_cmd_priv(scmd);
5737 if (st->direct_io &&
5738 ((ioc_status & MPI2_IOCSTATUS_MASK)
5739 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
5742 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
5743 mpi_request->DevHandle =
5744 cpu_to_le16(sas_device_priv_data->sas_target->handle);
5745 ioc->put_smid_scsi_io(ioc, smid,
5746 sas_device_priv_data->sas_target->handle);
5749 /* turning off TLR */
5750 scsi_state = mpi_reply->SCSIState;
5751 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
5753 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
5754 if (!sas_device_priv_data->tlr_snoop_check) {
5755 sas_device_priv_data->tlr_snoop_check++;
5756 if ((!ioc->is_warpdrive &&
5757 !scsih_is_raid(&scmd->device->sdev_gendev) &&
5758 !scsih_is_nvme(&scmd->device->sdev_gendev))
5759 && sas_is_tlr_enabled(scmd->device) &&
5760 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
5761 sas_disable_tlr(scmd->device);
5762 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
5766 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
5767 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
5768 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
5769 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
5772 ioc_status &= MPI2_IOCSTATUS_MASK;
5773 scsi_status = mpi_reply->SCSIStatus;
5775 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
5776 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
5777 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
5778 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
5779 ioc_status = MPI2_IOCSTATUS_SUCCESS;
5782 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
5783 struct sense_info data;
5784 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
5786 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
5787 le32_to_cpu(mpi_reply->SenseCount));
5788 memcpy(scmd->sense_buffer, sense_data, sz);
5789 _scsih_normalize_sense(scmd->sense_buffer, &data);
5790 /* failure prediction threshold exceeded */
5791 if (data.asc == 0x5D)
5792 _scsih_smart_predicted_fault(ioc,
5793 le16_to_cpu(mpi_reply->DevHandle));
5794 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
5796 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
5797 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
5798 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
5799 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
5800 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
5802 switch (ioc_status) {
5803 case MPI2_IOCSTATUS_BUSY:
5804 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
5805 scmd->result = SAM_STAT_BUSY;
5808 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
5809 scmd->result = DID_NO_CONNECT << 16;
5812 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
5813 if (sas_device_priv_data->block) {
5814 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
5817 if (log_info == 0x31110630) {
5818 if (scmd->retries > 2) {
5819 scmd->result = DID_NO_CONNECT << 16;
5820 scsi_device_set_state(scmd->device,
5823 scmd->result = DID_SOFT_ERROR << 16;
5824 scmd->device->expecting_cc_ua = 1;
5827 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
5828 scmd->result = DID_RESET << 16;
5830 } else if ((scmd->device->channel == RAID_CHANNEL) &&
5831 (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
5832 MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
5833 scmd->result = DID_RESET << 16;
5836 scmd->result = DID_SOFT_ERROR << 16;
5838 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
5839 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
5840 scmd->result = DID_RESET << 16;
5843 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
5844 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
5845 scmd->result = DID_SOFT_ERROR << 16;
5847 scmd->result = (DID_OK << 16) | scsi_status;
5850 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
5851 scmd->result = (DID_OK << 16) | scsi_status;
5853 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
5856 if (xfer_cnt < scmd->underflow) {
5857 if (scsi_status == SAM_STAT_BUSY)
5858 scmd->result = SAM_STAT_BUSY;
5860 scmd->result = DID_SOFT_ERROR << 16;
5861 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5862 MPI2_SCSI_STATE_NO_SCSI_STATUS))
5863 scmd->result = DID_SOFT_ERROR << 16;
5864 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5865 scmd->result = DID_RESET << 16;
5866 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
5867 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
5868 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
5869 scsi_build_sense(scmd, 0, ILLEGAL_REQUEST,
5874 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
5875 scsi_set_resid(scmd, 0);
5877 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
5878 case MPI2_IOCSTATUS_SUCCESS:
5879 scmd->result = (DID_OK << 16) | scsi_status;
5880 if (response_code ==
5881 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
5882 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
5883 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
5884 scmd->result = DID_SOFT_ERROR << 16;
5885 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
5886 scmd->result = DID_RESET << 16;
5889 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
5890 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
5891 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
5892 _scsih_eedp_error_handling(scmd, ioc_status);
5895 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
5896 case MPI2_IOCSTATUS_INVALID_FUNCTION:
5897 case MPI2_IOCSTATUS_INVALID_SGL:
5898 case MPI2_IOCSTATUS_INTERNAL_ERROR:
5899 case MPI2_IOCSTATUS_INVALID_FIELD:
5900 case MPI2_IOCSTATUS_INVALID_STATE:
5901 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
5902 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
5903 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
5905 scmd->result = DID_SOFT_ERROR << 16;
5910 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
5911 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
5915 scsi_dma_unmap(scmd);
5916 mpt3sas_base_free_smid(ioc, smid);
5922 * _scsih_update_vphys_after_reset - update the Port's
5923 * vphys_list after reset
5924 * @ioc: per adapter object
5929 _scsih_update_vphys_after_reset(struct MPT3SAS_ADAPTER *ioc)
5933 Mpi2ConfigReply_t mpi_reply;
5934 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
5935 u16 attached_handle;
5936 u64 attached_sas_addr;
5937 u8 found = 0, port_id;
5938 Mpi2SasPhyPage0_t phy_pg0;
5939 struct hba_port *port, *port_next, *mport;
5940 struct virtual_phy *vphy, *vphy_next;
5941 struct _sas_device *sas_device;
5944 * Mark all the vphys objects as dirty.
5946 list_for_each_entry_safe(port, port_next,
5947 &ioc->port_table_list, list) {
5948 if (!port->vphys_mask)
5950 list_for_each_entry_safe(vphy, vphy_next,
5951 &port->vphys_list, list) {
5952 vphy->flags |= MPT_VPHY_FLAG_DIRTY_PHY;
5957 * Read SASIOUnitPage0 to get each HBA Phy's data.
5959 sz = struct_size(sas_iounit_pg0, PhyData, ioc->sas_hba.num_phys);
5960 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5961 if (!sas_iounit_pg0) {
5962 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5963 __FILE__, __LINE__, __func__);
5966 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5967 sas_iounit_pg0, sz)) != 0)
5969 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5970 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5973 * Loop over each HBA Phy.
5975 for (i = 0; i < ioc->sas_hba.num_phys; i++) {
5977 * Check whether Phy's Negotiation Link Rate is > 1.5G or not.
5979 if ((sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4) <
5980 MPI2_SAS_NEG_LINK_RATE_1_5)
5983 * Check whether Phy is connected to SEP device or not,
5984 * if it is SEP device then read the Phy's SASPHYPage0 data to
5985 * determine whether Phy is a virtual Phy or not. if it is
5986 * virtual phy then it is conformed that the attached remote
5987 * device is a HBA's vSES device.
5990 sas_iounit_pg0->PhyData[i].ControllerPhyDeviceInfo) &
5991 MPI2_SAS_DEVICE_INFO_SEP))
5994 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5996 ioc_err(ioc, "failure at %s:%d/%s()!\n",
5997 __FILE__, __LINE__, __func__);
6001 if (!(le32_to_cpu(phy_pg0.PhyInfo) &
6002 MPI2_SAS_PHYINFO_VIRTUAL_PHY))
6005 * Get the vSES device's SAS Address.
6007 attached_handle = le16_to_cpu(
6008 sas_iounit_pg0->PhyData[i].AttachedDevHandle);
6009 if (_scsih_get_sas_address(ioc, attached_handle,
6010 &attached_sas_addr) != 0) {
6011 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6012 __FILE__, __LINE__, __func__);
6017 port = port_next = NULL;
6019 * Loop over each virtual_phy object from
6020 * each port's vphys_list.
6022 list_for_each_entry_safe(port,
6023 port_next, &ioc->port_table_list, list) {
6024 if (!port->vphys_mask)
6026 list_for_each_entry_safe(vphy, vphy_next,
6027 &port->vphys_list, list) {
6029 * Continue with next virtual_phy object
6030 * if the object is not marked as dirty.
6032 if (!(vphy->flags & MPT_VPHY_FLAG_DIRTY_PHY))
6036 * Continue with next virtual_phy object
6037 * if the object's SAS Address is not equals
6038 * to current Phy's vSES device SAS Address.
6040 if (vphy->sas_address != attached_sas_addr)
6043 * Enable current Phy number bit in object's
6046 if (!(vphy->phy_mask & (1 << i)))
6047 vphy->phy_mask = (1 << i);
6049 * Get hba_port object from hba_port table
6050 * corresponding to current phy's Port ID.
6051 * if there is no hba_port object corresponding
6052 * to Phy's Port ID then create a new hba_port
6053 * object & add to hba_port table.
6055 port_id = sas_iounit_pg0->PhyData[i].Port;
6056 mport = mpt3sas_get_port_by_id(ioc, port_id, 1);
6059 sizeof(struct hba_port), GFP_KERNEL);
6062 mport->port_id = port_id;
6064 "%s: hba_port entry: %p, port: %d is added to hba_port list\n",
6065 __func__, mport, mport->port_id);
6066 list_add_tail(&mport->list,
6067 &ioc->port_table_list);
6070 * If mport & port pointers are not pointing to
6071 * same hba_port object then it means that vSES
6072 * device's Port ID got changed after reset and
6073 * hence move current virtual_phy object from
6074 * port's vphys_list to mport's vphys_list.
6076 if (port != mport) {
6077 if (!mport->vphys_mask)
6079 &mport->vphys_list);
6080 mport->vphys_mask |= (1 << i);
6081 port->vphys_mask &= ~(1 << i);
6082 list_move(&vphy->list,
6083 &mport->vphys_list);
6084 sas_device = mpt3sas_get_sdev_by_addr(
6085 ioc, attached_sas_addr, port);
6087 sas_device->port = mport;
6090 * Earlier while updating the hba_port table,
6091 * it is determined that there is no other
6092 * direct attached device with mport's Port ID,
6093 * Hence mport was marked as dirty. Only vSES
6094 * device has this Port ID, so unmark the mport
6097 if (mport->flags & HBA_PORT_FLAG_DIRTY_PORT) {
6098 mport->sas_address = 0;
6099 mport->phy_mask = 0;
6101 ~HBA_PORT_FLAG_DIRTY_PORT;
6104 * Unmark current virtual_phy object as dirty.
6106 vphy->flags &= ~MPT_VPHY_FLAG_DIRTY_PHY;
6115 kfree(sas_iounit_pg0);
6119 * _scsih_get_port_table_after_reset - Construct temporary port table
6120 * @ioc: per adapter object
6121 * @port_table: address where port table needs to be constructed
6123 * return number of HBA port entries available after reset.
6126 _scsih_get_port_table_after_reset(struct MPT3SAS_ADAPTER *ioc,
6127 struct hba_port *port_table)
6131 Mpi2ConfigReply_t mpi_reply;
6132 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
6133 u16 attached_handle;
6134 u64 attached_sas_addr;
6135 u8 found = 0, port_count = 0, port_id;
6137 sz = struct_size(sas_iounit_pg0, PhyData, ioc->sas_hba.num_phys);
6138 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
6139 if (!sas_iounit_pg0) {
6140 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6141 __FILE__, __LINE__, __func__);
6145 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
6146 sas_iounit_pg0, sz)) != 0)
6148 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6149 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6151 for (i = 0; i < ioc->sas_hba.num_phys; i++) {
6153 if ((sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4) <
6154 MPI2_SAS_NEG_LINK_RATE_1_5)
6157 le16_to_cpu(sas_iounit_pg0->PhyData[i].AttachedDevHandle);
6158 if (_scsih_get_sas_address(
6159 ioc, attached_handle, &attached_sas_addr) != 0) {
6160 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6161 __FILE__, __LINE__, __func__);
6165 for (j = 0; j < port_count; j++) {
6166 port_id = sas_iounit_pg0->PhyData[i].Port;
6167 if (port_table[j].port_id == port_id &&
6168 port_table[j].sas_address == attached_sas_addr) {
6169 port_table[j].phy_mask |= (1 << i);
6178 port_id = sas_iounit_pg0->PhyData[i].Port;
6179 port_table[port_count].port_id = port_id;
6180 port_table[port_count].phy_mask = (1 << i);
6181 port_table[port_count].sas_address = attached_sas_addr;
6185 kfree(sas_iounit_pg0);
6189 enum hba_port_matched_codes {
6191 MATCHED_WITH_ADDR_AND_PHYMASK,
6192 MATCHED_WITH_ADDR_SUBPHYMASK_AND_PORT,
6193 MATCHED_WITH_ADDR_AND_SUBPHYMASK,
6198 * _scsih_look_and_get_matched_port_entry - Get matched hba port entry
6199 * from HBA port table
6200 * @ioc: per adapter object
6201 * @port_entry: hba port entry from temporary port table which needs to be
6202 * searched for matched entry in the HBA port table
6203 * @matched_port_entry: save matched hba port entry here
6204 * @count: count of matched entries
6206 * return type of matched entry found.
6208 static enum hba_port_matched_codes
6209 _scsih_look_and_get_matched_port_entry(struct MPT3SAS_ADAPTER *ioc,
6210 struct hba_port *port_entry,
6211 struct hba_port **matched_port_entry, int *count)
6213 struct hba_port *port_table_entry, *matched_port = NULL;
6214 enum hba_port_matched_codes matched_code = NOT_MATCHED;
6216 *matched_port_entry = NULL;
6218 list_for_each_entry(port_table_entry, &ioc->port_table_list, list) {
6219 if (!(port_table_entry->flags & HBA_PORT_FLAG_DIRTY_PORT))
6222 if ((port_table_entry->sas_address == port_entry->sas_address)
6223 && (port_table_entry->phy_mask == port_entry->phy_mask)) {
6224 matched_code = MATCHED_WITH_ADDR_AND_PHYMASK;
6225 matched_port = port_table_entry;
6229 if ((port_table_entry->sas_address == port_entry->sas_address)
6230 && (port_table_entry->phy_mask & port_entry->phy_mask)
6231 && (port_table_entry->port_id == port_entry->port_id)) {
6232 matched_code = MATCHED_WITH_ADDR_SUBPHYMASK_AND_PORT;
6233 matched_port = port_table_entry;
6237 if ((port_table_entry->sas_address == port_entry->sas_address)
6238 && (port_table_entry->phy_mask & port_entry->phy_mask)) {
6240 MATCHED_WITH_ADDR_SUBPHYMASK_AND_PORT)
6242 matched_code = MATCHED_WITH_ADDR_AND_SUBPHYMASK;
6243 matched_port = port_table_entry;
6247 if (port_table_entry->sas_address == port_entry->sas_address) {
6249 MATCHED_WITH_ADDR_SUBPHYMASK_AND_PORT)
6251 if (matched_code == MATCHED_WITH_ADDR_AND_SUBPHYMASK)
6253 matched_code = MATCHED_WITH_ADDR;
6254 matched_port = port_table_entry;
6259 *matched_port_entry = matched_port;
6260 if (matched_code == MATCHED_WITH_ADDR)
6262 return matched_code;
6266 * _scsih_del_phy_part_of_anther_port - remove phy if it
6267 * is a part of anther port
6268 *@ioc: per adapter object
6269 *@port_table: port table after reset
6270 *@index: hba port entry index
6271 *@port_count: number of ports available after host reset
6272 *@offset: HBA phy bit offset
6276 _scsih_del_phy_part_of_anther_port(struct MPT3SAS_ADAPTER *ioc,
6277 struct hba_port *port_table,
6278 int index, u8 port_count, int offset)
6280 struct _sas_node *sas_node = &ioc->sas_hba;
6283 for (i = 0; i < port_count; i++) {
6287 if (port_table[i].phy_mask & (1 << offset)) {
6288 mpt3sas_transport_del_phy_from_an_existing_port(
6289 ioc, sas_node, &sas_node->phy[offset]);
6295 port_table[index].phy_mask |= (1 << offset);
6299 * _scsih_add_or_del_phys_from_existing_port - add/remove phy to/from
6301 *@ioc: per adapter object
6302 *@hba_port_entry: hba port table entry
6303 *@port_table: temporary port table
6304 *@index: hba port entry index
6305 *@port_count: number of ports available after host reset
6309 _scsih_add_or_del_phys_from_existing_port(struct MPT3SAS_ADAPTER *ioc,
6310 struct hba_port *hba_port_entry, struct hba_port *port_table,
6311 int index, int port_count)
6313 u32 phy_mask, offset = 0;
6314 struct _sas_node *sas_node = &ioc->sas_hba;
6316 phy_mask = hba_port_entry->phy_mask ^ port_table[index].phy_mask;
6318 for (offset = 0; offset < ioc->sas_hba.num_phys; offset++) {
6319 if (phy_mask & (1 << offset)) {
6320 if (!(port_table[index].phy_mask & (1 << offset))) {
6321 _scsih_del_phy_part_of_anther_port(
6322 ioc, port_table, index, port_count,
6326 if (sas_node->phy[offset].phy_belongs_to_port)
6327 mpt3sas_transport_del_phy_from_an_existing_port(
6328 ioc, sas_node, &sas_node->phy[offset]);
6329 mpt3sas_transport_add_phy_to_an_existing_port(
6330 ioc, sas_node, &sas_node->phy[offset],
6331 hba_port_entry->sas_address,
6338 * _scsih_del_dirty_vphy - delete virtual_phy objects marked as dirty.
6339 * @ioc: per adapter object
6344 _scsih_del_dirty_vphy(struct MPT3SAS_ADAPTER *ioc)
6346 struct hba_port *port, *port_next;
6347 struct virtual_phy *vphy, *vphy_next;
6349 list_for_each_entry_safe(port, port_next,
6350 &ioc->port_table_list, list) {
6351 if (!port->vphys_mask)
6353 list_for_each_entry_safe(vphy, vphy_next,
6354 &port->vphys_list, list) {
6355 if (vphy->flags & MPT_VPHY_FLAG_DIRTY_PHY) {
6356 drsprintk(ioc, ioc_info(ioc,
6357 "Deleting vphy %p entry from port id: %d\t, Phy_mask 0x%08x\n",
6358 vphy, port->port_id,
6360 port->vphys_mask &= ~vphy->phy_mask;
6361 list_del(&vphy->list);
6365 if (!port->vphys_mask && !port->sas_address)
6366 port->flags |= HBA_PORT_FLAG_DIRTY_PORT;
6371 * _scsih_del_dirty_port_entries - delete dirty port entries from port list
6373 *@ioc: per adapter object
6377 _scsih_del_dirty_port_entries(struct MPT3SAS_ADAPTER *ioc)
6379 struct hba_port *port, *port_next;
6381 list_for_each_entry_safe(port, port_next,
6382 &ioc->port_table_list, list) {
6383 if (!(port->flags & HBA_PORT_FLAG_DIRTY_PORT) ||
6384 port->flags & HBA_PORT_FLAG_NEW_PORT)
6387 drsprintk(ioc, ioc_info(ioc,
6388 "Deleting port table entry %p having Port: %d\t Phy_mask 0x%08x\n",
6389 port, port->port_id, port->phy_mask));
6390 list_del(&port->list);
6396 * _scsih_sas_port_refresh - Update HBA port table after host reset
6397 * @ioc: per adapter object
6400 _scsih_sas_port_refresh(struct MPT3SAS_ADAPTER *ioc)
6403 struct hba_port *port_table;
6404 struct hba_port *port_table_entry;
6405 struct hba_port *port_entry = NULL;
6406 int i, j, count = 0, lcount = 0;
6411 drsprintk(ioc, ioc_info(ioc,
6412 "updating ports for sas_host(0x%016llx)\n",
6413 (unsigned long long)ioc->sas_hba.sas_address));
6415 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
6417 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6418 __FILE__, __LINE__, __func__);
6422 if (num_phys > ioc->sas_hba.nr_phys_allocated) {
6423 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6424 __FILE__, __LINE__, __func__);
6427 ioc->sas_hba.num_phys = num_phys;
6429 port_table = kcalloc(ioc->sas_hba.num_phys,
6430 sizeof(struct hba_port), GFP_KERNEL);
6434 port_count = _scsih_get_port_table_after_reset(ioc, port_table);
6438 drsprintk(ioc, ioc_info(ioc, "New Port table\n"));
6439 for (j = 0; j < port_count; j++)
6440 drsprintk(ioc, ioc_info(ioc,
6441 "Port: %d\t Phy_mask 0x%08x\t sas_addr(0x%016llx)\n",
6442 port_table[j].port_id,
6443 port_table[j].phy_mask, port_table[j].sas_address));
6445 list_for_each_entry(port_table_entry, &ioc->port_table_list, list)
6446 port_table_entry->flags |= HBA_PORT_FLAG_DIRTY_PORT;
6448 drsprintk(ioc, ioc_info(ioc, "Old Port table\n"));
6449 port_table_entry = NULL;
6450 list_for_each_entry(port_table_entry, &ioc->port_table_list, list) {
6451 drsprintk(ioc, ioc_info(ioc,
6452 "Port: %d\t Phy_mask 0x%08x\t sas_addr(0x%016llx)\n",
6453 port_table_entry->port_id,
6454 port_table_entry->phy_mask,
6455 port_table_entry->sas_address));
6458 for (j = 0; j < port_count; j++) {
6459 ret = _scsih_look_and_get_matched_port_entry(ioc,
6460 &port_table[j], &port_entry, &count);
6462 drsprintk(ioc, ioc_info(ioc,
6463 "No Matched entry for sas_addr(0x%16llx), Port:%d\n",
6464 port_table[j].sas_address,
6465 port_table[j].port_id));
6470 case MATCHED_WITH_ADDR_SUBPHYMASK_AND_PORT:
6471 case MATCHED_WITH_ADDR_AND_SUBPHYMASK:
6472 _scsih_add_or_del_phys_from_existing_port(ioc,
6473 port_entry, port_table, j, port_count);
6475 case MATCHED_WITH_ADDR:
6476 sas_addr = port_table[j].sas_address;
6477 for (i = 0; i < port_count; i++) {
6478 if (port_table[i].sas_address == sas_addr)
6482 if (count > 1 || lcount > 1)
6485 _scsih_add_or_del_phys_from_existing_port(ioc,
6486 port_entry, port_table, j, port_count);
6492 if (port_entry->port_id != port_table[j].port_id)
6493 port_entry->port_id = port_table[j].port_id;
6494 port_entry->flags &= ~HBA_PORT_FLAG_DIRTY_PORT;
6495 port_entry->phy_mask = port_table[j].phy_mask;
6498 port_table_entry = NULL;
6502 * _scsih_alloc_vphy - allocate virtual_phy object
6503 * @ioc: per adapter object
6504 * @port_id: Port ID number
6505 * @phy_num: HBA Phy number
6507 * Returns allocated virtual_phy object.
6509 static struct virtual_phy *
6510 _scsih_alloc_vphy(struct MPT3SAS_ADAPTER *ioc, u8 port_id, u8 phy_num)
6512 struct virtual_phy *vphy;
6513 struct hba_port *port;
6515 port = mpt3sas_get_port_by_id(ioc, port_id, 0);
6519 vphy = mpt3sas_get_vphy_by_phy(ioc, port, phy_num);
6521 vphy = kzalloc(sizeof(struct virtual_phy), GFP_KERNEL);
6525 if (!port->vphys_mask)
6526 INIT_LIST_HEAD(&port->vphys_list);
6529 * Enable bit corresponding to HBA phy number on its
6530 * parent hba_port object's vphys_mask field.
6532 port->vphys_mask |= (1 << phy_num);
6533 vphy->phy_mask |= (1 << phy_num);
6535 list_add_tail(&vphy->list, &port->vphys_list);
6538 "vphy entry: %p, port id: %d, phy:%d is added to port's vphys_list\n",
6539 vphy, port->port_id, phy_num);
6545 * _scsih_sas_host_refresh - refreshing sas host object contents
6546 * @ioc: per adapter object
6549 * During port enable, fw will send topology events for every device. Its
6550 * possible that the handles may change from the previous setting, so this
6551 * code keeping handles updating if changed.
6554 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
6559 Mpi2ConfigReply_t mpi_reply;
6560 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
6561 u16 attached_handle;
6562 u8 link_rate, port_id;
6563 struct hba_port *port;
6564 Mpi2SasPhyPage0_t phy_pg0;
6567 ioc_info(ioc, "updating handles for sas_host(0x%016llx)\n",
6568 (u64)ioc->sas_hba.sas_address));
6570 sz = struct_size(sas_iounit_pg0, PhyData, ioc->sas_hba.num_phys);
6571 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
6572 if (!sas_iounit_pg0) {
6573 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6574 __FILE__, __LINE__, __func__);
6578 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
6579 sas_iounit_pg0, sz)) != 0)
6581 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
6582 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6584 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
6585 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
6587 ioc->sas_hba.handle = le16_to_cpu(
6588 sas_iounit_pg0->PhyData[0].ControllerDevHandle);
6589 port_id = sas_iounit_pg0->PhyData[i].Port;
6590 if (!(mpt3sas_get_port_by_id(ioc, port_id, 0))) {
6591 port = kzalloc(sizeof(struct hba_port), GFP_KERNEL);
6595 port->port_id = port_id;
6597 "hba_port entry: %p, port: %d is added to hba_port list\n",
6598 port, port->port_id);
6599 if (ioc->shost_recovery)
6600 port->flags = HBA_PORT_FLAG_NEW_PORT;
6601 list_add_tail(&port->list, &ioc->port_table_list);
6604 * Check whether current Phy belongs to HBA vSES device or not.
6606 if (le32_to_cpu(sas_iounit_pg0->PhyData[i].ControllerPhyDeviceInfo) &
6607 MPI2_SAS_DEVICE_INFO_SEP &&
6608 (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)) {
6609 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply,
6612 "failure at %s:%d/%s()!\n",
6613 __FILE__, __LINE__, __func__);
6616 if (!(le32_to_cpu(phy_pg0.PhyInfo) &
6617 MPI2_SAS_PHYINFO_VIRTUAL_PHY))
6620 * Allocate a virtual_phy object for vSES device, if
6621 * this vSES device is hot added.
6623 if (!_scsih_alloc_vphy(ioc, port_id, i))
6625 ioc->sas_hba.phy[i].hba_vphy = 1;
6629 * Add new HBA phys to STL if these new phys got added as part
6630 * of HBA Firmware upgrade/downgrade operation.
6632 if (!ioc->sas_hba.phy[i].phy) {
6633 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply,
6635 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6636 __FILE__, __LINE__, __func__);
6639 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6640 MPI2_IOCSTATUS_MASK;
6641 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6642 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6643 __FILE__, __LINE__, __func__);
6646 ioc->sas_hba.phy[i].phy_id = i;
6647 mpt3sas_transport_add_host_phy(ioc,
6648 &ioc->sas_hba.phy[i], phy_pg0,
6649 ioc->sas_hba.parent_dev);
6652 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
6653 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
6655 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
6656 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
6657 ioc->sas_hba.phy[i].port =
6658 mpt3sas_get_port_by_id(ioc, port_id, 0);
6659 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
6660 attached_handle, i, link_rate,
6661 ioc->sas_hba.phy[i].port);
6664 * Clear the phy details if this phy got disabled as part of
6665 * HBA Firmware upgrade/downgrade operation.
6667 for (i = ioc->sas_hba.num_phys;
6668 i < ioc->sas_hba.nr_phys_allocated; i++) {
6669 if (ioc->sas_hba.phy[i].phy &&
6670 ioc->sas_hba.phy[i].phy->negotiated_linkrate >=
6671 SAS_LINK_RATE_1_5_GBPS)
6672 mpt3sas_transport_update_links(ioc,
6673 ioc->sas_hba.sas_address, 0, i,
6674 MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED, NULL);
6677 kfree(sas_iounit_pg0);
6681 * _scsih_sas_host_add - create sas host object
6682 * @ioc: per adapter object
6684 * Creating host side data object, stored in ioc->sas_hba
6687 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
6690 Mpi2ConfigReply_t mpi_reply;
6691 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
6692 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
6693 Mpi2SasPhyPage0_t phy_pg0;
6694 Mpi2SasDevicePage0_t sas_device_pg0;
6695 Mpi2SasEnclosurePage0_t enclosure_pg0;
6698 u8 device_missing_delay;
6699 u8 num_phys, port_id;
6700 struct hba_port *port;
6702 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
6704 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6705 __FILE__, __LINE__, __func__);
6709 ioc->sas_hba.nr_phys_allocated = max_t(u8,
6710 MPT_MAX_HBA_NUM_PHYS, num_phys);
6711 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.nr_phys_allocated,
6712 sizeof(struct _sas_phy), GFP_KERNEL);
6713 if (!ioc->sas_hba.phy) {
6714 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6715 __FILE__, __LINE__, __func__);
6718 ioc->sas_hba.num_phys = num_phys;
6720 /* sas_iounit page 0 */
6721 sz = struct_size(sas_iounit_pg0, PhyData, ioc->sas_hba.num_phys);
6722 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
6723 if (!sas_iounit_pg0) {
6724 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6725 __FILE__, __LINE__, __func__);
6728 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
6729 sas_iounit_pg0, sz))) {
6730 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6731 __FILE__, __LINE__, __func__);
6734 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6735 MPI2_IOCSTATUS_MASK;
6736 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6737 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6738 __FILE__, __LINE__, __func__);
6742 /* sas_iounit page 1 */
6743 sz = struct_size(sas_iounit_pg1, PhyData, ioc->sas_hba.num_phys);
6744 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
6745 if (!sas_iounit_pg1) {
6746 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6747 __FILE__, __LINE__, __func__);
6750 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
6751 sas_iounit_pg1, sz))) {
6752 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6753 __FILE__, __LINE__, __func__);
6756 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6757 MPI2_IOCSTATUS_MASK;
6758 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6759 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6760 __FILE__, __LINE__, __func__);
6764 ioc->io_missing_delay =
6765 sas_iounit_pg1->IODeviceMissingDelay;
6766 device_missing_delay =
6767 sas_iounit_pg1->ReportDeviceMissingDelay;
6768 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
6769 ioc->device_missing_delay = (device_missing_delay &
6770 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
6772 ioc->device_missing_delay = device_missing_delay &
6773 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
6775 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
6776 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
6777 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
6779 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6780 __FILE__, __LINE__, __func__);
6783 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6784 MPI2_IOCSTATUS_MASK;
6785 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6786 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6787 __FILE__, __LINE__, __func__);
6792 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
6793 PhyData[0].ControllerDevHandle);
6795 port_id = sas_iounit_pg0->PhyData[i].Port;
6796 if (!(mpt3sas_get_port_by_id(ioc, port_id, 0))) {
6797 port = kzalloc(sizeof(struct hba_port), GFP_KERNEL);
6801 port->port_id = port_id;
6803 "hba_port entry: %p, port: %d is added to hba_port list\n",
6804 port, port->port_id);
6805 list_add_tail(&port->list,
6806 &ioc->port_table_list);
6810 * Check whether current Phy belongs to HBA vSES device or not.
6812 if ((le32_to_cpu(phy_pg0.PhyInfo) &
6813 MPI2_SAS_PHYINFO_VIRTUAL_PHY) &&
6814 (phy_pg0.NegotiatedLinkRate >> 4) >=
6815 MPI2_SAS_NEG_LINK_RATE_1_5) {
6817 * Allocate a virtual_phy object for vSES device.
6819 if (!_scsih_alloc_vphy(ioc, port_id, i))
6821 ioc->sas_hba.phy[i].hba_vphy = 1;
6824 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
6825 ioc->sas_hba.phy[i].phy_id = i;
6826 ioc->sas_hba.phy[i].port =
6827 mpt3sas_get_port_by_id(ioc, port_id, 0);
6828 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
6829 phy_pg0, ioc->sas_hba.parent_dev);
6831 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6832 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
6833 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6834 __FILE__, __LINE__, __func__);
6837 ioc->sas_hba.enclosure_handle =
6838 le16_to_cpu(sas_device_pg0.EnclosureHandle);
6839 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6840 ioc_info(ioc, "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
6841 ioc->sas_hba.handle,
6842 (u64)ioc->sas_hba.sas_address,
6843 ioc->sas_hba.num_phys);
6845 if (ioc->sas_hba.enclosure_handle) {
6846 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
6847 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
6848 ioc->sas_hba.enclosure_handle)))
6849 ioc->sas_hba.enclosure_logical_id =
6850 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
6854 kfree(sas_iounit_pg1);
6855 kfree(sas_iounit_pg0);
6859 * _scsih_expander_add - creating expander object
6860 * @ioc: per adapter object
6861 * @handle: expander handle
6863 * Creating expander object, stored in ioc->sas_expander_list.
6865 * Return: 0 for success, else error.
6868 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6870 struct _sas_node *sas_expander;
6871 struct _enclosure_node *enclosure_dev;
6872 Mpi2ConfigReply_t mpi_reply;
6873 Mpi2ExpanderPage0_t expander_pg0;
6874 Mpi2ExpanderPage1_t expander_pg1;
6877 u64 sas_address, sas_address_parent = 0;
6879 unsigned long flags;
6880 struct _sas_port *mpt3sas_port = NULL;
6888 if (ioc->shost_recovery || ioc->pci_error_recovery)
6891 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6892 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
6893 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6894 __FILE__, __LINE__, __func__);
6898 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6899 MPI2_IOCSTATUS_MASK;
6900 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6901 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6902 __FILE__, __LINE__, __func__);
6906 /* handle out of order topology events */
6907 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
6908 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
6910 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6911 __FILE__, __LINE__, __func__);
6915 port_id = expander_pg0.PhysicalPort;
6916 if (sas_address_parent != ioc->sas_hba.sas_address) {
6917 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6918 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
6920 mpt3sas_get_port_by_id(ioc, port_id, 0));
6921 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6922 if (!sas_expander) {
6923 rc = _scsih_expander_add(ioc, parent_handle);
6929 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6930 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6931 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
6932 sas_address, mpt3sas_get_port_by_id(ioc, port_id, 0));
6933 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6938 sas_expander = kzalloc(sizeof(struct _sas_node),
6940 if (!sas_expander) {
6941 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6942 __FILE__, __LINE__, __func__);
6946 sas_expander->handle = handle;
6947 sas_expander->num_phys = expander_pg0.NumPhys;
6948 sas_expander->sas_address_parent = sas_address_parent;
6949 sas_expander->sas_address = sas_address;
6950 sas_expander->port = mpt3sas_get_port_by_id(ioc, port_id, 0);
6951 if (!sas_expander->port) {
6952 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6953 __FILE__, __LINE__, __func__);
6958 ioc_info(ioc, "expander_add: handle(0x%04x), parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
6959 handle, parent_handle,
6960 (u64)sas_expander->sas_address, sas_expander->num_phys);
6962 if (!sas_expander->num_phys) {
6966 sas_expander->phy = kcalloc(sas_expander->num_phys,
6967 sizeof(struct _sas_phy), GFP_KERNEL);
6968 if (!sas_expander->phy) {
6969 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6970 __FILE__, __LINE__, __func__);
6975 INIT_LIST_HEAD(&sas_expander->sas_port_list);
6976 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
6977 sas_address_parent, sas_expander->port);
6978 if (!mpt3sas_port) {
6979 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6980 __FILE__, __LINE__, __func__);
6984 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
6985 sas_expander->rphy = mpt3sas_port->rphy;
6987 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6988 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
6989 &expander_pg1, i, handle))) {
6990 ioc_err(ioc, "failure at %s:%d/%s()!\n",
6991 __FILE__, __LINE__, __func__);
6995 sas_expander->phy[i].handle = handle;
6996 sas_expander->phy[i].phy_id = i;
6997 sas_expander->phy[i].port =
6998 mpt3sas_get_port_by_id(ioc, port_id, 0);
7000 if ((mpt3sas_transport_add_expander_phy(ioc,
7001 &sas_expander->phy[i], expander_pg1,
7002 sas_expander->parent_dev))) {
7003 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7004 __FILE__, __LINE__, __func__);
7010 if (sas_expander->enclosure_handle) {
7012 mpt3sas_scsih_enclosure_find_by_handle(ioc,
7013 sas_expander->enclosure_handle);
7015 sas_expander->enclosure_logical_id =
7016 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
7019 _scsih_expander_node_add(ioc, sas_expander);
7025 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7026 sas_address_parent, sas_expander->port);
7027 kfree(sas_expander);
7032 * mpt3sas_expander_remove - removing expander object
7033 * @ioc: per adapter object
7034 * @sas_address: expander sas_address
7035 * @port: hba port entry
7038 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7039 struct hba_port *port)
7041 struct _sas_node *sas_expander;
7042 unsigned long flags;
7044 if (ioc->shost_recovery)
7050 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7051 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
7053 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7055 _scsih_expander_node_remove(ioc, sas_expander);
7059 * _scsih_done - internal SCSI_IO callback handler.
7060 * @ioc: per adapter object
7061 * @smid: system request message index
7062 * @msix_index: MSIX table index supplied by the OS
7063 * @reply: reply message frame(lower 32bit addr)
7065 * Callback handler when sending internal generated SCSI_IO.
7066 * The callback index passed is `ioc->scsih_cb_idx`
7068 * Return: 1 meaning mf should be freed from _base_interrupt
7069 * 0 means the mf is freed from this function.
7072 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
7074 MPI2DefaultReply_t *mpi_reply;
7076 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7077 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
7079 if (ioc->scsih_cmds.smid != smid)
7081 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
7083 memcpy(ioc->scsih_cmds.reply, mpi_reply,
7084 mpi_reply->MsgLength*4);
7085 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
7087 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
7088 complete(&ioc->scsih_cmds.done);
7095 #define MPT3_MAX_LUNS (255)
7099 * _scsih_check_access_status - check access flags
7100 * @ioc: per adapter object
7101 * @sas_address: sas address
7102 * @handle: sas device handle
7103 * @access_status: errors returned during discovery of the device
7105 * Return: 0 for success, else failure
7108 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7109 u16 handle, u8 access_status)
7114 switch (access_status) {
7115 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
7116 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
7119 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
7120 desc = "sata capability failed";
7122 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
7123 desc = "sata affiliation conflict";
7125 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
7126 desc = "route not addressable";
7128 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
7129 desc = "smp error not addressable";
7131 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
7132 desc = "device blocked";
7134 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
7135 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
7136 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
7137 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
7138 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
7139 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
7140 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
7141 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
7142 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
7143 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
7144 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
7145 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
7146 desc = "sata initialization failed";
7156 ioc_err(ioc, "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
7157 desc, (u64)sas_address, handle);
7162 * _scsih_check_device - checking device responsiveness
7163 * @ioc: per adapter object
7164 * @parent_sas_address: sas address of parent expander or sas host
7165 * @handle: attached device handle
7166 * @phy_number: phy number
7167 * @link_rate: new link rate
7170 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
7171 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
7173 Mpi2ConfigReply_t mpi_reply;
7174 Mpi2SasDevicePage0_t sas_device_pg0;
7175 struct _sas_device *sas_device = NULL;
7176 struct _enclosure_node *enclosure_dev = NULL;
7178 unsigned long flags;
7180 struct scsi_target *starget;
7181 struct MPT3SAS_TARGET *sas_target_priv_data;
7183 struct hba_port *port;
7185 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
7186 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
7189 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
7190 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7193 /* wide port handling ~ we need only handle device once for the phy that
7194 * is matched in sas device page zero
7196 if (phy_number != sas_device_pg0.PhyNum)
7199 /* check if this is end device */
7200 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
7201 if (!(_scsih_is_end_device(device_info)))
7204 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7205 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
7206 port = mpt3sas_get_port_by_id(ioc, sas_device_pg0.PhysicalPort, 0);
7209 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
7215 if (unlikely(sas_device->handle != handle)) {
7216 starget = sas_device->starget;
7217 sas_target_priv_data = starget->hostdata;
7218 starget_printk(KERN_INFO, starget,
7219 "handle changed from(0x%04x) to (0x%04x)!!!\n",
7220 sas_device->handle, handle);
7221 sas_target_priv_data->handle = handle;
7222 sas_device->handle = handle;
7223 if (le16_to_cpu(sas_device_pg0.Flags) &
7224 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
7225 sas_device->enclosure_level =
7226 sas_device_pg0.EnclosureLevel;
7227 memcpy(sas_device->connector_name,
7228 sas_device_pg0.ConnectorName, 4);
7229 sas_device->connector_name[4] = '\0';
7231 sas_device->enclosure_level = 0;
7232 sas_device->connector_name[0] = '\0';
7235 sas_device->enclosure_handle =
7236 le16_to_cpu(sas_device_pg0.EnclosureHandle);
7237 sas_device->is_chassis_slot_valid = 0;
7238 enclosure_dev = mpt3sas_scsih_enclosure_find_by_handle(ioc,
7239 sas_device->enclosure_handle);
7240 if (enclosure_dev) {
7241 sas_device->enclosure_logical_id =
7242 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
7243 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
7244 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
7245 sas_device->is_chassis_slot_valid = 1;
7246 sas_device->chassis_slot =
7247 enclosure_dev->pg0.ChassisSlot;
7252 /* check if device is present */
7253 if (!(le16_to_cpu(sas_device_pg0.Flags) &
7254 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
7255 ioc_err(ioc, "device is not present handle(0x%04x), flags!!!\n",
7260 /* check if there were any issues with discovery */
7261 if (_scsih_check_access_status(ioc, sas_address, handle,
7262 sas_device_pg0.AccessStatus))
7265 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7266 _scsih_ublock_io_device(ioc, sas_address, port);
7269 sas_device_put(sas_device);
7273 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7275 sas_device_put(sas_device);
7279 * _scsih_add_device - creating sas device object
7280 * @ioc: per adapter object
7281 * @handle: sas device handle
7282 * @phy_num: phy number end device attached to
7283 * @is_pd: is this hidden raid component
7285 * Creating end device object, stored in ioc->sas_device_list.
7287 * Return: 0 for success, non-zero for failure.
7290 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
7293 Mpi2ConfigReply_t mpi_reply;
7294 Mpi2SasDevicePage0_t sas_device_pg0;
7295 struct _sas_device *sas_device;
7296 struct _enclosure_node *enclosure_dev = NULL;
7302 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
7303 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
7304 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7305 __FILE__, __LINE__, __func__);
7309 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7310 MPI2_IOCSTATUS_MASK;
7311 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7312 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7313 __FILE__, __LINE__, __func__);
7317 /* check if this is end device */
7318 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
7319 if (!(_scsih_is_end_device(device_info)))
7321 set_bit(handle, ioc->pend_os_device_add);
7322 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
7324 /* check if device is present */
7325 if (!(le16_to_cpu(sas_device_pg0.Flags) &
7326 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
7327 ioc_err(ioc, "device is not present handle(0x04%x)!!!\n",
7332 /* check if there were any issues with discovery */
7333 if (_scsih_check_access_status(ioc, sas_address, handle,
7334 sas_device_pg0.AccessStatus))
7337 port_id = sas_device_pg0.PhysicalPort;
7338 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7339 sas_address, mpt3sas_get_port_by_id(ioc, port_id, 0));
7341 clear_bit(handle, ioc->pend_os_device_add);
7342 sas_device_put(sas_device);
7346 if (sas_device_pg0.EnclosureHandle) {
7348 mpt3sas_scsih_enclosure_find_by_handle(ioc,
7349 le16_to_cpu(sas_device_pg0.EnclosureHandle));
7350 if (enclosure_dev == NULL)
7351 ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
7352 sas_device_pg0.EnclosureHandle);
7355 sas_device = kzalloc(sizeof(struct _sas_device),
7358 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7359 __FILE__, __LINE__, __func__);
7363 kref_init(&sas_device->refcount);
7364 sas_device->handle = handle;
7365 if (_scsih_get_sas_address(ioc,
7366 le16_to_cpu(sas_device_pg0.ParentDevHandle),
7367 &sas_device->sas_address_parent) != 0)
7368 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7369 __FILE__, __LINE__, __func__);
7370 sas_device->enclosure_handle =
7371 le16_to_cpu(sas_device_pg0.EnclosureHandle);
7372 if (sas_device->enclosure_handle != 0)
7374 le16_to_cpu(sas_device_pg0.Slot);
7375 sas_device->device_info = device_info;
7376 sas_device->sas_address = sas_address;
7377 sas_device->phy = sas_device_pg0.PhyNum;
7378 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
7379 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
7380 sas_device->port = mpt3sas_get_port_by_id(ioc, port_id, 0);
7381 if (!sas_device->port) {
7382 ioc_err(ioc, "failure at %s:%d/%s()!\n",
7383 __FILE__, __LINE__, __func__);
7387 if (le16_to_cpu(sas_device_pg0.Flags)
7388 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
7389 sas_device->enclosure_level =
7390 sas_device_pg0.EnclosureLevel;
7391 memcpy(sas_device->connector_name,
7392 sas_device_pg0.ConnectorName, 4);
7393 sas_device->connector_name[4] = '\0';
7395 sas_device->enclosure_level = 0;
7396 sas_device->connector_name[0] = '\0';
7398 /* get enclosure_logical_id & chassis_slot*/
7399 sas_device->is_chassis_slot_valid = 0;
7400 if (enclosure_dev) {
7401 sas_device->enclosure_logical_id =
7402 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
7403 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
7404 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
7405 sas_device->is_chassis_slot_valid = 1;
7406 sas_device->chassis_slot =
7407 enclosure_dev->pg0.ChassisSlot;
7411 /* get device name */
7412 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
7413 sas_device->port_type = sas_device_pg0.MaxPortConnections;
7415 "handle(0x%0x) sas_address(0x%016llx) port_type(0x%0x)\n",
7416 handle, sas_device->sas_address, sas_device->port_type);
7418 if (ioc->wait_for_discovery_to_complete)
7419 _scsih_sas_device_init_add(ioc, sas_device);
7421 _scsih_sas_device_add(ioc, sas_device);
7424 sas_device_put(sas_device);
7429 * _scsih_remove_device - removing sas device object
7430 * @ioc: per adapter object
7431 * @sas_device: the sas_device object
7434 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
7435 struct _sas_device *sas_device)
7437 struct MPT3SAS_TARGET *sas_target_priv_data;
7439 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
7440 (sas_device->pfa_led_on)) {
7441 _scsih_turn_off_pfa_led(ioc, sas_device);
7442 sas_device->pfa_led_on = 0;
7446 ioc_info(ioc, "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
7448 sas_device->handle, (u64)sas_device->sas_address));
7450 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
7453 if (sas_device->starget && sas_device->starget->hostdata) {
7454 sas_target_priv_data = sas_device->starget->hostdata;
7455 sas_target_priv_data->deleted = 1;
7456 _scsih_ublock_io_device(ioc, sas_device->sas_address,
7458 sas_target_priv_data->handle =
7459 MPT3SAS_INVALID_DEVICE_HANDLE;
7462 if (!ioc->hide_drives)
7463 mpt3sas_transport_port_remove(ioc,
7464 sas_device->sas_address,
7465 sas_device->sas_address_parent,
7468 ioc_info(ioc, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
7469 sas_device->handle, (u64)sas_device->sas_address);
7471 _scsih_display_enclosure_chassis_info(ioc, sas_device, NULL, NULL);
7474 ioc_info(ioc, "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
7476 sas_device->handle, (u64)sas_device->sas_address));
7477 dewtprintk(ioc, _scsih_display_enclosure_chassis_info(ioc, sas_device,
7482 * _scsih_sas_topology_change_event_debug - debug for topology event
7483 * @ioc: per adapter object
7484 * @event_data: event data payload
7488 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7489 Mpi2EventDataSasTopologyChangeList_t *event_data)
7495 char *status_str = NULL;
7496 u8 link_rate, prev_link_rate;
7498 switch (event_data->ExpStatus) {
7499 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
7502 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
7503 status_str = "remove";
7505 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
7507 status_str = "responding";
7509 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
7510 status_str = "remove delay";
7513 status_str = "unknown status";
7516 ioc_info(ioc, "sas topology change: (%s)\n", status_str);
7517 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
7518 "start_phy(%02d), count(%d)\n",
7519 le16_to_cpu(event_data->ExpanderDevHandle),
7520 le16_to_cpu(event_data->EnclosureHandle),
7521 event_data->StartPhyNum, event_data->NumEntries);
7522 for (i = 0; i < event_data->NumEntries; i++) {
7523 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
7526 phy_number = event_data->StartPhyNum + i;
7527 reason_code = event_data->PHY[i].PhyStatus &
7528 MPI2_EVENT_SAS_TOPO_RC_MASK;
7529 switch (reason_code) {
7530 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
7531 status_str = "target add";
7533 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
7534 status_str = "target remove";
7536 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
7537 status_str = "delay target remove";
7539 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
7540 status_str = "link rate change";
7542 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
7543 status_str = "target responding";
7546 status_str = "unknown";
7549 link_rate = event_data->PHY[i].LinkRate >> 4;
7550 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
7551 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
7552 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
7553 handle, status_str, link_rate, prev_link_rate);
7559 * _scsih_sas_topology_change_event - handle topology changes
7560 * @ioc: per adapter object
7561 * @fw_event: The fw_event_work object
7566 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
7567 struct fw_event_work *fw_event)
7570 u16 parent_handle, handle;
7572 u8 phy_number, max_phys;
7573 struct _sas_node *sas_expander;
7575 unsigned long flags;
7576 u8 link_rate, prev_link_rate;
7577 struct hba_port *port;
7578 Mpi2EventDataSasTopologyChangeList_t *event_data =
7579 (Mpi2EventDataSasTopologyChangeList_t *)
7580 fw_event->event_data;
7582 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7583 _scsih_sas_topology_change_event_debug(ioc, event_data);
7585 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
7588 if (!ioc->sas_hba.num_phys)
7589 _scsih_sas_host_add(ioc);
7591 _scsih_sas_host_refresh(ioc);
7593 if (fw_event->ignore) {
7594 dewtprintk(ioc, ioc_info(ioc, "ignoring expander event\n"));
7598 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
7599 port = mpt3sas_get_port_by_id(ioc, event_data->PhysicalPort, 0);
7601 /* handle expander add */
7602 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
7603 if (_scsih_expander_add(ioc, parent_handle) != 0)
7606 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7607 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
7610 sas_address = sas_expander->sas_address;
7611 max_phys = sas_expander->num_phys;
7612 port = sas_expander->port;
7613 } else if (parent_handle < ioc->sas_hba.num_phys) {
7614 sas_address = ioc->sas_hba.sas_address;
7615 max_phys = ioc->sas_hba.num_phys;
7617 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7620 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7622 /* handle siblings events */
7623 for (i = 0; i < event_data->NumEntries; i++) {
7624 if (fw_event->ignore) {
7626 ioc_info(ioc, "ignoring expander event\n"));
7629 if (ioc->remove_host || ioc->pci_error_recovery)
7631 phy_number = event_data->StartPhyNum + i;
7632 if (phy_number >= max_phys)
7634 reason_code = event_data->PHY[i].PhyStatus &
7635 MPI2_EVENT_SAS_TOPO_RC_MASK;
7636 if ((event_data->PHY[i].PhyStatus &
7637 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
7638 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
7640 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
7643 link_rate = event_data->PHY[i].LinkRate >> 4;
7644 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
7645 switch (reason_code) {
7646 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
7648 if (ioc->shost_recovery)
7651 if (link_rate == prev_link_rate)
7654 mpt3sas_transport_update_links(ioc, sas_address,
7655 handle, phy_number, link_rate, port);
7657 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
7660 _scsih_check_device(ioc, sas_address, handle,
7661 phy_number, link_rate);
7663 if (!test_bit(handle, ioc->pend_os_device_add))
7668 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
7670 if (ioc->shost_recovery)
7673 mpt3sas_transport_update_links(ioc, sas_address,
7674 handle, phy_number, link_rate, port);
7676 _scsih_add_device(ioc, handle, phy_number, 0);
7679 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
7681 _scsih_device_remove_by_handle(ioc, handle);
7686 /* handle expander removal */
7687 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
7689 mpt3sas_expander_remove(ioc, sas_address, port);
7695 * _scsih_sas_device_status_change_event_debug - debug for device event
7697 * @event_data: event data payload
7701 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
7702 Mpi2EventDataSasDeviceStatusChange_t *event_data)
7704 char *reason_str = NULL;
7706 switch (event_data->ReasonCode) {
7707 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
7708 reason_str = "smart data";
7710 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
7711 reason_str = "unsupported device discovered";
7713 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
7714 reason_str = "internal device reset";
7716 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
7717 reason_str = "internal task abort";
7719 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
7720 reason_str = "internal task abort set";
7722 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
7723 reason_str = "internal clear task set";
7725 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
7726 reason_str = "internal query task";
7728 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
7729 reason_str = "sata init failure";
7731 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
7732 reason_str = "internal device reset complete";
7734 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
7735 reason_str = "internal task abort complete";
7737 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
7738 reason_str = "internal async notification";
7740 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
7741 reason_str = "expander reduced functionality";
7743 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
7744 reason_str = "expander reduced functionality complete";
7747 reason_str = "unknown reason";
7750 ioc_info(ioc, "device status change: (%s)\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
7751 reason_str, le16_to_cpu(event_data->DevHandle),
7752 (u64)le64_to_cpu(event_data->SASAddress),
7753 le16_to_cpu(event_data->TaskTag));
7754 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
7755 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
7756 event_data->ASC, event_data->ASCQ);
7761 * _scsih_sas_device_status_change_event - handle device status change
7762 * @ioc: per adapter object
7763 * @event_data: The fw event
7767 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
7768 Mpi2EventDataSasDeviceStatusChange_t *event_data)
7770 struct MPT3SAS_TARGET *target_priv_data;
7771 struct _sas_device *sas_device;
7773 unsigned long flags;
7775 /* In MPI Revision K (0xC), the internal device reset complete was
7776 * implemented, so avoid setting tm_busy flag for older firmware.
7778 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
7781 if (event_data->ReasonCode !=
7782 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
7783 event_data->ReasonCode !=
7784 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
7787 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7788 sas_address = le64_to_cpu(event_data->SASAddress);
7789 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
7791 mpt3sas_get_port_by_id(ioc, event_data->PhysicalPort, 0));
7793 if (!sas_device || !sas_device->starget)
7796 target_priv_data = sas_device->starget->hostdata;
7797 if (!target_priv_data)
7800 if (event_data->ReasonCode ==
7801 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
7802 target_priv_data->tm_busy = 1;
7804 target_priv_data->tm_busy = 0;
7806 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
7808 "%s tm_busy flag for handle(0x%04x)\n",
7809 (target_priv_data->tm_busy == 1) ? "Enable" : "Disable",
7810 target_priv_data->handle);
7814 sas_device_put(sas_device);
7816 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7821 * _scsih_check_pcie_access_status - check access flags
7822 * @ioc: per adapter object
7824 * @handle: sas device handle
7825 * @access_status: errors returned during discovery of the device
7827 * Return: 0 for success, else failure
7830 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
7831 u16 handle, u8 access_status)
7836 switch (access_status) {
7837 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS:
7838 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION:
7841 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED:
7842 desc = "PCIe device capability failed";
7844 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED:
7845 desc = "PCIe device blocked";
7847 "Device with Access Status (%s): wwid(0x%016llx), "
7848 "handle(0x%04x)\n ll only be added to the internal list",
7849 desc, (u64)wwid, handle);
7852 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED:
7853 desc = "PCIe device mem space access failed";
7855 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE:
7856 desc = "PCIe device unsupported";
7858 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED:
7859 desc = "PCIe device MSIx Required";
7861 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX:
7862 desc = "PCIe device init fail max";
7864 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN:
7865 desc = "PCIe device status unknown";
7867 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT:
7868 desc = "nvme ready timeout";
7870 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED:
7871 desc = "nvme device configuration unsupported";
7873 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED:
7874 desc = "nvme identify failed";
7876 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED:
7877 desc = "nvme qconfig failed";
7879 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED:
7880 desc = "nvme qcreation failed";
7882 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED:
7883 desc = "nvme eventcfg failed";
7885 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED:
7886 desc = "nvme get feature stat failed";
7888 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT:
7889 desc = "nvme idle timeout";
7891 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS:
7892 desc = "nvme failure status";
7895 ioc_err(ioc, "NVMe discovery error(0x%02x): wwid(0x%016llx), handle(0x%04x)\n",
7896 access_status, (u64)wwid, handle);
7903 ioc_info(ioc, "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
7904 desc, (u64)wwid, handle);
7909 * _scsih_pcie_device_remove_from_sml - removing pcie device
7910 * from SML and free up associated memory
7911 * @ioc: per adapter object
7912 * @pcie_device: the pcie_device object
7915 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER *ioc,
7916 struct _pcie_device *pcie_device)
7918 struct MPT3SAS_TARGET *sas_target_priv_data;
7921 ioc_info(ioc, "%s: enter: handle(0x%04x), wwid(0x%016llx)\n",
7923 pcie_device->handle, (u64)pcie_device->wwid));
7924 if (pcie_device->enclosure_handle != 0)
7926 ioc_info(ioc, "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
7928 (u64)pcie_device->enclosure_logical_id,
7929 pcie_device->slot));
7930 if (pcie_device->connector_name[0] != '\0')
7932 ioc_info(ioc, "%s: enter: enclosure level(0x%04x), connector name(%s)\n",
7934 pcie_device->enclosure_level,
7935 pcie_device->connector_name));
7937 if (pcie_device->starget && pcie_device->starget->hostdata) {
7938 sas_target_priv_data = pcie_device->starget->hostdata;
7939 sas_target_priv_data->deleted = 1;
7940 _scsih_ublock_io_device(ioc, pcie_device->wwid, NULL);
7941 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
7944 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
7945 pcie_device->handle, (u64)pcie_device->wwid);
7946 if (pcie_device->enclosure_handle != 0)
7947 ioc_info(ioc, "removing : enclosure logical id(0x%016llx), slot(%d)\n",
7948 (u64)pcie_device->enclosure_logical_id,
7950 if (pcie_device->connector_name[0] != '\0')
7951 ioc_info(ioc, "removing: enclosure level(0x%04x), connector name( %s)\n",
7952 pcie_device->enclosure_level,
7953 pcie_device->connector_name);
7955 if (pcie_device->starget && (pcie_device->access_status !=
7956 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED))
7957 scsi_remove_target(&pcie_device->starget->dev);
7959 ioc_info(ioc, "%s: exit: handle(0x%04x), wwid(0x%016llx)\n",
7961 pcie_device->handle, (u64)pcie_device->wwid));
7962 if (pcie_device->enclosure_handle != 0)
7964 ioc_info(ioc, "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
7966 (u64)pcie_device->enclosure_logical_id,
7967 pcie_device->slot));
7968 if (pcie_device->connector_name[0] != '\0')
7970 ioc_info(ioc, "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
7972 pcie_device->enclosure_level,
7973 pcie_device->connector_name));
7975 kfree(pcie_device->serial_number);
7980 * _scsih_pcie_check_device - checking device responsiveness
7981 * @ioc: per adapter object
7982 * @handle: attached device handle
7985 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
7987 Mpi2ConfigReply_t mpi_reply;
7988 Mpi26PCIeDevicePage0_t pcie_device_pg0;
7990 struct _pcie_device *pcie_device;
7992 unsigned long flags;
7993 struct scsi_target *starget;
7994 struct MPT3SAS_TARGET *sas_target_priv_data;
7997 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
7998 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle)))
8001 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
8002 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
8005 /* check if this is end device */
8006 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
8007 if (!(_scsih_is_nvme_pciescsi_device(device_info)))
8010 wwid = le64_to_cpu(pcie_device_pg0.WWID);
8011 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8012 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
8015 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8019 if (unlikely(pcie_device->handle != handle)) {
8020 starget = pcie_device->starget;
8021 sas_target_priv_data = starget->hostdata;
8022 pcie_device->access_status = pcie_device_pg0.AccessStatus;
8023 starget_printk(KERN_INFO, starget,
8024 "handle changed from(0x%04x) to (0x%04x)!!!\n",
8025 pcie_device->handle, handle);
8026 sas_target_priv_data->handle = handle;
8027 pcie_device->handle = handle;
8029 if (le32_to_cpu(pcie_device_pg0.Flags) &
8030 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
8031 pcie_device->enclosure_level =
8032 pcie_device_pg0.EnclosureLevel;
8033 memcpy(&pcie_device->connector_name[0],
8034 &pcie_device_pg0.ConnectorName[0], 4);
8036 pcie_device->enclosure_level = 0;
8037 pcie_device->connector_name[0] = '\0';
8041 /* check if device is present */
8042 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
8043 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
8044 ioc_info(ioc, "device is not present handle(0x%04x), flags!!!\n",
8046 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8047 pcie_device_put(pcie_device);
8051 /* check if there were any issues with discovery */
8052 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
8053 pcie_device_pg0.AccessStatus)) {
8054 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8055 pcie_device_put(pcie_device);
8059 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8060 pcie_device_put(pcie_device);
8062 _scsih_ublock_io_device(ioc, wwid, NULL);
8068 * _scsih_pcie_add_device - creating pcie device object
8069 * @ioc: per adapter object
8070 * @handle: pcie device handle
8072 * Creating end device object, stored in ioc->pcie_device_list.
8074 * Return: 1 means queue the event later, 0 means complete the event
8077 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
8079 Mpi26PCIeDevicePage0_t pcie_device_pg0;
8080 Mpi26PCIeDevicePage2_t pcie_device_pg2;
8081 Mpi2ConfigReply_t mpi_reply;
8082 struct _pcie_device *pcie_device;
8083 struct _enclosure_node *enclosure_dev;
8087 if ((mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
8088 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE, handle))) {
8089 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8090 __FILE__, __LINE__, __func__);
8093 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8094 MPI2_IOCSTATUS_MASK;
8095 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8096 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8097 __FILE__, __LINE__, __func__);
8101 set_bit(handle, ioc->pend_os_device_add);
8102 wwid = le64_to_cpu(pcie_device_pg0.WWID);
8104 /* check if device is present */
8105 if (!(le32_to_cpu(pcie_device_pg0.Flags) &
8106 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT)) {
8107 ioc_err(ioc, "device is not present handle(0x04%x)!!!\n",
8112 /* check if there were any issues with discovery */
8113 if (_scsih_check_pcie_access_status(ioc, wwid, handle,
8114 pcie_device_pg0.AccessStatus))
8117 if (!(_scsih_is_nvme_pciescsi_device(le32_to_cpu
8118 (pcie_device_pg0.DeviceInfo))))
8121 pcie_device = mpt3sas_get_pdev_by_wwid(ioc, wwid);
8123 clear_bit(handle, ioc->pend_os_device_add);
8124 pcie_device_put(pcie_device);
8128 /* PCIe Device Page 2 contains read-only information about a
8129 * specific NVMe device; therefore, this page is only
8130 * valid for NVMe devices and skip for pcie devices of type scsi.
8132 if (!(mpt3sas_scsih_is_pcie_scsi_device(
8133 le32_to_cpu(pcie_device_pg0.DeviceInfo)))) {
8134 if (mpt3sas_config_get_pcie_device_pg2(ioc, &mpi_reply,
8135 &pcie_device_pg2, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
8138 "failure at %s:%d/%s()!\n", __FILE__,
8139 __LINE__, __func__);
8143 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
8144 MPI2_IOCSTATUS_MASK;
8145 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8147 "failure at %s:%d/%s()!\n", __FILE__,
8148 __LINE__, __func__);
8153 pcie_device = kzalloc(sizeof(struct _pcie_device), GFP_KERNEL);
8155 ioc_err(ioc, "failure at %s:%d/%s()!\n",
8156 __FILE__, __LINE__, __func__);
8160 kref_init(&pcie_device->refcount);
8161 pcie_device->id = ioc->pcie_target_id++;
8162 pcie_device->channel = PCIE_CHANNEL;
8163 pcie_device->handle = handle;
8164 pcie_device->access_status = pcie_device_pg0.AccessStatus;
8165 pcie_device->device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
8166 pcie_device->wwid = wwid;
8167 pcie_device->port_num = pcie_device_pg0.PortNum;
8168 pcie_device->fast_path = (le32_to_cpu(pcie_device_pg0.Flags) &
8169 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
8171 pcie_device->enclosure_handle =
8172 le16_to_cpu(pcie_device_pg0.EnclosureHandle);
8173 if (pcie_device->enclosure_handle != 0)
8174 pcie_device->slot = le16_to_cpu(pcie_device_pg0.Slot);
8176 if (le32_to_cpu(pcie_device_pg0.Flags) &
8177 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) {
8178 pcie_device->enclosure_level = pcie_device_pg0.EnclosureLevel;
8179 memcpy(&pcie_device->connector_name[0],
8180 &pcie_device_pg0.ConnectorName[0], 4);
8182 pcie_device->enclosure_level = 0;
8183 pcie_device->connector_name[0] = '\0';
8186 /* get enclosure_logical_id */
8187 if (pcie_device->enclosure_handle) {
8189 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8190 pcie_device->enclosure_handle);
8192 pcie_device->enclosure_logical_id =
8193 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
8195 /* TODO -- Add device name once FW supports it */
8196 if (!(mpt3sas_scsih_is_pcie_scsi_device(
8197 le32_to_cpu(pcie_device_pg0.DeviceInfo)))) {
8198 pcie_device->nvme_mdts =
8199 le32_to_cpu(pcie_device_pg2.MaximumDataTransferSize);
8200 pcie_device->shutdown_latency =
8201 le16_to_cpu(pcie_device_pg2.ShutdownLatency);
8203 * Set IOC's max_shutdown_latency to drive's RTD3 Entry Latency
8204 * if drive's RTD3 Entry Latency is greater then IOC's
8205 * max_shutdown_latency.
8207 if (pcie_device->shutdown_latency > ioc->max_shutdown_latency)
8208 ioc->max_shutdown_latency =
8209 pcie_device->shutdown_latency;
8210 if (pcie_device_pg2.ControllerResetTO)
8211 pcie_device->reset_timeout =
8212 pcie_device_pg2.ControllerResetTO;
8214 pcie_device->reset_timeout = 30;
8216 pcie_device->reset_timeout = 30;
8218 if (ioc->wait_for_discovery_to_complete)
8219 _scsih_pcie_device_init_add(ioc, pcie_device);
8221 _scsih_pcie_device_add(ioc, pcie_device);
8223 pcie_device_put(pcie_device);
8228 * _scsih_pcie_topology_change_event_debug - debug for topology
8230 * @ioc: per adapter object
8231 * @event_data: event data payload
8235 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
8236 Mpi26EventDataPCIeTopologyChangeList_t *event_data)
8242 char *status_str = NULL;
8243 u8 link_rate, prev_link_rate;
8245 switch (event_data->SwitchStatus) {
8246 case MPI26_EVENT_PCIE_TOPO_SS_ADDED:
8249 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING:
8250 status_str = "remove";
8252 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING:
8254 status_str = "responding";
8256 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING:
8257 status_str = "remove delay";
8260 status_str = "unknown status";
8263 ioc_info(ioc, "pcie topology change: (%s)\n", status_str);
8264 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
8265 "start_port(%02d), count(%d)\n",
8266 le16_to_cpu(event_data->SwitchDevHandle),
8267 le16_to_cpu(event_data->EnclosureHandle),
8268 event_data->StartPortNum, event_data->NumEntries);
8269 for (i = 0; i < event_data->NumEntries; i++) {
8271 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
8274 port_number = event_data->StartPortNum + i;
8275 reason_code = event_data->PortEntry[i].PortStatus;
8276 switch (reason_code) {
8277 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
8278 status_str = "target add";
8280 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
8281 status_str = "target remove";
8283 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING:
8284 status_str = "delay target remove";
8286 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
8287 status_str = "link rate change";
8289 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE:
8290 status_str = "target responding";
8293 status_str = "unknown";
8296 link_rate = event_data->PortEntry[i].CurrentPortInfo &
8297 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
8298 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo &
8299 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
8300 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
8301 " link rate: new(0x%02x), old(0x%02x)\n", port_number,
8302 handle, status_str, link_rate, prev_link_rate);
8307 * _scsih_pcie_topology_change_event - handle PCIe topology
8309 * @ioc: per adapter object
8310 * @fw_event: The fw_event_work object
8315 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
8316 struct fw_event_work *fw_event)
8321 u8 link_rate, prev_link_rate;
8322 unsigned long flags;
8324 Mpi26EventDataPCIeTopologyChangeList_t *event_data =
8325 (Mpi26EventDataPCIeTopologyChangeList_t *) fw_event->event_data;
8326 struct _pcie_device *pcie_device;
8328 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
8329 _scsih_pcie_topology_change_event_debug(ioc, event_data);
8331 if (ioc->shost_recovery || ioc->remove_host ||
8332 ioc->pci_error_recovery)
8335 if (fw_event->ignore) {
8336 dewtprintk(ioc, ioc_info(ioc, "ignoring switch event\n"));
8340 /* handle siblings events */
8341 for (i = 0; i < event_data->NumEntries; i++) {
8342 if (fw_event->ignore) {
8344 ioc_info(ioc, "ignoring switch event\n"));
8347 if (ioc->remove_host || ioc->pci_error_recovery)
8349 reason_code = event_data->PortEntry[i].PortStatus;
8351 le16_to_cpu(event_data->PortEntry[i].AttachedDevHandle);
8355 link_rate = event_data->PortEntry[i].CurrentPortInfo
8356 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
8357 prev_link_rate = event_data->PortEntry[i].PreviousPortInfo
8358 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK;
8360 switch (reason_code) {
8361 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED:
8362 if (ioc->shost_recovery)
8364 if (link_rate == prev_link_rate)
8366 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
8369 _scsih_pcie_check_device(ioc, handle);
8371 /* This code after this point handles the test case
8372 * where a device has been added, however its returning
8373 * BUSY for sometime. Then before the Device Missing
8374 * Delay expires and the device becomes READY, the
8375 * device is removed and added back.
8377 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8378 pcie_device = __mpt3sas_get_pdev_by_handle(ioc, handle);
8379 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8382 pcie_device_put(pcie_device);
8386 if (!test_bit(handle, ioc->pend_os_device_add))
8390 ioc_info(ioc, "handle(0x%04x) device not found: convert event to a device add\n",
8392 event_data->PortEntry[i].PortStatus &= 0xF0;
8393 event_data->PortEntry[i].PortStatus |=
8394 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED;
8396 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED:
8397 if (ioc->shost_recovery)
8399 if (link_rate < MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5)
8402 rc = _scsih_pcie_add_device(ioc, handle);
8404 /* mark entry vacant */
8405 /* TODO This needs to be reviewed and fixed,
8406 * we dont have an entry
8407 * to make an event void like vacant
8409 event_data->PortEntry[i].PortStatus |=
8410 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE;
8413 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING:
8414 _scsih_pcie_device_remove_by_handle(ioc, handle);
8421 * _scsih_pcie_device_status_change_event_debug - debug for device event
8423 * @event_data: event data payload
8427 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
8428 Mpi26EventDataPCIeDeviceStatusChange_t *event_data)
8430 char *reason_str = NULL;
8432 switch (event_data->ReasonCode) {
8433 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA:
8434 reason_str = "smart data";
8436 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED:
8437 reason_str = "unsupported device discovered";
8439 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET:
8440 reason_str = "internal device reset";
8442 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL:
8443 reason_str = "internal task abort";
8445 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
8446 reason_str = "internal task abort set";
8448 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
8449 reason_str = "internal clear task set";
8451 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL:
8452 reason_str = "internal query task";
8454 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE:
8455 reason_str = "device init failure";
8457 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
8458 reason_str = "internal device reset complete";
8460 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
8461 reason_str = "internal task abort complete";
8463 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION:
8464 reason_str = "internal async notification";
8466 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED:
8467 reason_str = "pcie hot reset failed";
8470 reason_str = "unknown reason";
8474 ioc_info(ioc, "PCIE device status change: (%s)\n"
8475 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
8476 reason_str, le16_to_cpu(event_data->DevHandle),
8477 (u64)le64_to_cpu(event_data->WWID),
8478 le16_to_cpu(event_data->TaskTag));
8479 if (event_data->ReasonCode == MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA)
8480 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
8481 event_data->ASC, event_data->ASCQ);
8486 * _scsih_pcie_device_status_change_event - handle device status
8488 * @ioc: per adapter object
8489 * @fw_event: The fw_event_work object
8493 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
8494 struct fw_event_work *fw_event)
8496 struct MPT3SAS_TARGET *target_priv_data;
8497 struct _pcie_device *pcie_device;
8499 unsigned long flags;
8500 Mpi26EventDataPCIeDeviceStatusChange_t *event_data =
8501 (Mpi26EventDataPCIeDeviceStatusChange_t *)fw_event->event_data;
8502 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
8503 _scsih_pcie_device_status_change_event_debug(ioc,
8506 if (event_data->ReasonCode !=
8507 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET &&
8508 event_data->ReasonCode !=
8509 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
8512 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
8513 wwid = le64_to_cpu(event_data->WWID);
8514 pcie_device = __mpt3sas_get_pdev_by_wwid(ioc, wwid);
8516 if (!pcie_device || !pcie_device->starget)
8519 target_priv_data = pcie_device->starget->hostdata;
8520 if (!target_priv_data)
8523 if (event_data->ReasonCode ==
8524 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET)
8525 target_priv_data->tm_busy = 1;
8527 target_priv_data->tm_busy = 0;
8530 pcie_device_put(pcie_device);
8532 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
8536 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
8538 * @ioc: per adapter object
8539 * @event_data: event data payload
8543 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
8544 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
8546 char *reason_str = NULL;
8548 switch (event_data->ReasonCode) {
8549 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
8550 reason_str = "enclosure add";
8552 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
8553 reason_str = "enclosure remove";
8556 reason_str = "unknown reason";
8560 ioc_info(ioc, "enclosure status change: (%s)\n"
8561 "\thandle(0x%04x), enclosure logical id(0x%016llx) number slots(%d)\n",
8563 le16_to_cpu(event_data->EnclosureHandle),
8564 (u64)le64_to_cpu(event_data->EnclosureLogicalID),
8565 le16_to_cpu(event_data->StartSlot));
8569 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
8570 * @ioc: per adapter object
8571 * @fw_event: The fw_event_work object
8575 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
8576 struct fw_event_work *fw_event)
8578 Mpi2ConfigReply_t mpi_reply;
8579 struct _enclosure_node *enclosure_dev = NULL;
8580 Mpi2EventDataSasEnclDevStatusChange_t *event_data =
8581 (Mpi2EventDataSasEnclDevStatusChange_t *)fw_event->event_data;
8583 u16 enclosure_handle = le16_to_cpu(event_data->EnclosureHandle);
8585 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
8586 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
8587 (Mpi2EventDataSasEnclDevStatusChange_t *)
8588 fw_event->event_data);
8589 if (ioc->shost_recovery)
8592 if (enclosure_handle)
8594 mpt3sas_scsih_enclosure_find_by_handle(ioc,
8596 switch (event_data->ReasonCode) {
8597 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
8598 if (!enclosure_dev) {
8600 kzalloc(sizeof(struct _enclosure_node),
8602 if (!enclosure_dev) {
8603 ioc_info(ioc, "failure at %s:%d/%s()!\n",
8604 __FILE__, __LINE__, __func__);
8607 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
8608 &enclosure_dev->pg0,
8609 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
8612 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
8613 MPI2_IOCSTATUS_MASK)) {
8614 kfree(enclosure_dev);
8618 list_add_tail(&enclosure_dev->list,
8619 &ioc->enclosure_list);
8622 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
8623 if (enclosure_dev) {
8624 list_del(&enclosure_dev->list);
8625 kfree(enclosure_dev);
8634 * _scsih_sas_broadcast_primitive_event - handle broadcast events
8635 * @ioc: per adapter object
8636 * @fw_event: The fw_event_work object
8640 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
8641 struct fw_event_work *fw_event)
8643 struct scsi_cmnd *scmd;
8644 struct scsi_device *sdev;
8645 struct scsiio_tracker *st;
8648 struct MPT3SAS_DEVICE *sas_device_priv_data;
8649 u32 termination_count;
8651 Mpi2SCSITaskManagementReply_t *mpi_reply;
8652 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
8653 (Mpi2EventDataSasBroadcastPrimitive_t *)
8654 fw_event->event_data;
8656 unsigned long flags;
8659 u8 task_abort_retries;
8661 mutex_lock(&ioc->tm_cmds.mutex);
8662 ioc_info(ioc, "%s: enter: phy number(%d), width(%d)\n",
8663 __func__, event_data->PhyNum, event_data->PortWidth);
8665 _scsih_block_io_all_device(ioc);
8667 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
8668 mpi_reply = ioc->tm_cmds.reply;
8669 broadcast_aen_retry:
8671 /* sanity checks for retrying this loop */
8672 if (max_retries++ == 5) {
8673 dewtprintk(ioc, ioc_info(ioc, "%s: giving up\n", __func__));
8675 } else if (max_retries > 1)
8677 ioc_info(ioc, "%s: %d retry\n",
8678 __func__, max_retries - 1));
8680 termination_count = 0;
8682 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
8683 if (ioc->shost_recovery)
8685 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
8688 st = scsi_cmd_priv(scmd);
8689 sdev = scmd->device;
8690 sas_device_priv_data = sdev->hostdata;
8691 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
8693 /* skip hidden raid components */
8694 if (sas_device_priv_data->sas_target->flags &
8695 MPT_TARGET_FLAGS_RAID_COMPONENT)
8698 if (sas_device_priv_data->sas_target->flags &
8699 MPT_TARGET_FLAGS_VOLUME)
8701 /* skip PCIe devices */
8702 if (sas_device_priv_data->sas_target->flags &
8703 MPT_TARGET_FLAGS_PCIE_DEVICE)
8706 handle = sas_device_priv_data->sas_target->handle;
8707 lun = sas_device_priv_data->lun;
8710 if (ioc->shost_recovery)
8713 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
8714 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
8715 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, st->smid,
8716 st->msix_io, 30, 0);
8718 sdev_printk(KERN_WARNING, sdev,
8719 "mpt3sas_scsih_issue_tm: FAILED when sending "
8720 "QUERY_TASK: scmd(%p)\n", scmd);
8721 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
8722 goto broadcast_aen_retry;
8724 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
8725 & MPI2_IOCSTATUS_MASK;
8726 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8727 sdev_printk(KERN_WARNING, sdev,
8728 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
8730 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
8731 goto broadcast_aen_retry;
8734 /* see if IO is still owned by IOC and target */
8735 if (mpi_reply->ResponseCode ==
8736 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
8737 mpi_reply->ResponseCode ==
8738 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
8739 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
8742 task_abort_retries = 0;
8744 if (task_abort_retries++ == 60) {
8746 ioc_info(ioc, "%s: ABORT_TASK: giving up\n",
8748 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
8749 goto broadcast_aen_retry;
8752 if (ioc->shost_recovery)
8755 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
8756 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
8757 st->smid, st->msix_io, 30, 0);
8758 if (r == FAILED || st->cb_idx != 0xFF) {
8759 sdev_printk(KERN_WARNING, sdev,
8760 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
8761 "scmd(%p)\n", scmd);
8765 if (task_abort_retries > 1)
8766 sdev_printk(KERN_WARNING, sdev,
8767 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
8769 task_abort_retries - 1, scmd);
8771 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
8772 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
8775 if (ioc->broadcast_aen_pending) {
8778 "%s: loop back due to pending AEN\n",
8780 ioc->broadcast_aen_pending = 0;
8781 goto broadcast_aen_retry;
8785 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
8789 ioc_info(ioc, "%s - exit, query_count = %d termination_count = %d\n",
8790 __func__, query_count, termination_count));
8792 ioc->broadcast_aen_busy = 0;
8793 if (!ioc->shost_recovery)
8794 _scsih_ublock_io_all_device(ioc);
8795 mutex_unlock(&ioc->tm_cmds.mutex);
8799 * _scsih_sas_discovery_event - handle discovery events
8800 * @ioc: per adapter object
8801 * @fw_event: The fw_event_work object
8805 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
8806 struct fw_event_work *fw_event)
8808 Mpi2EventDataSasDiscovery_t *event_data =
8809 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
8811 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
8812 ioc_info(ioc, "discovery event: (%s)",
8813 event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED ?
8815 if (event_data->DiscoveryStatus)
8816 pr_cont("discovery_status(0x%08x)",
8817 le32_to_cpu(event_data->DiscoveryStatus));
8821 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
8822 !ioc->sas_hba.num_phys) {
8823 if (disable_discovery > 0 && ioc->shost_recovery) {
8824 /* Wait for the reset to complete */
8825 while (ioc->shost_recovery)
8828 _scsih_sas_host_add(ioc);
8833 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
8835 * @ioc: per adapter object
8836 * @fw_event: The fw_event_work object
8840 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER *ioc,
8841 struct fw_event_work *fw_event)
8843 Mpi25EventDataSasDeviceDiscoveryError_t *event_data =
8844 (Mpi25EventDataSasDeviceDiscoveryError_t *)fw_event->event_data;
8846 switch (event_data->ReasonCode) {
8847 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED:
8848 ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has failed\n",
8849 le16_to_cpu(event_data->DevHandle),
8850 (u64)le64_to_cpu(event_data->SASAddress),
8851 event_data->PhysicalPort);
8853 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT:
8854 ioc_warn(ioc, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has timed out\n",
8855 le16_to_cpu(event_data->DevHandle),
8856 (u64)le64_to_cpu(event_data->SASAddress),
8857 event_data->PhysicalPort);
8865 * _scsih_pcie_enumeration_event - handle enumeration events
8866 * @ioc: per adapter object
8867 * @fw_event: The fw_event_work object
8871 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER *ioc,
8872 struct fw_event_work *fw_event)
8874 Mpi26EventDataPCIeEnumeration_t *event_data =
8875 (Mpi26EventDataPCIeEnumeration_t *)fw_event->event_data;
8877 if (!(ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK))
8880 ioc_info(ioc, "pcie enumeration event: (%s) Flag 0x%02x",
8881 (event_data->ReasonCode == MPI26_EVENT_PCIE_ENUM_RC_STARTED) ?
8882 "started" : "completed",
8884 if (event_data->EnumerationStatus)
8885 pr_cont("enumeration_status(0x%08x)",
8886 le32_to_cpu(event_data->EnumerationStatus));
8891 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
8892 * @ioc: per adapter object
8893 * @handle: device handle for physical disk
8894 * @phys_disk_num: physical disk number
8896 * Return: 0 for success, else failure.
8899 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
8901 Mpi2RaidActionRequest_t *mpi_request;
8902 Mpi2RaidActionReply_t *mpi_reply;
8909 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
8912 mutex_lock(&ioc->scsih_cmds.mutex);
8914 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
8915 ioc_err(ioc, "%s: scsih_cmd in use\n", __func__);
8919 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
8921 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
8923 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
8924 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8929 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
8930 ioc->scsih_cmds.smid = smid;
8931 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
8933 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
8934 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
8935 mpi_request->PhysDiskNum = phys_disk_num;
8938 ioc_info(ioc, "IR RAID_ACTION: turning fast path on for handle(0x%04x), phys_disk_num (0x%02x)\n",
8939 handle, phys_disk_num));
8941 init_completion(&ioc->scsih_cmds.done);
8942 ioc->put_smid_default(ioc, smid);
8943 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
8945 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
8946 mpt3sas_check_cmd_timeout(ioc,
8947 ioc->scsih_cmds.status, mpi_request,
8948 sizeof(Mpi2RaidActionRequest_t)/4, issue_reset);
8953 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
8955 mpi_reply = ioc->scsih_cmds.reply;
8956 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
8957 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
8958 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
8961 ioc_status &= MPI2_IOCSTATUS_MASK;
8962 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
8964 ioc_info(ioc, "IR RAID_ACTION: failed: ioc_status(0x%04x), loginfo(0x%08x)!!!\n",
8965 ioc_status, log_info));
8969 ioc_info(ioc, "IR RAID_ACTION: completed successfully\n"));
8973 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8974 mutex_unlock(&ioc->scsih_cmds.mutex);
8977 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
8982 * _scsih_reprobe_lun - reprobing lun
8983 * @sdev: scsi device struct
8984 * @no_uld_attach: sdev->no_uld_attach flag setting
8988 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
8990 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
8991 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
8992 sdev->no_uld_attach ? "hiding" : "exposing");
8993 WARN_ON(scsi_device_reprobe(sdev));
8997 * _scsih_sas_volume_add - add new volume
8998 * @ioc: per adapter object
8999 * @element: IR config element data
9003 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
9004 Mpi2EventIrConfigElement_t *element)
9006 struct _raid_device *raid_device;
9007 unsigned long flags;
9009 u16 handle = le16_to_cpu(element->VolDevHandle);
9012 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
9014 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9015 __FILE__, __LINE__, __func__);
9019 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9020 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
9021 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9026 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
9028 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9029 __FILE__, __LINE__, __func__);
9033 raid_device->id = ioc->sas_id++;
9034 raid_device->channel = RAID_CHANNEL;
9035 raid_device->handle = handle;
9036 raid_device->wwid = wwid;
9037 _scsih_raid_device_add(ioc, raid_device);
9038 if (!ioc->wait_for_discovery_to_complete) {
9039 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9040 raid_device->id, 0);
9042 _scsih_raid_device_remove(ioc, raid_device);
9044 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9045 _scsih_determine_boot_device(ioc, raid_device, 1);
9046 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9051 * _scsih_sas_volume_delete - delete volume
9052 * @ioc: per adapter object
9053 * @handle: volume device handle
9057 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
9059 struct _raid_device *raid_device;
9060 unsigned long flags;
9061 struct MPT3SAS_TARGET *sas_target_priv_data;
9062 struct scsi_target *starget = NULL;
9064 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9065 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
9067 if (raid_device->starget) {
9068 starget = raid_device->starget;
9069 sas_target_priv_data = starget->hostdata;
9070 sas_target_priv_data->deleted = 1;
9072 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
9073 raid_device->handle, (u64)raid_device->wwid);
9074 list_del(&raid_device->list);
9077 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9079 scsi_remove_target(&starget->dev);
9083 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
9084 * @ioc: per adapter object
9085 * @element: IR config element data
9089 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
9090 Mpi2EventIrConfigElement_t *element)
9092 struct _sas_device *sas_device;
9093 struct scsi_target *starget = NULL;
9094 struct MPT3SAS_TARGET *sas_target_priv_data;
9095 unsigned long flags;
9096 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
9098 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9099 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
9101 sas_device->volume_handle = 0;
9102 sas_device->volume_wwid = 0;
9103 clear_bit(handle, ioc->pd_handles);
9104 if (sas_device->starget && sas_device->starget->hostdata) {
9105 starget = sas_device->starget;
9106 sas_target_priv_data = starget->hostdata;
9107 sas_target_priv_data->flags &=
9108 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
9111 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9115 /* exposing raid component */
9117 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
9119 sas_device_put(sas_device);
9123 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
9124 * @ioc: per adapter object
9125 * @element: IR config element data
9129 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
9130 Mpi2EventIrConfigElement_t *element)
9132 struct _sas_device *sas_device;
9133 struct scsi_target *starget = NULL;
9134 struct MPT3SAS_TARGET *sas_target_priv_data;
9135 unsigned long flags;
9136 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
9137 u16 volume_handle = 0;
9138 u64 volume_wwid = 0;
9140 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
9142 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
9145 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9146 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
9148 set_bit(handle, ioc->pd_handles);
9149 if (sas_device->starget && sas_device->starget->hostdata) {
9150 starget = sas_device->starget;
9151 sas_target_priv_data = starget->hostdata;
9152 sas_target_priv_data->flags |=
9153 MPT_TARGET_FLAGS_RAID_COMPONENT;
9154 sas_device->volume_handle = volume_handle;
9155 sas_device->volume_wwid = volume_wwid;
9158 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9162 /* hiding raid component */
9163 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
9166 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
9168 sas_device_put(sas_device);
9172 * _scsih_sas_pd_delete - delete pd component
9173 * @ioc: per adapter object
9174 * @element: IR config element data
9178 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
9179 Mpi2EventIrConfigElement_t *element)
9181 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
9183 _scsih_device_remove_by_handle(ioc, handle);
9187 * _scsih_sas_pd_add - remove pd component
9188 * @ioc: per adapter object
9189 * @element: IR config element data
9193 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
9194 Mpi2EventIrConfigElement_t *element)
9196 struct _sas_device *sas_device;
9197 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
9198 Mpi2ConfigReply_t mpi_reply;
9199 Mpi2SasDevicePage0_t sas_device_pg0;
9204 set_bit(handle, ioc->pd_handles);
9206 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
9208 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
9209 sas_device_put(sas_device);
9213 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
9214 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
9215 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9216 __FILE__, __LINE__, __func__);
9220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9221 MPI2_IOCSTATUS_MASK;
9222 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9223 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9224 __FILE__, __LINE__, __func__);
9228 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9229 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
9230 mpt3sas_transport_update_links(ioc, sas_address, handle,
9231 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5,
9232 mpt3sas_get_port_by_id(ioc,
9233 sas_device_pg0.PhysicalPort, 0));
9235 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
9236 _scsih_add_device(ioc, handle, 0, 1);
9240 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
9241 * @ioc: per adapter object
9242 * @event_data: event data payload
9246 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
9247 Mpi2EventDataIrConfigChangeList_t *event_data)
9249 Mpi2EventIrConfigElement_t *element;
9252 char *reason_str = NULL, *element_str = NULL;
9254 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
9256 ioc_info(ioc, "raid config change: (%s), elements(%d)\n",
9257 le32_to_cpu(event_data->Flags) & MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG ?
9258 "foreign" : "native",
9259 event_data->NumElements);
9260 for (i = 0; i < event_data->NumElements; i++, element++) {
9261 switch (element->ReasonCode) {
9262 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
9265 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
9266 reason_str = "remove";
9268 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
9269 reason_str = "no change";
9271 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
9272 reason_str = "hide";
9274 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
9275 reason_str = "unhide";
9277 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
9278 reason_str = "volume_created";
9280 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
9281 reason_str = "volume_deleted";
9283 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
9284 reason_str = "pd_created";
9286 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
9287 reason_str = "pd_deleted";
9290 reason_str = "unknown reason";
9293 element_type = le16_to_cpu(element->ElementFlags) &
9294 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
9295 switch (element_type) {
9296 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
9297 element_str = "volume";
9299 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
9300 element_str = "phys disk";
9302 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
9303 element_str = "hot spare";
9306 element_str = "unknown element";
9309 pr_info("\t(%s:%s), vol handle(0x%04x), " \
9310 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
9311 reason_str, le16_to_cpu(element->VolDevHandle),
9312 le16_to_cpu(element->PhysDiskDevHandle),
9313 element->PhysDiskNum);
9318 * _scsih_sas_ir_config_change_event - handle ir configuration change events
9319 * @ioc: per adapter object
9320 * @fw_event: The fw_event_work object
9324 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
9325 struct fw_event_work *fw_event)
9327 Mpi2EventIrConfigElement_t *element;
9330 Mpi2EventDataIrConfigChangeList_t *event_data =
9331 (Mpi2EventDataIrConfigChangeList_t *)
9332 fw_event->event_data;
9334 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
9335 (!ioc->hide_ir_msg))
9336 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
9338 foreign_config = (le32_to_cpu(event_data->Flags) &
9339 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
9341 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
9342 if (ioc->shost_recovery &&
9343 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
9344 for (i = 0; i < event_data->NumElements; i++, element++) {
9345 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
9346 _scsih_ir_fastpath(ioc,
9347 le16_to_cpu(element->PhysDiskDevHandle),
9348 element->PhysDiskNum);
9353 for (i = 0; i < event_data->NumElements; i++, element++) {
9355 switch (element->ReasonCode) {
9356 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
9357 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
9358 if (!foreign_config)
9359 _scsih_sas_volume_add(ioc, element);
9361 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
9362 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
9363 if (!foreign_config)
9364 _scsih_sas_volume_delete(ioc,
9365 le16_to_cpu(element->VolDevHandle));
9367 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
9368 if (!ioc->is_warpdrive)
9369 _scsih_sas_pd_hide(ioc, element);
9371 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
9372 if (!ioc->is_warpdrive)
9373 _scsih_sas_pd_expose(ioc, element);
9375 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
9376 if (!ioc->is_warpdrive)
9377 _scsih_sas_pd_add(ioc, element);
9379 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
9380 if (!ioc->is_warpdrive)
9381 _scsih_sas_pd_delete(ioc, element);
9388 * _scsih_sas_ir_volume_event - IR volume event
9389 * @ioc: per adapter object
9390 * @fw_event: The fw_event_work object
9394 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
9395 struct fw_event_work *fw_event)
9398 unsigned long flags;
9399 struct _raid_device *raid_device;
9403 Mpi2EventDataIrVolume_t *event_data =
9404 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
9406 if (ioc->shost_recovery)
9409 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
9412 handle = le16_to_cpu(event_data->VolDevHandle);
9413 state = le32_to_cpu(event_data->NewValue);
9414 if (!ioc->hide_ir_msg)
9416 ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
9418 le32_to_cpu(event_data->PreviousValue),
9421 case MPI2_RAID_VOL_STATE_MISSING:
9422 case MPI2_RAID_VOL_STATE_FAILED:
9423 _scsih_sas_volume_delete(ioc, handle);
9426 case MPI2_RAID_VOL_STATE_ONLINE:
9427 case MPI2_RAID_VOL_STATE_DEGRADED:
9428 case MPI2_RAID_VOL_STATE_OPTIMAL:
9430 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9431 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
9432 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9437 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
9439 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9440 __FILE__, __LINE__, __func__);
9444 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
9446 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9447 __FILE__, __LINE__, __func__);
9451 raid_device->id = ioc->sas_id++;
9452 raid_device->channel = RAID_CHANNEL;
9453 raid_device->handle = handle;
9454 raid_device->wwid = wwid;
9455 _scsih_raid_device_add(ioc, raid_device);
9456 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
9457 raid_device->id, 0);
9459 _scsih_raid_device_remove(ioc, raid_device);
9462 case MPI2_RAID_VOL_STATE_INITIALIZING:
9469 * _scsih_sas_ir_physical_disk_event - PD event
9470 * @ioc: per adapter object
9471 * @fw_event: The fw_event_work object
9475 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
9476 struct fw_event_work *fw_event)
9478 u16 handle, parent_handle;
9480 struct _sas_device *sas_device;
9481 Mpi2ConfigReply_t mpi_reply;
9482 Mpi2SasDevicePage0_t sas_device_pg0;
9484 Mpi2EventDataIrPhysicalDisk_t *event_data =
9485 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
9488 if (ioc->shost_recovery)
9491 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
9494 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
9495 state = le32_to_cpu(event_data->NewValue);
9497 if (!ioc->hide_ir_msg)
9499 ioc_info(ioc, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
9501 le32_to_cpu(event_data->PreviousValue),
9505 case MPI2_RAID_PD_STATE_ONLINE:
9506 case MPI2_RAID_PD_STATE_DEGRADED:
9507 case MPI2_RAID_PD_STATE_REBUILDING:
9508 case MPI2_RAID_PD_STATE_OPTIMAL:
9509 case MPI2_RAID_PD_STATE_HOT_SPARE:
9511 if (!ioc->is_warpdrive)
9512 set_bit(handle, ioc->pd_handles);
9514 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
9516 sas_device_put(sas_device);
9520 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9521 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
9523 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9524 __FILE__, __LINE__, __func__);
9528 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9529 MPI2_IOCSTATUS_MASK;
9530 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9531 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9532 __FILE__, __LINE__, __func__);
9536 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
9537 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
9538 mpt3sas_transport_update_links(ioc, sas_address, handle,
9539 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5,
9540 mpt3sas_get_port_by_id(ioc,
9541 sas_device_pg0.PhysicalPort, 0));
9543 _scsih_add_device(ioc, handle, 0, 1);
9547 case MPI2_RAID_PD_STATE_OFFLINE:
9548 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
9549 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
9556 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
9557 * @ioc: per adapter object
9558 * @event_data: event data payload
9562 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
9563 Mpi2EventDataIrOperationStatus_t *event_data)
9565 char *reason_str = NULL;
9567 switch (event_data->RAIDOperation) {
9568 case MPI2_EVENT_IR_RAIDOP_RESYNC:
9569 reason_str = "resync";
9571 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
9572 reason_str = "online capacity expansion";
9574 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
9575 reason_str = "consistency check";
9577 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
9578 reason_str = "background init";
9580 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
9581 reason_str = "make data consistent";
9588 ioc_info(ioc, "raid operational status: (%s)\thandle(0x%04x), percent complete(%d)\n",
9590 le16_to_cpu(event_data->VolDevHandle),
9591 event_data->PercentComplete);
9595 * _scsih_sas_ir_operation_status_event - handle RAID operation events
9596 * @ioc: per adapter object
9597 * @fw_event: The fw_event_work object
9601 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
9602 struct fw_event_work *fw_event)
9604 Mpi2EventDataIrOperationStatus_t *event_data =
9605 (Mpi2EventDataIrOperationStatus_t *)
9606 fw_event->event_data;
9607 static struct _raid_device *raid_device;
9608 unsigned long flags;
9611 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
9612 (!ioc->hide_ir_msg))
9613 _scsih_sas_ir_operation_status_event_debug(ioc,
9616 /* code added for raid transport support */
9617 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
9619 spin_lock_irqsave(&ioc->raid_device_lock, flags);
9620 handle = le16_to_cpu(event_data->VolDevHandle);
9621 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
9623 raid_device->percent_complete =
9624 event_data->PercentComplete;
9625 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
9630 * _scsih_prep_device_scan - initialize parameters prior to device scan
9631 * @ioc: per adapter object
9633 * Set the deleted flag prior to device scan. If the device is found during
9634 * the scan, then we clear the deleted flag.
9637 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
9639 struct MPT3SAS_DEVICE *sas_device_priv_data;
9640 struct scsi_device *sdev;
9642 shost_for_each_device(sdev, ioc->shost) {
9643 sas_device_priv_data = sdev->hostdata;
9644 if (sas_device_priv_data && sas_device_priv_data->sas_target)
9645 sas_device_priv_data->sas_target->deleted = 1;
9650 * _scsih_update_device_qdepth - Update QD during Reset.
9651 * @ioc: per adapter object
9655 _scsih_update_device_qdepth(struct MPT3SAS_ADAPTER *ioc)
9657 struct MPT3SAS_DEVICE *sas_device_priv_data;
9658 struct MPT3SAS_TARGET *sas_target_priv_data;
9659 struct _sas_device *sas_device;
9660 struct scsi_device *sdev;
9663 ioc_info(ioc, "Update devices with firmware reported queue depth\n");
9664 shost_for_each_device(sdev, ioc->shost) {
9665 sas_device_priv_data = sdev->hostdata;
9666 if (sas_device_priv_data && sas_device_priv_data->sas_target) {
9667 sas_target_priv_data = sas_device_priv_data->sas_target;
9668 sas_device = sas_device_priv_data->sas_target->sas_dev;
9669 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_PCIE_DEVICE)
9670 qdepth = ioc->max_nvme_qd;
9671 else if (sas_device &&
9672 sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET)
9673 qdepth = (sas_device->port_type > 1) ?
9674 ioc->max_wideport_qd : ioc->max_narrowport_qd;
9675 else if (sas_device &&
9676 sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
9677 qdepth = ioc->max_sata_qd;
9680 mpt3sas_scsih_change_queue_depth(sdev, qdepth);
9686 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
9687 * @ioc: per adapter object
9688 * @sas_device_pg0: SAS Device page 0
9690 * After host reset, find out whether devices are still responding.
9691 * Used in _scsih_remove_unresponsive_sas_devices.
9694 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
9695 Mpi2SasDevicePage0_t *sas_device_pg0)
9697 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
9698 struct scsi_target *starget;
9699 struct _sas_device *sas_device = NULL;
9700 struct _enclosure_node *enclosure_dev = NULL;
9701 unsigned long flags;
9702 struct hba_port *port = mpt3sas_get_port_by_id(
9703 ioc, sas_device_pg0->PhysicalPort, 0);
9705 if (sas_device_pg0->EnclosureHandle) {
9707 mpt3sas_scsih_enclosure_find_by_handle(ioc,
9708 le16_to_cpu(sas_device_pg0->EnclosureHandle));
9709 if (enclosure_dev == NULL)
9710 ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
9711 sas_device_pg0->EnclosureHandle);
9713 spin_lock_irqsave(&ioc->sas_device_lock, flags);
9714 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
9715 if (sas_device->sas_address != le64_to_cpu(
9716 sas_device_pg0->SASAddress))
9718 if (sas_device->slot != le16_to_cpu(sas_device_pg0->Slot))
9720 if (sas_device->port != port)
9722 sas_device->responding = 1;
9723 starget = sas_device->starget;
9724 if (starget && starget->hostdata) {
9725 sas_target_priv_data = starget->hostdata;
9726 sas_target_priv_data->tm_busy = 0;
9727 sas_target_priv_data->deleted = 0;
9729 sas_target_priv_data = NULL;
9731 starget_printk(KERN_INFO, starget,
9732 "handle(0x%04x), sas_addr(0x%016llx)\n",
9733 le16_to_cpu(sas_device_pg0->DevHandle),
9734 (unsigned long long)
9735 sas_device->sas_address);
9737 if (sas_device->enclosure_handle != 0)
9738 starget_printk(KERN_INFO, starget,
9739 "enclosure logical id(0x%016llx), slot(%d)\n",
9740 (unsigned long long)
9741 sas_device->enclosure_logical_id,
9744 if (le16_to_cpu(sas_device_pg0->Flags) &
9745 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
9746 sas_device->enclosure_level =
9747 sas_device_pg0->EnclosureLevel;
9748 memcpy(&sas_device->connector_name[0],
9749 &sas_device_pg0->ConnectorName[0], 4);
9751 sas_device->enclosure_level = 0;
9752 sas_device->connector_name[0] = '\0';
9755 sas_device->enclosure_handle =
9756 le16_to_cpu(sas_device_pg0->EnclosureHandle);
9757 sas_device->is_chassis_slot_valid = 0;
9758 if (enclosure_dev) {
9759 sas_device->enclosure_logical_id = le64_to_cpu(
9760 enclosure_dev->pg0.EnclosureLogicalID);
9761 if (le16_to_cpu(enclosure_dev->pg0.Flags) &
9762 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
9763 sas_device->is_chassis_slot_valid = 1;
9764 sas_device->chassis_slot =
9765 enclosure_dev->pg0.ChassisSlot;
9769 if (sas_device->handle == le16_to_cpu(
9770 sas_device_pg0->DevHandle))
9772 pr_info("\thandle changed from(0x%04x)!!!\n",
9773 sas_device->handle);
9774 sas_device->handle = le16_to_cpu(
9775 sas_device_pg0->DevHandle);
9776 if (sas_target_priv_data)
9777 sas_target_priv_data->handle =
9778 le16_to_cpu(sas_device_pg0->DevHandle);
9782 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
9786 * _scsih_create_enclosure_list_after_reset - Free Existing list,
9787 * And create enclosure list by scanning all Enclosure Page(0)s
9788 * @ioc: per adapter object
9791 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER *ioc)
9793 struct _enclosure_node *enclosure_dev;
9794 Mpi2ConfigReply_t mpi_reply;
9795 u16 enclosure_handle;
9798 /* Free existing enclosure list */
9799 mpt3sas_free_enclosure_list(ioc);
9801 /* Re constructing enclosure list after reset*/
9802 enclosure_handle = 0xFFFF;
9805 kzalloc(sizeof(struct _enclosure_node), GFP_KERNEL);
9806 if (!enclosure_dev) {
9807 ioc_err(ioc, "failure at %s:%d/%s()!\n",
9808 __FILE__, __LINE__, __func__);
9811 rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
9812 &enclosure_dev->pg0,
9813 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE,
9816 if (rc || (le16_to_cpu(mpi_reply.IOCStatus) &
9817 MPI2_IOCSTATUS_MASK)) {
9818 kfree(enclosure_dev);
9821 list_add_tail(&enclosure_dev->list,
9822 &ioc->enclosure_list);
9824 le16_to_cpu(enclosure_dev->pg0.EnclosureHandle);
9829 * _scsih_search_responding_sas_devices -
9830 * @ioc: per adapter object
9832 * After host reset, find out whether devices are still responding.
9836 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
9838 Mpi2SasDevicePage0_t sas_device_pg0;
9839 Mpi2ConfigReply_t mpi_reply;
9844 ioc_info(ioc, "search for end-devices: start\n");
9846 if (list_empty(&ioc->sas_device_list))
9850 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
9851 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9853 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9854 MPI2_IOCSTATUS_MASK;
9855 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
9857 handle = le16_to_cpu(sas_device_pg0.DevHandle);
9858 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
9859 if (!(_scsih_is_end_device(device_info)))
9861 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
9865 ioc_info(ioc, "search for end-devices: complete\n");
9869 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
9870 * @ioc: per adapter object
9871 * @pcie_device_pg0: PCIe Device page 0
9873 * After host reset, find out whether devices are still responding.
9874 * Used in _scsih_remove_unresponding_devices.
9877 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER *ioc,
9878 Mpi26PCIeDevicePage0_t *pcie_device_pg0)
9880 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
9881 struct scsi_target *starget;
9882 struct _pcie_device *pcie_device;
9883 unsigned long flags;
9885 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
9886 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
9887 if ((pcie_device->wwid == le64_to_cpu(pcie_device_pg0->WWID))
9888 && (pcie_device->slot == le16_to_cpu(
9889 pcie_device_pg0->Slot))) {
9890 pcie_device->access_status =
9891 pcie_device_pg0->AccessStatus;
9892 pcie_device->responding = 1;
9893 starget = pcie_device->starget;
9894 if (starget && starget->hostdata) {
9895 sas_target_priv_data = starget->hostdata;
9896 sas_target_priv_data->tm_busy = 0;
9897 sas_target_priv_data->deleted = 0;
9899 sas_target_priv_data = NULL;
9901 starget_printk(KERN_INFO, starget,
9902 "handle(0x%04x), wwid(0x%016llx) ",
9903 pcie_device->handle,
9904 (unsigned long long)pcie_device->wwid);
9905 if (pcie_device->enclosure_handle != 0)
9906 starget_printk(KERN_INFO, starget,
9907 "enclosure logical id(0x%016llx), "
9909 (unsigned long long)
9910 pcie_device->enclosure_logical_id,
9914 if (((le32_to_cpu(pcie_device_pg0->Flags)) &
9915 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID) &&
9916 (ioc->hba_mpi_version_belonged != MPI2_VERSION)) {
9917 pcie_device->enclosure_level =
9918 pcie_device_pg0->EnclosureLevel;
9919 memcpy(&pcie_device->connector_name[0],
9920 &pcie_device_pg0->ConnectorName[0], 4);
9922 pcie_device->enclosure_level = 0;
9923 pcie_device->connector_name[0] = '\0';
9926 if (pcie_device->handle == le16_to_cpu(
9927 pcie_device_pg0->DevHandle))
9929 pr_info("\thandle changed from(0x%04x)!!!\n",
9930 pcie_device->handle);
9931 pcie_device->handle = le16_to_cpu(
9932 pcie_device_pg0->DevHandle);
9933 if (sas_target_priv_data)
9934 sas_target_priv_data->handle =
9935 le16_to_cpu(pcie_device_pg0->DevHandle);
9941 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
9945 * _scsih_search_responding_pcie_devices -
9946 * @ioc: per adapter object
9948 * After host reset, find out whether devices are still responding.
9952 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER *ioc)
9954 Mpi26PCIeDevicePage0_t pcie_device_pg0;
9955 Mpi2ConfigReply_t mpi_reply;
9960 ioc_info(ioc, "search for end-devices: start\n");
9962 if (list_empty(&ioc->pcie_device_list))
9966 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
9967 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
9969 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
9970 MPI2_IOCSTATUS_MASK;
9971 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
9972 ioc_info(ioc, "\tbreak from %s: ioc_status(0x%04x), loginfo(0x%08x)\n",
9973 __func__, ioc_status,
9974 le32_to_cpu(mpi_reply.IOCLogInfo));
9977 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
9978 device_info = le32_to_cpu(pcie_device_pg0.DeviceInfo);
9979 if (!(_scsih_is_nvme_pciescsi_device(device_info)))
9981 _scsih_mark_responding_pcie_device(ioc, &pcie_device_pg0);
9984 ioc_info(ioc, "search for PCIe end-devices: complete\n");
9988 * _scsih_mark_responding_raid_device - mark a raid_device as responding
9989 * @ioc: per adapter object
9990 * @wwid: world wide identifier for raid volume
9991 * @handle: device handle
9993 * After host reset, find out whether devices are still responding.
9994 * Used in _scsih_remove_unresponsive_raid_devices.
9997 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
10000 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
10001 struct scsi_target *starget;
10002 struct _raid_device *raid_device;
10003 unsigned long flags;
10005 spin_lock_irqsave(&ioc->raid_device_lock, flags);
10006 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
10007 if (raid_device->wwid == wwid && raid_device->starget) {
10008 starget = raid_device->starget;
10009 if (starget && starget->hostdata) {
10010 sas_target_priv_data = starget->hostdata;
10011 sas_target_priv_data->deleted = 0;
10013 sas_target_priv_data = NULL;
10014 raid_device->responding = 1;
10015 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
10016 starget_printk(KERN_INFO, raid_device->starget,
10017 "handle(0x%04x), wwid(0x%016llx)\n", handle,
10018 (unsigned long long)raid_device->wwid);
10021 * WARPDRIVE: The handles of the PDs might have changed
10022 * across the host reset so re-initialize the
10023 * required data for Direct IO
10025 mpt3sas_init_warpdrive_properties(ioc, raid_device);
10026 spin_lock_irqsave(&ioc->raid_device_lock, flags);
10027 if (raid_device->handle == handle) {
10028 spin_unlock_irqrestore(&ioc->raid_device_lock,
10032 pr_info("\thandle changed from(0x%04x)!!!\n",
10033 raid_device->handle);
10034 raid_device->handle = handle;
10035 if (sas_target_priv_data)
10036 sas_target_priv_data->handle = handle;
10037 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
10041 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
10045 * _scsih_search_responding_raid_devices -
10046 * @ioc: per adapter object
10048 * After host reset, find out whether devices are still responding.
10052 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
10054 Mpi2RaidVolPage1_t volume_pg1;
10055 Mpi2RaidVolPage0_t volume_pg0;
10056 Mpi2RaidPhysDiskPage0_t pd_pg0;
10057 Mpi2ConfigReply_t mpi_reply;
10062 if (!ioc->ir_firmware)
10065 ioc_info(ioc, "search for raid volumes: start\n");
10067 if (list_empty(&ioc->raid_device_list))
10071 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
10072 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
10073 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10074 MPI2_IOCSTATUS_MASK;
10075 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
10077 handle = le16_to_cpu(volume_pg1.DevHandle);
10079 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
10080 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
10081 sizeof(Mpi2RaidVolPage0_t)))
10084 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
10085 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
10086 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
10087 _scsih_mark_responding_raid_device(ioc,
10088 le64_to_cpu(volume_pg1.WWID), handle);
10091 /* refresh the pd_handles */
10092 if (!ioc->is_warpdrive) {
10093 phys_disk_num = 0xFF;
10094 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
10095 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
10096 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
10098 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10099 MPI2_IOCSTATUS_MASK;
10100 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
10102 phys_disk_num = pd_pg0.PhysDiskNum;
10103 handle = le16_to_cpu(pd_pg0.DevHandle);
10104 set_bit(handle, ioc->pd_handles);
10108 ioc_info(ioc, "search for responding raid volumes: complete\n");
10112 * _scsih_mark_responding_expander - mark a expander as responding
10113 * @ioc: per adapter object
10114 * @expander_pg0:SAS Expander Config Page0
10116 * After host reset, find out whether devices are still responding.
10117 * Used in _scsih_remove_unresponsive_expanders.
10120 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc,
10121 Mpi2ExpanderPage0_t *expander_pg0)
10123 struct _sas_node *sas_expander = NULL;
10124 unsigned long flags;
10126 struct _enclosure_node *enclosure_dev = NULL;
10127 u16 handle = le16_to_cpu(expander_pg0->DevHandle);
10128 u16 enclosure_handle = le16_to_cpu(expander_pg0->EnclosureHandle);
10129 u64 sas_address = le64_to_cpu(expander_pg0->SASAddress);
10130 struct hba_port *port = mpt3sas_get_port_by_id(
10131 ioc, expander_pg0->PhysicalPort, 0);
10133 if (enclosure_handle)
10135 mpt3sas_scsih_enclosure_find_by_handle(ioc,
10138 spin_lock_irqsave(&ioc->sas_node_lock, flags);
10139 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
10140 if (sas_expander->sas_address != sas_address)
10142 if (sas_expander->port != port)
10144 sas_expander->responding = 1;
10146 if (enclosure_dev) {
10147 sas_expander->enclosure_logical_id =
10148 le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
10149 sas_expander->enclosure_handle =
10150 le16_to_cpu(expander_pg0->EnclosureHandle);
10153 if (sas_expander->handle == handle)
10155 pr_info("\texpander(0x%016llx): handle changed" \
10156 " from(0x%04x) to (0x%04x)!!!\n",
10157 (unsigned long long)sas_expander->sas_address,
10158 sas_expander->handle, handle);
10159 sas_expander->handle = handle;
10160 for (i = 0 ; i < sas_expander->num_phys ; i++)
10161 sas_expander->phy[i].handle = handle;
10165 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
10169 * _scsih_search_responding_expanders -
10170 * @ioc: per adapter object
10172 * After host reset, find out whether devices are still responding.
10176 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
10178 Mpi2ExpanderPage0_t expander_pg0;
10179 Mpi2ConfigReply_t mpi_reply;
10185 ioc_info(ioc, "search for expanders: start\n");
10187 if (list_empty(&ioc->sas_expander_list))
10191 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
10192 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
10194 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10195 MPI2_IOCSTATUS_MASK;
10196 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
10199 handle = le16_to_cpu(expander_pg0.DevHandle);
10200 sas_address = le64_to_cpu(expander_pg0.SASAddress);
10201 port = expander_pg0.PhysicalPort;
10203 "\texpander present: handle(0x%04x), sas_addr(0x%016llx), port:%d\n",
10204 handle, (unsigned long long)sas_address,
10205 (ioc->multipath_on_hba ?
10206 port : MULTIPATH_DISABLED_PORT_ID));
10207 _scsih_mark_responding_expander(ioc, &expander_pg0);
10211 ioc_info(ioc, "search for expanders: complete\n");
10215 * _scsih_remove_unresponding_devices - removing unresponding devices
10216 * @ioc: per adapter object
10219 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER *ioc)
10221 struct _sas_device *sas_device, *sas_device_next;
10222 struct _sas_node *sas_expander, *sas_expander_next;
10223 struct _raid_device *raid_device, *raid_device_next;
10224 struct _pcie_device *pcie_device, *pcie_device_next;
10225 struct list_head tmp_list;
10226 unsigned long flags;
10229 ioc_info(ioc, "removing unresponding devices: start\n");
10231 /* removing unresponding end devices */
10232 ioc_info(ioc, "removing unresponding devices: end-devices\n");
10234 * Iterate, pulling off devices marked as non-responding. We become the
10235 * owner for the reference the list had on any object we prune.
10237 spin_lock_irqsave(&ioc->sas_device_lock, flags);
10240 * Clean up the sas_device_init_list list as
10241 * driver goes for fresh scan as part of diag reset.
10243 list_for_each_entry_safe(sas_device, sas_device_next,
10244 &ioc->sas_device_init_list, list) {
10245 list_del_init(&sas_device->list);
10246 sas_device_put(sas_device);
10249 list_for_each_entry_safe(sas_device, sas_device_next,
10250 &ioc->sas_device_list, list) {
10251 if (!sas_device->responding)
10252 list_move_tail(&sas_device->list, &head);
10254 sas_device->responding = 0;
10256 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
10259 * Now, uninitialize and remove the unresponding devices we pruned.
10261 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
10262 _scsih_remove_device(ioc, sas_device);
10263 list_del_init(&sas_device->list);
10264 sas_device_put(sas_device);
10267 ioc_info(ioc, "Removing unresponding devices: pcie end-devices\n");
10268 INIT_LIST_HEAD(&head);
10269 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
10271 * Clean up the pcie_device_init_list list as
10272 * driver goes for fresh scan as part of diag reset.
10274 list_for_each_entry_safe(pcie_device, pcie_device_next,
10275 &ioc->pcie_device_init_list, list) {
10276 list_del_init(&pcie_device->list);
10277 pcie_device_put(pcie_device);
10280 list_for_each_entry_safe(pcie_device, pcie_device_next,
10281 &ioc->pcie_device_list, list) {
10282 if (!pcie_device->responding)
10283 list_move_tail(&pcie_device->list, &head);
10285 pcie_device->responding = 0;
10287 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
10289 list_for_each_entry_safe(pcie_device, pcie_device_next, &head, list) {
10290 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
10291 list_del_init(&pcie_device->list);
10292 pcie_device_put(pcie_device);
10295 /* removing unresponding volumes */
10296 if (ioc->ir_firmware) {
10297 ioc_info(ioc, "removing unresponding devices: volumes\n");
10298 list_for_each_entry_safe(raid_device, raid_device_next,
10299 &ioc->raid_device_list, list) {
10300 if (!raid_device->responding)
10301 _scsih_sas_volume_delete(ioc,
10302 raid_device->handle);
10304 raid_device->responding = 0;
10308 /* removing unresponding expanders */
10309 ioc_info(ioc, "removing unresponding devices: expanders\n");
10310 spin_lock_irqsave(&ioc->sas_node_lock, flags);
10311 INIT_LIST_HEAD(&tmp_list);
10312 list_for_each_entry_safe(sas_expander, sas_expander_next,
10313 &ioc->sas_expander_list, list) {
10314 if (!sas_expander->responding)
10315 list_move_tail(&sas_expander->list, &tmp_list);
10317 sas_expander->responding = 0;
10319 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
10320 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
10322 _scsih_expander_node_remove(ioc, sas_expander);
10325 ioc_info(ioc, "removing unresponding devices: complete\n");
10327 /* unblock devices */
10328 _scsih_ublock_io_all_device(ioc);
10332 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
10333 struct _sas_node *sas_expander, u16 handle)
10335 Mpi2ExpanderPage1_t expander_pg1;
10336 Mpi2ConfigReply_t mpi_reply;
10339 for (i = 0 ; i < sas_expander->num_phys ; i++) {
10340 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
10341 &expander_pg1, i, handle))) {
10342 ioc_err(ioc, "failure at %s:%d/%s()!\n",
10343 __FILE__, __LINE__, __func__);
10347 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
10348 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
10349 expander_pg1.NegotiatedLinkRate >> 4,
10350 sas_expander->port);
10355 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
10356 * @ioc: per adapter object
10359 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
10361 Mpi2ExpanderPage0_t expander_pg0;
10362 Mpi2SasDevicePage0_t sas_device_pg0;
10363 Mpi26PCIeDevicePage0_t pcie_device_pg0;
10364 Mpi2RaidVolPage1_t volume_pg1;
10365 Mpi2RaidVolPage0_t volume_pg0;
10366 Mpi2RaidPhysDiskPage0_t pd_pg0;
10367 Mpi2EventIrConfigElement_t element;
10368 Mpi2ConfigReply_t mpi_reply;
10369 u8 phys_disk_num, port_id;
10371 u16 handle, parent_handle;
10373 struct _sas_device *sas_device;
10374 struct _pcie_device *pcie_device;
10375 struct _sas_node *expander_device;
10376 static struct _raid_device *raid_device;
10378 unsigned long flags;
10380 ioc_info(ioc, "scan devices: start\n");
10382 _scsih_sas_host_refresh(ioc);
10384 ioc_info(ioc, "\tscan devices: expanders start\n");
10388 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
10389 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
10390 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10391 MPI2_IOCSTATUS_MASK;
10392 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10393 ioc_info(ioc, "\tbreak from expander scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
10394 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10397 handle = le16_to_cpu(expander_pg0.DevHandle);
10398 spin_lock_irqsave(&ioc->sas_node_lock, flags);
10399 port_id = expander_pg0.PhysicalPort;
10400 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
10401 ioc, le64_to_cpu(expander_pg0.SASAddress),
10402 mpt3sas_get_port_by_id(ioc, port_id, 0));
10403 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
10404 if (expander_device)
10405 _scsih_refresh_expander_links(ioc, expander_device,
10408 ioc_info(ioc, "\tBEFORE adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
10410 (u64)le64_to_cpu(expander_pg0.SASAddress));
10411 _scsih_expander_add(ioc, handle);
10412 ioc_info(ioc, "\tAFTER adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
10414 (u64)le64_to_cpu(expander_pg0.SASAddress));
10418 ioc_info(ioc, "\tscan devices: expanders complete\n");
10420 if (!ioc->ir_firmware)
10423 ioc_info(ioc, "\tscan devices: phys disk start\n");
10426 phys_disk_num = 0xFF;
10427 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
10428 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
10430 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10431 MPI2_IOCSTATUS_MASK;
10432 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10433 ioc_info(ioc, "\tbreak from phys disk scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
10434 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10437 phys_disk_num = pd_pg0.PhysDiskNum;
10438 handle = le16_to_cpu(pd_pg0.DevHandle);
10439 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
10441 sas_device_put(sas_device);
10444 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
10445 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
10448 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10449 MPI2_IOCSTATUS_MASK;
10450 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10451 ioc_info(ioc, "\tbreak from phys disk scan ioc_status(0x%04x), loginfo(0x%08x)\n",
10452 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10455 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
10456 if (!_scsih_get_sas_address(ioc, parent_handle,
10458 ioc_info(ioc, "\tBEFORE adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
10460 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
10461 port_id = sas_device_pg0.PhysicalPort;
10462 mpt3sas_transport_update_links(ioc, sas_address,
10463 handle, sas_device_pg0.PhyNum,
10464 MPI2_SAS_NEG_LINK_RATE_1_5,
10465 mpt3sas_get_port_by_id(ioc, port_id, 0));
10466 set_bit(handle, ioc->pd_handles);
10468 /* This will retry adding the end device.
10469 * _scsih_add_device() will decide on retries and
10470 * return "1" when it should be retried
10472 while (_scsih_add_device(ioc, handle, retry_count++,
10476 ioc_info(ioc, "\tAFTER adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
10478 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
10482 ioc_info(ioc, "\tscan devices: phys disk complete\n");
10484 ioc_info(ioc, "\tscan devices: volumes start\n");
10488 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
10489 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
10490 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10491 MPI2_IOCSTATUS_MASK;
10492 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10493 ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
10494 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10497 handle = le16_to_cpu(volume_pg1.DevHandle);
10498 spin_lock_irqsave(&ioc->raid_device_lock, flags);
10499 raid_device = _scsih_raid_device_find_by_wwid(ioc,
10500 le64_to_cpu(volume_pg1.WWID));
10501 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
10504 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
10505 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
10506 sizeof(Mpi2RaidVolPage0_t)))
10508 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10509 MPI2_IOCSTATUS_MASK;
10510 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10511 ioc_info(ioc, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
10512 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10515 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
10516 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
10517 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
10518 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
10519 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
10520 element.VolDevHandle = volume_pg1.DevHandle;
10521 ioc_info(ioc, "\tBEFORE adding volume: handle (0x%04x)\n",
10522 volume_pg1.DevHandle);
10523 _scsih_sas_volume_add(ioc, &element);
10524 ioc_info(ioc, "\tAFTER adding volume: handle (0x%04x)\n",
10525 volume_pg1.DevHandle);
10529 ioc_info(ioc, "\tscan devices: volumes complete\n");
10533 ioc_info(ioc, "\tscan devices: end devices start\n");
10537 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
10538 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
10540 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
10541 MPI2_IOCSTATUS_MASK;
10542 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10543 ioc_info(ioc, "\tbreak from end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
10544 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10547 handle = le16_to_cpu(sas_device_pg0.DevHandle);
10548 if (!(_scsih_is_end_device(
10549 le32_to_cpu(sas_device_pg0.DeviceInfo))))
10551 port_id = sas_device_pg0.PhysicalPort;
10552 sas_device = mpt3sas_get_sdev_by_addr(ioc,
10553 le64_to_cpu(sas_device_pg0.SASAddress),
10554 mpt3sas_get_port_by_id(ioc, port_id, 0));
10556 sas_device_put(sas_device);
10559 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
10560 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
10561 ioc_info(ioc, "\tBEFORE adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
10563 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
10564 mpt3sas_transport_update_links(ioc, sas_address, handle,
10565 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5,
10566 mpt3sas_get_port_by_id(ioc, port_id, 0));
10568 /* This will retry adding the end device.
10569 * _scsih_add_device() will decide on retries and
10570 * return "1" when it should be retried
10572 while (_scsih_add_device(ioc, handle, retry_count++,
10576 ioc_info(ioc, "\tAFTER adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
10578 (u64)le64_to_cpu(sas_device_pg0.SASAddress));
10581 ioc_info(ioc, "\tscan devices: end devices complete\n");
10582 ioc_info(ioc, "\tscan devices: pcie end devices start\n");
10586 while (!(mpt3sas_config_get_pcie_device_pg0(ioc, &mpi_reply,
10587 &pcie_device_pg0, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
10589 ioc_status = le16_to_cpu(mpi_reply.IOCStatus)
10590 & MPI2_IOCSTATUS_MASK;
10591 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
10592 ioc_info(ioc, "\tbreak from pcie end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
10593 ioc_status, le32_to_cpu(mpi_reply.IOCLogInfo));
10596 handle = le16_to_cpu(pcie_device_pg0.DevHandle);
10597 if (!(_scsih_is_nvme_pciescsi_device(
10598 le32_to_cpu(pcie_device_pg0.DeviceInfo))))
10600 pcie_device = mpt3sas_get_pdev_by_wwid(ioc,
10601 le64_to_cpu(pcie_device_pg0.WWID));
10603 pcie_device_put(pcie_device);
10607 parent_handle = le16_to_cpu(pcie_device_pg0.ParentDevHandle);
10608 _scsih_pcie_add_device(ioc, handle);
10610 ioc_info(ioc, "\tAFTER adding pcie end device: handle (0x%04x), wwid(0x%016llx)\n",
10611 handle, (u64)le64_to_cpu(pcie_device_pg0.WWID));
10614 ioc_info(ioc, "\tpcie devices: pcie end devices complete\n");
10615 ioc_info(ioc, "scan devices: complete\n");
10619 * mpt3sas_scsih_pre_reset_handler - reset callback handler (for scsih)
10620 * @ioc: per adapter object
10622 * The handler for doing any required cleanup or initialization.
10624 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
10626 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__));
10630 * mpt3sas_scsih_clear_outstanding_scsi_tm_commands - clears outstanding
10632 * @ioc: per adapter object
10634 * The handler for doing any required cleanup or initialization.
10637 mpt3sas_scsih_clear_outstanding_scsi_tm_commands(struct MPT3SAS_ADAPTER *ioc)
10640 ioc_info(ioc, "%s: clear outstanding scsi & tm cmds\n", __func__));
10641 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
10642 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
10643 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
10644 complete(&ioc->scsih_cmds.done);
10646 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
10647 ioc->tm_cmds.status |= MPT3_CMD_RESET;
10648 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
10649 complete(&ioc->tm_cmds.done);
10652 memset(ioc->pend_os_device_add, 0, ioc->pend_os_device_add_sz);
10653 memset(ioc->device_remove_in_progress, 0,
10654 ioc->device_remove_in_progress_sz);
10655 _scsih_fw_event_cleanup_queue(ioc);
10656 _scsih_flush_running_cmds(ioc);
10660 * mpt3sas_scsih_reset_done_handler - reset callback handler (for scsih)
10661 * @ioc: per adapter object
10663 * The handler for doing any required cleanup or initialization.
10666 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
10668 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__));
10669 if (!(disable_discovery > 0 && !ioc->sas_hba.num_phys)) {
10670 if (ioc->multipath_on_hba) {
10671 _scsih_sas_port_refresh(ioc);
10672 _scsih_update_vphys_after_reset(ioc);
10674 _scsih_prep_device_scan(ioc);
10675 _scsih_create_enclosure_list_after_reset(ioc);
10676 _scsih_search_responding_sas_devices(ioc);
10677 _scsih_search_responding_pcie_devices(ioc);
10678 _scsih_search_responding_raid_devices(ioc);
10679 _scsih_search_responding_expanders(ioc);
10680 _scsih_error_recovery_delete_devices(ioc);
10685 * _mpt3sas_fw_work - delayed task for processing firmware events
10686 * @ioc: per adapter object
10687 * @fw_event: The fw_event_work object
10691 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
10693 ioc->current_event = fw_event;
10694 _scsih_fw_event_del_from_list(ioc, fw_event);
10696 /* the queue is being flushed so ignore this event */
10697 if (ioc->remove_host || ioc->pci_error_recovery) {
10698 fw_event_work_put(fw_event);
10699 ioc->current_event = NULL;
10703 switch (fw_event->event) {
10704 case MPT3SAS_PROCESS_TRIGGER_DIAG:
10705 mpt3sas_process_trigger_data(ioc,
10706 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
10707 fw_event->event_data);
10709 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
10710 while (scsi_host_in_recovery(ioc->shost) ||
10711 ioc->shost_recovery) {
10713 * If we're unloading or cancelling the work, bail.
10714 * Otherwise, this can become an infinite loop.
10716 if (ioc->remove_host || ioc->fw_events_cleanup)
10720 _scsih_remove_unresponding_devices(ioc);
10721 _scsih_del_dirty_vphy(ioc);
10722 _scsih_del_dirty_port_entries(ioc);
10723 if (ioc->is_gen35_ioc)
10724 _scsih_update_device_qdepth(ioc);
10725 _scsih_scan_for_devices_after_reset(ioc);
10727 * If diag reset has occurred during the driver load
10728 * then driver has to complete the driver load operation
10729 * by executing the following items:
10730 *- Register the devices from sas_device_init_list to SML
10731 *- clear is_driver_loading flag,
10732 *- start the watchdog thread.
10733 * In happy driver load path, above things are taken care of when
10734 * driver executes scsih_scan_finished().
10736 if (ioc->is_driver_loading)
10737 _scsih_complete_devices_scanning(ioc);
10738 _scsih_set_nvme_max_shutdown_latency(ioc);
10740 case MPT3SAS_PORT_ENABLE_COMPLETE:
10741 ioc->start_scan = 0;
10742 if (missing_delay[0] != -1 && missing_delay[1] != -1)
10743 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
10746 ioc_info(ioc, "port enable: complete from worker thread\n"));
10748 case MPT3SAS_TURN_ON_PFA_LED:
10749 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
10751 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
10752 _scsih_sas_topology_change_event(ioc, fw_event);
10754 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
10755 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
10756 _scsih_sas_device_status_change_event_debug(ioc,
10757 (Mpi2EventDataSasDeviceStatusChange_t *)
10758 fw_event->event_data);
10760 case MPI2_EVENT_SAS_DISCOVERY:
10761 _scsih_sas_discovery_event(ioc, fw_event);
10763 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
10764 _scsih_sas_device_discovery_error_event(ioc, fw_event);
10766 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
10767 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
10769 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
10770 _scsih_sas_enclosure_dev_status_change_event(ioc,
10773 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
10774 _scsih_sas_ir_config_change_event(ioc, fw_event);
10776 case MPI2_EVENT_IR_VOLUME:
10777 _scsih_sas_ir_volume_event(ioc, fw_event);
10779 case MPI2_EVENT_IR_PHYSICAL_DISK:
10780 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
10782 case MPI2_EVENT_IR_OPERATION_STATUS:
10783 _scsih_sas_ir_operation_status_event(ioc, fw_event);
10785 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
10786 _scsih_pcie_device_status_change_event(ioc, fw_event);
10788 case MPI2_EVENT_PCIE_ENUMERATION:
10789 _scsih_pcie_enumeration_event(ioc, fw_event);
10791 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
10792 _scsih_pcie_topology_change_event(ioc, fw_event);
10793 ioc->current_event = NULL;
10797 fw_event_work_put(fw_event);
10798 ioc->current_event = NULL;
10802 * _firmware_event_work
10803 * @work: The fw_event_work object
10806 * wrappers for the work thread handling firmware events
10810 _firmware_event_work(struct work_struct *work)
10812 struct fw_event_work *fw_event = container_of(work,
10813 struct fw_event_work, work);
10815 _mpt3sas_fw_work(fw_event->ioc, fw_event);
10819 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
10820 * @ioc: per adapter object
10821 * @msix_index: MSIX table index supplied by the OS
10822 * @reply: reply message frame(lower 32bit addr)
10823 * Context: interrupt.
10825 * This function merely adds a new work task into ioc->firmware_event_thread.
10826 * The tasks are worked from _firmware_event_work in user context.
10828 * Return: 1 meaning mf should be freed from _base_interrupt
10829 * 0 means the mf is freed from this function.
10832 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
10835 struct fw_event_work *fw_event;
10836 Mpi2EventNotificationReply_t *mpi_reply;
10839 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
10841 /* events turned off due to host reset */
10842 if (ioc->pci_error_recovery)
10845 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
10847 if (unlikely(!mpi_reply)) {
10848 ioc_err(ioc, "mpi_reply not valid at %s:%d/%s()!\n",
10849 __FILE__, __LINE__, __func__);
10853 event = le16_to_cpu(mpi_reply->Event);
10855 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
10856 mpt3sas_trigger_event(ioc, event, 0);
10860 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
10862 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
10863 (Mpi2EventDataSasBroadcastPrimitive_t *)
10864 mpi_reply->EventData;
10866 if (baen_data->Primitive !=
10867 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
10870 if (ioc->broadcast_aen_busy) {
10871 ioc->broadcast_aen_pending++;
10874 ioc->broadcast_aen_busy = 1;
10878 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
10879 _scsih_check_topo_delete_events(ioc,
10880 (Mpi2EventDataSasTopologyChangeList_t *)
10881 mpi_reply->EventData);
10883 * No need to add the topology change list
10884 * event to fw event work queue when
10885 * diag reset is going on. Since during diag
10886 * reset driver scan the devices by reading
10887 * sas device page0's not by processing the
10890 if (ioc->shost_recovery)
10893 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
10894 _scsih_check_pcie_topo_remove_events(ioc,
10895 (Mpi26EventDataPCIeTopologyChangeList_t *)
10896 mpi_reply->EventData);
10897 if (ioc->shost_recovery)
10900 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
10901 _scsih_check_ir_config_unhide_events(ioc,
10902 (Mpi2EventDataIrConfigChangeList_t *)
10903 mpi_reply->EventData);
10905 case MPI2_EVENT_IR_VOLUME:
10906 _scsih_check_volume_delete_events(ioc,
10907 (Mpi2EventDataIrVolume_t *)
10908 mpi_reply->EventData);
10910 case MPI2_EVENT_LOG_ENTRY_ADDED:
10912 Mpi2EventDataLogEntryAdded_t *log_entry;
10915 if (!ioc->is_warpdrive)
10918 log_entry = (Mpi2EventDataLogEntryAdded_t *)
10919 mpi_reply->EventData;
10920 log_code = le32_to_cpu(*(__le32 *)log_entry->LogData);
10922 if (le16_to_cpu(log_entry->LogEntryQualifier)
10923 != MPT2_WARPDRIVE_LOGENTRY)
10926 switch (log_code) {
10927 case MPT2_WARPDRIVE_LC_SSDT:
10928 ioc_warn(ioc, "WarpDrive Warning: IO Throttling has occurred in the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
10930 case MPT2_WARPDRIVE_LC_SSDLW:
10931 ioc_warn(ioc, "WarpDrive Warning: Program/Erase Cycles for the WarpDrive subsystem in degraded range. Check WarpDrive documentation for additional details.\n");
10933 case MPT2_WARPDRIVE_LC_SSDLF:
10934 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");
10936 case MPT2_WARPDRIVE_LC_BRMF:
10937 ioc_err(ioc, "WarpDrive Fatal Error: The Backup Rail Monitor has failed on the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
10943 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
10944 _scsih_sas_device_status_change_event(ioc,
10945 (Mpi2EventDataSasDeviceStatusChange_t *)
10946 mpi_reply->EventData);
10948 case MPI2_EVENT_IR_OPERATION_STATUS:
10949 case MPI2_EVENT_SAS_DISCOVERY:
10950 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
10951 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
10952 case MPI2_EVENT_IR_PHYSICAL_DISK:
10953 case MPI2_EVENT_PCIE_ENUMERATION:
10954 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE:
10957 case MPI2_EVENT_TEMP_THRESHOLD:
10958 _scsih_temp_threshold_events(ioc,
10959 (Mpi2EventDataTemperature_t *)
10960 mpi_reply->EventData);
10962 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
10963 ActiveCableEventData =
10964 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
10965 switch (ActiveCableEventData->ReasonCode) {
10966 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER:
10967 ioc_notice(ioc, "Currently an active cable with ReceptacleID %d\n",
10968 ActiveCableEventData->ReceptacleID);
10969 pr_notice("cannot be powered and devices connected\n");
10970 pr_notice("to this active cable will not be seen\n");
10971 pr_notice("This active cable requires %d mW of power\n",
10973 ActiveCableEventData->ActiveCablePowerRequirement));
10976 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED:
10977 ioc_notice(ioc, "Currently a cable with ReceptacleID %d\n",
10978 ActiveCableEventData->ReceptacleID);
10980 "is not running at optimal speed(12 Gb/s rate)\n");
10986 default: /* ignore the rest */
10990 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
10991 fw_event = alloc_fw_event_work(sz);
10993 ioc_err(ioc, "failure at %s:%d/%s()!\n",
10994 __FILE__, __LINE__, __func__);
10998 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
10999 fw_event->ioc = ioc;
11000 fw_event->VF_ID = mpi_reply->VF_ID;
11001 fw_event->VP_ID = mpi_reply->VP_ID;
11002 fw_event->event = event;
11003 _scsih_fw_event_add(ioc, fw_event);
11004 fw_event_work_put(fw_event);
11009 * _scsih_expander_node_remove - removing expander device from list.
11010 * @ioc: per adapter object
11011 * @sas_expander: the sas_device object
11013 * Removing object and freeing associated memory from the
11014 * ioc->sas_expander_list.
11017 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
11018 struct _sas_node *sas_expander)
11020 struct _sas_port *mpt3sas_port, *next;
11021 unsigned long flags;
11024 /* remove sibling ports attached to this expander */
11025 list_for_each_entry_safe(mpt3sas_port, next,
11026 &sas_expander->sas_port_list, port_list) {
11027 if (ioc->shost_recovery)
11029 if (mpt3sas_port->remote_identify.device_type ==
11031 mpt3sas_device_remove_by_sas_address(ioc,
11032 mpt3sas_port->remote_identify.sas_address,
11033 mpt3sas_port->hba_port);
11034 else if (mpt3sas_port->remote_identify.device_type ==
11035 SAS_EDGE_EXPANDER_DEVICE ||
11036 mpt3sas_port->remote_identify.device_type ==
11037 SAS_FANOUT_EXPANDER_DEVICE)
11038 mpt3sas_expander_remove(ioc,
11039 mpt3sas_port->remote_identify.sas_address,
11040 mpt3sas_port->hba_port);
11043 port_id = sas_expander->port->port_id;
11045 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
11046 sas_expander->sas_address_parent, sas_expander->port);
11049 "expander_remove: handle(0x%04x), sas_addr(0x%016llx), port:%d\n",
11050 sas_expander->handle, (unsigned long long)
11051 sas_expander->sas_address,
11054 spin_lock_irqsave(&ioc->sas_node_lock, flags);
11055 list_del(&sas_expander->list);
11056 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
11058 kfree(sas_expander->phy);
11059 kfree(sas_expander);
11063 * _scsih_nvme_shutdown - NVMe shutdown notification
11064 * @ioc: per adapter object
11066 * Sending IoUnitControl request with shutdown operation code to alert IOC that
11067 * the host system is shutting down so that IOC can issue NVMe shutdown to
11068 * NVMe drives attached to it.
11071 _scsih_nvme_shutdown(struct MPT3SAS_ADAPTER *ioc)
11073 Mpi26IoUnitControlRequest_t *mpi_request;
11074 Mpi26IoUnitControlReply_t *mpi_reply;
11077 /* are there any NVMe devices ? */
11078 if (list_empty(&ioc->pcie_device_list))
11081 mutex_lock(&ioc->scsih_cmds.mutex);
11083 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
11084 ioc_err(ioc, "%s: scsih_cmd in use\n", __func__);
11088 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
11090 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
11093 "%s: failed obtaining a smid\n", __func__);
11094 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
11098 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
11099 ioc->scsih_cmds.smid = smid;
11100 memset(mpi_request, 0, sizeof(Mpi26IoUnitControlRequest_t));
11101 mpi_request->Function = MPI2_FUNCTION_IO_UNIT_CONTROL;
11102 mpi_request->Operation = MPI26_CTRL_OP_SHUTDOWN;
11104 init_completion(&ioc->scsih_cmds.done);
11105 ioc->put_smid_default(ioc, smid);
11106 /* Wait for max_shutdown_latency seconds */
11108 "Io Unit Control shutdown (sending), Shutdown latency %d sec\n",
11109 ioc->max_shutdown_latency);
11110 wait_for_completion_timeout(&ioc->scsih_cmds.done,
11111 ioc->max_shutdown_latency*HZ);
11113 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
11114 ioc_err(ioc, "%s: timeout\n", __func__);
11118 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
11119 mpi_reply = ioc->scsih_cmds.reply;
11120 ioc_info(ioc, "Io Unit Control shutdown (complete):"
11121 "ioc_status(0x%04x), loginfo(0x%08x)\n",
11122 le16_to_cpu(mpi_reply->IOCStatus),
11123 le32_to_cpu(mpi_reply->IOCLogInfo));
11126 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
11127 mutex_unlock(&ioc->scsih_cmds.mutex);
11132 * _scsih_ir_shutdown - IR shutdown notification
11133 * @ioc: per adapter object
11135 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
11136 * the host system is shutting down.
11139 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
11141 Mpi2RaidActionRequest_t *mpi_request;
11142 Mpi2RaidActionReply_t *mpi_reply;
11145 /* is IR firmware build loaded ? */
11146 if (!ioc->ir_firmware)
11149 /* are there any volumes ? */
11150 if (list_empty(&ioc->raid_device_list))
11153 mutex_lock(&ioc->scsih_cmds.mutex);
11155 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
11156 ioc_err(ioc, "%s: scsih_cmd in use\n", __func__);
11159 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
11161 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
11163 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
11164 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
11168 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
11169 ioc->scsih_cmds.smid = smid;
11170 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
11172 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
11173 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
11175 if (!ioc->hide_ir_msg)
11176 ioc_info(ioc, "IR shutdown (sending)\n");
11177 init_completion(&ioc->scsih_cmds.done);
11178 ioc->put_smid_default(ioc, smid);
11179 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
11181 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
11182 ioc_err(ioc, "%s: timeout\n", __func__);
11186 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
11187 mpi_reply = ioc->scsih_cmds.reply;
11188 if (!ioc->hide_ir_msg)
11189 ioc_info(ioc, "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
11190 le16_to_cpu(mpi_reply->IOCStatus),
11191 le32_to_cpu(mpi_reply->IOCLogInfo));
11195 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
11196 mutex_unlock(&ioc->scsih_cmds.mutex);
11200 * _scsih_get_shost_and_ioc - get shost and ioc
11201 * and verify whether they are NULL or not
11202 * @pdev: PCI device struct
11203 * @shost: address of scsi host pointer
11204 * @ioc: address of HBA adapter pointer
11206 * Return zero if *shost and *ioc are not NULL otherwise return error number.
11209 _scsih_get_shost_and_ioc(struct pci_dev *pdev,
11210 struct Scsi_Host **shost, struct MPT3SAS_ADAPTER **ioc)
11212 *shost = pci_get_drvdata(pdev);
11213 if (*shost == NULL) {
11214 dev_err(&pdev->dev, "pdev's driver data is null\n");
11218 *ioc = shost_priv(*shost);
11219 if (*ioc == NULL) {
11220 dev_err(&pdev->dev, "shost's private data is null\n");
11228 * scsih_remove - detach and remove add host
11229 * @pdev: PCI device struct
11231 * Routine called when unloading the driver.
11233 static void scsih_remove(struct pci_dev *pdev)
11235 struct Scsi_Host *shost;
11236 struct MPT3SAS_ADAPTER *ioc;
11237 struct _sas_port *mpt3sas_port, *next_port;
11238 struct _raid_device *raid_device, *next;
11239 struct MPT3SAS_TARGET *sas_target_priv_data;
11240 struct _pcie_device *pcie_device, *pcienext;
11241 struct workqueue_struct *wq;
11242 unsigned long flags;
11243 Mpi2ConfigReply_t mpi_reply;
11244 struct hba_port *port, *port_next;
11246 if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
11249 ioc->remove_host = 1;
11251 if (!pci_device_is_present(pdev)) {
11252 mpt3sas_base_pause_mq_polling(ioc);
11253 _scsih_flush_running_cmds(ioc);
11256 _scsih_fw_event_cleanup_queue(ioc);
11258 spin_lock_irqsave(&ioc->fw_event_lock, flags);
11259 wq = ioc->firmware_event_thread;
11260 ioc->firmware_event_thread = NULL;
11261 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
11263 destroy_workqueue(wq);
11265 * Copy back the unmodified ioc page1. so that on next driver load,
11266 * current modified changes on ioc page1 won't take effect.
11268 if (ioc->is_aero_ioc)
11269 mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply,
11270 &ioc->ioc_pg1_copy);
11271 /* release all the volumes */
11272 _scsih_ir_shutdown(ioc);
11273 mpt3sas_destroy_debugfs(ioc);
11274 sas_remove_host(shost);
11275 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
11277 if (raid_device->starget) {
11278 sas_target_priv_data =
11279 raid_device->starget->hostdata;
11280 sas_target_priv_data->deleted = 1;
11281 scsi_remove_target(&raid_device->starget->dev);
11283 ioc_info(ioc, "removing handle(0x%04x), wwid(0x%016llx)\n",
11284 raid_device->handle, (u64)raid_device->wwid);
11285 _scsih_raid_device_remove(ioc, raid_device);
11287 list_for_each_entry_safe(pcie_device, pcienext, &ioc->pcie_device_list,
11289 _scsih_pcie_device_remove_from_sml(ioc, pcie_device);
11290 list_del_init(&pcie_device->list);
11291 pcie_device_put(pcie_device);
11294 /* free ports attached to the sas_host */
11295 list_for_each_entry_safe(mpt3sas_port, next_port,
11296 &ioc->sas_hba.sas_port_list, port_list) {
11297 if (mpt3sas_port->remote_identify.device_type ==
11299 mpt3sas_device_remove_by_sas_address(ioc,
11300 mpt3sas_port->remote_identify.sas_address,
11301 mpt3sas_port->hba_port);
11302 else if (mpt3sas_port->remote_identify.device_type ==
11303 SAS_EDGE_EXPANDER_DEVICE ||
11304 mpt3sas_port->remote_identify.device_type ==
11305 SAS_FANOUT_EXPANDER_DEVICE)
11306 mpt3sas_expander_remove(ioc,
11307 mpt3sas_port->remote_identify.sas_address,
11308 mpt3sas_port->hba_port);
11311 list_for_each_entry_safe(port, port_next,
11312 &ioc->port_table_list, list) {
11313 list_del(&port->list);
11317 /* free phys attached to the sas_host */
11318 if (ioc->sas_hba.num_phys) {
11319 kfree(ioc->sas_hba.phy);
11320 ioc->sas_hba.phy = NULL;
11321 ioc->sas_hba.num_phys = 0;
11324 mpt3sas_base_detach(ioc);
11325 mpt3sas_ctl_release(ioc);
11326 spin_lock(&gioc_lock);
11327 list_del(&ioc->list);
11328 spin_unlock(&gioc_lock);
11329 scsi_host_put(shost);
11333 * scsih_shutdown - routine call during system shutdown
11334 * @pdev: PCI device struct
11337 scsih_shutdown(struct pci_dev *pdev)
11339 struct Scsi_Host *shost;
11340 struct MPT3SAS_ADAPTER *ioc;
11341 struct workqueue_struct *wq;
11342 unsigned long flags;
11343 Mpi2ConfigReply_t mpi_reply;
11345 if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
11348 ioc->remove_host = 1;
11350 if (!pci_device_is_present(pdev)) {
11351 mpt3sas_base_pause_mq_polling(ioc);
11352 _scsih_flush_running_cmds(ioc);
11355 _scsih_fw_event_cleanup_queue(ioc);
11357 spin_lock_irqsave(&ioc->fw_event_lock, flags);
11358 wq = ioc->firmware_event_thread;
11359 ioc->firmware_event_thread = NULL;
11360 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
11362 destroy_workqueue(wq);
11364 * Copy back the unmodified ioc page1 so that on next driver load,
11365 * current modified changes on ioc page1 won't take effect.
11367 if (ioc->is_aero_ioc)
11368 mpt3sas_config_set_ioc_pg1(ioc, &mpi_reply,
11369 &ioc->ioc_pg1_copy);
11371 _scsih_ir_shutdown(ioc);
11372 _scsih_nvme_shutdown(ioc);
11373 mpt3sas_base_mask_interrupts(ioc);
11374 mpt3sas_base_stop_watchdog(ioc);
11375 ioc->shost_recovery = 1;
11376 mpt3sas_base_make_ioc_ready(ioc, SOFT_RESET);
11377 ioc->shost_recovery = 0;
11378 mpt3sas_base_free_irq(ioc);
11379 mpt3sas_base_disable_msix(ioc);
11384 * _scsih_probe_boot_devices - reports 1st device
11385 * @ioc: per adapter object
11387 * If specified in bios page 2, this routine reports the 1st
11388 * device scsi-ml or sas transport for persistent boot device
11389 * purposes. Please refer to function _scsih_determine_boot_device()
11392 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
11396 struct _sas_device *sas_device;
11397 struct _raid_device *raid_device;
11398 struct _pcie_device *pcie_device;
11400 u64 sas_address_parent;
11402 unsigned long flags;
11405 struct hba_port *port;
11407 /* no Bios, return immediately */
11408 if (!ioc->bios_pg3.BiosVersion)
11412 if (ioc->req_boot_device.device) {
11413 device = ioc->req_boot_device.device;
11414 channel = ioc->req_boot_device.channel;
11415 } else if (ioc->req_alt_boot_device.device) {
11416 device = ioc->req_alt_boot_device.device;
11417 channel = ioc->req_alt_boot_device.channel;
11418 } else if (ioc->current_boot_device.device) {
11419 device = ioc->current_boot_device.device;
11420 channel = ioc->current_boot_device.channel;
11426 if (channel == RAID_CHANNEL) {
11427 raid_device = device;
11429 * If this boot vd is already registered with SML then
11430 * no need to register it again as part of device scanning
11431 * after diag reset during driver load operation.
11433 if (raid_device->starget)
11435 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
11436 raid_device->id, 0);
11438 _scsih_raid_device_remove(ioc, raid_device);
11439 } else if (channel == PCIE_CHANNEL) {
11440 pcie_device = device;
11442 * If this boot NVMe device is already registered with SML then
11443 * no need to register it again as part of device scanning
11444 * after diag reset during driver load operation.
11446 if (pcie_device->starget)
11448 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
11449 tid = pcie_device->id;
11450 list_move_tail(&pcie_device->list, &ioc->pcie_device_list);
11451 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
11452 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL, tid, 0);
11454 _scsih_pcie_device_remove(ioc, pcie_device);
11456 sas_device = device;
11458 * If this boot sas/sata device is already registered with SML
11459 * then no need to register it again as part of device scanning
11460 * after diag reset during driver load operation.
11462 if (sas_device->starget)
11464 spin_lock_irqsave(&ioc->sas_device_lock, flags);
11465 handle = sas_device->handle;
11466 sas_address_parent = sas_device->sas_address_parent;
11467 sas_address = sas_device->sas_address;
11468 port = sas_device->port;
11469 list_move_tail(&sas_device->list, &ioc->sas_device_list);
11470 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
11472 if (ioc->hide_drives)
11478 if (!mpt3sas_transport_port_add(ioc, handle,
11479 sas_address_parent, port)) {
11480 _scsih_sas_device_remove(ioc, sas_device);
11481 } else if (!sas_device->starget) {
11482 if (!ioc->is_driver_loading) {
11483 mpt3sas_transport_port_remove(ioc,
11485 sas_address_parent, port);
11486 _scsih_sas_device_remove(ioc, sas_device);
11493 * _scsih_probe_raid - reporting raid volumes to scsi-ml
11494 * @ioc: per adapter object
11496 * Called during initial loading of the driver.
11499 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
11501 struct _raid_device *raid_device, *raid_next;
11504 list_for_each_entry_safe(raid_device, raid_next,
11505 &ioc->raid_device_list, list) {
11506 if (raid_device->starget)
11508 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
11509 raid_device->id, 0);
11511 _scsih_raid_device_remove(ioc, raid_device);
11515 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
11517 struct _sas_device *sas_device = NULL;
11518 unsigned long flags;
11520 spin_lock_irqsave(&ioc->sas_device_lock, flags);
11521 if (!list_empty(&ioc->sas_device_init_list)) {
11522 sas_device = list_first_entry(&ioc->sas_device_init_list,
11523 struct _sas_device, list);
11524 sas_device_get(sas_device);
11526 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
11531 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
11532 struct _sas_device *sas_device)
11534 unsigned long flags;
11536 spin_lock_irqsave(&ioc->sas_device_lock, flags);
11539 * Since we dropped the lock during the call to port_add(), we need to
11540 * be careful here that somebody else didn't move or delete this item
11541 * while we were busy with other things.
11543 * If it was on the list, we need a put() for the reference the list
11544 * had. Either way, we need a get() for the destination list.
11546 if (!list_empty(&sas_device->list)) {
11547 list_del_init(&sas_device->list);
11548 sas_device_put(sas_device);
11551 sas_device_get(sas_device);
11552 list_add_tail(&sas_device->list, &ioc->sas_device_list);
11554 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
11558 * _scsih_probe_sas - reporting sas devices to sas transport
11559 * @ioc: per adapter object
11561 * Called during initial loading of the driver.
11564 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
11566 struct _sas_device *sas_device;
11568 if (ioc->hide_drives)
11571 while ((sas_device = get_next_sas_device(ioc))) {
11572 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
11573 sas_device->sas_address_parent, sas_device->port)) {
11574 _scsih_sas_device_remove(ioc, sas_device);
11575 sas_device_put(sas_device);
11577 } else if (!sas_device->starget) {
11579 * When asyn scanning is enabled, its not possible to
11580 * remove devices while scanning is turned on due to an
11581 * oops in scsi_sysfs_add_sdev()->add_device()->
11582 * sysfs_addrm_start()
11584 if (!ioc->is_driver_loading) {
11585 mpt3sas_transport_port_remove(ioc,
11586 sas_device->sas_address,
11587 sas_device->sas_address_parent,
11589 _scsih_sas_device_remove(ioc, sas_device);
11590 sas_device_put(sas_device);
11594 sas_device_make_active(ioc, sas_device);
11595 sas_device_put(sas_device);
11600 * get_next_pcie_device - Get the next pcie device
11601 * @ioc: per adapter object
11603 * Get the next pcie device from pcie_device_init_list list.
11605 * Return: pcie device structure if pcie_device_init_list list is not empty
11606 * otherwise returns NULL
11608 static struct _pcie_device *get_next_pcie_device(struct MPT3SAS_ADAPTER *ioc)
11610 struct _pcie_device *pcie_device = NULL;
11611 unsigned long flags;
11613 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
11614 if (!list_empty(&ioc->pcie_device_init_list)) {
11615 pcie_device = list_first_entry(&ioc->pcie_device_init_list,
11616 struct _pcie_device, list);
11617 pcie_device_get(pcie_device);
11619 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
11621 return pcie_device;
11625 * pcie_device_make_active - Add pcie device to pcie_device_list list
11626 * @ioc: per adapter object
11627 * @pcie_device: pcie device object
11629 * Add the pcie device which has registered with SCSI Transport Later to
11630 * pcie_device_list list
11632 static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc,
11633 struct _pcie_device *pcie_device)
11635 unsigned long flags;
11637 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
11639 if (!list_empty(&pcie_device->list)) {
11640 list_del_init(&pcie_device->list);
11641 pcie_device_put(pcie_device);
11643 pcie_device_get(pcie_device);
11644 list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
11646 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
11650 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
11651 * @ioc: per adapter object
11653 * Called during initial loading of the driver.
11656 _scsih_probe_pcie(struct MPT3SAS_ADAPTER *ioc)
11658 struct _pcie_device *pcie_device;
11661 /* PCIe Device List */
11662 while ((pcie_device = get_next_pcie_device(ioc))) {
11663 if (pcie_device->starget) {
11664 pcie_device_put(pcie_device);
11667 if (pcie_device->access_status ==
11668 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED) {
11669 pcie_device_make_active(ioc, pcie_device);
11670 pcie_device_put(pcie_device);
11673 rc = scsi_add_device(ioc->shost, PCIE_CHANNEL,
11674 pcie_device->id, 0);
11676 _scsih_pcie_device_remove(ioc, pcie_device);
11677 pcie_device_put(pcie_device);
11679 } else if (!pcie_device->starget) {
11681 * When async scanning is enabled, its not possible to
11682 * remove devices while scanning is turned on due to an
11683 * oops in scsi_sysfs_add_sdev()->add_device()->
11684 * sysfs_addrm_start()
11686 if (!ioc->is_driver_loading) {
11687 /* TODO-- Need to find out whether this condition will
11690 _scsih_pcie_device_remove(ioc, pcie_device);
11691 pcie_device_put(pcie_device);
11695 pcie_device_make_active(ioc, pcie_device);
11696 pcie_device_put(pcie_device);
11701 * _scsih_probe_devices - probing for devices
11702 * @ioc: per adapter object
11704 * Called during initial loading of the driver.
11707 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
11709 u16 volume_mapping_flags;
11711 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
11712 return; /* return when IOC doesn't support initiator mode */
11714 _scsih_probe_boot_devices(ioc);
11716 if (ioc->ir_firmware) {
11717 volume_mapping_flags =
11718 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
11719 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
11720 if (volume_mapping_flags ==
11721 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
11722 _scsih_probe_raid(ioc);
11723 _scsih_probe_sas(ioc);
11725 _scsih_probe_sas(ioc);
11726 _scsih_probe_raid(ioc);
11729 _scsih_probe_sas(ioc);
11730 _scsih_probe_pcie(ioc);
11735 * scsih_scan_start - scsi lld callback for .scan_start
11736 * @shost: SCSI host pointer
11738 * The shost has the ability to discover targets on its own instead
11739 * of scanning the entire bus. In our implemention, we will kick off
11740 * firmware discovery.
11743 scsih_scan_start(struct Scsi_Host *shost)
11745 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
11747 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
11748 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
11749 else if (ioc->manu_pg11.HostTraceBufferMaxSizeKB != 0)
11750 mpt3sas_enable_diag_buffer(ioc, 1);
11752 if (disable_discovery > 0)
11755 ioc->start_scan = 1;
11756 rc = mpt3sas_port_enable(ioc);
11759 ioc_info(ioc, "port enable: FAILED\n");
11763 * _scsih_complete_devices_scanning - add the devices to sml and
11764 * complete ioc initialization.
11765 * @ioc: per adapter object
11769 static void _scsih_complete_devices_scanning(struct MPT3SAS_ADAPTER *ioc)
11772 if (ioc->wait_for_discovery_to_complete) {
11773 ioc->wait_for_discovery_to_complete = 0;
11774 _scsih_probe_devices(ioc);
11777 mpt3sas_base_start_watchdog(ioc);
11778 ioc->is_driver_loading = 0;
11782 * scsih_scan_finished - scsi lld callback for .scan_finished
11783 * @shost: SCSI host pointer
11784 * @time: elapsed time of the scan in jiffies
11786 * This function will be called periodicallyn until it returns 1 with the
11787 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
11788 * we wait for firmware discovery to complete, then return 1.
11791 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
11793 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
11795 int issue_hard_reset = 0;
11797 if (disable_discovery > 0) {
11798 ioc->is_driver_loading = 0;
11799 ioc->wait_for_discovery_to_complete = 0;
11803 if (time >= (300 * HZ)) {
11804 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
11805 ioc_info(ioc, "port enable: FAILED with timeout (timeout=300s)\n");
11806 ioc->is_driver_loading = 0;
11810 if (ioc->start_scan) {
11811 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
11812 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
11813 mpt3sas_print_fault_code(ioc, ioc_state &
11814 MPI2_DOORBELL_DATA_MASK);
11815 issue_hard_reset = 1;
11817 } else if ((ioc_state & MPI2_IOC_STATE_MASK) ==
11818 MPI2_IOC_STATE_COREDUMP) {
11819 mpt3sas_base_coredump_info(ioc, ioc_state &
11820 MPI2_DOORBELL_DATA_MASK);
11821 mpt3sas_base_wait_for_coredump_completion(ioc, __func__);
11822 issue_hard_reset = 1;
11828 if (ioc->port_enable_cmds.status & MPT3_CMD_RESET) {
11830 "port enable: aborted due to diag reset\n");
11831 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
11834 if (ioc->start_scan_failed) {
11835 ioc_info(ioc, "port enable: FAILED with (ioc_status=0x%08x)\n",
11836 ioc->start_scan_failed);
11837 ioc->is_driver_loading = 0;
11838 ioc->wait_for_discovery_to_complete = 0;
11839 ioc->remove_host = 1;
11843 ioc_info(ioc, "port enable: SUCCESS\n");
11844 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
11845 _scsih_complete_devices_scanning(ioc);
11848 if (issue_hard_reset) {
11849 ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED;
11850 if (mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET))
11851 ioc->is_driver_loading = 0;
11857 * scsih_map_queues - map reply queues with request queues
11858 * @shost: SCSI host pointer
11860 static void scsih_map_queues(struct Scsi_Host *shost)
11862 struct MPT3SAS_ADAPTER *ioc =
11863 (struct MPT3SAS_ADAPTER *)shost->hostdata;
11864 struct blk_mq_queue_map *map;
11865 int i, qoff, offset;
11866 int nr_msix_vectors = ioc->iopoll_q_start_index;
11867 int iopoll_q_count = ioc->reply_queue_count - nr_msix_vectors;
11869 if (shost->nr_hw_queues == 1)
11872 for (i = 0, qoff = 0; i < shost->nr_maps; i++) {
11873 map = &shost->tag_set.map[i];
11874 map->nr_queues = 0;
11876 if (i == HCTX_TYPE_DEFAULT) {
11878 nr_msix_vectors - ioc->high_iops_queues;
11879 offset = ioc->high_iops_queues;
11880 } else if (i == HCTX_TYPE_POLL)
11881 map->nr_queues = iopoll_q_count;
11883 if (!map->nr_queues)
11884 BUG_ON(i == HCTX_TYPE_DEFAULT);
11887 * The poll queue(s) doesn't have an IRQ (and hence IRQ
11888 * affinity), so use the regular blk-mq cpu mapping
11890 map->queue_offset = qoff;
11891 if (i != HCTX_TYPE_POLL)
11892 blk_mq_map_hw_queues(map, &ioc->pdev->dev, offset);
11894 blk_mq_map_queues(map);
11896 qoff += map->nr_queues;
11900 /* shost template for SAS 2.0 HBA devices */
11901 static const struct scsi_host_template mpt2sas_driver_template = {
11902 .module = THIS_MODULE,
11903 .name = "Fusion MPT SAS Host",
11904 .proc_name = MPT2SAS_DRIVER_NAME,
11905 .queuecommand = scsih_qcmd,
11906 .target_alloc = scsih_target_alloc,
11907 .sdev_init = scsih_sdev_init,
11908 .sdev_configure = scsih_sdev_configure,
11909 .target_destroy = scsih_target_destroy,
11910 .sdev_destroy = scsih_sdev_destroy,
11911 .scan_finished = scsih_scan_finished,
11912 .scan_start = scsih_scan_start,
11913 .change_queue_depth = scsih_change_queue_depth,
11914 .eh_abort_handler = scsih_abort,
11915 .eh_device_reset_handler = scsih_dev_reset,
11916 .eh_target_reset_handler = scsih_target_reset,
11917 .eh_host_reset_handler = scsih_host_reset,
11918 .bios_param = scsih_bios_param,
11921 .sg_tablesize = MPT2SAS_SG_DEPTH,
11922 .max_sectors = 32767,
11924 .shost_groups = mpt3sas_host_groups,
11925 .sdev_groups = mpt3sas_dev_groups,
11926 .track_queue_depth = 1,
11927 .cmd_size = sizeof(struct scsiio_tracker),
11930 /* raid transport support for SAS 2.0 HBA devices */
11931 static struct raid_function_template mpt2sas_raid_functions = {
11932 .cookie = &mpt2sas_driver_template,
11933 .is_raid = scsih_is_raid,
11934 .get_resync = scsih_get_resync,
11935 .get_state = scsih_get_state,
11938 /* shost template for SAS 3.0 HBA devices */
11939 static const struct scsi_host_template mpt3sas_driver_template = {
11940 .module = THIS_MODULE,
11941 .name = "Fusion MPT SAS Host",
11942 .proc_name = MPT3SAS_DRIVER_NAME,
11943 .queuecommand = scsih_qcmd,
11944 .target_alloc = scsih_target_alloc,
11945 .sdev_init = scsih_sdev_init,
11946 .sdev_configure = scsih_sdev_configure,
11947 .target_destroy = scsih_target_destroy,
11948 .sdev_destroy = scsih_sdev_destroy,
11949 .scan_finished = scsih_scan_finished,
11950 .scan_start = scsih_scan_start,
11951 .change_queue_depth = scsih_change_queue_depth,
11952 .eh_abort_handler = scsih_abort,
11953 .eh_device_reset_handler = scsih_dev_reset,
11954 .eh_target_reset_handler = scsih_target_reset,
11955 .eh_host_reset_handler = scsih_host_reset,
11956 .bios_param = scsih_bios_param,
11959 .sg_tablesize = MPT3SAS_SG_DEPTH,
11960 .max_sectors = 32767,
11961 .max_segment_size = 0xffffffff,
11962 .cmd_per_lun = 128,
11963 .shost_groups = mpt3sas_host_groups,
11964 .sdev_groups = mpt3sas_dev_groups,
11965 .track_queue_depth = 1,
11966 .cmd_size = sizeof(struct scsiio_tracker),
11967 .map_queues = scsih_map_queues,
11968 .mq_poll = mpt3sas_blk_mq_poll,
11971 /* raid transport support for SAS 3.0 HBA devices */
11972 static struct raid_function_template mpt3sas_raid_functions = {
11973 .cookie = &mpt3sas_driver_template,
11974 .is_raid = scsih_is_raid,
11975 .get_resync = scsih_get_resync,
11976 .get_state = scsih_get_state,
11980 * _scsih_determine_hba_mpi_version - determine in which MPI version class
11981 * this device belongs to.
11982 * @pdev: PCI device struct
11984 * return MPI2_VERSION for SAS 2.0 HBA devices,
11985 * MPI25_VERSION for SAS 3.0 HBA devices, and
11986 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
11989 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
11992 switch (pdev->device) {
11993 case MPI2_MFGPAGE_DEVID_SSS6200:
11994 case MPI2_MFGPAGE_DEVID_SAS2004:
11995 case MPI2_MFGPAGE_DEVID_SAS2008:
11996 case MPI2_MFGPAGE_DEVID_SAS2108_1:
11997 case MPI2_MFGPAGE_DEVID_SAS2108_2:
11998 case MPI2_MFGPAGE_DEVID_SAS2108_3:
11999 case MPI2_MFGPAGE_DEVID_SAS2116_1:
12000 case MPI2_MFGPAGE_DEVID_SAS2116_2:
12001 case MPI2_MFGPAGE_DEVID_SAS2208_1:
12002 case MPI2_MFGPAGE_DEVID_SAS2208_2:
12003 case MPI2_MFGPAGE_DEVID_SAS2208_3:
12004 case MPI2_MFGPAGE_DEVID_SAS2208_4:
12005 case MPI2_MFGPAGE_DEVID_SAS2208_5:
12006 case MPI2_MFGPAGE_DEVID_SAS2208_6:
12007 case MPI2_MFGPAGE_DEVID_SAS2308_1:
12008 case MPI2_MFGPAGE_DEVID_SAS2308_2:
12009 case MPI2_MFGPAGE_DEVID_SAS2308_3:
12010 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP:
12011 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1:
12012 return MPI2_VERSION;
12013 case MPI25_MFGPAGE_DEVID_SAS3004:
12014 case MPI25_MFGPAGE_DEVID_SAS3008:
12015 case MPI25_MFGPAGE_DEVID_SAS3108_1:
12016 case MPI25_MFGPAGE_DEVID_SAS3108_2:
12017 case MPI25_MFGPAGE_DEVID_SAS3108_5:
12018 case MPI25_MFGPAGE_DEVID_SAS3108_6:
12019 return MPI25_VERSION;
12020 case MPI26_MFGPAGE_DEVID_SAS3216:
12021 case MPI26_MFGPAGE_DEVID_SAS3224:
12022 case MPI26_MFGPAGE_DEVID_SAS3316_1:
12023 case MPI26_MFGPAGE_DEVID_SAS3316_2:
12024 case MPI26_MFGPAGE_DEVID_SAS3316_3:
12025 case MPI26_MFGPAGE_DEVID_SAS3316_4:
12026 case MPI26_MFGPAGE_DEVID_SAS3324_1:
12027 case MPI26_MFGPAGE_DEVID_SAS3324_2:
12028 case MPI26_MFGPAGE_DEVID_SAS3324_3:
12029 case MPI26_MFGPAGE_DEVID_SAS3324_4:
12030 case MPI26_MFGPAGE_DEVID_SAS3508:
12031 case MPI26_MFGPAGE_DEVID_SAS3508_1:
12032 case MPI26_MFGPAGE_DEVID_SAS3408:
12033 case MPI26_MFGPAGE_DEVID_SAS3516:
12034 case MPI26_MFGPAGE_DEVID_SAS3516_1:
12035 case MPI26_MFGPAGE_DEVID_SAS3416:
12036 case MPI26_MFGPAGE_DEVID_SAS3616:
12037 case MPI26_ATLAS_PCIe_SWITCH_DEVID:
12038 case MPI26_MFGPAGE_DEVID_CFG_SEC_3916:
12039 case MPI26_MFGPAGE_DEVID_HARD_SEC_3916:
12040 case MPI26_MFGPAGE_DEVID_CFG_SEC_3816:
12041 case MPI26_MFGPAGE_DEVID_HARD_SEC_3816:
12042 case MPI26_MFGPAGE_DEVID_INVALID0_3916:
12043 case MPI26_MFGPAGE_DEVID_INVALID1_3916:
12044 case MPI26_MFGPAGE_DEVID_INVALID0_3816:
12045 case MPI26_MFGPAGE_DEVID_INVALID1_3816:
12046 return MPI26_VERSION;
12052 * _scsih_probe - attach and add scsi host
12053 * @pdev: PCI device struct
12054 * @id: pci device id
12056 * Return: 0 success, anything else error.
12059 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
12061 struct MPT3SAS_ADAPTER *ioc;
12062 struct Scsi_Host *shost = NULL;
12064 u16 hba_mpi_version;
12065 int iopoll_q_count = 0;
12067 /* Determine in which MPI version class this pci device belongs */
12068 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
12069 if (hba_mpi_version == 0)
12072 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
12073 * for other generation HBA's return with -ENODEV
12075 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
12078 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
12079 * for other generation HBA's return with -ENODEV
12081 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
12082 || hba_mpi_version == MPI26_VERSION)))
12085 switch (hba_mpi_version) {
12087 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
12088 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
12089 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
12090 shost = scsi_host_alloc(&mpt2sas_driver_template,
12091 sizeof(struct MPT3SAS_ADAPTER));
12094 ioc = shost_priv(shost);
12095 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
12096 ioc->hba_mpi_version_belonged = hba_mpi_version;
12097 ioc->id = mpt2_ids++;
12098 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
12099 switch (pdev->device) {
12100 case MPI2_MFGPAGE_DEVID_SSS6200:
12101 ioc->is_warpdrive = 1;
12102 ioc->hide_ir_msg = 1;
12104 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP:
12105 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1:
12106 ioc->is_mcpu_endpoint = 1;
12109 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
12113 if (multipath_on_hba == -1 || multipath_on_hba == 0)
12114 ioc->multipath_on_hba = 0;
12116 ioc->multipath_on_hba = 1;
12119 case MPI25_VERSION:
12120 case MPI26_VERSION:
12121 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
12122 shost = scsi_host_alloc(&mpt3sas_driver_template,
12123 sizeof(struct MPT3SAS_ADAPTER));
12126 ioc = shost_priv(shost);
12127 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
12128 ioc->hba_mpi_version_belonged = hba_mpi_version;
12129 ioc->id = mpt3_ids++;
12130 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
12131 switch (pdev->device) {
12132 case MPI26_MFGPAGE_DEVID_SAS3508:
12133 case MPI26_MFGPAGE_DEVID_SAS3508_1:
12134 case MPI26_MFGPAGE_DEVID_SAS3408:
12135 case MPI26_MFGPAGE_DEVID_SAS3516:
12136 case MPI26_MFGPAGE_DEVID_SAS3516_1:
12137 case MPI26_MFGPAGE_DEVID_SAS3416:
12138 case MPI26_MFGPAGE_DEVID_SAS3616:
12139 case MPI26_ATLAS_PCIe_SWITCH_DEVID:
12140 ioc->is_gen35_ioc = 1;
12142 case MPI26_MFGPAGE_DEVID_INVALID0_3816:
12143 case MPI26_MFGPAGE_DEVID_INVALID0_3916:
12144 dev_err(&pdev->dev,
12145 "HBA with DeviceId 0x%04x, sub VendorId 0x%04x, sub DeviceId 0x%04x is Invalid",
12146 pdev->device, pdev->subsystem_vendor,
12147 pdev->subsystem_device);
12149 case MPI26_MFGPAGE_DEVID_INVALID1_3816:
12150 case MPI26_MFGPAGE_DEVID_INVALID1_3916:
12151 dev_err(&pdev->dev,
12152 "HBA with DeviceId 0x%04x, sub VendorId 0x%04x, sub DeviceId 0x%04x is Tampered",
12153 pdev->device, pdev->subsystem_vendor,
12154 pdev->subsystem_device);
12156 case MPI26_MFGPAGE_DEVID_CFG_SEC_3816:
12157 case MPI26_MFGPAGE_DEVID_CFG_SEC_3916:
12158 dev_info(&pdev->dev,
12159 "HBA is in Configurable Secure mode\n");
12161 case MPI26_MFGPAGE_DEVID_HARD_SEC_3816:
12162 case MPI26_MFGPAGE_DEVID_HARD_SEC_3916:
12163 ioc->is_aero_ioc = ioc->is_gen35_ioc = 1;
12166 ioc->is_gen35_ioc = ioc->is_aero_ioc = 0;
12168 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
12169 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
12170 (ioc->hba_mpi_version_belonged == MPI26_VERSION)) {
12171 ioc->combined_reply_queue = 1;
12172 if (ioc->is_gen35_ioc)
12173 ioc->combined_reply_index_count =
12174 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35;
12176 ioc->combined_reply_index_count =
12177 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3;
12180 switch (ioc->is_gen35_ioc) {
12182 if (multipath_on_hba == -1 || multipath_on_hba == 0)
12183 ioc->multipath_on_hba = 0;
12185 ioc->multipath_on_hba = 1;
12188 if (multipath_on_hba == -1 || multipath_on_hba > 0)
12189 ioc->multipath_on_hba = 1;
12191 ioc->multipath_on_hba = 0;
12202 INIT_LIST_HEAD(&ioc->list);
12203 spin_lock(&gioc_lock);
12204 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
12205 spin_unlock(&gioc_lock);
12206 ioc->shost = shost;
12208 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
12209 ioc->tm_cb_idx = tm_cb_idx;
12210 ioc->ctl_cb_idx = ctl_cb_idx;
12211 ioc->base_cb_idx = base_cb_idx;
12212 ioc->port_enable_cb_idx = port_enable_cb_idx;
12213 ioc->transport_cb_idx = transport_cb_idx;
12214 ioc->scsih_cb_idx = scsih_cb_idx;
12215 ioc->config_cb_idx = config_cb_idx;
12216 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
12217 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
12218 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
12219 ioc->logging_level = logging_level;
12220 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
12221 /* Host waits for minimum of six seconds */
12222 ioc->max_shutdown_latency = IO_UNIT_CONTROL_SHUTDOWN_TIMEOUT;
12224 * Enable MEMORY MOVE support flag.
12226 ioc->drv_support_bitmap |= MPT_DRV_SUPPORT_BITMAP_MEMMOVE;
12227 /* Enable ADDITIONAL QUERY support flag. */
12228 ioc->drv_support_bitmap |= MPT_DRV_SUPPORT_BITMAP_ADDNLQUERY;
12230 ioc->enable_sdev_max_qd = enable_sdev_max_qd;
12232 /* misc semaphores and spin locks */
12233 mutex_init(&ioc->reset_in_progress_mutex);
12234 mutex_init(&ioc->hostdiag_unlock_mutex);
12235 /* initializing pci_access_mutex lock */
12236 mutex_init(&ioc->pci_access_mutex);
12237 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
12238 spin_lock_init(&ioc->scsi_lookup_lock);
12239 spin_lock_init(&ioc->sas_device_lock);
12240 spin_lock_init(&ioc->sas_node_lock);
12241 spin_lock_init(&ioc->fw_event_lock);
12242 spin_lock_init(&ioc->raid_device_lock);
12243 spin_lock_init(&ioc->pcie_device_lock);
12244 spin_lock_init(&ioc->diag_trigger_lock);
12246 INIT_LIST_HEAD(&ioc->sas_device_list);
12247 INIT_LIST_HEAD(&ioc->sas_device_init_list);
12248 INIT_LIST_HEAD(&ioc->sas_expander_list);
12249 INIT_LIST_HEAD(&ioc->enclosure_list);
12250 INIT_LIST_HEAD(&ioc->pcie_device_list);
12251 INIT_LIST_HEAD(&ioc->pcie_device_init_list);
12252 INIT_LIST_HEAD(&ioc->fw_event_list);
12253 INIT_LIST_HEAD(&ioc->raid_device_list);
12254 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
12255 INIT_LIST_HEAD(&ioc->delayed_tr_list);
12256 INIT_LIST_HEAD(&ioc->delayed_sc_list);
12257 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
12258 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
12259 INIT_LIST_HEAD(&ioc->reply_queue_list);
12260 INIT_LIST_HEAD(&ioc->port_table_list);
12262 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
12264 /* init shost parameters */
12265 shost->max_cmd_len = 32;
12266 shost->max_lun = max_lun;
12267 shost->transportt = mpt3sas_transport_template;
12268 shost->unique_id = ioc->id;
12270 if (ioc->is_mcpu_endpoint) {
12271 /* mCPU MPI support 64K max IO */
12272 shost->max_sectors = 128;
12273 ioc_info(ioc, "The max_sectors value is set to %d\n",
12274 shost->max_sectors);
12276 if (max_sectors != 0xFFFF) {
12277 if (max_sectors < 64) {
12278 shost->max_sectors = 64;
12279 ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767. Assigning value of 64.\n",
12281 } else if (max_sectors > 32767) {
12282 shost->max_sectors = 32767;
12283 ioc_warn(ioc, "Invalid value %d passed for max_sectors, range is 64 to 32767.Assigning default value of 32767.\n",
12286 shost->max_sectors = max_sectors & 0xFFFE;
12287 ioc_info(ioc, "The max_sectors value is set to %d\n",
12288 shost->max_sectors);
12292 /* register EEDP capabilities with SCSI layer */
12293 if (prot_mask >= 0)
12294 scsi_host_set_prot(shost, (prot_mask & 0x07));
12296 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
12297 | SHOST_DIF_TYPE2_PROTECTION
12298 | SHOST_DIF_TYPE3_PROTECTION);
12300 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
12303 ioc->firmware_event_thread = alloc_ordered_workqueue(
12304 "fw_event_%s%d", 0, ioc->driver_name, ioc->id);
12305 if (!ioc->firmware_event_thread) {
12306 ioc_err(ioc, "failure at %s:%d/%s()!\n",
12307 __FILE__, __LINE__, __func__);
12309 goto out_thread_fail;
12312 shost->host_tagset = 0;
12314 if (ioc->is_gen35_ioc && host_tagset_enable)
12315 shost->host_tagset = 1;
12317 ioc->is_driver_loading = 1;
12318 if ((mpt3sas_base_attach(ioc))) {
12319 ioc_err(ioc, "failure at %s:%d/%s()!\n",
12320 __FILE__, __LINE__, __func__);
12322 goto out_attach_fail;
12325 if (ioc->is_warpdrive) {
12326 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
12327 ioc->hide_drives = 0;
12328 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
12329 ioc->hide_drives = 1;
12331 if (mpt3sas_get_num_volumes(ioc))
12332 ioc->hide_drives = 1;
12334 ioc->hide_drives = 0;
12337 ioc->hide_drives = 0;
12339 shost->nr_hw_queues = 1;
12341 if (shost->host_tagset) {
12342 shost->nr_hw_queues =
12343 ioc->reply_queue_count - ioc->high_iops_queues;
12346 ioc->reply_queue_count - ioc->iopoll_q_start_index;
12348 shost->nr_maps = iopoll_q_count ? 3 : 1;
12350 dev_info(&ioc->pdev->dev,
12351 "Max SCSIIO MPT commands: %d shared with nr_hw_queues = %d\n",
12352 shost->can_queue, shost->nr_hw_queues);
12355 rv = scsi_add_host(shost, &pdev->dev);
12357 ioc_err(ioc, "failure at %s:%d/%s()!\n",
12358 __FILE__, __LINE__, __func__);
12359 goto out_add_shost_fail;
12362 scsi_scan_host(shost);
12363 mpt3sas_setup_debugfs(ioc);
12365 out_add_shost_fail:
12366 mpt3sas_base_detach(ioc);
12368 destroy_workqueue(ioc->firmware_event_thread);
12370 spin_lock(&gioc_lock);
12371 list_del(&ioc->list);
12372 spin_unlock(&gioc_lock);
12373 scsi_host_put(shost);
12378 * scsih_suspend - power management suspend main entry point
12379 * @dev: Device struct
12381 * Return: 0 success, anything else error.
12383 static int __maybe_unused
12384 scsih_suspend(struct device *dev)
12386 struct pci_dev *pdev = to_pci_dev(dev);
12387 struct Scsi_Host *shost;
12388 struct MPT3SAS_ADAPTER *ioc;
12391 rc = _scsih_get_shost_and_ioc(pdev, &shost, &ioc);
12395 mpt3sas_base_stop_watchdog(ioc);
12396 scsi_block_requests(shost);
12397 _scsih_nvme_shutdown(ioc);
12398 ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state\n",
12399 pdev, pci_name(pdev));
12401 mpt3sas_base_free_resources(ioc);
12406 * scsih_resume - power management resume main entry point
12407 * @dev: Device struct
12409 * Return: 0 success, anything else error.
12411 static int __maybe_unused
12412 scsih_resume(struct device *dev)
12414 struct pci_dev *pdev = to_pci_dev(dev);
12415 struct Scsi_Host *shost;
12416 struct MPT3SAS_ADAPTER *ioc;
12417 pci_power_t device_state = pdev->current_state;
12420 r = _scsih_get_shost_and_ioc(pdev, &shost, &ioc);
12424 ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
12425 pdev, pci_name(pdev), device_state);
12428 r = mpt3sas_base_map_resources(ioc);
12431 ioc_info(ioc, "Issuing Hard Reset as part of OS Resume\n");
12432 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
12433 scsi_unblock_requests(shost);
12434 mpt3sas_base_start_watchdog(ioc);
12439 * scsih_pci_error_detected - Called when a PCI error is detected.
12440 * @pdev: PCI device struct
12441 * @state: PCI channel state
12443 * Description: Called when a PCI error is detected.
12445 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
12447 static pci_ers_result_t
12448 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12450 struct Scsi_Host *shost;
12451 struct MPT3SAS_ADAPTER *ioc;
12453 if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
12454 return PCI_ERS_RESULT_DISCONNECT;
12456 ioc_info(ioc, "PCI error: detected callback, state(%d)!!\n", state);
12459 case pci_channel_io_normal:
12460 return PCI_ERS_RESULT_CAN_RECOVER;
12461 case pci_channel_io_frozen:
12462 /* Fatal error, prepare for slot reset */
12463 ioc->pci_error_recovery = 1;
12464 scsi_block_requests(ioc->shost);
12465 mpt3sas_base_stop_watchdog(ioc);
12466 mpt3sas_base_free_resources(ioc);
12467 return PCI_ERS_RESULT_NEED_RESET;
12468 case pci_channel_io_perm_failure:
12469 /* Permanent error, prepare for device removal */
12470 ioc->pci_error_recovery = 1;
12471 mpt3sas_base_stop_watchdog(ioc);
12472 mpt3sas_base_pause_mq_polling(ioc);
12473 _scsih_flush_running_cmds(ioc);
12474 return PCI_ERS_RESULT_DISCONNECT;
12476 return PCI_ERS_RESULT_NEED_RESET;
12480 * scsih_pci_slot_reset - Called when PCI slot has been reset.
12481 * @pdev: PCI device struct
12483 * Description: This routine is called by the pci error recovery
12484 * code after the PCI slot has been reset, just before we
12485 * should resume normal operations.
12487 static pci_ers_result_t
12488 scsih_pci_slot_reset(struct pci_dev *pdev)
12490 struct Scsi_Host *shost;
12491 struct MPT3SAS_ADAPTER *ioc;
12494 if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
12495 return PCI_ERS_RESULT_DISCONNECT;
12497 ioc_info(ioc, "PCI error: slot reset callback!!\n");
12499 ioc->pci_error_recovery = 0;
12501 pci_restore_state(pdev);
12502 rc = mpt3sas_base_map_resources(ioc);
12504 return PCI_ERS_RESULT_DISCONNECT;
12506 ioc_info(ioc, "Issuing Hard Reset as part of PCI Slot Reset\n");
12507 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
12509 ioc_warn(ioc, "hard reset: %s\n",
12510 (rc == 0) ? "success" : "failed");
12513 return PCI_ERS_RESULT_RECOVERED;
12515 return PCI_ERS_RESULT_DISCONNECT;
12519 * scsih_pci_resume() - resume normal ops after PCI reset
12520 * @pdev: pointer to PCI device
12522 * Called when the error recovery driver tells us that its
12523 * OK to resume normal operation. Use completion to allow
12524 * halted scsi ops to resume.
12527 scsih_pci_resume(struct pci_dev *pdev)
12529 struct Scsi_Host *shost;
12530 struct MPT3SAS_ADAPTER *ioc;
12532 if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
12535 ioc_info(ioc, "PCI error: resume callback!!\n");
12537 mpt3sas_base_start_watchdog(ioc);
12538 scsi_unblock_requests(ioc->shost);
12542 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
12543 * @pdev: pointer to PCI device
12545 static pci_ers_result_t
12546 scsih_pci_mmio_enabled(struct pci_dev *pdev)
12548 struct Scsi_Host *shost;
12549 struct MPT3SAS_ADAPTER *ioc;
12551 if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc))
12552 return PCI_ERS_RESULT_DISCONNECT;
12554 ioc_info(ioc, "PCI error: mmio enabled callback!!\n");
12556 /* TODO - dump whatever for debugging purposes */
12558 /* This called only if scsih_pci_error_detected returns
12559 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
12560 * works, no need to reset slot.
12562 return PCI_ERS_RESULT_RECOVERED;
12566 * The pci device ids are defined in mpi/mpi2_cnfg.h.
12568 static const struct pci_device_id mpt3sas_pci_table[] = {
12569 /* Spitfire ~ 2004 */
12570 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
12571 PCI_ANY_ID, PCI_ANY_ID },
12572 /* Falcon ~ 2008 */
12573 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
12574 PCI_ANY_ID, PCI_ANY_ID },
12575 /* Liberator ~ 2108 */
12576 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
12577 PCI_ANY_ID, PCI_ANY_ID },
12578 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
12579 PCI_ANY_ID, PCI_ANY_ID },
12580 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
12581 PCI_ANY_ID, PCI_ANY_ID },
12582 /* Meteor ~ 2116 */
12583 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
12584 PCI_ANY_ID, PCI_ANY_ID },
12585 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
12586 PCI_ANY_ID, PCI_ANY_ID },
12587 /* Thunderbolt ~ 2208 */
12588 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
12589 PCI_ANY_ID, PCI_ANY_ID },
12590 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
12591 PCI_ANY_ID, PCI_ANY_ID },
12592 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
12593 PCI_ANY_ID, PCI_ANY_ID },
12594 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
12595 PCI_ANY_ID, PCI_ANY_ID },
12596 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
12597 PCI_ANY_ID, PCI_ANY_ID },
12598 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
12599 PCI_ANY_ID, PCI_ANY_ID },
12600 /* Mustang ~ 2308 */
12601 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
12602 PCI_ANY_ID, PCI_ANY_ID },
12603 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
12604 PCI_ANY_ID, PCI_ANY_ID },
12605 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
12606 PCI_ANY_ID, PCI_ANY_ID },
12607 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP,
12608 PCI_ANY_ID, PCI_ANY_ID },
12609 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1,
12610 PCI_ANY_ID, PCI_ANY_ID },
12612 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
12613 PCI_ANY_ID, PCI_ANY_ID },
12614 /* Fury ~ 3004 and 3008 */
12615 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
12616 PCI_ANY_ID, PCI_ANY_ID },
12617 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
12618 PCI_ANY_ID, PCI_ANY_ID },
12619 /* Invader ~ 3108 */
12620 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
12621 PCI_ANY_ID, PCI_ANY_ID },
12622 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
12623 PCI_ANY_ID, PCI_ANY_ID },
12624 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
12625 PCI_ANY_ID, PCI_ANY_ID },
12626 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
12627 PCI_ANY_ID, PCI_ANY_ID },
12628 /* Cutlass ~ 3216 and 3224 */
12629 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
12630 PCI_ANY_ID, PCI_ANY_ID },
12631 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
12632 PCI_ANY_ID, PCI_ANY_ID },
12633 /* Intruder ~ 3316 and 3324 */
12634 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
12635 PCI_ANY_ID, PCI_ANY_ID },
12636 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
12637 PCI_ANY_ID, PCI_ANY_ID },
12638 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
12639 PCI_ANY_ID, PCI_ANY_ID },
12640 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
12641 PCI_ANY_ID, PCI_ANY_ID },
12642 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
12643 PCI_ANY_ID, PCI_ANY_ID },
12644 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
12645 PCI_ANY_ID, PCI_ANY_ID },
12646 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
12647 PCI_ANY_ID, PCI_ANY_ID },
12648 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
12649 PCI_ANY_ID, PCI_ANY_ID },
12650 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
12651 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508,
12652 PCI_ANY_ID, PCI_ANY_ID },
12653 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3508_1,
12654 PCI_ANY_ID, PCI_ANY_ID },
12655 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3408,
12656 PCI_ANY_ID, PCI_ANY_ID },
12657 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516,
12658 PCI_ANY_ID, PCI_ANY_ID },
12659 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3516_1,
12660 PCI_ANY_ID, PCI_ANY_ID },
12661 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3416,
12662 PCI_ANY_ID, PCI_ANY_ID },
12663 /* Mercator ~ 3616*/
12664 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3616,
12665 PCI_ANY_ID, PCI_ANY_ID },
12667 /* Aero SI 0x00E1 Configurable Secure
12668 * 0x00E2 Hard Secure
12670 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_CFG_SEC_3916,
12671 PCI_ANY_ID, PCI_ANY_ID },
12672 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_HARD_SEC_3916,
12673 PCI_ANY_ID, PCI_ANY_ID },
12676 * Aero SI –> 0x00E0 Invalid, 0x00E3 Tampered
12678 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_INVALID0_3916,
12679 PCI_ANY_ID, PCI_ANY_ID },
12680 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_INVALID1_3916,
12681 PCI_ANY_ID, PCI_ANY_ID },
12683 /* Atlas PCIe Switch Management Port */
12684 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_ATLAS_PCIe_SWITCH_DEVID,
12685 PCI_ANY_ID, PCI_ANY_ID },
12687 /* Sea SI 0x00E5 Configurable Secure
12688 * 0x00E6 Hard Secure
12690 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_CFG_SEC_3816,
12691 PCI_ANY_ID, PCI_ANY_ID },
12692 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_HARD_SEC_3816,
12693 PCI_ANY_ID, PCI_ANY_ID },
12696 * ATTO Branded ExpressSAS H12xx GT
12698 { MPI2_MFGPAGE_VENDORID_ATTO, MPI26_MFGPAGE_DEVID_HARD_SEC_3816,
12699 PCI_ANY_ID, PCI_ANY_ID },
12702 * Sea SI –> 0x00E4 Invalid, 0x00E7 Tampered
12704 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_INVALID0_3816,
12705 PCI_ANY_ID, PCI_ANY_ID },
12706 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_INVALID1_3816,
12707 PCI_ANY_ID, PCI_ANY_ID },
12709 {0} /* Terminating entry */
12711 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
12713 static struct pci_error_handlers _mpt3sas_err_handler = {
12714 .error_detected = scsih_pci_error_detected,
12715 .mmio_enabled = scsih_pci_mmio_enabled,
12716 .slot_reset = scsih_pci_slot_reset,
12717 .resume = scsih_pci_resume,
12720 static SIMPLE_DEV_PM_OPS(scsih_pm_ops, scsih_suspend, scsih_resume);
12722 static struct pci_driver mpt3sas_driver = {
12723 .name = MPT3SAS_DRIVER_NAME,
12724 .id_table = mpt3sas_pci_table,
12725 .probe = _scsih_probe,
12726 .remove = scsih_remove,
12727 .shutdown = scsih_shutdown,
12728 .err_handler = &_mpt3sas_err_handler,
12729 .driver.pm = &scsih_pm_ops,
12733 * scsih_init - main entry point for this driver.
12735 * Return: 0 success, anything else error.
12743 mpt3sas_base_initialize_callback_handler();
12745 /* queuecommand callback hander */
12746 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
12748 /* task management callback handler */
12749 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
12751 /* base internal commands callback handler */
12752 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
12753 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
12754 mpt3sas_port_enable_done);
12756 /* transport internal commands callback handler */
12757 transport_cb_idx = mpt3sas_base_register_callback_handler(
12758 mpt3sas_transport_done);
12760 /* scsih internal commands callback handler */
12761 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
12763 /* configuration page API internal commands callback handler */
12764 config_cb_idx = mpt3sas_base_register_callback_handler(
12765 mpt3sas_config_done);
12767 /* ctl module callback handler */
12768 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
12770 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
12771 _scsih_tm_tr_complete);
12773 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
12774 _scsih_tm_volume_tr_complete);
12776 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
12777 _scsih_sas_control_complete);
12779 mpt3sas_init_debugfs();
12784 * scsih_exit - exit point for this driver (when it is a module).
12786 * Return: 0 success, anything else error.
12792 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
12793 mpt3sas_base_release_callback_handler(tm_cb_idx);
12794 mpt3sas_base_release_callback_handler(base_cb_idx);
12795 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
12796 mpt3sas_base_release_callback_handler(transport_cb_idx);
12797 mpt3sas_base_release_callback_handler(scsih_cb_idx);
12798 mpt3sas_base_release_callback_handler(config_cb_idx);
12799 mpt3sas_base_release_callback_handler(ctl_cb_idx);
12801 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
12802 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
12803 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
12805 /* raid transport support */
12806 if (hbas_to_enumerate != 1)
12807 raid_class_release(mpt3sas_raid_template);
12808 if (hbas_to_enumerate != 2)
12809 raid_class_release(mpt2sas_raid_template);
12810 sas_release_transport(mpt3sas_transport_template);
12811 mpt3sas_exit_debugfs();
12815 * _mpt3sas_init - main entry point for this driver.
12817 * Return: 0 success, anything else error.
12820 _mpt3sas_init(void)
12824 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
12825 MPT3SAS_DRIVER_VERSION);
12827 mpt3sas_transport_template =
12828 sas_attach_transport(&mpt3sas_transport_functions);
12829 if (!mpt3sas_transport_template)
12832 /* No need attach mpt3sas raid functions template
12833 * if hbas_to_enumarate value is one.
12835 if (hbas_to_enumerate != 1) {
12836 mpt3sas_raid_template =
12837 raid_class_attach(&mpt3sas_raid_functions);
12838 if (!mpt3sas_raid_template) {
12839 sas_release_transport(mpt3sas_transport_template);
12844 /* No need to attach mpt2sas raid functions template
12845 * if hbas_to_enumarate value is two
12847 if (hbas_to_enumerate != 2) {
12848 mpt2sas_raid_template =
12849 raid_class_attach(&mpt2sas_raid_functions);
12850 if (!mpt2sas_raid_template) {
12851 sas_release_transport(mpt3sas_transport_template);
12856 error = scsih_init();
12862 mpt3sas_ctl_init(hbas_to_enumerate);
12864 error = pci_register_driver(&mpt3sas_driver);
12866 mpt3sas_ctl_exit(hbas_to_enumerate);
12874 * _mpt3sas_exit - exit point for this driver (when it is a module).
12878 _mpt3sas_exit(void)
12880 pr_info("mpt3sas version %s unloading\n",
12881 MPT3SAS_DRIVER_VERSION);
12883 pci_unregister_driver(&mpt3sas_driver);
12885 mpt3sas_ctl_exit(hbas_to_enumerate);
12890 module_init(_mpt3sas_init);
12891 module_exit(_mpt3sas_exit);