2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/pci-aspm.h>
55 #include <linux/interrupt.h>
56 #include <linux/aer.h>
57 #include <linux/raid_class.h>
58 #include <asm/unaligned.h>
60 #include "mpt3sas_base.h"
62 #define RAID_CHANNEL 1
64 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
65 struct _sas_node *sas_expander);
66 static void _firmware_event_work(struct work_struct *work);
68 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
69 struct _sas_device *sas_device);
70 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
71 u8 retry_count, u8 is_pd);
73 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
75 /* global parameters */
76 LIST_HEAD(mpt3sas_ioc_list);
77 /* global ioc lock for list operations */
78 DEFINE_SPINLOCK(gioc_lock);
80 MODULE_AUTHOR(MPT3SAS_AUTHOR);
81 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
82 MODULE_LICENSE("GPL");
83 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
84 MODULE_ALIAS("mpt2sas");
86 /* local parameters */
87 static u8 scsi_io_cb_idx = -1;
88 static u8 tm_cb_idx = -1;
89 static u8 ctl_cb_idx = -1;
90 static u8 base_cb_idx = -1;
91 static u8 port_enable_cb_idx = -1;
92 static u8 transport_cb_idx = -1;
93 static u8 scsih_cb_idx = -1;
94 static u8 config_cb_idx = -1;
98 static u8 tm_tr_cb_idx = -1 ;
99 static u8 tm_tr_volume_cb_idx = -1 ;
100 static u8 tm_sas_control_cb_idx = -1;
102 /* command line options */
103 static u32 logging_level;
104 MODULE_PARM_DESC(logging_level,
105 " bits for enabling additional logging info (default=0)");
108 static ushort max_sectors = 0xFFFF;
109 module_param(max_sectors, ushort, 0);
110 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
113 static int missing_delay[2] = {-1, -1};
114 module_param_array(missing_delay, int, NULL, 0);
115 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
117 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
118 #define MPT3SAS_MAX_LUN (16895)
119 static u64 max_lun = MPT3SAS_MAX_LUN;
120 module_param(max_lun, ullong, 0);
121 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
123 static ushort hbas_to_enumerate;
124 module_param(hbas_to_enumerate, ushort, 0);
125 MODULE_PARM_DESC(hbas_to_enumerate,
126 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
127 1 - enumerates only SAS 2.0 generation HBAs\n \
128 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
130 /* diag_buffer_enable is bitwise
132 * bit 1 set = SNAPSHOT
133 * bit 2 set = EXTENDED
135 * Either bit can be set, or both
137 static int diag_buffer_enable = -1;
138 module_param(diag_buffer_enable, int, 0);
139 MODULE_PARM_DESC(diag_buffer_enable,
140 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
141 static int disable_discovery = -1;
142 module_param(disable_discovery, int, 0);
143 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
146 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
147 static int prot_mask = -1;
148 module_param(prot_mask, int, 0);
149 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
152 /* raid transport support */
153 struct raid_template *mpt3sas_raid_template;
154 struct raid_template *mpt2sas_raid_template;
158 * struct sense_info - common structure for obtaining sense keys
160 * @asc: additional sense code
161 * @ascq: additional sense code qualifier
169 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
170 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
171 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
172 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
173 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
175 * struct fw_event_work - firmware event struct
176 * @list: link list framework
177 * @work: work object (ioc->fault_reset_work_q)
178 * @ioc: per adapter object
179 * @device_handle: device handle
180 * @VF_ID: virtual function id
181 * @VP_ID: virtual port id
182 * @ignore: flag meaning this event has been marked to ignore
183 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
184 * @refcount: kref for this event
185 * @event_data: reply event data payload follows
187 * This object stored on ioc->fw_event_list.
189 struct fw_event_work {
190 struct list_head list;
191 struct work_struct work;
193 struct MPT3SAS_ADAPTER *ioc;
199 struct kref refcount;
200 char event_data[0] __aligned(4);
203 static void fw_event_work_free(struct kref *r)
205 kfree(container_of(r, struct fw_event_work, refcount));
208 static void fw_event_work_get(struct fw_event_work *fw_work)
210 kref_get(&fw_work->refcount);
213 static void fw_event_work_put(struct fw_event_work *fw_work)
215 kref_put(&fw_work->refcount, fw_event_work_free);
218 static struct fw_event_work *alloc_fw_event_work(int len)
220 struct fw_event_work *fw_event;
222 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
226 kref_init(&fw_event->refcount);
231 * struct _scsi_io_transfer - scsi io transfer
232 * @handle: sas device handle (assigned by firmware)
233 * @is_raid: flag set for hidden raid components
234 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
235 * @data_length: data transfer length
236 * @data_dma: dma pointer to data
239 * @cdb_length: cdb length
241 * @timeout: timeout for this command
242 * @VF_ID: virtual function id
243 * @VP_ID: virtual port id
244 * @valid_reply: flag set for reply message
245 * @sense_length: sense length
246 * @ioc_status: ioc status
247 * @scsi_state: scsi state
248 * @scsi_status: scsi staus
249 * @log_info: log information
250 * @transfer_length: data length transfer when there is a reply message
252 * Used for sending internal scsi commands to devices within this module.
253 * Refer to _scsi_send_scsi_io().
255 struct _scsi_io_transfer {
258 enum dma_data_direction dir;
261 u8 sense[SCSI_SENSE_BUFFERSIZE];
269 /* the following bits are only valid when 'valid_reply = 1' */
279 * _scsih_set_debug_level - global setting of ioc->logging_level.
281 * Note: The logging levels are defined in mpt3sas_debug.h.
284 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
286 int ret = param_set_int(val, kp);
287 struct MPT3SAS_ADAPTER *ioc;
292 pr_info("setting logging_level(0x%08x)\n", logging_level);
293 spin_lock(&gioc_lock);
294 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
295 ioc->logging_level = logging_level;
296 spin_unlock(&gioc_lock);
299 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
300 &logging_level, 0644);
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
307 * Returns 1 when there's a match, 0 means no match.
310 _scsih_srch_boot_sas_address(u64 sas_address,
311 Mpi2BootDeviceSasWwid_t *boot_device)
313 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_device_name(u64 device_name,
325 Mpi2BootDeviceDeviceName_t *boot_device)
327 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
336 * Returns 1 when there's a match, 0 means no match.
339 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
340 Mpi2BootDeviceEnclosureSlot_t *boot_device)
342 return (enclosure_logical_id == le64_to_cpu(boot_device->
343 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
344 SlotNumber)) ? 1 : 0;
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
356 * Returns 1 when there's a match, 0 means no match.
359 _scsih_is_boot_device(u64 sas_address, u64 device_name,
360 u64 enclosure_logical_id, u16 slot, u8 form,
361 Mpi2BiosPage2BootDevice_t *boot_device)
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
369 rc = _scsih_srch_boot_sas_address(
370 sas_address, &boot_device->SasWwid);
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
373 if (!enclosure_logical_id)
375 rc = _scsih_srch_boot_encl_slot(
376 enclosure_logical_id,
377 slot, &boot_device->EnclosureSlot);
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
382 rc = _scsih_srch_boot_device_name(
383 device_name, &boot_device->DeviceName);
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
397 * Returns 0 success, non-zero when failure
400 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
403 Mpi2SasDevicePage0_t sas_device_pg0;
404 Mpi2ConfigReply_t mpi_reply;
409 if (handle <= ioc->sas_hba.num_phys) {
410 *sas_address = ioc->sas_hba.sas_address;
414 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
415 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
416 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
417 __FILE__, __LINE__, __func__);
421 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
422 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
423 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
427 /* we hit this becuase the given parent handle doesn't exist */
428 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
431 /* else error case */
433 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
434 ioc->name, handle, ioc_status,
435 __FILE__, __LINE__, __func__);
440 * _scsih_determine_boot_device - determine boot device.
441 * @ioc: per adapter object
442 * @device: either sas_device or raid_device object
443 * @is_raid: [flag] 1 = raid object, 0 = sas object
445 * Determines whether this device should be first reported device to
446 * to scsi-ml or sas transport, this purpose is for persistent boot device.
447 * There are primary, alternate, and current entries in bios page 2. The order
448 * priority is primary, alternate, then current. This routine saves
449 * the corresponding device object and is_raid flag in the ioc object.
450 * The saved data to be used later in _scsih_probe_boot_devices().
453 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
454 void *device, u8 is_raid)
456 struct _sas_device *sas_device;
457 struct _raid_device *raid_device;
460 u64 enclosure_logical_id;
463 /* only process this function when driver loads */
464 if (!ioc->is_driver_loading)
467 /* no Bios, return immediately */
468 if (!ioc->bios_pg3.BiosVersion)
473 sas_address = sas_device->sas_address;
474 device_name = sas_device->device_name;
475 enclosure_logical_id = sas_device->enclosure_logical_id;
476 slot = sas_device->slot;
478 raid_device = device;
479 sas_address = raid_device->wwid;
481 enclosure_logical_id = 0;
485 if (!ioc->req_boot_device.device) {
486 if (_scsih_is_boot_device(sas_address, device_name,
487 enclosure_logical_id, slot,
488 (ioc->bios_pg2.ReqBootDeviceForm &
489 MPI2_BIOSPAGE2_FORM_MASK),
490 &ioc->bios_pg2.RequestedBootDevice)) {
491 dinitprintk(ioc, pr_info(MPT3SAS_FMT
492 "%s: req_boot_device(0x%016llx)\n",
494 (unsigned long long)sas_address));
495 ioc->req_boot_device.device = device;
496 ioc->req_boot_device.is_raid = is_raid;
500 if (!ioc->req_alt_boot_device.device) {
501 if (_scsih_is_boot_device(sas_address, device_name,
502 enclosure_logical_id, slot,
503 (ioc->bios_pg2.ReqAltBootDeviceForm &
504 MPI2_BIOSPAGE2_FORM_MASK),
505 &ioc->bios_pg2.RequestedAltBootDevice)) {
506 dinitprintk(ioc, pr_info(MPT3SAS_FMT
507 "%s: req_alt_boot_device(0x%016llx)\n",
509 (unsigned long long)sas_address));
510 ioc->req_alt_boot_device.device = device;
511 ioc->req_alt_boot_device.is_raid = is_raid;
515 if (!ioc->current_boot_device.device) {
516 if (_scsih_is_boot_device(sas_address, device_name,
517 enclosure_logical_id, slot,
518 (ioc->bios_pg2.CurrentBootDeviceForm &
519 MPI2_BIOSPAGE2_FORM_MASK),
520 &ioc->bios_pg2.CurrentBootDevice)) {
521 dinitprintk(ioc, pr_info(MPT3SAS_FMT
522 "%s: current_boot_device(0x%016llx)\n",
524 (unsigned long long)sas_address));
525 ioc->current_boot_device.device = device;
526 ioc->current_boot_device.is_raid = is_raid;
531 static struct _sas_device *
532 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
533 struct MPT3SAS_TARGET *tgt_priv)
535 struct _sas_device *ret;
537 assert_spin_locked(&ioc->sas_device_lock);
539 ret = tgt_priv->sdev;
546 static struct _sas_device *
547 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
548 struct MPT3SAS_TARGET *tgt_priv)
550 struct _sas_device *ret;
553 spin_lock_irqsave(&ioc->sas_device_lock, flags);
554 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
555 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
562 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
565 struct _sas_device *sas_device;
567 assert_spin_locked(&ioc->sas_device_lock);
569 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
570 if (sas_device->sas_address == sas_address)
573 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
574 if (sas_device->sas_address == sas_address)
580 sas_device_get(sas_device);
585 * mpt3sas_get_sdev_by_addr - sas device search
586 * @ioc: per adapter object
587 * @sas_address: sas address
588 * Context: Calling function should acquire ioc->sas_device_lock
590 * This searches for sas_device based on sas_address, then return sas_device
594 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
597 struct _sas_device *sas_device;
600 spin_lock_irqsave(&ioc->sas_device_lock, flags);
601 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
603 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
608 static struct _sas_device *
609 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
611 struct _sas_device *sas_device;
613 assert_spin_locked(&ioc->sas_device_lock);
615 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
616 if (sas_device->handle == handle)
619 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
620 if (sas_device->handle == handle)
626 sas_device_get(sas_device);
631 * mpt3sas_get_sdev_by_handle - sas device search
632 * @ioc: per adapter object
633 * @handle: sas device handle (assigned by firmware)
634 * Context: Calling function should acquire ioc->sas_device_lock
636 * This searches for sas_device based on sas_address, then return sas_device
639 static struct _sas_device *
640 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
642 struct _sas_device *sas_device;
645 spin_lock_irqsave(&ioc->sas_device_lock, flags);
646 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
647 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
653 * _scsih_sas_device_remove - remove sas_device from list.
654 * @ioc: per adapter object
655 * @sas_device: the sas_device object
656 * Context: This function will acquire ioc->sas_device_lock.
658 * If sas_device is on the list, remove it and decrement its reference count.
661 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
662 struct _sas_device *sas_device)
669 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
670 ioc->name, sas_device->handle,
671 (unsigned long long) sas_device->sas_address);
673 if (sas_device->enclosure_handle != 0)
675 "removing enclosure logical id(0x%016llx), slot(%d)\n",
676 ioc->name, (unsigned long long)
677 sas_device->enclosure_logical_id, sas_device->slot);
679 if (sas_device->connector_name[0] != '\0')
681 "removing enclosure level(0x%04x), connector name( %s)\n",
682 ioc->name, sas_device->enclosure_level,
683 sas_device->connector_name);
686 * The lock serializes access to the list, but we still need to verify
687 * that nobody removed the entry while we were waiting on the lock.
689 spin_lock_irqsave(&ioc->sas_device_lock, flags);
690 if (!list_empty(&sas_device->list)) {
691 list_del_init(&sas_device->list);
692 sas_device_put(sas_device);
694 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
698 * _scsih_device_remove_by_handle - removing device object by handle
699 * @ioc: per adapter object
700 * @handle: device handle
705 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
707 struct _sas_device *sas_device;
710 if (ioc->shost_recovery)
713 spin_lock_irqsave(&ioc->sas_device_lock, flags);
714 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
716 list_del_init(&sas_device->list);
717 sas_device_put(sas_device);
719 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
721 _scsih_remove_device(ioc, sas_device);
722 sas_device_put(sas_device);
727 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
728 * @ioc: per adapter object
729 * @sas_address: device sas_address
734 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
737 struct _sas_device *sas_device;
740 if (ioc->shost_recovery)
743 spin_lock_irqsave(&ioc->sas_device_lock, flags);
744 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
746 list_del_init(&sas_device->list);
747 sas_device_put(sas_device);
749 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
751 _scsih_remove_device(ioc, sas_device);
752 sas_device_put(sas_device);
757 * _scsih_sas_device_add - insert sas_device to the list.
758 * @ioc: per adapter object
759 * @sas_device: the sas_device object
760 * Context: This function will acquire ioc->sas_device_lock.
762 * Adding new object to the ioc->sas_device_list.
765 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
766 struct _sas_device *sas_device)
770 dewtprintk(ioc, pr_info(MPT3SAS_FMT
771 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
772 ioc->name, __func__, sas_device->handle,
773 (unsigned long long)sas_device->sas_address));
775 if (sas_device->enclosure_handle != 0)
776 dewtprintk(ioc, pr_info(MPT3SAS_FMT
777 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
778 ioc->name, __func__, (unsigned long long)
779 sas_device->enclosure_logical_id, sas_device->slot));
781 if (sas_device->connector_name[0] != '\0')
782 dewtprintk(ioc, pr_info(MPT3SAS_FMT
783 "%s: enclosure level(0x%04x), connector name( %s)\n",
785 sas_device->enclosure_level, sas_device->connector_name));
787 spin_lock_irqsave(&ioc->sas_device_lock, flags);
788 sas_device_get(sas_device);
789 list_add_tail(&sas_device->list, &ioc->sas_device_list);
790 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
792 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
793 sas_device->sas_address_parent)) {
794 _scsih_sas_device_remove(ioc, sas_device);
795 } else if (!sas_device->starget) {
797 * When asyn scanning is enabled, its not possible to remove
798 * devices while scanning is turned on due to an oops in
799 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
801 if (!ioc->is_driver_loading) {
802 mpt3sas_transport_port_remove(ioc,
803 sas_device->sas_address,
804 sas_device->sas_address_parent);
805 _scsih_sas_device_remove(ioc, sas_device);
811 * _scsih_sas_device_init_add - insert sas_device to the list.
812 * @ioc: per adapter object
813 * @sas_device: the sas_device object
814 * Context: This function will acquire ioc->sas_device_lock.
816 * Adding new object at driver load time to the ioc->sas_device_init_list.
819 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
820 struct _sas_device *sas_device)
824 dewtprintk(ioc, pr_info(MPT3SAS_FMT
825 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
826 __func__, sas_device->handle,
827 (unsigned long long)sas_device->sas_address));
829 if (sas_device->enclosure_handle != 0)
830 dewtprintk(ioc, pr_info(MPT3SAS_FMT
831 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
832 ioc->name, __func__, (unsigned long long)
833 sas_device->enclosure_logical_id, sas_device->slot));
835 if (sas_device->connector_name[0] != '\0')
836 dewtprintk(ioc, pr_info(MPT3SAS_FMT
837 "%s: enclosure level(0x%04x), connector name( %s)\n",
838 ioc->name, __func__, sas_device->enclosure_level,
839 sas_device->connector_name));
841 spin_lock_irqsave(&ioc->sas_device_lock, flags);
842 sas_device_get(sas_device);
843 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
844 _scsih_determine_boot_device(ioc, sas_device, 0);
845 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
849 * _scsih_raid_device_find_by_id - raid device search
850 * @ioc: per adapter object
851 * @id: sas device target id
852 * @channel: sas device channel
853 * Context: Calling function should acquire ioc->raid_device_lock
855 * This searches for raid_device based on target id, then return raid_device
858 static struct _raid_device *
859 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
861 struct _raid_device *raid_device, *r;
864 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
865 if (raid_device->id == id && raid_device->channel == channel) {
876 * mpt3sas_raid_device_find_by_handle - raid device search
877 * @ioc: per adapter object
878 * @handle: sas device handle (assigned by firmware)
879 * Context: Calling function should acquire ioc->raid_device_lock
881 * This searches for raid_device based on handle, then return raid_device
884 struct _raid_device *
885 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
887 struct _raid_device *raid_device, *r;
890 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
891 if (raid_device->handle != handle)
902 * _scsih_raid_device_find_by_wwid - raid device search
903 * @ioc: per adapter object
904 * @handle: sas device handle (assigned by firmware)
905 * Context: Calling function should acquire ioc->raid_device_lock
907 * This searches for raid_device based on wwid, then return raid_device
910 static struct _raid_device *
911 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
913 struct _raid_device *raid_device, *r;
916 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
917 if (raid_device->wwid != wwid)
928 * _scsih_raid_device_add - add raid_device object
929 * @ioc: per adapter object
930 * @raid_device: raid_device object
932 * This is added to the raid_device_list link list.
935 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
936 struct _raid_device *raid_device)
940 dewtprintk(ioc, pr_info(MPT3SAS_FMT
941 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
942 raid_device->handle, (unsigned long long)raid_device->wwid));
944 spin_lock_irqsave(&ioc->raid_device_lock, flags);
945 list_add_tail(&raid_device->list, &ioc->raid_device_list);
946 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
950 * _scsih_raid_device_remove - delete raid_device object
951 * @ioc: per adapter object
952 * @raid_device: raid_device object
956 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
957 struct _raid_device *raid_device)
961 spin_lock_irqsave(&ioc->raid_device_lock, flags);
962 list_del(&raid_device->list);
964 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
968 * mpt3sas_scsih_expander_find_by_handle - expander device search
969 * @ioc: per adapter object
970 * @handle: expander handle (assigned by firmware)
971 * Context: Calling function should acquire ioc->sas_device_lock
973 * This searches for expander device based on handle, then returns the
977 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
979 struct _sas_node *sas_expander, *r;
982 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
983 if (sas_expander->handle != handle)
993 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
994 * @ioc: per adapter object
995 * @sas_address: sas address
996 * Context: Calling function should acquire ioc->sas_node_lock.
998 * This searches for expander device based on sas_address, then returns the
1002 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1005 struct _sas_node *sas_expander, *r;
1008 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1009 if (sas_expander->sas_address != sas_address)
1019 * _scsih_expander_node_add - insert expander device to the list.
1020 * @ioc: per adapter object
1021 * @sas_expander: the sas_device object
1022 * Context: This function will acquire ioc->sas_node_lock.
1024 * Adding new object to the ioc->sas_expander_list.
1029 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1030 struct _sas_node *sas_expander)
1032 unsigned long flags;
1034 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1035 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1036 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1040 * _scsih_is_end_device - determines if device is an end device
1041 * @device_info: bitfield providing information about the device.
1044 * Returns 1 if end device.
1047 _scsih_is_end_device(u32 device_info)
1049 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1050 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1051 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1052 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1059 * _scsih_scsi_lookup_get - returns scmd entry
1060 * @ioc: per adapter object
1061 * @smid: system request message index
1063 * Returns the smid stored scmd pointer.
1065 static struct scsi_cmnd *
1066 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1068 return ioc->scsi_lookup[smid - 1].scmd;
1072 * _scsih_scsi_lookup_get_clear - returns scmd entry
1073 * @ioc: per adapter object
1074 * @smid: system request message index
1076 * Returns the smid stored scmd pointer.
1077 * Then will derefrence the stored scmd pointer.
1079 static inline struct scsi_cmnd *
1080 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1082 unsigned long flags;
1083 struct scsi_cmnd *scmd;
1085 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1086 scmd = ioc->scsi_lookup[smid - 1].scmd;
1087 ioc->scsi_lookup[smid - 1].scmd = NULL;
1088 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1094 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1095 * @ioc: per adapter object
1096 * @smid: system request message index
1097 * @scmd: pointer to scsi command object
1098 * Context: This function will acquire ioc->scsi_lookup_lock.
1100 * This will search for a scmd pointer in the scsi_lookup array,
1101 * returning the revelent smid. A returned value of zero means invalid.
1104 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1108 unsigned long flags;
1111 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1113 for (i = 0; i < ioc->scsiio_depth; i++) {
1114 if (ioc->scsi_lookup[i].scmd == scmd) {
1115 smid = ioc->scsi_lookup[i].smid;
1120 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1125 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1126 * @ioc: per adapter object
1129 * Context: This function will acquire ioc->scsi_lookup_lock.
1131 * This will search for a matching channel:id in the scsi_lookup array,
1132 * returning 1 if found.
1135 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1139 unsigned long flags;
1142 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1144 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1145 if (ioc->scsi_lookup[i].scmd &&
1146 (ioc->scsi_lookup[i].scmd->device->id == id &&
1147 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1153 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1158 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1159 * @ioc: per adapter object
1163 * Context: This function will acquire ioc->scsi_lookup_lock.
1165 * This will search for a matching channel:id:lun in the scsi_lookup array,
1166 * returning 1 if found.
1169 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1170 unsigned int lun, int channel)
1173 unsigned long flags;
1176 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1178 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1179 if (ioc->scsi_lookup[i].scmd &&
1180 (ioc->scsi_lookup[i].scmd->device->id == id &&
1181 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1182 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1188 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1193 * scsih_change_queue_depth - setting device queue depth
1194 * @sdev: scsi device struct
1195 * @qdepth: requested queue depth
1197 * Returns queue depth.
1200 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1202 struct Scsi_Host *shost = sdev->host;
1204 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1205 struct MPT3SAS_DEVICE *sas_device_priv_data;
1206 struct MPT3SAS_TARGET *sas_target_priv_data;
1207 struct _sas_device *sas_device;
1208 unsigned long flags;
1210 max_depth = shost->can_queue;
1212 /* limit max device queue for SATA to 32 */
1213 sas_device_priv_data = sdev->hostdata;
1214 if (!sas_device_priv_data)
1216 sas_target_priv_data = sas_device_priv_data->sas_target;
1217 if (!sas_target_priv_data)
1219 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1222 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1223 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1225 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1226 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1228 sas_device_put(sas_device);
1230 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1234 if (!sdev->tagged_supported)
1236 if (qdepth > max_depth)
1238 return scsi_change_queue_depth(sdev, qdepth);
1242 * scsih_target_alloc - target add routine
1243 * @starget: scsi target struct
1245 * Returns 0 if ok. Any other return is assumed to be an error and
1246 * the device is ignored.
1249 scsih_target_alloc(struct scsi_target *starget)
1251 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1252 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1253 struct MPT3SAS_TARGET *sas_target_priv_data;
1254 struct _sas_device *sas_device;
1255 struct _raid_device *raid_device;
1256 unsigned long flags;
1257 struct sas_rphy *rphy;
1259 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1261 if (!sas_target_priv_data)
1264 starget->hostdata = sas_target_priv_data;
1265 sas_target_priv_data->starget = starget;
1266 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1269 if (starget->channel == RAID_CHANNEL) {
1270 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1271 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1274 sas_target_priv_data->handle = raid_device->handle;
1275 sas_target_priv_data->sas_address = raid_device->wwid;
1276 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1277 if (ioc->is_warpdrive)
1278 sas_target_priv_data->raid_device = raid_device;
1279 raid_device->starget = starget;
1281 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1285 /* sas/sata devices */
1286 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1287 rphy = dev_to_rphy(starget->dev.parent);
1288 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1289 rphy->identify.sas_address);
1292 sas_target_priv_data->handle = sas_device->handle;
1293 sas_target_priv_data->sas_address = sas_device->sas_address;
1294 sas_target_priv_data->sdev = sas_device;
1295 sas_device->starget = starget;
1296 sas_device->id = starget->id;
1297 sas_device->channel = starget->channel;
1298 if (test_bit(sas_device->handle, ioc->pd_handles))
1299 sas_target_priv_data->flags |=
1300 MPT_TARGET_FLAGS_RAID_COMPONENT;
1301 if (sas_device->fast_path)
1302 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1304 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1310 * scsih_target_destroy - target destroy routine
1311 * @starget: scsi target struct
1316 scsih_target_destroy(struct scsi_target *starget)
1318 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1319 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1320 struct MPT3SAS_TARGET *sas_target_priv_data;
1321 struct _sas_device *sas_device;
1322 struct _raid_device *raid_device;
1323 unsigned long flags;
1325 sas_target_priv_data = starget->hostdata;
1326 if (!sas_target_priv_data)
1329 if (starget->channel == RAID_CHANNEL) {
1330 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1331 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1334 raid_device->starget = NULL;
1335 raid_device->sdev = NULL;
1337 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1341 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1342 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1343 if (sas_device && (sas_device->starget == starget) &&
1344 (sas_device->id == starget->id) &&
1345 (sas_device->channel == starget->channel))
1346 sas_device->starget = NULL;
1350 * Corresponding get() is in _scsih_target_alloc()
1352 sas_target_priv_data->sdev = NULL;
1353 sas_device_put(sas_device);
1355 sas_device_put(sas_device);
1357 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1360 kfree(sas_target_priv_data);
1361 starget->hostdata = NULL;
1365 * scsih_slave_alloc - device add routine
1366 * @sdev: scsi device struct
1368 * Returns 0 if ok. Any other return is assumed to be an error and
1369 * the device is ignored.
1372 scsih_slave_alloc(struct scsi_device *sdev)
1374 struct Scsi_Host *shost;
1375 struct MPT3SAS_ADAPTER *ioc;
1376 struct MPT3SAS_TARGET *sas_target_priv_data;
1377 struct MPT3SAS_DEVICE *sas_device_priv_data;
1378 struct scsi_target *starget;
1379 struct _raid_device *raid_device;
1380 struct _sas_device *sas_device;
1381 unsigned long flags;
1383 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1385 if (!sas_device_priv_data)
1388 sas_device_priv_data->lun = sdev->lun;
1389 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1391 starget = scsi_target(sdev);
1392 sas_target_priv_data = starget->hostdata;
1393 sas_target_priv_data->num_luns++;
1394 sas_device_priv_data->sas_target = sas_target_priv_data;
1395 sdev->hostdata = sas_device_priv_data;
1396 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1397 sdev->no_uld_attach = 1;
1399 shost = dev_to_shost(&starget->dev);
1400 ioc = shost_priv(shost);
1401 if (starget->channel == RAID_CHANNEL) {
1402 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1403 raid_device = _scsih_raid_device_find_by_id(ioc,
1404 starget->id, starget->channel);
1406 raid_device->sdev = sdev; /* raid is single lun */
1407 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1410 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1411 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1412 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1413 sas_target_priv_data->sas_address);
1414 if (sas_device && (sas_device->starget == NULL)) {
1415 sdev_printk(KERN_INFO, sdev,
1416 "%s : sas_device->starget set to starget @ %d\n",
1417 __func__, __LINE__);
1418 sas_device->starget = starget;
1422 sas_device_put(sas_device);
1424 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1431 * scsih_slave_destroy - device destroy routine
1432 * @sdev: scsi device struct
1437 scsih_slave_destroy(struct scsi_device *sdev)
1439 struct MPT3SAS_TARGET *sas_target_priv_data;
1440 struct scsi_target *starget;
1441 struct Scsi_Host *shost;
1442 struct MPT3SAS_ADAPTER *ioc;
1443 struct _sas_device *sas_device;
1444 unsigned long flags;
1446 if (!sdev->hostdata)
1449 starget = scsi_target(sdev);
1450 sas_target_priv_data = starget->hostdata;
1451 sas_target_priv_data->num_luns--;
1453 shost = dev_to_shost(&starget->dev);
1454 ioc = shost_priv(shost);
1456 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1457 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1458 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1459 sas_target_priv_data);
1460 if (sas_device && !sas_target_priv_data->num_luns)
1461 sas_device->starget = NULL;
1464 sas_device_put(sas_device);
1465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1468 kfree(sdev->hostdata);
1469 sdev->hostdata = NULL;
1473 * _scsih_display_sata_capabilities - sata capabilities
1474 * @ioc: per adapter object
1475 * @handle: device handle
1476 * @sdev: scsi device struct
1479 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1480 u16 handle, struct scsi_device *sdev)
1482 Mpi2ConfigReply_t mpi_reply;
1483 Mpi2SasDevicePage0_t sas_device_pg0;
1488 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1489 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1490 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1491 ioc->name, __FILE__, __LINE__, __func__);
1495 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1496 MPI2_IOCSTATUS_MASK;
1497 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1498 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1499 ioc->name, __FILE__, __LINE__, __func__);
1503 flags = le16_to_cpu(sas_device_pg0.Flags);
1504 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1506 sdev_printk(KERN_INFO, sdev,
1507 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1508 "sw_preserve(%s)\n",
1509 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1510 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1511 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1513 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1515 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1519 * raid transport support -
1520 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1521 * unloading the driver followed by a load - I beleive that the subroutine
1522 * raid_class_release() is not cleaning up properly.
1526 * scsih_is_raid - return boolean indicating device is raid volume
1527 * @dev the device struct object
1530 scsih_is_raid(struct device *dev)
1532 struct scsi_device *sdev = to_scsi_device(dev);
1533 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1535 if (ioc->is_warpdrive)
1537 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1541 * scsih_get_resync - get raid volume resync percent complete
1542 * @dev the device struct object
1545 scsih_get_resync(struct device *dev)
1547 struct scsi_device *sdev = to_scsi_device(dev);
1548 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1549 static struct _raid_device *raid_device;
1550 unsigned long flags;
1551 Mpi2RaidVolPage0_t vol_pg0;
1552 Mpi2ConfigReply_t mpi_reply;
1553 u32 volume_status_flags;
1554 u8 percent_complete;
1557 percent_complete = 0;
1559 if (ioc->is_warpdrive)
1562 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1563 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1566 handle = raid_device->handle;
1567 percent_complete = raid_device->percent_complete;
1569 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1574 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1575 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1576 sizeof(Mpi2RaidVolPage0_t))) {
1577 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1578 ioc->name, __FILE__, __LINE__, __func__);
1579 percent_complete = 0;
1583 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1584 if (!(volume_status_flags &
1585 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1586 percent_complete = 0;
1590 switch (ioc->hba_mpi_version_belonged) {
1592 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1596 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1602 * scsih_get_state - get raid volume level
1603 * @dev the device struct object
1606 scsih_get_state(struct device *dev)
1608 struct scsi_device *sdev = to_scsi_device(dev);
1609 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1610 static struct _raid_device *raid_device;
1611 unsigned long flags;
1612 Mpi2RaidVolPage0_t vol_pg0;
1613 Mpi2ConfigReply_t mpi_reply;
1615 enum raid_state state = RAID_STATE_UNKNOWN;
1618 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1619 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1622 handle = raid_device->handle;
1623 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1628 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1629 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1630 sizeof(Mpi2RaidVolPage0_t))) {
1631 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1632 ioc->name, __FILE__, __LINE__, __func__);
1636 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1637 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1638 state = RAID_STATE_RESYNCING;
1642 switch (vol_pg0.VolumeState) {
1643 case MPI2_RAID_VOL_STATE_OPTIMAL:
1644 case MPI2_RAID_VOL_STATE_ONLINE:
1645 state = RAID_STATE_ACTIVE;
1647 case MPI2_RAID_VOL_STATE_DEGRADED:
1648 state = RAID_STATE_DEGRADED;
1650 case MPI2_RAID_VOL_STATE_FAILED:
1651 case MPI2_RAID_VOL_STATE_MISSING:
1652 state = RAID_STATE_OFFLINE;
1656 switch (ioc->hba_mpi_version_belonged) {
1658 raid_set_state(mpt2sas_raid_template, dev, state);
1662 raid_set_state(mpt3sas_raid_template, dev, state);
1668 * _scsih_set_level - set raid level
1669 * @sdev: scsi device struct
1670 * @volume_type: volume type
1673 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1674 struct scsi_device *sdev, u8 volume_type)
1676 enum raid_level level = RAID_LEVEL_UNKNOWN;
1678 switch (volume_type) {
1679 case MPI2_RAID_VOL_TYPE_RAID0:
1680 level = RAID_LEVEL_0;
1682 case MPI2_RAID_VOL_TYPE_RAID10:
1683 level = RAID_LEVEL_10;
1685 case MPI2_RAID_VOL_TYPE_RAID1E:
1686 level = RAID_LEVEL_1E;
1688 case MPI2_RAID_VOL_TYPE_RAID1:
1689 level = RAID_LEVEL_1;
1693 switch (ioc->hba_mpi_version_belonged) {
1695 raid_set_level(mpt2sas_raid_template,
1696 &sdev->sdev_gendev, level);
1700 raid_set_level(mpt3sas_raid_template,
1701 &sdev->sdev_gendev, level);
1708 * _scsih_get_volume_capabilities - volume capabilities
1709 * @ioc: per adapter object
1710 * @sas_device: the raid_device object
1712 * Returns 0 for success, else 1
1715 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1716 struct _raid_device *raid_device)
1718 Mpi2RaidVolPage0_t *vol_pg0;
1719 Mpi2RaidPhysDiskPage0_t pd_pg0;
1720 Mpi2SasDevicePage0_t sas_device_pg0;
1721 Mpi2ConfigReply_t mpi_reply;
1725 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1726 &num_pds)) || !num_pds) {
1727 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1728 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1733 raid_device->num_pds = num_pds;
1734 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1735 sizeof(Mpi2RaidVol0PhysDisk_t));
1736 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1738 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1739 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1744 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1745 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1746 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1747 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1753 raid_device->volume_type = vol_pg0->VolumeType;
1755 /* figure out what the underlying devices are by
1756 * obtaining the device_info bits for the 1st device
1758 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1759 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1760 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1761 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1762 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1763 le16_to_cpu(pd_pg0.DevHandle)))) {
1764 raid_device->device_info =
1765 le32_to_cpu(sas_device_pg0.DeviceInfo);
1774 * _scsih_enable_tlr - setting TLR flags
1775 * @ioc: per adapter object
1776 * @sdev: scsi device struct
1778 * Enabling Transaction Layer Retries for tape devices when
1779 * vpd page 0x90 is present
1783 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1787 if (sdev->type != TYPE_TAPE)
1790 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1793 sas_enable_tlr(sdev);
1794 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1795 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1801 * scsih_slave_configure - device configure routine.
1802 * @sdev: scsi device struct
1804 * Returns 0 if ok. Any other return is assumed to be an error and
1805 * the device is ignored.
1808 scsih_slave_configure(struct scsi_device *sdev)
1810 struct Scsi_Host *shost = sdev->host;
1811 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1812 struct MPT3SAS_DEVICE *sas_device_priv_data;
1813 struct MPT3SAS_TARGET *sas_target_priv_data;
1814 struct _sas_device *sas_device;
1815 struct _raid_device *raid_device;
1816 unsigned long flags;
1821 u16 handle, volume_handle = 0;
1822 u64 volume_wwid = 0;
1825 sas_device_priv_data = sdev->hostdata;
1826 sas_device_priv_data->configured_lun = 1;
1827 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1828 sas_target_priv_data = sas_device_priv_data->sas_target;
1829 handle = sas_target_priv_data->handle;
1831 /* raid volume handling */
1832 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1834 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1835 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1836 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1838 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1839 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1840 __LINE__, __func__));
1844 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1845 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1846 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1847 __LINE__, __func__));
1852 * WARPDRIVE: Initialize the required data for Direct IO
1854 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1856 /* RAID Queue Depth Support
1857 * IS volume = underlying qdepth of drive type, either
1858 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1859 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1861 if (raid_device->device_info &
1862 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1863 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1866 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1867 if (raid_device->device_info &
1868 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1874 switch (raid_device->volume_type) {
1875 case MPI2_RAID_VOL_TYPE_RAID0:
1878 case MPI2_RAID_VOL_TYPE_RAID1E:
1879 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1880 if (ioc->manu_pg10.OEMIdentifier &&
1881 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1882 MFG10_GF0_R10_DISPLAY) &&
1883 !(raid_device->num_pds % 2))
1888 case MPI2_RAID_VOL_TYPE_RAID1:
1889 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1892 case MPI2_RAID_VOL_TYPE_RAID10:
1893 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1896 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1898 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1903 if (!ioc->hide_ir_msg)
1904 sdev_printk(KERN_INFO, sdev,
1905 "%s: handle(0x%04x), wwid(0x%016llx),"
1906 " pd_count(%d), type(%s)\n",
1907 r_level, raid_device->handle,
1908 (unsigned long long)raid_device->wwid,
1909 raid_device->num_pds, ds);
1911 if (shost->max_sectors > MPT3SAS_RAID_MAX_SECTORS) {
1912 blk_queue_max_hw_sectors(sdev->request_queue,
1913 MPT3SAS_RAID_MAX_SECTORS);
1914 sdev_printk(KERN_INFO, sdev,
1915 "Set queue's max_sector to: %u\n",
1916 MPT3SAS_RAID_MAX_SECTORS);
1919 scsih_change_queue_depth(sdev, qdepth);
1921 /* raid transport support */
1922 if (!ioc->is_warpdrive)
1923 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1927 /* non-raid handling */
1928 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1929 if (mpt3sas_config_get_volume_handle(ioc, handle,
1931 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1932 "failure at %s:%d/%s()!\n", ioc->name,
1933 __FILE__, __LINE__, __func__));
1936 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1937 volume_handle, &volume_wwid)) {
1938 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1939 "failure at %s:%d/%s()!\n", ioc->name,
1940 __FILE__, __LINE__, __func__));
1945 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1946 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1947 sas_device_priv_data->sas_target->sas_address);
1949 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1950 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1951 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1956 sas_device->volume_handle = volume_handle;
1957 sas_device->volume_wwid = volume_wwid;
1958 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1959 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1961 if (sas_device->device_info &
1962 MPI2_SAS_DEVICE_INFO_SEP) {
1963 sdev_printk(KERN_WARNING, sdev,
1964 "set ignore_delay_remove for handle(0x%04x)\n",
1965 sas_device_priv_data->sas_target->handle);
1966 sas_device_priv_data->ignore_delay_remove = 1;
1971 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1972 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1974 else if (sas_device->device_info &
1975 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1979 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1980 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1981 ds, handle, (unsigned long long)sas_device->sas_address,
1982 sas_device->phy, (unsigned long long)sas_device->device_name);
1983 if (sas_device->enclosure_handle != 0)
1984 sdev_printk(KERN_INFO, sdev,
1985 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1986 ds, (unsigned long long)
1987 sas_device->enclosure_logical_id, sas_device->slot);
1988 if (sas_device->connector_name[0] != '\0')
1989 sdev_printk(KERN_INFO, sdev,
1990 "%s: enclosure level(0x%04x), connector name( %s)\n",
1991 ds, sas_device->enclosure_level,
1992 sas_device->connector_name);
1994 sas_device_put(sas_device);
1995 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1998 _scsih_display_sata_capabilities(ioc, handle, sdev);
2001 scsih_change_queue_depth(sdev, qdepth);
2004 sas_read_port_mode_page(sdev);
2005 _scsih_enable_tlr(ioc, sdev);
2012 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2013 * @sdev: scsi device struct
2014 * @bdev: pointer to block device context
2015 * @capacity: device size (in 512 byte sectors)
2016 * @params: three element array to place output:
2017 * params[0] number of heads (max 255)
2018 * params[1] number of sectors (max 63)
2019 * params[2] number of cylinders
2024 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2025 sector_t capacity, int params[])
2035 dummy = heads * sectors;
2036 cylinders = capacity;
2037 sector_div(cylinders, dummy);
2040 * Handle extended translation size for logical drives
2043 if ((ulong)capacity >= 0x200000) {
2046 dummy = heads * sectors;
2047 cylinders = capacity;
2048 sector_div(cylinders, dummy);
2053 params[1] = sectors;
2054 params[2] = cylinders;
2060 * _scsih_response_code - translation of device response code
2061 * @ioc: per adapter object
2062 * @response_code: response code returned by the device
2067 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2071 switch (response_code) {
2072 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2073 desc = "task management request completed";
2075 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2076 desc = "invalid frame";
2078 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2079 desc = "task management request not supported";
2081 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2082 desc = "task management request failed";
2084 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2085 desc = "task management request succeeded";
2087 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2088 desc = "invalid lun";
2091 desc = "overlapped tag attempted";
2093 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2094 desc = "task queued, however not sent to target";
2100 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2101 ioc->name, response_code, desc);
2105 * _scsih_tm_done - tm completion routine
2106 * @ioc: per adapter object
2107 * @smid: system request message index
2108 * @msix_index: MSIX table index supplied by the OS
2109 * @reply: reply message frame(lower 32bit addr)
2112 * The callback handler when using scsih_issue_tm.
2114 * Return 1 meaning mf should be freed from _base_interrupt
2115 * 0 means the mf is freed from this function.
2118 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2120 MPI2DefaultReply_t *mpi_reply;
2122 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2124 if (ioc->tm_cmds.smid != smid)
2126 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2127 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2129 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2130 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2132 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2133 complete(&ioc->tm_cmds.done);
2138 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2139 * @ioc: per adapter object
2140 * @handle: device handle
2142 * During taskmangement request, we need to freeze the device queue.
2145 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2147 struct MPT3SAS_DEVICE *sas_device_priv_data;
2148 struct scsi_device *sdev;
2151 shost_for_each_device(sdev, ioc->shost) {
2154 sas_device_priv_data = sdev->hostdata;
2155 if (!sas_device_priv_data)
2157 if (sas_device_priv_data->sas_target->handle == handle) {
2158 sas_device_priv_data->sas_target->tm_busy = 1;
2160 ioc->ignore_loginfos = 1;
2166 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2167 * @ioc: per adapter object
2168 * @handle: device handle
2170 * During taskmangement request, we need to freeze the device queue.
2173 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2175 struct MPT3SAS_DEVICE *sas_device_priv_data;
2176 struct scsi_device *sdev;
2179 shost_for_each_device(sdev, ioc->shost) {
2182 sas_device_priv_data = sdev->hostdata;
2183 if (!sas_device_priv_data)
2185 if (sas_device_priv_data->sas_target->handle == handle) {
2186 sas_device_priv_data->sas_target->tm_busy = 0;
2188 ioc->ignore_loginfos = 0;
2194 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2195 * @ioc: per adapter struct
2196 * @device_handle: device handle
2197 * @channel: the channel assigned by the OS
2198 * @id: the id assigned by the OS
2200 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2201 * @smid_task: smid assigned to the task
2202 * @timeout: timeout in seconds
2205 * A generic API for sending task management requests to firmware.
2207 * The callback index is set inside `ioc->tm_cb_idx`.
2209 * Return SUCCESS or FAILED.
2212 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2213 uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
2215 Mpi2SCSITaskManagementRequest_t *mpi_request;
2216 Mpi2SCSITaskManagementReply_t *mpi_reply;
2219 struct scsiio_tracker *scsi_lookup = NULL;
2223 lockdep_assert_held(&ioc->tm_cmds.mutex);
2225 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2226 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2227 __func__, ioc->name);
2231 if (ioc->shost_recovery || ioc->remove_host ||
2232 ioc->pci_error_recovery) {
2233 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2234 __func__, ioc->name);
2238 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2239 if (ioc_state & MPI2_DOORBELL_USED) {
2240 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2241 "unexpected doorbell active!\n", ioc->name));
2242 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2243 return (!rc) ? SUCCESS : FAILED;
2246 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2247 mpt3sas_base_fault_info(ioc, ioc_state &
2248 MPI2_DOORBELL_DATA_MASK);
2249 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2250 return (!rc) ? SUCCESS : FAILED;
2253 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2255 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2256 ioc->name, __func__);
2260 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2261 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2263 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2264 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2265 ioc->name, handle, type, smid_task));
2266 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2267 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2268 ioc->tm_cmds.smid = smid;
2269 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2270 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2271 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2272 mpi_request->DevHandle = cpu_to_le16(handle);
2273 mpi_request->TaskType = type;
2274 mpi_request->TaskMID = cpu_to_le16(smid_task);
2275 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2276 mpt3sas_scsih_set_tm_flag(ioc, handle);
2277 init_completion(&ioc->tm_cmds.done);
2278 if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
2279 (scsi_lookup->msix_io < ioc->reply_queue_count))
2280 msix_task = scsi_lookup->msix_io;
2283 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2284 wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2285 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2286 pr_err(MPT3SAS_FMT "%s: timeout\n",
2287 ioc->name, __func__);
2288 _debug_dump_mf(mpi_request,
2289 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2290 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2291 rc = mpt3sas_base_hard_reset_handler(ioc,
2293 rc = (!rc) ? SUCCESS : FAILED;
2298 /* sync IRQs in case those were busy during flush. */
2299 mpt3sas_base_sync_reply_irqs(ioc);
2301 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2302 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2303 mpi_reply = ioc->tm_cmds.reply;
2304 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2305 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2306 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2307 le32_to_cpu(mpi_reply->IOCLogInfo),
2308 le32_to_cpu(mpi_reply->TerminationCount)));
2309 if (ioc->logging_level & MPT_DEBUG_TM) {
2310 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2311 if (mpi_reply->IOCStatus)
2312 _debug_dump_mf(mpi_request,
2313 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2318 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2320 if (scsi_lookup->scmd == NULL)
2325 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2326 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2331 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2332 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2333 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2338 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2347 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2348 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2352 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle,
2353 uint channel, uint id, uint lun, u8 type, u16 smid_task, ulong timeout)
2357 mutex_lock(&ioc->tm_cmds.mutex);
2358 ret = mpt3sas_scsih_issue_tm(ioc, handle, channel, id, lun, type,
2359 smid_task, timeout);
2360 mutex_unlock(&ioc->tm_cmds.mutex);
2366 * _scsih_tm_display_info - displays info about the device
2367 * @ioc: per adapter struct
2368 * @scmd: pointer to scsi command object
2370 * Called by task management callback handlers.
2373 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2375 struct scsi_target *starget = scmd->device->sdev_target;
2376 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2377 struct _sas_device *sas_device = NULL;
2378 unsigned long flags;
2379 char *device_str = NULL;
2383 if (ioc->hide_ir_msg)
2384 device_str = "WarpDrive";
2386 device_str = "volume";
2388 scsi_print_command(scmd);
2389 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2390 starget_printk(KERN_INFO, starget,
2391 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2392 device_str, priv_target->handle,
2393 device_str, (unsigned long long)priv_target->sas_address);
2395 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2396 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2398 if (priv_target->flags &
2399 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2400 starget_printk(KERN_INFO, starget,
2401 "volume handle(0x%04x), "
2402 "volume wwid(0x%016llx)\n",
2403 sas_device->volume_handle,
2404 (unsigned long long)sas_device->volume_wwid);
2406 starget_printk(KERN_INFO, starget,
2407 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2409 (unsigned long long)sas_device->sas_address,
2411 if (sas_device->enclosure_handle != 0)
2412 starget_printk(KERN_INFO, starget,
2413 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2414 (unsigned long long)
2415 sas_device->enclosure_logical_id,
2417 if (sas_device->connector_name[0] != '\0')
2418 starget_printk(KERN_INFO, starget,
2419 "enclosure level(0x%04x),connector name(%s)\n",
2420 sas_device->enclosure_level,
2421 sas_device->connector_name);
2423 sas_device_put(sas_device);
2425 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2430 * scsih_abort - eh threads main abort routine
2431 * @scmd: pointer to scsi command object
2433 * Returns SUCCESS if command aborted else FAILED
2436 scsih_abort(struct scsi_cmnd *scmd)
2438 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2439 struct MPT3SAS_DEVICE *sas_device_priv_data;
2444 sdev_printk(KERN_INFO, scmd->device,
2445 "attempting task abort! scmd(%p)\n", scmd);
2446 _scsih_tm_display_info(ioc, scmd);
2448 sas_device_priv_data = scmd->device->hostdata;
2449 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2450 sdev_printk(KERN_INFO, scmd->device,
2451 "device been deleted! scmd(%p)\n", scmd);
2452 scmd->result = DID_NO_CONNECT << 16;
2453 scmd->scsi_done(scmd);
2458 /* search for the command */
2459 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2461 scmd->result = DID_RESET << 16;
2466 /* for hidden raid components and volumes this is not supported */
2467 if (sas_device_priv_data->sas_target->flags &
2468 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2469 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2470 scmd->result = DID_RESET << 16;
2475 mpt3sas_halt_firmware(ioc);
2477 handle = sas_device_priv_data->sas_target->handle;
2478 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2479 scmd->device->id, scmd->device->lun,
2480 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
2483 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2484 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2489 * scsih_dev_reset - eh threads main device reset routine
2490 * @scmd: pointer to scsi command object
2492 * Returns SUCCESS if command aborted else FAILED
2495 scsih_dev_reset(struct scsi_cmnd *scmd)
2497 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2498 struct MPT3SAS_DEVICE *sas_device_priv_data;
2499 struct _sas_device *sas_device = NULL;
2503 struct scsi_target *starget = scmd->device->sdev_target;
2504 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2506 sdev_printk(KERN_INFO, scmd->device,
2507 "attempting device reset! scmd(%p)\n", scmd);
2508 _scsih_tm_display_info(ioc, scmd);
2510 sas_device_priv_data = scmd->device->hostdata;
2511 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2512 sdev_printk(KERN_INFO, scmd->device,
2513 "device been deleted! scmd(%p)\n", scmd);
2514 scmd->result = DID_NO_CONNECT << 16;
2515 scmd->scsi_done(scmd);
2520 /* for hidden raid components obtain the volume_handle */
2522 if (sas_device_priv_data->sas_target->flags &
2523 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2524 sas_device = mpt3sas_get_sdev_from_target(ioc,
2527 handle = sas_device->volume_handle;
2529 handle = sas_device_priv_data->sas_target->handle;
2532 scmd->result = DID_RESET << 16;
2537 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2538 scmd->device->id, scmd->device->lun,
2539 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30);
2542 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2543 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2546 sas_device_put(sas_device);
2552 * scsih_target_reset - eh threads main target reset routine
2553 * @scmd: pointer to scsi command object
2555 * Returns SUCCESS if command aborted else FAILED
2558 scsih_target_reset(struct scsi_cmnd *scmd)
2560 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2561 struct MPT3SAS_DEVICE *sas_device_priv_data;
2562 struct _sas_device *sas_device = NULL;
2565 struct scsi_target *starget = scmd->device->sdev_target;
2566 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2568 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2570 _scsih_tm_display_info(ioc, scmd);
2572 sas_device_priv_data = scmd->device->hostdata;
2573 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2574 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2576 scmd->result = DID_NO_CONNECT << 16;
2577 scmd->scsi_done(scmd);
2582 /* for hidden raid components obtain the volume_handle */
2584 if (sas_device_priv_data->sas_target->flags &
2585 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2586 sas_device = mpt3sas_get_sdev_from_target(ioc,
2589 handle = sas_device->volume_handle;
2591 handle = sas_device_priv_data->sas_target->handle;
2594 scmd->result = DID_RESET << 16;
2599 r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel,
2600 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2604 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2605 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2608 sas_device_put(sas_device);
2615 * scsih_host_reset - eh threads main host reset routine
2616 * @scmd: pointer to scsi command object
2618 * Returns SUCCESS if command aborted else FAILED
2621 scsih_host_reset(struct scsi_cmnd *scmd)
2623 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2626 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2628 scsi_print_command(scmd);
2630 if (ioc->is_driver_loading) {
2631 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2637 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2638 r = (retval < 0) ? FAILED : SUCCESS;
2640 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2641 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2647 * _scsih_fw_event_add - insert and queue up fw_event
2648 * @ioc: per adapter object
2649 * @fw_event: object describing the event
2650 * Context: This function will acquire ioc->fw_event_lock.
2652 * This adds the firmware event object into link list, then queues it up to
2653 * be processed from user context.
2658 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2660 unsigned long flags;
2662 if (ioc->firmware_event_thread == NULL)
2665 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2666 fw_event_work_get(fw_event);
2667 INIT_LIST_HEAD(&fw_event->list);
2668 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2669 INIT_WORK(&fw_event->work, _firmware_event_work);
2670 fw_event_work_get(fw_event);
2671 queue_work(ioc->firmware_event_thread, &fw_event->work);
2672 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2676 * _scsih_fw_event_del_from_list - delete fw_event from the list
2677 * @ioc: per adapter object
2678 * @fw_event: object describing the event
2679 * Context: This function will acquire ioc->fw_event_lock.
2681 * If the fw_event is on the fw_event_list, remove it and do a put.
2686 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2689 unsigned long flags;
2691 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2692 if (!list_empty(&fw_event->list)) {
2693 list_del_init(&fw_event->list);
2694 fw_event_work_put(fw_event);
2696 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2701 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2702 * @ioc: per adapter object
2703 * @event_data: trigger event data
2708 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2709 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2711 struct fw_event_work *fw_event;
2714 if (ioc->is_driver_loading)
2716 sz = sizeof(*event_data);
2717 fw_event = alloc_fw_event_work(sz);
2720 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2721 fw_event->ioc = ioc;
2722 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2723 _scsih_fw_event_add(ioc, fw_event);
2724 fw_event_work_put(fw_event);
2728 * _scsih_error_recovery_delete_devices - remove devices not responding
2729 * @ioc: per adapter object
2734 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2736 struct fw_event_work *fw_event;
2738 if (ioc->is_driver_loading)
2740 fw_event = alloc_fw_event_work(0);
2743 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2744 fw_event->ioc = ioc;
2745 _scsih_fw_event_add(ioc, fw_event);
2746 fw_event_work_put(fw_event);
2750 * mpt3sas_port_enable_complete - port enable completed (fake event)
2751 * @ioc: per adapter object
2756 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2758 struct fw_event_work *fw_event;
2760 fw_event = alloc_fw_event_work(0);
2763 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2764 fw_event->ioc = ioc;
2765 _scsih_fw_event_add(ioc, fw_event);
2766 fw_event_work_put(fw_event);
2769 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2771 unsigned long flags;
2772 struct fw_event_work *fw_event = NULL;
2774 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2775 if (!list_empty(&ioc->fw_event_list)) {
2776 fw_event = list_first_entry(&ioc->fw_event_list,
2777 struct fw_event_work, list);
2778 list_del_init(&fw_event->list);
2780 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2786 * _scsih_fw_event_cleanup_queue - cleanup event queue
2787 * @ioc: per adapter object
2789 * Walk the firmware event queue, either killing timers, or waiting
2790 * for outstanding events to complete
2795 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2797 struct fw_event_work *fw_event;
2799 if (list_empty(&ioc->fw_event_list) ||
2800 !ioc->firmware_event_thread || in_interrupt())
2803 while ((fw_event = dequeue_next_fw_event(ioc))) {
2805 * Wait on the fw_event to complete. If this returns 1, then
2806 * the event was never executed, and we need a put for the
2807 * reference the work had on the fw_event.
2809 * If it did execute, we wait for it to finish, and the put will
2810 * happen from _firmware_event_work()
2812 if (cancel_work_sync(&fw_event->work))
2813 fw_event_work_put(fw_event);
2815 fw_event_work_put(fw_event);
2820 * _scsih_internal_device_block - block the sdev device
2821 * @sdev: per device object
2822 * @sas_device_priv_data : per device driver private data
2824 * make sure device is blocked without error, if not
2828 _scsih_internal_device_block(struct scsi_device *sdev,
2829 struct MPT3SAS_DEVICE *sas_device_priv_data)
2833 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2834 sas_device_priv_data->sas_target->handle);
2835 sas_device_priv_data->block = 1;
2837 r = scsi_internal_device_block(sdev);
2839 sdev_printk(KERN_WARNING, sdev,
2840 "device_block failed with return(%d) for handle(0x%04x)\n",
2841 sas_device_priv_data->sas_target->handle, r);
2845 * _scsih_internal_device_unblock - unblock the sdev device
2846 * @sdev: per device object
2847 * @sas_device_priv_data : per device driver private data
2848 * make sure device is unblocked without error, if not retry
2849 * by blocking and then unblocking
2853 _scsih_internal_device_unblock(struct scsi_device *sdev,
2854 struct MPT3SAS_DEVICE *sas_device_priv_data)
2858 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2859 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2860 sas_device_priv_data->block = 0;
2861 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2863 /* The device has been set to SDEV_RUNNING by SD layer during
2864 * device addition but the request queue is still stopped by
2865 * our earlier block call. We need to perform a block again
2866 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2868 sdev_printk(KERN_WARNING, sdev,
2869 "device_unblock failed with return(%d) for handle(0x%04x) "
2870 "performing a block followed by an unblock\n",
2871 sas_device_priv_data->sas_target->handle, r);
2872 sas_device_priv_data->block = 1;
2873 r = scsi_internal_device_block(sdev);
2875 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2876 "failed with return(%d) for handle(0x%04x)\n",
2877 sas_device_priv_data->sas_target->handle, r);
2879 sas_device_priv_data->block = 0;
2880 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2882 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2883 " failed with return(%d) for handle(0x%04x)\n",
2884 sas_device_priv_data->sas_target->handle, r);
2889 * _scsih_ublock_io_all_device - unblock every device
2890 * @ioc: per adapter object
2892 * change the device state from block to running
2895 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2897 struct MPT3SAS_DEVICE *sas_device_priv_data;
2898 struct scsi_device *sdev;
2900 shost_for_each_device(sdev, ioc->shost) {
2901 sas_device_priv_data = sdev->hostdata;
2902 if (!sas_device_priv_data)
2904 if (!sas_device_priv_data->block)
2907 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2908 "device_running, handle(0x%04x)\n",
2909 sas_device_priv_data->sas_target->handle));
2910 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2916 * _scsih_ublock_io_device - prepare device to be deleted
2917 * @ioc: per adapter object
2918 * @sas_addr: sas address
2920 * unblock then put device in offline state
2923 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2925 struct MPT3SAS_DEVICE *sas_device_priv_data;
2926 struct scsi_device *sdev;
2928 shost_for_each_device(sdev, ioc->shost) {
2929 sas_device_priv_data = sdev->hostdata;
2930 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
2932 if (sas_device_priv_data->sas_target->sas_address
2935 if (sas_device_priv_data->block)
2936 _scsih_internal_device_unblock(sdev,
2937 sas_device_priv_data);
2942 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2943 * @ioc: per adapter object
2944 * @handle: device handle
2946 * During device pull we need to appropiately set the sdev state.
2949 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2951 struct MPT3SAS_DEVICE *sas_device_priv_data;
2952 struct scsi_device *sdev;
2954 shost_for_each_device(sdev, ioc->shost) {
2955 sas_device_priv_data = sdev->hostdata;
2956 if (!sas_device_priv_data)
2958 if (sas_device_priv_data->block)
2960 if (sas_device_priv_data->ignore_delay_remove) {
2961 sdev_printk(KERN_INFO, sdev,
2962 "%s skip device_block for SES handle(0x%04x)\n",
2963 __func__, sas_device_priv_data->sas_target->handle);
2966 _scsih_internal_device_block(sdev, sas_device_priv_data);
2971 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2972 * @ioc: per adapter object
2973 * @handle: device handle
2975 * During device pull we need to appropiately set the sdev state.
2978 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2980 struct MPT3SAS_DEVICE *sas_device_priv_data;
2981 struct scsi_device *sdev;
2982 struct _sas_device *sas_device;
2984 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2988 shost_for_each_device(sdev, ioc->shost) {
2989 sas_device_priv_data = sdev->hostdata;
2990 if (!sas_device_priv_data)
2992 if (sas_device_priv_data->sas_target->handle != handle)
2994 if (sas_device_priv_data->block)
2996 if (sas_device->pend_sas_rphy_add)
2998 if (sas_device_priv_data->ignore_delay_remove) {
2999 sdev_printk(KERN_INFO, sdev,
3000 "%s skip device_block for SES handle(0x%04x)\n",
3001 __func__, sas_device_priv_data->sas_target->handle);
3004 _scsih_internal_device_block(sdev, sas_device_priv_data);
3007 sas_device_put(sas_device);
3011 * _scsih_block_io_to_children_attached_to_ex
3012 * @ioc: per adapter object
3013 * @sas_expander: the sas_device object
3015 * This routine set sdev state to SDEV_BLOCK for all devices
3016 * attached to this expander. This function called when expander is
3020 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3021 struct _sas_node *sas_expander)
3023 struct _sas_port *mpt3sas_port;
3024 struct _sas_device *sas_device;
3025 struct _sas_node *expander_sibling;
3026 unsigned long flags;
3031 list_for_each_entry(mpt3sas_port,
3032 &sas_expander->sas_port_list, port_list) {
3033 if (mpt3sas_port->remote_identify.device_type ==
3035 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3036 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3037 mpt3sas_port->remote_identify.sas_address);
3039 set_bit(sas_device->handle,
3040 ioc->blocking_handles);
3041 sas_device_put(sas_device);
3043 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3047 list_for_each_entry(mpt3sas_port,
3048 &sas_expander->sas_port_list, port_list) {
3050 if (mpt3sas_port->remote_identify.device_type ==
3051 SAS_EDGE_EXPANDER_DEVICE ||
3052 mpt3sas_port->remote_identify.device_type ==
3053 SAS_FANOUT_EXPANDER_DEVICE) {
3055 mpt3sas_scsih_expander_find_by_sas_address(
3056 ioc, mpt3sas_port->remote_identify.sas_address);
3057 _scsih_block_io_to_children_attached_to_ex(ioc,
3064 * _scsih_block_io_to_children_attached_directly
3065 * @ioc: per adapter object
3066 * @event_data: topology change event data
3068 * This routine set sdev state to SDEV_BLOCK for all devices
3069 * direct attached during device pull.
3072 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3073 Mpi2EventDataSasTopologyChangeList_t *event_data)
3079 for (i = 0; i < event_data->NumEntries; i++) {
3080 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3083 reason_code = event_data->PHY[i].PhyStatus &
3084 MPI2_EVENT_SAS_TOPO_RC_MASK;
3085 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3086 _scsih_block_io_device(ioc, handle);
3091 * _scsih_tm_tr_send - send task management request
3092 * @ioc: per adapter object
3093 * @handle: device handle
3094 * Context: interrupt time.
3096 * This code is to initiate the device removal handshake protocol
3097 * with controller firmware. This function will issue target reset
3098 * using high priority request queue. It will send a sas iounit
3099 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3101 * This is designed to send muliple task management request at the same
3102 * time to the fifo. If the fifo is full, we will append the request,
3103 * and process it in a future completion.
3106 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3108 Mpi2SCSITaskManagementRequest_t *mpi_request;
3110 struct _sas_device *sas_device = NULL;
3111 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3112 u64 sas_address = 0;
3113 unsigned long flags;
3114 struct _tr_list *delayed_tr;
3117 if (ioc->remove_host) {
3118 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3119 "%s: host has been removed: handle(0x%04x)\n",
3120 __func__, ioc->name, handle));
3122 } else if (ioc->pci_error_recovery) {
3123 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3124 "%s: host in pci error recovery: handle(0x%04x)\n",
3125 __func__, ioc->name,
3129 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3130 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3131 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3132 "%s: host is not operational: handle(0x%04x)\n",
3133 __func__, ioc->name,
3138 /* if PD, then return */
3139 if (test_bit(handle, ioc->pd_handles))
3142 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3143 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3144 if (sas_device && sas_device->starget &&
3145 sas_device->starget->hostdata) {
3146 sas_target_priv_data = sas_device->starget->hostdata;
3147 sas_target_priv_data->deleted = 1;
3148 sas_address = sas_device->sas_address;
3150 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3152 if (sas_target_priv_data) {
3153 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3154 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3156 (unsigned long long)sas_address));
3157 if (sas_device->enclosure_handle != 0)
3158 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3159 "setting delete flag:enclosure logical id(0x%016llx),"
3160 " slot(%d)\n", ioc->name, (unsigned long long)
3161 sas_device->enclosure_logical_id,
3163 if (sas_device->connector_name[0] != '\0')
3164 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3165 "setting delete flag: enclosure level(0x%04x),"
3166 " connector name( %s)\n", ioc->name,
3167 sas_device->enclosure_level,
3168 sas_device->connector_name));
3169 _scsih_ublock_io_device(ioc, sas_address);
3170 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3173 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3175 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3178 INIT_LIST_HEAD(&delayed_tr->list);
3179 delayed_tr->handle = handle;
3180 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3181 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3182 "DELAYED:tr:handle(0x%04x), (open)\n",
3183 ioc->name, handle));
3187 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3188 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3189 ioc->name, handle, smid,
3190 ioc->tm_tr_cb_idx));
3191 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3192 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3193 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3194 mpi_request->DevHandle = cpu_to_le16(handle);
3195 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3196 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3197 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3201 sas_device_put(sas_device);
3205 * _scsih_tm_tr_complete -
3206 * @ioc: per adapter object
3207 * @smid: system request message index
3208 * @msix_index: MSIX table index supplied by the OS
3209 * @reply: reply message frame(lower 32bit addr)
3210 * Context: interrupt time.
3212 * This is the target reset completion routine.
3213 * This code is part of the code to initiate the device removal
3214 * handshake protocol with controller firmware.
3215 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3217 * Return 1 meaning mf should be freed from _base_interrupt
3218 * 0 means the mf is freed from this function.
3221 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3225 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3226 Mpi2SCSITaskManagementReply_t *mpi_reply =
3227 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3228 Mpi2SasIoUnitControlRequest_t *mpi_request;
3231 struct _sc_list *delayed_sc;
3233 if (ioc->remove_host) {
3234 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3235 "%s: host has been removed\n", __func__, ioc->name));
3237 } else if (ioc->pci_error_recovery) {
3238 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3239 "%s: host in pci error recovery\n", __func__,
3243 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3244 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3245 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3246 "%s: host is not operational\n", __func__, ioc->name));
3249 if (unlikely(!mpi_reply)) {
3250 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3251 ioc->name, __FILE__, __LINE__, __func__);
3254 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3255 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3256 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3257 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3258 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3260 le16_to_cpu(mpi_reply->DevHandle), smid));
3264 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3265 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3266 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3267 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3268 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3269 le32_to_cpu(mpi_reply->IOCLogInfo),
3270 le32_to_cpu(mpi_reply->TerminationCount)));
3272 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3273 if (!smid_sas_ctrl) {
3274 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3276 return _scsih_check_for_pending_tm(ioc, smid);
3277 INIT_LIST_HEAD(&delayed_sc->list);
3278 delayed_sc->handle = mpi_request_tm->DevHandle;
3279 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3280 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3281 "DELAYED:sc:handle(0x%04x), (open)\n",
3282 ioc->name, handle));
3283 return _scsih_check_for_pending_tm(ioc, smid);
3286 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3287 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3288 ioc->name, handle, smid_sas_ctrl,
3289 ioc->tm_sas_control_cb_idx));
3290 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3291 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3292 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3293 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3294 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3295 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3297 return _scsih_check_for_pending_tm(ioc, smid);
3300 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3301 * issue to IOC or not.
3302 * @ioc: per adapter object
3303 * @scmd: pointer to scsi command object
3305 * Returns true if scmd can be issued to IOC otherwise returns false.
3307 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc,
3308 struct scsi_cmnd *scmd)
3311 if (ioc->pci_error_recovery)
3314 if (ioc->hba_mpi_version_belonged == MPI2_VERSION) {
3315 if (ioc->remove_host)
3321 if (ioc->remove_host) {
3323 switch (scmd->cmnd[0]) {
3324 case SYNCHRONIZE_CACHE:
3336 * _scsih_sas_control_complete - completion routine
3337 * @ioc: per adapter object
3338 * @smid: system request message index
3339 * @msix_index: MSIX table index supplied by the OS
3340 * @reply: reply message frame(lower 32bit addr)
3341 * Context: interrupt time.
3343 * This is the sas iounit control completion routine.
3344 * This code is part of the code to initiate the device removal
3345 * handshake protocol with controller firmware.
3347 * Return 1 meaning mf should be freed from _base_interrupt
3348 * 0 means the mf is freed from this function.
3351 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3352 u8 msix_index, u32 reply)
3354 Mpi2SasIoUnitControlReply_t *mpi_reply =
3355 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3357 if (likely(mpi_reply)) {
3358 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3359 "sc_complete:handle(0x%04x), (open) "
3360 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3361 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3362 le16_to_cpu(mpi_reply->IOCStatus),
3363 le32_to_cpu(mpi_reply->IOCLogInfo)));
3365 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3366 ioc->name, __FILE__, __LINE__, __func__);
3368 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3372 * _scsih_tm_tr_volume_send - send target reset request for volumes
3373 * @ioc: per adapter object
3374 * @handle: device handle
3375 * Context: interrupt time.
3377 * This is designed to send muliple task management request at the same
3378 * time to the fifo. If the fifo is full, we will append the request,
3379 * and process it in a future completion.
3382 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3384 Mpi2SCSITaskManagementRequest_t *mpi_request;
3386 struct _tr_list *delayed_tr;
3388 if (ioc->shost_recovery || ioc->remove_host ||
3389 ioc->pci_error_recovery) {
3390 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3391 "%s: host reset in progress!\n",
3392 __func__, ioc->name));
3396 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3398 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3401 INIT_LIST_HEAD(&delayed_tr->list);
3402 delayed_tr->handle = handle;
3403 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3404 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3405 "DELAYED:tr:handle(0x%04x), (open)\n",
3406 ioc->name, handle));
3410 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3411 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3412 ioc->name, handle, smid,
3413 ioc->tm_tr_volume_cb_idx));
3414 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3415 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3416 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3417 mpi_request->DevHandle = cpu_to_le16(handle);
3418 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3419 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3423 * _scsih_tm_volume_tr_complete - target reset completion
3424 * @ioc: per adapter object
3425 * @smid: system request message index
3426 * @msix_index: MSIX table index supplied by the OS
3427 * @reply: reply message frame(lower 32bit addr)
3428 * Context: interrupt time.
3430 * Return 1 meaning mf should be freed from _base_interrupt
3431 * 0 means the mf is freed from this function.
3434 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3435 u8 msix_index, u32 reply)
3438 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3439 Mpi2SCSITaskManagementReply_t *mpi_reply =
3440 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3442 if (ioc->shost_recovery || ioc->remove_host ||
3443 ioc->pci_error_recovery) {
3444 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3445 "%s: host reset in progress!\n",
3446 __func__, ioc->name));
3449 if (unlikely(!mpi_reply)) {
3450 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3451 ioc->name, __FILE__, __LINE__, __func__);
3455 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3456 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3457 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3458 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3459 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3461 le16_to_cpu(mpi_reply->DevHandle), smid));
3465 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3466 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3467 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3468 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3469 le32_to_cpu(mpi_reply->IOCLogInfo),
3470 le32_to_cpu(mpi_reply->TerminationCount)));
3472 return _scsih_check_for_pending_tm(ioc, smid);
3476 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3477 * @ioc: per adapter object
3478 * @smid: system request message index
3480 * @event_context: used to track events uniquely
3482 * Context - processed in interrupt context.
3485 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event,
3488 Mpi2EventAckRequest_t *ack_request;
3489 int i = smid - ioc->internal_smid;
3490 unsigned long flags;
3492 /* Without releasing the smid just update the
3493 * call back index and reuse the same smid for
3494 * processing this delayed request
3496 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3497 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3498 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3500 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3501 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3502 ioc->name, le16_to_cpu(event), smid,
3504 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
3505 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
3506 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
3507 ack_request->Event = event;
3508 ack_request->EventContext = event_context;
3509 ack_request->VF_ID = 0; /* TODO */
3510 ack_request->VP_ID = 0;
3511 mpt3sas_base_put_smid_default(ioc, smid);
3515 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3516 * sas_io_unit_ctrl messages
3517 * @ioc: per adapter object
3518 * @smid: system request message index
3519 * @handle: device handle
3521 * Context - processed in interrupt context.
3524 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
3525 u16 smid, u16 handle)
3527 Mpi2SasIoUnitControlRequest_t *mpi_request;
3529 int i = smid - ioc->internal_smid;
3530 unsigned long flags;
3532 if (ioc->remove_host) {
3533 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3534 "%s: host has been removed\n",
3535 __func__, ioc->name));
3537 } else if (ioc->pci_error_recovery) {
3538 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3539 "%s: host in pci error recovery\n",
3540 __func__, ioc->name));
3543 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3544 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3545 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3546 "%s: host is not operational\n",
3547 __func__, ioc->name));
3551 /* Without releasing the smid just update the
3552 * call back index and reuse the same smid for
3553 * processing this delayed request
3555 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3556 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
3557 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3559 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3560 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3561 ioc->name, le16_to_cpu(handle), smid,
3562 ioc->tm_sas_control_cb_idx));
3563 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3564 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3565 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3566 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3567 mpi_request->DevHandle = handle;
3568 mpt3sas_base_put_smid_default(ioc, smid);
3572 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3573 * @ioc: per adapter object
3574 * @smid: system request message index
3576 * Context: Executed in interrupt context
3578 * This will check delayed internal messages list, and process the
3581 * Return 1 meaning mf should be freed from _base_interrupt
3582 * 0 means the mf is freed from this function.
3585 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3587 struct _sc_list *delayed_sc;
3588 struct _event_ack_list *delayed_event_ack;
3590 if (!list_empty(&ioc->delayed_event_ack_list)) {
3591 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
3592 struct _event_ack_list, list);
3593 _scsih_issue_delayed_event_ack(ioc, smid,
3594 delayed_event_ack->Event, delayed_event_ack->EventContext);
3595 list_del(&delayed_event_ack->list);
3596 kfree(delayed_event_ack);
3600 if (!list_empty(&ioc->delayed_sc_list)) {
3601 delayed_sc = list_entry(ioc->delayed_sc_list.next,
3602 struct _sc_list, list);
3603 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
3604 delayed_sc->handle);
3605 list_del(&delayed_sc->list);
3613 * _scsih_check_for_pending_tm - check for pending task management
3614 * @ioc: per adapter object
3615 * @smid: system request message index
3617 * This will check delayed target reset list, and feed the
3620 * Return 1 meaning mf should be freed from _base_interrupt
3621 * 0 means the mf is freed from this function.
3624 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3626 struct _tr_list *delayed_tr;
3628 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3629 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3630 struct _tr_list, list);
3631 mpt3sas_base_free_smid(ioc, smid);
3632 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3633 list_del(&delayed_tr->list);
3638 if (!list_empty(&ioc->delayed_tr_list)) {
3639 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3640 struct _tr_list, list);
3641 mpt3sas_base_free_smid(ioc, smid);
3642 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3643 list_del(&delayed_tr->list);
3652 * _scsih_check_topo_delete_events - sanity check on topo events
3653 * @ioc: per adapter object
3654 * @event_data: the event data payload
3656 * This routine added to better handle cable breaker.
3658 * This handles the case where driver receives multiple expander
3659 * add and delete events in a single shot. When there is a delete event
3660 * the routine will void any pending add events waiting in the event queue.
3665 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3666 Mpi2EventDataSasTopologyChangeList_t *event_data)
3668 struct fw_event_work *fw_event;
3669 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3670 u16 expander_handle;
3671 struct _sas_node *sas_expander;
3672 unsigned long flags;
3676 for (i = 0 ; i < event_data->NumEntries; i++) {
3677 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3680 reason_code = event_data->PHY[i].PhyStatus &
3681 MPI2_EVENT_SAS_TOPO_RC_MASK;
3682 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3683 _scsih_tm_tr_send(ioc, handle);
3686 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3687 if (expander_handle < ioc->sas_hba.num_phys) {
3688 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3691 if (event_data->ExpStatus ==
3692 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3693 /* put expander attached devices into blocking state */
3694 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3695 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3697 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3698 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3700 handle = find_first_bit(ioc->blocking_handles,
3701 ioc->facts.MaxDevHandle);
3702 if (handle < ioc->facts.MaxDevHandle)
3703 _scsih_block_io_device(ioc, handle);
3704 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3705 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3706 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3708 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3711 /* mark ignore flag for pending events */
3712 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3713 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3714 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3717 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3718 fw_event->event_data;
3719 if (local_event_data->ExpStatus ==
3720 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3721 local_event_data->ExpStatus ==
3722 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3723 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3725 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3726 "setting ignoring flag\n", ioc->name));
3727 fw_event->ignore = 1;
3731 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3735 * _scsih_set_volume_delete_flag - setting volume delete flag
3736 * @ioc: per adapter object
3737 * @handle: device handle
3739 * This returns nothing.
3742 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3744 struct _raid_device *raid_device;
3745 struct MPT3SAS_TARGET *sas_target_priv_data;
3746 unsigned long flags;
3748 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3749 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3750 if (raid_device && raid_device->starget &&
3751 raid_device->starget->hostdata) {
3752 sas_target_priv_data =
3753 raid_device->starget->hostdata;
3754 sas_target_priv_data->deleted = 1;
3755 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3756 "setting delete flag: handle(0x%04x), "
3757 "wwid(0x%016llx)\n", ioc->name, handle,
3758 (unsigned long long) raid_device->wwid));
3760 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3764 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3765 * @handle: input handle
3766 * @a: handle for volume a
3767 * @b: handle for volume b
3769 * IR firmware only supports two raid volumes. The purpose of this
3770 * routine is to set the volume handle in either a or b. When the given
3771 * input handle is non-zero, or when a and b have not been set before.
3774 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3776 if (!handle || handle == *a || handle == *b)
3785 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3786 * @ioc: per adapter object
3787 * @event_data: the event data payload
3788 * Context: interrupt time.
3790 * This routine will send target reset to volume, followed by target
3791 * resets to the PDs. This is called when a PD has been removed, or
3792 * volume has been deleted or removed. When the target reset is sent
3793 * to volume, the PD target resets need to be queued to start upon
3794 * completion of the volume target reset.
3799 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3800 Mpi2EventDataIrConfigChangeList_t *event_data)
3802 Mpi2EventIrConfigElement_t *element;
3804 u16 handle, volume_handle, a, b;
3805 struct _tr_list *delayed_tr;
3810 if (ioc->is_warpdrive)
3813 /* Volume Resets for Deleted or Removed */
3814 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3815 for (i = 0; i < event_data->NumElements; i++, element++) {
3816 if (le32_to_cpu(event_data->Flags) &
3817 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3819 if (element->ReasonCode ==
3820 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3821 element->ReasonCode ==
3822 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3823 volume_handle = le16_to_cpu(element->VolDevHandle);
3824 _scsih_set_volume_delete_flag(ioc, volume_handle);
3825 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3829 /* Volume Resets for UNHIDE events */
3830 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3831 for (i = 0; i < event_data->NumElements; i++, element++) {
3832 if (le32_to_cpu(event_data->Flags) &
3833 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3835 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3836 volume_handle = le16_to_cpu(element->VolDevHandle);
3837 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3842 _scsih_tm_tr_volume_send(ioc, a);
3844 _scsih_tm_tr_volume_send(ioc, b);
3846 /* PD target resets */
3847 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3848 for (i = 0; i < event_data->NumElements; i++, element++) {
3849 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3851 handle = le16_to_cpu(element->PhysDiskDevHandle);
3852 volume_handle = le16_to_cpu(element->VolDevHandle);
3853 clear_bit(handle, ioc->pd_handles);
3855 _scsih_tm_tr_send(ioc, handle);
3856 else if (volume_handle == a || volume_handle == b) {
3857 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3858 BUG_ON(!delayed_tr);
3859 INIT_LIST_HEAD(&delayed_tr->list);
3860 delayed_tr->handle = handle;
3861 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3862 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3863 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3866 _scsih_tm_tr_send(ioc, handle);
3872 * _scsih_check_volume_delete_events - set delete flag for volumes
3873 * @ioc: per adapter object
3874 * @event_data: the event data payload
3875 * Context: interrupt time.
3877 * This will handle the case when the cable connected to entire volume is
3878 * pulled. We will take care of setting the deleted flag so normal IO will
3884 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3885 Mpi2EventDataIrVolume_t *event_data)
3889 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3891 state = le32_to_cpu(event_data->NewValue);
3892 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3893 MPI2_RAID_VOL_STATE_FAILED)
3894 _scsih_set_volume_delete_flag(ioc,
3895 le16_to_cpu(event_data->VolDevHandle));
3899 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3900 * @ioc: per adapter object
3901 * @event_data: the temp threshold event data
3902 * Context: interrupt time.
3907 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3908 Mpi2EventDataTemperature_t *event_data)
3910 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3911 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3912 " exceeded for Sensor: %d !!!\n", ioc->name,
3913 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3914 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3915 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3916 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3917 event_data->SensorNum);
3918 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3919 ioc->name, event_data->CurrentTemperature);
3923 static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
3925 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
3927 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
3931 return test_and_set_bit(0, &priv->ata_command_pending);
3933 clear_bit(0, &priv->ata_command_pending);
3938 * _scsih_flush_running_cmds - completing outstanding commands.
3939 * @ioc: per adapter object
3941 * The flushing out of all pending scmd commands following host reset,
3942 * where all IO is dropped to the floor.
3947 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3949 struct scsi_cmnd *scmd;
3953 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3954 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3958 _scsih_set_satl_pending(scmd, false);
3959 mpt3sas_base_free_smid(ioc, smid);
3960 scsi_dma_unmap(scmd);
3961 if (ioc->pci_error_recovery)
3962 scmd->result = DID_NO_CONNECT << 16;
3964 scmd->result = DID_RESET << 16;
3965 scmd->scsi_done(scmd);
3967 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3972 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3973 * @ioc: per adapter object
3974 * @scmd: pointer to scsi command object
3975 * @mpi_request: pointer to the SCSI_IO reqest message frame
3977 * Supporting protection 1 and 3.
3982 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3983 Mpi2SCSIIORequest_t *mpi_request)
3986 unsigned char prot_op = scsi_get_prot_op(scmd);
3987 unsigned char prot_type = scsi_get_prot_type(scmd);
3988 Mpi25SCSIIORequest_t *mpi_request_3v =
3989 (Mpi25SCSIIORequest_t *)mpi_request;
3991 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3994 if (prot_op == SCSI_PROT_READ_STRIP)
3995 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3996 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3997 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
4001 switch (prot_type) {
4002 case SCSI_PROT_DIF_TYPE1:
4003 case SCSI_PROT_DIF_TYPE2:
4006 * enable ref/guard checking
4007 * auto increment ref tag
4009 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
4010 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
4011 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4012 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
4013 cpu_to_be32(scsi_prot_ref_tag(scmd));
4016 case SCSI_PROT_DIF_TYPE3:
4019 * enable guard checking
4021 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
4026 mpi_request_3v->EEDPBlockSize =
4027 cpu_to_le16(scmd->device->sector_size);
4028 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
4032 * _scsih_eedp_error_handling - return sense code for EEDP errors
4033 * @scmd: pointer to scsi command object
4034 * @ioc_status: ioc status
4039 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4043 switch (ioc_status) {
4044 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4047 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4050 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4057 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4059 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4060 SAM_STAT_CHECK_CONDITION;
4064 * scsih_qcmd - main scsi request entry point
4065 * @scmd: pointer to scsi command object
4066 * @done: function pointer to be invoked on completion
4068 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4070 * Returns 0 on success. If there's a failure, return either:
4071 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4072 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4075 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4077 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4078 struct MPT3SAS_DEVICE *sas_device_priv_data;
4079 struct MPT3SAS_TARGET *sas_target_priv_data;
4080 struct _raid_device *raid_device;
4081 Mpi2SCSIIORequest_t *mpi_request;
4086 if (ioc->logging_level & MPT_DEBUG_SCSI)
4087 scsi_print_command(scmd);
4089 sas_device_priv_data = scmd->device->hostdata;
4090 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4091 scmd->result = DID_NO_CONNECT << 16;
4092 scmd->scsi_done(scmd);
4096 if (!(_scsih_allow_scmd_to_device(ioc, scmd))) {
4097 scmd->result = DID_NO_CONNECT << 16;
4098 scmd->scsi_done(scmd);
4102 sas_target_priv_data = sas_device_priv_data->sas_target;
4104 /* invalid device handle */
4105 handle = sas_target_priv_data->handle;
4106 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4107 scmd->result = DID_NO_CONNECT << 16;
4108 scmd->scsi_done(scmd);
4113 /* host recovery or link resets sent via IOCTLs */
4114 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4115 return SCSI_MLQUEUE_HOST_BUSY;
4117 /* device has been deleted */
4118 else if (sas_target_priv_data->deleted) {
4119 scmd->result = DID_NO_CONNECT << 16;
4120 scmd->scsi_done(scmd);
4122 /* device busy with task managment */
4123 } else if (sas_target_priv_data->tm_busy ||
4124 sas_device_priv_data->block)
4125 return SCSI_MLQUEUE_DEVICE_BUSY;
4128 * Bug work around for firmware SATL handling. The loop
4129 * is based on atomic operations and ensures consistency
4130 * since we're lockless at this point
4133 if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
4134 scmd->result = SAM_STAT_BUSY;
4135 scmd->scsi_done(scmd);
4138 } while (_scsih_set_satl_pending(scmd, true));
4140 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4141 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4142 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4143 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4145 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4148 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4150 /* Make sure Device is not raid volume.
4151 * We do not expose raid functionality to upper layer for warpdrive.
4153 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
4154 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4155 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4157 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4159 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
4160 ioc->name, __func__);
4161 _scsih_set_satl_pending(scmd, false);
4164 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4165 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4166 _scsih_setup_eedp(ioc, scmd, mpi_request);
4168 if (scmd->cmd_len == 32)
4169 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4170 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4171 if (sas_device_priv_data->sas_target->flags &
4172 MPT_TARGET_FLAGS_RAID_COMPONENT)
4173 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4175 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4176 mpi_request->DevHandle = cpu_to_le16(handle);
4177 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4178 mpi_request->Control = cpu_to_le32(mpi_control);
4179 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4180 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4181 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4182 mpi_request->SenseBufferLowAddress =
4183 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4184 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4185 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4187 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4189 if (mpi_request->DataLength) {
4190 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
4191 mpt3sas_base_free_smid(ioc, smid);
4192 _scsih_set_satl_pending(scmd, false);
4196 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4198 raid_device = sas_target_priv_data->raid_device;
4199 if (raid_device && raid_device->direct_io_enabled)
4200 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4203 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4204 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4205 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4206 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4207 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
4209 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4210 le16_to_cpu(mpi_request->DevHandle));
4212 mpt3sas_base_put_smid_default(ioc, smid);
4216 return SCSI_MLQUEUE_HOST_BUSY;
4220 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4221 * @sense_buffer: sense data returned by target
4222 * @data: normalized skey/asc/ascq
4227 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4229 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4230 /* descriptor format */
4231 data->skey = sense_buffer[1] & 0x0F;
4232 data->asc = sense_buffer[2];
4233 data->ascq = sense_buffer[3];
4236 data->skey = sense_buffer[2] & 0x0F;
4237 data->asc = sense_buffer[12];
4238 data->ascq = sense_buffer[13];
4243 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4244 * @ioc: per adapter object
4245 * @scmd: pointer to scsi command object
4246 * @mpi_reply: reply mf payload returned from firmware
4248 * scsi_status - SCSI Status code returned from target device
4249 * scsi_state - state info associated with SCSI_IO determined by ioc
4250 * ioc_status - ioc supplied status info
4255 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4256 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4260 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4261 MPI2_IOCSTATUS_MASK;
4262 u8 scsi_state = mpi_reply->SCSIState;
4263 u8 scsi_status = mpi_reply->SCSIStatus;
4264 char *desc_ioc_state = NULL;
4265 char *desc_scsi_status = NULL;
4266 char *desc_scsi_state = ioc->tmp_string;
4267 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4268 struct _sas_device *sas_device = NULL;
4269 struct scsi_target *starget = scmd->device->sdev_target;
4270 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4271 char *device_str = NULL;
4275 if (ioc->hide_ir_msg)
4276 device_str = "WarpDrive";
4278 device_str = "volume";
4280 if (log_info == 0x31170000)
4283 switch (ioc_status) {
4284 case MPI2_IOCSTATUS_SUCCESS:
4285 desc_ioc_state = "success";
4287 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4288 desc_ioc_state = "invalid function";
4290 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4291 desc_ioc_state = "scsi recovered error";
4293 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4294 desc_ioc_state = "scsi invalid dev handle";
4296 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4297 desc_ioc_state = "scsi device not there";
4299 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4300 desc_ioc_state = "scsi data overrun";
4302 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4303 desc_ioc_state = "scsi data underrun";
4305 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4306 desc_ioc_state = "scsi io data error";
4308 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4309 desc_ioc_state = "scsi protocol error";
4311 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4312 desc_ioc_state = "scsi task terminated";
4314 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4315 desc_ioc_state = "scsi residual mismatch";
4317 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4318 desc_ioc_state = "scsi task mgmt failed";
4320 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4321 desc_ioc_state = "scsi ioc terminated";
4323 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4324 desc_ioc_state = "scsi ext terminated";
4326 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4327 desc_ioc_state = "eedp guard error";
4329 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4330 desc_ioc_state = "eedp ref tag error";
4332 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4333 desc_ioc_state = "eedp app tag error";
4335 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4336 desc_ioc_state = "insufficient power";
4339 desc_ioc_state = "unknown";
4343 switch (scsi_status) {
4344 case MPI2_SCSI_STATUS_GOOD:
4345 desc_scsi_status = "good";
4347 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4348 desc_scsi_status = "check condition";
4350 case MPI2_SCSI_STATUS_CONDITION_MET:
4351 desc_scsi_status = "condition met";
4353 case MPI2_SCSI_STATUS_BUSY:
4354 desc_scsi_status = "busy";
4356 case MPI2_SCSI_STATUS_INTERMEDIATE:
4357 desc_scsi_status = "intermediate";
4359 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4360 desc_scsi_status = "intermediate condmet";
4362 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4363 desc_scsi_status = "reservation conflict";
4365 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4366 desc_scsi_status = "command terminated";
4368 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4369 desc_scsi_status = "task set full";
4371 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4372 desc_scsi_status = "aca active";
4374 case MPI2_SCSI_STATUS_TASK_ABORTED:
4375 desc_scsi_status = "task aborted";
4378 desc_scsi_status = "unknown";
4382 desc_scsi_state[0] = '\0';
4384 desc_scsi_state = " ";
4385 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4386 strcat(desc_scsi_state, "response info ");
4387 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4388 strcat(desc_scsi_state, "state terminated ");
4389 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4390 strcat(desc_scsi_state, "no status ");
4391 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4392 strcat(desc_scsi_state, "autosense failed ");
4393 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4394 strcat(desc_scsi_state, "autosense valid ");
4396 scsi_print_command(scmd);
4398 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4399 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4400 device_str, (unsigned long long)priv_target->sas_address);
4402 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4405 "\tsas_address(0x%016llx), phy(%d)\n",
4406 ioc->name, (unsigned long long)
4407 sas_device->sas_address, sas_device->phy);
4408 if (sas_device->enclosure_handle != 0)
4410 "\tenclosure_logical_id(0x%016llx),"
4411 "slot(%d)\n", ioc->name,
4412 (unsigned long long)
4413 sas_device->enclosure_logical_id,
4415 if (sas_device->connector_name[0])
4417 "\tenclosure level(0x%04x),"
4418 " connector name( %s)\n", ioc->name,
4419 sas_device->enclosure_level,
4420 sas_device->connector_name);
4422 sas_device_put(sas_device);
4427 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4428 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4429 desc_ioc_state, ioc_status, smid);
4431 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4432 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4433 scsi_get_resid(scmd));
4435 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4436 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4437 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4439 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4440 ioc->name, desc_scsi_status,
4441 scsi_status, desc_scsi_state, scsi_state);
4443 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4444 struct sense_info data;
4445 _scsih_normalize_sense(scmd->sense_buffer, &data);
4447 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4448 ioc->name, data.skey,
4449 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4452 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4453 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4454 response_bytes = (u8 *)&response_info;
4455 _scsih_response_code(ioc, response_bytes[0]);
4460 * _scsih_turn_on_pfa_led - illuminate PFA LED
4461 * @ioc: per adapter object
4462 * @handle: device handle
4468 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4470 Mpi2SepReply_t mpi_reply;
4471 Mpi2SepRequest_t mpi_request;
4472 struct _sas_device *sas_device;
4474 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4478 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4479 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4480 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4481 mpi_request.SlotStatus =
4482 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4483 mpi_request.DevHandle = cpu_to_le16(handle);
4484 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4485 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4486 &mpi_request)) != 0) {
4487 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4488 __FILE__, __LINE__, __func__);
4491 sas_device->pfa_led_on = 1;
4493 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4494 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4495 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4496 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4497 le32_to_cpu(mpi_reply.IOCLogInfo)));
4501 sas_device_put(sas_device);
4505 * _scsih_turn_off_pfa_led - turn off Fault LED
4506 * @ioc: per adapter object
4507 * @sas_device: sas device whose PFA LED has to turned off
4513 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4514 struct _sas_device *sas_device)
4516 Mpi2SepReply_t mpi_reply;
4517 Mpi2SepRequest_t mpi_request;
4519 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4520 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4521 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4522 mpi_request.SlotStatus = 0;
4523 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4524 mpi_request.DevHandle = 0;
4525 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4526 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4527 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4528 &mpi_request)) != 0) {
4529 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4530 __FILE__, __LINE__, __func__);
4534 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4535 dewtprintk(ioc, printk(MPT3SAS_FMT
4536 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4537 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4538 le32_to_cpu(mpi_reply.IOCLogInfo)));
4544 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4545 * @ioc: per adapter object
4546 * @handle: device handle
4547 * Context: interrupt.
4552 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4554 struct fw_event_work *fw_event;
4556 fw_event = alloc_fw_event_work(0);
4559 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4560 fw_event->device_handle = handle;
4561 fw_event->ioc = ioc;
4562 _scsih_fw_event_add(ioc, fw_event);
4563 fw_event_work_put(fw_event);
4567 * _scsih_smart_predicted_fault - process smart errors
4568 * @ioc: per adapter object
4569 * @handle: device handle
4570 * Context: interrupt.
4575 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4577 struct scsi_target *starget;
4578 struct MPT3SAS_TARGET *sas_target_priv_data;
4579 Mpi2EventNotificationReply_t *event_reply;
4580 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4581 struct _sas_device *sas_device;
4583 unsigned long flags;
4585 /* only handle non-raid devices */
4586 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4587 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4591 starget = sas_device->starget;
4592 sas_target_priv_data = starget->hostdata;
4594 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4595 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4598 if (sas_device->enclosure_handle != 0)
4599 starget_printk(KERN_INFO, starget, "predicted fault, "
4600 "enclosure logical id(0x%016llx), slot(%d)\n",
4601 (unsigned long long)sas_device->enclosure_logical_id,
4603 if (sas_device->connector_name[0] != '\0')
4604 starget_printk(KERN_WARNING, starget, "predicted fault, "
4605 "enclosure level(0x%04x), connector name( %s)\n",
4606 sas_device->enclosure_level,
4607 sas_device->connector_name);
4608 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4610 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4611 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4613 /* insert into event log */
4614 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4615 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4616 event_reply = kzalloc(sz, GFP_KERNEL);
4618 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4619 ioc->name, __FILE__, __LINE__, __func__);
4623 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4624 event_reply->Event =
4625 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4626 event_reply->MsgLength = sz/4;
4627 event_reply->EventDataLength =
4628 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4629 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4630 event_reply->EventData;
4631 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4632 event_data->ASC = 0x5D;
4633 event_data->DevHandle = cpu_to_le16(handle);
4634 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4635 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4639 sas_device_put(sas_device);
4643 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4648 * _scsih_io_done - scsi request callback
4649 * @ioc: per adapter object
4650 * @smid: system request message index
4651 * @msix_index: MSIX table index supplied by the OS
4652 * @reply: reply message frame(lower 32bit addr)
4654 * Callback handler when using _scsih_qcmd.
4656 * Return 1 meaning mf should be freed from _base_interrupt
4657 * 0 means the mf is freed from this function.
4660 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4662 Mpi2SCSIIORequest_t *mpi_request;
4663 Mpi2SCSIIOReply_t *mpi_reply;
4664 struct scsi_cmnd *scmd;
4670 struct MPT3SAS_DEVICE *sas_device_priv_data;
4671 u32 response_code = 0;
4672 unsigned long flags;
4673 unsigned int sector_sz;
4675 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4676 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4680 _scsih_set_satl_pending(scmd, false);
4682 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4684 if (mpi_reply == NULL) {
4685 scmd->result = DID_OK << 16;
4689 sas_device_priv_data = scmd->device->hostdata;
4690 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4691 sas_device_priv_data->sas_target->deleted) {
4692 scmd->result = DID_NO_CONNECT << 16;
4695 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4698 * WARPDRIVE: If direct_io is set then it is directIO,
4699 * the failed direct I/O should be redirected to volume
4701 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4702 ((ioc_status & MPI2_IOCSTATUS_MASK)
4703 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4704 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4705 ioc->scsi_lookup[smid - 1].scmd = scmd;
4706 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4707 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4708 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4709 mpi_request->DevHandle =
4710 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4711 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4712 sas_device_priv_data->sas_target->handle);
4715 /* turning off TLR */
4716 scsi_state = mpi_reply->SCSIState;
4717 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4719 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4720 if (!sas_device_priv_data->tlr_snoop_check) {
4721 sas_device_priv_data->tlr_snoop_check++;
4722 if (!ioc->is_warpdrive &&
4723 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4724 sas_is_tlr_enabled(scmd->device) &&
4725 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4726 sas_disable_tlr(scmd->device);
4727 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4731 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4733 /* In case of bogus fw or device, we could end up having
4734 * unaligned partial completion. We can force alignment here,
4735 * then scsi-ml does not need to handle this misbehavior.
4737 sector_sz = scmd->device->sector_size;
4738 if (unlikely(scmd->request->cmd_type == REQ_TYPE_FS && sector_sz &&
4739 xfer_cnt % sector_sz)) {
4740 sdev_printk(KERN_INFO, scmd->device,
4741 "unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4742 xfer_cnt, sector_sz);
4743 xfer_cnt = round_down(xfer_cnt, sector_sz);
4746 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4747 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4748 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4751 ioc_status &= MPI2_IOCSTATUS_MASK;
4752 scsi_status = mpi_reply->SCSIStatus;
4754 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4755 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4756 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4757 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4758 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4761 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4762 struct sense_info data;
4763 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4765 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4766 le32_to_cpu(mpi_reply->SenseCount));
4767 memcpy(scmd->sense_buffer, sense_data, sz);
4768 _scsih_normalize_sense(scmd->sense_buffer, &data);
4769 /* failure prediction threshold exceeded */
4770 if (data.asc == 0x5D)
4771 _scsih_smart_predicted_fault(ioc,
4772 le16_to_cpu(mpi_reply->DevHandle));
4773 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4775 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
4776 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4777 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4778 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4779 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4781 switch (ioc_status) {
4782 case MPI2_IOCSTATUS_BUSY:
4783 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4784 scmd->result = SAM_STAT_BUSY;
4787 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4788 scmd->result = DID_NO_CONNECT << 16;
4791 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4792 if (sas_device_priv_data->block) {
4793 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4796 if (log_info == 0x31110630) {
4797 if (scmd->retries > 2) {
4798 scmd->result = DID_NO_CONNECT << 16;
4799 scsi_device_set_state(scmd->device,
4802 scmd->result = DID_SOFT_ERROR << 16;
4803 scmd->device->expecting_cc_ua = 1;
4806 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4807 scmd->result = DID_RESET << 16;
4809 } else if ((scmd->device->channel == RAID_CHANNEL) &&
4810 (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
4811 MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
4812 scmd->result = DID_RESET << 16;
4815 scmd->result = DID_SOFT_ERROR << 16;
4817 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4818 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4819 scmd->result = DID_RESET << 16;
4822 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4823 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4824 scmd->result = DID_SOFT_ERROR << 16;
4826 scmd->result = (DID_OK << 16) | scsi_status;
4829 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4830 scmd->result = (DID_OK << 16) | scsi_status;
4832 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4835 if (xfer_cnt < scmd->underflow) {
4836 if (scsi_status == SAM_STAT_BUSY)
4837 scmd->result = SAM_STAT_BUSY;
4839 scmd->result = DID_SOFT_ERROR << 16;
4840 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4841 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4842 scmd->result = DID_SOFT_ERROR << 16;
4843 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4844 scmd->result = DID_RESET << 16;
4845 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4846 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4847 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4848 scmd->result = (DRIVER_SENSE << 24) |
4849 SAM_STAT_CHECK_CONDITION;
4850 scmd->sense_buffer[0] = 0x70;
4851 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4852 scmd->sense_buffer[12] = 0x20;
4853 scmd->sense_buffer[13] = 0;
4857 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4858 scsi_set_resid(scmd, 0);
4859 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4860 case MPI2_IOCSTATUS_SUCCESS:
4861 scmd->result = (DID_OK << 16) | scsi_status;
4862 if (response_code ==
4863 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4864 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4865 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4866 scmd->result = DID_SOFT_ERROR << 16;
4867 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4868 scmd->result = DID_RESET << 16;
4871 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4872 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4873 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4874 _scsih_eedp_error_handling(scmd, ioc_status);
4877 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4878 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4879 case MPI2_IOCSTATUS_INVALID_SGL:
4880 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4881 case MPI2_IOCSTATUS_INVALID_FIELD:
4882 case MPI2_IOCSTATUS_INVALID_STATE:
4883 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4884 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4885 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4887 scmd->result = DID_SOFT_ERROR << 16;
4892 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4893 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4897 scsi_dma_unmap(scmd);
4899 scmd->scsi_done(scmd);
4904 * _scsih_sas_host_refresh - refreshing sas host object contents
4905 * @ioc: per adapter object
4908 * During port enable, fw will send topology events for every device. Its
4909 * possible that the handles may change from the previous setting, so this
4910 * code keeping handles updating if changed.
4915 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4920 Mpi2ConfigReply_t mpi_reply;
4921 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4922 u16 attached_handle;
4925 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4926 "updating handles for sas_host(0x%016llx)\n",
4927 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4929 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4930 * sizeof(Mpi2SasIOUnit0PhyData_t));
4931 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4932 if (!sas_iounit_pg0) {
4933 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4934 ioc->name, __FILE__, __LINE__, __func__);
4938 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4939 sas_iounit_pg0, sz)) != 0)
4941 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4942 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4944 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4945 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4947 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4948 PhyData[0].ControllerDevHandle);
4949 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4950 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4952 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4953 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4954 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4955 attached_handle, i, link_rate);
4958 kfree(sas_iounit_pg0);
4962 * _scsih_sas_host_add - create sas host object
4963 * @ioc: per adapter object
4965 * Creating host side data object, stored in ioc->sas_hba
4970 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4973 Mpi2ConfigReply_t mpi_reply;
4974 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4975 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4976 Mpi2SasPhyPage0_t phy_pg0;
4977 Mpi2SasDevicePage0_t sas_device_pg0;
4978 Mpi2SasEnclosurePage0_t enclosure_pg0;
4981 u8 device_missing_delay;
4984 mpt3sas_config_get_number_hba_phys(ioc, &num_phys);
4986 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4987 ioc->name, __FILE__, __LINE__, __func__);
4990 ioc->sas_hba.phy = kcalloc(num_phys,
4991 sizeof(struct _sas_phy), GFP_KERNEL);
4992 if (!ioc->sas_hba.phy) {
4993 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4994 ioc->name, __FILE__, __LINE__, __func__);
4997 ioc->sas_hba.num_phys = num_phys;
4999 /* sas_iounit page 0 */
5000 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
5001 sizeof(Mpi2SasIOUnit0PhyData_t));
5002 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
5003 if (!sas_iounit_pg0) {
5004 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5005 ioc->name, __FILE__, __LINE__, __func__);
5008 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
5009 sas_iounit_pg0, sz))) {
5010 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5011 ioc->name, __FILE__, __LINE__, __func__);
5014 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5015 MPI2_IOCSTATUS_MASK;
5016 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5017 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5018 ioc->name, __FILE__, __LINE__, __func__);
5022 /* sas_iounit page 1 */
5023 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
5024 sizeof(Mpi2SasIOUnit1PhyData_t));
5025 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
5026 if (!sas_iounit_pg1) {
5027 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5028 ioc->name, __FILE__, __LINE__, __func__);
5031 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
5032 sas_iounit_pg1, sz))) {
5033 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5034 ioc->name, __FILE__, __LINE__, __func__);
5037 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5038 MPI2_IOCSTATUS_MASK;
5039 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5040 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5041 ioc->name, __FILE__, __LINE__, __func__);
5045 ioc->io_missing_delay =
5046 sas_iounit_pg1->IODeviceMissingDelay;
5047 device_missing_delay =
5048 sas_iounit_pg1->ReportDeviceMissingDelay;
5049 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
5050 ioc->device_missing_delay = (device_missing_delay &
5051 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
5053 ioc->device_missing_delay = device_missing_delay &
5054 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
5056 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
5057 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
5058 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
5060 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5061 ioc->name, __FILE__, __LINE__, __func__);
5064 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5065 MPI2_IOCSTATUS_MASK;
5066 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5067 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5068 ioc->name, __FILE__, __LINE__, __func__);
5073 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
5074 PhyData[0].ControllerDevHandle);
5075 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
5076 ioc->sas_hba.phy[i].phy_id = i;
5077 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
5078 phy_pg0, ioc->sas_hba.parent_dev);
5080 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5081 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
5082 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5083 ioc->name, __FILE__, __LINE__, __func__);
5086 ioc->sas_hba.enclosure_handle =
5087 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5088 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5090 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5091 ioc->name, ioc->sas_hba.handle,
5092 (unsigned long long) ioc->sas_hba.sas_address,
5093 ioc->sas_hba.num_phys) ;
5095 if (ioc->sas_hba.enclosure_handle) {
5096 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5097 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5098 ioc->sas_hba.enclosure_handle)))
5099 ioc->sas_hba.enclosure_logical_id =
5100 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5104 kfree(sas_iounit_pg1);
5105 kfree(sas_iounit_pg0);
5109 * _scsih_expander_add - creating expander object
5110 * @ioc: per adapter object
5111 * @handle: expander handle
5113 * Creating expander object, stored in ioc->sas_expander_list.
5115 * Return 0 for success, else error.
5118 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5120 struct _sas_node *sas_expander;
5121 Mpi2ConfigReply_t mpi_reply;
5122 Mpi2ExpanderPage0_t expander_pg0;
5123 Mpi2ExpanderPage1_t expander_pg1;
5124 Mpi2SasEnclosurePage0_t enclosure_pg0;
5127 u64 sas_address, sas_address_parent = 0;
5129 unsigned long flags;
5130 struct _sas_port *mpt3sas_port = NULL;
5137 if (ioc->shost_recovery || ioc->pci_error_recovery)
5140 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5141 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5142 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5143 ioc->name, __FILE__, __LINE__, __func__);
5147 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5148 MPI2_IOCSTATUS_MASK;
5149 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5150 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5151 ioc->name, __FILE__, __LINE__, __func__);
5155 /* handle out of order topology events */
5156 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5157 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5159 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5160 ioc->name, __FILE__, __LINE__, __func__);
5163 if (sas_address_parent != ioc->sas_hba.sas_address) {
5164 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5165 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5166 sas_address_parent);
5167 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5168 if (!sas_expander) {
5169 rc = _scsih_expander_add(ioc, parent_handle);
5175 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5176 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5177 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5179 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5184 sas_expander = kzalloc(sizeof(struct _sas_node),
5186 if (!sas_expander) {
5187 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5188 ioc->name, __FILE__, __LINE__, __func__);
5192 sas_expander->handle = handle;
5193 sas_expander->num_phys = expander_pg0.NumPhys;
5194 sas_expander->sas_address_parent = sas_address_parent;
5195 sas_expander->sas_address = sas_address;
5197 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5198 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5199 handle, parent_handle, (unsigned long long)
5200 sas_expander->sas_address, sas_expander->num_phys);
5202 if (!sas_expander->num_phys) {
5206 sas_expander->phy = kcalloc(sas_expander->num_phys,
5207 sizeof(struct _sas_phy), GFP_KERNEL);
5208 if (!sas_expander->phy) {
5209 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5210 ioc->name, __FILE__, __LINE__, __func__);
5215 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5216 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5217 sas_address_parent);
5218 if (!mpt3sas_port) {
5219 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5220 ioc->name, __FILE__, __LINE__, __func__);
5224 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5226 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5227 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5228 &expander_pg1, i, handle))) {
5229 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5230 ioc->name, __FILE__, __LINE__, __func__);
5234 sas_expander->phy[i].handle = handle;
5235 sas_expander->phy[i].phy_id = i;
5237 if ((mpt3sas_transport_add_expander_phy(ioc,
5238 &sas_expander->phy[i], expander_pg1,
5239 sas_expander->parent_dev))) {
5240 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5241 ioc->name, __FILE__, __LINE__, __func__);
5247 if (sas_expander->enclosure_handle) {
5248 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5249 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5250 sas_expander->enclosure_handle)))
5251 sas_expander->enclosure_logical_id =
5252 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5255 _scsih_expander_node_add(ioc, sas_expander);
5261 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5262 sas_address_parent);
5263 kfree(sas_expander);
5268 * mpt3sas_expander_remove - removing expander object
5269 * @ioc: per adapter object
5270 * @sas_address: expander sas_address
5275 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5277 struct _sas_node *sas_expander;
5278 unsigned long flags;
5280 if (ioc->shost_recovery)
5283 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5284 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5287 list_del(&sas_expander->list);
5288 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5290 _scsih_expander_node_remove(ioc, sas_expander);
5294 * _scsih_done - internal SCSI_IO callback handler.
5295 * @ioc: per adapter object
5296 * @smid: system request message index
5297 * @msix_index: MSIX table index supplied by the OS
5298 * @reply: reply message frame(lower 32bit addr)
5300 * Callback handler when sending internal generated SCSI_IO.
5301 * The callback index passed is `ioc->scsih_cb_idx`
5303 * Return 1 meaning mf should be freed from _base_interrupt
5304 * 0 means the mf is freed from this function.
5307 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5309 MPI2DefaultReply_t *mpi_reply;
5311 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5312 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5314 if (ioc->scsih_cmds.smid != smid)
5316 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5318 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5319 mpi_reply->MsgLength*4);
5320 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5322 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5323 complete(&ioc->scsih_cmds.done);
5330 #define MPT3_MAX_LUNS (255)
5334 * _scsih_check_access_status - check access flags
5335 * @ioc: per adapter object
5336 * @sas_address: sas address
5337 * @handle: sas device handle
5338 * @access_flags: errors returned during discovery of the device
5340 * Return 0 for success, else failure
5343 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5344 u16 handle, u8 access_status)
5349 switch (access_status) {
5350 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5351 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5354 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5355 desc = "sata capability failed";
5357 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5358 desc = "sata affiliation conflict";
5360 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5361 desc = "route not addressable";
5363 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5364 desc = "smp error not addressable";
5366 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5367 desc = "device blocked";
5369 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5370 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5371 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5372 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5373 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5374 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5375 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5376 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5377 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5378 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5379 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5380 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5381 desc = "sata initialization failed";
5392 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5393 ioc->name, desc, (unsigned long long)sas_address, handle);
5398 * _scsih_check_device - checking device responsiveness
5399 * @ioc: per adapter object
5400 * @parent_sas_address: sas address of parent expander or sas host
5401 * @handle: attached device handle
5402 * @phy_numberv: phy number
5403 * @link_rate: new link rate
5408 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5409 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5411 Mpi2ConfigReply_t mpi_reply;
5412 Mpi2SasDevicePage0_t sas_device_pg0;
5413 struct _sas_device *sas_device;
5415 unsigned long flags;
5417 struct scsi_target *starget;
5418 struct MPT3SAS_TARGET *sas_target_priv_data;
5422 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5423 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5426 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5427 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5430 /* wide port handling ~ we need only handle device once for the phy that
5431 * is matched in sas device page zero
5433 if (phy_number != sas_device_pg0.PhyNum)
5436 /* check if this is end device */
5437 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5438 if (!(_scsih_is_end_device(device_info)))
5441 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5442 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5443 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5449 if (unlikely(sas_device->handle != handle)) {
5450 starget = sas_device->starget;
5451 sas_target_priv_data = starget->hostdata;
5452 starget_printk(KERN_INFO, starget,
5453 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5454 sas_device->handle, handle);
5455 sas_target_priv_data->handle = handle;
5456 sas_device->handle = handle;
5457 if (sas_device_pg0.Flags &
5458 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5459 sas_device->enclosure_level =
5460 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5461 memcpy(sas_device->connector_name,
5462 sas_device_pg0.ConnectorName, 4);
5463 sas_device->connector_name[4] = '\0';
5465 sas_device->enclosure_level = 0;
5466 sas_device->connector_name[0] = '\0';
5470 /* check if device is present */
5471 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5472 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5474 "device is not present handle(0x%04x), flags!!!\n",
5479 /* check if there were any issues with discovery */
5480 if (_scsih_check_access_status(ioc, sas_address, handle,
5481 sas_device_pg0.AccessStatus))
5484 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5485 _scsih_ublock_io_device(ioc, sas_address);
5488 sas_device_put(sas_device);
5492 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5494 sas_device_put(sas_device);
5498 * _scsih_add_device - creating sas device object
5499 * @ioc: per adapter object
5500 * @handle: sas device handle
5501 * @phy_num: phy number end device attached to
5502 * @is_pd: is this hidden raid component
5504 * Creating end device object, stored in ioc->sas_device_list.
5506 * Returns 0 for success, non-zero for failure.
5509 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5512 Mpi2ConfigReply_t mpi_reply;
5513 Mpi2SasDevicePage0_t sas_device_pg0;
5514 Mpi2SasEnclosurePage0_t enclosure_pg0;
5515 struct _sas_device *sas_device;
5520 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5521 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5522 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5523 ioc->name, __FILE__, __LINE__, __func__);
5527 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5528 MPI2_IOCSTATUS_MASK;
5529 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5530 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5531 ioc->name, __FILE__, __LINE__, __func__);
5535 /* check if this is end device */
5536 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5537 if (!(_scsih_is_end_device(device_info)))
5539 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5541 /* check if device is present */
5542 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5543 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5544 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5549 /* check if there were any issues with discovery */
5550 if (_scsih_check_access_status(ioc, sas_address, handle,
5551 sas_device_pg0.AccessStatus))
5554 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5557 sas_device_put(sas_device);
5561 sas_device = kzalloc(sizeof(struct _sas_device),
5564 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5565 ioc->name, __FILE__, __LINE__, __func__);
5569 kref_init(&sas_device->refcount);
5570 sas_device->handle = handle;
5571 if (_scsih_get_sas_address(ioc,
5572 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5573 &sas_device->sas_address_parent) != 0)
5574 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5575 ioc->name, __FILE__, __LINE__, __func__);
5576 sas_device->enclosure_handle =
5577 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5578 if (sas_device->enclosure_handle != 0)
5580 le16_to_cpu(sas_device_pg0.Slot);
5581 sas_device->device_info = device_info;
5582 sas_device->sas_address = sas_address;
5583 sas_device->phy = sas_device_pg0.PhyNum;
5584 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5585 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5587 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5588 sas_device->enclosure_level =
5589 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5590 memcpy(sas_device->connector_name,
5591 sas_device_pg0.ConnectorName, 4);
5592 sas_device->connector_name[4] = '\0';
5594 sas_device->enclosure_level = 0;
5595 sas_device->connector_name[0] = '\0';
5597 /* get enclosure_logical_id */
5598 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5599 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5600 sas_device->enclosure_handle)))
5601 sas_device->enclosure_logical_id =
5602 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5604 /* get device name */
5605 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5607 if (ioc->wait_for_discovery_to_complete)
5608 _scsih_sas_device_init_add(ioc, sas_device);
5610 _scsih_sas_device_add(ioc, sas_device);
5612 sas_device_put(sas_device);
5617 * _scsih_remove_device - removing sas device object
5618 * @ioc: per adapter object
5619 * @sas_device_delete: the sas_device object
5624 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5625 struct _sas_device *sas_device)
5627 struct MPT3SAS_TARGET *sas_target_priv_data;
5629 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5630 (sas_device->pfa_led_on)) {
5631 _scsih_turn_off_pfa_led(ioc, sas_device);
5632 sas_device->pfa_led_on = 0;
5634 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5635 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5636 ioc->name, __func__,
5637 sas_device->handle, (unsigned long long)
5638 sas_device->sas_address));
5639 if (sas_device->enclosure_handle != 0)
5640 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5641 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5642 ioc->name, __func__,
5643 (unsigned long long)sas_device->enclosure_logical_id,
5645 if (sas_device->connector_name[0] != '\0')
5646 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5647 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5648 ioc->name, __func__,
5649 sas_device->enclosure_level,
5650 sas_device->connector_name));
5652 if (sas_device->starget && sas_device->starget->hostdata) {
5653 sas_target_priv_data = sas_device->starget->hostdata;
5654 sas_target_priv_data->deleted = 1;
5655 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5656 sas_target_priv_data->handle =
5657 MPT3SAS_INVALID_DEVICE_HANDLE;
5660 if (!ioc->hide_drives)
5661 mpt3sas_transport_port_remove(ioc,
5662 sas_device->sas_address,
5663 sas_device->sas_address_parent);
5666 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5667 ioc->name, sas_device->handle,
5668 (unsigned long long) sas_device->sas_address);
5669 if (sas_device->enclosure_handle != 0)
5671 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5673 (unsigned long long)sas_device->enclosure_logical_id,
5675 if (sas_device->connector_name[0] != '\0')
5677 "removing enclosure level(0x%04x), connector name( %s)\n",
5678 ioc->name, sas_device->enclosure_level,
5679 sas_device->connector_name);
5681 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5682 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5683 ioc->name, __func__,
5684 sas_device->handle, (unsigned long long)
5685 sas_device->sas_address));
5686 if (sas_device->enclosure_handle != 0)
5687 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5688 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5689 ioc->name, __func__,
5690 (unsigned long long)sas_device->enclosure_logical_id,
5692 if (sas_device->connector_name[0] != '\0')
5693 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5694 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5695 ioc->name, __func__, sas_device->enclosure_level,
5696 sas_device->connector_name));
5700 * _scsih_sas_topology_change_event_debug - debug for topology event
5701 * @ioc: per adapter object
5702 * @event_data: event data payload
5706 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5707 Mpi2EventDataSasTopologyChangeList_t *event_data)
5713 char *status_str = NULL;
5714 u8 link_rate, prev_link_rate;
5716 switch (event_data->ExpStatus) {
5717 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5720 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5721 status_str = "remove";
5723 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5725 status_str = "responding";
5727 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5728 status_str = "remove delay";
5731 status_str = "unknown status";
5734 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5735 ioc->name, status_str);
5736 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5737 "start_phy(%02d), count(%d)\n",
5738 le16_to_cpu(event_data->ExpanderDevHandle),
5739 le16_to_cpu(event_data->EnclosureHandle),
5740 event_data->StartPhyNum, event_data->NumEntries);
5741 for (i = 0; i < event_data->NumEntries; i++) {
5742 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5745 phy_number = event_data->StartPhyNum + i;
5746 reason_code = event_data->PHY[i].PhyStatus &
5747 MPI2_EVENT_SAS_TOPO_RC_MASK;
5748 switch (reason_code) {
5749 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5750 status_str = "target add";
5752 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5753 status_str = "target remove";
5755 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5756 status_str = "delay target remove";
5758 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5759 status_str = "link rate change";
5761 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5762 status_str = "target responding";
5765 status_str = "unknown";
5768 link_rate = event_data->PHY[i].LinkRate >> 4;
5769 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5770 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5771 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5772 handle, status_str, link_rate, prev_link_rate);
5778 * _scsih_sas_topology_change_event - handle topology changes
5779 * @ioc: per adapter object
5780 * @fw_event: The fw_event_work object
5785 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5786 struct fw_event_work *fw_event)
5789 u16 parent_handle, handle;
5791 u8 phy_number, max_phys;
5792 struct _sas_node *sas_expander;
5794 unsigned long flags;
5795 u8 link_rate, prev_link_rate;
5796 Mpi2EventDataSasTopologyChangeList_t *event_data =
5797 (Mpi2EventDataSasTopologyChangeList_t *)
5798 fw_event->event_data;
5800 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5801 _scsih_sas_topology_change_event_debug(ioc, event_data);
5803 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5806 if (!ioc->sas_hba.num_phys)
5807 _scsih_sas_host_add(ioc);
5809 _scsih_sas_host_refresh(ioc);
5811 if (fw_event->ignore) {
5812 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5813 "ignoring expander event\n", ioc->name));
5817 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5819 /* handle expander add */
5820 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5821 if (_scsih_expander_add(ioc, parent_handle) != 0)
5824 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5825 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5828 sas_address = sas_expander->sas_address;
5829 max_phys = sas_expander->num_phys;
5830 } else if (parent_handle < ioc->sas_hba.num_phys) {
5831 sas_address = ioc->sas_hba.sas_address;
5832 max_phys = ioc->sas_hba.num_phys;
5834 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5837 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5839 /* handle siblings events */
5840 for (i = 0; i < event_data->NumEntries; i++) {
5841 if (fw_event->ignore) {
5842 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5843 "ignoring expander event\n", ioc->name));
5846 if (ioc->remove_host || ioc->pci_error_recovery)
5848 phy_number = event_data->StartPhyNum + i;
5849 if (phy_number >= max_phys)
5851 reason_code = event_data->PHY[i].PhyStatus &
5852 MPI2_EVENT_SAS_TOPO_RC_MASK;
5853 if ((event_data->PHY[i].PhyStatus &
5854 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5855 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5857 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5860 link_rate = event_data->PHY[i].LinkRate >> 4;
5861 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5862 switch (reason_code) {
5863 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5865 if (ioc->shost_recovery)
5868 if (link_rate == prev_link_rate)
5871 mpt3sas_transport_update_links(ioc, sas_address,
5872 handle, phy_number, link_rate);
5874 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5877 _scsih_check_device(ioc, sas_address, handle,
5878 phy_number, link_rate);
5881 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5883 if (ioc->shost_recovery)
5886 mpt3sas_transport_update_links(ioc, sas_address,
5887 handle, phy_number, link_rate);
5889 _scsih_add_device(ioc, handle, phy_number, 0);
5892 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5894 _scsih_device_remove_by_handle(ioc, handle);
5899 /* handle expander removal */
5900 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5902 mpt3sas_expander_remove(ioc, sas_address);
5908 * _scsih_sas_device_status_change_event_debug - debug for device event
5909 * @event_data: event data payload
5915 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5916 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5918 char *reason_str = NULL;
5920 switch (event_data->ReasonCode) {
5921 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5922 reason_str = "smart data";
5924 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5925 reason_str = "unsupported device discovered";
5927 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5928 reason_str = "internal device reset";
5930 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5931 reason_str = "internal task abort";
5933 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5934 reason_str = "internal task abort set";
5936 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5937 reason_str = "internal clear task set";
5939 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5940 reason_str = "internal query task";
5942 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5943 reason_str = "sata init failure";
5945 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5946 reason_str = "internal device reset complete";
5948 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5949 reason_str = "internal task abort complete";
5951 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5952 reason_str = "internal async notification";
5954 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5955 reason_str = "expander reduced functionality";
5957 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5958 reason_str = "expander reduced functionality complete";
5961 reason_str = "unknown reason";
5964 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5965 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5966 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5967 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5968 le16_to_cpu(event_data->TaskTag));
5969 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5970 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5971 event_data->ASC, event_data->ASCQ);
5976 * _scsih_sas_device_status_change_event - handle device status change
5977 * @ioc: per adapter object
5978 * @fw_event: The fw_event_work object
5984 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5985 struct fw_event_work *fw_event)
5987 struct MPT3SAS_TARGET *target_priv_data;
5988 struct _sas_device *sas_device;
5990 unsigned long flags;
5991 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5992 (Mpi2EventDataSasDeviceStatusChange_t *)
5993 fw_event->event_data;
5995 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5996 _scsih_sas_device_status_change_event_debug(ioc,
5999 /* In MPI Revision K (0xC), the internal device reset complete was
6000 * implemented, so avoid setting tm_busy flag for older firmware.
6002 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
6005 if (event_data->ReasonCode !=
6006 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
6007 event_data->ReasonCode !=
6008 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
6011 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6012 sas_address = le64_to_cpu(event_data->SASAddress);
6013 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
6016 if (!sas_device || !sas_device->starget)
6019 target_priv_data = sas_device->starget->hostdata;
6020 if (!target_priv_data)
6023 if (event_data->ReasonCode ==
6024 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
6025 target_priv_data->tm_busy = 1;
6027 target_priv_data->tm_busy = 0;
6031 sas_device_put(sas_device);
6033 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6038 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
6040 * @ioc: per adapter object
6041 * @event_data: event data payload
6047 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6048 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
6050 char *reason_str = NULL;
6052 switch (event_data->ReasonCode) {
6053 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
6054 reason_str = "enclosure add";
6056 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
6057 reason_str = "enclosure remove";
6060 reason_str = "unknown reason";
6064 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
6065 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
6066 " number slots(%d)\n", ioc->name, reason_str,
6067 le16_to_cpu(event_data->EnclosureHandle),
6068 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
6069 le16_to_cpu(event_data->StartSlot));
6073 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
6074 * @ioc: per adapter object
6075 * @fw_event: The fw_event_work object
6081 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
6082 struct fw_event_work *fw_event)
6084 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6085 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
6086 (Mpi2EventDataSasEnclDevStatusChange_t *)
6087 fw_event->event_data);
6091 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6092 * @ioc: per adapter object
6093 * @fw_event: The fw_event_work object
6099 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
6100 struct fw_event_work *fw_event)
6102 struct scsi_cmnd *scmd;
6103 struct scsi_device *sdev;
6106 struct MPT3SAS_DEVICE *sas_device_priv_data;
6107 u32 termination_count;
6109 Mpi2SCSITaskManagementReply_t *mpi_reply;
6110 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
6111 (Mpi2EventDataSasBroadcastPrimitive_t *)
6112 fw_event->event_data;
6114 unsigned long flags;
6117 u8 task_abort_retries;
6119 mutex_lock(&ioc->tm_cmds.mutex);
6121 "%s: enter: phy number(%d), width(%d)\n",
6122 ioc->name, __func__, event_data->PhyNum,
6123 event_data->PortWidth);
6125 _scsih_block_io_all_device(ioc);
6127 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6128 mpi_reply = ioc->tm_cmds.reply;
6129 broadcast_aen_retry:
6131 /* sanity checks for retrying this loop */
6132 if (max_retries++ == 5) {
6133 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
6134 ioc->name, __func__));
6136 } else if (max_retries > 1)
6137 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
6138 ioc->name, __func__, max_retries - 1));
6140 termination_count = 0;
6142 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
6143 if (ioc->shost_recovery)
6145 scmd = _scsih_scsi_lookup_get(ioc, smid);
6148 sdev = scmd->device;
6149 sas_device_priv_data = sdev->hostdata;
6150 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
6152 /* skip hidden raid components */
6153 if (sas_device_priv_data->sas_target->flags &
6154 MPT_TARGET_FLAGS_RAID_COMPONENT)
6157 if (sas_device_priv_data->sas_target->flags &
6158 MPT_TARGET_FLAGS_VOLUME)
6161 handle = sas_device_priv_data->sas_target->handle;
6162 lun = sas_device_priv_data->lun;
6165 if (ioc->shost_recovery)
6168 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6169 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6170 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
6172 sdev_printk(KERN_WARNING, sdev,
6173 "mpt3sas_scsih_issue_tm: FAILED when sending "
6174 "QUERY_TASK: scmd(%p)\n", scmd);
6175 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6176 goto broadcast_aen_retry;
6178 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6179 & MPI2_IOCSTATUS_MASK;
6180 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6181 sdev_printk(KERN_WARNING, sdev,
6182 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6184 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6185 goto broadcast_aen_retry;
6188 /* see if IO is still owned by IOC and target */
6189 if (mpi_reply->ResponseCode ==
6190 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6191 mpi_reply->ResponseCode ==
6192 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6193 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6196 task_abort_retries = 0;
6198 if (task_abort_retries++ == 60) {
6199 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6200 "%s: ABORT_TASK: giving up\n", ioc->name,
6202 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6203 goto broadcast_aen_retry;
6206 if (ioc->shost_recovery)
6209 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6210 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid,
6213 sdev_printk(KERN_WARNING, sdev,
6214 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6215 "scmd(%p)\n", scmd);
6219 if (task_abort_retries > 1)
6220 sdev_printk(KERN_WARNING, sdev,
6221 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6223 task_abort_retries - 1, scmd);
6225 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6226 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6229 if (ioc->broadcast_aen_pending) {
6230 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6231 "%s: loop back due to pending AEN\n",
6232 ioc->name, __func__));
6233 ioc->broadcast_aen_pending = 0;
6234 goto broadcast_aen_retry;
6238 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6241 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6242 "%s - exit, query_count = %d termination_count = %d\n",
6243 ioc->name, __func__, query_count, termination_count));
6245 ioc->broadcast_aen_busy = 0;
6246 if (!ioc->shost_recovery)
6247 _scsih_ublock_io_all_device(ioc);
6248 mutex_unlock(&ioc->tm_cmds.mutex);
6252 * _scsih_sas_discovery_event - handle discovery events
6253 * @ioc: per adapter object
6254 * @fw_event: The fw_event_work object
6260 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
6261 struct fw_event_work *fw_event)
6263 Mpi2EventDataSasDiscovery_t *event_data =
6264 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
6266 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6267 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
6268 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6270 if (event_data->DiscoveryStatus)
6271 pr_info("discovery_status(0x%08x)",
6272 le32_to_cpu(event_data->DiscoveryStatus));
6276 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6277 !ioc->sas_hba.num_phys) {
6278 if (disable_discovery > 0 && ioc->shost_recovery) {
6279 /* Wait for the reset to complete */
6280 while (ioc->shost_recovery)
6283 _scsih_sas_host_add(ioc);
6288 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6289 * @ioc: per adapter object
6290 * @handle: device handle for physical disk
6291 * @phys_disk_num: physical disk number
6293 * Return 0 for success, else failure.
6296 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6298 Mpi2RaidActionRequest_t *mpi_request;
6299 Mpi2RaidActionReply_t *mpi_reply;
6306 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6309 mutex_lock(&ioc->scsih_cmds.mutex);
6311 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6312 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6313 ioc->name, __func__);
6317 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6319 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6321 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6322 ioc->name, __func__);
6323 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6328 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6329 ioc->scsih_cmds.smid = smid;
6330 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6332 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6333 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6334 mpi_request->PhysDiskNum = phys_disk_num;
6336 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6337 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6338 handle, phys_disk_num));
6340 init_completion(&ioc->scsih_cmds.done);
6341 mpt3sas_base_put_smid_default(ioc, smid);
6342 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6344 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6345 pr_err(MPT3SAS_FMT "%s: timeout\n",
6346 ioc->name, __func__);
6347 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6353 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6355 mpi_reply = ioc->scsih_cmds.reply;
6356 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6357 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6358 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6361 ioc_status &= MPI2_IOCSTATUS_MASK;
6362 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6363 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6364 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6365 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6369 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6370 "IR RAID_ACTION: completed successfully\n",
6375 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6376 mutex_unlock(&ioc->scsih_cmds.mutex);
6379 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
6384 * _scsih_reprobe_lun - reprobing lun
6385 * @sdev: scsi device struct
6386 * @no_uld_attach: sdev->no_uld_attach flag setting
6390 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6392 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6393 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6394 sdev->no_uld_attach ? "hidding" : "exposing");
6395 WARN_ON(scsi_device_reprobe(sdev));
6399 * _scsih_sas_volume_add - add new volume
6400 * @ioc: per adapter object
6401 * @element: IR config element data
6407 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6408 Mpi2EventIrConfigElement_t *element)
6410 struct _raid_device *raid_device;
6411 unsigned long flags;
6413 u16 handle = le16_to_cpu(element->VolDevHandle);
6416 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6419 "failure at %s:%d/%s()!\n", ioc->name,
6420 __FILE__, __LINE__, __func__);
6424 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6425 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6426 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6431 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6434 "failure at %s:%d/%s()!\n", ioc->name,
6435 __FILE__, __LINE__, __func__);
6439 raid_device->id = ioc->sas_id++;
6440 raid_device->channel = RAID_CHANNEL;
6441 raid_device->handle = handle;
6442 raid_device->wwid = wwid;
6443 _scsih_raid_device_add(ioc, raid_device);
6444 if (!ioc->wait_for_discovery_to_complete) {
6445 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6446 raid_device->id, 0);
6448 _scsih_raid_device_remove(ioc, raid_device);
6450 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6451 _scsih_determine_boot_device(ioc, raid_device, 1);
6452 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6457 * _scsih_sas_volume_delete - delete volume
6458 * @ioc: per adapter object
6459 * @handle: volume device handle
6465 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6467 struct _raid_device *raid_device;
6468 unsigned long flags;
6469 struct MPT3SAS_TARGET *sas_target_priv_data;
6470 struct scsi_target *starget = NULL;
6472 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6473 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6475 if (raid_device->starget) {
6476 starget = raid_device->starget;
6477 sas_target_priv_data = starget->hostdata;
6478 sas_target_priv_data->deleted = 1;
6480 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6481 ioc->name, raid_device->handle,
6482 (unsigned long long) raid_device->wwid);
6483 list_del(&raid_device->list);
6486 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6488 scsi_remove_target(&starget->dev);
6492 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6493 * @ioc: per adapter object
6494 * @element: IR config element data
6500 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6501 Mpi2EventIrConfigElement_t *element)
6503 struct _sas_device *sas_device;
6504 struct scsi_target *starget = NULL;
6505 struct MPT3SAS_TARGET *sas_target_priv_data;
6506 unsigned long flags;
6507 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6509 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6510 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6512 sas_device->volume_handle = 0;
6513 sas_device->volume_wwid = 0;
6514 clear_bit(handle, ioc->pd_handles);
6515 if (sas_device->starget && sas_device->starget->hostdata) {
6516 starget = sas_device->starget;
6517 sas_target_priv_data = starget->hostdata;
6518 sas_target_priv_data->flags &=
6519 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6522 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6526 /* exposing raid component */
6528 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6530 sas_device_put(sas_device);
6534 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6535 * @ioc: per adapter object
6536 * @element: IR config element data
6542 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6543 Mpi2EventIrConfigElement_t *element)
6545 struct _sas_device *sas_device;
6546 struct scsi_target *starget = NULL;
6547 struct MPT3SAS_TARGET *sas_target_priv_data;
6548 unsigned long flags;
6549 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6550 u16 volume_handle = 0;
6551 u64 volume_wwid = 0;
6553 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6555 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6558 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6559 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6561 set_bit(handle, ioc->pd_handles);
6562 if (sas_device->starget && sas_device->starget->hostdata) {
6563 starget = sas_device->starget;
6564 sas_target_priv_data = starget->hostdata;
6565 sas_target_priv_data->flags |=
6566 MPT_TARGET_FLAGS_RAID_COMPONENT;
6567 sas_device->volume_handle = volume_handle;
6568 sas_device->volume_wwid = volume_wwid;
6571 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6575 /* hiding raid component */
6576 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6579 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6581 sas_device_put(sas_device);
6585 * _scsih_sas_pd_delete - delete pd component
6586 * @ioc: per adapter object
6587 * @element: IR config element data
6593 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6594 Mpi2EventIrConfigElement_t *element)
6596 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6598 _scsih_device_remove_by_handle(ioc, handle);
6602 * _scsih_sas_pd_add - remove pd component
6603 * @ioc: per adapter object
6604 * @element: IR config element data
6610 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6611 Mpi2EventIrConfigElement_t *element)
6613 struct _sas_device *sas_device;
6614 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6615 Mpi2ConfigReply_t mpi_reply;
6616 Mpi2SasDevicePage0_t sas_device_pg0;
6621 set_bit(handle, ioc->pd_handles);
6623 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6625 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6626 sas_device_put(sas_device);
6630 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6631 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6632 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6633 ioc->name, __FILE__, __LINE__, __func__);
6637 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6638 MPI2_IOCSTATUS_MASK;
6639 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6640 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6641 ioc->name, __FILE__, __LINE__, __func__);
6645 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6646 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6647 mpt3sas_transport_update_links(ioc, sas_address, handle,
6648 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6650 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6651 _scsih_add_device(ioc, handle, 0, 1);
6655 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6656 * @ioc: per adapter object
6657 * @event_data: event data payload
6663 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6664 Mpi2EventDataIrConfigChangeList_t *event_data)
6666 Mpi2EventIrConfigElement_t *element;
6669 char *reason_str = NULL, *element_str = NULL;
6671 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6673 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6674 ioc->name, (le32_to_cpu(event_data->Flags) &
6675 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6676 "foreign" : "native", event_data->NumElements);
6677 for (i = 0; i < event_data->NumElements; i++, element++) {
6678 switch (element->ReasonCode) {
6679 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6682 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6683 reason_str = "remove";
6685 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6686 reason_str = "no change";
6688 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6689 reason_str = "hide";
6691 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6692 reason_str = "unhide";
6694 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6695 reason_str = "volume_created";
6697 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6698 reason_str = "volume_deleted";
6700 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6701 reason_str = "pd_created";
6703 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6704 reason_str = "pd_deleted";
6707 reason_str = "unknown reason";
6710 element_type = le16_to_cpu(element->ElementFlags) &
6711 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6712 switch (element_type) {
6713 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6714 element_str = "volume";
6716 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6717 element_str = "phys disk";
6719 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6720 element_str = "hot spare";
6723 element_str = "unknown element";
6726 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6727 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6728 reason_str, le16_to_cpu(element->VolDevHandle),
6729 le16_to_cpu(element->PhysDiskDevHandle),
6730 element->PhysDiskNum);
6735 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6736 * @ioc: per adapter object
6737 * @fw_event: The fw_event_work object
6743 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6744 struct fw_event_work *fw_event)
6746 Mpi2EventIrConfigElement_t *element;
6749 Mpi2EventDataIrConfigChangeList_t *event_data =
6750 (Mpi2EventDataIrConfigChangeList_t *)
6751 fw_event->event_data;
6753 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6754 (!ioc->hide_ir_msg))
6755 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6757 foreign_config = (le32_to_cpu(event_data->Flags) &
6758 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6760 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6761 if (ioc->shost_recovery &&
6762 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6763 for (i = 0; i < event_data->NumElements; i++, element++) {
6764 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6765 _scsih_ir_fastpath(ioc,
6766 le16_to_cpu(element->PhysDiskDevHandle),
6767 element->PhysDiskNum);
6772 for (i = 0; i < event_data->NumElements; i++, element++) {
6774 switch (element->ReasonCode) {
6775 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6776 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6777 if (!foreign_config)
6778 _scsih_sas_volume_add(ioc, element);
6780 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6781 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6782 if (!foreign_config)
6783 _scsih_sas_volume_delete(ioc,
6784 le16_to_cpu(element->VolDevHandle));
6786 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6787 if (!ioc->is_warpdrive)
6788 _scsih_sas_pd_hide(ioc, element);
6790 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6791 if (!ioc->is_warpdrive)
6792 _scsih_sas_pd_expose(ioc, element);
6794 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6795 if (!ioc->is_warpdrive)
6796 _scsih_sas_pd_add(ioc, element);
6798 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6799 if (!ioc->is_warpdrive)
6800 _scsih_sas_pd_delete(ioc, element);
6807 * _scsih_sas_ir_volume_event - IR volume event
6808 * @ioc: per adapter object
6809 * @fw_event: The fw_event_work object
6815 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6816 struct fw_event_work *fw_event)
6819 unsigned long flags;
6820 struct _raid_device *raid_device;
6824 Mpi2EventDataIrVolume_t *event_data =
6825 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6827 if (ioc->shost_recovery)
6830 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6833 handle = le16_to_cpu(event_data->VolDevHandle);
6834 state = le32_to_cpu(event_data->NewValue);
6835 if (!ioc->hide_ir_msg)
6836 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6837 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6838 ioc->name, __func__, handle,
6839 le32_to_cpu(event_data->PreviousValue), state));
6841 case MPI2_RAID_VOL_STATE_MISSING:
6842 case MPI2_RAID_VOL_STATE_FAILED:
6843 _scsih_sas_volume_delete(ioc, handle);
6846 case MPI2_RAID_VOL_STATE_ONLINE:
6847 case MPI2_RAID_VOL_STATE_DEGRADED:
6848 case MPI2_RAID_VOL_STATE_OPTIMAL:
6850 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6851 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6852 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6857 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6860 "failure at %s:%d/%s()!\n", ioc->name,
6861 __FILE__, __LINE__, __func__);
6865 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6868 "failure at %s:%d/%s()!\n", ioc->name,
6869 __FILE__, __LINE__, __func__);
6873 raid_device->id = ioc->sas_id++;
6874 raid_device->channel = RAID_CHANNEL;
6875 raid_device->handle = handle;
6876 raid_device->wwid = wwid;
6877 _scsih_raid_device_add(ioc, raid_device);
6878 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6879 raid_device->id, 0);
6881 _scsih_raid_device_remove(ioc, raid_device);
6884 case MPI2_RAID_VOL_STATE_INITIALIZING:
6891 * _scsih_sas_ir_physical_disk_event - PD event
6892 * @ioc: per adapter object
6893 * @fw_event: The fw_event_work object
6899 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6900 struct fw_event_work *fw_event)
6902 u16 handle, parent_handle;
6904 struct _sas_device *sas_device;
6905 Mpi2ConfigReply_t mpi_reply;
6906 Mpi2SasDevicePage0_t sas_device_pg0;
6908 Mpi2EventDataIrPhysicalDisk_t *event_data =
6909 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6912 if (ioc->shost_recovery)
6915 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6918 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6919 state = le32_to_cpu(event_data->NewValue);
6921 if (!ioc->hide_ir_msg)
6922 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6923 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6924 ioc->name, __func__, handle,
6925 le32_to_cpu(event_data->PreviousValue), state));
6928 case MPI2_RAID_PD_STATE_ONLINE:
6929 case MPI2_RAID_PD_STATE_DEGRADED:
6930 case MPI2_RAID_PD_STATE_REBUILDING:
6931 case MPI2_RAID_PD_STATE_OPTIMAL:
6932 case MPI2_RAID_PD_STATE_HOT_SPARE:
6934 if (!ioc->is_warpdrive)
6935 set_bit(handle, ioc->pd_handles);
6937 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6939 sas_device_put(sas_device);
6943 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6944 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6946 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6947 ioc->name, __FILE__, __LINE__, __func__);
6951 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6952 MPI2_IOCSTATUS_MASK;
6953 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6954 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6955 ioc->name, __FILE__, __LINE__, __func__);
6959 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6960 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6961 mpt3sas_transport_update_links(ioc, sas_address, handle,
6962 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6964 _scsih_add_device(ioc, handle, 0, 1);
6968 case MPI2_RAID_PD_STATE_OFFLINE:
6969 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6970 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6977 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6978 * @ioc: per adapter object
6979 * @event_data: event data payload
6985 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6986 Mpi2EventDataIrOperationStatus_t *event_data)
6988 char *reason_str = NULL;
6990 switch (event_data->RAIDOperation) {
6991 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6992 reason_str = "resync";
6994 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6995 reason_str = "online capacity expansion";
6997 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6998 reason_str = "consistency check";
7000 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
7001 reason_str = "background init";
7003 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
7004 reason_str = "make data consistent";
7011 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
7012 "\thandle(0x%04x), percent complete(%d)\n",
7013 ioc->name, reason_str,
7014 le16_to_cpu(event_data->VolDevHandle),
7015 event_data->PercentComplete);
7019 * _scsih_sas_ir_operation_status_event - handle RAID operation events
7020 * @ioc: per adapter object
7021 * @fw_event: The fw_event_work object
7027 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
7028 struct fw_event_work *fw_event)
7030 Mpi2EventDataIrOperationStatus_t *event_data =
7031 (Mpi2EventDataIrOperationStatus_t *)
7032 fw_event->event_data;
7033 static struct _raid_device *raid_device;
7034 unsigned long flags;
7037 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
7038 (!ioc->hide_ir_msg))
7039 _scsih_sas_ir_operation_status_event_debug(ioc,
7042 /* code added for raid transport support */
7043 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
7045 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7046 handle = le16_to_cpu(event_data->VolDevHandle);
7047 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
7049 raid_device->percent_complete =
7050 event_data->PercentComplete;
7051 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7056 * _scsih_prep_device_scan - initialize parameters prior to device scan
7057 * @ioc: per adapter object
7059 * Set the deleted flag prior to device scan. If the device is found during
7060 * the scan, then we clear the deleted flag.
7063 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
7065 struct MPT3SAS_DEVICE *sas_device_priv_data;
7066 struct scsi_device *sdev;
7068 shost_for_each_device(sdev, ioc->shost) {
7069 sas_device_priv_data = sdev->hostdata;
7070 if (sas_device_priv_data && sas_device_priv_data->sas_target)
7071 sas_device_priv_data->sas_target->deleted = 1;
7076 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
7077 * @ioc: per adapter object
7078 * @sas_device_pg0: SAS Device page 0
7080 * After host reset, find out whether devices are still responding.
7081 * Used in _scsih_remove_unresponsive_sas_devices.
7086 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
7087 Mpi2SasDevicePage0_t *sas_device_pg0)
7089 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7090 struct scsi_target *starget;
7091 struct _sas_device *sas_device;
7092 unsigned long flags;
7094 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7095 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
7096 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
7097 (sas_device->slot == sas_device_pg0->Slot)) {
7098 sas_device->responding = 1;
7099 starget = sas_device->starget;
7100 if (starget && starget->hostdata) {
7101 sas_target_priv_data = starget->hostdata;
7102 sas_target_priv_data->tm_busy = 0;
7103 sas_target_priv_data->deleted = 0;
7105 sas_target_priv_data = NULL;
7107 starget_printk(KERN_INFO, starget,
7108 "handle(0x%04x), sas_addr(0x%016llx)\n",
7109 sas_device_pg0->DevHandle,
7110 (unsigned long long)
7111 sas_device->sas_address);
7113 if (sas_device->enclosure_handle != 0)
7114 starget_printk(KERN_INFO, starget,
7115 "enclosure logical id(0x%016llx),"
7117 (unsigned long long)
7118 sas_device->enclosure_logical_id,
7121 if (sas_device_pg0->Flags &
7122 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
7123 sas_device->enclosure_level =
7124 le16_to_cpu(sas_device_pg0->EnclosureLevel);
7125 memcpy(&sas_device->connector_name[0],
7126 &sas_device_pg0->ConnectorName[0], 4);
7128 sas_device->enclosure_level = 0;
7129 sas_device->connector_name[0] = '\0';
7132 if (sas_device->handle == sas_device_pg0->DevHandle)
7134 pr_info("\thandle changed from(0x%04x)!!!\n",
7135 sas_device->handle);
7136 sas_device->handle = sas_device_pg0->DevHandle;
7137 if (sas_target_priv_data)
7138 sas_target_priv_data->handle =
7139 sas_device_pg0->DevHandle;
7144 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7148 * _scsih_search_responding_sas_devices -
7149 * @ioc: per adapter object
7151 * After host reset, find out whether devices are still responding.
7157 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7159 Mpi2SasDevicePage0_t sas_device_pg0;
7160 Mpi2ConfigReply_t mpi_reply;
7165 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
7167 if (list_empty(&ioc->sas_device_list))
7171 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7172 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7174 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7175 MPI2_IOCSTATUS_MASK;
7176 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7178 handle = sas_device_pg0.DevHandle =
7179 le16_to_cpu(sas_device_pg0.DevHandle);
7180 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
7181 if (!(_scsih_is_end_device(device_info)))
7183 sas_device_pg0.SASAddress =
7184 le64_to_cpu(sas_device_pg0.SASAddress);
7185 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
7186 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
7190 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
7195 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7196 * @ioc: per adapter object
7197 * @wwid: world wide identifier for raid volume
7198 * @handle: device handle
7200 * After host reset, find out whether devices are still responding.
7201 * Used in _scsih_remove_unresponsive_raid_devices.
7206 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
7209 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7210 struct scsi_target *starget;
7211 struct _raid_device *raid_device;
7212 unsigned long flags;
7214 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7215 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
7216 if (raid_device->wwid == wwid && raid_device->starget) {
7217 starget = raid_device->starget;
7218 if (starget && starget->hostdata) {
7219 sas_target_priv_data = starget->hostdata;
7220 sas_target_priv_data->deleted = 0;
7222 sas_target_priv_data = NULL;
7223 raid_device->responding = 1;
7224 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7225 starget_printk(KERN_INFO, raid_device->starget,
7226 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7227 (unsigned long long)raid_device->wwid);
7230 * WARPDRIVE: The handles of the PDs might have changed
7231 * across the host reset so re-initialize the
7232 * required data for Direct IO
7234 mpt3sas_init_warpdrive_properties(ioc, raid_device);
7235 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7236 if (raid_device->handle == handle) {
7237 spin_unlock_irqrestore(&ioc->raid_device_lock,
7241 pr_info("\thandle changed from(0x%04x)!!!\n",
7242 raid_device->handle);
7243 raid_device->handle = handle;
7244 if (sas_target_priv_data)
7245 sas_target_priv_data->handle = handle;
7246 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7250 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7254 * _scsih_search_responding_raid_devices -
7255 * @ioc: per adapter object
7257 * After host reset, find out whether devices are still responding.
7263 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
7265 Mpi2RaidVolPage1_t volume_pg1;
7266 Mpi2RaidVolPage0_t volume_pg0;
7267 Mpi2RaidPhysDiskPage0_t pd_pg0;
7268 Mpi2ConfigReply_t mpi_reply;
7273 if (!ioc->ir_firmware)
7276 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7279 if (list_empty(&ioc->raid_device_list))
7283 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7284 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7285 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7286 MPI2_IOCSTATUS_MASK;
7287 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7289 handle = le16_to_cpu(volume_pg1.DevHandle);
7291 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7292 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7293 sizeof(Mpi2RaidVolPage0_t)))
7296 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7297 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7298 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7299 _scsih_mark_responding_raid_device(ioc,
7300 le64_to_cpu(volume_pg1.WWID), handle);
7303 /* refresh the pd_handles */
7304 if (!ioc->is_warpdrive) {
7305 phys_disk_num = 0xFF;
7306 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7307 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7308 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7310 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7311 MPI2_IOCSTATUS_MASK;
7312 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7314 phys_disk_num = pd_pg0.PhysDiskNum;
7315 handle = le16_to_cpu(pd_pg0.DevHandle);
7316 set_bit(handle, ioc->pd_handles);
7320 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7325 * _scsih_mark_responding_expander - mark a expander as responding
7326 * @ioc: per adapter object
7327 * @sas_address: sas address
7330 * After host reset, find out whether devices are still responding.
7331 * Used in _scsih_remove_unresponsive_expanders.
7336 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7339 struct _sas_node *sas_expander;
7340 unsigned long flags;
7343 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7344 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7345 if (sas_expander->sas_address != sas_address)
7347 sas_expander->responding = 1;
7348 if (sas_expander->handle == handle)
7350 pr_info("\texpander(0x%016llx): handle changed" \
7351 " from(0x%04x) to (0x%04x)!!!\n",
7352 (unsigned long long)sas_expander->sas_address,
7353 sas_expander->handle, handle);
7354 sas_expander->handle = handle;
7355 for (i = 0 ; i < sas_expander->num_phys ; i++)
7356 sas_expander->phy[i].handle = handle;
7360 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7364 * _scsih_search_responding_expanders -
7365 * @ioc: per adapter object
7367 * After host reset, find out whether devices are still responding.
7373 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7375 Mpi2ExpanderPage0_t expander_pg0;
7376 Mpi2ConfigReply_t mpi_reply;
7381 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7383 if (list_empty(&ioc->sas_expander_list))
7387 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7388 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7390 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7391 MPI2_IOCSTATUS_MASK;
7392 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7395 handle = le16_to_cpu(expander_pg0.DevHandle);
7396 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7397 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7399 (unsigned long long)sas_address);
7400 _scsih_mark_responding_expander(ioc, sas_address, handle);
7404 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7408 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7409 * @ioc: per adapter object
7414 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7416 struct _sas_device *sas_device, *sas_device_next;
7417 struct _sas_node *sas_expander, *sas_expander_next;
7418 struct _raid_device *raid_device, *raid_device_next;
7419 struct list_head tmp_list;
7420 unsigned long flags;
7423 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7426 /* removing unresponding end devices */
7427 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7430 * Iterate, pulling off devices marked as non-responding. We become the
7431 * owner for the reference the list had on any object we prune.
7433 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7434 list_for_each_entry_safe(sas_device, sas_device_next,
7435 &ioc->sas_device_list, list) {
7436 if (!sas_device->responding)
7437 list_move_tail(&sas_device->list, &head);
7439 sas_device->responding = 0;
7441 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7444 * Now, uninitialize and remove the unresponding devices we pruned.
7446 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7447 _scsih_remove_device(ioc, sas_device);
7448 list_del_init(&sas_device->list);
7449 sas_device_put(sas_device);
7452 /* removing unresponding volumes */
7453 if (ioc->ir_firmware) {
7454 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7456 list_for_each_entry_safe(raid_device, raid_device_next,
7457 &ioc->raid_device_list, list) {
7458 if (!raid_device->responding)
7459 _scsih_sas_volume_delete(ioc,
7460 raid_device->handle);
7462 raid_device->responding = 0;
7466 /* removing unresponding expanders */
7467 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7469 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7470 INIT_LIST_HEAD(&tmp_list);
7471 list_for_each_entry_safe(sas_expander, sas_expander_next,
7472 &ioc->sas_expander_list, list) {
7473 if (!sas_expander->responding)
7474 list_move_tail(&sas_expander->list, &tmp_list);
7476 sas_expander->responding = 0;
7478 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7479 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7481 list_del(&sas_expander->list);
7482 _scsih_expander_node_remove(ioc, sas_expander);
7485 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7488 /* unblock devices */
7489 _scsih_ublock_io_all_device(ioc);
7493 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7494 struct _sas_node *sas_expander, u16 handle)
7496 Mpi2ExpanderPage1_t expander_pg1;
7497 Mpi2ConfigReply_t mpi_reply;
7500 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7501 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7502 &expander_pg1, i, handle))) {
7503 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7504 ioc->name, __FILE__, __LINE__, __func__);
7508 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7509 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7510 expander_pg1.NegotiatedLinkRate >> 4);
7515 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7516 * @ioc: per adapter object
7521 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7523 Mpi2ExpanderPage0_t expander_pg0;
7524 Mpi2SasDevicePage0_t sas_device_pg0;
7525 Mpi2RaidVolPage1_t volume_pg1;
7526 Mpi2RaidVolPage0_t volume_pg0;
7527 Mpi2RaidPhysDiskPage0_t pd_pg0;
7528 Mpi2EventIrConfigElement_t element;
7529 Mpi2ConfigReply_t mpi_reply;
7532 u16 handle, parent_handle;
7534 struct _sas_device *sas_device;
7535 struct _sas_node *expander_device;
7536 static struct _raid_device *raid_device;
7538 unsigned long flags;
7540 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7542 _scsih_sas_host_refresh(ioc);
7544 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7548 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7549 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7550 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7551 MPI2_IOCSTATUS_MASK;
7552 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7553 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7554 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7555 ioc->name, ioc_status,
7556 le32_to_cpu(mpi_reply.IOCLogInfo));
7559 handle = le16_to_cpu(expander_pg0.DevHandle);
7560 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7561 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7562 ioc, le64_to_cpu(expander_pg0.SASAddress));
7563 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7564 if (expander_device)
7565 _scsih_refresh_expander_links(ioc, expander_device,
7568 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7569 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7570 handle, (unsigned long long)
7571 le64_to_cpu(expander_pg0.SASAddress));
7572 _scsih_expander_add(ioc, handle);
7573 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7574 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7575 handle, (unsigned long long)
7576 le64_to_cpu(expander_pg0.SASAddress));
7580 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7583 if (!ioc->ir_firmware)
7586 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7589 phys_disk_num = 0xFF;
7590 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7591 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7593 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7594 MPI2_IOCSTATUS_MASK;
7595 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7596 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7597 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7598 ioc->name, ioc_status,
7599 le32_to_cpu(mpi_reply.IOCLogInfo));
7602 phys_disk_num = pd_pg0.PhysDiskNum;
7603 handle = le16_to_cpu(pd_pg0.DevHandle);
7604 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7606 sas_device_put(sas_device);
7609 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7610 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7613 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7614 MPI2_IOCSTATUS_MASK;
7615 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7616 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7617 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7618 ioc->name, ioc_status,
7619 le32_to_cpu(mpi_reply.IOCLogInfo));
7622 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7623 if (!_scsih_get_sas_address(ioc, parent_handle,
7625 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7626 " handle (0x%04x), sas_addr(0x%016llx)\n",
7627 ioc->name, handle, (unsigned long long)
7628 le64_to_cpu(sas_device_pg0.SASAddress));
7629 mpt3sas_transport_update_links(ioc, sas_address,
7630 handle, sas_device_pg0.PhyNum,
7631 MPI2_SAS_NEG_LINK_RATE_1_5);
7632 set_bit(handle, ioc->pd_handles);
7634 /* This will retry adding the end device.
7635 * _scsih_add_device() will decide on retries and
7636 * return "1" when it should be retried
7638 while (_scsih_add_device(ioc, handle, retry_count++,
7642 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7643 " handle (0x%04x), sas_addr(0x%016llx)\n",
7644 ioc->name, handle, (unsigned long long)
7645 le64_to_cpu(sas_device_pg0.SASAddress));
7649 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7652 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7656 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7657 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7658 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7659 MPI2_IOCSTATUS_MASK;
7660 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7661 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7662 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7663 ioc->name, ioc_status,
7664 le32_to_cpu(mpi_reply.IOCLogInfo));
7667 handle = le16_to_cpu(volume_pg1.DevHandle);
7668 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7669 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7670 le64_to_cpu(volume_pg1.WWID));
7671 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7674 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7675 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7676 sizeof(Mpi2RaidVolPage0_t)))
7678 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7679 MPI2_IOCSTATUS_MASK;
7680 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7681 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7682 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7683 ioc->name, ioc_status,
7684 le32_to_cpu(mpi_reply.IOCLogInfo));
7687 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7688 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7689 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7690 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7691 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7692 element.VolDevHandle = volume_pg1.DevHandle;
7694 "\tBEFORE adding volume: handle (0x%04x)\n",
7695 ioc->name, volume_pg1.DevHandle);
7696 _scsih_sas_volume_add(ioc, &element);
7698 "\tAFTER adding volume: handle (0x%04x)\n",
7699 ioc->name, volume_pg1.DevHandle);
7703 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7708 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7713 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7714 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7716 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7717 MPI2_IOCSTATUS_MASK;
7718 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7719 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7720 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7721 ioc->name, ioc_status,
7722 le32_to_cpu(mpi_reply.IOCLogInfo));
7725 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7726 if (!(_scsih_is_end_device(
7727 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7729 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7730 le64_to_cpu(sas_device_pg0.SASAddress));
7732 sas_device_put(sas_device);
7735 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7736 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7737 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7738 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7739 handle, (unsigned long long)
7740 le64_to_cpu(sas_device_pg0.SASAddress));
7741 mpt3sas_transport_update_links(ioc, sas_address, handle,
7742 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7744 /* This will retry adding the end device.
7745 * _scsih_add_device() will decide on retries and
7746 * return "1" when it should be retried
7748 while (_scsih_add_device(ioc, handle, retry_count++,
7752 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7753 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7754 handle, (unsigned long long)
7755 le64_to_cpu(sas_device_pg0.SASAddress));
7758 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7761 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7764 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7765 * @ioc: per adapter object
7766 * @reset_phase: phase
7768 * The handler for doing any required cleanup or initialization.
7770 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7771 * MPT3_IOC_DONE_RESET
7776 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7778 switch (reset_phase) {
7779 case MPT3_IOC_PRE_RESET:
7780 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7781 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7783 case MPT3_IOC_AFTER_RESET:
7784 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7785 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7786 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7787 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7788 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7789 complete(&ioc->scsih_cmds.done);
7791 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7792 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7793 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7794 complete(&ioc->tm_cmds.done);
7797 _scsih_fw_event_cleanup_queue(ioc);
7798 _scsih_flush_running_cmds(ioc);
7800 case MPT3_IOC_DONE_RESET:
7801 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7802 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7803 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7804 !ioc->sas_hba.num_phys)) {
7805 _scsih_prep_device_scan(ioc);
7806 _scsih_search_responding_sas_devices(ioc);
7807 _scsih_search_responding_raid_devices(ioc);
7808 _scsih_search_responding_expanders(ioc);
7809 _scsih_error_recovery_delete_devices(ioc);
7816 * _mpt3sas_fw_work - delayed task for processing firmware events
7817 * @ioc: per adapter object
7818 * @fw_event: The fw_event_work object
7824 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7826 _scsih_fw_event_del_from_list(ioc, fw_event);
7828 /* the queue is being flushed so ignore this event */
7829 if (ioc->remove_host || ioc->pci_error_recovery) {
7830 fw_event_work_put(fw_event);
7834 switch (fw_event->event) {
7835 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7836 mpt3sas_process_trigger_data(ioc,
7837 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7838 fw_event->event_data);
7840 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7841 while (scsi_host_in_recovery(ioc->shost) ||
7842 ioc->shost_recovery) {
7844 * If we're unloading, bail. Otherwise, this can become
7847 if (ioc->remove_host)
7851 _scsih_remove_unresponding_sas_devices(ioc);
7852 _scsih_scan_for_devices_after_reset(ioc);
7854 case MPT3SAS_PORT_ENABLE_COMPLETE:
7855 ioc->start_scan = 0;
7856 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7857 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7859 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7860 "port enable: complete from worker thread\n",
7863 case MPT3SAS_TURN_ON_PFA_LED:
7864 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7866 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7867 _scsih_sas_topology_change_event(ioc, fw_event);
7869 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7870 _scsih_sas_device_status_change_event(ioc, fw_event);
7872 case MPI2_EVENT_SAS_DISCOVERY:
7873 _scsih_sas_discovery_event(ioc, fw_event);
7875 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7876 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7878 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7879 _scsih_sas_enclosure_dev_status_change_event(ioc,
7882 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7883 _scsih_sas_ir_config_change_event(ioc, fw_event);
7885 case MPI2_EVENT_IR_VOLUME:
7886 _scsih_sas_ir_volume_event(ioc, fw_event);
7888 case MPI2_EVENT_IR_PHYSICAL_DISK:
7889 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7891 case MPI2_EVENT_IR_OPERATION_STATUS:
7892 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7896 fw_event_work_put(fw_event);
7900 * _firmware_event_work
7901 * @ioc: per adapter object
7902 * @work: The fw_event_work object
7905 * wrappers for the work thread handling firmware events
7911 _firmware_event_work(struct work_struct *work)
7913 struct fw_event_work *fw_event = container_of(work,
7914 struct fw_event_work, work);
7916 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7920 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7921 * @ioc: per adapter object
7922 * @msix_index: MSIX table index supplied by the OS
7923 * @reply: reply message frame(lower 32bit addr)
7924 * Context: interrupt.
7926 * This function merely adds a new work task into ioc->firmware_event_thread.
7927 * The tasks are worked from _firmware_event_work in user context.
7929 * Return 1 meaning mf should be freed from _base_interrupt
7930 * 0 means the mf is freed from this function.
7933 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7936 struct fw_event_work *fw_event;
7937 Mpi2EventNotificationReply_t *mpi_reply;
7940 Mpi26EventDataActiveCableExcept_t *ActiveCableEventData;
7942 /* events turned off due to host reset or driver unloading */
7943 if (ioc->remove_host || ioc->pci_error_recovery)
7946 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7948 if (unlikely(!mpi_reply)) {
7949 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7950 ioc->name, __FILE__, __LINE__, __func__);
7954 event = le16_to_cpu(mpi_reply->Event);
7956 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7957 mpt3sas_trigger_event(ioc, event, 0);
7961 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7963 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7964 (Mpi2EventDataSasBroadcastPrimitive_t *)
7965 mpi_reply->EventData;
7967 if (baen_data->Primitive !=
7968 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7971 if (ioc->broadcast_aen_busy) {
7972 ioc->broadcast_aen_pending++;
7975 ioc->broadcast_aen_busy = 1;
7979 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7980 _scsih_check_topo_delete_events(ioc,
7981 (Mpi2EventDataSasTopologyChangeList_t *)
7982 mpi_reply->EventData);
7984 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7985 _scsih_check_ir_config_unhide_events(ioc,
7986 (Mpi2EventDataIrConfigChangeList_t *)
7987 mpi_reply->EventData);
7989 case MPI2_EVENT_IR_VOLUME:
7990 _scsih_check_volume_delete_events(ioc,
7991 (Mpi2EventDataIrVolume_t *)
7992 mpi_reply->EventData);
7994 case MPI2_EVENT_LOG_ENTRY_ADDED:
7996 Mpi2EventDataLogEntryAdded_t *log_entry;
7999 if (!ioc->is_warpdrive)
8002 log_entry = (Mpi2EventDataLogEntryAdded_t *)
8003 mpi_reply->EventData;
8004 log_code = (u32 *)log_entry->LogData;
8006 if (le16_to_cpu(log_entry->LogEntryQualifier)
8007 != MPT2_WARPDRIVE_LOGENTRY)
8010 switch (le32_to_cpu(*log_code)) {
8011 case MPT2_WARPDRIVE_LC_SSDT:
8012 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
8013 "IO Throttling has occurred in the WarpDrive "
8014 "subsystem. Check WarpDrive documentation for "
8015 "additional details.\n", ioc->name);
8017 case MPT2_WARPDRIVE_LC_SSDLW:
8018 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
8019 "Program/Erase Cycles for the WarpDrive subsystem "
8020 "in degraded range. Check WarpDrive documentation "
8021 "for additional details.\n", ioc->name);
8023 case MPT2_WARPDRIVE_LC_SSDLF:
8024 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
8025 "There are no Program/Erase Cycles for the "
8026 "WarpDrive subsystem. The storage device will be "
8027 "in read-only mode. Check WarpDrive documentation "
8028 "for additional details.\n", ioc->name);
8030 case MPT2_WARPDRIVE_LC_BRMF:
8031 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
8032 "The Backup Rail Monitor has failed on the "
8033 "WarpDrive subsystem. Check WarpDrive "
8034 "documentation for additional details.\n",
8041 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
8042 case MPI2_EVENT_IR_OPERATION_STATUS:
8043 case MPI2_EVENT_SAS_DISCOVERY:
8044 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
8045 case MPI2_EVENT_IR_PHYSICAL_DISK:
8048 case MPI2_EVENT_TEMP_THRESHOLD:
8049 _scsih_temp_threshold_events(ioc,
8050 (Mpi2EventDataTemperature_t *)
8051 mpi_reply->EventData);
8053 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION:
8054 ActiveCableEventData =
8055 (Mpi26EventDataActiveCableExcept_t *) mpi_reply->EventData;
8056 if (ActiveCableEventData->ReasonCode ==
8057 MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER) {
8058 pr_info(MPT3SAS_FMT "Currently an active cable with ReceptacleID %d",
8059 ioc->name, ActiveCableEventData->ReceptacleID);
8060 pr_info("cannot be powered and devices connected to this active cable");
8061 pr_info("will not be seen. This active cable");
8062 pr_info("requires %d mW of power",
8063 ActiveCableEventData->ActiveCablePowerRequirement);
8067 default: /* ignore the rest */
8071 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
8072 fw_event = alloc_fw_event_work(sz);
8074 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8075 ioc->name, __FILE__, __LINE__, __func__);
8079 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
8080 fw_event->ioc = ioc;
8081 fw_event->VF_ID = mpi_reply->VF_ID;
8082 fw_event->VP_ID = mpi_reply->VP_ID;
8083 fw_event->event = event;
8084 _scsih_fw_event_add(ioc, fw_event);
8085 fw_event_work_put(fw_event);
8090 * _scsih_expander_node_remove - removing expander device from list.
8091 * @ioc: per adapter object
8092 * @sas_expander: the sas_device object
8093 * Context: Calling function should acquire ioc->sas_node_lock.
8095 * Removing object and freeing associated memory from the
8096 * ioc->sas_expander_list.
8101 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
8102 struct _sas_node *sas_expander)
8104 struct _sas_port *mpt3sas_port, *next;
8106 /* remove sibling ports attached to this expander */
8107 list_for_each_entry_safe(mpt3sas_port, next,
8108 &sas_expander->sas_port_list, port_list) {
8109 if (ioc->shost_recovery)
8111 if (mpt3sas_port->remote_identify.device_type ==
8113 mpt3sas_device_remove_by_sas_address(ioc,
8114 mpt3sas_port->remote_identify.sas_address);
8115 else if (mpt3sas_port->remote_identify.device_type ==
8116 SAS_EDGE_EXPANDER_DEVICE ||
8117 mpt3sas_port->remote_identify.device_type ==
8118 SAS_FANOUT_EXPANDER_DEVICE)
8119 mpt3sas_expander_remove(ioc,
8120 mpt3sas_port->remote_identify.sas_address);
8123 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
8124 sas_expander->sas_address_parent);
8127 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8129 sas_expander->handle, (unsigned long long)
8130 sas_expander->sas_address);
8132 kfree(sas_expander->phy);
8133 kfree(sas_expander);
8137 * _scsih_ir_shutdown - IR shutdown notification
8138 * @ioc: per adapter object
8140 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8141 * the host system is shutting down.
8146 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
8148 Mpi2RaidActionRequest_t *mpi_request;
8149 Mpi2RaidActionReply_t *mpi_reply;
8152 /* is IR firmware build loaded ? */
8153 if (!ioc->ir_firmware)
8156 /* are there any volumes ? */
8157 if (list_empty(&ioc->raid_device_list))
8160 mutex_lock(&ioc->scsih_cmds.mutex);
8162 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
8163 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
8164 ioc->name, __func__);
8167 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
8169 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
8171 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
8172 ioc->name, __func__);
8173 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8177 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
8178 ioc->scsih_cmds.smid = smid;
8179 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
8181 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
8182 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
8184 if (!ioc->hide_ir_msg)
8185 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
8186 init_completion(&ioc->scsih_cmds.done);
8187 mpt3sas_base_put_smid_default(ioc, smid);
8188 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
8190 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
8191 pr_err(MPT3SAS_FMT "%s: timeout\n",
8192 ioc->name, __func__);
8196 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
8197 mpi_reply = ioc->scsih_cmds.reply;
8198 if (!ioc->hide_ir_msg)
8199 pr_info(MPT3SAS_FMT "IR shutdown "
8200 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8201 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
8202 le32_to_cpu(mpi_reply->IOCLogInfo));
8206 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8207 mutex_unlock(&ioc->scsih_cmds.mutex);
8211 * scsih_remove - detach and remove add host
8212 * @pdev: PCI device struct
8214 * Routine called when unloading the driver.
8217 static void scsih_remove(struct pci_dev *pdev)
8219 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8220 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8221 struct _sas_port *mpt3sas_port, *next_port;
8222 struct _raid_device *raid_device, *next;
8223 struct MPT3SAS_TARGET *sas_target_priv_data;
8224 struct workqueue_struct *wq;
8225 unsigned long flags;
8227 ioc->remove_host = 1;
8228 _scsih_fw_event_cleanup_queue(ioc);
8230 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8231 wq = ioc->firmware_event_thread;
8232 ioc->firmware_event_thread = NULL;
8233 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8235 destroy_workqueue(wq);
8237 /* release all the volumes */
8238 _scsih_ir_shutdown(ioc);
8239 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8241 if (raid_device->starget) {
8242 sas_target_priv_data =
8243 raid_device->starget->hostdata;
8244 sas_target_priv_data->deleted = 1;
8245 scsi_remove_target(&raid_device->starget->dev);
8247 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
8248 ioc->name, raid_device->handle,
8249 (unsigned long long) raid_device->wwid);
8250 _scsih_raid_device_remove(ioc, raid_device);
8253 /* free ports attached to the sas_host */
8254 list_for_each_entry_safe(mpt3sas_port, next_port,
8255 &ioc->sas_hba.sas_port_list, port_list) {
8256 if (mpt3sas_port->remote_identify.device_type ==
8258 mpt3sas_device_remove_by_sas_address(ioc,
8259 mpt3sas_port->remote_identify.sas_address);
8260 else if (mpt3sas_port->remote_identify.device_type ==
8261 SAS_EDGE_EXPANDER_DEVICE ||
8262 mpt3sas_port->remote_identify.device_type ==
8263 SAS_FANOUT_EXPANDER_DEVICE)
8264 mpt3sas_expander_remove(ioc,
8265 mpt3sas_port->remote_identify.sas_address);
8268 /* free phys attached to the sas_host */
8269 if (ioc->sas_hba.num_phys) {
8270 kfree(ioc->sas_hba.phy);
8271 ioc->sas_hba.phy = NULL;
8272 ioc->sas_hba.num_phys = 0;
8275 sas_remove_host(shost);
8276 scsi_remove_host(shost);
8277 mpt3sas_base_detach(ioc);
8278 spin_lock(&gioc_lock);
8279 list_del(&ioc->list);
8280 spin_unlock(&gioc_lock);
8281 scsi_host_put(shost);
8285 * scsih_shutdown - routine call during system shutdown
8286 * @pdev: PCI device struct
8291 scsih_shutdown(struct pci_dev *pdev)
8293 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8294 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8295 struct workqueue_struct *wq;
8296 unsigned long flags;
8298 ioc->remove_host = 1;
8299 _scsih_fw_event_cleanup_queue(ioc);
8301 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8302 wq = ioc->firmware_event_thread;
8303 ioc->firmware_event_thread = NULL;
8304 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8306 destroy_workqueue(wq);
8308 _scsih_ir_shutdown(ioc);
8309 mpt3sas_base_detach(ioc);
8314 * _scsih_probe_boot_devices - reports 1st device
8315 * @ioc: per adapter object
8317 * If specified in bios page 2, this routine reports the 1st
8318 * device scsi-ml or sas transport for persistent boot device
8319 * purposes. Please refer to function _scsih_determine_boot_device()
8322 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8326 struct _sas_device *sas_device;
8327 struct _raid_device *raid_device;
8329 u64 sas_address_parent;
8331 unsigned long flags;
8334 /* no Bios, return immediately */
8335 if (!ioc->bios_pg3.BiosVersion)
8340 if (ioc->req_boot_device.device) {
8341 device = ioc->req_boot_device.device;
8342 is_raid = ioc->req_boot_device.is_raid;
8343 } else if (ioc->req_alt_boot_device.device) {
8344 device = ioc->req_alt_boot_device.device;
8345 is_raid = ioc->req_alt_boot_device.is_raid;
8346 } else if (ioc->current_boot_device.device) {
8347 device = ioc->current_boot_device.device;
8348 is_raid = ioc->current_boot_device.is_raid;
8355 raid_device = device;
8356 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8357 raid_device->id, 0);
8359 _scsih_raid_device_remove(ioc, raid_device);
8361 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8362 sas_device = device;
8363 handle = sas_device->handle;
8364 sas_address_parent = sas_device->sas_address_parent;
8365 sas_address = sas_device->sas_address;
8366 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8367 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8369 if (ioc->hide_drives)
8371 if (!mpt3sas_transport_port_add(ioc, handle,
8372 sas_address_parent)) {
8373 _scsih_sas_device_remove(ioc, sas_device);
8374 } else if (!sas_device->starget) {
8375 if (!ioc->is_driver_loading) {
8376 mpt3sas_transport_port_remove(ioc,
8378 sas_address_parent);
8379 _scsih_sas_device_remove(ioc, sas_device);
8386 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8387 * @ioc: per adapter object
8389 * Called during initial loading of the driver.
8392 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8394 struct _raid_device *raid_device, *raid_next;
8397 list_for_each_entry_safe(raid_device, raid_next,
8398 &ioc->raid_device_list, list) {
8399 if (raid_device->starget)
8401 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8402 raid_device->id, 0);
8404 _scsih_raid_device_remove(ioc, raid_device);
8408 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8410 struct _sas_device *sas_device = NULL;
8411 unsigned long flags;
8413 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8414 if (!list_empty(&ioc->sas_device_init_list)) {
8415 sas_device = list_first_entry(&ioc->sas_device_init_list,
8416 struct _sas_device, list);
8417 sas_device_get(sas_device);
8419 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8424 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8425 struct _sas_device *sas_device)
8427 unsigned long flags;
8429 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8432 * Since we dropped the lock during the call to port_add(), we need to
8433 * be careful here that somebody else didn't move or delete this item
8434 * while we were busy with other things.
8436 * If it was on the list, we need a put() for the reference the list
8437 * had. Either way, we need a get() for the destination list.
8439 if (!list_empty(&sas_device->list)) {
8440 list_del_init(&sas_device->list);
8441 sas_device_put(sas_device);
8444 sas_device_get(sas_device);
8445 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8447 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8451 * _scsih_probe_sas - reporting sas devices to sas transport
8452 * @ioc: per adapter object
8454 * Called during initial loading of the driver.
8457 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8459 struct _sas_device *sas_device;
8461 if (ioc->hide_drives)
8464 while ((sas_device = get_next_sas_device(ioc))) {
8465 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8466 sas_device->sas_address_parent)) {
8467 _scsih_sas_device_remove(ioc, sas_device);
8468 sas_device_put(sas_device);
8470 } else if (!sas_device->starget) {
8472 * When asyn scanning is enabled, its not possible to
8473 * remove devices while scanning is turned on due to an
8474 * oops in scsi_sysfs_add_sdev()->add_device()->
8475 * sysfs_addrm_start()
8477 if (!ioc->is_driver_loading) {
8478 mpt3sas_transport_port_remove(ioc,
8479 sas_device->sas_address,
8480 sas_device->sas_address_parent);
8481 _scsih_sas_device_remove(ioc, sas_device);
8482 sas_device_put(sas_device);
8486 sas_device_make_active(ioc, sas_device);
8487 sas_device_put(sas_device);
8492 * _scsih_probe_devices - probing for devices
8493 * @ioc: per adapter object
8495 * Called during initial loading of the driver.
8498 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8500 u16 volume_mapping_flags;
8502 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8503 return; /* return when IOC doesn't support initiator mode */
8505 _scsih_probe_boot_devices(ioc);
8507 if (ioc->ir_firmware) {
8508 volume_mapping_flags =
8509 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8510 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8511 if (volume_mapping_flags ==
8512 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8513 _scsih_probe_raid(ioc);
8514 _scsih_probe_sas(ioc);
8516 _scsih_probe_sas(ioc);
8517 _scsih_probe_raid(ioc);
8520 _scsih_probe_sas(ioc);
8524 * scsih_scan_start - scsi lld callback for .scan_start
8525 * @shost: SCSI host pointer
8527 * The shost has the ability to discover targets on its own instead
8528 * of scanning the entire bus. In our implemention, we will kick off
8529 * firmware discovery.
8532 scsih_scan_start(struct Scsi_Host *shost)
8534 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8536 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8537 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8539 if (disable_discovery > 0)
8542 ioc->start_scan = 1;
8543 rc = mpt3sas_port_enable(ioc);
8546 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8550 * scsih_scan_finished - scsi lld callback for .scan_finished
8551 * @shost: SCSI host pointer
8552 * @time: elapsed time of the scan in jiffies
8554 * This function will be called periodicallyn until it returns 1 with the
8555 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8556 * we wait for firmware discovery to complete, then return 1.
8559 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8561 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8563 if (disable_discovery > 0) {
8564 ioc->is_driver_loading = 0;
8565 ioc->wait_for_discovery_to_complete = 0;
8569 if (time >= (300 * HZ)) {
8570 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8572 "port enable: FAILED with timeout (timeout=300s)\n",
8574 ioc->is_driver_loading = 0;
8578 if (ioc->start_scan)
8581 if (ioc->start_scan_failed) {
8583 "port enable: FAILED with (ioc_status=0x%08x)\n",
8584 ioc->name, ioc->start_scan_failed);
8585 ioc->is_driver_loading = 0;
8586 ioc->wait_for_discovery_to_complete = 0;
8587 ioc->remove_host = 1;
8591 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8592 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8594 if (ioc->wait_for_discovery_to_complete) {
8595 ioc->wait_for_discovery_to_complete = 0;
8596 _scsih_probe_devices(ioc);
8598 mpt3sas_base_start_watchdog(ioc);
8599 ioc->is_driver_loading = 0;
8603 /* shost template for SAS 2.0 HBA devices */
8604 static struct scsi_host_template mpt2sas_driver_template = {
8605 .module = THIS_MODULE,
8606 .name = "Fusion MPT SAS Host",
8607 .proc_name = MPT2SAS_DRIVER_NAME,
8608 .queuecommand = scsih_qcmd,
8609 .target_alloc = scsih_target_alloc,
8610 .slave_alloc = scsih_slave_alloc,
8611 .slave_configure = scsih_slave_configure,
8612 .target_destroy = scsih_target_destroy,
8613 .slave_destroy = scsih_slave_destroy,
8614 .scan_finished = scsih_scan_finished,
8615 .scan_start = scsih_scan_start,
8616 .change_queue_depth = scsih_change_queue_depth,
8617 .eh_abort_handler = scsih_abort,
8618 .eh_device_reset_handler = scsih_dev_reset,
8619 .eh_target_reset_handler = scsih_target_reset,
8620 .eh_host_reset_handler = scsih_host_reset,
8621 .bios_param = scsih_bios_param,
8624 .sg_tablesize = MPT2SAS_SG_DEPTH,
8625 .max_sectors = 32767,
8627 .use_clustering = ENABLE_CLUSTERING,
8628 .shost_attrs = mpt3sas_host_attrs,
8629 .sdev_attrs = mpt3sas_dev_attrs,
8630 .track_queue_depth = 1,
8633 /* raid transport support for SAS 2.0 HBA devices */
8634 static struct raid_function_template mpt2sas_raid_functions = {
8635 .cookie = &mpt2sas_driver_template,
8636 .is_raid = scsih_is_raid,
8637 .get_resync = scsih_get_resync,
8638 .get_state = scsih_get_state,
8641 /* shost template for SAS 3.0 HBA devices */
8642 static struct scsi_host_template mpt3sas_driver_template = {
8643 .module = THIS_MODULE,
8644 .name = "Fusion MPT SAS Host",
8645 .proc_name = MPT3SAS_DRIVER_NAME,
8646 .queuecommand = scsih_qcmd,
8647 .target_alloc = scsih_target_alloc,
8648 .slave_alloc = scsih_slave_alloc,
8649 .slave_configure = scsih_slave_configure,
8650 .target_destroy = scsih_target_destroy,
8651 .slave_destroy = scsih_slave_destroy,
8652 .scan_finished = scsih_scan_finished,
8653 .scan_start = scsih_scan_start,
8654 .change_queue_depth = scsih_change_queue_depth,
8655 .eh_abort_handler = scsih_abort,
8656 .eh_device_reset_handler = scsih_dev_reset,
8657 .eh_target_reset_handler = scsih_target_reset,
8658 .eh_host_reset_handler = scsih_host_reset,
8659 .bios_param = scsih_bios_param,
8662 .sg_tablesize = MPT3SAS_SG_DEPTH,
8663 .max_sectors = 32767,
8665 .use_clustering = ENABLE_CLUSTERING,
8666 .shost_attrs = mpt3sas_host_attrs,
8667 .sdev_attrs = mpt3sas_dev_attrs,
8668 .track_queue_depth = 1,
8671 /* raid transport support for SAS 3.0 HBA devices */
8672 static struct raid_function_template mpt3sas_raid_functions = {
8673 .cookie = &mpt3sas_driver_template,
8674 .is_raid = scsih_is_raid,
8675 .get_resync = scsih_get_resync,
8676 .get_state = scsih_get_state,
8680 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8681 * this device belongs to.
8682 * @pdev: PCI device struct
8684 * return MPI2_VERSION for SAS 2.0 HBA devices,
8685 * MPI25_VERSION for SAS 3.0 HBA devices, and
8686 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8689 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8692 switch (pdev->device) {
8693 case MPI2_MFGPAGE_DEVID_SSS6200:
8694 case MPI2_MFGPAGE_DEVID_SAS2004:
8695 case MPI2_MFGPAGE_DEVID_SAS2008:
8696 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8697 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8698 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8699 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8700 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8701 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8702 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8703 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8704 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8705 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8706 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8707 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8708 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8709 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8710 return MPI2_VERSION;
8711 case MPI25_MFGPAGE_DEVID_SAS3004:
8712 case MPI25_MFGPAGE_DEVID_SAS3008:
8713 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8714 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8715 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8716 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8717 return MPI25_VERSION;
8718 case MPI26_MFGPAGE_DEVID_SAS3216:
8719 case MPI26_MFGPAGE_DEVID_SAS3224:
8720 case MPI26_MFGPAGE_DEVID_SAS3316_1:
8721 case MPI26_MFGPAGE_DEVID_SAS3316_2:
8722 case MPI26_MFGPAGE_DEVID_SAS3316_3:
8723 case MPI26_MFGPAGE_DEVID_SAS3316_4:
8724 case MPI26_MFGPAGE_DEVID_SAS3324_1:
8725 case MPI26_MFGPAGE_DEVID_SAS3324_2:
8726 case MPI26_MFGPAGE_DEVID_SAS3324_3:
8727 case MPI26_MFGPAGE_DEVID_SAS3324_4:
8728 return MPI26_VERSION;
8734 * _scsih_probe - attach and add scsi host
8735 * @pdev: PCI device struct
8736 * @id: pci device id
8738 * Returns 0 success, anything else error.
8741 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8743 struct MPT3SAS_ADAPTER *ioc;
8744 struct Scsi_Host *shost = NULL;
8746 u16 hba_mpi_version;
8748 /* Determine in which MPI version class this pci device belongs */
8749 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8750 if (hba_mpi_version == 0)
8753 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8754 * for other generation HBA's return with -ENODEV
8756 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8759 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8760 * for other generation HBA's return with -ENODEV
8762 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
8763 || hba_mpi_version == MPI26_VERSION)))
8766 switch (hba_mpi_version) {
8768 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
8769 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
8770 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8771 shost = scsi_host_alloc(&mpt2sas_driver_template,
8772 sizeof(struct MPT3SAS_ADAPTER));
8775 ioc = shost_priv(shost);
8776 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8777 ioc->hba_mpi_version_belonged = hba_mpi_version;
8778 ioc->id = mpt2_ids++;
8779 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8780 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8781 ioc->is_warpdrive = 1;
8782 ioc->hide_ir_msg = 1;
8784 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8788 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8789 shost = scsi_host_alloc(&mpt3sas_driver_template,
8790 sizeof(struct MPT3SAS_ADAPTER));
8793 ioc = shost_priv(shost);
8794 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8795 ioc->hba_mpi_version_belonged = hba_mpi_version;
8796 ioc->id = mpt3_ids++;
8797 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8798 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
8799 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
8800 (ioc->hba_mpi_version_belonged == MPI26_VERSION))
8801 ioc->msix96_vector = 1;
8807 INIT_LIST_HEAD(&ioc->list);
8808 spin_lock(&gioc_lock);
8809 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8810 spin_unlock(&gioc_lock);
8813 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8814 ioc->tm_cb_idx = tm_cb_idx;
8815 ioc->ctl_cb_idx = ctl_cb_idx;
8816 ioc->base_cb_idx = base_cb_idx;
8817 ioc->port_enable_cb_idx = port_enable_cb_idx;
8818 ioc->transport_cb_idx = transport_cb_idx;
8819 ioc->scsih_cb_idx = scsih_cb_idx;
8820 ioc->config_cb_idx = config_cb_idx;
8821 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8822 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8823 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8824 ioc->logging_level = logging_level;
8825 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8826 /* misc semaphores and spin locks */
8827 mutex_init(&ioc->reset_in_progress_mutex);
8828 /* initializing pci_access_mutex lock */
8829 mutex_init(&ioc->pci_access_mutex);
8830 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8831 spin_lock_init(&ioc->scsi_lookup_lock);
8832 spin_lock_init(&ioc->sas_device_lock);
8833 spin_lock_init(&ioc->sas_node_lock);
8834 spin_lock_init(&ioc->fw_event_lock);
8835 spin_lock_init(&ioc->raid_device_lock);
8836 spin_lock_init(&ioc->diag_trigger_lock);
8838 INIT_LIST_HEAD(&ioc->sas_device_list);
8839 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8840 INIT_LIST_HEAD(&ioc->sas_expander_list);
8841 INIT_LIST_HEAD(&ioc->fw_event_list);
8842 INIT_LIST_HEAD(&ioc->raid_device_list);
8843 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8844 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8845 INIT_LIST_HEAD(&ioc->delayed_sc_list);
8846 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
8847 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8848 INIT_LIST_HEAD(&ioc->reply_queue_list);
8850 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8852 /* init shost parameters */
8853 shost->max_cmd_len = 32;
8854 shost->max_lun = max_lun;
8855 shost->transportt = mpt3sas_transport_template;
8856 shost->unique_id = ioc->id;
8858 if (max_sectors != 0xFFFF) {
8859 if (max_sectors < 64) {
8860 shost->max_sectors = 64;
8861 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8862 "for max_sectors, range is 64 to 32767. Assigning "
8863 "value of 64.\n", ioc->name, max_sectors);
8864 } else if (max_sectors > 32767) {
8865 shost->max_sectors = 32767;
8866 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8867 "for max_sectors, range is 64 to 32767. Assigning "
8868 "default value of 32767.\n", ioc->name,
8871 shost->max_sectors = max_sectors & 0xFFFE;
8873 "The max_sectors value is set to %d\n",
8874 ioc->name, shost->max_sectors);
8878 /* register EEDP capabilities with SCSI layer */
8880 scsi_host_set_prot(shost, prot_mask);
8882 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8883 | SHOST_DIF_TYPE2_PROTECTION
8884 | SHOST_DIF_TYPE3_PROTECTION);
8886 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8889 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8890 "fw_event_%s%d", ioc->driver_name, ioc->id);
8891 ioc->firmware_event_thread = alloc_ordered_workqueue(
8892 ioc->firmware_event_name, 0);
8893 if (!ioc->firmware_event_thread) {
8894 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8895 ioc->name, __FILE__, __LINE__, __func__);
8897 goto out_thread_fail;
8900 ioc->is_driver_loading = 1;
8901 if ((mpt3sas_base_attach(ioc))) {
8902 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8903 ioc->name, __FILE__, __LINE__, __func__);
8905 goto out_attach_fail;
8908 if (ioc->is_warpdrive) {
8909 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8910 ioc->hide_drives = 0;
8911 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8912 ioc->hide_drives = 1;
8914 if (mpt3sas_get_num_volumes(ioc))
8915 ioc->hide_drives = 1;
8917 ioc->hide_drives = 0;
8920 ioc->hide_drives = 0;
8922 rv = scsi_add_host(shost, &pdev->dev);
8924 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8925 ioc->name, __FILE__, __LINE__, __func__);
8926 goto out_add_shost_fail;
8929 scsi_scan_host(shost);
8932 mpt3sas_base_detach(ioc);
8934 destroy_workqueue(ioc->firmware_event_thread);
8936 spin_lock(&gioc_lock);
8937 list_del(&ioc->list);
8938 spin_unlock(&gioc_lock);
8939 scsi_host_put(shost);
8945 * scsih_suspend - power management suspend main entry point
8946 * @pdev: PCI device struct
8947 * @state: PM state change to (usually PCI_D3)
8949 * Returns 0 success, anything else error.
8952 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8954 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8955 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8956 pci_power_t device_state;
8958 mpt3sas_base_stop_watchdog(ioc);
8959 flush_scheduled_work();
8960 scsi_block_requests(shost);
8961 device_state = pci_choose_state(pdev, state);
8963 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8964 ioc->name, pdev, pci_name(pdev), device_state);
8966 pci_save_state(pdev);
8967 mpt3sas_base_free_resources(ioc);
8968 pci_set_power_state(pdev, device_state);
8973 * scsih_resume - power management resume main entry point
8974 * @pdev: PCI device struct
8976 * Returns 0 success, anything else error.
8979 scsih_resume(struct pci_dev *pdev)
8981 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8982 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8983 pci_power_t device_state = pdev->current_state;
8987 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8988 ioc->name, pdev, pci_name(pdev), device_state);
8990 pci_set_power_state(pdev, PCI_D0);
8991 pci_enable_wake(pdev, PCI_D0, 0);
8992 pci_restore_state(pdev);
8994 r = mpt3sas_base_map_resources(ioc);
8998 mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET);
8999 scsi_unblock_requests(shost);
9000 mpt3sas_base_start_watchdog(ioc);
9003 #endif /* CONFIG_PM */
9006 * scsih_pci_error_detected - Called when a PCI error is detected.
9007 * @pdev: PCI device struct
9008 * @state: PCI channel state
9010 * Description: Called when a PCI error is detected.
9013 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9015 static pci_ers_result_t
9016 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9018 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9019 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9021 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
9025 case pci_channel_io_normal:
9026 return PCI_ERS_RESULT_CAN_RECOVER;
9027 case pci_channel_io_frozen:
9028 /* Fatal error, prepare for slot reset */
9029 ioc->pci_error_recovery = 1;
9030 scsi_block_requests(ioc->shost);
9031 mpt3sas_base_stop_watchdog(ioc);
9032 mpt3sas_base_free_resources(ioc);
9033 return PCI_ERS_RESULT_NEED_RESET;
9034 case pci_channel_io_perm_failure:
9035 /* Permanent error, prepare for device removal */
9036 ioc->pci_error_recovery = 1;
9037 mpt3sas_base_stop_watchdog(ioc);
9038 _scsih_flush_running_cmds(ioc);
9039 return PCI_ERS_RESULT_DISCONNECT;
9041 return PCI_ERS_RESULT_NEED_RESET;
9045 * scsih_pci_slot_reset - Called when PCI slot has been reset.
9046 * @pdev: PCI device struct
9048 * Description: This routine is called by the pci error recovery
9049 * code after the PCI slot has been reset, just before we
9050 * should resume normal operations.
9052 static pci_ers_result_t
9053 scsih_pci_slot_reset(struct pci_dev *pdev)
9055 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9056 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9059 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
9062 ioc->pci_error_recovery = 0;
9064 pci_restore_state(pdev);
9065 rc = mpt3sas_base_map_resources(ioc);
9067 return PCI_ERS_RESULT_DISCONNECT;
9069 rc = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
9071 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
9072 (rc == 0) ? "success" : "failed");
9075 return PCI_ERS_RESULT_RECOVERED;
9077 return PCI_ERS_RESULT_DISCONNECT;
9081 * scsih_pci_resume() - resume normal ops after PCI reset
9082 * @pdev: pointer to PCI device
9084 * Called when the error recovery driver tells us that its
9085 * OK to resume normal operation. Use completion to allow
9086 * halted scsi ops to resume.
9089 scsih_pci_resume(struct pci_dev *pdev)
9091 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9092 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9094 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
9096 pci_cleanup_aer_uncorrect_error_status(pdev);
9097 mpt3sas_base_start_watchdog(ioc);
9098 scsi_unblock_requests(ioc->shost);
9102 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
9103 * @pdev: pointer to PCI device
9105 static pci_ers_result_t
9106 scsih_pci_mmio_enabled(struct pci_dev *pdev)
9108 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9109 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9111 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
9114 /* TODO - dump whatever for debugging purposes */
9116 /* This called only if scsih_pci_error_detected returns
9117 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
9118 * works, no need to reset slot.
9120 return PCI_ERS_RESULT_RECOVERED;
9124 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9126 static const struct pci_device_id mpt3sas_pci_table[] = {
9127 /* Spitfire ~ 2004 */
9128 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
9129 PCI_ANY_ID, PCI_ANY_ID },
9131 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
9132 PCI_ANY_ID, PCI_ANY_ID },
9133 /* Liberator ~ 2108 */
9134 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
9135 PCI_ANY_ID, PCI_ANY_ID },
9136 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
9137 PCI_ANY_ID, PCI_ANY_ID },
9138 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
9139 PCI_ANY_ID, PCI_ANY_ID },
9141 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
9142 PCI_ANY_ID, PCI_ANY_ID },
9143 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
9144 PCI_ANY_ID, PCI_ANY_ID },
9145 /* Thunderbolt ~ 2208 */
9146 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
9147 PCI_ANY_ID, PCI_ANY_ID },
9148 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
9149 PCI_ANY_ID, PCI_ANY_ID },
9150 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
9151 PCI_ANY_ID, PCI_ANY_ID },
9152 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
9153 PCI_ANY_ID, PCI_ANY_ID },
9154 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
9155 PCI_ANY_ID, PCI_ANY_ID },
9156 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
9157 PCI_ANY_ID, PCI_ANY_ID },
9158 /* Mustang ~ 2308 */
9159 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
9160 PCI_ANY_ID, PCI_ANY_ID },
9161 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
9162 PCI_ANY_ID, PCI_ANY_ID },
9163 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
9164 PCI_ANY_ID, PCI_ANY_ID },
9166 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
9167 PCI_ANY_ID, PCI_ANY_ID },
9168 /* Fury ~ 3004 and 3008 */
9169 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
9170 PCI_ANY_ID, PCI_ANY_ID },
9171 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
9172 PCI_ANY_ID, PCI_ANY_ID },
9173 /* Invader ~ 3108 */
9174 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
9175 PCI_ANY_ID, PCI_ANY_ID },
9176 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
9177 PCI_ANY_ID, PCI_ANY_ID },
9178 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
9179 PCI_ANY_ID, PCI_ANY_ID },
9180 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
9181 PCI_ANY_ID, PCI_ANY_ID },
9182 /* Cutlass ~ 3216 and 3224 */
9183 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
9184 PCI_ANY_ID, PCI_ANY_ID },
9185 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
9186 PCI_ANY_ID, PCI_ANY_ID },
9187 /* Intruder ~ 3316 and 3324 */
9188 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
9189 PCI_ANY_ID, PCI_ANY_ID },
9190 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
9191 PCI_ANY_ID, PCI_ANY_ID },
9192 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
9193 PCI_ANY_ID, PCI_ANY_ID },
9194 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
9195 PCI_ANY_ID, PCI_ANY_ID },
9196 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
9197 PCI_ANY_ID, PCI_ANY_ID },
9198 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
9199 PCI_ANY_ID, PCI_ANY_ID },
9200 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
9201 PCI_ANY_ID, PCI_ANY_ID },
9202 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
9203 PCI_ANY_ID, PCI_ANY_ID },
9204 {0} /* Terminating entry */
9206 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
9208 static struct pci_error_handlers _mpt3sas_err_handler = {
9209 .error_detected = scsih_pci_error_detected,
9210 .mmio_enabled = scsih_pci_mmio_enabled,
9211 .slot_reset = scsih_pci_slot_reset,
9212 .resume = scsih_pci_resume,
9215 static struct pci_driver mpt3sas_driver = {
9216 .name = MPT3SAS_DRIVER_NAME,
9217 .id_table = mpt3sas_pci_table,
9218 .probe = _scsih_probe,
9219 .remove = scsih_remove,
9220 .shutdown = scsih_shutdown,
9221 .err_handler = &_mpt3sas_err_handler,
9223 .suspend = scsih_suspend,
9224 .resume = scsih_resume,
9229 * scsih_init - main entry point for this driver.
9231 * Returns 0 success, anything else error.
9239 mpt3sas_base_initialize_callback_handler();
9241 /* queuecommand callback hander */
9242 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
9244 /* task managment callback handler */
9245 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
9247 /* base internal commands callback handler */
9248 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
9249 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
9250 mpt3sas_port_enable_done);
9252 /* transport internal commands callback handler */
9253 transport_cb_idx = mpt3sas_base_register_callback_handler(
9254 mpt3sas_transport_done);
9256 /* scsih internal commands callback handler */
9257 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
9259 /* configuration page API internal commands callback handler */
9260 config_cb_idx = mpt3sas_base_register_callback_handler(
9261 mpt3sas_config_done);
9263 /* ctl module callback handler */
9264 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
9266 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
9267 _scsih_tm_tr_complete);
9269 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
9270 _scsih_tm_volume_tr_complete);
9272 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
9273 _scsih_sas_control_complete);
9279 * scsih_exit - exit point for this driver (when it is a module).
9281 * Returns 0 success, anything else error.
9287 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
9288 mpt3sas_base_release_callback_handler(tm_cb_idx);
9289 mpt3sas_base_release_callback_handler(base_cb_idx);
9290 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
9291 mpt3sas_base_release_callback_handler(transport_cb_idx);
9292 mpt3sas_base_release_callback_handler(scsih_cb_idx);
9293 mpt3sas_base_release_callback_handler(config_cb_idx);
9294 mpt3sas_base_release_callback_handler(ctl_cb_idx);
9296 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
9297 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
9298 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
9300 /* raid transport support */
9301 if (hbas_to_enumerate != 1)
9302 raid_class_release(mpt3sas_raid_template);
9303 if (hbas_to_enumerate != 2)
9304 raid_class_release(mpt2sas_raid_template);
9305 sas_release_transport(mpt3sas_transport_template);
9309 * _mpt3sas_init - main entry point for this driver.
9311 * Returns 0 success, anything else error.
9318 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
9319 MPT3SAS_DRIVER_VERSION);
9321 mpt3sas_transport_template =
9322 sas_attach_transport(&mpt3sas_transport_functions);
9323 if (!mpt3sas_transport_template)
9326 /* No need attach mpt3sas raid functions template
9327 * if hbas_to_enumarate value is one.
9329 if (hbas_to_enumerate != 1) {
9330 mpt3sas_raid_template =
9331 raid_class_attach(&mpt3sas_raid_functions);
9332 if (!mpt3sas_raid_template) {
9333 sas_release_transport(mpt3sas_transport_template);
9338 /* No need to attach mpt2sas raid functions template
9339 * if hbas_to_enumarate value is two
9341 if (hbas_to_enumerate != 2) {
9342 mpt2sas_raid_template =
9343 raid_class_attach(&mpt2sas_raid_functions);
9344 if (!mpt2sas_raid_template) {
9345 sas_release_transport(mpt3sas_transport_template);
9350 error = scsih_init();
9356 mpt3sas_ctl_init(hbas_to_enumerate);
9358 error = pci_register_driver(&mpt3sas_driver);
9366 * _mpt3sas_exit - exit point for this driver (when it is a module).
9372 pr_info("mpt3sas version %s unloading\n",
9373 MPT3SAS_DRIVER_VERSION);
9375 pci_unregister_driver(&mpt3sas_driver);
9377 mpt3sas_ctl_exit(hbas_to_enumerate);
9382 module_init(_mpt3sas_init);
9383 module_exit(_mpt3sas_exit);