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);
3257 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3258 * issue to IOC or not.
3259 * @ioc: per adapter object
3260 * @scmd: pointer to scsi command object
3262 * Returns true if scmd can be issued to IOC otherwise returns false.
3264 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc,
3265 struct scsi_cmnd *scmd)
3268 if (ioc->pci_error_recovery)
3271 if (ioc->hba_mpi_version_belonged == MPI2_VERSION) {
3272 if (ioc->remove_host)
3278 if (ioc->remove_host) {
3280 switch (scmd->cmnd[0]) {
3281 case SYNCHRONIZE_CACHE:
3293 * _scsih_sas_control_complete - completion routine
3294 * @ioc: per adapter object
3295 * @smid: system request message index
3296 * @msix_index: MSIX table index supplied by the OS
3297 * @reply: reply message frame(lower 32bit addr)
3298 * Context: interrupt time.
3300 * This is the sas iounit control completion routine.
3301 * This code is part of the code to initiate the device removal
3302 * handshake protocol with controller firmware.
3304 * Return 1 meaning mf should be freed from _base_interrupt
3305 * 0 means the mf is freed from this function.
3308 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3309 u8 msix_index, u32 reply)
3311 Mpi2SasIoUnitControlReply_t *mpi_reply =
3312 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3314 if (likely(mpi_reply)) {
3315 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3316 "sc_complete:handle(0x%04x), (open) "
3317 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3318 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3319 le16_to_cpu(mpi_reply->IOCStatus),
3320 le32_to_cpu(mpi_reply->IOCLogInfo)));
3322 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3323 ioc->name, __FILE__, __LINE__, __func__);
3329 * _scsih_tm_tr_volume_send - send target reset request for volumes
3330 * @ioc: per adapter object
3331 * @handle: device handle
3332 * Context: interrupt time.
3334 * This is designed to send muliple task management request at the same
3335 * time to the fifo. If the fifo is full, we will append the request,
3336 * and process it in a future completion.
3339 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3341 Mpi2SCSITaskManagementRequest_t *mpi_request;
3343 struct _tr_list *delayed_tr;
3345 if (ioc->shost_recovery || ioc->remove_host ||
3346 ioc->pci_error_recovery) {
3347 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3348 "%s: host reset in progress!\n",
3349 __func__, ioc->name));
3353 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3355 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3358 INIT_LIST_HEAD(&delayed_tr->list);
3359 delayed_tr->handle = handle;
3360 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3361 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3362 "DELAYED:tr:handle(0x%04x), (open)\n",
3363 ioc->name, handle));
3367 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3368 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3369 ioc->name, handle, smid,
3370 ioc->tm_tr_volume_cb_idx));
3371 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3372 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3373 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3374 mpi_request->DevHandle = cpu_to_le16(handle);
3375 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3376 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3380 * _scsih_tm_volume_tr_complete - target reset completion
3381 * @ioc: per adapter object
3382 * @smid: system request message index
3383 * @msix_index: MSIX table index supplied by the OS
3384 * @reply: reply message frame(lower 32bit addr)
3385 * Context: interrupt time.
3387 * Return 1 meaning mf should be freed from _base_interrupt
3388 * 0 means the mf is freed from this function.
3391 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3392 u8 msix_index, u32 reply)
3395 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3396 Mpi2SCSITaskManagementReply_t *mpi_reply =
3397 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3399 if (ioc->shost_recovery || ioc->remove_host ||
3400 ioc->pci_error_recovery) {
3401 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3402 "%s: host reset in progress!\n",
3403 __func__, ioc->name));
3406 if (unlikely(!mpi_reply)) {
3407 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3408 ioc->name, __FILE__, __LINE__, __func__);
3412 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3413 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3414 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3415 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3416 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3418 le16_to_cpu(mpi_reply->DevHandle), smid));
3422 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3423 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3424 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3425 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3426 le32_to_cpu(mpi_reply->IOCLogInfo),
3427 le32_to_cpu(mpi_reply->TerminationCount)));
3429 return _scsih_check_for_pending_tm(ioc, smid);
3434 * _scsih_check_for_pending_tm - check for pending task management
3435 * @ioc: per adapter object
3436 * @smid: system request message index
3438 * This will check delayed target reset list, and feed the
3441 * Return 1 meaning mf should be freed from _base_interrupt
3442 * 0 means the mf is freed from this function.
3445 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3447 struct _tr_list *delayed_tr;
3449 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3450 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3451 struct _tr_list, list);
3452 mpt3sas_base_free_smid(ioc, smid);
3453 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3454 list_del(&delayed_tr->list);
3459 if (!list_empty(&ioc->delayed_tr_list)) {
3460 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3461 struct _tr_list, list);
3462 mpt3sas_base_free_smid(ioc, smid);
3463 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3464 list_del(&delayed_tr->list);
3473 * _scsih_check_topo_delete_events - sanity check on topo events
3474 * @ioc: per adapter object
3475 * @event_data: the event data payload
3477 * This routine added to better handle cable breaker.
3479 * This handles the case where driver receives multiple expander
3480 * add and delete events in a single shot. When there is a delete event
3481 * the routine will void any pending add events waiting in the event queue.
3486 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3487 Mpi2EventDataSasTopologyChangeList_t *event_data)
3489 struct fw_event_work *fw_event;
3490 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3491 u16 expander_handle;
3492 struct _sas_node *sas_expander;
3493 unsigned long flags;
3497 for (i = 0 ; i < event_data->NumEntries; i++) {
3498 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3501 reason_code = event_data->PHY[i].PhyStatus &
3502 MPI2_EVENT_SAS_TOPO_RC_MASK;
3503 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3504 _scsih_tm_tr_send(ioc, handle);
3507 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3508 if (expander_handle < ioc->sas_hba.num_phys) {
3509 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3512 if (event_data->ExpStatus ==
3513 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3514 /* put expander attached devices into blocking state */
3515 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3516 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3518 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3519 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3521 handle = find_first_bit(ioc->blocking_handles,
3522 ioc->facts.MaxDevHandle);
3523 if (handle < ioc->facts.MaxDevHandle)
3524 _scsih_block_io_device(ioc, handle);
3525 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3526 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3527 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3529 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3532 /* mark ignore flag for pending events */
3533 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3534 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3535 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3538 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3539 fw_event->event_data;
3540 if (local_event_data->ExpStatus ==
3541 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3542 local_event_data->ExpStatus ==
3543 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3544 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3546 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3547 "setting ignoring flag\n", ioc->name));
3548 fw_event->ignore = 1;
3552 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3556 * _scsih_set_volume_delete_flag - setting volume delete flag
3557 * @ioc: per adapter object
3558 * @handle: device handle
3560 * This returns nothing.
3563 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3565 struct _raid_device *raid_device;
3566 struct MPT3SAS_TARGET *sas_target_priv_data;
3567 unsigned long flags;
3569 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3570 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3571 if (raid_device && raid_device->starget &&
3572 raid_device->starget->hostdata) {
3573 sas_target_priv_data =
3574 raid_device->starget->hostdata;
3575 sas_target_priv_data->deleted = 1;
3576 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3577 "setting delete flag: handle(0x%04x), "
3578 "wwid(0x%016llx)\n", ioc->name, handle,
3579 (unsigned long long) raid_device->wwid));
3581 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3585 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3586 * @handle: input handle
3587 * @a: handle for volume a
3588 * @b: handle for volume b
3590 * IR firmware only supports two raid volumes. The purpose of this
3591 * routine is to set the volume handle in either a or b. When the given
3592 * input handle is non-zero, or when a and b have not been set before.
3595 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3597 if (!handle || handle == *a || handle == *b)
3606 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3607 * @ioc: per adapter object
3608 * @event_data: the event data payload
3609 * Context: interrupt time.
3611 * This routine will send target reset to volume, followed by target
3612 * resets to the PDs. This is called when a PD has been removed, or
3613 * volume has been deleted or removed. When the target reset is sent
3614 * to volume, the PD target resets need to be queued to start upon
3615 * completion of the volume target reset.
3620 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3621 Mpi2EventDataIrConfigChangeList_t *event_data)
3623 Mpi2EventIrConfigElement_t *element;
3625 u16 handle, volume_handle, a, b;
3626 struct _tr_list *delayed_tr;
3631 if (ioc->is_warpdrive)
3634 /* Volume Resets for Deleted or Removed */
3635 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3636 for (i = 0; i < event_data->NumElements; i++, element++) {
3637 if (le32_to_cpu(event_data->Flags) &
3638 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3640 if (element->ReasonCode ==
3641 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3642 element->ReasonCode ==
3643 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3644 volume_handle = le16_to_cpu(element->VolDevHandle);
3645 _scsih_set_volume_delete_flag(ioc, volume_handle);
3646 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3650 /* Volume Resets for UNHIDE events */
3651 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3652 for (i = 0; i < event_data->NumElements; i++, element++) {
3653 if (le32_to_cpu(event_data->Flags) &
3654 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3656 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3657 volume_handle = le16_to_cpu(element->VolDevHandle);
3658 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3663 _scsih_tm_tr_volume_send(ioc, a);
3665 _scsih_tm_tr_volume_send(ioc, b);
3667 /* PD target resets */
3668 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3669 for (i = 0; i < event_data->NumElements; i++, element++) {
3670 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3672 handle = le16_to_cpu(element->PhysDiskDevHandle);
3673 volume_handle = le16_to_cpu(element->VolDevHandle);
3674 clear_bit(handle, ioc->pd_handles);
3676 _scsih_tm_tr_send(ioc, handle);
3677 else if (volume_handle == a || volume_handle == b) {
3678 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3679 BUG_ON(!delayed_tr);
3680 INIT_LIST_HEAD(&delayed_tr->list);
3681 delayed_tr->handle = handle;
3682 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3683 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3684 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3687 _scsih_tm_tr_send(ioc, handle);
3693 * _scsih_check_volume_delete_events - set delete flag for volumes
3694 * @ioc: per adapter object
3695 * @event_data: the event data payload
3696 * Context: interrupt time.
3698 * This will handle the case when the cable connected to entire volume is
3699 * pulled. We will take care of setting the deleted flag so normal IO will
3705 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3706 Mpi2EventDataIrVolume_t *event_data)
3710 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3712 state = le32_to_cpu(event_data->NewValue);
3713 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3714 MPI2_RAID_VOL_STATE_FAILED)
3715 _scsih_set_volume_delete_flag(ioc,
3716 le16_to_cpu(event_data->VolDevHandle));
3720 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3721 * @ioc: per adapter object
3722 * @event_data: the temp threshold event data
3723 * Context: interrupt time.
3728 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3729 Mpi2EventDataTemperature_t *event_data)
3731 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3732 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3733 " exceeded for Sensor: %d !!!\n", ioc->name,
3734 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3735 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3736 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3737 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3738 event_data->SensorNum);
3739 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3740 ioc->name, event_data->CurrentTemperature);
3744 static int _scsih_set_satl_pending(struct scsi_cmnd *scmd, bool pending)
3746 struct MPT3SAS_DEVICE *priv = scmd->device->hostdata;
3748 if (scmd->cmnd[0] != ATA_12 && scmd->cmnd[0] != ATA_16)
3752 return test_and_set_bit(0, &priv->ata_command_pending);
3754 clear_bit(0, &priv->ata_command_pending);
3759 * _scsih_flush_running_cmds - completing outstanding commands.
3760 * @ioc: per adapter object
3762 * The flushing out of all pending scmd commands following host reset,
3763 * where all IO is dropped to the floor.
3768 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3770 struct scsi_cmnd *scmd;
3774 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3775 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3779 _scsih_set_satl_pending(scmd, false);
3780 mpt3sas_base_free_smid(ioc, smid);
3781 scsi_dma_unmap(scmd);
3782 if (ioc->pci_error_recovery)
3783 scmd->result = DID_NO_CONNECT << 16;
3785 scmd->result = DID_RESET << 16;
3786 scmd->scsi_done(scmd);
3788 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3793 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3794 * @ioc: per adapter object
3795 * @scmd: pointer to scsi command object
3796 * @mpi_request: pointer to the SCSI_IO reqest message frame
3798 * Supporting protection 1 and 3.
3803 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3804 Mpi2SCSIIORequest_t *mpi_request)
3807 unsigned char prot_op = scsi_get_prot_op(scmd);
3808 unsigned char prot_type = scsi_get_prot_type(scmd);
3809 Mpi25SCSIIORequest_t *mpi_request_3v =
3810 (Mpi25SCSIIORequest_t *)mpi_request;
3812 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3815 if (prot_op == SCSI_PROT_READ_STRIP)
3816 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3817 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3818 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3822 switch (prot_type) {
3823 case SCSI_PROT_DIF_TYPE1:
3824 case SCSI_PROT_DIF_TYPE2:
3827 * enable ref/guard checking
3828 * auto increment ref tag
3830 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3831 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3832 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3833 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3834 cpu_to_be32(scsi_get_lba(scmd));
3837 case SCSI_PROT_DIF_TYPE3:
3840 * enable guard checking
3842 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3847 mpi_request_3v->EEDPBlockSize =
3848 cpu_to_le16(scmd->device->sector_size);
3849 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3853 * _scsih_eedp_error_handling - return sense code for EEDP errors
3854 * @scmd: pointer to scsi command object
3855 * @ioc_status: ioc status
3860 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3864 switch (ioc_status) {
3865 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3868 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3871 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3878 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
3880 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3881 SAM_STAT_CHECK_CONDITION;
3885 * scsih_qcmd - main scsi request entry point
3886 * @scmd: pointer to scsi command object
3887 * @done: function pointer to be invoked on completion
3889 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3891 * Returns 0 on success. If there's a failure, return either:
3892 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3893 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3896 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3898 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3899 struct MPT3SAS_DEVICE *sas_device_priv_data;
3900 struct MPT3SAS_TARGET *sas_target_priv_data;
3901 struct _raid_device *raid_device;
3902 Mpi2SCSIIORequest_t *mpi_request;
3907 if (ioc->logging_level & MPT_DEBUG_SCSI)
3908 scsi_print_command(scmd);
3910 sas_device_priv_data = scmd->device->hostdata;
3911 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3912 scmd->result = DID_NO_CONNECT << 16;
3913 scmd->scsi_done(scmd);
3917 if (!(_scsih_allow_scmd_to_device(ioc, scmd))) {
3918 scmd->result = DID_NO_CONNECT << 16;
3919 scmd->scsi_done(scmd);
3923 sas_target_priv_data = sas_device_priv_data->sas_target;
3925 /* invalid device handle */
3926 handle = sas_target_priv_data->handle;
3927 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
3928 scmd->result = DID_NO_CONNECT << 16;
3929 scmd->scsi_done(scmd);
3934 /* host recovery or link resets sent via IOCTLs */
3935 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3936 return SCSI_MLQUEUE_HOST_BUSY;
3938 /* device has been deleted */
3939 else if (sas_target_priv_data->deleted) {
3940 scmd->result = DID_NO_CONNECT << 16;
3941 scmd->scsi_done(scmd);
3943 /* device busy with task managment */
3944 } else if (sas_target_priv_data->tm_busy ||
3945 sas_device_priv_data->block)
3946 return SCSI_MLQUEUE_DEVICE_BUSY;
3949 * Bug work around for firmware SATL handling. The loop
3950 * is based on atomic operations and ensures consistency
3951 * since we're lockless at this point
3954 if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
3955 scmd->result = SAM_STAT_BUSY;
3956 scmd->scsi_done(scmd);
3959 } while (_scsih_set_satl_pending(scmd, true));
3961 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3962 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3963 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3964 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3966 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3969 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3971 /* Make sure Device is not raid volume.
3972 * We do not expose raid functionality to upper layer for warpdrive.
3974 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
3975 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3976 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3978 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3980 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
3981 ioc->name, __func__);
3982 _scsih_set_satl_pending(scmd, false);
3985 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3986 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3987 _scsih_setup_eedp(ioc, scmd, mpi_request);
3989 if (scmd->cmd_len == 32)
3990 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3991 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3992 if (sas_device_priv_data->sas_target->flags &
3993 MPT_TARGET_FLAGS_RAID_COMPONENT)
3994 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3996 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3997 mpi_request->DevHandle = cpu_to_le16(handle);
3998 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3999 mpi_request->Control = cpu_to_le32(mpi_control);
4000 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4001 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4002 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4003 mpi_request->SenseBufferLowAddress =
4004 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4005 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4006 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4008 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4010 if (mpi_request->DataLength) {
4011 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
4012 mpt3sas_base_free_smid(ioc, smid);
4013 _scsih_set_satl_pending(scmd, false);
4017 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4019 raid_device = sas_target_priv_data->raid_device;
4020 if (raid_device && raid_device->direct_io_enabled)
4021 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4024 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4025 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4026 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4027 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4028 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
4030 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4031 le16_to_cpu(mpi_request->DevHandle));
4033 mpt3sas_base_put_smid_default(ioc, smid);
4037 return SCSI_MLQUEUE_HOST_BUSY;
4041 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4042 * @sense_buffer: sense data returned by target
4043 * @data: normalized skey/asc/ascq
4048 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4050 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4051 /* descriptor format */
4052 data->skey = sense_buffer[1] & 0x0F;
4053 data->asc = sense_buffer[2];
4054 data->ascq = sense_buffer[3];
4057 data->skey = sense_buffer[2] & 0x0F;
4058 data->asc = sense_buffer[12];
4059 data->ascq = sense_buffer[13];
4064 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4065 * @ioc: per adapter object
4066 * @scmd: pointer to scsi command object
4067 * @mpi_reply: reply mf payload returned from firmware
4069 * scsi_status - SCSI Status code returned from target device
4070 * scsi_state - state info associated with SCSI_IO determined by ioc
4071 * ioc_status - ioc supplied status info
4076 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4077 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4081 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4082 MPI2_IOCSTATUS_MASK;
4083 u8 scsi_state = mpi_reply->SCSIState;
4084 u8 scsi_status = mpi_reply->SCSIStatus;
4085 char *desc_ioc_state = NULL;
4086 char *desc_scsi_status = NULL;
4087 char *desc_scsi_state = ioc->tmp_string;
4088 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4089 struct _sas_device *sas_device = NULL;
4090 struct scsi_target *starget = scmd->device->sdev_target;
4091 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4092 char *device_str = NULL;
4096 if (ioc->hide_ir_msg)
4097 device_str = "WarpDrive";
4099 device_str = "volume";
4101 if (log_info == 0x31170000)
4104 switch (ioc_status) {
4105 case MPI2_IOCSTATUS_SUCCESS:
4106 desc_ioc_state = "success";
4108 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4109 desc_ioc_state = "invalid function";
4111 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4112 desc_ioc_state = "scsi recovered error";
4114 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4115 desc_ioc_state = "scsi invalid dev handle";
4117 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4118 desc_ioc_state = "scsi device not there";
4120 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4121 desc_ioc_state = "scsi data overrun";
4123 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4124 desc_ioc_state = "scsi data underrun";
4126 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4127 desc_ioc_state = "scsi io data error";
4129 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4130 desc_ioc_state = "scsi protocol error";
4132 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4133 desc_ioc_state = "scsi task terminated";
4135 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4136 desc_ioc_state = "scsi residual mismatch";
4138 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4139 desc_ioc_state = "scsi task mgmt failed";
4141 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4142 desc_ioc_state = "scsi ioc terminated";
4144 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4145 desc_ioc_state = "scsi ext terminated";
4147 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4148 desc_ioc_state = "eedp guard error";
4150 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4151 desc_ioc_state = "eedp ref tag error";
4153 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4154 desc_ioc_state = "eedp app tag error";
4157 desc_ioc_state = "unknown";
4161 switch (scsi_status) {
4162 case MPI2_SCSI_STATUS_GOOD:
4163 desc_scsi_status = "good";
4165 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4166 desc_scsi_status = "check condition";
4168 case MPI2_SCSI_STATUS_CONDITION_MET:
4169 desc_scsi_status = "condition met";
4171 case MPI2_SCSI_STATUS_BUSY:
4172 desc_scsi_status = "busy";
4174 case MPI2_SCSI_STATUS_INTERMEDIATE:
4175 desc_scsi_status = "intermediate";
4177 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4178 desc_scsi_status = "intermediate condmet";
4180 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4181 desc_scsi_status = "reservation conflict";
4183 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4184 desc_scsi_status = "command terminated";
4186 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4187 desc_scsi_status = "task set full";
4189 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4190 desc_scsi_status = "aca active";
4192 case MPI2_SCSI_STATUS_TASK_ABORTED:
4193 desc_scsi_status = "task aborted";
4196 desc_scsi_status = "unknown";
4200 desc_scsi_state[0] = '\0';
4202 desc_scsi_state = " ";
4203 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4204 strcat(desc_scsi_state, "response info ");
4205 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4206 strcat(desc_scsi_state, "state terminated ");
4207 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4208 strcat(desc_scsi_state, "no status ");
4209 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4210 strcat(desc_scsi_state, "autosense failed ");
4211 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4212 strcat(desc_scsi_state, "autosense valid ");
4214 scsi_print_command(scmd);
4216 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4217 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4218 device_str, (unsigned long long)priv_target->sas_address);
4220 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4223 "\tsas_address(0x%016llx), phy(%d)\n",
4224 ioc->name, (unsigned long long)
4225 sas_device->sas_address, sas_device->phy);
4226 if (sas_device->enclosure_handle != 0)
4228 "\tenclosure_logical_id(0x%016llx),"
4229 "slot(%d)\n", ioc->name,
4230 (unsigned long long)
4231 sas_device->enclosure_logical_id,
4233 if (sas_device->connector_name[0])
4235 "\tenclosure level(0x%04x),"
4236 " connector name( %s)\n", ioc->name,
4237 sas_device->enclosure_level,
4238 sas_device->connector_name);
4240 sas_device_put(sas_device);
4245 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4246 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4247 desc_ioc_state, ioc_status, smid);
4249 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4250 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4251 scsi_get_resid(scmd));
4253 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4254 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4255 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4257 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4258 ioc->name, desc_scsi_status,
4259 scsi_status, desc_scsi_state, scsi_state);
4261 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4262 struct sense_info data;
4263 _scsih_normalize_sense(scmd->sense_buffer, &data);
4265 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4266 ioc->name, data.skey,
4267 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4270 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4271 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4272 response_bytes = (u8 *)&response_info;
4273 _scsih_response_code(ioc, response_bytes[0]);
4278 * _scsih_turn_on_pfa_led - illuminate PFA LED
4279 * @ioc: per adapter object
4280 * @handle: device handle
4286 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4288 Mpi2SepReply_t mpi_reply;
4289 Mpi2SepRequest_t mpi_request;
4290 struct _sas_device *sas_device;
4292 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4296 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4297 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4298 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4299 mpi_request.SlotStatus =
4300 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4301 mpi_request.DevHandle = cpu_to_le16(handle);
4302 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4303 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4304 &mpi_request)) != 0) {
4305 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4306 __FILE__, __LINE__, __func__);
4309 sas_device->pfa_led_on = 1;
4311 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4312 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4313 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4314 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4315 le32_to_cpu(mpi_reply.IOCLogInfo)));
4319 sas_device_put(sas_device);
4323 * _scsih_turn_off_pfa_led - turn off Fault LED
4324 * @ioc: per adapter object
4325 * @sas_device: sas device whose PFA LED has to turned off
4331 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4332 struct _sas_device *sas_device)
4334 Mpi2SepReply_t mpi_reply;
4335 Mpi2SepRequest_t mpi_request;
4337 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4338 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4339 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4340 mpi_request.SlotStatus = 0;
4341 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4342 mpi_request.DevHandle = 0;
4343 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4344 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4345 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4346 &mpi_request)) != 0) {
4347 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4348 __FILE__, __LINE__, __func__);
4352 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4353 dewtprintk(ioc, printk(MPT3SAS_FMT
4354 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4355 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4356 le32_to_cpu(mpi_reply.IOCLogInfo)));
4362 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4363 * @ioc: per adapter object
4364 * @handle: device handle
4365 * Context: interrupt.
4370 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4372 struct fw_event_work *fw_event;
4374 fw_event = alloc_fw_event_work(0);
4377 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4378 fw_event->device_handle = handle;
4379 fw_event->ioc = ioc;
4380 _scsih_fw_event_add(ioc, fw_event);
4381 fw_event_work_put(fw_event);
4385 * _scsih_smart_predicted_fault - process smart errors
4386 * @ioc: per adapter object
4387 * @handle: device handle
4388 * Context: interrupt.
4393 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4395 struct scsi_target *starget;
4396 struct MPT3SAS_TARGET *sas_target_priv_data;
4397 Mpi2EventNotificationReply_t *event_reply;
4398 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4399 struct _sas_device *sas_device;
4401 unsigned long flags;
4403 /* only handle non-raid devices */
4404 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4405 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4409 starget = sas_device->starget;
4410 sas_target_priv_data = starget->hostdata;
4412 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4413 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4416 if (sas_device->enclosure_handle != 0)
4417 starget_printk(KERN_INFO, starget, "predicted fault, "
4418 "enclosure logical id(0x%016llx), slot(%d)\n",
4419 (unsigned long long)sas_device->enclosure_logical_id,
4421 if (sas_device->connector_name[0] != '\0')
4422 starget_printk(KERN_WARNING, starget, "predicted fault, "
4423 "enclosure level(0x%04x), connector name( %s)\n",
4424 sas_device->enclosure_level,
4425 sas_device->connector_name);
4426 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4428 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4429 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4431 /* insert into event log */
4432 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4433 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4434 event_reply = kzalloc(sz, GFP_KERNEL);
4436 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4437 ioc->name, __FILE__, __LINE__, __func__);
4441 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4442 event_reply->Event =
4443 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4444 event_reply->MsgLength = sz/4;
4445 event_reply->EventDataLength =
4446 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4447 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4448 event_reply->EventData;
4449 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4450 event_data->ASC = 0x5D;
4451 event_data->DevHandle = cpu_to_le16(handle);
4452 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4453 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4457 sas_device_put(sas_device);
4461 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4466 * _scsih_io_done - scsi request callback
4467 * @ioc: per adapter object
4468 * @smid: system request message index
4469 * @msix_index: MSIX table index supplied by the OS
4470 * @reply: reply message frame(lower 32bit addr)
4472 * Callback handler when using _scsih_qcmd.
4474 * Return 1 meaning mf should be freed from _base_interrupt
4475 * 0 means the mf is freed from this function.
4478 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4480 Mpi2SCSIIORequest_t *mpi_request;
4481 Mpi2SCSIIOReply_t *mpi_reply;
4482 struct scsi_cmnd *scmd;
4488 struct MPT3SAS_DEVICE *sas_device_priv_data;
4489 u32 response_code = 0;
4490 unsigned long flags;
4491 unsigned int sector_sz;
4493 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4494 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4498 _scsih_set_satl_pending(scmd, false);
4500 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4502 if (mpi_reply == NULL) {
4503 scmd->result = DID_OK << 16;
4507 sas_device_priv_data = scmd->device->hostdata;
4508 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4509 sas_device_priv_data->sas_target->deleted) {
4510 scmd->result = DID_NO_CONNECT << 16;
4513 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4516 * WARPDRIVE: If direct_io is set then it is directIO,
4517 * the failed direct I/O should be redirected to volume
4519 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4520 ((ioc_status & MPI2_IOCSTATUS_MASK)
4521 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4522 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4523 ioc->scsi_lookup[smid - 1].scmd = scmd;
4524 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4525 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4526 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4527 mpi_request->DevHandle =
4528 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4529 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4530 sas_device_priv_data->sas_target->handle);
4533 /* turning off TLR */
4534 scsi_state = mpi_reply->SCSIState;
4535 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4537 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4538 if (!sas_device_priv_data->tlr_snoop_check) {
4539 sas_device_priv_data->tlr_snoop_check++;
4540 if (!ioc->is_warpdrive &&
4541 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4542 sas_is_tlr_enabled(scmd->device) &&
4543 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4544 sas_disable_tlr(scmd->device);
4545 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4549 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4551 /* In case of bogus fw or device, we could end up having
4552 * unaligned partial completion. We can force alignment here,
4553 * then scsi-ml does not need to handle this misbehavior.
4555 sector_sz = scmd->device->sector_size;
4556 if (unlikely(scmd->request->cmd_type == REQ_TYPE_FS && sector_sz &&
4557 xfer_cnt % sector_sz)) {
4558 sdev_printk(KERN_INFO, scmd->device,
4559 "unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4560 xfer_cnt, sector_sz);
4561 xfer_cnt = round_down(xfer_cnt, sector_sz);
4564 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4565 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4566 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4569 ioc_status &= MPI2_IOCSTATUS_MASK;
4570 scsi_status = mpi_reply->SCSIStatus;
4572 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4573 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4574 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4575 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4576 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4579 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4580 struct sense_info data;
4581 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4583 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4584 le32_to_cpu(mpi_reply->SenseCount));
4585 memcpy(scmd->sense_buffer, sense_data, sz);
4586 _scsih_normalize_sense(scmd->sense_buffer, &data);
4587 /* failure prediction threshold exceeded */
4588 if (data.asc == 0x5D)
4589 _scsih_smart_predicted_fault(ioc,
4590 le16_to_cpu(mpi_reply->DevHandle));
4591 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4593 if ((ioc->logging_level & MPT_DEBUG_REPLY) &&
4594 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4595 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4596 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4597 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4599 switch (ioc_status) {
4600 case MPI2_IOCSTATUS_BUSY:
4601 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4602 scmd->result = SAM_STAT_BUSY;
4605 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4606 scmd->result = DID_NO_CONNECT << 16;
4609 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4610 if (sas_device_priv_data->block) {
4611 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4614 if (log_info == 0x31110630) {
4615 if (scmd->retries > 2) {
4616 scmd->result = DID_NO_CONNECT << 16;
4617 scsi_device_set_state(scmd->device,
4620 scmd->result = DID_SOFT_ERROR << 16;
4621 scmd->device->expecting_cc_ua = 1;
4624 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4625 scmd->result = DID_RESET << 16;
4627 } else if ((scmd->device->channel == RAID_CHANNEL) &&
4628 (scsi_state == (MPI2_SCSI_STATE_TERMINATED |
4629 MPI2_SCSI_STATE_NO_SCSI_STATUS))) {
4630 scmd->result = DID_RESET << 16;
4633 scmd->result = DID_SOFT_ERROR << 16;
4635 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4636 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4637 scmd->result = DID_RESET << 16;
4640 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4641 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4642 scmd->result = DID_SOFT_ERROR << 16;
4644 scmd->result = (DID_OK << 16) | scsi_status;
4647 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4648 scmd->result = (DID_OK << 16) | scsi_status;
4650 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4653 if (xfer_cnt < scmd->underflow) {
4654 if (scsi_status == SAM_STAT_BUSY)
4655 scmd->result = SAM_STAT_BUSY;
4657 scmd->result = DID_SOFT_ERROR << 16;
4658 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4659 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4660 scmd->result = DID_SOFT_ERROR << 16;
4661 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4662 scmd->result = DID_RESET << 16;
4663 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4664 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4665 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4666 scmd->result = (DRIVER_SENSE << 24) |
4667 SAM_STAT_CHECK_CONDITION;
4668 scmd->sense_buffer[0] = 0x70;
4669 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4670 scmd->sense_buffer[12] = 0x20;
4671 scmd->sense_buffer[13] = 0;
4675 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4676 scsi_set_resid(scmd, 0);
4677 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4678 case MPI2_IOCSTATUS_SUCCESS:
4679 scmd->result = (DID_OK << 16) | scsi_status;
4680 if (response_code ==
4681 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4682 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4683 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4684 scmd->result = DID_SOFT_ERROR << 16;
4685 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4686 scmd->result = DID_RESET << 16;
4689 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4690 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4691 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4692 _scsih_eedp_error_handling(scmd, ioc_status);
4695 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4696 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4697 case MPI2_IOCSTATUS_INVALID_SGL:
4698 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4699 case MPI2_IOCSTATUS_INVALID_FIELD:
4700 case MPI2_IOCSTATUS_INVALID_STATE:
4701 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4702 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4704 scmd->result = DID_SOFT_ERROR << 16;
4709 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4710 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4714 scsi_dma_unmap(scmd);
4716 scmd->scsi_done(scmd);
4721 * _scsih_sas_host_refresh - refreshing sas host object contents
4722 * @ioc: per adapter object
4725 * During port enable, fw will send topology events for every device. Its
4726 * possible that the handles may change from the previous setting, so this
4727 * code keeping handles updating if changed.
4732 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4737 Mpi2ConfigReply_t mpi_reply;
4738 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4739 u16 attached_handle;
4742 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4743 "updating handles for sas_host(0x%016llx)\n",
4744 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4746 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4747 * sizeof(Mpi2SasIOUnit0PhyData_t));
4748 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4749 if (!sas_iounit_pg0) {
4750 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4755 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4756 sas_iounit_pg0, sz)) != 0)
4758 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4759 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4761 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4762 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4764 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4765 PhyData[0].ControllerDevHandle);
4766 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4767 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4769 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4770 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4771 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4772 attached_handle, i, link_rate);
4775 kfree(sas_iounit_pg0);
4779 * _scsih_sas_host_add - create sas host object
4780 * @ioc: per adapter object
4782 * Creating host side data object, stored in ioc->sas_hba
4787 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4790 Mpi2ConfigReply_t mpi_reply;
4791 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4792 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4793 Mpi2SasPhyPage0_t phy_pg0;
4794 Mpi2SasDevicePage0_t sas_device_pg0;
4795 Mpi2SasEnclosurePage0_t enclosure_pg0;
4798 u8 device_missing_delay;
4800 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4801 if (!ioc->sas_hba.num_phys) {
4802 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4803 ioc->name, __FILE__, __LINE__, __func__);
4807 /* sas_iounit page 0 */
4808 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4809 sizeof(Mpi2SasIOUnit0PhyData_t));
4810 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4811 if (!sas_iounit_pg0) {
4812 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4813 ioc->name, __FILE__, __LINE__, __func__);
4816 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4817 sas_iounit_pg0, sz))) {
4818 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4819 ioc->name, __FILE__, __LINE__, __func__);
4822 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4823 MPI2_IOCSTATUS_MASK;
4824 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4825 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4826 ioc->name, __FILE__, __LINE__, __func__);
4830 /* sas_iounit page 1 */
4831 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4832 sizeof(Mpi2SasIOUnit1PhyData_t));
4833 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4834 if (!sas_iounit_pg1) {
4835 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4836 ioc->name, __FILE__, __LINE__, __func__);
4839 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4840 sas_iounit_pg1, sz))) {
4841 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4842 ioc->name, __FILE__, __LINE__, __func__);
4845 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4846 MPI2_IOCSTATUS_MASK;
4847 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4848 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4849 ioc->name, __FILE__, __LINE__, __func__);
4853 ioc->io_missing_delay =
4854 sas_iounit_pg1->IODeviceMissingDelay;
4855 device_missing_delay =
4856 sas_iounit_pg1->ReportDeviceMissingDelay;
4857 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4858 ioc->device_missing_delay = (device_missing_delay &
4859 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4861 ioc->device_missing_delay = device_missing_delay &
4862 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4864 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4865 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4866 sizeof(struct _sas_phy), GFP_KERNEL);
4867 if (!ioc->sas_hba.phy) {
4868 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4869 ioc->name, __FILE__, __LINE__, __func__);
4872 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4873 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4875 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4876 ioc->name, __FILE__, __LINE__, __func__);
4879 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4880 MPI2_IOCSTATUS_MASK;
4881 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4882 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4883 ioc->name, __FILE__, __LINE__, __func__);
4888 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4889 PhyData[0].ControllerDevHandle);
4890 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4891 ioc->sas_hba.phy[i].phy_id = i;
4892 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4893 phy_pg0, ioc->sas_hba.parent_dev);
4895 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4896 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4897 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4898 ioc->name, __FILE__, __LINE__, __func__);
4901 ioc->sas_hba.enclosure_handle =
4902 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4903 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4905 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
4906 ioc->name, ioc->sas_hba.handle,
4907 (unsigned long long) ioc->sas_hba.sas_address,
4908 ioc->sas_hba.num_phys) ;
4910 if (ioc->sas_hba.enclosure_handle) {
4911 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4912 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4913 ioc->sas_hba.enclosure_handle)))
4914 ioc->sas_hba.enclosure_logical_id =
4915 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4919 kfree(sas_iounit_pg1);
4920 kfree(sas_iounit_pg0);
4924 * _scsih_expander_add - creating expander object
4925 * @ioc: per adapter object
4926 * @handle: expander handle
4928 * Creating expander object, stored in ioc->sas_expander_list.
4930 * Return 0 for success, else error.
4933 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4935 struct _sas_node *sas_expander;
4936 Mpi2ConfigReply_t mpi_reply;
4937 Mpi2ExpanderPage0_t expander_pg0;
4938 Mpi2ExpanderPage1_t expander_pg1;
4939 Mpi2SasEnclosurePage0_t enclosure_pg0;
4942 u64 sas_address, sas_address_parent = 0;
4944 unsigned long flags;
4945 struct _sas_port *mpt3sas_port = NULL;
4952 if (ioc->shost_recovery || ioc->pci_error_recovery)
4955 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4956 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4957 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4958 ioc->name, __FILE__, __LINE__, __func__);
4962 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4963 MPI2_IOCSTATUS_MASK;
4964 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4965 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4966 ioc->name, __FILE__, __LINE__, __func__);
4970 /* handle out of order topology events */
4971 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4972 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4974 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4975 ioc->name, __FILE__, __LINE__, __func__);
4978 if (sas_address_parent != ioc->sas_hba.sas_address) {
4979 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4980 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4981 sas_address_parent);
4982 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4983 if (!sas_expander) {
4984 rc = _scsih_expander_add(ioc, parent_handle);
4990 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4991 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4992 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
4994 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4999 sas_expander = kzalloc(sizeof(struct _sas_node),
5001 if (!sas_expander) {
5002 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5003 ioc->name, __FILE__, __LINE__, __func__);
5007 sas_expander->handle = handle;
5008 sas_expander->num_phys = expander_pg0.NumPhys;
5009 sas_expander->sas_address_parent = sas_address_parent;
5010 sas_expander->sas_address = sas_address;
5012 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5013 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5014 handle, parent_handle, (unsigned long long)
5015 sas_expander->sas_address, sas_expander->num_phys);
5017 if (!sas_expander->num_phys) {
5021 sas_expander->phy = kcalloc(sas_expander->num_phys,
5022 sizeof(struct _sas_phy), GFP_KERNEL);
5023 if (!sas_expander->phy) {
5024 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5025 ioc->name, __FILE__, __LINE__, __func__);
5030 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5031 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5032 sas_address_parent);
5033 if (!mpt3sas_port) {
5034 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5035 ioc->name, __FILE__, __LINE__, __func__);
5039 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5041 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5042 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5043 &expander_pg1, i, handle))) {
5044 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5045 ioc->name, __FILE__, __LINE__, __func__);
5049 sas_expander->phy[i].handle = handle;
5050 sas_expander->phy[i].phy_id = i;
5052 if ((mpt3sas_transport_add_expander_phy(ioc,
5053 &sas_expander->phy[i], expander_pg1,
5054 sas_expander->parent_dev))) {
5055 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5056 ioc->name, __FILE__, __LINE__, __func__);
5062 if (sas_expander->enclosure_handle) {
5063 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5064 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5065 sas_expander->enclosure_handle)))
5066 sas_expander->enclosure_logical_id =
5067 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5070 _scsih_expander_node_add(ioc, sas_expander);
5076 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5077 sas_address_parent);
5078 kfree(sas_expander);
5083 * mpt3sas_expander_remove - removing expander object
5084 * @ioc: per adapter object
5085 * @sas_address: expander sas_address
5090 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5092 struct _sas_node *sas_expander;
5093 unsigned long flags;
5095 if (ioc->shost_recovery)
5098 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5099 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5102 list_del(&sas_expander->list);
5103 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5105 _scsih_expander_node_remove(ioc, sas_expander);
5109 * _scsih_done - internal SCSI_IO callback handler.
5110 * @ioc: per adapter object
5111 * @smid: system request message index
5112 * @msix_index: MSIX table index supplied by the OS
5113 * @reply: reply message frame(lower 32bit addr)
5115 * Callback handler when sending internal generated SCSI_IO.
5116 * The callback index passed is `ioc->scsih_cb_idx`
5118 * Return 1 meaning mf should be freed from _base_interrupt
5119 * 0 means the mf is freed from this function.
5122 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5124 MPI2DefaultReply_t *mpi_reply;
5126 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5127 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5129 if (ioc->scsih_cmds.smid != smid)
5131 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5133 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5134 mpi_reply->MsgLength*4);
5135 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5137 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5138 complete(&ioc->scsih_cmds.done);
5145 #define MPT3_MAX_LUNS (255)
5149 * _scsih_check_access_status - check access flags
5150 * @ioc: per adapter object
5151 * @sas_address: sas address
5152 * @handle: sas device handle
5153 * @access_flags: errors returned during discovery of the device
5155 * Return 0 for success, else failure
5158 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5159 u16 handle, u8 access_status)
5164 switch (access_status) {
5165 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5166 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5169 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5170 desc = "sata capability failed";
5172 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5173 desc = "sata affiliation conflict";
5175 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5176 desc = "route not addressable";
5178 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5179 desc = "smp error not addressable";
5181 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5182 desc = "device blocked";
5184 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5185 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5186 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5187 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5188 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5189 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5190 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5191 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5192 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5193 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5194 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5195 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5196 desc = "sata initialization failed";
5207 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5208 ioc->name, desc, (unsigned long long)sas_address, handle);
5213 * _scsih_check_device - checking device responsiveness
5214 * @ioc: per adapter object
5215 * @parent_sas_address: sas address of parent expander or sas host
5216 * @handle: attached device handle
5217 * @phy_numberv: phy number
5218 * @link_rate: new link rate
5223 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5224 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5226 Mpi2ConfigReply_t mpi_reply;
5227 Mpi2SasDevicePage0_t sas_device_pg0;
5228 struct _sas_device *sas_device;
5230 unsigned long flags;
5232 struct scsi_target *starget;
5233 struct MPT3SAS_TARGET *sas_target_priv_data;
5237 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5238 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5241 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5242 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5245 /* wide port handling ~ we need only handle device once for the phy that
5246 * is matched in sas device page zero
5248 if (phy_number != sas_device_pg0.PhyNum)
5251 /* check if this is end device */
5252 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5253 if (!(_scsih_is_end_device(device_info)))
5256 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5257 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5258 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5264 if (unlikely(sas_device->handle != handle)) {
5265 starget = sas_device->starget;
5266 sas_target_priv_data = starget->hostdata;
5267 starget_printk(KERN_INFO, starget,
5268 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5269 sas_device->handle, handle);
5270 sas_target_priv_data->handle = handle;
5271 sas_device->handle = handle;
5272 if (sas_device_pg0.Flags &
5273 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5274 sas_device->enclosure_level =
5275 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5276 memcpy(&sas_device->connector_name[0],
5277 &sas_device_pg0.ConnectorName[0], 4);
5279 sas_device->enclosure_level = 0;
5280 sas_device->connector_name[0] = '\0';
5284 /* check if device is present */
5285 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5286 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5288 "device is not present handle(0x%04x), flags!!!\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 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5299 _scsih_ublock_io_device(ioc, sas_address);
5302 sas_device_put(sas_device);
5306 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5308 sas_device_put(sas_device);
5312 * _scsih_add_device - creating sas device object
5313 * @ioc: per adapter object
5314 * @handle: sas device handle
5315 * @phy_num: phy number end device attached to
5316 * @is_pd: is this hidden raid component
5318 * Creating end device object, stored in ioc->sas_device_list.
5320 * Returns 0 for success, non-zero for failure.
5323 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5326 Mpi2ConfigReply_t mpi_reply;
5327 Mpi2SasDevicePage0_t sas_device_pg0;
5328 Mpi2SasEnclosurePage0_t enclosure_pg0;
5329 struct _sas_device *sas_device;
5334 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5335 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5336 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5337 ioc->name, __FILE__, __LINE__, __func__);
5341 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5342 MPI2_IOCSTATUS_MASK;
5343 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5344 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5345 ioc->name, __FILE__, __LINE__, __func__);
5349 /* check if this is end device */
5350 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5351 if (!(_scsih_is_end_device(device_info)))
5353 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5355 /* check if device is present */
5356 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5357 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5358 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5363 /* check if there were any issues with discovery */
5364 if (_scsih_check_access_status(ioc, sas_address, handle,
5365 sas_device_pg0.AccessStatus))
5368 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5371 sas_device_put(sas_device);
5375 sas_device = kzalloc(sizeof(struct _sas_device),
5378 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5379 ioc->name, __FILE__, __LINE__, __func__);
5383 kref_init(&sas_device->refcount);
5384 sas_device->handle = handle;
5385 if (_scsih_get_sas_address(ioc,
5386 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5387 &sas_device->sas_address_parent) != 0)
5388 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5389 ioc->name, __FILE__, __LINE__, __func__);
5390 sas_device->enclosure_handle =
5391 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5392 if (sas_device->enclosure_handle != 0)
5394 le16_to_cpu(sas_device_pg0.Slot);
5395 sas_device->device_info = device_info;
5396 sas_device->sas_address = sas_address;
5397 sas_device->phy = sas_device_pg0.PhyNum;
5398 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5399 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5401 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5402 sas_device->enclosure_level =
5403 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5404 memcpy(&sas_device->connector_name[0],
5405 &sas_device_pg0.ConnectorName[0], 4);
5407 sas_device->enclosure_level = 0;
5408 sas_device->connector_name[0] = '\0';
5410 /* get enclosure_logical_id */
5411 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5412 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5413 sas_device->enclosure_handle)))
5414 sas_device->enclosure_logical_id =
5415 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5417 /* get device name */
5418 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5420 if (ioc->wait_for_discovery_to_complete)
5421 _scsih_sas_device_init_add(ioc, sas_device);
5423 _scsih_sas_device_add(ioc, sas_device);
5425 sas_device_put(sas_device);
5430 * _scsih_remove_device - removing sas device object
5431 * @ioc: per adapter object
5432 * @sas_device_delete: the sas_device object
5437 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5438 struct _sas_device *sas_device)
5440 struct MPT3SAS_TARGET *sas_target_priv_data;
5442 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5443 (sas_device->pfa_led_on)) {
5444 _scsih_turn_off_pfa_led(ioc, sas_device);
5445 sas_device->pfa_led_on = 0;
5447 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5448 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5449 ioc->name, __func__,
5450 sas_device->handle, (unsigned long long)
5451 sas_device->sas_address));
5452 if (sas_device->enclosure_handle != 0)
5453 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5454 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5455 ioc->name, __func__,
5456 (unsigned long long)sas_device->enclosure_logical_id,
5458 if (sas_device->connector_name[0] != '\0')
5459 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5460 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5461 ioc->name, __func__,
5462 sas_device->enclosure_level,
5463 sas_device->connector_name));
5465 if (sas_device->starget && sas_device->starget->hostdata) {
5466 sas_target_priv_data = sas_device->starget->hostdata;
5467 sas_target_priv_data->deleted = 1;
5468 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5469 sas_target_priv_data->handle =
5470 MPT3SAS_INVALID_DEVICE_HANDLE;
5473 if (!ioc->hide_drives)
5474 mpt3sas_transport_port_remove(ioc,
5475 sas_device->sas_address,
5476 sas_device->sas_address_parent);
5479 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5480 ioc->name, sas_device->handle,
5481 (unsigned long long) sas_device->sas_address);
5482 if (sas_device->enclosure_handle != 0)
5484 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5486 (unsigned long long)sas_device->enclosure_logical_id,
5488 if (sas_device->connector_name[0] != '\0')
5490 "removing enclosure level(0x%04x), connector name( %s)\n",
5491 ioc->name, sas_device->enclosure_level,
5492 sas_device->connector_name);
5494 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5495 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5496 ioc->name, __func__,
5497 sas_device->handle, (unsigned long long)
5498 sas_device->sas_address));
5499 if (sas_device->enclosure_handle != 0)
5500 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5501 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5502 ioc->name, __func__,
5503 (unsigned long long)sas_device->enclosure_logical_id,
5505 if (sas_device->connector_name[0] != '\0')
5506 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5507 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5508 ioc->name, __func__, sas_device->enclosure_level,
5509 sas_device->connector_name));
5513 * _scsih_sas_topology_change_event_debug - debug for topology event
5514 * @ioc: per adapter object
5515 * @event_data: event data payload
5519 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5520 Mpi2EventDataSasTopologyChangeList_t *event_data)
5526 char *status_str = NULL;
5527 u8 link_rate, prev_link_rate;
5529 switch (event_data->ExpStatus) {
5530 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5533 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5534 status_str = "remove";
5536 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5538 status_str = "responding";
5540 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5541 status_str = "remove delay";
5544 status_str = "unknown status";
5547 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5548 ioc->name, status_str);
5549 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5550 "start_phy(%02d), count(%d)\n",
5551 le16_to_cpu(event_data->ExpanderDevHandle),
5552 le16_to_cpu(event_data->EnclosureHandle),
5553 event_data->StartPhyNum, event_data->NumEntries);
5554 for (i = 0; i < event_data->NumEntries; i++) {
5555 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5558 phy_number = event_data->StartPhyNum + i;
5559 reason_code = event_data->PHY[i].PhyStatus &
5560 MPI2_EVENT_SAS_TOPO_RC_MASK;
5561 switch (reason_code) {
5562 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5563 status_str = "target add";
5565 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5566 status_str = "target remove";
5568 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5569 status_str = "delay target remove";
5571 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5572 status_str = "link rate change";
5574 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5575 status_str = "target responding";
5578 status_str = "unknown";
5581 link_rate = event_data->PHY[i].LinkRate >> 4;
5582 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5583 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5584 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5585 handle, status_str, link_rate, prev_link_rate);
5591 * _scsih_sas_topology_change_event - handle topology changes
5592 * @ioc: per adapter object
5593 * @fw_event: The fw_event_work object
5598 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5599 struct fw_event_work *fw_event)
5602 u16 parent_handle, handle;
5604 u8 phy_number, max_phys;
5605 struct _sas_node *sas_expander;
5607 unsigned long flags;
5608 u8 link_rate, prev_link_rate;
5609 Mpi2EventDataSasTopologyChangeList_t *event_data =
5610 (Mpi2EventDataSasTopologyChangeList_t *)
5611 fw_event->event_data;
5613 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5614 _scsih_sas_topology_change_event_debug(ioc, event_data);
5616 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5619 if (!ioc->sas_hba.num_phys)
5620 _scsih_sas_host_add(ioc);
5622 _scsih_sas_host_refresh(ioc);
5624 if (fw_event->ignore) {
5625 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5626 "ignoring expander event\n", ioc->name));
5630 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5632 /* handle expander add */
5633 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5634 if (_scsih_expander_add(ioc, parent_handle) != 0)
5637 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5638 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5641 sas_address = sas_expander->sas_address;
5642 max_phys = sas_expander->num_phys;
5643 } else if (parent_handle < ioc->sas_hba.num_phys) {
5644 sas_address = ioc->sas_hba.sas_address;
5645 max_phys = ioc->sas_hba.num_phys;
5647 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5650 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5652 /* handle siblings events */
5653 for (i = 0; i < event_data->NumEntries; i++) {
5654 if (fw_event->ignore) {
5655 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5656 "ignoring expander event\n", ioc->name));
5659 if (ioc->remove_host || ioc->pci_error_recovery)
5661 phy_number = event_data->StartPhyNum + i;
5662 if (phy_number >= max_phys)
5664 reason_code = event_data->PHY[i].PhyStatus &
5665 MPI2_EVENT_SAS_TOPO_RC_MASK;
5666 if ((event_data->PHY[i].PhyStatus &
5667 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5668 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5670 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5673 link_rate = event_data->PHY[i].LinkRate >> 4;
5674 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5675 switch (reason_code) {
5676 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5678 if (ioc->shost_recovery)
5681 if (link_rate == prev_link_rate)
5684 mpt3sas_transport_update_links(ioc, sas_address,
5685 handle, phy_number, link_rate);
5687 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5690 _scsih_check_device(ioc, sas_address, handle,
5691 phy_number, link_rate);
5694 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5696 if (ioc->shost_recovery)
5699 mpt3sas_transport_update_links(ioc, sas_address,
5700 handle, phy_number, link_rate);
5702 _scsih_add_device(ioc, handle, phy_number, 0);
5705 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5707 _scsih_device_remove_by_handle(ioc, handle);
5712 /* handle expander removal */
5713 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5715 mpt3sas_expander_remove(ioc, sas_address);
5721 * _scsih_sas_device_status_change_event_debug - debug for device event
5722 * @event_data: event data payload
5728 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5729 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5731 char *reason_str = NULL;
5733 switch (event_data->ReasonCode) {
5734 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5735 reason_str = "smart data";
5737 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5738 reason_str = "unsupported device discovered";
5740 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5741 reason_str = "internal device reset";
5743 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5744 reason_str = "internal task abort";
5746 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5747 reason_str = "internal task abort set";
5749 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5750 reason_str = "internal clear task set";
5752 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5753 reason_str = "internal query task";
5755 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5756 reason_str = "sata init failure";
5758 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5759 reason_str = "internal device reset complete";
5761 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5762 reason_str = "internal task abort complete";
5764 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5765 reason_str = "internal async notification";
5767 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5768 reason_str = "expander reduced functionality";
5770 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5771 reason_str = "expander reduced functionality complete";
5774 reason_str = "unknown reason";
5777 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5778 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5779 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5780 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5781 le16_to_cpu(event_data->TaskTag));
5782 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5783 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5784 event_data->ASC, event_data->ASCQ);
5789 * _scsih_sas_device_status_change_event - handle device status change
5790 * @ioc: per adapter object
5791 * @fw_event: The fw_event_work object
5797 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5798 struct fw_event_work *fw_event)
5800 struct MPT3SAS_TARGET *target_priv_data;
5801 struct _sas_device *sas_device;
5803 unsigned long flags;
5804 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5805 (Mpi2EventDataSasDeviceStatusChange_t *)
5806 fw_event->event_data;
5808 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5809 _scsih_sas_device_status_change_event_debug(ioc,
5812 /* In MPI Revision K (0xC), the internal device reset complete was
5813 * implemented, so avoid setting tm_busy flag for older firmware.
5815 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5818 if (event_data->ReasonCode !=
5819 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5820 event_data->ReasonCode !=
5821 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5824 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5825 sas_address = le64_to_cpu(event_data->SASAddress);
5826 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5829 if (!sas_device || !sas_device->starget)
5832 target_priv_data = sas_device->starget->hostdata;
5833 if (!target_priv_data)
5836 if (event_data->ReasonCode ==
5837 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5838 target_priv_data->tm_busy = 1;
5840 target_priv_data->tm_busy = 0;
5844 sas_device_put(sas_device);
5846 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5851 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5853 * @ioc: per adapter object
5854 * @event_data: event data payload
5860 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5861 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5863 char *reason_str = NULL;
5865 switch (event_data->ReasonCode) {
5866 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5867 reason_str = "enclosure add";
5869 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5870 reason_str = "enclosure remove";
5873 reason_str = "unknown reason";
5877 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5878 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5879 " number slots(%d)\n", ioc->name, reason_str,
5880 le16_to_cpu(event_data->EnclosureHandle),
5881 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5882 le16_to_cpu(event_data->StartSlot));
5886 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5887 * @ioc: per adapter object
5888 * @fw_event: The fw_event_work object
5894 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5895 struct fw_event_work *fw_event)
5897 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5898 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5899 (Mpi2EventDataSasEnclDevStatusChange_t *)
5900 fw_event->event_data);
5904 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5905 * @ioc: per adapter object
5906 * @fw_event: The fw_event_work object
5912 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
5913 struct fw_event_work *fw_event)
5915 struct scsi_cmnd *scmd;
5916 struct scsi_device *sdev;
5919 struct MPT3SAS_DEVICE *sas_device_priv_data;
5920 u32 termination_count;
5922 Mpi2SCSITaskManagementReply_t *mpi_reply;
5923 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5924 (Mpi2EventDataSasBroadcastPrimitive_t *)
5925 fw_event->event_data;
5927 unsigned long flags;
5930 u8 task_abort_retries;
5932 mutex_lock(&ioc->tm_cmds.mutex);
5934 "%s: enter: phy number(%d), width(%d)\n",
5935 ioc->name, __func__, event_data->PhyNum,
5936 event_data->PortWidth);
5938 _scsih_block_io_all_device(ioc);
5940 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5941 mpi_reply = ioc->tm_cmds.reply;
5942 broadcast_aen_retry:
5944 /* sanity checks for retrying this loop */
5945 if (max_retries++ == 5) {
5946 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
5947 ioc->name, __func__));
5949 } else if (max_retries > 1)
5950 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
5951 ioc->name, __func__, max_retries - 1));
5953 termination_count = 0;
5955 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5956 if (ioc->shost_recovery)
5958 scmd = _scsih_scsi_lookup_get(ioc, smid);
5961 sdev = scmd->device;
5962 sas_device_priv_data = sdev->hostdata;
5963 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5965 /* skip hidden raid components */
5966 if (sas_device_priv_data->sas_target->flags &
5967 MPT_TARGET_FLAGS_RAID_COMPONENT)
5970 if (sas_device_priv_data->sas_target->flags &
5971 MPT_TARGET_FLAGS_VOLUME)
5974 handle = sas_device_priv_data->sas_target->handle;
5975 lun = sas_device_priv_data->lun;
5978 if (ioc->shost_recovery)
5981 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5982 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5983 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5986 sdev_printk(KERN_WARNING, sdev,
5987 "mpt3sas_scsih_issue_tm: FAILED when sending "
5988 "QUERY_TASK: scmd(%p)\n", scmd);
5989 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5990 goto broadcast_aen_retry;
5992 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5993 & MPI2_IOCSTATUS_MASK;
5994 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5995 sdev_printk(KERN_WARNING, sdev,
5996 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
5998 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5999 goto broadcast_aen_retry;
6002 /* see if IO is still owned by IOC and target */
6003 if (mpi_reply->ResponseCode ==
6004 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6005 mpi_reply->ResponseCode ==
6006 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6007 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6010 task_abort_retries = 0;
6012 if (task_abort_retries++ == 60) {
6013 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6014 "%s: ABORT_TASK: giving up\n", ioc->name,
6016 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6017 goto broadcast_aen_retry;
6020 if (ioc->shost_recovery)
6023 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6024 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
6027 sdev_printk(KERN_WARNING, sdev,
6028 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6029 "scmd(%p)\n", scmd);
6033 if (task_abort_retries > 1)
6034 sdev_printk(KERN_WARNING, sdev,
6035 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6037 task_abort_retries - 1, scmd);
6039 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6040 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6043 if (ioc->broadcast_aen_pending) {
6044 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6045 "%s: loop back due to pending AEN\n",
6046 ioc->name, __func__));
6047 ioc->broadcast_aen_pending = 0;
6048 goto broadcast_aen_retry;
6052 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6055 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6056 "%s - exit, query_count = %d termination_count = %d\n",
6057 ioc->name, __func__, query_count, termination_count));
6059 ioc->broadcast_aen_busy = 0;
6060 if (!ioc->shost_recovery)
6061 _scsih_ublock_io_all_device(ioc);
6062 mutex_unlock(&ioc->tm_cmds.mutex);
6066 * _scsih_sas_discovery_event - handle discovery events
6067 * @ioc: per adapter object
6068 * @fw_event: The fw_event_work object
6074 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
6075 struct fw_event_work *fw_event)
6077 Mpi2EventDataSasDiscovery_t *event_data =
6078 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
6080 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6081 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
6082 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6084 if (event_data->DiscoveryStatus)
6085 pr_info("discovery_status(0x%08x)",
6086 le32_to_cpu(event_data->DiscoveryStatus));
6090 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6091 !ioc->sas_hba.num_phys) {
6092 if (disable_discovery > 0 && ioc->shost_recovery) {
6093 /* Wait for the reset to complete */
6094 while (ioc->shost_recovery)
6097 _scsih_sas_host_add(ioc);
6102 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6103 * @ioc: per adapter object
6104 * @handle: device handle for physical disk
6105 * @phys_disk_num: physical disk number
6107 * Return 0 for success, else failure.
6110 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6112 Mpi2RaidActionRequest_t *mpi_request;
6113 Mpi2RaidActionReply_t *mpi_reply;
6120 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6123 mutex_lock(&ioc->scsih_cmds.mutex);
6125 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6126 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6127 ioc->name, __func__);
6131 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6133 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6135 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6136 ioc->name, __func__);
6137 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6142 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6143 ioc->scsih_cmds.smid = smid;
6144 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6146 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6147 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6148 mpi_request->PhysDiskNum = phys_disk_num;
6150 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6151 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6152 handle, phys_disk_num));
6154 init_completion(&ioc->scsih_cmds.done);
6155 mpt3sas_base_put_smid_default(ioc, smid);
6156 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6158 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6159 pr_err(MPT3SAS_FMT "%s: timeout\n",
6160 ioc->name, __func__);
6161 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6167 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6169 mpi_reply = ioc->scsih_cmds.reply;
6170 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6171 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6172 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6175 ioc_status &= MPI2_IOCSTATUS_MASK;
6176 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6177 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6178 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6179 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6183 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6184 "IR RAID_ACTION: completed successfully\n",
6189 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6190 mutex_unlock(&ioc->scsih_cmds.mutex);
6193 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
6199 * _scsih_reprobe_lun - reprobing lun
6200 * @sdev: scsi device struct
6201 * @no_uld_attach: sdev->no_uld_attach flag setting
6205 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6208 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6209 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6210 sdev->no_uld_attach ? "hidding" : "exposing");
6211 rc = scsi_device_reprobe(sdev);
6215 * _scsih_sas_volume_add - add new volume
6216 * @ioc: per adapter object
6217 * @element: IR config element data
6223 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6224 Mpi2EventIrConfigElement_t *element)
6226 struct _raid_device *raid_device;
6227 unsigned long flags;
6229 u16 handle = le16_to_cpu(element->VolDevHandle);
6232 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6235 "failure at %s:%d/%s()!\n", ioc->name,
6236 __FILE__, __LINE__, __func__);
6240 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6241 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6242 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6247 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6250 "failure at %s:%d/%s()!\n", ioc->name,
6251 __FILE__, __LINE__, __func__);
6255 raid_device->id = ioc->sas_id++;
6256 raid_device->channel = RAID_CHANNEL;
6257 raid_device->handle = handle;
6258 raid_device->wwid = wwid;
6259 _scsih_raid_device_add(ioc, raid_device);
6260 if (!ioc->wait_for_discovery_to_complete) {
6261 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6262 raid_device->id, 0);
6264 _scsih_raid_device_remove(ioc, raid_device);
6266 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6267 _scsih_determine_boot_device(ioc, raid_device, 1);
6268 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6273 * _scsih_sas_volume_delete - delete volume
6274 * @ioc: per adapter object
6275 * @handle: volume device handle
6281 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6283 struct _raid_device *raid_device;
6284 unsigned long flags;
6285 struct MPT3SAS_TARGET *sas_target_priv_data;
6286 struct scsi_target *starget = NULL;
6288 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6289 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6291 if (raid_device->starget) {
6292 starget = raid_device->starget;
6293 sas_target_priv_data = starget->hostdata;
6294 sas_target_priv_data->deleted = 1;
6296 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6297 ioc->name, raid_device->handle,
6298 (unsigned long long) raid_device->wwid);
6299 list_del(&raid_device->list);
6302 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6304 scsi_remove_target(&starget->dev);
6308 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6309 * @ioc: per adapter object
6310 * @element: IR config element data
6316 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6317 Mpi2EventIrConfigElement_t *element)
6319 struct _sas_device *sas_device;
6320 struct scsi_target *starget = NULL;
6321 struct MPT3SAS_TARGET *sas_target_priv_data;
6322 unsigned long flags;
6323 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6325 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6326 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6328 sas_device->volume_handle = 0;
6329 sas_device->volume_wwid = 0;
6330 clear_bit(handle, ioc->pd_handles);
6331 if (sas_device->starget && sas_device->starget->hostdata) {
6332 starget = sas_device->starget;
6333 sas_target_priv_data = starget->hostdata;
6334 sas_target_priv_data->flags &=
6335 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6338 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6342 /* exposing raid component */
6344 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6346 sas_device_put(sas_device);
6350 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6351 * @ioc: per adapter object
6352 * @element: IR config element data
6358 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6359 Mpi2EventIrConfigElement_t *element)
6361 struct _sas_device *sas_device;
6362 struct scsi_target *starget = NULL;
6363 struct MPT3SAS_TARGET *sas_target_priv_data;
6364 unsigned long flags;
6365 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6366 u16 volume_handle = 0;
6367 u64 volume_wwid = 0;
6369 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6371 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6374 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6375 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6377 set_bit(handle, ioc->pd_handles);
6378 if (sas_device->starget && sas_device->starget->hostdata) {
6379 starget = sas_device->starget;
6380 sas_target_priv_data = starget->hostdata;
6381 sas_target_priv_data->flags |=
6382 MPT_TARGET_FLAGS_RAID_COMPONENT;
6383 sas_device->volume_handle = volume_handle;
6384 sas_device->volume_wwid = volume_wwid;
6387 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6391 /* hiding raid component */
6392 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6395 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6397 sas_device_put(sas_device);
6401 * _scsih_sas_pd_delete - delete pd component
6402 * @ioc: per adapter object
6403 * @element: IR config element data
6409 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6410 Mpi2EventIrConfigElement_t *element)
6412 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6414 _scsih_device_remove_by_handle(ioc, handle);
6418 * _scsih_sas_pd_add - remove pd component
6419 * @ioc: per adapter object
6420 * @element: IR config element data
6426 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6427 Mpi2EventIrConfigElement_t *element)
6429 struct _sas_device *sas_device;
6430 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6431 Mpi2ConfigReply_t mpi_reply;
6432 Mpi2SasDevicePage0_t sas_device_pg0;
6437 set_bit(handle, ioc->pd_handles);
6439 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6441 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6442 sas_device_put(sas_device);
6446 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6447 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6448 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6449 ioc->name, __FILE__, __LINE__, __func__);
6453 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6454 MPI2_IOCSTATUS_MASK;
6455 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6456 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6457 ioc->name, __FILE__, __LINE__, __func__);
6461 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6462 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6463 mpt3sas_transport_update_links(ioc, sas_address, handle,
6464 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6466 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6467 _scsih_add_device(ioc, handle, 0, 1);
6471 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6472 * @ioc: per adapter object
6473 * @event_data: event data payload
6479 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6480 Mpi2EventDataIrConfigChangeList_t *event_data)
6482 Mpi2EventIrConfigElement_t *element;
6485 char *reason_str = NULL, *element_str = NULL;
6487 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6489 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6490 ioc->name, (le32_to_cpu(event_data->Flags) &
6491 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6492 "foreign" : "native", event_data->NumElements);
6493 for (i = 0; i < event_data->NumElements; i++, element++) {
6494 switch (element->ReasonCode) {
6495 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6498 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6499 reason_str = "remove";
6501 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6502 reason_str = "no change";
6504 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6505 reason_str = "hide";
6507 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6508 reason_str = "unhide";
6510 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6511 reason_str = "volume_created";
6513 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6514 reason_str = "volume_deleted";
6516 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6517 reason_str = "pd_created";
6519 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6520 reason_str = "pd_deleted";
6523 reason_str = "unknown reason";
6526 element_type = le16_to_cpu(element->ElementFlags) &
6527 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6528 switch (element_type) {
6529 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6530 element_str = "volume";
6532 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6533 element_str = "phys disk";
6535 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6536 element_str = "hot spare";
6539 element_str = "unknown element";
6542 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6543 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6544 reason_str, le16_to_cpu(element->VolDevHandle),
6545 le16_to_cpu(element->PhysDiskDevHandle),
6546 element->PhysDiskNum);
6551 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6552 * @ioc: per adapter object
6553 * @fw_event: The fw_event_work object
6559 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6560 struct fw_event_work *fw_event)
6562 Mpi2EventIrConfigElement_t *element;
6565 Mpi2EventDataIrConfigChangeList_t *event_data =
6566 (Mpi2EventDataIrConfigChangeList_t *)
6567 fw_event->event_data;
6569 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6570 (!ioc->hide_ir_msg))
6571 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6573 foreign_config = (le32_to_cpu(event_data->Flags) &
6574 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6576 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6577 if (ioc->shost_recovery &&
6578 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6579 for (i = 0; i < event_data->NumElements; i++, element++) {
6580 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6581 _scsih_ir_fastpath(ioc,
6582 le16_to_cpu(element->PhysDiskDevHandle),
6583 element->PhysDiskNum);
6588 for (i = 0; i < event_data->NumElements; i++, element++) {
6590 switch (element->ReasonCode) {
6591 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6592 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6593 if (!foreign_config)
6594 _scsih_sas_volume_add(ioc, element);
6596 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6597 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6598 if (!foreign_config)
6599 _scsih_sas_volume_delete(ioc,
6600 le16_to_cpu(element->VolDevHandle));
6602 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6603 if (!ioc->is_warpdrive)
6604 _scsih_sas_pd_hide(ioc, element);
6606 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6607 if (!ioc->is_warpdrive)
6608 _scsih_sas_pd_expose(ioc, element);
6610 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6611 if (!ioc->is_warpdrive)
6612 _scsih_sas_pd_add(ioc, element);
6614 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6615 if (!ioc->is_warpdrive)
6616 _scsih_sas_pd_delete(ioc, element);
6623 * _scsih_sas_ir_volume_event - IR volume event
6624 * @ioc: per adapter object
6625 * @fw_event: The fw_event_work object
6631 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6632 struct fw_event_work *fw_event)
6635 unsigned long flags;
6636 struct _raid_device *raid_device;
6640 Mpi2EventDataIrVolume_t *event_data =
6641 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6643 if (ioc->shost_recovery)
6646 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6649 handle = le16_to_cpu(event_data->VolDevHandle);
6650 state = le32_to_cpu(event_data->NewValue);
6651 if (!ioc->hide_ir_msg)
6652 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6653 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6654 ioc->name, __func__, handle,
6655 le32_to_cpu(event_data->PreviousValue), state));
6657 case MPI2_RAID_VOL_STATE_MISSING:
6658 case MPI2_RAID_VOL_STATE_FAILED:
6659 _scsih_sas_volume_delete(ioc, handle);
6662 case MPI2_RAID_VOL_STATE_ONLINE:
6663 case MPI2_RAID_VOL_STATE_DEGRADED:
6664 case MPI2_RAID_VOL_STATE_OPTIMAL:
6666 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6667 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6668 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6673 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6676 "failure at %s:%d/%s()!\n", ioc->name,
6677 __FILE__, __LINE__, __func__);
6681 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6684 "failure at %s:%d/%s()!\n", ioc->name,
6685 __FILE__, __LINE__, __func__);
6689 raid_device->id = ioc->sas_id++;
6690 raid_device->channel = RAID_CHANNEL;
6691 raid_device->handle = handle;
6692 raid_device->wwid = wwid;
6693 _scsih_raid_device_add(ioc, raid_device);
6694 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6695 raid_device->id, 0);
6697 _scsih_raid_device_remove(ioc, raid_device);
6700 case MPI2_RAID_VOL_STATE_INITIALIZING:
6707 * _scsih_sas_ir_physical_disk_event - PD event
6708 * @ioc: per adapter object
6709 * @fw_event: The fw_event_work object
6715 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6716 struct fw_event_work *fw_event)
6718 u16 handle, parent_handle;
6720 struct _sas_device *sas_device;
6721 Mpi2ConfigReply_t mpi_reply;
6722 Mpi2SasDevicePage0_t sas_device_pg0;
6724 Mpi2EventDataIrPhysicalDisk_t *event_data =
6725 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6728 if (ioc->shost_recovery)
6731 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6734 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6735 state = le32_to_cpu(event_data->NewValue);
6737 if (!ioc->hide_ir_msg)
6738 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6739 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6740 ioc->name, __func__, handle,
6741 le32_to_cpu(event_data->PreviousValue), state));
6744 case MPI2_RAID_PD_STATE_ONLINE:
6745 case MPI2_RAID_PD_STATE_DEGRADED:
6746 case MPI2_RAID_PD_STATE_REBUILDING:
6747 case MPI2_RAID_PD_STATE_OPTIMAL:
6748 case MPI2_RAID_PD_STATE_HOT_SPARE:
6750 if (!ioc->is_warpdrive)
6751 set_bit(handle, ioc->pd_handles);
6753 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6755 sas_device_put(sas_device);
6759 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6760 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6762 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6763 ioc->name, __FILE__, __LINE__, __func__);
6767 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6768 MPI2_IOCSTATUS_MASK;
6769 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6770 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6771 ioc->name, __FILE__, __LINE__, __func__);
6775 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6776 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6777 mpt3sas_transport_update_links(ioc, sas_address, handle,
6778 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6780 _scsih_add_device(ioc, handle, 0, 1);
6784 case MPI2_RAID_PD_STATE_OFFLINE:
6785 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6786 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6793 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6794 * @ioc: per adapter object
6795 * @event_data: event data payload
6801 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6802 Mpi2EventDataIrOperationStatus_t *event_data)
6804 char *reason_str = NULL;
6806 switch (event_data->RAIDOperation) {
6807 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6808 reason_str = "resync";
6810 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6811 reason_str = "online capacity expansion";
6813 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6814 reason_str = "consistency check";
6816 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6817 reason_str = "background init";
6819 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6820 reason_str = "make data consistent";
6827 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6828 "\thandle(0x%04x), percent complete(%d)\n",
6829 ioc->name, reason_str,
6830 le16_to_cpu(event_data->VolDevHandle),
6831 event_data->PercentComplete);
6835 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6836 * @ioc: per adapter object
6837 * @fw_event: The fw_event_work object
6843 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6844 struct fw_event_work *fw_event)
6846 Mpi2EventDataIrOperationStatus_t *event_data =
6847 (Mpi2EventDataIrOperationStatus_t *)
6848 fw_event->event_data;
6849 static struct _raid_device *raid_device;
6850 unsigned long flags;
6853 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6854 (!ioc->hide_ir_msg))
6855 _scsih_sas_ir_operation_status_event_debug(ioc,
6858 /* code added for raid transport support */
6859 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6861 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6862 handle = le16_to_cpu(event_data->VolDevHandle);
6863 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6865 raid_device->percent_complete =
6866 event_data->PercentComplete;
6867 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6872 * _scsih_prep_device_scan - initialize parameters prior to device scan
6873 * @ioc: per adapter object
6875 * Set the deleted flag prior to device scan. If the device is found during
6876 * the scan, then we clear the deleted flag.
6879 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6881 struct MPT3SAS_DEVICE *sas_device_priv_data;
6882 struct scsi_device *sdev;
6884 shost_for_each_device(sdev, ioc->shost) {
6885 sas_device_priv_data = sdev->hostdata;
6886 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6887 sas_device_priv_data->sas_target->deleted = 1;
6892 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6893 * @ioc: per adapter object
6894 * @sas_device_pg0: SAS Device page 0
6896 * After host reset, find out whether devices are still responding.
6897 * Used in _scsih_remove_unresponsive_sas_devices.
6902 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6903 Mpi2SasDevicePage0_t *sas_device_pg0)
6905 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
6906 struct scsi_target *starget;
6907 struct _sas_device *sas_device;
6908 unsigned long flags;
6910 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6911 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6912 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
6913 (sas_device->slot == sas_device_pg0->Slot)) {
6914 sas_device->responding = 1;
6915 starget = sas_device->starget;
6916 if (starget && starget->hostdata) {
6917 sas_target_priv_data = starget->hostdata;
6918 sas_target_priv_data->tm_busy = 0;
6919 sas_target_priv_data->deleted = 0;
6921 sas_target_priv_data = NULL;
6923 starget_printk(KERN_INFO, starget,
6924 "handle(0x%04x), sas_addr(0x%016llx)\n",
6925 sas_device_pg0->DevHandle,
6926 (unsigned long long)
6927 sas_device->sas_address);
6929 if (sas_device->enclosure_handle != 0)
6930 starget_printk(KERN_INFO, starget,
6931 "enclosure logical id(0x%016llx),"
6933 (unsigned long long)
6934 sas_device->enclosure_logical_id,
6937 if (sas_device_pg0->Flags &
6938 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
6939 sas_device->enclosure_level =
6940 le16_to_cpu(sas_device_pg0->EnclosureLevel);
6941 memcpy(&sas_device->connector_name[0],
6942 &sas_device_pg0->ConnectorName[0], 4);
6944 sas_device->enclosure_level = 0;
6945 sas_device->connector_name[0] = '\0';
6948 if (sas_device->handle == sas_device_pg0->DevHandle)
6950 pr_info("\thandle changed from(0x%04x)!!!\n",
6951 sas_device->handle);
6952 sas_device->handle = sas_device_pg0->DevHandle;
6953 if (sas_target_priv_data)
6954 sas_target_priv_data->handle =
6955 sas_device_pg0->DevHandle;
6960 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6964 * _scsih_search_responding_sas_devices -
6965 * @ioc: per adapter object
6967 * After host reset, find out whether devices are still responding.
6973 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
6975 Mpi2SasDevicePage0_t sas_device_pg0;
6976 Mpi2ConfigReply_t mpi_reply;
6981 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
6983 if (list_empty(&ioc->sas_device_list))
6987 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6988 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6990 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6991 MPI2_IOCSTATUS_MASK;
6992 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6994 handle = sas_device_pg0.DevHandle =
6995 le16_to_cpu(sas_device_pg0.DevHandle);
6996 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6997 if (!(_scsih_is_end_device(device_info)))
6999 sas_device_pg0.SASAddress =
7000 le64_to_cpu(sas_device_pg0.SASAddress);
7001 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
7002 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
7006 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
7011 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7012 * @ioc: per adapter object
7013 * @wwid: world wide identifier for raid volume
7014 * @handle: device handle
7016 * After host reset, find out whether devices are still responding.
7017 * Used in _scsih_remove_unresponsive_raid_devices.
7022 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
7025 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7026 struct scsi_target *starget;
7027 struct _raid_device *raid_device;
7028 unsigned long flags;
7030 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7031 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
7032 if (raid_device->wwid == wwid && raid_device->starget) {
7033 starget = raid_device->starget;
7034 if (starget && starget->hostdata) {
7035 sas_target_priv_data = starget->hostdata;
7036 sas_target_priv_data->deleted = 0;
7038 sas_target_priv_data = NULL;
7039 raid_device->responding = 1;
7040 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7041 starget_printk(KERN_INFO, raid_device->starget,
7042 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7043 (unsigned long long)raid_device->wwid);
7046 * WARPDRIVE: The handles of the PDs might have changed
7047 * across the host reset so re-initialize the
7048 * required data for Direct IO
7050 mpt3sas_init_warpdrive_properties(ioc, raid_device);
7051 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7052 if (raid_device->handle == handle) {
7053 spin_unlock_irqrestore(&ioc->raid_device_lock,
7057 pr_info("\thandle changed from(0x%04x)!!!\n",
7058 raid_device->handle);
7059 raid_device->handle = handle;
7060 if (sas_target_priv_data)
7061 sas_target_priv_data->handle = handle;
7062 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7066 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7070 * _scsih_search_responding_raid_devices -
7071 * @ioc: per adapter object
7073 * After host reset, find out whether devices are still responding.
7079 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
7081 Mpi2RaidVolPage1_t volume_pg1;
7082 Mpi2RaidVolPage0_t volume_pg0;
7083 Mpi2RaidPhysDiskPage0_t pd_pg0;
7084 Mpi2ConfigReply_t mpi_reply;
7089 if (!ioc->ir_firmware)
7092 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7095 if (list_empty(&ioc->raid_device_list))
7099 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7100 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7101 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7102 MPI2_IOCSTATUS_MASK;
7103 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7105 handle = le16_to_cpu(volume_pg1.DevHandle);
7107 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7108 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7109 sizeof(Mpi2RaidVolPage0_t)))
7112 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7113 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7114 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7115 _scsih_mark_responding_raid_device(ioc,
7116 le64_to_cpu(volume_pg1.WWID), handle);
7119 /* refresh the pd_handles */
7120 if (!ioc->is_warpdrive) {
7121 phys_disk_num = 0xFF;
7122 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7123 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7124 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7126 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7127 MPI2_IOCSTATUS_MASK;
7128 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7130 phys_disk_num = pd_pg0.PhysDiskNum;
7131 handle = le16_to_cpu(pd_pg0.DevHandle);
7132 set_bit(handle, ioc->pd_handles);
7136 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7141 * _scsih_mark_responding_expander - mark a expander as responding
7142 * @ioc: per adapter object
7143 * @sas_address: sas address
7146 * After host reset, find out whether devices are still responding.
7147 * Used in _scsih_remove_unresponsive_expanders.
7152 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7155 struct _sas_node *sas_expander;
7156 unsigned long flags;
7159 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7160 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7161 if (sas_expander->sas_address != sas_address)
7163 sas_expander->responding = 1;
7164 if (sas_expander->handle == handle)
7166 pr_info("\texpander(0x%016llx): handle changed" \
7167 " from(0x%04x) to (0x%04x)!!!\n",
7168 (unsigned long long)sas_expander->sas_address,
7169 sas_expander->handle, handle);
7170 sas_expander->handle = handle;
7171 for (i = 0 ; i < sas_expander->num_phys ; i++)
7172 sas_expander->phy[i].handle = handle;
7176 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7180 * _scsih_search_responding_expanders -
7181 * @ioc: per adapter object
7183 * After host reset, find out whether devices are still responding.
7189 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7191 Mpi2ExpanderPage0_t expander_pg0;
7192 Mpi2ConfigReply_t mpi_reply;
7197 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7199 if (list_empty(&ioc->sas_expander_list))
7203 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7204 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7206 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7207 MPI2_IOCSTATUS_MASK;
7208 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7211 handle = le16_to_cpu(expander_pg0.DevHandle);
7212 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7213 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7215 (unsigned long long)sas_address);
7216 _scsih_mark_responding_expander(ioc, sas_address, handle);
7220 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7224 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7225 * @ioc: per adapter object
7230 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7232 struct _sas_device *sas_device, *sas_device_next;
7233 struct _sas_node *sas_expander, *sas_expander_next;
7234 struct _raid_device *raid_device, *raid_device_next;
7235 struct list_head tmp_list;
7236 unsigned long flags;
7239 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7242 /* removing unresponding end devices */
7243 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7246 * Iterate, pulling off devices marked as non-responding. We become the
7247 * owner for the reference the list had on any object we prune.
7249 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7250 list_for_each_entry_safe(sas_device, sas_device_next,
7251 &ioc->sas_device_list, list) {
7252 if (!sas_device->responding)
7253 list_move_tail(&sas_device->list, &head);
7255 sas_device->responding = 0;
7257 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7260 * Now, uninitialize and remove the unresponding devices we pruned.
7262 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7263 _scsih_remove_device(ioc, sas_device);
7264 list_del_init(&sas_device->list);
7265 sas_device_put(sas_device);
7268 /* removing unresponding volumes */
7269 if (ioc->ir_firmware) {
7270 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7272 list_for_each_entry_safe(raid_device, raid_device_next,
7273 &ioc->raid_device_list, list) {
7274 if (!raid_device->responding)
7275 _scsih_sas_volume_delete(ioc,
7276 raid_device->handle);
7278 raid_device->responding = 0;
7282 /* removing unresponding expanders */
7283 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7285 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7286 INIT_LIST_HEAD(&tmp_list);
7287 list_for_each_entry_safe(sas_expander, sas_expander_next,
7288 &ioc->sas_expander_list, list) {
7289 if (!sas_expander->responding)
7290 list_move_tail(&sas_expander->list, &tmp_list);
7292 sas_expander->responding = 0;
7294 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7295 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7297 list_del(&sas_expander->list);
7298 _scsih_expander_node_remove(ioc, sas_expander);
7301 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7304 /* unblock devices */
7305 _scsih_ublock_io_all_device(ioc);
7309 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7310 struct _sas_node *sas_expander, u16 handle)
7312 Mpi2ExpanderPage1_t expander_pg1;
7313 Mpi2ConfigReply_t mpi_reply;
7316 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7317 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7318 &expander_pg1, i, handle))) {
7319 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7320 ioc->name, __FILE__, __LINE__, __func__);
7324 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7325 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7326 expander_pg1.NegotiatedLinkRate >> 4);
7331 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7332 * @ioc: per adapter object
7337 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7339 Mpi2ExpanderPage0_t expander_pg0;
7340 Mpi2SasDevicePage0_t sas_device_pg0;
7341 Mpi2RaidVolPage1_t volume_pg1;
7342 Mpi2RaidVolPage0_t volume_pg0;
7343 Mpi2RaidPhysDiskPage0_t pd_pg0;
7344 Mpi2EventIrConfigElement_t element;
7345 Mpi2ConfigReply_t mpi_reply;
7348 u16 handle, parent_handle;
7350 struct _sas_device *sas_device;
7351 struct _sas_node *expander_device;
7352 static struct _raid_device *raid_device;
7354 unsigned long flags;
7356 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7358 _scsih_sas_host_refresh(ioc);
7360 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7364 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7365 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7366 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7367 MPI2_IOCSTATUS_MASK;
7368 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7369 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7370 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7371 ioc->name, ioc_status,
7372 le32_to_cpu(mpi_reply.IOCLogInfo));
7375 handle = le16_to_cpu(expander_pg0.DevHandle);
7376 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7377 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7378 ioc, le64_to_cpu(expander_pg0.SASAddress));
7379 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7380 if (expander_device)
7381 _scsih_refresh_expander_links(ioc, expander_device,
7384 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7385 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7386 handle, (unsigned long long)
7387 le64_to_cpu(expander_pg0.SASAddress));
7388 _scsih_expander_add(ioc, handle);
7389 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7390 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7391 handle, (unsigned long long)
7392 le64_to_cpu(expander_pg0.SASAddress));
7396 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7399 if (!ioc->ir_firmware)
7402 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7405 phys_disk_num = 0xFF;
7406 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7407 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7409 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7410 MPI2_IOCSTATUS_MASK;
7411 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7412 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7413 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7414 ioc->name, ioc_status,
7415 le32_to_cpu(mpi_reply.IOCLogInfo));
7418 phys_disk_num = pd_pg0.PhysDiskNum;
7419 handle = le16_to_cpu(pd_pg0.DevHandle);
7420 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7422 sas_device_put(sas_device);
7425 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7426 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7429 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7430 MPI2_IOCSTATUS_MASK;
7431 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7432 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7433 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7434 ioc->name, ioc_status,
7435 le32_to_cpu(mpi_reply.IOCLogInfo));
7438 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7439 if (!_scsih_get_sas_address(ioc, parent_handle,
7441 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7442 " handle (0x%04x), sas_addr(0x%016llx)\n",
7443 ioc->name, handle, (unsigned long long)
7444 le64_to_cpu(sas_device_pg0.SASAddress));
7445 mpt3sas_transport_update_links(ioc, sas_address,
7446 handle, sas_device_pg0.PhyNum,
7447 MPI2_SAS_NEG_LINK_RATE_1_5);
7448 set_bit(handle, ioc->pd_handles);
7450 /* This will retry adding the end device.
7451 * _scsih_add_device() will decide on retries and
7452 * return "1" when it should be retried
7454 while (_scsih_add_device(ioc, handle, retry_count++,
7458 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7459 " handle (0x%04x), sas_addr(0x%016llx)\n",
7460 ioc->name, handle, (unsigned long long)
7461 le64_to_cpu(sas_device_pg0.SASAddress));
7465 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7468 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7472 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7473 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7474 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7475 MPI2_IOCSTATUS_MASK;
7476 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7477 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7478 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7479 ioc->name, ioc_status,
7480 le32_to_cpu(mpi_reply.IOCLogInfo));
7483 handle = le16_to_cpu(volume_pg1.DevHandle);
7484 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7485 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7486 le64_to_cpu(volume_pg1.WWID));
7487 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7490 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7491 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7492 sizeof(Mpi2RaidVolPage0_t)))
7494 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7495 MPI2_IOCSTATUS_MASK;
7496 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7497 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7498 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7499 ioc->name, ioc_status,
7500 le32_to_cpu(mpi_reply.IOCLogInfo));
7503 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7504 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7505 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7506 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7507 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7508 element.VolDevHandle = volume_pg1.DevHandle;
7510 "\tBEFORE adding volume: handle (0x%04x)\n",
7511 ioc->name, volume_pg1.DevHandle);
7512 _scsih_sas_volume_add(ioc, &element);
7514 "\tAFTER adding volume: handle (0x%04x)\n",
7515 ioc->name, volume_pg1.DevHandle);
7519 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7524 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7529 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7530 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7532 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7533 MPI2_IOCSTATUS_MASK;
7534 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7535 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7536 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7537 ioc->name, ioc_status,
7538 le32_to_cpu(mpi_reply.IOCLogInfo));
7541 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7542 if (!(_scsih_is_end_device(
7543 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7545 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7546 le64_to_cpu(sas_device_pg0.SASAddress));
7548 sas_device_put(sas_device);
7551 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7552 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7553 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7554 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7555 handle, (unsigned long long)
7556 le64_to_cpu(sas_device_pg0.SASAddress));
7557 mpt3sas_transport_update_links(ioc, sas_address, handle,
7558 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7560 /* This will retry adding the end device.
7561 * _scsih_add_device() will decide on retries and
7562 * return "1" when it should be retried
7564 while (_scsih_add_device(ioc, handle, retry_count++,
7568 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7569 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7570 handle, (unsigned long long)
7571 le64_to_cpu(sas_device_pg0.SASAddress));
7574 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7577 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7580 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7581 * @ioc: per adapter object
7582 * @reset_phase: phase
7584 * The handler for doing any required cleanup or initialization.
7586 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7587 * MPT3_IOC_DONE_RESET
7592 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7594 switch (reset_phase) {
7595 case MPT3_IOC_PRE_RESET:
7596 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7597 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7599 case MPT3_IOC_AFTER_RESET:
7600 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7601 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7602 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7603 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7604 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7605 complete(&ioc->scsih_cmds.done);
7607 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7608 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7609 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7610 complete(&ioc->tm_cmds.done);
7613 _scsih_fw_event_cleanup_queue(ioc);
7614 _scsih_flush_running_cmds(ioc);
7616 case MPT3_IOC_DONE_RESET:
7617 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7618 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7619 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7620 !ioc->sas_hba.num_phys)) {
7621 _scsih_prep_device_scan(ioc);
7622 _scsih_search_responding_sas_devices(ioc);
7623 _scsih_search_responding_raid_devices(ioc);
7624 _scsih_search_responding_expanders(ioc);
7625 _scsih_error_recovery_delete_devices(ioc);
7632 * _mpt3sas_fw_work - delayed task for processing firmware events
7633 * @ioc: per adapter object
7634 * @fw_event: The fw_event_work object
7640 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7642 _scsih_fw_event_del_from_list(ioc, fw_event);
7644 /* the queue is being flushed so ignore this event */
7645 if (ioc->remove_host || ioc->pci_error_recovery) {
7646 fw_event_work_put(fw_event);
7650 switch (fw_event->event) {
7651 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7652 mpt3sas_process_trigger_data(ioc,
7653 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7654 fw_event->event_data);
7656 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7657 while (scsi_host_in_recovery(ioc->shost) ||
7658 ioc->shost_recovery) {
7660 * If we're unloading, bail. Otherwise, this can become
7663 if (ioc->remove_host)
7667 _scsih_remove_unresponding_sas_devices(ioc);
7668 _scsih_scan_for_devices_after_reset(ioc);
7670 case MPT3SAS_PORT_ENABLE_COMPLETE:
7671 ioc->start_scan = 0;
7672 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7673 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7675 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7676 "port enable: complete from worker thread\n",
7679 case MPT3SAS_TURN_ON_PFA_LED:
7680 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7682 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7683 _scsih_sas_topology_change_event(ioc, fw_event);
7685 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7686 _scsih_sas_device_status_change_event(ioc, fw_event);
7688 case MPI2_EVENT_SAS_DISCOVERY:
7689 _scsih_sas_discovery_event(ioc, fw_event);
7691 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7692 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7694 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7695 _scsih_sas_enclosure_dev_status_change_event(ioc,
7698 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7699 _scsih_sas_ir_config_change_event(ioc, fw_event);
7701 case MPI2_EVENT_IR_VOLUME:
7702 _scsih_sas_ir_volume_event(ioc, fw_event);
7704 case MPI2_EVENT_IR_PHYSICAL_DISK:
7705 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7707 case MPI2_EVENT_IR_OPERATION_STATUS:
7708 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7712 fw_event_work_put(fw_event);
7716 * _firmware_event_work
7717 * @ioc: per adapter object
7718 * @work: The fw_event_work object
7721 * wrappers for the work thread handling firmware events
7727 _firmware_event_work(struct work_struct *work)
7729 struct fw_event_work *fw_event = container_of(work,
7730 struct fw_event_work, work);
7732 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7736 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7737 * @ioc: per adapter object
7738 * @msix_index: MSIX table index supplied by the OS
7739 * @reply: reply message frame(lower 32bit addr)
7740 * Context: interrupt.
7742 * This function merely adds a new work task into ioc->firmware_event_thread.
7743 * The tasks are worked from _firmware_event_work in user context.
7745 * Return 1 meaning mf should be freed from _base_interrupt
7746 * 0 means the mf is freed from this function.
7749 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7752 struct fw_event_work *fw_event;
7753 Mpi2EventNotificationReply_t *mpi_reply;
7757 /* events turned off due to host reset or driver unloading */
7758 if (ioc->remove_host || ioc->pci_error_recovery)
7761 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7763 if (unlikely(!mpi_reply)) {
7764 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7765 ioc->name, __FILE__, __LINE__, __func__);
7769 event = le16_to_cpu(mpi_reply->Event);
7771 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7772 mpt3sas_trigger_event(ioc, event, 0);
7776 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7778 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7779 (Mpi2EventDataSasBroadcastPrimitive_t *)
7780 mpi_reply->EventData;
7782 if (baen_data->Primitive !=
7783 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7786 if (ioc->broadcast_aen_busy) {
7787 ioc->broadcast_aen_pending++;
7790 ioc->broadcast_aen_busy = 1;
7794 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7795 _scsih_check_topo_delete_events(ioc,
7796 (Mpi2EventDataSasTopologyChangeList_t *)
7797 mpi_reply->EventData);
7799 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7800 _scsih_check_ir_config_unhide_events(ioc,
7801 (Mpi2EventDataIrConfigChangeList_t *)
7802 mpi_reply->EventData);
7804 case MPI2_EVENT_IR_VOLUME:
7805 _scsih_check_volume_delete_events(ioc,
7806 (Mpi2EventDataIrVolume_t *)
7807 mpi_reply->EventData);
7809 case MPI2_EVENT_LOG_ENTRY_ADDED:
7811 Mpi2EventDataLogEntryAdded_t *log_entry;
7814 if (!ioc->is_warpdrive)
7817 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7818 mpi_reply->EventData;
7819 log_code = (u32 *)log_entry->LogData;
7821 if (le16_to_cpu(log_entry->LogEntryQualifier)
7822 != MPT2_WARPDRIVE_LOGENTRY)
7825 switch (le32_to_cpu(*log_code)) {
7826 case MPT2_WARPDRIVE_LC_SSDT:
7827 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7828 "IO Throttling has occurred in the WarpDrive "
7829 "subsystem. Check WarpDrive documentation for "
7830 "additional details.\n", ioc->name);
7832 case MPT2_WARPDRIVE_LC_SSDLW:
7833 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7834 "Program/Erase Cycles for the WarpDrive subsystem "
7835 "in degraded range. Check WarpDrive documentation "
7836 "for additional details.\n", ioc->name);
7838 case MPT2_WARPDRIVE_LC_SSDLF:
7839 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7840 "There are no Program/Erase Cycles for the "
7841 "WarpDrive subsystem. The storage device will be "
7842 "in read-only mode. Check WarpDrive documentation "
7843 "for additional details.\n", ioc->name);
7845 case MPT2_WARPDRIVE_LC_BRMF:
7846 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7847 "The Backup Rail Monitor has failed on the "
7848 "WarpDrive subsystem. Check WarpDrive "
7849 "documentation for additional details.\n",
7856 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7857 case MPI2_EVENT_IR_OPERATION_STATUS:
7858 case MPI2_EVENT_SAS_DISCOVERY:
7859 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7860 case MPI2_EVENT_IR_PHYSICAL_DISK:
7863 case MPI2_EVENT_TEMP_THRESHOLD:
7864 _scsih_temp_threshold_events(ioc,
7865 (Mpi2EventDataTemperature_t *)
7866 mpi_reply->EventData);
7869 default: /* ignore the rest */
7873 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7874 fw_event = alloc_fw_event_work(sz);
7876 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7877 ioc->name, __FILE__, __LINE__, __func__);
7881 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7882 fw_event->ioc = ioc;
7883 fw_event->VF_ID = mpi_reply->VF_ID;
7884 fw_event->VP_ID = mpi_reply->VP_ID;
7885 fw_event->event = event;
7886 _scsih_fw_event_add(ioc, fw_event);
7887 fw_event_work_put(fw_event);
7892 * _scsih_expander_node_remove - removing expander device from list.
7893 * @ioc: per adapter object
7894 * @sas_expander: the sas_device object
7895 * Context: Calling function should acquire ioc->sas_node_lock.
7897 * Removing object and freeing associated memory from the
7898 * ioc->sas_expander_list.
7903 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7904 struct _sas_node *sas_expander)
7906 struct _sas_port *mpt3sas_port, *next;
7908 /* remove sibling ports attached to this expander */
7909 list_for_each_entry_safe(mpt3sas_port, next,
7910 &sas_expander->sas_port_list, port_list) {
7911 if (ioc->shost_recovery)
7913 if (mpt3sas_port->remote_identify.device_type ==
7915 mpt3sas_device_remove_by_sas_address(ioc,
7916 mpt3sas_port->remote_identify.sas_address);
7917 else if (mpt3sas_port->remote_identify.device_type ==
7918 SAS_EDGE_EXPANDER_DEVICE ||
7919 mpt3sas_port->remote_identify.device_type ==
7920 SAS_FANOUT_EXPANDER_DEVICE)
7921 mpt3sas_expander_remove(ioc,
7922 mpt3sas_port->remote_identify.sas_address);
7925 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
7926 sas_expander->sas_address_parent);
7929 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
7931 sas_expander->handle, (unsigned long long)
7932 sas_expander->sas_address);
7934 kfree(sas_expander->phy);
7935 kfree(sas_expander);
7939 * _scsih_ir_shutdown - IR shutdown notification
7940 * @ioc: per adapter object
7942 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7943 * the host system is shutting down.
7948 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
7950 Mpi2RaidActionRequest_t *mpi_request;
7951 Mpi2RaidActionReply_t *mpi_reply;
7954 /* is IR firmware build loaded ? */
7955 if (!ioc->ir_firmware)
7958 /* are there any volumes ? */
7959 if (list_empty(&ioc->raid_device_list))
7962 mutex_lock(&ioc->scsih_cmds.mutex);
7964 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
7965 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
7966 ioc->name, __func__);
7969 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
7971 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7973 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
7974 ioc->name, __func__);
7975 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
7979 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
7980 ioc->scsih_cmds.smid = smid;
7981 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7983 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7984 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7986 if (!ioc->hide_ir_msg)
7987 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
7988 init_completion(&ioc->scsih_cmds.done);
7989 mpt3sas_base_put_smid_default(ioc, smid);
7990 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7992 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
7993 pr_err(MPT3SAS_FMT "%s: timeout\n",
7994 ioc->name, __func__);
7998 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
7999 mpi_reply = ioc->scsih_cmds.reply;
8000 if (!ioc->hide_ir_msg)
8001 pr_info(MPT3SAS_FMT "IR shutdown "
8002 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8003 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
8004 le32_to_cpu(mpi_reply->IOCLogInfo));
8008 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8009 mutex_unlock(&ioc->scsih_cmds.mutex);
8013 * scsih_remove - detach and remove add host
8014 * @pdev: PCI device struct
8016 * Routine called when unloading the driver.
8019 void scsih_remove(struct pci_dev *pdev)
8021 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8022 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8023 struct _sas_port *mpt3sas_port, *next_port;
8024 struct _raid_device *raid_device, *next;
8025 struct MPT3SAS_TARGET *sas_target_priv_data;
8026 struct workqueue_struct *wq;
8027 unsigned long flags;
8029 ioc->remove_host = 1;
8030 _scsih_fw_event_cleanup_queue(ioc);
8032 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8033 wq = ioc->firmware_event_thread;
8034 ioc->firmware_event_thread = NULL;
8035 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8037 destroy_workqueue(wq);
8039 /* release all the volumes */
8040 _scsih_ir_shutdown(ioc);
8041 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8043 if (raid_device->starget) {
8044 sas_target_priv_data =
8045 raid_device->starget->hostdata;
8046 sas_target_priv_data->deleted = 1;
8047 scsi_remove_target(&raid_device->starget->dev);
8049 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
8050 ioc->name, raid_device->handle,
8051 (unsigned long long) raid_device->wwid);
8052 _scsih_raid_device_remove(ioc, raid_device);
8055 /* free ports attached to the sas_host */
8056 list_for_each_entry_safe(mpt3sas_port, next_port,
8057 &ioc->sas_hba.sas_port_list, port_list) {
8058 if (mpt3sas_port->remote_identify.device_type ==
8060 mpt3sas_device_remove_by_sas_address(ioc,
8061 mpt3sas_port->remote_identify.sas_address);
8062 else if (mpt3sas_port->remote_identify.device_type ==
8063 SAS_EDGE_EXPANDER_DEVICE ||
8064 mpt3sas_port->remote_identify.device_type ==
8065 SAS_FANOUT_EXPANDER_DEVICE)
8066 mpt3sas_expander_remove(ioc,
8067 mpt3sas_port->remote_identify.sas_address);
8070 /* free phys attached to the sas_host */
8071 if (ioc->sas_hba.num_phys) {
8072 kfree(ioc->sas_hba.phy);
8073 ioc->sas_hba.phy = NULL;
8074 ioc->sas_hba.num_phys = 0;
8077 sas_remove_host(shost);
8078 scsi_remove_host(shost);
8079 mpt3sas_base_detach(ioc);
8080 spin_lock(&gioc_lock);
8081 list_del(&ioc->list);
8082 spin_unlock(&gioc_lock);
8083 scsi_host_put(shost);
8087 * scsih_shutdown - routine call during system shutdown
8088 * @pdev: PCI device struct
8093 scsih_shutdown(struct pci_dev *pdev)
8095 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8096 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8097 struct workqueue_struct *wq;
8098 unsigned long flags;
8100 ioc->remove_host = 1;
8101 _scsih_fw_event_cleanup_queue(ioc);
8103 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8104 wq = ioc->firmware_event_thread;
8105 ioc->firmware_event_thread = NULL;
8106 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8108 destroy_workqueue(wq);
8110 _scsih_ir_shutdown(ioc);
8111 mpt3sas_base_detach(ioc);
8116 * _scsih_probe_boot_devices - reports 1st device
8117 * @ioc: per adapter object
8119 * If specified in bios page 2, this routine reports the 1st
8120 * device scsi-ml or sas transport for persistent boot device
8121 * purposes. Please refer to function _scsih_determine_boot_device()
8124 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8128 struct _sas_device *sas_device;
8129 struct _raid_device *raid_device;
8131 u64 sas_address_parent;
8133 unsigned long flags;
8136 /* no Bios, return immediately */
8137 if (!ioc->bios_pg3.BiosVersion)
8142 if (ioc->req_boot_device.device) {
8143 device = ioc->req_boot_device.device;
8144 is_raid = ioc->req_boot_device.is_raid;
8145 } else if (ioc->req_alt_boot_device.device) {
8146 device = ioc->req_alt_boot_device.device;
8147 is_raid = ioc->req_alt_boot_device.is_raid;
8148 } else if (ioc->current_boot_device.device) {
8149 device = ioc->current_boot_device.device;
8150 is_raid = ioc->current_boot_device.is_raid;
8157 raid_device = device;
8158 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8159 raid_device->id, 0);
8161 _scsih_raid_device_remove(ioc, raid_device);
8163 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8164 sas_device = device;
8165 handle = sas_device->handle;
8166 sas_address_parent = sas_device->sas_address_parent;
8167 sas_address = sas_device->sas_address;
8168 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8169 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8171 if (ioc->hide_drives)
8173 if (!mpt3sas_transport_port_add(ioc, handle,
8174 sas_address_parent)) {
8175 _scsih_sas_device_remove(ioc, sas_device);
8176 } else if (!sas_device->starget) {
8177 if (!ioc->is_driver_loading) {
8178 mpt3sas_transport_port_remove(ioc,
8180 sas_address_parent);
8181 _scsih_sas_device_remove(ioc, sas_device);
8188 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8189 * @ioc: per adapter object
8191 * Called during initial loading of the driver.
8194 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8196 struct _raid_device *raid_device, *raid_next;
8199 list_for_each_entry_safe(raid_device, raid_next,
8200 &ioc->raid_device_list, list) {
8201 if (raid_device->starget)
8203 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8204 raid_device->id, 0);
8206 _scsih_raid_device_remove(ioc, raid_device);
8210 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8212 struct _sas_device *sas_device = NULL;
8213 unsigned long flags;
8215 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8216 if (!list_empty(&ioc->sas_device_init_list)) {
8217 sas_device = list_first_entry(&ioc->sas_device_init_list,
8218 struct _sas_device, list);
8219 sas_device_get(sas_device);
8221 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8226 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8227 struct _sas_device *sas_device)
8229 unsigned long flags;
8231 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8234 * Since we dropped the lock during the call to port_add(), we need to
8235 * be careful here that somebody else didn't move or delete this item
8236 * while we were busy with other things.
8238 * If it was on the list, we need a put() for the reference the list
8239 * had. Either way, we need a get() for the destination list.
8241 if (!list_empty(&sas_device->list)) {
8242 list_del_init(&sas_device->list);
8243 sas_device_put(sas_device);
8246 sas_device_get(sas_device);
8247 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8249 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8253 * _scsih_probe_sas - reporting sas devices to sas transport
8254 * @ioc: per adapter object
8256 * Called during initial loading of the driver.
8259 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8261 struct _sas_device *sas_device;
8263 if (ioc->hide_drives)
8266 while ((sas_device = get_next_sas_device(ioc))) {
8267 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8268 sas_device->sas_address_parent)) {
8269 _scsih_sas_device_remove(ioc, sas_device);
8270 sas_device_put(sas_device);
8272 } else if (!sas_device->starget) {
8274 * When asyn scanning is enabled, its not possible to
8275 * remove devices while scanning is turned on due to an
8276 * oops in scsi_sysfs_add_sdev()->add_device()->
8277 * sysfs_addrm_start()
8279 if (!ioc->is_driver_loading) {
8280 mpt3sas_transport_port_remove(ioc,
8281 sas_device->sas_address,
8282 sas_device->sas_address_parent);
8283 _scsih_sas_device_remove(ioc, sas_device);
8284 sas_device_put(sas_device);
8288 sas_device_make_active(ioc, sas_device);
8289 sas_device_put(sas_device);
8294 * _scsih_probe_devices - probing for devices
8295 * @ioc: per adapter object
8297 * Called during initial loading of the driver.
8300 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8302 u16 volume_mapping_flags;
8304 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8305 return; /* return when IOC doesn't support initiator mode */
8307 _scsih_probe_boot_devices(ioc);
8309 if (ioc->ir_firmware) {
8310 volume_mapping_flags =
8311 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8312 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8313 if (volume_mapping_flags ==
8314 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8315 _scsih_probe_raid(ioc);
8316 _scsih_probe_sas(ioc);
8318 _scsih_probe_sas(ioc);
8319 _scsih_probe_raid(ioc);
8322 _scsih_probe_sas(ioc);
8326 * scsih_scan_start - scsi lld callback for .scan_start
8327 * @shost: SCSI host pointer
8329 * The shost has the ability to discover targets on its own instead
8330 * of scanning the entire bus. In our implemention, we will kick off
8331 * firmware discovery.
8334 scsih_scan_start(struct Scsi_Host *shost)
8336 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8338 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8339 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8341 if (disable_discovery > 0)
8344 ioc->start_scan = 1;
8345 rc = mpt3sas_port_enable(ioc);
8348 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8352 * scsih_scan_finished - scsi lld callback for .scan_finished
8353 * @shost: SCSI host pointer
8354 * @time: elapsed time of the scan in jiffies
8356 * This function will be called periodicallyn until it returns 1 with the
8357 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8358 * we wait for firmware discovery to complete, then return 1.
8361 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8363 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8365 if (disable_discovery > 0) {
8366 ioc->is_driver_loading = 0;
8367 ioc->wait_for_discovery_to_complete = 0;
8371 if (time >= (300 * HZ)) {
8372 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8374 "port enable: FAILED with timeout (timeout=300s)\n",
8376 ioc->is_driver_loading = 0;
8380 if (ioc->start_scan)
8383 if (ioc->start_scan_failed) {
8385 "port enable: FAILED with (ioc_status=0x%08x)\n",
8386 ioc->name, ioc->start_scan_failed);
8387 ioc->is_driver_loading = 0;
8388 ioc->wait_for_discovery_to_complete = 0;
8389 ioc->remove_host = 1;
8393 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8394 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8396 if (ioc->wait_for_discovery_to_complete) {
8397 ioc->wait_for_discovery_to_complete = 0;
8398 _scsih_probe_devices(ioc);
8400 mpt3sas_base_start_watchdog(ioc);
8401 ioc->is_driver_loading = 0;
8405 /* shost template for SAS 2.0 HBA devices */
8406 static struct scsi_host_template mpt2sas_driver_template = {
8407 .module = THIS_MODULE,
8408 .name = "Fusion MPT SAS Host",
8409 .proc_name = MPT2SAS_DRIVER_NAME,
8410 .queuecommand = scsih_qcmd,
8411 .target_alloc = scsih_target_alloc,
8412 .slave_alloc = scsih_slave_alloc,
8413 .slave_configure = scsih_slave_configure,
8414 .target_destroy = scsih_target_destroy,
8415 .slave_destroy = scsih_slave_destroy,
8416 .scan_finished = scsih_scan_finished,
8417 .scan_start = scsih_scan_start,
8418 .change_queue_depth = scsih_change_queue_depth,
8419 .eh_abort_handler = scsih_abort,
8420 .eh_device_reset_handler = scsih_dev_reset,
8421 .eh_target_reset_handler = scsih_target_reset,
8422 .eh_host_reset_handler = scsih_host_reset,
8423 .bios_param = scsih_bios_param,
8426 .sg_tablesize = MPT2SAS_SG_DEPTH,
8427 .max_sectors = 32767,
8429 .use_clustering = ENABLE_CLUSTERING,
8430 .shost_attrs = mpt3sas_host_attrs,
8431 .sdev_attrs = mpt3sas_dev_attrs,
8432 .track_queue_depth = 1,
8435 /* raid transport support for SAS 2.0 HBA devices */
8436 static struct raid_function_template mpt2sas_raid_functions = {
8437 .cookie = &mpt2sas_driver_template,
8438 .is_raid = scsih_is_raid,
8439 .get_resync = scsih_get_resync,
8440 .get_state = scsih_get_state,
8443 /* shost template for SAS 3.0 HBA devices */
8444 static struct scsi_host_template mpt3sas_driver_template = {
8445 .module = THIS_MODULE,
8446 .name = "Fusion MPT SAS Host",
8447 .proc_name = MPT3SAS_DRIVER_NAME,
8448 .queuecommand = scsih_qcmd,
8449 .target_alloc = scsih_target_alloc,
8450 .slave_alloc = scsih_slave_alloc,
8451 .slave_configure = scsih_slave_configure,
8452 .target_destroy = scsih_target_destroy,
8453 .slave_destroy = scsih_slave_destroy,
8454 .scan_finished = scsih_scan_finished,
8455 .scan_start = scsih_scan_start,
8456 .change_queue_depth = scsih_change_queue_depth,
8457 .eh_abort_handler = scsih_abort,
8458 .eh_device_reset_handler = scsih_dev_reset,
8459 .eh_target_reset_handler = scsih_target_reset,
8460 .eh_host_reset_handler = scsih_host_reset,
8461 .bios_param = scsih_bios_param,
8464 .sg_tablesize = MPT3SAS_SG_DEPTH,
8465 .max_sectors = 32767,
8467 .use_clustering = ENABLE_CLUSTERING,
8468 .shost_attrs = mpt3sas_host_attrs,
8469 .sdev_attrs = mpt3sas_dev_attrs,
8470 .track_queue_depth = 1,
8473 /* raid transport support for SAS 3.0 HBA devices */
8474 static struct raid_function_template mpt3sas_raid_functions = {
8475 .cookie = &mpt3sas_driver_template,
8476 .is_raid = scsih_is_raid,
8477 .get_resync = scsih_get_resync,
8478 .get_state = scsih_get_state,
8482 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8483 * this device belongs to.
8484 * @pdev: PCI device struct
8486 * return MPI2_VERSION for SAS 2.0 HBA devices,
8487 * MPI25_VERSION for SAS 3.0 HBA devices.
8490 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8493 switch (pdev->device) {
8494 case MPI2_MFGPAGE_DEVID_SSS6200:
8495 case MPI2_MFGPAGE_DEVID_SAS2004:
8496 case MPI2_MFGPAGE_DEVID_SAS2008:
8497 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8498 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8499 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8500 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8501 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8502 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8503 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8504 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8505 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8506 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8507 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8508 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8509 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8510 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8511 return MPI2_VERSION;
8512 case MPI25_MFGPAGE_DEVID_SAS3004:
8513 case MPI25_MFGPAGE_DEVID_SAS3008:
8514 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8515 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8516 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8517 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8518 return MPI25_VERSION;
8524 * _scsih_probe - attach and add scsi host
8525 * @pdev: PCI device struct
8526 * @id: pci device id
8528 * Returns 0 success, anything else error.
8531 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8533 struct MPT3SAS_ADAPTER *ioc;
8534 struct Scsi_Host *shost = NULL;
8536 u16 hba_mpi_version;
8538 /* Determine in which MPI version class this pci device belongs */
8539 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8540 if (hba_mpi_version == 0)
8543 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8544 * for other generation HBA's return with -ENODEV
8546 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8549 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8550 * for other generation HBA's return with -ENODEV
8552 if ((hbas_to_enumerate == 2) && (hba_mpi_version != MPI25_VERSION))
8555 switch (hba_mpi_version) {
8557 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S |
8558 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
8559 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8560 shost = scsi_host_alloc(&mpt2sas_driver_template,
8561 sizeof(struct MPT3SAS_ADAPTER));
8564 ioc = shost_priv(shost);
8565 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8566 ioc->hba_mpi_version_belonged = hba_mpi_version;
8567 ioc->id = mpt2_ids++;
8568 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8569 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8570 ioc->is_warpdrive = 1;
8571 ioc->hide_ir_msg = 1;
8573 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8576 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8577 shost = scsi_host_alloc(&mpt3sas_driver_template,
8578 sizeof(struct MPT3SAS_ADAPTER));
8581 ioc = shost_priv(shost);
8582 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8583 ioc->hba_mpi_version_belonged = hba_mpi_version;
8584 ioc->id = mpt3_ids++;
8585 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8586 if (pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION)
8587 ioc->msix96_vector = 1;
8593 INIT_LIST_HEAD(&ioc->list);
8594 spin_lock(&gioc_lock);
8595 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8596 spin_unlock(&gioc_lock);
8599 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8600 ioc->tm_cb_idx = tm_cb_idx;
8601 ioc->ctl_cb_idx = ctl_cb_idx;
8602 ioc->base_cb_idx = base_cb_idx;
8603 ioc->port_enable_cb_idx = port_enable_cb_idx;
8604 ioc->transport_cb_idx = transport_cb_idx;
8605 ioc->scsih_cb_idx = scsih_cb_idx;
8606 ioc->config_cb_idx = config_cb_idx;
8607 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8608 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8609 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8610 ioc->logging_level = logging_level;
8611 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8612 /* misc semaphores and spin locks */
8613 mutex_init(&ioc->reset_in_progress_mutex);
8614 /* initializing pci_access_mutex lock */
8615 mutex_init(&ioc->pci_access_mutex);
8616 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8617 spin_lock_init(&ioc->scsi_lookup_lock);
8618 spin_lock_init(&ioc->sas_device_lock);
8619 spin_lock_init(&ioc->sas_node_lock);
8620 spin_lock_init(&ioc->fw_event_lock);
8621 spin_lock_init(&ioc->raid_device_lock);
8622 spin_lock_init(&ioc->diag_trigger_lock);
8624 INIT_LIST_HEAD(&ioc->sas_device_list);
8625 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8626 INIT_LIST_HEAD(&ioc->sas_expander_list);
8627 INIT_LIST_HEAD(&ioc->fw_event_list);
8628 INIT_LIST_HEAD(&ioc->raid_device_list);
8629 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8630 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8631 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8632 INIT_LIST_HEAD(&ioc->reply_queue_list);
8634 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8636 /* init shost parameters */
8637 shost->max_cmd_len = 32;
8638 shost->max_lun = max_lun;
8639 shost->transportt = mpt3sas_transport_template;
8640 shost->unique_id = ioc->id;
8642 if (max_sectors != 0xFFFF) {
8643 if (max_sectors < 64) {
8644 shost->max_sectors = 64;
8645 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8646 "for max_sectors, range is 64 to 32767. Assigning "
8647 "value of 64.\n", ioc->name, max_sectors);
8648 } else if (max_sectors > 32767) {
8649 shost->max_sectors = 32767;
8650 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8651 "for max_sectors, range is 64 to 32767. Assigning "
8652 "default value of 32767.\n", ioc->name,
8655 shost->max_sectors = max_sectors & 0xFFFE;
8657 "The max_sectors value is set to %d\n",
8658 ioc->name, shost->max_sectors);
8662 /* register EEDP capabilities with SCSI layer */
8664 scsi_host_set_prot(shost, prot_mask);
8666 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8667 | SHOST_DIF_TYPE2_PROTECTION
8668 | SHOST_DIF_TYPE3_PROTECTION);
8670 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8673 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8674 "fw_event_%s%d", ioc->driver_name, ioc->id);
8675 ioc->firmware_event_thread = alloc_ordered_workqueue(
8676 ioc->firmware_event_name, 0);
8677 if (!ioc->firmware_event_thread) {
8678 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8679 ioc->name, __FILE__, __LINE__, __func__);
8681 goto out_thread_fail;
8684 ioc->is_driver_loading = 1;
8685 if ((mpt3sas_base_attach(ioc))) {
8686 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8687 ioc->name, __FILE__, __LINE__, __func__);
8689 goto out_attach_fail;
8692 if (ioc->is_warpdrive) {
8693 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8694 ioc->hide_drives = 0;
8695 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8696 ioc->hide_drives = 1;
8698 if (mpt3sas_get_num_volumes(ioc))
8699 ioc->hide_drives = 1;
8701 ioc->hide_drives = 0;
8704 ioc->hide_drives = 0;
8706 rv = scsi_add_host(shost, &pdev->dev);
8708 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8709 ioc->name, __FILE__, __LINE__, __func__);
8710 goto out_add_shost_fail;
8713 scsi_scan_host(shost);
8716 mpt3sas_base_detach(ioc);
8718 destroy_workqueue(ioc->firmware_event_thread);
8720 spin_lock(&gioc_lock);
8721 list_del(&ioc->list);
8722 spin_unlock(&gioc_lock);
8723 scsi_host_put(shost);
8729 * scsih_suspend - power management suspend main entry point
8730 * @pdev: PCI device struct
8731 * @state: PM state change to (usually PCI_D3)
8733 * Returns 0 success, anything else error.
8736 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8738 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8739 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8740 pci_power_t device_state;
8742 mpt3sas_base_stop_watchdog(ioc);
8743 flush_scheduled_work();
8744 scsi_block_requests(shost);
8745 device_state = pci_choose_state(pdev, state);
8747 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8748 ioc->name, pdev, pci_name(pdev), device_state);
8750 pci_save_state(pdev);
8751 mpt3sas_base_free_resources(ioc);
8752 pci_set_power_state(pdev, device_state);
8757 * scsih_resume - power management resume main entry point
8758 * @pdev: PCI device struct
8760 * Returns 0 success, anything else error.
8763 scsih_resume(struct pci_dev *pdev)
8765 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8766 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8767 pci_power_t device_state = pdev->current_state;
8771 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8772 ioc->name, pdev, pci_name(pdev), device_state);
8774 pci_set_power_state(pdev, PCI_D0);
8775 pci_enable_wake(pdev, PCI_D0, 0);
8776 pci_restore_state(pdev);
8778 r = mpt3sas_base_map_resources(ioc);
8782 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8783 scsi_unblock_requests(shost);
8784 mpt3sas_base_start_watchdog(ioc);
8787 #endif /* CONFIG_PM */
8790 * scsih_pci_error_detected - Called when a PCI error is detected.
8791 * @pdev: PCI device struct
8792 * @state: PCI channel state
8794 * Description: Called when a PCI error is detected.
8797 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8800 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8802 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8803 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8805 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8809 case pci_channel_io_normal:
8810 return PCI_ERS_RESULT_CAN_RECOVER;
8811 case pci_channel_io_frozen:
8812 /* Fatal error, prepare for slot reset */
8813 ioc->pci_error_recovery = 1;
8814 scsi_block_requests(ioc->shost);
8815 mpt3sas_base_stop_watchdog(ioc);
8816 mpt3sas_base_free_resources(ioc);
8817 return PCI_ERS_RESULT_NEED_RESET;
8818 case pci_channel_io_perm_failure:
8819 /* Permanent error, prepare for device removal */
8820 ioc->pci_error_recovery = 1;
8821 mpt3sas_base_stop_watchdog(ioc);
8822 _scsih_flush_running_cmds(ioc);
8823 return PCI_ERS_RESULT_DISCONNECT;
8825 return PCI_ERS_RESULT_NEED_RESET;
8829 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8830 * @pdev: PCI device struct
8832 * Description: This routine is called by the pci error recovery
8833 * code after the PCI slot has been reset, just before we
8834 * should resume normal operations.
8837 scsih_pci_slot_reset(struct pci_dev *pdev)
8839 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8840 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8843 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8846 ioc->pci_error_recovery = 0;
8848 pci_restore_state(pdev);
8849 rc = mpt3sas_base_map_resources(ioc);
8851 return PCI_ERS_RESULT_DISCONNECT;
8853 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8856 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8857 (rc == 0) ? "success" : "failed");
8860 return PCI_ERS_RESULT_RECOVERED;
8862 return PCI_ERS_RESULT_DISCONNECT;
8866 * scsih_pci_resume() - resume normal ops after PCI reset
8867 * @pdev: pointer to PCI device
8869 * Called when the error recovery driver tells us that its
8870 * OK to resume normal operation. Use completion to allow
8871 * halted scsi ops to resume.
8874 scsih_pci_resume(struct pci_dev *pdev)
8876 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8877 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8879 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8881 pci_cleanup_aer_uncorrect_error_status(pdev);
8882 mpt3sas_base_start_watchdog(ioc);
8883 scsi_unblock_requests(ioc->shost);
8887 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8888 * @pdev: pointer to PCI device
8891 scsih_pci_mmio_enabled(struct pci_dev *pdev)
8893 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8894 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8896 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
8899 /* TODO - dump whatever for debugging purposes */
8901 /* Request a slot reset. */
8902 return PCI_ERS_RESULT_NEED_RESET;
8906 * The pci device ids are defined in mpi/mpi2_cnfg.h.
8908 static const struct pci_device_id mpt3sas_pci_table[] = {
8909 /* Spitfire ~ 2004 */
8910 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
8911 PCI_ANY_ID, PCI_ANY_ID },
8913 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
8914 PCI_ANY_ID, PCI_ANY_ID },
8915 /* Liberator ~ 2108 */
8916 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
8917 PCI_ANY_ID, PCI_ANY_ID },
8918 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
8919 PCI_ANY_ID, PCI_ANY_ID },
8920 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
8921 PCI_ANY_ID, PCI_ANY_ID },
8923 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
8924 PCI_ANY_ID, PCI_ANY_ID },
8925 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
8926 PCI_ANY_ID, PCI_ANY_ID },
8927 /* Thunderbolt ~ 2208 */
8928 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
8929 PCI_ANY_ID, PCI_ANY_ID },
8930 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
8931 PCI_ANY_ID, PCI_ANY_ID },
8932 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
8933 PCI_ANY_ID, PCI_ANY_ID },
8934 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
8935 PCI_ANY_ID, PCI_ANY_ID },
8936 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
8937 PCI_ANY_ID, PCI_ANY_ID },
8938 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
8939 PCI_ANY_ID, PCI_ANY_ID },
8940 /* Mustang ~ 2308 */
8941 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
8942 PCI_ANY_ID, PCI_ANY_ID },
8943 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
8944 PCI_ANY_ID, PCI_ANY_ID },
8945 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
8946 PCI_ANY_ID, PCI_ANY_ID },
8948 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
8949 PCI_ANY_ID, PCI_ANY_ID },
8950 /* Fury ~ 3004 and 3008 */
8951 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
8952 PCI_ANY_ID, PCI_ANY_ID },
8953 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
8954 PCI_ANY_ID, PCI_ANY_ID },
8955 /* Invader ~ 3108 */
8956 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
8957 PCI_ANY_ID, PCI_ANY_ID },
8958 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
8959 PCI_ANY_ID, PCI_ANY_ID },
8960 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
8961 PCI_ANY_ID, PCI_ANY_ID },
8962 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
8963 PCI_ANY_ID, PCI_ANY_ID },
8964 {0} /* Terminating entry */
8966 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
8968 static struct pci_error_handlers _mpt3sas_err_handler = {
8969 .error_detected = scsih_pci_error_detected,
8970 .mmio_enabled = scsih_pci_mmio_enabled,
8971 .slot_reset = scsih_pci_slot_reset,
8972 .resume = scsih_pci_resume,
8975 static struct pci_driver mpt3sas_driver = {
8976 .name = MPT3SAS_DRIVER_NAME,
8977 .id_table = mpt3sas_pci_table,
8978 .probe = _scsih_probe,
8979 .remove = scsih_remove,
8980 .shutdown = scsih_shutdown,
8981 .err_handler = &_mpt3sas_err_handler,
8983 .suspend = scsih_suspend,
8984 .resume = scsih_resume,
8989 * scsih_init - main entry point for this driver.
8991 * Returns 0 success, anything else error.
8999 mpt3sas_base_initialize_callback_handler();
9001 /* queuecommand callback hander */
9002 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
9004 /* task managment callback handler */
9005 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
9007 /* base internal commands callback handler */
9008 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
9009 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
9010 mpt3sas_port_enable_done);
9012 /* transport internal commands callback handler */
9013 transport_cb_idx = mpt3sas_base_register_callback_handler(
9014 mpt3sas_transport_done);
9016 /* scsih internal commands callback handler */
9017 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
9019 /* configuration page API internal commands callback handler */
9020 config_cb_idx = mpt3sas_base_register_callback_handler(
9021 mpt3sas_config_done);
9023 /* ctl module callback handler */
9024 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
9026 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
9027 _scsih_tm_tr_complete);
9029 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
9030 _scsih_tm_volume_tr_complete);
9032 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
9033 _scsih_sas_control_complete);
9039 * scsih_exit - exit point for this driver (when it is a module).
9041 * Returns 0 success, anything else error.
9047 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
9048 mpt3sas_base_release_callback_handler(tm_cb_idx);
9049 mpt3sas_base_release_callback_handler(base_cb_idx);
9050 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
9051 mpt3sas_base_release_callback_handler(transport_cb_idx);
9052 mpt3sas_base_release_callback_handler(scsih_cb_idx);
9053 mpt3sas_base_release_callback_handler(config_cb_idx);
9054 mpt3sas_base_release_callback_handler(ctl_cb_idx);
9056 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
9057 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
9058 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
9060 /* raid transport support */
9061 if (hbas_to_enumerate != 1)
9062 raid_class_release(mpt3sas_raid_template);
9063 if (hbas_to_enumerate != 2)
9064 raid_class_release(mpt2sas_raid_template);
9065 sas_release_transport(mpt3sas_transport_template);
9069 * _mpt3sas_init - main entry point for this driver.
9071 * Returns 0 success, anything else error.
9078 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
9079 MPT3SAS_DRIVER_VERSION);
9081 mpt3sas_transport_template =
9082 sas_attach_transport(&mpt3sas_transport_functions);
9083 if (!mpt3sas_transport_template)
9086 /* No need attach mpt3sas raid functions template
9087 * if hbas_to_enumarate value is one.
9089 if (hbas_to_enumerate != 1) {
9090 mpt3sas_raid_template =
9091 raid_class_attach(&mpt3sas_raid_functions);
9092 if (!mpt3sas_raid_template) {
9093 sas_release_transport(mpt3sas_transport_template);
9098 /* No need to attach mpt2sas raid functions template
9099 * if hbas_to_enumarate value is two
9101 if (hbas_to_enumerate != 2) {
9102 mpt2sas_raid_template =
9103 raid_class_attach(&mpt2sas_raid_functions);
9104 if (!mpt2sas_raid_template) {
9105 sas_release_transport(mpt3sas_transport_template);
9110 error = scsih_init();
9116 mpt3sas_ctl_init(hbas_to_enumerate);
9118 error = pci_register_driver(&mpt3sas_driver);
9126 * _mpt3sas_exit - exit point for this driver (when it is a module).
9132 pr_info("mpt3sas version %s unloading\n",
9133 MPT3SAS_DRIVER_VERSION);
9135 pci_unregister_driver(&mpt3sas_driver);
9137 mpt3sas_ctl_exit(hbas_to_enumerate);
9142 module_init(_mpt3sas_init);
9143 module_exit(_mpt3sas_exit);