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 * @cancel_pending_work: flag set during reset handling
179 * @ioc: per adapter object
180 * @device_handle: device handle
181 * @VF_ID: virtual function id
182 * @VP_ID: virtual port id
183 * @ignore: flag meaning this event has been marked to ignore
184 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
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;
192 u8 cancel_pending_work;
193 struct delayed_work delayed_work;
195 struct MPT3SAS_ADAPTER *ioc;
201 struct kref refcount;
202 char event_data[0] __aligned(4);
205 static void fw_event_work_free(struct kref *r)
207 kfree(container_of(r, struct fw_event_work, refcount));
210 static void fw_event_work_get(struct fw_event_work *fw_work)
212 kref_get(&fw_work->refcount);
215 static void fw_event_work_put(struct fw_event_work *fw_work)
217 kref_put(&fw_work->refcount, fw_event_work_free);
220 static struct fw_event_work *alloc_fw_event_work(int len)
222 struct fw_event_work *fw_event;
224 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
228 kref_init(&fw_event->refcount);
233 * struct _scsi_io_transfer - scsi io transfer
234 * @handle: sas device handle (assigned by firmware)
235 * @is_raid: flag set for hidden raid components
236 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
237 * @data_length: data transfer length
238 * @data_dma: dma pointer to data
241 * @cdb_length: cdb length
243 * @timeout: timeout for this command
244 * @VF_ID: virtual function id
245 * @VP_ID: virtual port id
246 * @valid_reply: flag set for reply message
247 * @sense_length: sense length
248 * @ioc_status: ioc status
249 * @scsi_state: scsi state
250 * @scsi_status: scsi staus
251 * @log_info: log information
252 * @transfer_length: data length transfer when there is a reply message
254 * Used for sending internal scsi commands to devices within this module.
255 * Refer to _scsi_send_scsi_io().
257 struct _scsi_io_transfer {
260 enum dma_data_direction dir;
263 u8 sense[SCSI_SENSE_BUFFERSIZE];
271 /* the following bits are only valid when 'valid_reply = 1' */
281 * _scsih_set_debug_level - global setting of ioc->logging_level.
283 * Note: The logging levels are defined in mpt3sas_debug.h.
286 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
288 int ret = param_set_int(val, kp);
289 struct MPT3SAS_ADAPTER *ioc;
294 pr_info("setting logging_level(0x%08x)\n", logging_level);
295 spin_lock(&gioc_lock);
296 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
297 ioc->logging_level = logging_level;
298 spin_unlock(&gioc_lock);
301 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
302 &logging_level, 0644);
305 * _scsih_srch_boot_sas_address - search based on sas_address
306 * @sas_address: sas address
307 * @boot_device: boot device object from bios page 2
309 * Returns 1 when there's a match, 0 means no match.
312 _scsih_srch_boot_sas_address(u64 sas_address,
313 Mpi2BootDeviceSasWwid_t *boot_device)
315 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
319 * _scsih_srch_boot_device_name - search based on device name
320 * @device_name: device name specified in INDENTIFY fram
321 * @boot_device: boot device object from bios page 2
323 * Returns 1 when there's a match, 0 means no match.
326 _scsih_srch_boot_device_name(u64 device_name,
327 Mpi2BootDeviceDeviceName_t *boot_device)
329 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
333 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
334 * @enclosure_logical_id: enclosure logical id
335 * @slot_number: slot number
336 * @boot_device: boot device object from bios page 2
338 * Returns 1 when there's a match, 0 means no match.
341 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
342 Mpi2BootDeviceEnclosureSlot_t *boot_device)
344 return (enclosure_logical_id == le64_to_cpu(boot_device->
345 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
346 SlotNumber)) ? 1 : 0;
350 * _scsih_is_boot_device - search for matching boot device.
351 * @sas_address: sas address
352 * @device_name: device name specified in INDENTIFY fram
353 * @enclosure_logical_id: enclosure logical id
354 * @slot_number: slot number
355 * @form: specifies boot device form
356 * @boot_device: boot device object from bios page 2
358 * Returns 1 when there's a match, 0 means no match.
361 _scsih_is_boot_device(u64 sas_address, u64 device_name,
362 u64 enclosure_logical_id, u16 slot, u8 form,
363 Mpi2BiosPage2BootDevice_t *boot_device)
368 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
371 rc = _scsih_srch_boot_sas_address(
372 sas_address, &boot_device->SasWwid);
374 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
375 if (!enclosure_logical_id)
377 rc = _scsih_srch_boot_encl_slot(
378 enclosure_logical_id,
379 slot, &boot_device->EnclosureSlot);
381 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
384 rc = _scsih_srch_boot_device_name(
385 device_name, &boot_device->DeviceName);
387 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
395 * _scsih_get_sas_address - set the sas_address for given device handle
396 * @handle: device handle
397 * @sas_address: sas address
399 * Returns 0 success, non-zero when failure
402 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
405 Mpi2SasDevicePage0_t sas_device_pg0;
406 Mpi2ConfigReply_t mpi_reply;
411 if (handle <= ioc->sas_hba.num_phys) {
412 *sas_address = ioc->sas_hba.sas_address;
416 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
417 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
418 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
419 __FILE__, __LINE__, __func__);
423 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
424 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
425 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
429 /* we hit this becuase the given parent handle doesn't exist */
430 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
433 /* else error case */
435 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
436 ioc->name, handle, ioc_status,
437 __FILE__, __LINE__, __func__);
442 * _scsih_determine_boot_device - determine boot device.
443 * @ioc: per adapter object
444 * @device: either sas_device or raid_device object
445 * @is_raid: [flag] 1 = raid object, 0 = sas object
447 * Determines whether this device should be first reported device to
448 * to scsi-ml or sas transport, this purpose is for persistent boot device.
449 * There are primary, alternate, and current entries in bios page 2. The order
450 * priority is primary, alternate, then current. This routine saves
451 * the corresponding device object and is_raid flag in the ioc object.
452 * The saved data to be used later in _scsih_probe_boot_devices().
455 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
456 void *device, u8 is_raid)
458 struct _sas_device *sas_device;
459 struct _raid_device *raid_device;
462 u64 enclosure_logical_id;
465 /* only process this function when driver loads */
466 if (!ioc->is_driver_loading)
469 /* no Bios, return immediately */
470 if (!ioc->bios_pg3.BiosVersion)
475 sas_address = sas_device->sas_address;
476 device_name = sas_device->device_name;
477 enclosure_logical_id = sas_device->enclosure_logical_id;
478 slot = sas_device->slot;
480 raid_device = device;
481 sas_address = raid_device->wwid;
483 enclosure_logical_id = 0;
487 if (!ioc->req_boot_device.device) {
488 if (_scsih_is_boot_device(sas_address, device_name,
489 enclosure_logical_id, slot,
490 (ioc->bios_pg2.ReqBootDeviceForm &
491 MPI2_BIOSPAGE2_FORM_MASK),
492 &ioc->bios_pg2.RequestedBootDevice)) {
493 dinitprintk(ioc, pr_info(MPT3SAS_FMT
494 "%s: req_boot_device(0x%016llx)\n",
496 (unsigned long long)sas_address));
497 ioc->req_boot_device.device = device;
498 ioc->req_boot_device.is_raid = is_raid;
502 if (!ioc->req_alt_boot_device.device) {
503 if (_scsih_is_boot_device(sas_address, device_name,
504 enclosure_logical_id, slot,
505 (ioc->bios_pg2.ReqAltBootDeviceForm &
506 MPI2_BIOSPAGE2_FORM_MASK),
507 &ioc->bios_pg2.RequestedAltBootDevice)) {
508 dinitprintk(ioc, pr_info(MPT3SAS_FMT
509 "%s: req_alt_boot_device(0x%016llx)\n",
511 (unsigned long long)sas_address));
512 ioc->req_alt_boot_device.device = device;
513 ioc->req_alt_boot_device.is_raid = is_raid;
517 if (!ioc->current_boot_device.device) {
518 if (_scsih_is_boot_device(sas_address, device_name,
519 enclosure_logical_id, slot,
520 (ioc->bios_pg2.CurrentBootDeviceForm &
521 MPI2_BIOSPAGE2_FORM_MASK),
522 &ioc->bios_pg2.CurrentBootDevice)) {
523 dinitprintk(ioc, pr_info(MPT3SAS_FMT
524 "%s: current_boot_device(0x%016llx)\n",
526 (unsigned long long)sas_address));
527 ioc->current_boot_device.device = device;
528 ioc->current_boot_device.is_raid = is_raid;
533 static struct _sas_device *
534 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
535 struct MPT3SAS_TARGET *tgt_priv)
537 struct _sas_device *ret;
539 assert_spin_locked(&ioc->sas_device_lock);
541 ret = tgt_priv->sdev;
548 static struct _sas_device *
549 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
550 struct MPT3SAS_TARGET *tgt_priv)
552 struct _sas_device *ret;
555 spin_lock_irqsave(&ioc->sas_device_lock, flags);
556 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
557 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
564 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
567 struct _sas_device *sas_device;
569 assert_spin_locked(&ioc->sas_device_lock);
571 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
572 if (sas_device->sas_address == sas_address)
575 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
576 if (sas_device->sas_address == sas_address)
582 sas_device_get(sas_device);
587 * mpt3sas_get_sdev_by_addr - sas device search
588 * @ioc: per adapter object
589 * @sas_address: sas address
590 * Context: Calling function should acquire ioc->sas_device_lock
592 * This searches for sas_device based on sas_address, then return sas_device
596 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
599 struct _sas_device *sas_device;
602 spin_lock_irqsave(&ioc->sas_device_lock, flags);
603 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
605 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
610 static struct _sas_device *
611 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
613 struct _sas_device *sas_device;
615 assert_spin_locked(&ioc->sas_device_lock);
617 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
618 if (sas_device->handle == handle)
621 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
622 if (sas_device->handle == handle)
628 sas_device_get(sas_device);
633 * mpt3sas_get_sdev_by_handle - sas device search
634 * @ioc: per adapter object
635 * @handle: sas device handle (assigned by firmware)
636 * Context: Calling function should acquire ioc->sas_device_lock
638 * This searches for sas_device based on sas_address, then return sas_device
641 static struct _sas_device *
642 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
644 struct _sas_device *sas_device;
647 spin_lock_irqsave(&ioc->sas_device_lock, flags);
648 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
649 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
655 * _scsih_sas_device_remove - remove sas_device from list.
656 * @ioc: per adapter object
657 * @sas_device: the sas_device object
658 * Context: This function will acquire ioc->sas_device_lock.
660 * If sas_device is on the list, remove it and decrement its reference count.
663 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
664 struct _sas_device *sas_device)
671 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
672 ioc->name, sas_device->handle,
673 (unsigned long long) sas_device->sas_address);
675 if (sas_device->enclosure_handle != 0)
677 "removing enclosure logical id(0x%016llx), slot(%d)\n",
678 ioc->name, (unsigned long long)
679 sas_device->enclosure_logical_id, sas_device->slot);
681 if (sas_device->connector_name[0] != '\0')
683 "removing enclosure level(0x%04x), connector name( %s)\n",
684 ioc->name, sas_device->enclosure_level,
685 sas_device->connector_name);
688 * The lock serializes access to the list, but we still need to verify
689 * that nobody removed the entry while we were waiting on the lock.
691 spin_lock_irqsave(&ioc->sas_device_lock, flags);
692 if (!list_empty(&sas_device->list)) {
693 list_del_init(&sas_device->list);
694 sas_device_put(sas_device);
696 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
700 * _scsih_device_remove_by_handle - removing device object by handle
701 * @ioc: per adapter object
702 * @handle: device handle
707 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
709 struct _sas_device *sas_device;
712 if (ioc->shost_recovery)
715 spin_lock_irqsave(&ioc->sas_device_lock, flags);
716 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
718 list_del_init(&sas_device->list);
719 sas_device_put(sas_device);
721 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
723 _scsih_remove_device(ioc, sas_device);
724 sas_device_put(sas_device);
729 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
730 * @ioc: per adapter object
731 * @sas_address: device sas_address
736 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
739 struct _sas_device *sas_device;
742 if (ioc->shost_recovery)
745 spin_lock_irqsave(&ioc->sas_device_lock, flags);
746 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
748 list_del_init(&sas_device->list);
749 sas_device_put(sas_device);
751 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
753 _scsih_remove_device(ioc, sas_device);
754 sas_device_put(sas_device);
759 * _scsih_sas_device_add - insert sas_device to the list.
760 * @ioc: per adapter object
761 * @sas_device: the sas_device object
762 * Context: This function will acquire ioc->sas_device_lock.
764 * Adding new object to the ioc->sas_device_list.
767 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
768 struct _sas_device *sas_device)
772 dewtprintk(ioc, pr_info(MPT3SAS_FMT
773 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
774 ioc->name, __func__, sas_device->handle,
775 (unsigned long long)sas_device->sas_address));
777 if (sas_device->enclosure_handle != 0)
778 dewtprintk(ioc, pr_info(MPT3SAS_FMT
779 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
780 ioc->name, __func__, (unsigned long long)
781 sas_device->enclosure_logical_id, sas_device->slot));
783 if (sas_device->connector_name[0] != '\0')
784 dewtprintk(ioc, pr_info(MPT3SAS_FMT
785 "%s: enclosure level(0x%04x), connector name( %s)\n",
787 sas_device->enclosure_level, sas_device->connector_name));
789 spin_lock_irqsave(&ioc->sas_device_lock, flags);
790 sas_device_get(sas_device);
791 list_add_tail(&sas_device->list, &ioc->sas_device_list);
792 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
794 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
795 sas_device->sas_address_parent)) {
796 _scsih_sas_device_remove(ioc, sas_device);
797 } else if (!sas_device->starget) {
799 * When asyn scanning is enabled, its not possible to remove
800 * devices while scanning is turned on due to an oops in
801 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
803 if (!ioc->is_driver_loading) {
804 mpt3sas_transport_port_remove(ioc,
805 sas_device->sas_address,
806 sas_device->sas_address_parent);
807 _scsih_sas_device_remove(ioc, sas_device);
813 * _scsih_sas_device_init_add - insert sas_device to the list.
814 * @ioc: per adapter object
815 * @sas_device: the sas_device object
816 * Context: This function will acquire ioc->sas_device_lock.
818 * Adding new object at driver load time to the ioc->sas_device_init_list.
821 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
822 struct _sas_device *sas_device)
826 dewtprintk(ioc, pr_info(MPT3SAS_FMT
827 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
828 __func__, sas_device->handle,
829 (unsigned long long)sas_device->sas_address));
831 if (sas_device->enclosure_handle != 0)
832 dewtprintk(ioc, pr_info(MPT3SAS_FMT
833 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
834 ioc->name, __func__, (unsigned long long)
835 sas_device->enclosure_logical_id, sas_device->slot));
837 if (sas_device->connector_name[0] != '\0')
838 dewtprintk(ioc, pr_info(MPT3SAS_FMT
839 "%s: enclosure level(0x%04x), connector name( %s)\n",
840 ioc->name, __func__, sas_device->enclosure_level,
841 sas_device->connector_name));
843 spin_lock_irqsave(&ioc->sas_device_lock, flags);
844 sas_device_get(sas_device);
845 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
846 _scsih_determine_boot_device(ioc, sas_device, 0);
847 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
851 * _scsih_raid_device_find_by_id - raid device search
852 * @ioc: per adapter object
853 * @id: sas device target id
854 * @channel: sas device channel
855 * Context: Calling function should acquire ioc->raid_device_lock
857 * This searches for raid_device based on target id, then return raid_device
860 static struct _raid_device *
861 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
863 struct _raid_device *raid_device, *r;
866 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
867 if (raid_device->id == id && raid_device->channel == channel) {
878 * mpt3sas_raid_device_find_by_handle - raid device search
879 * @ioc: per adapter object
880 * @handle: sas device handle (assigned by firmware)
881 * Context: Calling function should acquire ioc->raid_device_lock
883 * This searches for raid_device based on handle, then return raid_device
886 struct _raid_device *
887 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
889 struct _raid_device *raid_device, *r;
892 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
893 if (raid_device->handle != handle)
904 * _scsih_raid_device_find_by_wwid - raid device search
905 * @ioc: per adapter object
906 * @handle: sas device handle (assigned by firmware)
907 * Context: Calling function should acquire ioc->raid_device_lock
909 * This searches for raid_device based on wwid, then return raid_device
912 static struct _raid_device *
913 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
915 struct _raid_device *raid_device, *r;
918 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
919 if (raid_device->wwid != wwid)
930 * _scsih_raid_device_add - add raid_device object
931 * @ioc: per adapter object
932 * @raid_device: raid_device object
934 * This is added to the raid_device_list link list.
937 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
938 struct _raid_device *raid_device)
942 dewtprintk(ioc, pr_info(MPT3SAS_FMT
943 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
944 raid_device->handle, (unsigned long long)raid_device->wwid));
946 spin_lock_irqsave(&ioc->raid_device_lock, flags);
947 list_add_tail(&raid_device->list, &ioc->raid_device_list);
948 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
952 * _scsih_raid_device_remove - delete raid_device object
953 * @ioc: per adapter object
954 * @raid_device: raid_device object
958 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
959 struct _raid_device *raid_device)
963 spin_lock_irqsave(&ioc->raid_device_lock, flags);
964 list_del(&raid_device->list);
966 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
970 * mpt3sas_scsih_expander_find_by_handle - expander device search
971 * @ioc: per adapter object
972 * @handle: expander handle (assigned by firmware)
973 * Context: Calling function should acquire ioc->sas_device_lock
975 * This searches for expander device based on handle, then returns the
979 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
981 struct _sas_node *sas_expander, *r;
984 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
985 if (sas_expander->handle != handle)
995 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
996 * @ioc: per adapter object
997 * @sas_address: sas address
998 * Context: Calling function should acquire ioc->sas_node_lock.
1000 * This searches for expander device based on sas_address, then returns the
1004 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1007 struct _sas_node *sas_expander, *r;
1010 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1011 if (sas_expander->sas_address != sas_address)
1021 * _scsih_expander_node_add - insert expander device to the list.
1022 * @ioc: per adapter object
1023 * @sas_expander: the sas_device object
1024 * Context: This function will acquire ioc->sas_node_lock.
1026 * Adding new object to the ioc->sas_expander_list.
1031 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1032 struct _sas_node *sas_expander)
1034 unsigned long flags;
1036 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1037 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1038 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1042 * _scsih_is_end_device - determines if device is an end device
1043 * @device_info: bitfield providing information about the device.
1046 * Returns 1 if end device.
1049 _scsih_is_end_device(u32 device_info)
1051 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1052 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1053 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1054 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1061 * _scsih_scsi_lookup_get - returns scmd entry
1062 * @ioc: per adapter object
1063 * @smid: system request message index
1065 * Returns the smid stored scmd pointer.
1067 static struct scsi_cmnd *
1068 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1070 return ioc->scsi_lookup[smid - 1].scmd;
1074 * _scsih_scsi_lookup_get_clear - returns scmd entry
1075 * @ioc: per adapter object
1076 * @smid: system request message index
1078 * Returns the smid stored scmd pointer.
1079 * Then will derefrence the stored scmd pointer.
1081 static inline struct scsi_cmnd *
1082 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1084 unsigned long flags;
1085 struct scsi_cmnd *scmd;
1087 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1088 scmd = ioc->scsi_lookup[smid - 1].scmd;
1089 ioc->scsi_lookup[smid - 1].scmd = NULL;
1090 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1096 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1097 * @ioc: per adapter object
1098 * @smid: system request message index
1099 * @scmd: pointer to scsi command object
1100 * Context: This function will acquire ioc->scsi_lookup_lock.
1102 * This will search for a scmd pointer in the scsi_lookup array,
1103 * returning the revelent smid. A returned value of zero means invalid.
1106 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1110 unsigned long flags;
1113 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1115 for (i = 0; i < ioc->scsiio_depth; i++) {
1116 if (ioc->scsi_lookup[i].scmd == scmd) {
1117 smid = ioc->scsi_lookup[i].smid;
1122 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1127 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1128 * @ioc: per adapter object
1131 * Context: This function will acquire ioc->scsi_lookup_lock.
1133 * This will search for a matching channel:id in the scsi_lookup array,
1134 * returning 1 if found.
1137 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1141 unsigned long flags;
1144 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1146 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1147 if (ioc->scsi_lookup[i].scmd &&
1148 (ioc->scsi_lookup[i].scmd->device->id == id &&
1149 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1155 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1160 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1161 * @ioc: per adapter object
1165 * Context: This function will acquire ioc->scsi_lookup_lock.
1167 * This will search for a matching channel:id:lun in the scsi_lookup array,
1168 * returning 1 if found.
1171 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1172 unsigned int lun, int channel)
1175 unsigned long flags;
1178 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1180 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1181 if (ioc->scsi_lookup[i].scmd &&
1182 (ioc->scsi_lookup[i].scmd->device->id == id &&
1183 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1184 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1190 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1195 * scsih_change_queue_depth - setting device queue depth
1196 * @sdev: scsi device struct
1197 * @qdepth: requested queue depth
1199 * Returns queue depth.
1202 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1204 struct Scsi_Host *shost = sdev->host;
1206 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1207 struct MPT3SAS_DEVICE *sas_device_priv_data;
1208 struct MPT3SAS_TARGET *sas_target_priv_data;
1209 struct _sas_device *sas_device;
1210 unsigned long flags;
1212 max_depth = shost->can_queue;
1214 /* limit max device queue for SATA to 32 */
1215 sas_device_priv_data = sdev->hostdata;
1216 if (!sas_device_priv_data)
1218 sas_target_priv_data = sas_device_priv_data->sas_target;
1219 if (!sas_target_priv_data)
1221 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1224 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1225 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1227 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1228 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1230 sas_device_put(sas_device);
1232 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1236 if (!sdev->tagged_supported)
1238 if (qdepth > max_depth)
1240 return scsi_change_queue_depth(sdev, qdepth);
1244 * scsih_target_alloc - target add routine
1245 * @starget: scsi target struct
1247 * Returns 0 if ok. Any other return is assumed to be an error and
1248 * the device is ignored.
1251 scsih_target_alloc(struct scsi_target *starget)
1253 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1254 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1255 struct MPT3SAS_TARGET *sas_target_priv_data;
1256 struct _sas_device *sas_device;
1257 struct _raid_device *raid_device;
1258 unsigned long flags;
1259 struct sas_rphy *rphy;
1261 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1263 if (!sas_target_priv_data)
1266 starget->hostdata = sas_target_priv_data;
1267 sas_target_priv_data->starget = starget;
1268 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1271 if (starget->channel == RAID_CHANNEL) {
1272 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1273 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1276 sas_target_priv_data->handle = raid_device->handle;
1277 sas_target_priv_data->sas_address = raid_device->wwid;
1278 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1279 if (ioc->is_warpdrive)
1280 sas_target_priv_data->raid_device = raid_device;
1281 raid_device->starget = starget;
1283 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1287 /* sas/sata devices */
1288 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1289 rphy = dev_to_rphy(starget->dev.parent);
1290 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1291 rphy->identify.sas_address);
1294 sas_target_priv_data->handle = sas_device->handle;
1295 sas_target_priv_data->sas_address = sas_device->sas_address;
1296 sas_target_priv_data->sdev = sas_device;
1297 sas_device->starget = starget;
1298 sas_device->id = starget->id;
1299 sas_device->channel = starget->channel;
1300 if (test_bit(sas_device->handle, ioc->pd_handles))
1301 sas_target_priv_data->flags |=
1302 MPT_TARGET_FLAGS_RAID_COMPONENT;
1303 if (sas_device->fast_path)
1304 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1306 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1312 * scsih_target_destroy - target destroy routine
1313 * @starget: scsi target struct
1318 scsih_target_destroy(struct scsi_target *starget)
1320 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1321 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1322 struct MPT3SAS_TARGET *sas_target_priv_data;
1323 struct _sas_device *sas_device;
1324 struct _raid_device *raid_device;
1325 unsigned long flags;
1326 struct sas_rphy *rphy;
1328 sas_target_priv_data = starget->hostdata;
1329 if (!sas_target_priv_data)
1332 if (starget->channel == RAID_CHANNEL) {
1333 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1334 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1337 raid_device->starget = NULL;
1338 raid_device->sdev = NULL;
1340 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1344 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1345 rphy = dev_to_rphy(starget->dev.parent);
1346 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1347 if (sas_device && (sas_device->starget == starget) &&
1348 (sas_device->id == starget->id) &&
1349 (sas_device->channel == starget->channel))
1350 sas_device->starget = NULL;
1354 * Corresponding get() is in _scsih_target_alloc()
1356 sas_target_priv_data->sdev = NULL;
1357 sas_device_put(sas_device);
1359 sas_device_put(sas_device);
1361 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1364 kfree(sas_target_priv_data);
1365 starget->hostdata = NULL;
1369 * scsih_slave_alloc - device add routine
1370 * @sdev: scsi device struct
1372 * Returns 0 if ok. Any other return is assumed to be an error and
1373 * the device is ignored.
1376 scsih_slave_alloc(struct scsi_device *sdev)
1378 struct Scsi_Host *shost;
1379 struct MPT3SAS_ADAPTER *ioc;
1380 struct MPT3SAS_TARGET *sas_target_priv_data;
1381 struct MPT3SAS_DEVICE *sas_device_priv_data;
1382 struct scsi_target *starget;
1383 struct _raid_device *raid_device;
1384 struct _sas_device *sas_device;
1385 unsigned long flags;
1387 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1389 if (!sas_device_priv_data)
1392 sas_device_priv_data->lun = sdev->lun;
1393 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1395 starget = scsi_target(sdev);
1396 sas_target_priv_data = starget->hostdata;
1397 sas_target_priv_data->num_luns++;
1398 sas_device_priv_data->sas_target = sas_target_priv_data;
1399 sdev->hostdata = sas_device_priv_data;
1400 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1401 sdev->no_uld_attach = 1;
1403 shost = dev_to_shost(&starget->dev);
1404 ioc = shost_priv(shost);
1405 if (starget->channel == RAID_CHANNEL) {
1406 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1407 raid_device = _scsih_raid_device_find_by_id(ioc,
1408 starget->id, starget->channel);
1410 raid_device->sdev = sdev; /* raid is single lun */
1411 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1414 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1415 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1416 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1417 sas_target_priv_data->sas_address);
1418 if (sas_device && (sas_device->starget == NULL)) {
1419 sdev_printk(KERN_INFO, sdev,
1420 "%s : sas_device->starget set to starget @ %d\n",
1421 __func__, __LINE__);
1422 sas_device->starget = starget;
1426 sas_device_put(sas_device);
1428 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1435 * scsih_slave_destroy - device destroy routine
1436 * @sdev: scsi device struct
1441 scsih_slave_destroy(struct scsi_device *sdev)
1443 struct MPT3SAS_TARGET *sas_target_priv_data;
1444 struct scsi_target *starget;
1445 struct Scsi_Host *shost;
1446 struct MPT3SAS_ADAPTER *ioc;
1447 struct _sas_device *sas_device;
1448 unsigned long flags;
1450 if (!sdev->hostdata)
1453 starget = scsi_target(sdev);
1454 sas_target_priv_data = starget->hostdata;
1455 sas_target_priv_data->num_luns--;
1457 shost = dev_to_shost(&starget->dev);
1458 ioc = shost_priv(shost);
1460 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1461 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1462 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1463 sas_target_priv_data);
1464 if (sas_device && !sas_target_priv_data->num_luns)
1465 sas_device->starget = NULL;
1468 sas_device_put(sas_device);
1469 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1472 kfree(sdev->hostdata);
1473 sdev->hostdata = NULL;
1477 * _scsih_display_sata_capabilities - sata capabilities
1478 * @ioc: per adapter object
1479 * @handle: device handle
1480 * @sdev: scsi device struct
1483 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1484 u16 handle, struct scsi_device *sdev)
1486 Mpi2ConfigReply_t mpi_reply;
1487 Mpi2SasDevicePage0_t sas_device_pg0;
1492 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1493 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1494 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1495 ioc->name, __FILE__, __LINE__, __func__);
1499 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1500 MPI2_IOCSTATUS_MASK;
1501 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1502 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1503 ioc->name, __FILE__, __LINE__, __func__);
1507 flags = le16_to_cpu(sas_device_pg0.Flags);
1508 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1510 sdev_printk(KERN_INFO, sdev,
1511 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1512 "sw_preserve(%s)\n",
1513 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1515 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1517 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1518 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1519 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1523 * raid transport support -
1524 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1525 * unloading the driver followed by a load - I beleive that the subroutine
1526 * raid_class_release() is not cleaning up properly.
1530 * scsih_is_raid - return boolean indicating device is raid volume
1531 * @dev the device struct object
1534 scsih_is_raid(struct device *dev)
1536 struct scsi_device *sdev = to_scsi_device(dev);
1537 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1539 if (ioc->is_warpdrive)
1541 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1545 * scsih_get_resync - get raid volume resync percent complete
1546 * @dev the device struct object
1549 scsih_get_resync(struct device *dev)
1551 struct scsi_device *sdev = to_scsi_device(dev);
1552 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1553 static struct _raid_device *raid_device;
1554 unsigned long flags;
1555 Mpi2RaidVolPage0_t vol_pg0;
1556 Mpi2ConfigReply_t mpi_reply;
1557 u32 volume_status_flags;
1558 u8 percent_complete;
1561 percent_complete = 0;
1563 if (ioc->is_warpdrive)
1566 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1567 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1570 handle = raid_device->handle;
1571 percent_complete = raid_device->percent_complete;
1573 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1578 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1579 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1580 sizeof(Mpi2RaidVolPage0_t))) {
1581 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1582 ioc->name, __FILE__, __LINE__, __func__);
1583 percent_complete = 0;
1587 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1588 if (!(volume_status_flags &
1589 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1590 percent_complete = 0;
1593 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1594 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1595 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1596 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1600 * scsih_get_state - get raid volume level
1601 * @dev the device struct object
1604 scsih_get_state(struct device *dev)
1606 struct scsi_device *sdev = to_scsi_device(dev);
1607 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1608 static struct _raid_device *raid_device;
1609 unsigned long flags;
1610 Mpi2RaidVolPage0_t vol_pg0;
1611 Mpi2ConfigReply_t mpi_reply;
1613 enum raid_state state = RAID_STATE_UNKNOWN;
1616 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1617 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1620 handle = raid_device->handle;
1621 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1626 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1627 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1628 sizeof(Mpi2RaidVolPage0_t))) {
1629 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1630 ioc->name, __FILE__, __LINE__, __func__);
1634 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1635 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1636 state = RAID_STATE_RESYNCING;
1640 switch (vol_pg0.VolumeState) {
1641 case MPI2_RAID_VOL_STATE_OPTIMAL:
1642 case MPI2_RAID_VOL_STATE_ONLINE:
1643 state = RAID_STATE_ACTIVE;
1645 case MPI2_RAID_VOL_STATE_DEGRADED:
1646 state = RAID_STATE_DEGRADED;
1648 case MPI2_RAID_VOL_STATE_FAILED:
1649 case MPI2_RAID_VOL_STATE_MISSING:
1650 state = RAID_STATE_OFFLINE;
1654 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1655 raid_set_state(mpt2sas_raid_template, dev, state);
1656 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1657 raid_set_state(mpt3sas_raid_template, dev, state);
1661 * _scsih_set_level - set raid level
1662 * @sdev: scsi device struct
1663 * @volume_type: volume type
1666 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1667 struct scsi_device *sdev, u8 volume_type)
1669 enum raid_level level = RAID_LEVEL_UNKNOWN;
1671 switch (volume_type) {
1672 case MPI2_RAID_VOL_TYPE_RAID0:
1673 level = RAID_LEVEL_0;
1675 case MPI2_RAID_VOL_TYPE_RAID10:
1676 level = RAID_LEVEL_10;
1678 case MPI2_RAID_VOL_TYPE_RAID1E:
1679 level = RAID_LEVEL_1E;
1681 case MPI2_RAID_VOL_TYPE_RAID1:
1682 level = RAID_LEVEL_1;
1686 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
1687 raid_set_level(mpt2sas_raid_template,
1688 &sdev->sdev_gendev, level);
1689 if (ioc->hba_mpi_version_belonged == MPI25_VERSION)
1690 raid_set_level(mpt3sas_raid_template,
1691 &sdev->sdev_gendev, level);
1696 * _scsih_get_volume_capabilities - volume capabilities
1697 * @ioc: per adapter object
1698 * @sas_device: the raid_device object
1700 * Returns 0 for success, else 1
1703 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1704 struct _raid_device *raid_device)
1706 Mpi2RaidVolPage0_t *vol_pg0;
1707 Mpi2RaidPhysDiskPage0_t pd_pg0;
1708 Mpi2SasDevicePage0_t sas_device_pg0;
1709 Mpi2ConfigReply_t mpi_reply;
1713 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1714 &num_pds)) || !num_pds) {
1715 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1716 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1721 raid_device->num_pds = num_pds;
1722 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1723 sizeof(Mpi2RaidVol0PhysDisk_t));
1724 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1726 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1727 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1732 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1733 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1734 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1735 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1741 raid_device->volume_type = vol_pg0->VolumeType;
1743 /* figure out what the underlying devices are by
1744 * obtaining the device_info bits for the 1st device
1746 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1747 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1748 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1749 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1750 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1751 le16_to_cpu(pd_pg0.DevHandle)))) {
1752 raid_device->device_info =
1753 le32_to_cpu(sas_device_pg0.DeviceInfo);
1762 * _scsih_enable_tlr - setting TLR flags
1763 * @ioc: per adapter object
1764 * @sdev: scsi device struct
1766 * Enabling Transaction Layer Retries for tape devices when
1767 * vpd page 0x90 is present
1771 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1775 if (sdev->type != TYPE_TAPE)
1778 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1781 sas_enable_tlr(sdev);
1782 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1783 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1789 * scsih_slave_configure - device configure routine.
1790 * @sdev: scsi device struct
1792 * Returns 0 if ok. Any other return is assumed to be an error and
1793 * the device is ignored.
1796 scsih_slave_configure(struct scsi_device *sdev)
1798 struct Scsi_Host *shost = sdev->host;
1799 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1800 struct MPT3SAS_DEVICE *sas_device_priv_data;
1801 struct MPT3SAS_TARGET *sas_target_priv_data;
1802 struct _sas_device *sas_device;
1803 struct _raid_device *raid_device;
1804 unsigned long flags;
1809 u16 handle, volume_handle = 0;
1810 u64 volume_wwid = 0;
1813 sas_device_priv_data = sdev->hostdata;
1814 sas_device_priv_data->configured_lun = 1;
1815 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1816 sas_target_priv_data = sas_device_priv_data->sas_target;
1817 handle = sas_target_priv_data->handle;
1819 /* raid volume handling */
1820 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1822 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1823 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1824 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1826 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1827 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1828 __LINE__, __func__));
1832 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1833 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1834 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1835 __LINE__, __func__));
1840 * WARPDRIVE: Initialize the required data for Direct IO
1842 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1844 /* RAID Queue Depth Support
1845 * IS volume = underlying qdepth of drive type, either
1846 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1847 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1849 if (raid_device->device_info &
1850 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1851 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1854 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1855 if (raid_device->device_info &
1856 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1862 switch (raid_device->volume_type) {
1863 case MPI2_RAID_VOL_TYPE_RAID0:
1866 case MPI2_RAID_VOL_TYPE_RAID1E:
1867 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1868 if (ioc->manu_pg10.OEMIdentifier &&
1869 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1870 MFG10_GF0_R10_DISPLAY) &&
1871 !(raid_device->num_pds % 2))
1876 case MPI2_RAID_VOL_TYPE_RAID1:
1877 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1880 case MPI2_RAID_VOL_TYPE_RAID10:
1881 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1884 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1886 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1891 if (!ioc->hide_ir_msg)
1892 sdev_printk(KERN_INFO, sdev,
1893 "%s: handle(0x%04x), wwid(0x%016llx),"
1894 " pd_count(%d), type(%s)\n",
1895 r_level, raid_device->handle,
1896 (unsigned long long)raid_device->wwid,
1897 raid_device->num_pds, ds);
1899 scsih_change_queue_depth(sdev, qdepth);
1901 /* raid transport support */
1902 if (!ioc->is_warpdrive)
1903 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1907 /* non-raid handling */
1908 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1909 if (mpt3sas_config_get_volume_handle(ioc, handle,
1911 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1912 "failure at %s:%d/%s()!\n", ioc->name,
1913 __FILE__, __LINE__, __func__));
1916 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1917 volume_handle, &volume_wwid)) {
1918 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1919 "failure at %s:%d/%s()!\n", ioc->name,
1920 __FILE__, __LINE__, __func__));
1925 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1926 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1927 sas_device_priv_data->sas_target->sas_address);
1929 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1930 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1931 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1936 sas_device->volume_handle = volume_handle;
1937 sas_device->volume_wwid = volume_wwid;
1938 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1939 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1943 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1944 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1946 else if (sas_device->device_info &
1947 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1951 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1952 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1953 ds, handle, (unsigned long long)sas_device->sas_address,
1954 sas_device->phy, (unsigned long long)sas_device->device_name);
1955 if (sas_device->enclosure_handle != 0)
1956 sdev_printk(KERN_INFO, sdev,
1957 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1958 ds, (unsigned long long)
1959 sas_device->enclosure_logical_id, sas_device->slot);
1960 if (sas_device->connector_name[0] != '\0')
1961 sdev_printk(KERN_INFO, sdev,
1962 "%s: enclosure level(0x%04x), connector name( %s)\n",
1963 ds, sas_device->enclosure_level,
1964 sas_device->connector_name);
1966 sas_device_put(sas_device);
1967 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1970 _scsih_display_sata_capabilities(ioc, handle, sdev);
1973 scsih_change_queue_depth(sdev, qdepth);
1976 sas_read_port_mode_page(sdev);
1977 _scsih_enable_tlr(ioc, sdev);
1984 * scsih_bios_param - fetch head, sector, cylinder info for a disk
1985 * @sdev: scsi device struct
1986 * @bdev: pointer to block device context
1987 * @capacity: device size (in 512 byte sectors)
1988 * @params: three element array to place output:
1989 * params[0] number of heads (max 255)
1990 * params[1] number of sectors (max 63)
1991 * params[2] number of cylinders
1996 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1997 sector_t capacity, int params[])
2007 dummy = heads * sectors;
2008 cylinders = capacity;
2009 sector_div(cylinders, dummy);
2012 * Handle extended translation size for logical drives
2015 if ((ulong)capacity >= 0x200000) {
2018 dummy = heads * sectors;
2019 cylinders = capacity;
2020 sector_div(cylinders, dummy);
2025 params[1] = sectors;
2026 params[2] = cylinders;
2032 * _scsih_response_code - translation of device response code
2033 * @ioc: per adapter object
2034 * @response_code: response code returned by the device
2039 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2043 switch (response_code) {
2044 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2045 desc = "task management request completed";
2047 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2048 desc = "invalid frame";
2050 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2051 desc = "task management request not supported";
2053 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2054 desc = "task management request failed";
2056 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2057 desc = "task management request succeeded";
2059 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2060 desc = "invalid lun";
2063 desc = "overlapped tag attempted";
2065 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2066 desc = "task queued, however not sent to target";
2072 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2073 ioc->name, response_code, desc);
2077 * _scsih_tm_done - tm completion routine
2078 * @ioc: per adapter object
2079 * @smid: system request message index
2080 * @msix_index: MSIX table index supplied by the OS
2081 * @reply: reply message frame(lower 32bit addr)
2084 * The callback handler when using scsih_issue_tm.
2086 * Return 1 meaning mf should be freed from _base_interrupt
2087 * 0 means the mf is freed from this function.
2090 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2092 MPI2DefaultReply_t *mpi_reply;
2094 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2096 if (ioc->tm_cmds.smid != smid)
2098 mpt3sas_base_flush_reply_queues(ioc);
2099 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2100 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2102 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2103 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2105 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2106 complete(&ioc->tm_cmds.done);
2111 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2112 * @ioc: per adapter object
2113 * @handle: device handle
2115 * During taskmangement request, we need to freeze the device queue.
2118 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2120 struct MPT3SAS_DEVICE *sas_device_priv_data;
2121 struct scsi_device *sdev;
2124 shost_for_each_device(sdev, ioc->shost) {
2127 sas_device_priv_data = sdev->hostdata;
2128 if (!sas_device_priv_data)
2130 if (sas_device_priv_data->sas_target->handle == handle) {
2131 sas_device_priv_data->sas_target->tm_busy = 1;
2133 ioc->ignore_loginfos = 1;
2139 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2140 * @ioc: per adapter object
2141 * @handle: device handle
2143 * During taskmangement request, we need to freeze the device queue.
2146 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2148 struct MPT3SAS_DEVICE *sas_device_priv_data;
2149 struct scsi_device *sdev;
2152 shost_for_each_device(sdev, ioc->shost) {
2155 sas_device_priv_data = sdev->hostdata;
2156 if (!sas_device_priv_data)
2158 if (sas_device_priv_data->sas_target->handle == handle) {
2159 sas_device_priv_data->sas_target->tm_busy = 0;
2161 ioc->ignore_loginfos = 0;
2167 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2168 * @ioc: per adapter struct
2169 * @device_handle: device handle
2170 * @channel: the channel assigned by the OS
2171 * @id: the id assigned by the OS
2173 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2174 * @smid_task: smid assigned to the task
2175 * @timeout: timeout in seconds
2176 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2179 * A generic API for sending task management requests to firmware.
2181 * The callback index is set inside `ioc->tm_cb_idx`.
2183 * Return SUCCESS or FAILED.
2186 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2187 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2188 enum mutex_type m_type)
2190 Mpi2SCSITaskManagementRequest_t *mpi_request;
2191 Mpi2SCSITaskManagementReply_t *mpi_reply;
2194 unsigned long timeleft;
2195 struct scsiio_tracker *scsi_lookup = NULL;
2199 if (m_type == TM_MUTEX_ON)
2200 mutex_lock(&ioc->tm_cmds.mutex);
2201 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2202 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2203 __func__, ioc->name);
2208 if (ioc->shost_recovery || ioc->remove_host ||
2209 ioc->pci_error_recovery) {
2210 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2211 __func__, ioc->name);
2216 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2217 if (ioc_state & MPI2_DOORBELL_USED) {
2218 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2219 "unexpected doorbell active!\n", ioc->name));
2220 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2222 rc = (!rc) ? SUCCESS : FAILED;
2226 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2227 mpt3sas_base_fault_info(ioc, ioc_state &
2228 MPI2_DOORBELL_DATA_MASK);
2229 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2231 rc = (!rc) ? SUCCESS : FAILED;
2235 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2237 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2238 ioc->name, __func__);
2243 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2244 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2246 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2247 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2248 ioc->name, handle, type, smid_task));
2249 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2250 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2251 ioc->tm_cmds.smid = smid;
2252 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2253 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2254 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2255 mpi_request->DevHandle = cpu_to_le16(handle);
2256 mpi_request->TaskType = type;
2257 mpi_request->TaskMID = cpu_to_le16(smid_task);
2258 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2259 mpt3sas_scsih_set_tm_flag(ioc, handle);
2260 init_completion(&ioc->tm_cmds.done);
2261 if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
2262 (scsi_lookup->msix_io < ioc->reply_queue_count))
2263 msix_task = scsi_lookup->msix_io;
2266 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2267 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2268 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2269 pr_err(MPT3SAS_FMT "%s: timeout\n",
2270 ioc->name, __func__);
2271 _debug_dump_mf(mpi_request,
2272 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2273 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2274 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2276 rc = (!rc) ? SUCCESS : FAILED;
2277 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2278 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2283 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2284 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2285 mpi_reply = ioc->tm_cmds.reply;
2286 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2287 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2288 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2289 le32_to_cpu(mpi_reply->IOCLogInfo),
2290 le32_to_cpu(mpi_reply->TerminationCount)));
2291 if (ioc->logging_level & MPT_DEBUG_TM) {
2292 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2293 if (mpi_reply->IOCStatus)
2294 _debug_dump_mf(mpi_request,
2295 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2300 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2302 if (scsi_lookup->scmd == NULL)
2307 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2308 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2313 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2314 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2315 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2320 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2328 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2329 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2330 if (m_type == TM_MUTEX_ON)
2331 mutex_unlock(&ioc->tm_cmds.mutex);
2336 if (m_type == TM_MUTEX_ON)
2337 mutex_unlock(&ioc->tm_cmds.mutex);
2342 * _scsih_tm_display_info - displays info about the device
2343 * @ioc: per adapter struct
2344 * @scmd: pointer to scsi command object
2346 * Called by task management callback handlers.
2349 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2351 struct scsi_target *starget = scmd->device->sdev_target;
2352 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2353 struct _sas_device *sas_device = NULL;
2354 unsigned long flags;
2355 char *device_str = NULL;
2359 if (ioc->hide_ir_msg)
2360 device_str = "WarpDrive";
2362 device_str = "volume";
2364 scsi_print_command(scmd);
2365 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2366 starget_printk(KERN_INFO, starget,
2367 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2368 device_str, priv_target->handle,
2369 device_str, (unsigned long long)priv_target->sas_address);
2371 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2372 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2374 if (priv_target->flags &
2375 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2376 starget_printk(KERN_INFO, starget,
2377 "volume handle(0x%04x), "
2378 "volume wwid(0x%016llx)\n",
2379 sas_device->volume_handle,
2380 (unsigned long long)sas_device->volume_wwid);
2382 starget_printk(KERN_INFO, starget,
2383 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2385 (unsigned long long)sas_device->sas_address,
2387 if (sas_device->enclosure_handle != 0)
2388 starget_printk(KERN_INFO, starget,
2389 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2390 (unsigned long long)
2391 sas_device->enclosure_logical_id,
2393 if (sas_device->connector_name)
2394 starget_printk(KERN_INFO, starget,
2395 "enclosure level(0x%04x),connector name(%s)\n",
2396 sas_device->enclosure_level,
2397 sas_device->connector_name);
2399 sas_device_put(sas_device);
2401 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2406 * scsih_abort - eh threads main abort routine
2407 * @scmd: pointer to scsi command object
2409 * Returns SUCCESS if command aborted else FAILED
2412 scsih_abort(struct scsi_cmnd *scmd)
2414 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2415 struct MPT3SAS_DEVICE *sas_device_priv_data;
2420 sdev_printk(KERN_INFO, scmd->device,
2421 "attempting task abort! scmd(%p)\n", scmd);
2422 _scsih_tm_display_info(ioc, scmd);
2424 sas_device_priv_data = scmd->device->hostdata;
2425 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2426 sdev_printk(KERN_INFO, scmd->device,
2427 "device been deleted! scmd(%p)\n", scmd);
2428 scmd->result = DID_NO_CONNECT << 16;
2429 scmd->scsi_done(scmd);
2434 /* search for the command */
2435 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2437 scmd->result = DID_RESET << 16;
2442 /* for hidden raid components and volumes this is not supported */
2443 if (sas_device_priv_data->sas_target->flags &
2444 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2445 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2446 scmd->result = DID_RESET << 16;
2451 mpt3sas_halt_firmware(ioc);
2453 handle = sas_device_priv_data->sas_target->handle;
2454 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2455 scmd->device->id, scmd->device->lun,
2456 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2459 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2460 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2465 * scsih_dev_reset - eh threads main device reset routine
2466 * @scmd: pointer to scsi command object
2468 * Returns SUCCESS if command aborted else FAILED
2471 scsih_dev_reset(struct scsi_cmnd *scmd)
2473 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2474 struct MPT3SAS_DEVICE *sas_device_priv_data;
2475 struct _sas_device *sas_device = NULL;
2479 struct scsi_target *starget = scmd->device->sdev_target;
2480 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2482 sdev_printk(KERN_INFO, scmd->device,
2483 "attempting device reset! scmd(%p)\n", scmd);
2484 _scsih_tm_display_info(ioc, scmd);
2486 sas_device_priv_data = scmd->device->hostdata;
2487 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2488 sdev_printk(KERN_INFO, scmd->device,
2489 "device been deleted! scmd(%p)\n", scmd);
2490 scmd->result = DID_NO_CONNECT << 16;
2491 scmd->scsi_done(scmd);
2496 /* for hidden raid components obtain the volume_handle */
2498 if (sas_device_priv_data->sas_target->flags &
2499 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2500 sas_device = mpt3sas_get_sdev_from_target(ioc,
2503 handle = sas_device->volume_handle;
2505 handle = sas_device_priv_data->sas_target->handle;
2508 scmd->result = DID_RESET << 16;
2513 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2514 scmd->device->id, scmd->device->lun,
2515 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2518 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2519 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2522 sas_device_put(sas_device);
2528 * scsih_target_reset - eh threads main target reset routine
2529 * @scmd: pointer to scsi command object
2531 * Returns SUCCESS if command aborted else FAILED
2534 scsih_target_reset(struct scsi_cmnd *scmd)
2536 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2537 struct MPT3SAS_DEVICE *sas_device_priv_data;
2538 struct _sas_device *sas_device = NULL;
2541 struct scsi_target *starget = scmd->device->sdev_target;
2542 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2544 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2546 _scsih_tm_display_info(ioc, scmd);
2548 sas_device_priv_data = scmd->device->hostdata;
2549 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2550 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2552 scmd->result = DID_NO_CONNECT << 16;
2553 scmd->scsi_done(scmd);
2558 /* for hidden raid components obtain the volume_handle */
2560 if (sas_device_priv_data->sas_target->flags &
2561 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2562 sas_device = mpt3sas_get_sdev_from_target(ioc,
2565 handle = sas_device->volume_handle;
2567 handle = sas_device_priv_data->sas_target->handle;
2570 scmd->result = DID_RESET << 16;
2575 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2576 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2580 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2581 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2584 sas_device_put(sas_device);
2591 * scsih_host_reset - eh threads main host reset routine
2592 * @scmd: pointer to scsi command object
2594 * Returns SUCCESS if command aborted else FAILED
2597 scsih_host_reset(struct scsi_cmnd *scmd)
2599 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2602 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2604 scsi_print_command(scmd);
2606 if (ioc->is_driver_loading) {
2607 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2613 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2615 r = (retval < 0) ? FAILED : SUCCESS;
2617 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2618 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2624 * _scsih_fw_event_add - insert and queue up fw_event
2625 * @ioc: per adapter object
2626 * @fw_event: object describing the event
2627 * Context: This function will acquire ioc->fw_event_lock.
2629 * This adds the firmware event object into link list, then queues it up to
2630 * be processed from user context.
2635 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2637 unsigned long flags;
2639 if (ioc->firmware_event_thread == NULL)
2642 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2643 fw_event_work_get(fw_event);
2644 INIT_LIST_HEAD(&fw_event->list);
2645 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2646 INIT_WORK(&fw_event->work, _firmware_event_work);
2647 fw_event_work_get(fw_event);
2648 queue_work(ioc->firmware_event_thread, &fw_event->work);
2649 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2653 * _scsih_fw_event_del_from_list - delete fw_event from the list
2654 * @ioc: per adapter object
2655 * @fw_event: object describing the event
2656 * Context: This function will acquire ioc->fw_event_lock.
2658 * If the fw_event is on the fw_event_list, remove it and do a put.
2663 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2666 unsigned long flags;
2668 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2669 if (!list_empty(&fw_event->list)) {
2670 list_del_init(&fw_event->list);
2671 fw_event_work_put(fw_event);
2673 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2678 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2679 * @ioc: per adapter object
2680 * @event_data: trigger event data
2685 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2686 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2688 struct fw_event_work *fw_event;
2691 if (ioc->is_driver_loading)
2693 sz = sizeof(*event_data);
2694 fw_event = alloc_fw_event_work(sz);
2697 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2698 fw_event->ioc = ioc;
2699 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2700 _scsih_fw_event_add(ioc, fw_event);
2701 fw_event_work_put(fw_event);
2705 * _scsih_error_recovery_delete_devices - remove devices not responding
2706 * @ioc: per adapter object
2711 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2713 struct fw_event_work *fw_event;
2715 if (ioc->is_driver_loading)
2717 fw_event = alloc_fw_event_work(0);
2720 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2721 fw_event->ioc = ioc;
2722 _scsih_fw_event_add(ioc, fw_event);
2723 fw_event_work_put(fw_event);
2727 * mpt3sas_port_enable_complete - port enable completed (fake event)
2728 * @ioc: per adapter object
2733 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2735 struct fw_event_work *fw_event;
2737 fw_event = alloc_fw_event_work(0);
2740 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2741 fw_event->ioc = ioc;
2742 _scsih_fw_event_add(ioc, fw_event);
2743 fw_event_work_put(fw_event);
2746 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2748 unsigned long flags;
2749 struct fw_event_work *fw_event = NULL;
2751 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2752 if (!list_empty(&ioc->fw_event_list)) {
2753 fw_event = list_first_entry(&ioc->fw_event_list,
2754 struct fw_event_work, list);
2755 list_del_init(&fw_event->list);
2757 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2763 * _scsih_fw_event_cleanup_queue - cleanup event queue
2764 * @ioc: per adapter object
2766 * Walk the firmware event queue, either killing timers, or waiting
2767 * for outstanding events to complete
2772 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2774 struct fw_event_work *fw_event;
2776 if (list_empty(&ioc->fw_event_list) ||
2777 !ioc->firmware_event_thread || in_interrupt())
2780 while ((fw_event = dequeue_next_fw_event(ioc))) {
2782 * Wait on the fw_event to complete. If this returns 1, then
2783 * the event was never executed, and we need a put for the
2784 * reference the delayed_work had on the fw_event.
2786 * If it did execute, we wait for it to finish, and the put will
2787 * happen from _firmware_event_work()
2789 if (cancel_delayed_work_sync(&fw_event->delayed_work))
2790 fw_event_work_put(fw_event);
2792 fw_event_work_put(fw_event);
2797 * _scsih_internal_device_block - block the sdev device
2798 * @sdev: per device object
2799 * @sas_device_priv_data : per device driver private data
2801 * make sure device is blocked without error, if not
2805 _scsih_internal_device_block(struct scsi_device *sdev,
2806 struct MPT3SAS_DEVICE *sas_device_priv_data)
2810 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2811 sas_device_priv_data->sas_target->handle);
2812 sas_device_priv_data->block = 1;
2814 r = scsi_internal_device_block(sdev);
2816 sdev_printk(KERN_WARNING, sdev,
2817 "device_block failed with return(%d) for handle(0x%04x)\n",
2818 sas_device_priv_data->sas_target->handle, r);
2822 * _scsih_internal_device_unblock - unblock the sdev device
2823 * @sdev: per device object
2824 * @sas_device_priv_data : per device driver private data
2825 * make sure device is unblocked without error, if not retry
2826 * by blocking and then unblocking
2830 _scsih_internal_device_unblock(struct scsi_device *sdev,
2831 struct MPT3SAS_DEVICE *sas_device_priv_data)
2835 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2836 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2837 sas_device_priv_data->block = 0;
2838 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2840 /* The device has been set to SDEV_RUNNING by SD layer during
2841 * device addition but the request queue is still stopped by
2842 * our earlier block call. We need to perform a block again
2843 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2845 sdev_printk(KERN_WARNING, sdev,
2846 "device_unblock failed with return(%d) for handle(0x%04x) "
2847 "performing a block followed by an unblock\n",
2848 sas_device_priv_data->sas_target->handle, r);
2849 sas_device_priv_data->block = 1;
2850 r = scsi_internal_device_block(sdev);
2852 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2853 "failed with return(%d) for handle(0x%04x)\n",
2854 sas_device_priv_data->sas_target->handle, r);
2856 sas_device_priv_data->block = 0;
2857 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2859 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2860 " failed with return(%d) for handle(0x%04x)\n",
2861 sas_device_priv_data->sas_target->handle, r);
2866 * _scsih_ublock_io_all_device - unblock every device
2867 * @ioc: per adapter object
2869 * change the device state from block to running
2872 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2874 struct MPT3SAS_DEVICE *sas_device_priv_data;
2875 struct scsi_device *sdev;
2877 shost_for_each_device(sdev, ioc->shost) {
2878 sas_device_priv_data = sdev->hostdata;
2879 if (!sas_device_priv_data)
2881 if (!sas_device_priv_data->block)
2884 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2885 "device_running, handle(0x%04x)\n",
2886 sas_device_priv_data->sas_target->handle));
2887 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2893 * _scsih_ublock_io_device - prepare device to be deleted
2894 * @ioc: per adapter object
2895 * @sas_addr: sas address
2897 * unblock then put device in offline state
2900 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2902 struct MPT3SAS_DEVICE *sas_device_priv_data;
2903 struct scsi_device *sdev;
2905 shost_for_each_device(sdev, ioc->shost) {
2906 sas_device_priv_data = sdev->hostdata;
2907 if (!sas_device_priv_data)
2909 if (sas_device_priv_data->sas_target->sas_address
2912 if (sas_device_priv_data->block)
2913 _scsih_internal_device_unblock(sdev,
2914 sas_device_priv_data);
2919 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2920 * @ioc: per adapter object
2921 * @handle: device handle
2923 * During device pull we need to appropiately set the sdev state.
2926 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2928 struct MPT3SAS_DEVICE *sas_device_priv_data;
2929 struct scsi_device *sdev;
2931 shost_for_each_device(sdev, ioc->shost) {
2932 sas_device_priv_data = sdev->hostdata;
2933 if (!sas_device_priv_data)
2935 if (sas_device_priv_data->block)
2937 _scsih_internal_device_block(sdev, sas_device_priv_data);
2942 * _scsih_block_io_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_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2951 struct MPT3SAS_DEVICE *sas_device_priv_data;
2952 struct scsi_device *sdev;
2953 struct _sas_device *sas_device;
2955 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2959 shost_for_each_device(sdev, ioc->shost) {
2960 sas_device_priv_data = sdev->hostdata;
2961 if (!sas_device_priv_data)
2963 if (sas_device_priv_data->sas_target->handle != handle)
2965 if (sas_device_priv_data->block)
2967 if (sas_device->pend_sas_rphy_add)
2969 _scsih_internal_device_block(sdev, sas_device_priv_data);
2972 sas_device_put(sas_device);
2976 * _scsih_block_io_to_children_attached_to_ex
2977 * @ioc: per adapter object
2978 * @sas_expander: the sas_device object
2980 * This routine set sdev state to SDEV_BLOCK for all devices
2981 * attached to this expander. This function called when expander is
2985 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
2986 struct _sas_node *sas_expander)
2988 struct _sas_port *mpt3sas_port;
2989 struct _sas_device *sas_device;
2990 struct _sas_node *expander_sibling;
2991 unsigned long flags;
2996 list_for_each_entry(mpt3sas_port,
2997 &sas_expander->sas_port_list, port_list) {
2998 if (mpt3sas_port->remote_identify.device_type ==
3000 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3001 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3002 mpt3sas_port->remote_identify.sas_address);
3004 set_bit(sas_device->handle,
3005 ioc->blocking_handles);
3006 sas_device_put(sas_device);
3008 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3012 list_for_each_entry(mpt3sas_port,
3013 &sas_expander->sas_port_list, port_list) {
3015 if (mpt3sas_port->remote_identify.device_type ==
3016 SAS_EDGE_EXPANDER_DEVICE ||
3017 mpt3sas_port->remote_identify.device_type ==
3018 SAS_FANOUT_EXPANDER_DEVICE) {
3020 mpt3sas_scsih_expander_find_by_sas_address(
3021 ioc, mpt3sas_port->remote_identify.sas_address);
3022 _scsih_block_io_to_children_attached_to_ex(ioc,
3029 * _scsih_block_io_to_children_attached_directly
3030 * @ioc: per adapter object
3031 * @event_data: topology change event data
3033 * This routine set sdev state to SDEV_BLOCK for all devices
3034 * direct attached during device pull.
3037 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3038 Mpi2EventDataSasTopologyChangeList_t *event_data)
3044 for (i = 0; i < event_data->NumEntries; i++) {
3045 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3048 reason_code = event_data->PHY[i].PhyStatus &
3049 MPI2_EVENT_SAS_TOPO_RC_MASK;
3050 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3051 _scsih_block_io_device(ioc, handle);
3056 * _scsih_tm_tr_send - send task management request
3057 * @ioc: per adapter object
3058 * @handle: device handle
3059 * Context: interrupt time.
3061 * This code is to initiate the device removal handshake protocol
3062 * with controller firmware. This function will issue target reset
3063 * using high priority request queue. It will send a sas iounit
3064 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3066 * This is designed to send muliple task management request at the same
3067 * time to the fifo. If the fifo is full, we will append the request,
3068 * and process it in a future completion.
3071 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3073 Mpi2SCSITaskManagementRequest_t *mpi_request;
3075 struct _sas_device *sas_device = NULL;
3076 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3077 u64 sas_address = 0;
3078 unsigned long flags;
3079 struct _tr_list *delayed_tr;
3082 if (ioc->remove_host) {
3083 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3084 "%s: host has been removed: handle(0x%04x)\n",
3085 __func__, ioc->name, handle));
3087 } else if (ioc->pci_error_recovery) {
3088 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3089 "%s: host in pci error recovery: handle(0x%04x)\n",
3090 __func__, ioc->name,
3094 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3095 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3096 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3097 "%s: host is not operational: handle(0x%04x)\n",
3098 __func__, ioc->name,
3103 /* if PD, then return */
3104 if (test_bit(handle, ioc->pd_handles))
3107 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3108 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3109 if (sas_device && sas_device->starget &&
3110 sas_device->starget->hostdata) {
3111 sas_target_priv_data = sas_device->starget->hostdata;
3112 sas_target_priv_data->deleted = 1;
3113 sas_address = sas_device->sas_address;
3115 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3117 if (sas_target_priv_data) {
3118 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3119 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3121 (unsigned long long)sas_address));
3122 if (sas_device->enclosure_handle != 0)
3123 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3124 "setting delete flag:enclosure logical id(0x%016llx),"
3125 " slot(%d)\n", ioc->name, (unsigned long long)
3126 sas_device->enclosure_logical_id,
3128 if (sas_device->connector_name)
3129 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3130 "setting delete flag: enclosure level(0x%04x),"
3131 " connector name( %s)\n", ioc->name,
3132 sas_device->enclosure_level,
3133 sas_device->connector_name));
3134 _scsih_ublock_io_device(ioc, sas_address);
3135 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3138 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3140 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3143 INIT_LIST_HEAD(&delayed_tr->list);
3144 delayed_tr->handle = handle;
3145 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3146 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3147 "DELAYED:tr:handle(0x%04x), (open)\n",
3148 ioc->name, handle));
3152 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3153 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3154 ioc->name, handle, smid,
3155 ioc->tm_tr_cb_idx));
3156 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3157 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3158 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3159 mpi_request->DevHandle = cpu_to_le16(handle);
3160 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3161 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3162 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3166 sas_device_put(sas_device);
3170 * _scsih_tm_tr_complete -
3171 * @ioc: per adapter object
3172 * @smid: system request message index
3173 * @msix_index: MSIX table index supplied by the OS
3174 * @reply: reply message frame(lower 32bit addr)
3175 * Context: interrupt time.
3177 * This is the target reset completion routine.
3178 * This code is part of the code to initiate the device removal
3179 * handshake protocol with controller firmware.
3180 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3182 * Return 1 meaning mf should be freed from _base_interrupt
3183 * 0 means the mf is freed from this function.
3186 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3190 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3191 Mpi2SCSITaskManagementReply_t *mpi_reply =
3192 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3193 Mpi2SasIoUnitControlRequest_t *mpi_request;
3197 if (ioc->remove_host) {
3198 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3199 "%s: host has been removed\n", __func__, ioc->name));
3201 } else if (ioc->pci_error_recovery) {
3202 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3203 "%s: host in pci error recovery\n", __func__,
3207 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3208 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3209 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3210 "%s: host is not operational\n", __func__, ioc->name));
3213 if (unlikely(!mpi_reply)) {
3214 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3215 ioc->name, __FILE__, __LINE__, __func__);
3218 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3219 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3220 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3221 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3222 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3224 le16_to_cpu(mpi_reply->DevHandle), smid));
3228 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3229 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3230 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3231 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3232 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3233 le32_to_cpu(mpi_reply->IOCLogInfo),
3234 le32_to_cpu(mpi_reply->TerminationCount)));
3236 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3237 if (!smid_sas_ctrl) {
3238 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3239 ioc->name, __func__);
3243 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3244 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3245 ioc->name, handle, smid_sas_ctrl,
3246 ioc->tm_sas_control_cb_idx));
3247 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3248 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3249 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3250 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3251 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3252 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3254 return _scsih_check_for_pending_tm(ioc, smid);
3259 * _scsih_sas_control_complete - completion routine
3260 * @ioc: per adapter object
3261 * @smid: system request message index
3262 * @msix_index: MSIX table index supplied by the OS
3263 * @reply: reply message frame(lower 32bit addr)
3264 * Context: interrupt time.
3266 * This is the sas iounit control completion routine.
3267 * This code is part of the code to initiate the device removal
3268 * handshake protocol with controller firmware.
3270 * Return 1 meaning mf should be freed from _base_interrupt
3271 * 0 means the mf is freed from this function.
3274 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3275 u8 msix_index, u32 reply)
3277 Mpi2SasIoUnitControlReply_t *mpi_reply =
3278 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3280 if (likely(mpi_reply)) {
3281 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3282 "sc_complete:handle(0x%04x), (open) "
3283 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3284 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3285 le16_to_cpu(mpi_reply->IOCStatus),
3286 le32_to_cpu(mpi_reply->IOCLogInfo)));
3288 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3289 ioc->name, __FILE__, __LINE__, __func__);
3295 * _scsih_tm_tr_volume_send - send target reset request for volumes
3296 * @ioc: per adapter object
3297 * @handle: device handle
3298 * Context: interrupt time.
3300 * This is designed to send muliple task management request at the same
3301 * time to the fifo. If the fifo is full, we will append the request,
3302 * and process it in a future completion.
3305 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3307 Mpi2SCSITaskManagementRequest_t *mpi_request;
3309 struct _tr_list *delayed_tr;
3311 if (ioc->shost_recovery || ioc->remove_host ||
3312 ioc->pci_error_recovery) {
3313 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3314 "%s: host reset in progress!\n",
3315 __func__, ioc->name));
3319 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3321 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3324 INIT_LIST_HEAD(&delayed_tr->list);
3325 delayed_tr->handle = handle;
3326 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3327 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3328 "DELAYED:tr:handle(0x%04x), (open)\n",
3329 ioc->name, handle));
3333 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3334 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3335 ioc->name, handle, smid,
3336 ioc->tm_tr_volume_cb_idx));
3337 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3338 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3339 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3340 mpi_request->DevHandle = cpu_to_le16(handle);
3341 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3342 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3346 * _scsih_tm_volume_tr_complete - target reset completion
3347 * @ioc: per adapter object
3348 * @smid: system request message index
3349 * @msix_index: MSIX table index supplied by the OS
3350 * @reply: reply message frame(lower 32bit addr)
3351 * Context: interrupt time.
3353 * Return 1 meaning mf should be freed from _base_interrupt
3354 * 0 means the mf is freed from this function.
3357 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3358 u8 msix_index, u32 reply)
3361 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3362 Mpi2SCSITaskManagementReply_t *mpi_reply =
3363 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3365 if (ioc->shost_recovery || ioc->remove_host ||
3366 ioc->pci_error_recovery) {
3367 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3368 "%s: host reset in progress!\n",
3369 __func__, ioc->name));
3372 if (unlikely(!mpi_reply)) {
3373 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3374 ioc->name, __FILE__, __LINE__, __func__);
3378 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3379 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3380 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3381 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3382 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3384 le16_to_cpu(mpi_reply->DevHandle), smid));
3388 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3389 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3390 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3391 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3392 le32_to_cpu(mpi_reply->IOCLogInfo),
3393 le32_to_cpu(mpi_reply->TerminationCount)));
3395 return _scsih_check_for_pending_tm(ioc, smid);
3400 * _scsih_check_for_pending_tm - check for pending task management
3401 * @ioc: per adapter object
3402 * @smid: system request message index
3404 * This will check delayed target reset list, and feed the
3407 * Return 1 meaning mf should be freed from _base_interrupt
3408 * 0 means the mf is freed from this function.
3411 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3413 struct _tr_list *delayed_tr;
3415 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3416 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3417 struct _tr_list, list);
3418 mpt3sas_base_free_smid(ioc, smid);
3419 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3420 list_del(&delayed_tr->list);
3425 if (!list_empty(&ioc->delayed_tr_list)) {
3426 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3427 struct _tr_list, list);
3428 mpt3sas_base_free_smid(ioc, smid);
3429 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3430 list_del(&delayed_tr->list);
3439 * _scsih_check_topo_delete_events - sanity check on topo events
3440 * @ioc: per adapter object
3441 * @event_data: the event data payload
3443 * This routine added to better handle cable breaker.
3445 * This handles the case where driver receives multiple expander
3446 * add and delete events in a single shot. When there is a delete event
3447 * the routine will void any pending add events waiting in the event queue.
3452 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3453 Mpi2EventDataSasTopologyChangeList_t *event_data)
3455 struct fw_event_work *fw_event;
3456 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3457 u16 expander_handle;
3458 struct _sas_node *sas_expander;
3459 unsigned long flags;
3463 for (i = 0 ; i < event_data->NumEntries; i++) {
3464 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3467 reason_code = event_data->PHY[i].PhyStatus &
3468 MPI2_EVENT_SAS_TOPO_RC_MASK;
3469 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3470 _scsih_tm_tr_send(ioc, handle);
3473 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3474 if (expander_handle < ioc->sas_hba.num_phys) {
3475 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3478 if (event_data->ExpStatus ==
3479 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3480 /* put expander attached devices into blocking state */
3481 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3482 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3484 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3485 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3487 handle = find_first_bit(ioc->blocking_handles,
3488 ioc->facts.MaxDevHandle);
3489 if (handle < ioc->facts.MaxDevHandle)
3490 _scsih_block_io_device(ioc, handle);
3491 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3492 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3493 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3495 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3498 /* mark ignore flag for pending events */
3499 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3500 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3501 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3504 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3505 fw_event->event_data;
3506 if (local_event_data->ExpStatus ==
3507 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3508 local_event_data->ExpStatus ==
3509 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3510 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3512 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3513 "setting ignoring flag\n", ioc->name));
3514 fw_event->ignore = 1;
3518 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3522 * _scsih_set_volume_delete_flag - setting volume delete flag
3523 * @ioc: per adapter object
3524 * @handle: device handle
3526 * This returns nothing.
3529 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3531 struct _raid_device *raid_device;
3532 struct MPT3SAS_TARGET *sas_target_priv_data;
3533 unsigned long flags;
3535 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3536 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3537 if (raid_device && raid_device->starget &&
3538 raid_device->starget->hostdata) {
3539 sas_target_priv_data =
3540 raid_device->starget->hostdata;
3541 sas_target_priv_data->deleted = 1;
3542 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3543 "setting delete flag: handle(0x%04x), "
3544 "wwid(0x%016llx)\n", ioc->name, handle,
3545 (unsigned long long) raid_device->wwid));
3547 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3551 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3552 * @handle: input handle
3553 * @a: handle for volume a
3554 * @b: handle for volume b
3556 * IR firmware only supports two raid volumes. The purpose of this
3557 * routine is to set the volume handle in either a or b. When the given
3558 * input handle is non-zero, or when a and b have not been set before.
3561 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3563 if (!handle || handle == *a || handle == *b)
3572 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3573 * @ioc: per adapter object
3574 * @event_data: the event data payload
3575 * Context: interrupt time.
3577 * This routine will send target reset to volume, followed by target
3578 * resets to the PDs. This is called when a PD has been removed, or
3579 * volume has been deleted or removed. When the target reset is sent
3580 * to volume, the PD target resets need to be queued to start upon
3581 * completion of the volume target reset.
3586 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3587 Mpi2EventDataIrConfigChangeList_t *event_data)
3589 Mpi2EventIrConfigElement_t *element;
3591 u16 handle, volume_handle, a, b;
3592 struct _tr_list *delayed_tr;
3597 if (ioc->is_warpdrive)
3600 /* Volume Resets for Deleted or Removed */
3601 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3602 for (i = 0; i < event_data->NumElements; i++, element++) {
3603 if (le32_to_cpu(event_data->Flags) &
3604 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3606 if (element->ReasonCode ==
3607 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3608 element->ReasonCode ==
3609 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3610 volume_handle = le16_to_cpu(element->VolDevHandle);
3611 _scsih_set_volume_delete_flag(ioc, volume_handle);
3612 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3616 /* Volume Resets for UNHIDE events */
3617 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3618 for (i = 0; i < event_data->NumElements; i++, element++) {
3619 if (le32_to_cpu(event_data->Flags) &
3620 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3622 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3623 volume_handle = le16_to_cpu(element->VolDevHandle);
3624 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3629 _scsih_tm_tr_volume_send(ioc, a);
3631 _scsih_tm_tr_volume_send(ioc, b);
3633 /* PD target resets */
3634 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3635 for (i = 0; i < event_data->NumElements; i++, element++) {
3636 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3638 handle = le16_to_cpu(element->PhysDiskDevHandle);
3639 volume_handle = le16_to_cpu(element->VolDevHandle);
3640 clear_bit(handle, ioc->pd_handles);
3642 _scsih_tm_tr_send(ioc, handle);
3643 else if (volume_handle == a || volume_handle == b) {
3644 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3645 BUG_ON(!delayed_tr);
3646 INIT_LIST_HEAD(&delayed_tr->list);
3647 delayed_tr->handle = handle;
3648 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3649 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3650 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3653 _scsih_tm_tr_send(ioc, handle);
3659 * _scsih_check_volume_delete_events - set delete flag for volumes
3660 * @ioc: per adapter object
3661 * @event_data: the event data payload
3662 * Context: interrupt time.
3664 * This will handle the case when the cable connected to entire volume is
3665 * pulled. We will take care of setting the deleted flag so normal IO will
3671 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3672 Mpi2EventDataIrVolume_t *event_data)
3676 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3678 state = le32_to_cpu(event_data->NewValue);
3679 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3680 MPI2_RAID_VOL_STATE_FAILED)
3681 _scsih_set_volume_delete_flag(ioc,
3682 le16_to_cpu(event_data->VolDevHandle));
3686 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3687 * @ioc: per adapter object
3688 * @event_data: the temp threshold event data
3689 * Context: interrupt time.
3694 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3695 Mpi2EventDataTemperature_t *event_data)
3697 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3698 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3699 " exceeded for Sensor: %d !!!\n", ioc->name,
3700 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3701 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3702 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3703 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3704 event_data->SensorNum);
3705 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3706 ioc->name, event_data->CurrentTemperature);
3710 static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
3712 return (scmd->cmnd[0] == ATA_12 || scmd->cmnd[0] == ATA_16);
3716 * _scsih_flush_running_cmds - completing outstanding commands.
3717 * @ioc: per adapter object
3719 * The flushing out of all pending scmd commands following host reset,
3720 * where all IO is dropped to the floor.
3725 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3727 struct scsi_cmnd *scmd;
3731 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3732 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3736 if (ata_12_16_cmd(scmd))
3737 scsi_internal_device_unblock(scmd->device,
3739 mpt3sas_base_free_smid(ioc, smid);
3740 scsi_dma_unmap(scmd);
3741 if (ioc->pci_error_recovery)
3742 scmd->result = DID_NO_CONNECT << 16;
3744 scmd->result = DID_RESET << 16;
3745 scmd->scsi_done(scmd);
3747 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3752 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3753 * @ioc: per adapter object
3754 * @scmd: pointer to scsi command object
3755 * @mpi_request: pointer to the SCSI_IO reqest message frame
3757 * Supporting protection 1 and 3.
3762 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3763 Mpi2SCSIIORequest_t *mpi_request)
3766 unsigned char prot_op = scsi_get_prot_op(scmd);
3767 unsigned char prot_type = scsi_get_prot_type(scmd);
3768 Mpi25SCSIIORequest_t *mpi_request_3v =
3769 (Mpi25SCSIIORequest_t *)mpi_request;
3771 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3774 if (prot_op == SCSI_PROT_READ_STRIP)
3775 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3776 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3777 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3781 switch (prot_type) {
3782 case SCSI_PROT_DIF_TYPE1:
3783 case SCSI_PROT_DIF_TYPE2:
3786 * enable ref/guard checking
3787 * auto increment ref tag
3789 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3790 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3791 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3792 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3793 cpu_to_be32(scsi_get_lba(scmd));
3796 case SCSI_PROT_DIF_TYPE3:
3799 * enable guard checking
3801 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3806 mpi_request_3v->EEDPBlockSize =
3807 cpu_to_le16(scmd->device->sector_size);
3808 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3812 * _scsih_eedp_error_handling - return sense code for EEDP errors
3813 * @scmd: pointer to scsi command object
3814 * @ioc_status: ioc status
3819 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3823 switch (ioc_status) {
3824 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3827 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3830 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3837 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3839 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3840 SAM_STAT_CHECK_CONDITION;
3844 * scsih_qcmd - main scsi request entry point
3845 * @scmd: pointer to scsi command object
3846 * @done: function pointer to be invoked on completion
3848 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3850 * Returns 0 on success. If there's a failure, return either:
3851 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3852 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3855 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3857 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3858 struct MPT3SAS_DEVICE *sas_device_priv_data;
3859 struct MPT3SAS_TARGET *sas_target_priv_data;
3860 struct _raid_device *raid_device;
3861 Mpi2SCSIIORequest_t *mpi_request;
3866 if (ioc->logging_level & MPT_DEBUG_SCSI)
3867 scsi_print_command(scmd);
3870 * Lock the device for any subsequent command until command is
3873 if (ata_12_16_cmd(scmd))
3874 scsi_internal_device_block(scmd->device);
3876 sas_device_priv_data = scmd->device->hostdata;
3877 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3878 scmd->result = DID_NO_CONNECT << 16;
3879 scmd->scsi_done(scmd);
3883 if (ioc->pci_error_recovery || ioc->remove_host) {
3884 scmd->result = DID_NO_CONNECT << 16;
3885 scmd->scsi_done(scmd);
3889 sas_target_priv_data = sas_device_priv_data->sas_target;
3891 /* invalid device handle */
3892 handle = sas_target_priv_data->handle;
3893 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3894 scmd->result = DID_NO_CONNECT << 16;
3895 scmd->scsi_done(scmd);
3900 /* host recovery or link resets sent via IOCTLs */
3901 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3902 return SCSI_MLQUEUE_HOST_BUSY;
3904 /* device has been deleted */
3905 else if (sas_target_priv_data->deleted) {
3906 scmd->result = DID_NO_CONNECT << 16;
3907 scmd->scsi_done(scmd);
3909 /* device busy with task managment */
3910 } else if (sas_target_priv_data->tm_busy ||
3911 sas_device_priv_data->block)
3912 return SCSI_MLQUEUE_DEVICE_BUSY;
3914 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3915 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3916 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3917 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3919 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3922 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3924 /* Make sure Device is not raid volume.
3925 * We do not expose raid functionality to upper layer for warpdrive.
3927 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
3928 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3929 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3931 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3933 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3934 ioc->name, __func__);
3937 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3938 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3939 _scsih_setup_eedp(ioc, scmd, mpi_request);
3941 if (scmd->cmd_len == 32)
3942 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3943 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3944 if (sas_device_priv_data->sas_target->flags &
3945 MPT_TARGET_FLAGS_RAID_COMPONENT)
3946 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3948 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3949 mpi_request->DevHandle = cpu_to_le16(handle);
3950 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3951 mpi_request->Control = cpu_to_le32(mpi_control);
3952 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3953 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3954 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3955 mpi_request->SenseBufferLowAddress =
3956 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
3957 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3958 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3960 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3962 if (mpi_request->DataLength) {
3963 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
3964 mpt3sas_base_free_smid(ioc, smid);
3968 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
3970 raid_device = sas_target_priv_data->raid_device;
3971 if (raid_device && raid_device->direct_io_enabled)
3972 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3975 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
3976 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
3977 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
3978 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
3979 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
3981 mpt3sas_base_put_smid_scsi_io(ioc, smid,
3982 le16_to_cpu(mpi_request->DevHandle));
3984 mpt3sas_base_put_smid_default(ioc, smid);
3988 return SCSI_MLQUEUE_HOST_BUSY;
3992 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3993 * @sense_buffer: sense data returned by target
3994 * @data: normalized skey/asc/ascq
3999 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4001 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4002 /* descriptor format */
4003 data->skey = sense_buffer[1] & 0x0F;
4004 data->asc = sense_buffer[2];
4005 data->ascq = sense_buffer[3];
4008 data->skey = sense_buffer[2] & 0x0F;
4009 data->asc = sense_buffer[12];
4010 data->ascq = sense_buffer[13];
4015 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4016 * @ioc: per adapter object
4017 * @scmd: pointer to scsi command object
4018 * @mpi_reply: reply mf payload returned from firmware
4020 * scsi_status - SCSI Status code returned from target device
4021 * scsi_state - state info associated with SCSI_IO determined by ioc
4022 * ioc_status - ioc supplied status info
4027 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4028 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4032 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4033 MPI2_IOCSTATUS_MASK;
4034 u8 scsi_state = mpi_reply->SCSIState;
4035 u8 scsi_status = mpi_reply->SCSIStatus;
4036 char *desc_ioc_state = NULL;
4037 char *desc_scsi_status = NULL;
4038 char *desc_scsi_state = ioc->tmp_string;
4039 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4040 struct _sas_device *sas_device = NULL;
4041 struct scsi_target *starget = scmd->device->sdev_target;
4042 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4043 char *device_str = NULL;
4047 if (ioc->hide_ir_msg)
4048 device_str = "WarpDrive";
4050 device_str = "volume";
4052 if (log_info == 0x31170000)
4055 switch (ioc_status) {
4056 case MPI2_IOCSTATUS_SUCCESS:
4057 desc_ioc_state = "success";
4059 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4060 desc_ioc_state = "invalid function";
4062 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4063 desc_ioc_state = "scsi recovered error";
4065 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4066 desc_ioc_state = "scsi invalid dev handle";
4068 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4069 desc_ioc_state = "scsi device not there";
4071 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4072 desc_ioc_state = "scsi data overrun";
4074 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4075 desc_ioc_state = "scsi data underrun";
4077 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4078 desc_ioc_state = "scsi io data error";
4080 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4081 desc_ioc_state = "scsi protocol error";
4083 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4084 desc_ioc_state = "scsi task terminated";
4086 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4087 desc_ioc_state = "scsi residual mismatch";
4089 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4090 desc_ioc_state = "scsi task mgmt failed";
4092 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4093 desc_ioc_state = "scsi ioc terminated";
4095 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4096 desc_ioc_state = "scsi ext terminated";
4098 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4099 desc_ioc_state = "eedp guard error";
4101 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4102 desc_ioc_state = "eedp ref tag error";
4104 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4105 desc_ioc_state = "eedp app tag error";
4108 desc_ioc_state = "unknown";
4112 switch (scsi_status) {
4113 case MPI2_SCSI_STATUS_GOOD:
4114 desc_scsi_status = "good";
4116 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4117 desc_scsi_status = "check condition";
4119 case MPI2_SCSI_STATUS_CONDITION_MET:
4120 desc_scsi_status = "condition met";
4122 case MPI2_SCSI_STATUS_BUSY:
4123 desc_scsi_status = "busy";
4125 case MPI2_SCSI_STATUS_INTERMEDIATE:
4126 desc_scsi_status = "intermediate";
4128 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4129 desc_scsi_status = "intermediate condmet";
4131 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4132 desc_scsi_status = "reservation conflict";
4134 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4135 desc_scsi_status = "command terminated";
4137 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4138 desc_scsi_status = "task set full";
4140 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4141 desc_scsi_status = "aca active";
4143 case MPI2_SCSI_STATUS_TASK_ABORTED:
4144 desc_scsi_status = "task aborted";
4147 desc_scsi_status = "unknown";
4151 desc_scsi_state[0] = '\0';
4153 desc_scsi_state = " ";
4154 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4155 strcat(desc_scsi_state, "response info ");
4156 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4157 strcat(desc_scsi_state, "state terminated ");
4158 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4159 strcat(desc_scsi_state, "no status ");
4160 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4161 strcat(desc_scsi_state, "autosense failed ");
4162 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4163 strcat(desc_scsi_state, "autosense valid ");
4165 scsi_print_command(scmd);
4167 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4168 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4169 device_str, (unsigned long long)priv_target->sas_address);
4171 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4174 "\tsas_address(0x%016llx), phy(%d)\n",
4175 ioc->name, (unsigned long long)
4176 sas_device->sas_address, sas_device->phy);
4177 if (sas_device->enclosure_handle != 0)
4179 "\tenclosure_logical_id(0x%016llx),"
4180 "slot(%d)\n", ioc->name,
4181 (unsigned long long)
4182 sas_device->enclosure_logical_id,
4184 if (sas_device->connector_name[0])
4186 "\tenclosure level(0x%04x),"
4187 " connector name( %s)\n", ioc->name,
4188 sas_device->enclosure_level,
4189 sas_device->connector_name);
4191 sas_device_put(sas_device);
4196 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4197 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4198 desc_ioc_state, ioc_status, smid);
4200 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4201 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4202 scsi_get_resid(scmd));
4204 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4205 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4206 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4208 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4209 ioc->name, desc_scsi_status,
4210 scsi_status, desc_scsi_state, scsi_state);
4212 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4213 struct sense_info data;
4214 _scsih_normalize_sense(scmd->sense_buffer, &data);
4216 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4217 ioc->name, data.skey,
4218 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4221 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4222 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4223 response_bytes = (u8 *)&response_info;
4224 _scsih_response_code(ioc, response_bytes[0]);
4229 * _scsih_turn_on_pfa_led - illuminate PFA LED
4230 * @ioc: per adapter object
4231 * @handle: device handle
4237 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4239 Mpi2SepReply_t mpi_reply;
4240 Mpi2SepRequest_t mpi_request;
4241 struct _sas_device *sas_device;
4243 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4247 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4248 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4249 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4250 mpi_request.SlotStatus =
4251 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4252 mpi_request.DevHandle = cpu_to_le16(handle);
4253 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4254 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4255 &mpi_request)) != 0) {
4256 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4257 __FILE__, __LINE__, __func__);
4260 sas_device->pfa_led_on = 1;
4262 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4263 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4264 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4265 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4266 le32_to_cpu(mpi_reply.IOCLogInfo)));
4270 sas_device_put(sas_device);
4274 * _scsih_turn_off_pfa_led - turn off Fault LED
4275 * @ioc: per adapter object
4276 * @sas_device: sas device whose PFA LED has to turned off
4282 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4283 struct _sas_device *sas_device)
4285 Mpi2SepReply_t mpi_reply;
4286 Mpi2SepRequest_t mpi_request;
4288 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4289 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4290 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4291 mpi_request.SlotStatus = 0;
4292 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4293 mpi_request.DevHandle = 0;
4294 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4295 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4296 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4297 &mpi_request)) != 0) {
4298 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4299 __FILE__, __LINE__, __func__);
4303 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4304 dewtprintk(ioc, printk(MPT3SAS_FMT
4305 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4306 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4307 le32_to_cpu(mpi_reply.IOCLogInfo)));
4313 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4314 * @ioc: per adapter object
4315 * @handle: device handle
4316 * Context: interrupt.
4321 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4323 struct fw_event_work *fw_event;
4325 fw_event = alloc_fw_event_work(0);
4328 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4329 fw_event->device_handle = handle;
4330 fw_event->ioc = ioc;
4331 _scsih_fw_event_add(ioc, fw_event);
4332 fw_event_work_put(fw_event);
4336 * _scsih_smart_predicted_fault - process smart errors
4337 * @ioc: per adapter object
4338 * @handle: device handle
4339 * Context: interrupt.
4344 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4346 struct scsi_target *starget;
4347 struct MPT3SAS_TARGET *sas_target_priv_data;
4348 Mpi2EventNotificationReply_t *event_reply;
4349 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4350 struct _sas_device *sas_device;
4352 unsigned long flags;
4354 /* only handle non-raid devices */
4355 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4356 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4360 starget = sas_device->starget;
4361 sas_target_priv_data = starget->hostdata;
4363 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4364 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4367 if (sas_device->enclosure_handle != 0)
4368 starget_printk(KERN_INFO, starget, "predicted fault, "
4369 "enclosure logical id(0x%016llx), slot(%d)\n",
4370 (unsigned long long)sas_device->enclosure_logical_id,
4372 if (sas_device->connector_name[0] != '\0')
4373 starget_printk(KERN_WARNING, starget, "predicted fault, "
4374 "enclosure level(0x%04x), connector name( %s)\n",
4375 sas_device->enclosure_level,
4376 sas_device->connector_name);
4377 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4379 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4380 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4382 /* insert into event log */
4383 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4384 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4385 event_reply = kzalloc(sz, GFP_KERNEL);
4387 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4388 ioc->name, __FILE__, __LINE__, __func__);
4392 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4393 event_reply->Event =
4394 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4395 event_reply->MsgLength = sz/4;
4396 event_reply->EventDataLength =
4397 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4398 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4399 event_reply->EventData;
4400 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4401 event_data->ASC = 0x5D;
4402 event_data->DevHandle = cpu_to_le16(handle);
4403 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4404 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4408 sas_device_put(sas_device);
4412 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4417 * _scsih_io_done - scsi request callback
4418 * @ioc: per adapter object
4419 * @smid: system request message index
4420 * @msix_index: MSIX table index supplied by the OS
4421 * @reply: reply message frame(lower 32bit addr)
4423 * Callback handler when using _scsih_qcmd.
4425 * Return 1 meaning mf should be freed from _base_interrupt
4426 * 0 means the mf is freed from this function.
4429 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4431 Mpi2SCSIIORequest_t *mpi_request;
4432 Mpi2SCSIIOReply_t *mpi_reply;
4433 struct scsi_cmnd *scmd;
4439 struct MPT3SAS_DEVICE *sas_device_priv_data;
4440 u32 response_code = 0;
4441 unsigned long flags;
4443 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4444 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4448 if (ata_12_16_cmd(scmd))
4449 scsi_internal_device_unblock(scmd->device, SDEV_RUNNING);
4451 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4453 if (mpi_reply == NULL) {
4454 scmd->result = DID_OK << 16;
4458 sas_device_priv_data = scmd->device->hostdata;
4459 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4460 sas_device_priv_data->sas_target->deleted) {
4461 scmd->result = DID_NO_CONNECT << 16;
4464 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4467 * WARPDRIVE: If direct_io is set then it is directIO,
4468 * the failed direct I/O should be redirected to volume
4470 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4471 ((ioc_status & MPI2_IOCSTATUS_MASK)
4472 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4473 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4474 ioc->scsi_lookup[smid - 1].scmd = scmd;
4475 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4476 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4477 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4478 mpi_request->DevHandle =
4479 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4480 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4481 sas_device_priv_data->sas_target->handle);
4484 /* turning off TLR */
4485 scsi_state = mpi_reply->SCSIState;
4486 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4488 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4489 if (!sas_device_priv_data->tlr_snoop_check) {
4490 sas_device_priv_data->tlr_snoop_check++;
4491 if (!ioc->is_warpdrive &&
4492 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4493 sas_is_tlr_enabled(scmd->device) &&
4494 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4495 sas_disable_tlr(scmd->device);
4496 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4500 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4501 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4502 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4503 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4506 ioc_status &= MPI2_IOCSTATUS_MASK;
4507 scsi_status = mpi_reply->SCSIStatus;
4509 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4510 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4511 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4512 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4513 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4516 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4517 struct sense_info data;
4518 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4520 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4521 le32_to_cpu(mpi_reply->SenseCount));
4522 memcpy(scmd->sense_buffer, sense_data, sz);
4523 _scsih_normalize_sense(scmd->sense_buffer, &data);
4524 /* failure prediction threshold exceeded */
4525 if (data.asc == 0x5D)
4526 _scsih_smart_predicted_fault(ioc,
4527 le16_to_cpu(mpi_reply->DevHandle));
4528 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4530 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
4531 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4532 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4533 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4534 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4536 switch (ioc_status) {
4537 case MPI2_IOCSTATUS_BUSY:
4538 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4539 scmd->result = SAM_STAT_BUSY;
4542 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4543 scmd->result = DID_NO_CONNECT << 16;
4546 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4547 if (sas_device_priv_data->block) {
4548 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4551 if (log_info == 0x31110630) {
4552 if (scmd->retries > 2) {
4553 scmd->result = DID_NO_CONNECT << 16;
4554 scsi_device_set_state(scmd->device,
4557 scmd->result = DID_SOFT_ERROR << 16;
4558 scmd->device->expecting_cc_ua = 1;
4561 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4562 scmd->result = DID_RESET << 16;
4565 scmd->result = DID_SOFT_ERROR << 16;
4567 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4568 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4569 scmd->result = DID_RESET << 16;
4572 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4573 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4574 scmd->result = DID_SOFT_ERROR << 16;
4576 scmd->result = (DID_OK << 16) | scsi_status;
4579 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4580 scmd->result = (DID_OK << 16) | scsi_status;
4582 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4585 if (xfer_cnt < scmd->underflow) {
4586 if (scsi_status == SAM_STAT_BUSY)
4587 scmd->result = SAM_STAT_BUSY;
4589 scmd->result = DID_SOFT_ERROR << 16;
4590 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4591 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4592 scmd->result = DID_SOFT_ERROR << 16;
4593 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4594 scmd->result = DID_RESET << 16;
4595 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4596 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4597 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4598 scmd->result = (DRIVER_SENSE << 24) |
4599 SAM_STAT_CHECK_CONDITION;
4600 scmd->sense_buffer[0] = 0x70;
4601 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4602 scmd->sense_buffer[12] = 0x20;
4603 scmd->sense_buffer[13] = 0;
4607 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4608 scsi_set_resid(scmd, 0);
4609 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4610 case MPI2_IOCSTATUS_SUCCESS:
4611 scmd->result = (DID_OK << 16) | scsi_status;
4612 if (response_code ==
4613 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4614 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4615 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4616 scmd->result = DID_SOFT_ERROR << 16;
4617 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4618 scmd->result = DID_RESET << 16;
4621 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4622 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4623 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4624 _scsih_eedp_error_handling(scmd, ioc_status);
4627 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4628 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4629 case MPI2_IOCSTATUS_INVALID_SGL:
4630 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4631 case MPI2_IOCSTATUS_INVALID_FIELD:
4632 case MPI2_IOCSTATUS_INVALID_STATE:
4633 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4634 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4636 scmd->result = DID_SOFT_ERROR << 16;
4641 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4642 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4646 scsi_dma_unmap(scmd);
4648 scmd->scsi_done(scmd);
4653 * _scsih_sas_host_refresh - refreshing sas host object contents
4654 * @ioc: per adapter object
4657 * During port enable, fw will send topology events for every device. Its
4658 * possible that the handles may change from the previous setting, so this
4659 * code keeping handles updating if changed.
4664 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4669 Mpi2ConfigReply_t mpi_reply;
4670 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4671 u16 attached_handle;
4674 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4675 "updating handles for sas_host(0x%016llx)\n",
4676 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4678 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4679 * sizeof(Mpi2SasIOUnit0PhyData_t));
4680 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4681 if (!sas_iounit_pg0) {
4682 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4683 ioc->name, __FILE__, __LINE__, __func__);
4687 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4688 sas_iounit_pg0, sz)) != 0)
4690 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4691 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4693 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4694 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4696 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4697 PhyData[0].ControllerDevHandle);
4698 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4699 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4701 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4702 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4703 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4704 attached_handle, i, link_rate);
4707 kfree(sas_iounit_pg0);
4711 * _scsih_sas_host_add - create sas host object
4712 * @ioc: per adapter object
4714 * Creating host side data object, stored in ioc->sas_hba
4719 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4722 Mpi2ConfigReply_t mpi_reply;
4723 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4724 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4725 Mpi2SasPhyPage0_t phy_pg0;
4726 Mpi2SasDevicePage0_t sas_device_pg0;
4727 Mpi2SasEnclosurePage0_t enclosure_pg0;
4730 u8 device_missing_delay;
4732 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4733 if (!ioc->sas_hba.num_phys) {
4734 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4735 ioc->name, __FILE__, __LINE__, __func__);
4739 /* sas_iounit page 0 */
4740 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4741 sizeof(Mpi2SasIOUnit0PhyData_t));
4742 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4743 if (!sas_iounit_pg0) {
4744 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4745 ioc->name, __FILE__, __LINE__, __func__);
4748 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4749 sas_iounit_pg0, sz))) {
4750 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4755 MPI2_IOCSTATUS_MASK;
4756 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4757 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4758 ioc->name, __FILE__, __LINE__, __func__);
4762 /* sas_iounit page 1 */
4763 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4764 sizeof(Mpi2SasIOUnit1PhyData_t));
4765 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4766 if (!sas_iounit_pg1) {
4767 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4768 ioc->name, __FILE__, __LINE__, __func__);
4771 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4772 sas_iounit_pg1, sz))) {
4773 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4774 ioc->name, __FILE__, __LINE__, __func__);
4777 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4778 MPI2_IOCSTATUS_MASK;
4779 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4780 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4781 ioc->name, __FILE__, __LINE__, __func__);
4785 ioc->io_missing_delay =
4786 sas_iounit_pg1->IODeviceMissingDelay;
4787 device_missing_delay =
4788 sas_iounit_pg1->ReportDeviceMissingDelay;
4789 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4790 ioc->device_missing_delay = (device_missing_delay &
4791 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4793 ioc->device_missing_delay = device_missing_delay &
4794 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4796 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4797 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4798 sizeof(struct _sas_phy), GFP_KERNEL);
4799 if (!ioc->sas_hba.phy) {
4800 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4801 ioc->name, __FILE__, __LINE__, __func__);
4804 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4805 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4807 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4808 ioc->name, __FILE__, __LINE__, __func__);
4811 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4812 MPI2_IOCSTATUS_MASK;
4813 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4814 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4815 ioc->name, __FILE__, __LINE__, __func__);
4820 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4821 PhyData[0].ControllerDevHandle);
4822 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4823 ioc->sas_hba.phy[i].phy_id = i;
4824 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4825 phy_pg0, ioc->sas_hba.parent_dev);
4827 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4828 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4829 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4830 ioc->name, __FILE__, __LINE__, __func__);
4833 ioc->sas_hba.enclosure_handle =
4834 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4835 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4837 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4838 ioc->name, ioc->sas_hba.handle,
4839 (unsigned long long) ioc->sas_hba.sas_address,
4840 ioc->sas_hba.num_phys) ;
4842 if (ioc->sas_hba.enclosure_handle) {
4843 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4844 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4845 ioc->sas_hba.enclosure_handle)))
4846 ioc->sas_hba.enclosure_logical_id =
4847 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4851 kfree(sas_iounit_pg1);
4852 kfree(sas_iounit_pg0);
4856 * _scsih_expander_add - creating expander object
4857 * @ioc: per adapter object
4858 * @handle: expander handle
4860 * Creating expander object, stored in ioc->sas_expander_list.
4862 * Return 0 for success, else error.
4865 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4867 struct _sas_node *sas_expander;
4868 Mpi2ConfigReply_t mpi_reply;
4869 Mpi2ExpanderPage0_t expander_pg0;
4870 Mpi2ExpanderPage1_t expander_pg1;
4871 Mpi2SasEnclosurePage0_t enclosure_pg0;
4874 u64 sas_address, sas_address_parent = 0;
4876 unsigned long flags;
4877 struct _sas_port *mpt3sas_port = NULL;
4884 if (ioc->shost_recovery || ioc->pci_error_recovery)
4887 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4888 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4889 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4890 ioc->name, __FILE__, __LINE__, __func__);
4894 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4895 MPI2_IOCSTATUS_MASK;
4896 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4897 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4898 ioc->name, __FILE__, __LINE__, __func__);
4902 /* handle out of order topology events */
4903 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4904 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4906 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4907 ioc->name, __FILE__, __LINE__, __func__);
4910 if (sas_address_parent != ioc->sas_hba.sas_address) {
4911 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4912 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4913 sas_address_parent);
4914 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4915 if (!sas_expander) {
4916 rc = _scsih_expander_add(ioc, parent_handle);
4922 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4923 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4924 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4926 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4931 sas_expander = kzalloc(sizeof(struct _sas_node),
4933 if (!sas_expander) {
4934 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4935 ioc->name, __FILE__, __LINE__, __func__);
4939 sas_expander->handle = handle;
4940 sas_expander->num_phys = expander_pg0.NumPhys;
4941 sas_expander->sas_address_parent = sas_address_parent;
4942 sas_expander->sas_address = sas_address;
4944 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
4945 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4946 handle, parent_handle, (unsigned long long)
4947 sas_expander->sas_address, sas_expander->num_phys);
4949 if (!sas_expander->num_phys)
4951 sas_expander->phy = kcalloc(sas_expander->num_phys,
4952 sizeof(struct _sas_phy), GFP_KERNEL);
4953 if (!sas_expander->phy) {
4954 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4955 ioc->name, __FILE__, __LINE__, __func__);
4960 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4961 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
4962 sas_address_parent);
4963 if (!mpt3sas_port) {
4964 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4965 ioc->name, __FILE__, __LINE__, __func__);
4969 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
4971 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4972 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
4973 &expander_pg1, i, handle))) {
4974 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4975 ioc->name, __FILE__, __LINE__, __func__);
4979 sas_expander->phy[i].handle = handle;
4980 sas_expander->phy[i].phy_id = i;
4982 if ((mpt3sas_transport_add_expander_phy(ioc,
4983 &sas_expander->phy[i], expander_pg1,
4984 sas_expander->parent_dev))) {
4985 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4986 ioc->name, __FILE__, __LINE__, __func__);
4992 if (sas_expander->enclosure_handle) {
4993 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4994 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4995 sas_expander->enclosure_handle)))
4996 sas_expander->enclosure_logical_id =
4997 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5000 _scsih_expander_node_add(ioc, sas_expander);
5006 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5007 sas_address_parent);
5008 kfree(sas_expander);
5013 * mpt3sas_expander_remove - removing expander object
5014 * @ioc: per adapter object
5015 * @sas_address: expander sas_address
5020 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5022 struct _sas_node *sas_expander;
5023 unsigned long flags;
5025 if (ioc->shost_recovery)
5028 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5029 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5032 list_del(&sas_expander->list);
5033 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5035 _scsih_expander_node_remove(ioc, sas_expander);
5039 * _scsih_done - internal SCSI_IO callback handler.
5040 * @ioc: per adapter object
5041 * @smid: system request message index
5042 * @msix_index: MSIX table index supplied by the OS
5043 * @reply: reply message frame(lower 32bit addr)
5045 * Callback handler when sending internal generated SCSI_IO.
5046 * The callback index passed is `ioc->scsih_cb_idx`
5048 * Return 1 meaning mf should be freed from _base_interrupt
5049 * 0 means the mf is freed from this function.
5052 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5054 MPI2DefaultReply_t *mpi_reply;
5056 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5057 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5059 if (ioc->scsih_cmds.smid != smid)
5061 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5063 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5064 mpi_reply->MsgLength*4);
5065 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5067 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5068 complete(&ioc->scsih_cmds.done);
5075 #define MPT3_MAX_LUNS (255)
5079 * _scsih_check_access_status - check access flags
5080 * @ioc: per adapter object
5081 * @sas_address: sas address
5082 * @handle: sas device handle
5083 * @access_flags: errors returned during discovery of the device
5085 * Return 0 for success, else failure
5088 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5089 u16 handle, u8 access_status)
5094 switch (access_status) {
5095 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5100 desc = "sata capability failed";
5102 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5103 desc = "sata affiliation conflict";
5105 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5106 desc = "route not addressable";
5108 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5109 desc = "smp error not addressable";
5111 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5112 desc = "device blocked";
5114 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5115 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5116 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5117 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5118 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5119 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5120 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5121 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5122 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5123 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5124 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5125 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5126 desc = "sata initialization failed";
5137 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5138 ioc->name, desc, (unsigned long long)sas_address, handle);
5143 * _scsih_check_device - checking device responsiveness
5144 * @ioc: per adapter object
5145 * @parent_sas_address: sas address of parent expander or sas host
5146 * @handle: attached device handle
5147 * @phy_numberv: phy number
5148 * @link_rate: new link rate
5153 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5154 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5156 Mpi2ConfigReply_t mpi_reply;
5157 Mpi2SasDevicePage0_t sas_device_pg0;
5158 struct _sas_device *sas_device;
5160 unsigned long flags;
5162 struct scsi_target *starget;
5163 struct MPT3SAS_TARGET *sas_target_priv_data;
5167 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5168 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5171 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5172 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5175 /* wide port handling ~ we need only handle device once for the phy that
5176 * is matched in sas device page zero
5178 if (phy_number != sas_device_pg0.PhyNum)
5181 /* check if this is end device */
5182 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5183 if (!(_scsih_is_end_device(device_info)))
5186 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5187 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5188 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5194 if (unlikely(sas_device->handle != handle)) {
5195 starget = sas_device->starget;
5196 sas_target_priv_data = starget->hostdata;
5197 starget_printk(KERN_INFO, starget,
5198 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5199 sas_device->handle, handle);
5200 sas_target_priv_data->handle = handle;
5201 sas_device->handle = handle;
5202 if (sas_device_pg0.Flags &
5203 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5204 sas_device->enclosure_level =
5205 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5206 memcpy(&sas_device->connector_name[0],
5207 &sas_device_pg0.ConnectorName[0], 4);
5209 sas_device->enclosure_level = 0;
5210 sas_device->connector_name[0] = '\0';
5214 /* check if device is present */
5215 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5216 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5218 "device is not present handle(0x%04x), flags!!!\n",
5223 /* check if there were any issues with discovery */
5224 if (_scsih_check_access_status(ioc, sas_address, handle,
5225 sas_device_pg0.AccessStatus))
5228 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5229 _scsih_ublock_io_device(ioc, sas_address);
5232 sas_device_put(sas_device);
5236 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5238 sas_device_put(sas_device);
5242 * _scsih_add_device - creating sas device object
5243 * @ioc: per adapter object
5244 * @handle: sas device handle
5245 * @phy_num: phy number end device attached to
5246 * @is_pd: is this hidden raid component
5248 * Creating end device object, stored in ioc->sas_device_list.
5250 * Returns 0 for success, non-zero for failure.
5253 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5256 Mpi2ConfigReply_t mpi_reply;
5257 Mpi2SasDevicePage0_t sas_device_pg0;
5258 Mpi2SasEnclosurePage0_t enclosure_pg0;
5259 struct _sas_device *sas_device;
5264 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5265 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5266 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5267 ioc->name, __FILE__, __LINE__, __func__);
5271 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5272 MPI2_IOCSTATUS_MASK;
5273 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5274 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5275 ioc->name, __FILE__, __LINE__, __func__);
5279 /* check if this is end device */
5280 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5281 if (!(_scsih_is_end_device(device_info)))
5283 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5285 /* check if device is present */
5286 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5287 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5288 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5293 /* check if there were any issues with discovery */
5294 if (_scsih_check_access_status(ioc, sas_address, handle,
5295 sas_device_pg0.AccessStatus))
5298 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5301 sas_device_put(sas_device);
5305 sas_device = kzalloc(sizeof(struct _sas_device),
5308 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5309 ioc->name, __FILE__, __LINE__, __func__);
5313 kref_init(&sas_device->refcount);
5314 sas_device->handle = handle;
5315 if (_scsih_get_sas_address(ioc,
5316 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5317 &sas_device->sas_address_parent) != 0)
5318 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5319 ioc->name, __FILE__, __LINE__, __func__);
5320 sas_device->enclosure_handle =
5321 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5322 if (sas_device->enclosure_handle != 0)
5324 le16_to_cpu(sas_device_pg0.Slot);
5325 sas_device->device_info = device_info;
5326 sas_device->sas_address = sas_address;
5327 sas_device->phy = sas_device_pg0.PhyNum;
5328 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5329 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5331 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5332 sas_device->enclosure_level =
5333 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5334 memcpy(&sas_device->connector_name[0],
5335 &sas_device_pg0.ConnectorName[0], 4);
5337 sas_device->enclosure_level = 0;
5338 sas_device->connector_name[0] = '\0';
5340 /* get enclosure_logical_id */
5341 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5342 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5343 sas_device->enclosure_handle)))
5344 sas_device->enclosure_logical_id =
5345 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5347 /* get device name */
5348 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5350 if (ioc->wait_for_discovery_to_complete)
5351 _scsih_sas_device_init_add(ioc, sas_device);
5353 _scsih_sas_device_add(ioc, sas_device);
5355 sas_device_put(sas_device);
5360 * _scsih_remove_device - removing sas device object
5361 * @ioc: per adapter object
5362 * @sas_device_delete: the sas_device object
5367 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5368 struct _sas_device *sas_device)
5370 struct MPT3SAS_TARGET *sas_target_priv_data;
5372 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5373 (sas_device->pfa_led_on)) {
5374 _scsih_turn_off_pfa_led(ioc, sas_device);
5375 sas_device->pfa_led_on = 0;
5377 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5378 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5379 ioc->name, __func__,
5380 sas_device->handle, (unsigned long long)
5381 sas_device->sas_address));
5382 if (sas_device->enclosure_handle != 0)
5383 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5384 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5385 ioc->name, __func__,
5386 (unsigned long long)sas_device->enclosure_logical_id,
5388 if (sas_device->connector_name[0] != '\0')
5389 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5390 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5391 ioc->name, __func__,
5392 sas_device->enclosure_level,
5393 sas_device->connector_name));
5395 if (sas_device->starget && sas_device->starget->hostdata) {
5396 sas_target_priv_data = sas_device->starget->hostdata;
5397 sas_target_priv_data->deleted = 1;
5398 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5399 sas_target_priv_data->handle =
5400 MPT3SAS_INVALID_DEVICE_HANDLE;
5403 if (!ioc->hide_drives)
5404 mpt3sas_transport_port_remove(ioc,
5405 sas_device->sas_address,
5406 sas_device->sas_address_parent);
5409 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5410 ioc->name, sas_device->handle,
5411 (unsigned long long) sas_device->sas_address);
5412 if (sas_device->enclosure_handle != 0)
5414 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5416 (unsigned long long)sas_device->enclosure_logical_id,
5418 if (sas_device->connector_name[0] != '\0')
5420 "removing enclosure level(0x%04x), connector name( %s)\n",
5421 ioc->name, sas_device->enclosure_level,
5422 sas_device->connector_name);
5424 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5425 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5426 ioc->name, __func__,
5427 sas_device->handle, (unsigned long long)
5428 sas_device->sas_address));
5429 if (sas_device->enclosure_handle != 0)
5430 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5431 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5432 ioc->name, __func__,
5433 (unsigned long long)sas_device->enclosure_logical_id,
5435 if (sas_device->connector_name[0] != '\0')
5436 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5437 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5438 ioc->name, __func__, sas_device->enclosure_level,
5439 sas_device->connector_name));
5443 * _scsih_sas_topology_change_event_debug - debug for topology event
5444 * @ioc: per adapter object
5445 * @event_data: event data payload
5449 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5450 Mpi2EventDataSasTopologyChangeList_t *event_data)
5456 char *status_str = NULL;
5457 u8 link_rate, prev_link_rate;
5459 switch (event_data->ExpStatus) {
5460 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5463 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5464 status_str = "remove";
5466 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5468 status_str = "responding";
5470 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5471 status_str = "remove delay";
5474 status_str = "unknown status";
5477 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5478 ioc->name, status_str);
5479 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5480 "start_phy(%02d), count(%d)\n",
5481 le16_to_cpu(event_data->ExpanderDevHandle),
5482 le16_to_cpu(event_data->EnclosureHandle),
5483 event_data->StartPhyNum, event_data->NumEntries);
5484 for (i = 0; i < event_data->NumEntries; i++) {
5485 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5488 phy_number = event_data->StartPhyNum + i;
5489 reason_code = event_data->PHY[i].PhyStatus &
5490 MPI2_EVENT_SAS_TOPO_RC_MASK;
5491 switch (reason_code) {
5492 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5493 status_str = "target add";
5495 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5496 status_str = "target remove";
5498 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5499 status_str = "delay target remove";
5501 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5502 status_str = "link rate change";
5504 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5505 status_str = "target responding";
5508 status_str = "unknown";
5511 link_rate = event_data->PHY[i].LinkRate >> 4;
5512 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5513 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5514 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5515 handle, status_str, link_rate, prev_link_rate);
5521 * _scsih_sas_topology_change_event - handle topology changes
5522 * @ioc: per adapter object
5523 * @fw_event: The fw_event_work object
5528 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5529 struct fw_event_work *fw_event)
5532 u16 parent_handle, handle;
5534 u8 phy_number, max_phys;
5535 struct _sas_node *sas_expander;
5537 unsigned long flags;
5538 u8 link_rate, prev_link_rate;
5539 Mpi2EventDataSasTopologyChangeList_t *event_data =
5540 (Mpi2EventDataSasTopologyChangeList_t *)
5541 fw_event->event_data;
5543 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5544 _scsih_sas_topology_change_event_debug(ioc, event_data);
5546 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5549 if (!ioc->sas_hba.num_phys)
5550 _scsih_sas_host_add(ioc);
5552 _scsih_sas_host_refresh(ioc);
5554 if (fw_event->ignore) {
5555 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5556 "ignoring expander event\n", ioc->name));
5560 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5562 /* handle expander add */
5563 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5564 if (_scsih_expander_add(ioc, parent_handle) != 0)
5567 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5568 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5571 sas_address = sas_expander->sas_address;
5572 max_phys = sas_expander->num_phys;
5573 } else if (parent_handle < ioc->sas_hba.num_phys) {
5574 sas_address = ioc->sas_hba.sas_address;
5575 max_phys = ioc->sas_hba.num_phys;
5577 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5580 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5582 /* handle siblings events */
5583 for (i = 0; i < event_data->NumEntries; i++) {
5584 if (fw_event->ignore) {
5585 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5586 "ignoring expander event\n", ioc->name));
5589 if (ioc->remove_host || ioc->pci_error_recovery)
5591 phy_number = event_data->StartPhyNum + i;
5592 if (phy_number >= max_phys)
5594 reason_code = event_data->PHY[i].PhyStatus &
5595 MPI2_EVENT_SAS_TOPO_RC_MASK;
5596 if ((event_data->PHY[i].PhyStatus &
5597 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5598 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5600 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5603 link_rate = event_data->PHY[i].LinkRate >> 4;
5604 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5605 switch (reason_code) {
5606 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5608 if (ioc->shost_recovery)
5611 if (link_rate == prev_link_rate)
5614 mpt3sas_transport_update_links(ioc, sas_address,
5615 handle, phy_number, link_rate);
5617 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5620 _scsih_check_device(ioc, sas_address, handle,
5621 phy_number, link_rate);
5624 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5626 if (ioc->shost_recovery)
5629 mpt3sas_transport_update_links(ioc, sas_address,
5630 handle, phy_number, link_rate);
5632 _scsih_add_device(ioc, handle, phy_number, 0);
5635 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5637 _scsih_device_remove_by_handle(ioc, handle);
5642 /* handle expander removal */
5643 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5645 mpt3sas_expander_remove(ioc, sas_address);
5651 * _scsih_sas_device_status_change_event_debug - debug for device event
5652 * @event_data: event data payload
5658 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5659 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5661 char *reason_str = NULL;
5663 switch (event_data->ReasonCode) {
5664 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5665 reason_str = "smart data";
5667 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5668 reason_str = "unsupported device discovered";
5670 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5671 reason_str = "internal device reset";
5673 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5674 reason_str = "internal task abort";
5676 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5677 reason_str = "internal task abort set";
5679 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5680 reason_str = "internal clear task set";
5682 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5683 reason_str = "internal query task";
5685 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5686 reason_str = "sata init failure";
5688 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5689 reason_str = "internal device reset complete";
5691 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5692 reason_str = "internal task abort complete";
5694 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5695 reason_str = "internal async notification";
5697 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5698 reason_str = "expander reduced functionality";
5700 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5701 reason_str = "expander reduced functionality complete";
5704 reason_str = "unknown reason";
5707 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5708 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5709 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5710 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5711 le16_to_cpu(event_data->TaskTag));
5712 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5713 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5714 event_data->ASC, event_data->ASCQ);
5719 * _scsih_sas_device_status_change_event - handle device status change
5720 * @ioc: per adapter object
5721 * @fw_event: The fw_event_work object
5727 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5728 struct fw_event_work *fw_event)
5730 struct MPT3SAS_TARGET *target_priv_data;
5731 struct _sas_device *sas_device;
5733 unsigned long flags;
5734 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5735 (Mpi2EventDataSasDeviceStatusChange_t *)
5736 fw_event->event_data;
5738 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5739 _scsih_sas_device_status_change_event_debug(ioc,
5742 /* In MPI Revision K (0xC), the internal device reset complete was
5743 * implemented, so avoid setting tm_busy flag for older firmware.
5745 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5748 if (event_data->ReasonCode !=
5749 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5750 event_data->ReasonCode !=
5751 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5754 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5755 sas_address = le64_to_cpu(event_data->SASAddress);
5756 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5759 if (!sas_device || !sas_device->starget)
5762 target_priv_data = sas_device->starget->hostdata;
5763 if (!target_priv_data)
5766 if (event_data->ReasonCode ==
5767 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5768 target_priv_data->tm_busy = 1;
5770 target_priv_data->tm_busy = 0;
5774 sas_device_put(sas_device);
5776 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5781 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5783 * @ioc: per adapter object
5784 * @event_data: event data payload
5790 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5791 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5793 char *reason_str = NULL;
5795 switch (event_data->ReasonCode) {
5796 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5797 reason_str = "enclosure add";
5799 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5800 reason_str = "enclosure remove";
5803 reason_str = "unknown reason";
5807 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5808 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5809 " number slots(%d)\n", ioc->name, reason_str,
5810 le16_to_cpu(event_data->EnclosureHandle),
5811 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5812 le16_to_cpu(event_data->StartSlot));
5816 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5817 * @ioc: per adapter object
5818 * @fw_event: The fw_event_work object
5824 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5825 struct fw_event_work *fw_event)
5827 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5828 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5829 (Mpi2EventDataSasEnclDevStatusChange_t *)
5830 fw_event->event_data);
5834 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5835 * @ioc: per adapter object
5836 * @fw_event: The fw_event_work object
5842 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5843 struct fw_event_work *fw_event)
5845 struct scsi_cmnd *scmd;
5846 struct scsi_device *sdev;
5849 struct MPT3SAS_DEVICE *sas_device_priv_data;
5850 u32 termination_count;
5852 Mpi2SCSITaskManagementReply_t *mpi_reply;
5853 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5854 (Mpi2EventDataSasBroadcastPrimitive_t *)
5855 fw_event->event_data;
5857 unsigned long flags;
5860 u8 task_abort_retries;
5862 mutex_lock(&ioc->tm_cmds.mutex);
5864 "%s: enter: phy number(%d), width(%d)\n",
5865 ioc->name, __func__, event_data->PhyNum,
5866 event_data->PortWidth);
5868 _scsih_block_io_all_device(ioc);
5870 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5871 mpi_reply = ioc->tm_cmds.reply;
5872 broadcast_aen_retry:
5874 /* sanity checks for retrying this loop */
5875 if (max_retries++ == 5) {
5876 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5877 ioc->name, __func__));
5879 } else if (max_retries > 1)
5880 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5881 ioc->name, __func__, max_retries - 1));
5883 termination_count = 0;
5885 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5886 if (ioc->shost_recovery)
5888 scmd = _scsih_scsi_lookup_get(ioc, smid);
5891 sdev = scmd->device;
5892 sas_device_priv_data = sdev->hostdata;
5893 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5895 /* skip hidden raid components */
5896 if (sas_device_priv_data->sas_target->flags &
5897 MPT_TARGET_FLAGS_RAID_COMPONENT)
5900 if (sas_device_priv_data->sas_target->flags &
5901 MPT_TARGET_FLAGS_VOLUME)
5904 handle = sas_device_priv_data->sas_target->handle;
5905 lun = sas_device_priv_data->lun;
5908 if (ioc->shost_recovery)
5911 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5912 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5913 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5916 sdev_printk(KERN_WARNING, sdev,
5917 "mpt3sas_scsih_issue_tm: FAILED when sending "
5918 "QUERY_TASK: scmd(%p)\n", scmd);
5919 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5920 goto broadcast_aen_retry;
5922 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5923 & MPI2_IOCSTATUS_MASK;
5924 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5925 sdev_printk(KERN_WARNING, sdev,
5926 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5928 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5929 goto broadcast_aen_retry;
5932 /* see if IO is still owned by IOC and target */
5933 if (mpi_reply->ResponseCode ==
5934 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5935 mpi_reply->ResponseCode ==
5936 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5937 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5940 task_abort_retries = 0;
5942 if (task_abort_retries++ == 60) {
5943 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5944 "%s: ABORT_TASK: giving up\n", ioc->name,
5946 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5947 goto broadcast_aen_retry;
5950 if (ioc->shost_recovery)
5953 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5954 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5957 sdev_printk(KERN_WARNING, sdev,
5958 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5959 "scmd(%p)\n", scmd);
5963 if (task_abort_retries > 1)
5964 sdev_printk(KERN_WARNING, sdev,
5965 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5967 task_abort_retries - 1, scmd);
5969 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5970 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5973 if (ioc->broadcast_aen_pending) {
5974 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5975 "%s: loop back due to pending AEN\n",
5976 ioc->name, __func__));
5977 ioc->broadcast_aen_pending = 0;
5978 goto broadcast_aen_retry;
5982 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5985 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5986 "%s - exit, query_count = %d termination_count = %d\n",
5987 ioc->name, __func__, query_count, termination_count));
5989 ioc->broadcast_aen_busy = 0;
5990 if (!ioc->shost_recovery)
5991 _scsih_ublock_io_all_device(ioc);
5992 mutex_unlock(&ioc->tm_cmds.mutex);
5996 * _scsih_sas_discovery_event - handle discovery events
5997 * @ioc: per adapter object
5998 * @fw_event: The fw_event_work object
6004 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
6005 struct fw_event_work *fw_event)
6007 Mpi2EventDataSasDiscovery_t *event_data =
6008 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
6010 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6011 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
6012 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6014 if (event_data->DiscoveryStatus)
6015 pr_info("discovery_status(0x%08x)",
6016 le32_to_cpu(event_data->DiscoveryStatus));
6020 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6021 !ioc->sas_hba.num_phys) {
6022 if (disable_discovery > 0 && ioc->shost_recovery) {
6023 /* Wait for the reset to complete */
6024 while (ioc->shost_recovery)
6027 _scsih_sas_host_add(ioc);
6032 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6033 * @ioc: per adapter object
6034 * @handle: device handle for physical disk
6035 * @phys_disk_num: physical disk number
6037 * Return 0 for success, else failure.
6040 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6042 Mpi2RaidActionRequest_t *mpi_request;
6043 Mpi2RaidActionReply_t *mpi_reply;
6050 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6053 mutex_lock(&ioc->scsih_cmds.mutex);
6055 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6056 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6057 ioc->name, __func__);
6061 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6063 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6065 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6066 ioc->name, __func__);
6067 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6072 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6073 ioc->scsih_cmds.smid = smid;
6074 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6076 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6077 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6078 mpi_request->PhysDiskNum = phys_disk_num;
6080 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6081 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6082 handle, phys_disk_num));
6084 init_completion(&ioc->scsih_cmds.done);
6085 mpt3sas_base_put_smid_default(ioc, smid);
6086 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6088 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6089 pr_err(MPT3SAS_FMT "%s: timeout\n",
6090 ioc->name, __func__);
6091 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6097 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6099 mpi_reply = ioc->scsih_cmds.reply;
6100 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6101 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6102 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6105 ioc_status &= MPI2_IOCSTATUS_MASK;
6106 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6107 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6108 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6109 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6113 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6114 "IR RAID_ACTION: completed successfully\n",
6119 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6120 mutex_unlock(&ioc->scsih_cmds.mutex);
6123 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
6129 * _scsih_reprobe_lun - reprobing lun
6130 * @sdev: scsi device struct
6131 * @no_uld_attach: sdev->no_uld_attach flag setting
6135 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6138 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6139 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6140 sdev->no_uld_attach ? "hidding" : "exposing");
6141 rc = scsi_device_reprobe(sdev);
6145 * _scsih_sas_volume_add - add new volume
6146 * @ioc: per adapter object
6147 * @element: IR config element data
6153 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6154 Mpi2EventIrConfigElement_t *element)
6156 struct _raid_device *raid_device;
6157 unsigned long flags;
6159 u16 handle = le16_to_cpu(element->VolDevHandle);
6162 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6165 "failure at %s:%d/%s()!\n", ioc->name,
6166 __FILE__, __LINE__, __func__);
6170 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6171 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6172 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6177 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6180 "failure at %s:%d/%s()!\n", ioc->name,
6181 __FILE__, __LINE__, __func__);
6185 raid_device->id = ioc->sas_id++;
6186 raid_device->channel = RAID_CHANNEL;
6187 raid_device->handle = handle;
6188 raid_device->wwid = wwid;
6189 _scsih_raid_device_add(ioc, raid_device);
6190 if (!ioc->wait_for_discovery_to_complete) {
6191 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6192 raid_device->id, 0);
6194 _scsih_raid_device_remove(ioc, raid_device);
6196 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6197 _scsih_determine_boot_device(ioc, raid_device, 1);
6198 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6203 * _scsih_sas_volume_delete - delete volume
6204 * @ioc: per adapter object
6205 * @handle: volume device handle
6211 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6213 struct _raid_device *raid_device;
6214 unsigned long flags;
6215 struct MPT3SAS_TARGET *sas_target_priv_data;
6216 struct scsi_target *starget = NULL;
6218 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6219 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6221 if (raid_device->starget) {
6222 starget = raid_device->starget;
6223 sas_target_priv_data = starget->hostdata;
6224 sas_target_priv_data->deleted = 1;
6226 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6227 ioc->name, raid_device->handle,
6228 (unsigned long long) raid_device->wwid);
6229 list_del(&raid_device->list);
6232 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6234 scsi_remove_target(&starget->dev);
6238 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6239 * @ioc: per adapter object
6240 * @element: IR config element data
6246 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6247 Mpi2EventIrConfigElement_t *element)
6249 struct _sas_device *sas_device;
6250 struct scsi_target *starget = NULL;
6251 struct MPT3SAS_TARGET *sas_target_priv_data;
6252 unsigned long flags;
6253 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6255 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6256 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6258 sas_device->volume_handle = 0;
6259 sas_device->volume_wwid = 0;
6260 clear_bit(handle, ioc->pd_handles);
6261 if (sas_device->starget && sas_device->starget->hostdata) {
6262 starget = sas_device->starget;
6263 sas_target_priv_data = starget->hostdata;
6264 sas_target_priv_data->flags &=
6265 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6268 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6272 /* exposing raid component */
6274 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6276 sas_device_put(sas_device);
6280 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6281 * @ioc: per adapter object
6282 * @element: IR config element data
6288 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6289 Mpi2EventIrConfigElement_t *element)
6291 struct _sas_device *sas_device;
6292 struct scsi_target *starget = NULL;
6293 struct MPT3SAS_TARGET *sas_target_priv_data;
6294 unsigned long flags;
6295 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6296 u16 volume_handle = 0;
6297 u64 volume_wwid = 0;
6299 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6301 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6304 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6305 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6307 set_bit(handle, ioc->pd_handles);
6308 if (sas_device->starget && sas_device->starget->hostdata) {
6309 starget = sas_device->starget;
6310 sas_target_priv_data = starget->hostdata;
6311 sas_target_priv_data->flags |=
6312 MPT_TARGET_FLAGS_RAID_COMPONENT;
6313 sas_device->volume_handle = volume_handle;
6314 sas_device->volume_wwid = volume_wwid;
6317 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6321 /* hiding raid component */
6322 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6325 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6327 sas_device_put(sas_device);
6331 * _scsih_sas_pd_delete - delete pd component
6332 * @ioc: per adapter object
6333 * @element: IR config element data
6339 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6340 Mpi2EventIrConfigElement_t *element)
6342 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6344 _scsih_device_remove_by_handle(ioc, handle);
6348 * _scsih_sas_pd_add - remove pd component
6349 * @ioc: per adapter object
6350 * @element: IR config element data
6356 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6357 Mpi2EventIrConfigElement_t *element)
6359 struct _sas_device *sas_device;
6360 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6361 Mpi2ConfigReply_t mpi_reply;
6362 Mpi2SasDevicePage0_t sas_device_pg0;
6367 set_bit(handle, ioc->pd_handles);
6369 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6371 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6372 sas_device_put(sas_device);
6376 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6377 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6378 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6379 ioc->name, __FILE__, __LINE__, __func__);
6383 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6384 MPI2_IOCSTATUS_MASK;
6385 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6386 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6387 ioc->name, __FILE__, __LINE__, __func__);
6391 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6392 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6393 mpt3sas_transport_update_links(ioc, sas_address, handle,
6394 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6396 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6397 _scsih_add_device(ioc, handle, 0, 1);
6401 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6402 * @ioc: per adapter object
6403 * @event_data: event data payload
6409 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6410 Mpi2EventDataIrConfigChangeList_t *event_data)
6412 Mpi2EventIrConfigElement_t *element;
6415 char *reason_str = NULL, *element_str = NULL;
6417 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6419 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6420 ioc->name, (le32_to_cpu(event_data->Flags) &
6421 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6422 "foreign" : "native", event_data->NumElements);
6423 for (i = 0; i < event_data->NumElements; i++, element++) {
6424 switch (element->ReasonCode) {
6425 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6428 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6429 reason_str = "remove";
6431 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6432 reason_str = "no change";
6434 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6435 reason_str = "hide";
6437 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6438 reason_str = "unhide";
6440 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6441 reason_str = "volume_created";
6443 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6444 reason_str = "volume_deleted";
6446 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6447 reason_str = "pd_created";
6449 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6450 reason_str = "pd_deleted";
6453 reason_str = "unknown reason";
6456 element_type = le16_to_cpu(element->ElementFlags) &
6457 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6458 switch (element_type) {
6459 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6460 element_str = "volume";
6462 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6463 element_str = "phys disk";
6465 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6466 element_str = "hot spare";
6469 element_str = "unknown element";
6472 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6473 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6474 reason_str, le16_to_cpu(element->VolDevHandle),
6475 le16_to_cpu(element->PhysDiskDevHandle),
6476 element->PhysDiskNum);
6481 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6482 * @ioc: per adapter object
6483 * @fw_event: The fw_event_work object
6489 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6490 struct fw_event_work *fw_event)
6492 Mpi2EventIrConfigElement_t *element;
6495 Mpi2EventDataIrConfigChangeList_t *event_data =
6496 (Mpi2EventDataIrConfigChangeList_t *)
6497 fw_event->event_data;
6499 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6500 (!ioc->hide_ir_msg))
6501 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6503 foreign_config = (le32_to_cpu(event_data->Flags) &
6504 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6506 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6507 if (ioc->shost_recovery &&
6508 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6509 for (i = 0; i < event_data->NumElements; i++, element++) {
6510 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6511 _scsih_ir_fastpath(ioc,
6512 le16_to_cpu(element->PhysDiskDevHandle),
6513 element->PhysDiskNum);
6518 for (i = 0; i < event_data->NumElements; i++, element++) {
6520 switch (element->ReasonCode) {
6521 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6522 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6523 if (!foreign_config)
6524 _scsih_sas_volume_add(ioc, element);
6526 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6527 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6528 if (!foreign_config)
6529 _scsih_sas_volume_delete(ioc,
6530 le16_to_cpu(element->VolDevHandle));
6532 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6533 if (!ioc->is_warpdrive)
6534 _scsih_sas_pd_hide(ioc, element);
6536 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6537 if (!ioc->is_warpdrive)
6538 _scsih_sas_pd_expose(ioc, element);
6540 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6541 if (!ioc->is_warpdrive)
6542 _scsih_sas_pd_add(ioc, element);
6544 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6545 if (!ioc->is_warpdrive)
6546 _scsih_sas_pd_delete(ioc, element);
6553 * _scsih_sas_ir_volume_event - IR volume event
6554 * @ioc: per adapter object
6555 * @fw_event: The fw_event_work object
6561 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6562 struct fw_event_work *fw_event)
6565 unsigned long flags;
6566 struct _raid_device *raid_device;
6570 Mpi2EventDataIrVolume_t *event_data =
6571 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6573 if (ioc->shost_recovery)
6576 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6579 handle = le16_to_cpu(event_data->VolDevHandle);
6580 state = le32_to_cpu(event_data->NewValue);
6581 if (!ioc->hide_ir_msg)
6582 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6583 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6584 ioc->name, __func__, handle,
6585 le32_to_cpu(event_data->PreviousValue), state));
6587 case MPI2_RAID_VOL_STATE_MISSING:
6588 case MPI2_RAID_VOL_STATE_FAILED:
6589 _scsih_sas_volume_delete(ioc, handle);
6592 case MPI2_RAID_VOL_STATE_ONLINE:
6593 case MPI2_RAID_VOL_STATE_DEGRADED:
6594 case MPI2_RAID_VOL_STATE_OPTIMAL:
6596 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6597 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6598 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6603 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6606 "failure at %s:%d/%s()!\n", ioc->name,
6607 __FILE__, __LINE__, __func__);
6611 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6614 "failure at %s:%d/%s()!\n", ioc->name,
6615 __FILE__, __LINE__, __func__);
6619 raid_device->id = ioc->sas_id++;
6620 raid_device->channel = RAID_CHANNEL;
6621 raid_device->handle = handle;
6622 raid_device->wwid = wwid;
6623 _scsih_raid_device_add(ioc, raid_device);
6624 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6625 raid_device->id, 0);
6627 _scsih_raid_device_remove(ioc, raid_device);
6630 case MPI2_RAID_VOL_STATE_INITIALIZING:
6637 * _scsih_sas_ir_physical_disk_event - PD event
6638 * @ioc: per adapter object
6639 * @fw_event: The fw_event_work object
6645 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6646 struct fw_event_work *fw_event)
6648 u16 handle, parent_handle;
6650 struct _sas_device *sas_device;
6651 Mpi2ConfigReply_t mpi_reply;
6652 Mpi2SasDevicePage0_t sas_device_pg0;
6654 Mpi2EventDataIrPhysicalDisk_t *event_data =
6655 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6658 if (ioc->shost_recovery)
6661 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6664 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6665 state = le32_to_cpu(event_data->NewValue);
6667 if (!ioc->hide_ir_msg)
6668 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6669 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6670 ioc->name, __func__, handle,
6671 le32_to_cpu(event_data->PreviousValue), state));
6674 case MPI2_RAID_PD_STATE_ONLINE:
6675 case MPI2_RAID_PD_STATE_DEGRADED:
6676 case MPI2_RAID_PD_STATE_REBUILDING:
6677 case MPI2_RAID_PD_STATE_OPTIMAL:
6678 case MPI2_RAID_PD_STATE_HOT_SPARE:
6680 if (!ioc->is_warpdrive)
6681 set_bit(handle, ioc->pd_handles);
6683 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6685 sas_device_put(sas_device);
6689 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6690 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6692 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6693 ioc->name, __FILE__, __LINE__, __func__);
6697 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6698 MPI2_IOCSTATUS_MASK;
6699 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6700 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6701 ioc->name, __FILE__, __LINE__, __func__);
6705 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6706 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6707 mpt3sas_transport_update_links(ioc, sas_address, handle,
6708 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6710 _scsih_add_device(ioc, handle, 0, 1);
6714 case MPI2_RAID_PD_STATE_OFFLINE:
6715 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6716 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6723 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6724 * @ioc: per adapter object
6725 * @event_data: event data payload
6731 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6732 Mpi2EventDataIrOperationStatus_t *event_data)
6734 char *reason_str = NULL;
6736 switch (event_data->RAIDOperation) {
6737 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6738 reason_str = "resync";
6740 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6741 reason_str = "online capacity expansion";
6743 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6744 reason_str = "consistency check";
6746 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6747 reason_str = "background init";
6749 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6750 reason_str = "make data consistent";
6757 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6758 "\thandle(0x%04x), percent complete(%d)\n",
6759 ioc->name, reason_str,
6760 le16_to_cpu(event_data->VolDevHandle),
6761 event_data->PercentComplete);
6765 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6766 * @ioc: per adapter object
6767 * @fw_event: The fw_event_work object
6773 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6774 struct fw_event_work *fw_event)
6776 Mpi2EventDataIrOperationStatus_t *event_data =
6777 (Mpi2EventDataIrOperationStatus_t *)
6778 fw_event->event_data;
6779 static struct _raid_device *raid_device;
6780 unsigned long flags;
6783 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6784 (!ioc->hide_ir_msg))
6785 _scsih_sas_ir_operation_status_event_debug(ioc,
6788 /* code added for raid transport support */
6789 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6791 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6792 handle = le16_to_cpu(event_data->VolDevHandle);
6793 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6795 raid_device->percent_complete =
6796 event_data->PercentComplete;
6797 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6802 * _scsih_prep_device_scan - initialize parameters prior to device scan
6803 * @ioc: per adapter object
6805 * Set the deleted flag prior to device scan. If the device is found during
6806 * the scan, then we clear the deleted flag.
6809 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6811 struct MPT3SAS_DEVICE *sas_device_priv_data;
6812 struct scsi_device *sdev;
6814 shost_for_each_device(sdev, ioc->shost) {
6815 sas_device_priv_data = sdev->hostdata;
6816 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6817 sas_device_priv_data->sas_target->deleted = 1;
6822 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6823 * @ioc: per adapter object
6824 * @sas_device_pg0: SAS Device page 0
6826 * After host reset, find out whether devices are still responding.
6827 * Used in _scsih_remove_unresponsive_sas_devices.
6832 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6833 Mpi2SasDevicePage0_t *sas_device_pg0)
6835 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6836 struct scsi_target *starget;
6837 struct _sas_device *sas_device;
6838 unsigned long flags;
6840 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6841 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6842 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
6843 (sas_device->slot == sas_device_pg0->Slot)) {
6844 sas_device->responding = 1;
6845 starget = sas_device->starget;
6846 if (starget && starget->hostdata) {
6847 sas_target_priv_data = starget->hostdata;
6848 sas_target_priv_data->tm_busy = 0;
6849 sas_target_priv_data->deleted = 0;
6851 sas_target_priv_data = NULL;
6853 starget_printk(KERN_INFO, starget,
6854 "handle(0x%04x), sas_addr(0x%016llx)\n",
6855 sas_device_pg0->DevHandle,
6856 (unsigned long long)
6857 sas_device->sas_address);
6859 if (sas_device->enclosure_handle != 0)
6860 starget_printk(KERN_INFO, starget,
6861 "enclosure logical id(0x%016llx),"
6863 (unsigned long long)
6864 sas_device->enclosure_logical_id,
6867 if (sas_device_pg0->Flags &
6868 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6869 sas_device->enclosure_level =
6870 le16_to_cpu(sas_device_pg0->EnclosureLevel);
6871 memcpy(&sas_device->connector_name[0],
6872 &sas_device_pg0->ConnectorName[0], 4);
6874 sas_device->enclosure_level = 0;
6875 sas_device->connector_name[0] = '\0';
6878 if (sas_device->handle == sas_device_pg0->DevHandle)
6880 pr_info("\thandle changed from(0x%04x)!!!\n",
6881 sas_device->handle);
6882 sas_device->handle = sas_device_pg0->DevHandle;
6883 if (sas_target_priv_data)
6884 sas_target_priv_data->handle =
6885 sas_device_pg0->DevHandle;
6890 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6894 * _scsih_search_responding_sas_devices -
6895 * @ioc: per adapter object
6897 * After host reset, find out whether devices are still responding.
6903 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6905 Mpi2SasDevicePage0_t sas_device_pg0;
6906 Mpi2ConfigReply_t mpi_reply;
6911 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6913 if (list_empty(&ioc->sas_device_list))
6917 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6918 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6920 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6921 MPI2_IOCSTATUS_MASK;
6922 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6924 handle = sas_device_pg0.DevHandle =
6925 le16_to_cpu(sas_device_pg0.DevHandle);
6926 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6927 if (!(_scsih_is_end_device(device_info)))
6929 sas_device_pg0.SASAddress =
6930 le64_to_cpu(sas_device_pg0.SASAddress);
6931 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
6932 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
6936 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
6941 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6942 * @ioc: per adapter object
6943 * @wwid: world wide identifier for raid volume
6944 * @handle: device handle
6946 * After host reset, find out whether devices are still responding.
6947 * Used in _scsih_remove_unresponsive_raid_devices.
6952 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
6955 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6956 struct scsi_target *starget;
6957 struct _raid_device *raid_device;
6958 unsigned long flags;
6960 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6961 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6962 if (raid_device->wwid == wwid && raid_device->starget) {
6963 starget = raid_device->starget;
6964 if (starget && starget->hostdata) {
6965 sas_target_priv_data = starget->hostdata;
6966 sas_target_priv_data->deleted = 0;
6968 sas_target_priv_data = NULL;
6969 raid_device->responding = 1;
6970 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6971 starget_printk(KERN_INFO, raid_device->starget,
6972 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6973 (unsigned long long)raid_device->wwid);
6976 * WARPDRIVE: The handles of the PDs might have changed
6977 * across the host reset so re-initialize the
6978 * required data for Direct IO
6980 mpt3sas_init_warpdrive_properties(ioc, raid_device);
6981 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6982 if (raid_device->handle == handle) {
6983 spin_unlock_irqrestore(&ioc->raid_device_lock,
6987 pr_info("\thandle changed from(0x%04x)!!!\n",
6988 raid_device->handle);
6989 raid_device->handle = handle;
6990 if (sas_target_priv_data)
6991 sas_target_priv_data->handle = handle;
6992 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6996 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7000 * _scsih_search_responding_raid_devices -
7001 * @ioc: per adapter object
7003 * After host reset, find out whether devices are still responding.
7009 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
7011 Mpi2RaidVolPage1_t volume_pg1;
7012 Mpi2RaidVolPage0_t volume_pg0;
7013 Mpi2RaidPhysDiskPage0_t pd_pg0;
7014 Mpi2ConfigReply_t mpi_reply;
7019 if (!ioc->ir_firmware)
7022 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7025 if (list_empty(&ioc->raid_device_list))
7029 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7030 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7031 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7032 MPI2_IOCSTATUS_MASK;
7033 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7035 handle = le16_to_cpu(volume_pg1.DevHandle);
7037 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7038 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7039 sizeof(Mpi2RaidVolPage0_t)))
7042 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7043 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7044 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7045 _scsih_mark_responding_raid_device(ioc,
7046 le64_to_cpu(volume_pg1.WWID), handle);
7049 /* refresh the pd_handles */
7050 if (!ioc->is_warpdrive) {
7051 phys_disk_num = 0xFF;
7052 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7053 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7054 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7056 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7057 MPI2_IOCSTATUS_MASK;
7058 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7060 phys_disk_num = pd_pg0.PhysDiskNum;
7061 handle = le16_to_cpu(pd_pg0.DevHandle);
7062 set_bit(handle, ioc->pd_handles);
7066 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7071 * _scsih_mark_responding_expander - mark a expander as responding
7072 * @ioc: per adapter object
7073 * @sas_address: sas address
7076 * After host reset, find out whether devices are still responding.
7077 * Used in _scsih_remove_unresponsive_expanders.
7082 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7085 struct _sas_node *sas_expander;
7086 unsigned long flags;
7089 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7090 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7091 if (sas_expander->sas_address != sas_address)
7093 sas_expander->responding = 1;
7094 if (sas_expander->handle == handle)
7096 pr_info("\texpander(0x%016llx): handle changed" \
7097 " from(0x%04x) to (0x%04x)!!!\n",
7098 (unsigned long long)sas_expander->sas_address,
7099 sas_expander->handle, handle);
7100 sas_expander->handle = handle;
7101 for (i = 0 ; i < sas_expander->num_phys ; i++)
7102 sas_expander->phy[i].handle = handle;
7106 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7110 * _scsih_search_responding_expanders -
7111 * @ioc: per adapter object
7113 * After host reset, find out whether devices are still responding.
7119 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7121 Mpi2ExpanderPage0_t expander_pg0;
7122 Mpi2ConfigReply_t mpi_reply;
7127 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7129 if (list_empty(&ioc->sas_expander_list))
7133 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7134 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7136 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7137 MPI2_IOCSTATUS_MASK;
7138 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7141 handle = le16_to_cpu(expander_pg0.DevHandle);
7142 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7143 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7145 (unsigned long long)sas_address);
7146 _scsih_mark_responding_expander(ioc, sas_address, handle);
7150 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7154 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7155 * @ioc: per adapter object
7160 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7162 struct _sas_device *sas_device, *sas_device_next;
7163 struct _sas_node *sas_expander, *sas_expander_next;
7164 struct _raid_device *raid_device, *raid_device_next;
7165 struct list_head tmp_list;
7166 unsigned long flags;
7169 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7172 /* removing unresponding end devices */
7173 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7176 * Iterate, pulling off devices marked as non-responding. We become the
7177 * owner for the reference the list had on any object we prune.
7179 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7180 list_for_each_entry_safe(sas_device, sas_device_next,
7181 &ioc->sas_device_list, list) {
7182 if (!sas_device->responding)
7183 list_move_tail(&sas_device->list, &head);
7185 sas_device->responding = 0;
7187 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7190 * Now, uninitialize and remove the unresponding devices we pruned.
7192 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7193 _scsih_remove_device(ioc, sas_device);
7194 list_del_init(&sas_device->list);
7195 sas_device_put(sas_device);
7198 /* removing unresponding volumes */
7199 if (ioc->ir_firmware) {
7200 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7202 list_for_each_entry_safe(raid_device, raid_device_next,
7203 &ioc->raid_device_list, list) {
7204 if (!raid_device->responding)
7205 _scsih_sas_volume_delete(ioc,
7206 raid_device->handle);
7208 raid_device->responding = 0;
7212 /* removing unresponding expanders */
7213 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7215 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7216 INIT_LIST_HEAD(&tmp_list);
7217 list_for_each_entry_safe(sas_expander, sas_expander_next,
7218 &ioc->sas_expander_list, list) {
7219 if (!sas_expander->responding)
7220 list_move_tail(&sas_expander->list, &tmp_list);
7222 sas_expander->responding = 0;
7224 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7225 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7227 list_del(&sas_expander->list);
7228 _scsih_expander_node_remove(ioc, sas_expander);
7231 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7234 /* unblock devices */
7235 _scsih_ublock_io_all_device(ioc);
7239 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7240 struct _sas_node *sas_expander, u16 handle)
7242 Mpi2ExpanderPage1_t expander_pg1;
7243 Mpi2ConfigReply_t mpi_reply;
7246 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7247 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7248 &expander_pg1, i, handle))) {
7249 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7250 ioc->name, __FILE__, __LINE__, __func__);
7254 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7255 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7256 expander_pg1.NegotiatedLinkRate >> 4);
7261 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7262 * @ioc: per adapter object
7267 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7269 Mpi2ExpanderPage0_t expander_pg0;
7270 Mpi2SasDevicePage0_t sas_device_pg0;
7271 Mpi2RaidVolPage1_t volume_pg1;
7272 Mpi2RaidVolPage0_t volume_pg0;
7273 Mpi2RaidPhysDiskPage0_t pd_pg0;
7274 Mpi2EventIrConfigElement_t element;
7275 Mpi2ConfigReply_t mpi_reply;
7278 u16 handle, parent_handle;
7280 struct _sas_device *sas_device;
7281 struct _sas_node *expander_device;
7282 static struct _raid_device *raid_device;
7284 unsigned long flags;
7286 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7288 _scsih_sas_host_refresh(ioc);
7290 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7294 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7295 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7296 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7297 MPI2_IOCSTATUS_MASK;
7298 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7299 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7300 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7301 ioc->name, ioc_status,
7302 le32_to_cpu(mpi_reply.IOCLogInfo));
7305 handle = le16_to_cpu(expander_pg0.DevHandle);
7306 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7307 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7308 ioc, le64_to_cpu(expander_pg0.SASAddress));
7309 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7310 if (expander_device)
7311 _scsih_refresh_expander_links(ioc, expander_device,
7314 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7315 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7316 handle, (unsigned long long)
7317 le64_to_cpu(expander_pg0.SASAddress));
7318 _scsih_expander_add(ioc, handle);
7319 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7320 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7321 handle, (unsigned long long)
7322 le64_to_cpu(expander_pg0.SASAddress));
7326 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7329 if (!ioc->ir_firmware)
7332 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7335 phys_disk_num = 0xFF;
7336 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7337 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7339 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7340 MPI2_IOCSTATUS_MASK;
7341 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7342 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7343 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7344 ioc->name, ioc_status,
7345 le32_to_cpu(mpi_reply.IOCLogInfo));
7348 phys_disk_num = pd_pg0.PhysDiskNum;
7349 handle = le16_to_cpu(pd_pg0.DevHandle);
7350 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7352 sas_device_put(sas_device);
7355 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7356 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7359 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7360 MPI2_IOCSTATUS_MASK;
7361 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7362 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7363 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7364 ioc->name, ioc_status,
7365 le32_to_cpu(mpi_reply.IOCLogInfo));
7368 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7369 if (!_scsih_get_sas_address(ioc, parent_handle,
7371 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7372 " handle (0x%04x), sas_addr(0x%016llx)\n",
7373 ioc->name, handle, (unsigned long long)
7374 le64_to_cpu(sas_device_pg0.SASAddress));
7375 mpt3sas_transport_update_links(ioc, sas_address,
7376 handle, sas_device_pg0.PhyNum,
7377 MPI2_SAS_NEG_LINK_RATE_1_5);
7378 set_bit(handle, ioc->pd_handles);
7380 /* This will retry adding the end device.
7381 * _scsih_add_device() will decide on retries and
7382 * return "1" when it should be retried
7384 while (_scsih_add_device(ioc, handle, retry_count++,
7388 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7389 " handle (0x%04x), sas_addr(0x%016llx)\n",
7390 ioc->name, handle, (unsigned long long)
7391 le64_to_cpu(sas_device_pg0.SASAddress));
7395 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7398 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7402 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7403 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7404 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7405 MPI2_IOCSTATUS_MASK;
7406 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7407 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7408 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7409 ioc->name, ioc_status,
7410 le32_to_cpu(mpi_reply.IOCLogInfo));
7413 handle = le16_to_cpu(volume_pg1.DevHandle);
7414 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7415 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7416 le64_to_cpu(volume_pg1.WWID));
7417 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7420 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7421 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7422 sizeof(Mpi2RaidVolPage0_t)))
7424 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7425 MPI2_IOCSTATUS_MASK;
7426 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7427 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7428 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7429 ioc->name, ioc_status,
7430 le32_to_cpu(mpi_reply.IOCLogInfo));
7433 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7434 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7435 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7436 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7437 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7438 element.VolDevHandle = volume_pg1.DevHandle;
7440 "\tBEFORE adding volume: handle (0x%04x)\n",
7441 ioc->name, volume_pg1.DevHandle);
7442 _scsih_sas_volume_add(ioc, &element);
7444 "\tAFTER adding volume: handle (0x%04x)\n",
7445 ioc->name, volume_pg1.DevHandle);
7449 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7454 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7459 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7460 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7462 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7463 MPI2_IOCSTATUS_MASK;
7464 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7465 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7466 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7467 ioc->name, ioc_status,
7468 le32_to_cpu(mpi_reply.IOCLogInfo));
7471 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7472 if (!(_scsih_is_end_device(
7473 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7475 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7476 le64_to_cpu(sas_device_pg0.SASAddress));
7478 sas_device_put(sas_device);
7481 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7482 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7483 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7484 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7485 handle, (unsigned long long)
7486 le64_to_cpu(sas_device_pg0.SASAddress));
7487 mpt3sas_transport_update_links(ioc, sas_address, handle,
7488 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7490 /* This will retry adding the end device.
7491 * _scsih_add_device() will decide on retries and
7492 * return "1" when it should be retried
7494 while (_scsih_add_device(ioc, handle, retry_count++,
7498 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7499 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7500 handle, (unsigned long long)
7501 le64_to_cpu(sas_device_pg0.SASAddress));
7504 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7507 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7510 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7511 * @ioc: per adapter object
7512 * @reset_phase: phase
7514 * The handler for doing any required cleanup or initialization.
7516 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7517 * MPT3_IOC_DONE_RESET
7522 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7524 switch (reset_phase) {
7525 case MPT3_IOC_PRE_RESET:
7526 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7527 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7529 case MPT3_IOC_AFTER_RESET:
7530 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7531 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7532 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7533 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7534 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7535 complete(&ioc->scsih_cmds.done);
7537 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7538 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7539 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7540 complete(&ioc->tm_cmds.done);
7543 _scsih_fw_event_cleanup_queue(ioc);
7544 _scsih_flush_running_cmds(ioc);
7546 case MPT3_IOC_DONE_RESET:
7547 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7548 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7549 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7550 !ioc->sas_hba.num_phys)) {
7551 _scsih_prep_device_scan(ioc);
7552 _scsih_search_responding_sas_devices(ioc);
7553 _scsih_search_responding_raid_devices(ioc);
7554 _scsih_search_responding_expanders(ioc);
7555 _scsih_error_recovery_delete_devices(ioc);
7562 * _mpt3sas_fw_work - delayed task for processing firmware events
7563 * @ioc: per adapter object
7564 * @fw_event: The fw_event_work object
7570 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7572 _scsih_fw_event_del_from_list(ioc, fw_event);
7574 /* the queue is being flushed so ignore this event */
7575 if (ioc->remove_host || ioc->pci_error_recovery) {
7576 fw_event_work_put(fw_event);
7580 switch (fw_event->event) {
7581 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7582 mpt3sas_process_trigger_data(ioc,
7583 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7584 fw_event->event_data);
7586 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7587 while (scsi_host_in_recovery(ioc->shost) ||
7588 ioc->shost_recovery) {
7590 * If we're unloading, bail. Otherwise, this can become
7593 if (ioc->remove_host)
7597 _scsih_remove_unresponding_sas_devices(ioc);
7598 _scsih_scan_for_devices_after_reset(ioc);
7600 case MPT3SAS_PORT_ENABLE_COMPLETE:
7601 ioc->start_scan = 0;
7602 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7603 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7605 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7606 "port enable: complete from worker thread\n",
7609 case MPT3SAS_TURN_ON_PFA_LED:
7610 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7612 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7613 _scsih_sas_topology_change_event(ioc, fw_event);
7615 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7616 _scsih_sas_device_status_change_event(ioc, fw_event);
7618 case MPI2_EVENT_SAS_DISCOVERY:
7619 _scsih_sas_discovery_event(ioc, fw_event);
7621 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7622 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7624 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7625 _scsih_sas_enclosure_dev_status_change_event(ioc,
7628 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7629 _scsih_sas_ir_config_change_event(ioc, fw_event);
7631 case MPI2_EVENT_IR_VOLUME:
7632 _scsih_sas_ir_volume_event(ioc, fw_event);
7634 case MPI2_EVENT_IR_PHYSICAL_DISK:
7635 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7637 case MPI2_EVENT_IR_OPERATION_STATUS:
7638 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7642 fw_event_work_put(fw_event);
7646 * _firmware_event_work
7647 * @ioc: per adapter object
7648 * @work: The fw_event_work object
7651 * wrappers for the work thread handling firmware events
7657 _firmware_event_work(struct work_struct *work)
7659 struct fw_event_work *fw_event = container_of(work,
7660 struct fw_event_work, work);
7662 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7666 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7667 * @ioc: per adapter object
7668 * @msix_index: MSIX table index supplied by the OS
7669 * @reply: reply message frame(lower 32bit addr)
7670 * Context: interrupt.
7672 * This function merely adds a new work task into ioc->firmware_event_thread.
7673 * The tasks are worked from _firmware_event_work in user context.
7675 * Return 1 meaning mf should be freed from _base_interrupt
7676 * 0 means the mf is freed from this function.
7679 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7682 struct fw_event_work *fw_event;
7683 Mpi2EventNotificationReply_t *mpi_reply;
7687 /* events turned off due to host reset or driver unloading */
7688 if (ioc->remove_host || ioc->pci_error_recovery)
7691 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7693 if (unlikely(!mpi_reply)) {
7694 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7695 ioc->name, __FILE__, __LINE__, __func__);
7699 event = le16_to_cpu(mpi_reply->Event);
7701 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7702 mpt3sas_trigger_event(ioc, event, 0);
7706 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7708 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7709 (Mpi2EventDataSasBroadcastPrimitive_t *)
7710 mpi_reply->EventData;
7712 if (baen_data->Primitive !=
7713 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7716 if (ioc->broadcast_aen_busy) {
7717 ioc->broadcast_aen_pending++;
7720 ioc->broadcast_aen_busy = 1;
7724 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7725 _scsih_check_topo_delete_events(ioc,
7726 (Mpi2EventDataSasTopologyChangeList_t *)
7727 mpi_reply->EventData);
7729 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7730 _scsih_check_ir_config_unhide_events(ioc,
7731 (Mpi2EventDataIrConfigChangeList_t *)
7732 mpi_reply->EventData);
7734 case MPI2_EVENT_IR_VOLUME:
7735 _scsih_check_volume_delete_events(ioc,
7736 (Mpi2EventDataIrVolume_t *)
7737 mpi_reply->EventData);
7739 case MPI2_EVENT_LOG_ENTRY_ADDED:
7741 Mpi2EventDataLogEntryAdded_t *log_entry;
7744 if (!ioc->is_warpdrive)
7747 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7748 mpi_reply->EventData;
7749 log_code = (u32 *)log_entry->LogData;
7751 if (le16_to_cpu(log_entry->LogEntryQualifier)
7752 != MPT2_WARPDRIVE_LOGENTRY)
7755 switch (le32_to_cpu(*log_code)) {
7756 case MPT2_WARPDRIVE_LC_SSDT:
7757 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7758 "IO Throttling has occurred in the WarpDrive "
7759 "subsystem. Check WarpDrive documentation for "
7760 "additional details.\n", ioc->name);
7762 case MPT2_WARPDRIVE_LC_SSDLW:
7763 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7764 "Program/Erase Cycles for the WarpDrive subsystem "
7765 "in degraded range. Check WarpDrive documentation "
7766 "for additional details.\n", ioc->name);
7768 case MPT2_WARPDRIVE_LC_SSDLF:
7769 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7770 "There are no Program/Erase Cycles for the "
7771 "WarpDrive subsystem. The storage device will be "
7772 "in read-only mode. Check WarpDrive documentation "
7773 "for additional details.\n", ioc->name);
7775 case MPT2_WARPDRIVE_LC_BRMF:
7776 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7777 "The Backup Rail Monitor has failed on the "
7778 "WarpDrive subsystem. Check WarpDrive "
7779 "documentation for additional details.\n",
7786 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7787 case MPI2_EVENT_IR_OPERATION_STATUS:
7788 case MPI2_EVENT_SAS_DISCOVERY:
7789 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7790 case MPI2_EVENT_IR_PHYSICAL_DISK:
7793 case MPI2_EVENT_TEMP_THRESHOLD:
7794 _scsih_temp_threshold_events(ioc,
7795 (Mpi2EventDataTemperature_t *)
7796 mpi_reply->EventData);
7799 default: /* ignore the rest */
7803 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7804 fw_event = alloc_fw_event_work(sz);
7806 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7807 ioc->name, __FILE__, __LINE__, __func__);
7811 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7812 fw_event->ioc = ioc;
7813 fw_event->VF_ID = mpi_reply->VF_ID;
7814 fw_event->VP_ID = mpi_reply->VP_ID;
7815 fw_event->event = event;
7816 _scsih_fw_event_add(ioc, fw_event);
7817 fw_event_work_put(fw_event);
7822 * _scsih_expander_node_remove - removing expander device from list.
7823 * @ioc: per adapter object
7824 * @sas_expander: the sas_device object
7825 * Context: Calling function should acquire ioc->sas_node_lock.
7827 * Removing object and freeing associated memory from the
7828 * ioc->sas_expander_list.
7833 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7834 struct _sas_node *sas_expander)
7836 struct _sas_port *mpt3sas_port, *next;
7838 /* remove sibling ports attached to this expander */
7839 list_for_each_entry_safe(mpt3sas_port, next,
7840 &sas_expander->sas_port_list, port_list) {
7841 if (ioc->shost_recovery)
7843 if (mpt3sas_port->remote_identify.device_type ==
7845 mpt3sas_device_remove_by_sas_address(ioc,
7846 mpt3sas_port->remote_identify.sas_address);
7847 else if (mpt3sas_port->remote_identify.device_type ==
7848 SAS_EDGE_EXPANDER_DEVICE ||
7849 mpt3sas_port->remote_identify.device_type ==
7850 SAS_FANOUT_EXPANDER_DEVICE)
7851 mpt3sas_expander_remove(ioc,
7852 mpt3sas_port->remote_identify.sas_address);
7855 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7856 sas_expander->sas_address_parent);
7859 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7861 sas_expander->handle, (unsigned long long)
7862 sas_expander->sas_address);
7864 kfree(sas_expander->phy);
7865 kfree(sas_expander);
7869 * _scsih_ir_shutdown - IR shutdown notification
7870 * @ioc: per adapter object
7872 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7873 * the host system is shutting down.
7878 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7880 Mpi2RaidActionRequest_t *mpi_request;
7881 Mpi2RaidActionReply_t *mpi_reply;
7884 /* is IR firmware build loaded ? */
7885 if (!ioc->ir_firmware)
7888 /* are there any volumes ? */
7889 if (list_empty(&ioc->raid_device_list))
7892 mutex_lock(&ioc->scsih_cmds.mutex);
7894 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7895 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7896 ioc->name, __func__);
7899 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7901 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7903 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7904 ioc->name, __func__);
7905 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7909 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7910 ioc->scsih_cmds.smid = smid;
7911 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7913 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7914 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7916 if (!ioc->hide_ir_msg)
7917 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7918 init_completion(&ioc->scsih_cmds.done);
7919 mpt3sas_base_put_smid_default(ioc, smid);
7920 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7922 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7923 pr_err(MPT3SAS_FMT "%s: timeout\n",
7924 ioc->name, __func__);
7928 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7929 mpi_reply = ioc->scsih_cmds.reply;
7930 if (!ioc->hide_ir_msg)
7931 pr_info(MPT3SAS_FMT "IR shutdown "
7932 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
7933 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7934 le32_to_cpu(mpi_reply->IOCLogInfo));
7938 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7939 mutex_unlock(&ioc->scsih_cmds.mutex);
7943 * scsih_remove - detach and remove add host
7944 * @pdev: PCI device struct
7946 * Routine called when unloading the driver.
7949 void scsih_remove(struct pci_dev *pdev)
7951 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7952 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
7953 struct _sas_port *mpt3sas_port, *next_port;
7954 struct _raid_device *raid_device, *next;
7955 struct MPT3SAS_TARGET *sas_target_priv_data;
7956 struct workqueue_struct *wq;
7957 unsigned long flags;
7959 ioc->remove_host = 1;
7960 _scsih_fw_event_cleanup_queue(ioc);
7962 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7963 wq = ioc->firmware_event_thread;
7964 ioc->firmware_event_thread = NULL;
7965 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7967 destroy_workqueue(wq);
7969 /* release all the volumes */
7970 _scsih_ir_shutdown(ioc);
7971 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7973 if (raid_device->starget) {
7974 sas_target_priv_data =
7975 raid_device->starget->hostdata;
7976 sas_target_priv_data->deleted = 1;
7977 scsi_remove_target(&raid_device->starget->dev);
7979 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
7980 ioc->name, raid_device->handle,
7981 (unsigned long long) raid_device->wwid);
7982 _scsih_raid_device_remove(ioc, raid_device);
7985 /* free ports attached to the sas_host */
7986 list_for_each_entry_safe(mpt3sas_port, next_port,
7987 &ioc->sas_hba.sas_port_list, port_list) {
7988 if (mpt3sas_port->remote_identify.device_type ==
7990 mpt3sas_device_remove_by_sas_address(ioc,
7991 mpt3sas_port->remote_identify.sas_address);
7992 else if (mpt3sas_port->remote_identify.device_type ==
7993 SAS_EDGE_EXPANDER_DEVICE ||
7994 mpt3sas_port->remote_identify.device_type ==
7995 SAS_FANOUT_EXPANDER_DEVICE)
7996 mpt3sas_expander_remove(ioc,
7997 mpt3sas_port->remote_identify.sas_address);
8000 /* free phys attached to the sas_host */
8001 if (ioc->sas_hba.num_phys) {
8002 kfree(ioc->sas_hba.phy);
8003 ioc->sas_hba.phy = NULL;
8004 ioc->sas_hba.num_phys = 0;
8007 sas_remove_host(shost);
8008 scsi_remove_host(shost);
8009 mpt3sas_base_detach(ioc);
8010 spin_lock(&gioc_lock);
8011 list_del(&ioc->list);
8012 spin_unlock(&gioc_lock);
8013 scsi_host_put(shost);
8017 * scsih_shutdown - routine call during system shutdown
8018 * @pdev: PCI device struct
8023 scsih_shutdown(struct pci_dev *pdev)
8025 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8026 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8027 struct workqueue_struct *wq;
8028 unsigned long flags;
8030 ioc->remove_host = 1;
8031 _scsih_fw_event_cleanup_queue(ioc);
8033 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8034 wq = ioc->firmware_event_thread;
8035 ioc->firmware_event_thread = NULL;
8036 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8038 destroy_workqueue(wq);
8040 _scsih_ir_shutdown(ioc);
8041 mpt3sas_base_detach(ioc);
8046 * _scsih_probe_boot_devices - reports 1st device
8047 * @ioc: per adapter object
8049 * If specified in bios page 2, this routine reports the 1st
8050 * device scsi-ml or sas transport for persistent boot device
8051 * purposes. Please refer to function _scsih_determine_boot_device()
8054 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8058 struct _sas_device *sas_device;
8059 struct _raid_device *raid_device;
8061 u64 sas_address_parent;
8063 unsigned long flags;
8066 /* no Bios, return immediately */
8067 if (!ioc->bios_pg3.BiosVersion)
8072 if (ioc->req_boot_device.device) {
8073 device = ioc->req_boot_device.device;
8074 is_raid = ioc->req_boot_device.is_raid;
8075 } else if (ioc->req_alt_boot_device.device) {
8076 device = ioc->req_alt_boot_device.device;
8077 is_raid = ioc->req_alt_boot_device.is_raid;
8078 } else if (ioc->current_boot_device.device) {
8079 device = ioc->current_boot_device.device;
8080 is_raid = ioc->current_boot_device.is_raid;
8087 raid_device = device;
8088 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8089 raid_device->id, 0);
8091 _scsih_raid_device_remove(ioc, raid_device);
8093 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8094 sas_device = device;
8095 handle = sas_device->handle;
8096 sas_address_parent = sas_device->sas_address_parent;
8097 sas_address = sas_device->sas_address;
8098 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8099 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8101 if (ioc->hide_drives)
8103 if (!mpt3sas_transport_port_add(ioc, handle,
8104 sas_address_parent)) {
8105 _scsih_sas_device_remove(ioc, sas_device);
8106 } else if (!sas_device->starget) {
8107 if (!ioc->is_driver_loading) {
8108 mpt3sas_transport_port_remove(ioc,
8110 sas_address_parent);
8111 _scsih_sas_device_remove(ioc, sas_device);
8118 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8119 * @ioc: per adapter object
8121 * Called during initial loading of the driver.
8124 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8126 struct _raid_device *raid_device, *raid_next;
8129 list_for_each_entry_safe(raid_device, raid_next,
8130 &ioc->raid_device_list, list) {
8131 if (raid_device->starget)
8133 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8134 raid_device->id, 0);
8136 _scsih_raid_device_remove(ioc, raid_device);
8140 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8142 struct _sas_device *sas_device = NULL;
8143 unsigned long flags;
8145 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8146 if (!list_empty(&ioc->sas_device_init_list)) {
8147 sas_device = list_first_entry(&ioc->sas_device_init_list,
8148 struct _sas_device, list);
8149 sas_device_get(sas_device);
8151 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8156 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8157 struct _sas_device *sas_device)
8159 unsigned long flags;
8161 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8164 * Since we dropped the lock during the call to port_add(), we need to
8165 * be careful here that somebody else didn't move or delete this item
8166 * while we were busy with other things.
8168 * If it was on the list, we need a put() for the reference the list
8169 * had. Either way, we need a get() for the destination list.
8171 if (!list_empty(&sas_device->list)) {
8172 list_del_init(&sas_device->list);
8173 sas_device_put(sas_device);
8176 sas_device_get(sas_device);
8177 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8179 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8183 * _scsih_probe_sas - reporting sas devices to sas transport
8184 * @ioc: per adapter object
8186 * Called during initial loading of the driver.
8189 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8191 struct _sas_device *sas_device;
8193 if (ioc->hide_drives)
8196 while ((sas_device = get_next_sas_device(ioc))) {
8197 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8198 sas_device->sas_address_parent)) {
8199 _scsih_sas_device_remove(ioc, sas_device);
8200 sas_device_put(sas_device);
8202 } else if (!sas_device->starget) {
8204 * When asyn scanning is enabled, its not possible to
8205 * remove devices while scanning is turned on due to an
8206 * oops in scsi_sysfs_add_sdev()->add_device()->
8207 * sysfs_addrm_start()
8209 if (!ioc->is_driver_loading) {
8210 mpt3sas_transport_port_remove(ioc,
8211 sas_device->sas_address,
8212 sas_device->sas_address_parent);
8213 _scsih_sas_device_remove(ioc, sas_device);
8214 sas_device_put(sas_device);
8218 sas_device_make_active(ioc, sas_device);
8219 sas_device_put(sas_device);
8224 * _scsih_probe_devices - probing for devices
8225 * @ioc: per adapter object
8227 * Called during initial loading of the driver.
8230 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8232 u16 volume_mapping_flags;
8234 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8235 return; /* return when IOC doesn't support initiator mode */
8237 _scsih_probe_boot_devices(ioc);
8239 if (ioc->ir_firmware) {
8240 volume_mapping_flags =
8241 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8242 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8243 if (volume_mapping_flags ==
8244 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8245 _scsih_probe_raid(ioc);
8246 _scsih_probe_sas(ioc);
8248 _scsih_probe_sas(ioc);
8249 _scsih_probe_raid(ioc);
8252 _scsih_probe_sas(ioc);
8256 * scsih_scan_start - scsi lld callback for .scan_start
8257 * @shost: SCSI host pointer
8259 * The shost has the ability to discover targets on its own instead
8260 * of scanning the entire bus. In our implemention, we will kick off
8261 * firmware discovery.
8264 scsih_scan_start(struct Scsi_Host *shost)
8266 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8268 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8269 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8271 if (disable_discovery > 0)
8274 ioc->start_scan = 1;
8275 rc = mpt3sas_port_enable(ioc);
8278 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8282 * scsih_scan_finished - scsi lld callback for .scan_finished
8283 * @shost: SCSI host pointer
8284 * @time: elapsed time of the scan in jiffies
8286 * This function will be called periodicallyn until it returns 1 with the
8287 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8288 * we wait for firmware discovery to complete, then return 1.
8291 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8293 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8295 if (disable_discovery > 0) {
8296 ioc->is_driver_loading = 0;
8297 ioc->wait_for_discovery_to_complete = 0;
8301 if (time >= (300 * HZ)) {
8302 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8304 "port enable: FAILED with timeout (timeout=300s)\n",
8306 ioc->is_driver_loading = 0;
8310 if (ioc->start_scan)
8313 if (ioc->start_scan_failed) {
8315 "port enable: FAILED with (ioc_status=0x%08x)\n",
8316 ioc->name, ioc->start_scan_failed);
8317 ioc->is_driver_loading = 0;
8318 ioc->wait_for_discovery_to_complete = 0;
8319 ioc->remove_host = 1;
8323 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8324 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8326 if (ioc->wait_for_discovery_to_complete) {
8327 ioc->wait_for_discovery_to_complete = 0;
8328 _scsih_probe_devices(ioc);
8330 mpt3sas_base_start_watchdog(ioc);
8331 ioc->is_driver_loading = 0;
8335 /* shost template for SAS 2.0 HBA devices */
8336 static struct scsi_host_template mpt2sas_driver_template = {
8337 .module = THIS_MODULE,
8338 .name = "Fusion MPT SAS Host",
8339 .proc_name = MPT2SAS_DRIVER_NAME,
8340 .queuecommand = scsih_qcmd,
8341 .target_alloc = scsih_target_alloc,
8342 .slave_alloc = scsih_slave_alloc,
8343 .slave_configure = scsih_slave_configure,
8344 .target_destroy = scsih_target_destroy,
8345 .slave_destroy = scsih_slave_destroy,
8346 .scan_finished = scsih_scan_finished,
8347 .scan_start = scsih_scan_start,
8348 .change_queue_depth = scsih_change_queue_depth,
8349 .eh_abort_handler = scsih_abort,
8350 .eh_device_reset_handler = scsih_dev_reset,
8351 .eh_target_reset_handler = scsih_target_reset,
8352 .eh_host_reset_handler = scsih_host_reset,
8353 .bios_param = scsih_bios_param,
8356 .sg_tablesize = MPT2SAS_SG_DEPTH,
8357 .max_sectors = 32767,
8359 .use_clustering = ENABLE_CLUSTERING,
8360 .shost_attrs = mpt3sas_host_attrs,
8361 .sdev_attrs = mpt3sas_dev_attrs,
8362 .track_queue_depth = 1,
8365 /* raid transport support for SAS 2.0 HBA devices */
8366 static struct raid_function_template mpt2sas_raid_functions = {
8367 .cookie = &mpt2sas_driver_template,
8368 .is_raid = scsih_is_raid,
8369 .get_resync = scsih_get_resync,
8370 .get_state = scsih_get_state,
8373 /* shost template for SAS 3.0 HBA devices */
8374 static struct scsi_host_template mpt3sas_driver_template = {
8375 .module = THIS_MODULE,
8376 .name = "Fusion MPT SAS Host",
8377 .proc_name = MPT3SAS_DRIVER_NAME,
8378 .queuecommand = scsih_qcmd,
8379 .target_alloc = scsih_target_alloc,
8380 .slave_alloc = scsih_slave_alloc,
8381 .slave_configure = scsih_slave_configure,
8382 .target_destroy = scsih_target_destroy,
8383 .slave_destroy = scsih_slave_destroy,
8384 .scan_finished = scsih_scan_finished,
8385 .scan_start = scsih_scan_start,
8386 .change_queue_depth = scsih_change_queue_depth,
8387 .eh_abort_handler = scsih_abort,
8388 .eh_device_reset_handler = scsih_dev_reset,
8389 .eh_target_reset_handler = scsih_target_reset,
8390 .eh_host_reset_handler = scsih_host_reset,
8391 .bios_param = scsih_bios_param,
8394 .sg_tablesize = MPT3SAS_SG_DEPTH,
8395 .max_sectors = 32767,
8397 .use_clustering = ENABLE_CLUSTERING,
8398 .shost_attrs = mpt3sas_host_attrs,
8399 .sdev_attrs = mpt3sas_dev_attrs,
8400 .track_queue_depth = 1,
8403 /* raid transport support for SAS 3.0 HBA devices */
8404 static struct raid_function_template mpt3sas_raid_functions = {
8405 .cookie = &mpt3sas_driver_template,
8406 .is_raid = scsih_is_raid,
8407 .get_resync = scsih_get_resync,
8408 .get_state = scsih_get_state,
8412 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8413 * this device belongs to.
8414 * @pdev: PCI device struct
8416 * return MPI2_VERSION for SAS 2.0 HBA devices,
8417 * MPI25_VERSION for SAS 3.0 HBA devices.
8420 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8423 switch (pdev->device) {
8424 case MPI2_MFGPAGE_DEVID_SSS6200:
8425 case MPI2_MFGPAGE_DEVID_SAS2004:
8426 case MPI2_MFGPAGE_DEVID_SAS2008:
8427 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8428 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8429 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8430 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8431 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8432 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8433 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8434 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8435 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8436 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8437 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8438 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8439 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8440 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8441 return MPI2_VERSION;
8442 case MPI25_MFGPAGE_DEVID_SAS3004:
8443 case MPI25_MFGPAGE_DEVID_SAS3008:
8444 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8445 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8446 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8447 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8448 return MPI25_VERSION;
8454 * _scsih_probe - attach and add scsi host
8455 * @pdev: PCI device struct
8456 * @id: pci device id
8458 * Returns 0 success, anything else error.
8461 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8463 struct MPT3SAS_ADAPTER *ioc;
8464 struct Scsi_Host *shost = NULL;
8466 u16 hba_mpi_version;
8468 /* Determine in which MPI version class this pci device belongs */
8469 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8470 if (hba_mpi_version == 0)
8473 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8474 * for other generation HBA's return with -ENODEV
8476 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8479 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8480 * for other generation HBA's return with -ENODEV
8482 if ((hbas_to_enumerate == 2) && (hba_mpi_version != MPI25_VERSION))
8485 switch (hba_mpi_version) {
8487 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
8488 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
8489 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8490 shost = scsi_host_alloc(&mpt2sas_driver_template,
8491 sizeof(struct MPT3SAS_ADAPTER));
8494 ioc = shost_priv(shost);
8495 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8496 ioc->hba_mpi_version_belonged = hba_mpi_version;
8497 ioc->id = mpt2_ids++;
8498 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8499 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8500 ioc->is_warpdrive = 1;
8501 ioc->hide_ir_msg = 1;
8503 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8506 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8507 shost = scsi_host_alloc(&mpt3sas_driver_template,
8508 sizeof(struct MPT3SAS_ADAPTER));
8511 ioc = shost_priv(shost);
8512 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8513 ioc->hba_mpi_version_belonged = hba_mpi_version;
8514 ioc->id = mpt3_ids++;
8515 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8516 if (pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION)
8517 ioc->msix96_vector = 1;
8523 INIT_LIST_HEAD(&ioc->list);
8524 spin_lock(&gioc_lock);
8525 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8526 spin_unlock(&gioc_lock);
8529 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8530 ioc->tm_cb_idx = tm_cb_idx;
8531 ioc->ctl_cb_idx = ctl_cb_idx;
8532 ioc->base_cb_idx = base_cb_idx;
8533 ioc->port_enable_cb_idx = port_enable_cb_idx;
8534 ioc->transport_cb_idx = transport_cb_idx;
8535 ioc->scsih_cb_idx = scsih_cb_idx;
8536 ioc->config_cb_idx = config_cb_idx;
8537 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8538 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8539 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8540 ioc->logging_level = logging_level;
8541 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8542 /* misc semaphores and spin locks */
8543 mutex_init(&ioc->reset_in_progress_mutex);
8544 /* initializing pci_access_mutex lock */
8545 mutex_init(&ioc->pci_access_mutex);
8546 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8547 spin_lock_init(&ioc->scsi_lookup_lock);
8548 spin_lock_init(&ioc->sas_device_lock);
8549 spin_lock_init(&ioc->sas_node_lock);
8550 spin_lock_init(&ioc->fw_event_lock);
8551 spin_lock_init(&ioc->raid_device_lock);
8552 spin_lock_init(&ioc->diag_trigger_lock);
8554 INIT_LIST_HEAD(&ioc->sas_device_list);
8555 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8556 INIT_LIST_HEAD(&ioc->sas_expander_list);
8557 INIT_LIST_HEAD(&ioc->fw_event_list);
8558 INIT_LIST_HEAD(&ioc->raid_device_list);
8559 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8560 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8561 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8562 INIT_LIST_HEAD(&ioc->reply_queue_list);
8564 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8566 /* init shost parameters */
8567 shost->max_cmd_len = 32;
8568 shost->max_lun = max_lun;
8569 shost->transportt = mpt3sas_transport_template;
8570 shost->unique_id = ioc->id;
8572 if (max_sectors != 0xFFFF) {
8573 if (max_sectors < 64) {
8574 shost->max_sectors = 64;
8575 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8576 "for max_sectors, range is 64 to 32767. Assigning "
8577 "value of 64.\n", ioc->name, max_sectors);
8578 } else if (max_sectors > 32767) {
8579 shost->max_sectors = 32767;
8580 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8581 "for max_sectors, range is 64 to 32767. Assigning "
8582 "default value of 32767.\n", ioc->name,
8585 shost->max_sectors = max_sectors & 0xFFFE;
8587 "The max_sectors value is set to %d\n",
8588 ioc->name, shost->max_sectors);
8592 /* register EEDP capabilities with SCSI layer */
8594 scsi_host_set_prot(shost, prot_mask);
8596 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8597 | SHOST_DIF_TYPE2_PROTECTION
8598 | SHOST_DIF_TYPE3_PROTECTION);
8600 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8603 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8604 "fw_event_%s%d", ioc->driver_name, ioc->id);
8605 ioc->firmware_event_thread = alloc_ordered_workqueue(
8606 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8607 if (!ioc->firmware_event_thread) {
8608 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8609 ioc->name, __FILE__, __LINE__, __func__);
8611 goto out_thread_fail;
8614 ioc->is_driver_loading = 1;
8615 if ((mpt3sas_base_attach(ioc))) {
8616 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8617 ioc->name, __FILE__, __LINE__, __func__);
8619 goto out_attach_fail;
8622 if (ioc->is_warpdrive) {
8623 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8624 ioc->hide_drives = 0;
8625 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8626 ioc->hide_drives = 1;
8628 if (mpt3sas_get_num_volumes(ioc))
8629 ioc->hide_drives = 1;
8631 ioc->hide_drives = 0;
8634 ioc->hide_drives = 0;
8636 rv = scsi_add_host(shost, &pdev->dev);
8638 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8639 ioc->name, __FILE__, __LINE__, __func__);
8640 goto out_add_shost_fail;
8643 scsi_scan_host(shost);
8646 mpt3sas_base_detach(ioc);
8648 destroy_workqueue(ioc->firmware_event_thread);
8650 spin_lock(&gioc_lock);
8651 list_del(&ioc->list);
8652 spin_unlock(&gioc_lock);
8653 scsi_host_put(shost);
8659 * scsih_suspend - power management suspend main entry point
8660 * @pdev: PCI device struct
8661 * @state: PM state change to (usually PCI_D3)
8663 * Returns 0 success, anything else error.
8666 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8668 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8669 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8670 pci_power_t device_state;
8672 mpt3sas_base_stop_watchdog(ioc);
8673 flush_scheduled_work();
8674 scsi_block_requests(shost);
8675 device_state = pci_choose_state(pdev, state);
8677 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8678 ioc->name, pdev, pci_name(pdev), device_state);
8680 pci_save_state(pdev);
8681 mpt3sas_base_free_resources(ioc);
8682 pci_set_power_state(pdev, device_state);
8687 * scsih_resume - power management resume main entry point
8688 * @pdev: PCI device struct
8690 * Returns 0 success, anything else error.
8693 scsih_resume(struct pci_dev *pdev)
8695 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8696 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8697 pci_power_t device_state = pdev->current_state;
8701 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8702 ioc->name, pdev, pci_name(pdev), device_state);
8704 pci_set_power_state(pdev, PCI_D0);
8705 pci_enable_wake(pdev, PCI_D0, 0);
8706 pci_restore_state(pdev);
8708 r = mpt3sas_base_map_resources(ioc);
8712 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8713 scsi_unblock_requests(shost);
8714 mpt3sas_base_start_watchdog(ioc);
8717 #endif /* CONFIG_PM */
8720 * scsih_pci_error_detected - Called when a PCI error is detected.
8721 * @pdev: PCI device struct
8722 * @state: PCI channel state
8724 * Description: Called when a PCI error is detected.
8727 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8730 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8732 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8733 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8735 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8739 case pci_channel_io_normal:
8740 return PCI_ERS_RESULT_CAN_RECOVER;
8741 case pci_channel_io_frozen:
8742 /* Fatal error, prepare for slot reset */
8743 ioc->pci_error_recovery = 1;
8744 scsi_block_requests(ioc->shost);
8745 mpt3sas_base_stop_watchdog(ioc);
8746 mpt3sas_base_free_resources(ioc);
8747 return PCI_ERS_RESULT_NEED_RESET;
8748 case pci_channel_io_perm_failure:
8749 /* Permanent error, prepare for device removal */
8750 ioc->pci_error_recovery = 1;
8751 mpt3sas_base_stop_watchdog(ioc);
8752 _scsih_flush_running_cmds(ioc);
8753 return PCI_ERS_RESULT_DISCONNECT;
8755 return PCI_ERS_RESULT_NEED_RESET;
8759 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8760 * @pdev: PCI device struct
8762 * Description: This routine is called by the pci error recovery
8763 * code after the PCI slot has been reset, just before we
8764 * should resume normal operations.
8767 scsih_pci_slot_reset(struct pci_dev *pdev)
8769 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8770 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8773 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8776 ioc->pci_error_recovery = 0;
8778 pci_restore_state(pdev);
8779 rc = mpt3sas_base_map_resources(ioc);
8781 return PCI_ERS_RESULT_DISCONNECT;
8783 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8786 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8787 (rc == 0) ? "success" : "failed");
8790 return PCI_ERS_RESULT_RECOVERED;
8792 return PCI_ERS_RESULT_DISCONNECT;
8796 * scsih_pci_resume() - resume normal ops after PCI reset
8797 * @pdev: pointer to PCI device
8799 * Called when the error recovery driver tells us that its
8800 * OK to resume normal operation. Use completion to allow
8801 * halted scsi ops to resume.
8804 scsih_pci_resume(struct pci_dev *pdev)
8806 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8807 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8809 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8811 pci_cleanup_aer_uncorrect_error_status(pdev);
8812 mpt3sas_base_start_watchdog(ioc);
8813 scsi_unblock_requests(ioc->shost);
8817 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8818 * @pdev: pointer to PCI device
8821 scsih_pci_mmio_enabled(struct pci_dev *pdev)
8823 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8824 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8826 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8829 /* TODO - dump whatever for debugging purposes */
8831 /* Request a slot reset. */
8832 return PCI_ERS_RESULT_NEED_RESET;
8836 * The pci device ids are defined in mpi/mpi2_cnfg.h.
8838 static const struct pci_device_id mpt3sas_pci_table[] = {
8839 /* Spitfire ~ 2004 */
8840 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
8841 PCI_ANY_ID, PCI_ANY_ID },
8843 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
8844 PCI_ANY_ID, PCI_ANY_ID },
8845 /* Liberator ~ 2108 */
8846 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
8847 PCI_ANY_ID, PCI_ANY_ID },
8848 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
8849 PCI_ANY_ID, PCI_ANY_ID },
8850 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
8851 PCI_ANY_ID, PCI_ANY_ID },
8853 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
8854 PCI_ANY_ID, PCI_ANY_ID },
8855 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
8856 PCI_ANY_ID, PCI_ANY_ID },
8857 /* Thunderbolt ~ 2208 */
8858 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
8859 PCI_ANY_ID, PCI_ANY_ID },
8860 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
8861 PCI_ANY_ID, PCI_ANY_ID },
8862 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
8863 PCI_ANY_ID, PCI_ANY_ID },
8864 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
8865 PCI_ANY_ID, PCI_ANY_ID },
8866 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
8867 PCI_ANY_ID, PCI_ANY_ID },
8868 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
8869 PCI_ANY_ID, PCI_ANY_ID },
8870 /* Mustang ~ 2308 */
8871 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
8872 PCI_ANY_ID, PCI_ANY_ID },
8873 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
8874 PCI_ANY_ID, PCI_ANY_ID },
8875 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
8876 PCI_ANY_ID, PCI_ANY_ID },
8878 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
8879 PCI_ANY_ID, PCI_ANY_ID },
8880 /* Fury ~ 3004 and 3008 */
8881 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
8882 PCI_ANY_ID, PCI_ANY_ID },
8883 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
8884 PCI_ANY_ID, PCI_ANY_ID },
8885 /* Invader ~ 3108 */
8886 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
8887 PCI_ANY_ID, PCI_ANY_ID },
8888 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
8889 PCI_ANY_ID, PCI_ANY_ID },
8890 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
8891 PCI_ANY_ID, PCI_ANY_ID },
8892 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
8893 PCI_ANY_ID, PCI_ANY_ID },
8894 {0} /* Terminating entry */
8896 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
8898 static struct pci_error_handlers _mpt3sas_err_handler = {
8899 .error_detected = scsih_pci_error_detected,
8900 .mmio_enabled = scsih_pci_mmio_enabled,
8901 .slot_reset = scsih_pci_slot_reset,
8902 .resume = scsih_pci_resume,
8905 static struct pci_driver mpt3sas_driver = {
8906 .name = MPT3SAS_DRIVER_NAME,
8907 .id_table = mpt3sas_pci_table,
8908 .probe = _scsih_probe,
8909 .remove = scsih_remove,
8910 .shutdown = scsih_shutdown,
8911 .err_handler = &_mpt3sas_err_handler,
8913 .suspend = scsih_suspend,
8914 .resume = scsih_resume,
8919 * scsih_init - main entry point for this driver.
8921 * Returns 0 success, anything else error.
8929 mpt3sas_base_initialize_callback_handler();
8931 /* queuecommand callback hander */
8932 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
8934 /* task managment callback handler */
8935 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
8937 /* base internal commands callback handler */
8938 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
8939 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
8940 mpt3sas_port_enable_done);
8942 /* transport internal commands callback handler */
8943 transport_cb_idx = mpt3sas_base_register_callback_handler(
8944 mpt3sas_transport_done);
8946 /* scsih internal commands callback handler */
8947 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
8949 /* configuration page API internal commands callback handler */
8950 config_cb_idx = mpt3sas_base_register_callback_handler(
8951 mpt3sas_config_done);
8953 /* ctl module callback handler */
8954 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
8956 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
8957 _scsih_tm_tr_complete);
8959 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
8960 _scsih_tm_volume_tr_complete);
8962 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
8963 _scsih_sas_control_complete);
8969 * scsih_exit - exit point for this driver (when it is a module).
8971 * Returns 0 success, anything else error.
8977 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
8978 mpt3sas_base_release_callback_handler(tm_cb_idx);
8979 mpt3sas_base_release_callback_handler(base_cb_idx);
8980 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
8981 mpt3sas_base_release_callback_handler(transport_cb_idx);
8982 mpt3sas_base_release_callback_handler(scsih_cb_idx);
8983 mpt3sas_base_release_callback_handler(config_cb_idx);
8984 mpt3sas_base_release_callback_handler(ctl_cb_idx);
8986 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
8987 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8988 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
8990 /* raid transport support */
8991 if (hbas_to_enumerate != 1)
8992 raid_class_release(mpt3sas_raid_template);
8993 if (hbas_to_enumerate != 2)
8994 raid_class_release(mpt2sas_raid_template);
8995 sas_release_transport(mpt3sas_transport_template);
8999 * _mpt3sas_init - main entry point for this driver.
9001 * Returns 0 success, anything else error.
9008 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
9009 MPT3SAS_DRIVER_VERSION);
9011 mpt3sas_transport_template =
9012 sas_attach_transport(&mpt3sas_transport_functions);
9013 if (!mpt3sas_transport_template)
9016 /* No need attach mpt3sas raid functions template
9017 * if hbas_to_enumarate value is one.
9019 if (hbas_to_enumerate != 1) {
9020 mpt3sas_raid_template =
9021 raid_class_attach(&mpt3sas_raid_functions);
9022 if (!mpt3sas_raid_template) {
9023 sas_release_transport(mpt3sas_transport_template);
9028 /* No need to attach mpt2sas raid functions template
9029 * if hbas_to_enumarate value is two
9031 if (hbas_to_enumerate != 2) {
9032 mpt2sas_raid_template =
9033 raid_class_attach(&mpt2sas_raid_functions);
9034 if (!mpt2sas_raid_template) {
9035 sas_release_transport(mpt3sas_transport_template);
9040 error = scsih_init();
9046 mpt3sas_ctl_init(hbas_to_enumerate);
9048 error = pci_register_driver(&mpt3sas_driver);
9056 * _mpt3sas_exit - exit point for this driver (when it is a module).
9062 pr_info("mpt3sas version %s unloading\n",
9063 MPT3SAS_DRIVER_VERSION);
9065 pci_unregister_driver(&mpt3sas_driver);
9067 mpt3sas_ctl_exit(hbas_to_enumerate);
9072 module_init(_mpt3sas_init);
9073 module_exit(_mpt3sas_exit);