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/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <asm/unaligned.h>
59 #include "mpt3sas_base.h"
61 #define RAID_CHANNEL 1
63 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
64 struct _sas_node *sas_expander);
65 static void _firmware_event_work(struct work_struct *work);
67 static void _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
68 struct _sas_device *sas_device);
69 static int _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle,
70 u8 retry_count, u8 is_pd);
72 static u8 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid);
74 /* global parameters */
75 LIST_HEAD(mpt3sas_ioc_list);
76 /* global ioc lock for list operations */
77 DEFINE_SPINLOCK(gioc_lock);
79 MODULE_AUTHOR(MPT3SAS_AUTHOR);
80 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION);
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(MPT3SAS_DRIVER_VERSION);
83 MODULE_ALIAS("mpt2sas");
85 /* local parameters */
86 static u8 scsi_io_cb_idx = -1;
87 static u8 tm_cb_idx = -1;
88 static u8 ctl_cb_idx = -1;
89 static u8 base_cb_idx = -1;
90 static u8 port_enable_cb_idx = -1;
91 static u8 transport_cb_idx = -1;
92 static u8 scsih_cb_idx = -1;
93 static u8 config_cb_idx = -1;
97 static u8 tm_tr_cb_idx = -1 ;
98 static u8 tm_tr_volume_cb_idx = -1 ;
99 static u8 tm_sas_control_cb_idx = -1;
101 /* command line options */
102 static u32 logging_level;
103 MODULE_PARM_DESC(logging_level,
104 " bits for enabling additional logging info (default=0)");
107 static ushort max_sectors = 0xFFFF;
108 module_param(max_sectors, ushort, 0);
109 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
112 static int missing_delay[2] = {-1, -1};
113 module_param_array(missing_delay, int, NULL, 0);
114 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
116 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
117 #define MPT3SAS_MAX_LUN (16895)
118 static u64 max_lun = MPT3SAS_MAX_LUN;
119 module_param(max_lun, ullong, 0);
120 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
122 static ushort hbas_to_enumerate;
123 module_param(hbas_to_enumerate, ushort, 0);
124 MODULE_PARM_DESC(hbas_to_enumerate,
125 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
126 1 - enumerates only SAS 2.0 generation HBAs\n \
127 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
129 /* diag_buffer_enable is bitwise
131 * bit 1 set = SNAPSHOT
132 * bit 2 set = EXTENDED
134 * Either bit can be set, or both
136 static int diag_buffer_enable = -1;
137 module_param(diag_buffer_enable, int, 0);
138 MODULE_PARM_DESC(diag_buffer_enable,
139 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
140 static int disable_discovery = -1;
141 module_param(disable_discovery, int, 0);
142 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
145 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
146 static int prot_mask = -1;
147 module_param(prot_mask, int, 0);
148 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
151 /* raid transport support */
152 struct raid_template *mpt3sas_raid_template;
153 struct raid_template *mpt2sas_raid_template;
157 * struct sense_info - common structure for obtaining sense keys
159 * @asc: additional sense code
160 * @ascq: additional sense code qualifier
168 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
169 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
170 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
171 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
172 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
174 * struct fw_event_work - firmware event struct
175 * @list: link list framework
176 * @work: work object (ioc->fault_reset_work_q)
177 * @ioc: per adapter object
178 * @device_handle: device handle
179 * @VF_ID: virtual function id
180 * @VP_ID: virtual port id
181 * @ignore: flag meaning this event has been marked to ignore
182 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
183 * @refcount: kref for this event
184 * @event_data: reply event data payload follows
186 * This object stored on ioc->fw_event_list.
188 struct fw_event_work {
189 struct list_head list;
190 struct work_struct work;
192 struct MPT3SAS_ADAPTER *ioc;
198 struct kref refcount;
199 char event_data[0] __aligned(4);
202 static void fw_event_work_free(struct kref *r)
204 kfree(container_of(r, struct fw_event_work, refcount));
207 static void fw_event_work_get(struct fw_event_work *fw_work)
209 kref_get(&fw_work->refcount);
212 static void fw_event_work_put(struct fw_event_work *fw_work)
214 kref_put(&fw_work->refcount, fw_event_work_free);
217 static struct fw_event_work *alloc_fw_event_work(int len)
219 struct fw_event_work *fw_event;
221 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
225 kref_init(&fw_event->refcount);
230 * struct _scsi_io_transfer - scsi io transfer
231 * @handle: sas device handle (assigned by firmware)
232 * @is_raid: flag set for hidden raid components
233 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
234 * @data_length: data transfer length
235 * @data_dma: dma pointer to data
238 * @cdb_length: cdb length
240 * @timeout: timeout for this command
241 * @VF_ID: virtual function id
242 * @VP_ID: virtual port id
243 * @valid_reply: flag set for reply message
244 * @sense_length: sense length
245 * @ioc_status: ioc status
246 * @scsi_state: scsi state
247 * @scsi_status: scsi staus
248 * @log_info: log information
249 * @transfer_length: data length transfer when there is a reply message
251 * Used for sending internal scsi commands to devices within this module.
252 * Refer to _scsi_send_scsi_io().
254 struct _scsi_io_transfer {
257 enum dma_data_direction dir;
260 u8 sense[SCSI_SENSE_BUFFERSIZE];
268 /* the following bits are only valid when 'valid_reply = 1' */
278 * _scsih_set_debug_level - global setting of ioc->logging_level.
280 * Note: The logging levels are defined in mpt3sas_debug.h.
283 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
285 int ret = param_set_int(val, kp);
286 struct MPT3SAS_ADAPTER *ioc;
291 pr_info("setting logging_level(0x%08x)\n", logging_level);
292 spin_lock(&gioc_lock);
293 list_for_each_entry(ioc, &mpt3sas_ioc_list, list)
294 ioc->logging_level = logging_level;
295 spin_unlock(&gioc_lock);
298 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
299 &logging_level, 0644);
302 * _scsih_srch_boot_sas_address - search based on sas_address
303 * @sas_address: sas address
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_srch_boot_sas_address(u64 sas_address,
310 Mpi2BootDeviceSasWwid_t *boot_device)
312 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
316 * _scsih_srch_boot_device_name - search based on device name
317 * @device_name: device name specified in INDENTIFY fram
318 * @boot_device: boot device object from bios page 2
320 * Returns 1 when there's a match, 0 means no match.
323 _scsih_srch_boot_device_name(u64 device_name,
324 Mpi2BootDeviceDeviceName_t *boot_device)
326 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
330 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
331 * @enclosure_logical_id: enclosure logical id
332 * @slot_number: slot number
333 * @boot_device: boot device object from bios page 2
335 * Returns 1 when there's a match, 0 means no match.
338 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
339 Mpi2BootDeviceEnclosureSlot_t *boot_device)
341 return (enclosure_logical_id == le64_to_cpu(boot_device->
342 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
343 SlotNumber)) ? 1 : 0;
347 * _scsih_is_boot_device - search for matching boot device.
348 * @sas_address: sas address
349 * @device_name: device name specified in INDENTIFY fram
350 * @enclosure_logical_id: enclosure logical id
351 * @slot_number: slot number
352 * @form: specifies boot device form
353 * @boot_device: boot device object from bios page 2
355 * Returns 1 when there's a match, 0 means no match.
358 _scsih_is_boot_device(u64 sas_address, u64 device_name,
359 u64 enclosure_logical_id, u16 slot, u8 form,
360 Mpi2BiosPage2BootDevice_t *boot_device)
365 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
368 rc = _scsih_srch_boot_sas_address(
369 sas_address, &boot_device->SasWwid);
371 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
372 if (!enclosure_logical_id)
374 rc = _scsih_srch_boot_encl_slot(
375 enclosure_logical_id,
376 slot, &boot_device->EnclosureSlot);
378 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
381 rc = _scsih_srch_boot_device_name(
382 device_name, &boot_device->DeviceName);
384 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
392 * _scsih_get_sas_address - set the sas_address for given device handle
393 * @handle: device handle
394 * @sas_address: sas address
396 * Returns 0 success, non-zero when failure
399 _scsih_get_sas_address(struct MPT3SAS_ADAPTER *ioc, u16 handle,
402 Mpi2SasDevicePage0_t sas_device_pg0;
403 Mpi2ConfigReply_t mpi_reply;
408 if (handle <= ioc->sas_hba.num_phys) {
409 *sas_address = ioc->sas_hba.sas_address;
413 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
415 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
416 __FILE__, __LINE__, __func__);
420 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
421 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
422 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
430 /* else error case */
432 "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
433 ioc->name, handle, ioc_status,
434 __FILE__, __LINE__, __func__);
439 * _scsih_determine_boot_device - determine boot device.
440 * @ioc: per adapter object
441 * @device: either sas_device or raid_device object
442 * @is_raid: [flag] 1 = raid object, 0 = sas object
444 * Determines whether this device should be first reported device to
445 * to scsi-ml or sas transport, this purpose is for persistent boot device.
446 * There are primary, alternate, and current entries in bios page 2. The order
447 * priority is primary, alternate, then current. This routine saves
448 * the corresponding device object and is_raid flag in the ioc object.
449 * The saved data to be used later in _scsih_probe_boot_devices().
452 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER *ioc,
453 void *device, u8 is_raid)
455 struct _sas_device *sas_device;
456 struct _raid_device *raid_device;
459 u64 enclosure_logical_id;
462 /* only process this function when driver loads */
463 if (!ioc->is_driver_loading)
466 /* no Bios, return immediately */
467 if (!ioc->bios_pg3.BiosVersion)
472 sas_address = sas_device->sas_address;
473 device_name = sas_device->device_name;
474 enclosure_logical_id = sas_device->enclosure_logical_id;
475 slot = sas_device->slot;
477 raid_device = device;
478 sas_address = raid_device->wwid;
480 enclosure_logical_id = 0;
484 if (!ioc->req_boot_device.device) {
485 if (_scsih_is_boot_device(sas_address, device_name,
486 enclosure_logical_id, slot,
487 (ioc->bios_pg2.ReqBootDeviceForm &
488 MPI2_BIOSPAGE2_FORM_MASK),
489 &ioc->bios_pg2.RequestedBootDevice)) {
490 dinitprintk(ioc, pr_info(MPT3SAS_FMT
491 "%s: req_boot_device(0x%016llx)\n",
493 (unsigned long long)sas_address));
494 ioc->req_boot_device.device = device;
495 ioc->req_boot_device.is_raid = is_raid;
499 if (!ioc->req_alt_boot_device.device) {
500 if (_scsih_is_boot_device(sas_address, device_name,
501 enclosure_logical_id, slot,
502 (ioc->bios_pg2.ReqAltBootDeviceForm &
503 MPI2_BIOSPAGE2_FORM_MASK),
504 &ioc->bios_pg2.RequestedAltBootDevice)) {
505 dinitprintk(ioc, pr_info(MPT3SAS_FMT
506 "%s: req_alt_boot_device(0x%016llx)\n",
508 (unsigned long long)sas_address));
509 ioc->req_alt_boot_device.device = device;
510 ioc->req_alt_boot_device.is_raid = is_raid;
514 if (!ioc->current_boot_device.device) {
515 if (_scsih_is_boot_device(sas_address, device_name,
516 enclosure_logical_id, slot,
517 (ioc->bios_pg2.CurrentBootDeviceForm &
518 MPI2_BIOSPAGE2_FORM_MASK),
519 &ioc->bios_pg2.CurrentBootDevice)) {
520 dinitprintk(ioc, pr_info(MPT3SAS_FMT
521 "%s: current_boot_device(0x%016llx)\n",
523 (unsigned long long)sas_address));
524 ioc->current_boot_device.device = device;
525 ioc->current_boot_device.is_raid = is_raid;
530 static struct _sas_device *
531 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
532 struct MPT3SAS_TARGET *tgt_priv)
534 struct _sas_device *ret;
536 assert_spin_locked(&ioc->sas_device_lock);
538 ret = tgt_priv->sdev;
545 static struct _sas_device *
546 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER *ioc,
547 struct MPT3SAS_TARGET *tgt_priv)
549 struct _sas_device *ret;
552 spin_lock_irqsave(&ioc->sas_device_lock, flags);
553 ret = __mpt3sas_get_sdev_from_target(ioc, tgt_priv);
554 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
561 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
564 struct _sas_device *sas_device;
566 assert_spin_locked(&ioc->sas_device_lock);
568 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
569 if (sas_device->sas_address == sas_address)
572 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
573 if (sas_device->sas_address == sas_address)
579 sas_device_get(sas_device);
584 * mpt3sas_get_sdev_by_addr - sas device search
585 * @ioc: per adapter object
586 * @sas_address: sas address
587 * Context: Calling function should acquire ioc->sas_device_lock
589 * This searches for sas_device based on sas_address, then return sas_device
593 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER *ioc,
596 struct _sas_device *sas_device;
599 spin_lock_irqsave(&ioc->sas_device_lock, flags);
600 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
602 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
607 static struct _sas_device *
608 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
610 struct _sas_device *sas_device;
612 assert_spin_locked(&ioc->sas_device_lock);
614 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
615 if (sas_device->handle == handle)
618 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
619 if (sas_device->handle == handle)
625 sas_device_get(sas_device);
630 * mpt3sas_get_sdev_by_handle - sas device search
631 * @ioc: per adapter object
632 * @handle: sas device handle (assigned by firmware)
633 * Context: Calling function should acquire ioc->sas_device_lock
635 * This searches for sas_device based on sas_address, then return sas_device
638 static struct _sas_device *
639 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
641 struct _sas_device *sas_device;
644 spin_lock_irqsave(&ioc->sas_device_lock, flags);
645 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
646 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
652 * _scsih_sas_device_remove - remove sas_device from list.
653 * @ioc: per adapter object
654 * @sas_device: the sas_device object
655 * Context: This function will acquire ioc->sas_device_lock.
657 * If sas_device is on the list, remove it and decrement its reference count.
660 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER *ioc,
661 struct _sas_device *sas_device)
668 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
669 ioc->name, sas_device->handle,
670 (unsigned long long) sas_device->sas_address);
672 if (sas_device->enclosure_handle != 0)
674 "removing enclosure logical id(0x%016llx), slot(%d)\n",
675 ioc->name, (unsigned long long)
676 sas_device->enclosure_logical_id, sas_device->slot);
678 if (sas_device->connector_name[0] != '\0')
680 "removing enclosure level(0x%04x), connector name( %s)\n",
681 ioc->name, sas_device->enclosure_level,
682 sas_device->connector_name);
685 * The lock serializes access to the list, but we still need to verify
686 * that nobody removed the entry while we were waiting on the lock.
688 spin_lock_irqsave(&ioc->sas_device_lock, flags);
689 if (!list_empty(&sas_device->list)) {
690 list_del_init(&sas_device->list);
691 sas_device_put(sas_device);
693 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
697 * _scsih_device_remove_by_handle - removing device object by handle
698 * @ioc: per adapter object
699 * @handle: device handle
704 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
706 struct _sas_device *sas_device;
709 if (ioc->shost_recovery)
712 spin_lock_irqsave(&ioc->sas_device_lock, flags);
713 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
715 list_del_init(&sas_device->list);
716 sas_device_put(sas_device);
718 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
720 _scsih_remove_device(ioc, sas_device);
721 sas_device_put(sas_device);
726 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
727 * @ioc: per adapter object
728 * @sas_address: device sas_address
733 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
736 struct _sas_device *sas_device;
739 if (ioc->shost_recovery)
742 spin_lock_irqsave(&ioc->sas_device_lock, flags);
743 sas_device = __mpt3sas_get_sdev_by_addr(ioc, sas_address);
745 list_del_init(&sas_device->list);
746 sas_device_put(sas_device);
748 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
750 _scsih_remove_device(ioc, sas_device);
751 sas_device_put(sas_device);
756 * _scsih_sas_device_add - insert sas_device to the list.
757 * @ioc: per adapter object
758 * @sas_device: the sas_device object
759 * Context: This function will acquire ioc->sas_device_lock.
761 * Adding new object to the ioc->sas_device_list.
764 _scsih_sas_device_add(struct MPT3SAS_ADAPTER *ioc,
765 struct _sas_device *sas_device)
769 dewtprintk(ioc, pr_info(MPT3SAS_FMT
770 "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
771 ioc->name, __func__, sas_device->handle,
772 (unsigned long long)sas_device->sas_address));
774 if (sas_device->enclosure_handle != 0)
775 dewtprintk(ioc, pr_info(MPT3SAS_FMT
776 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
777 ioc->name, __func__, (unsigned long long)
778 sas_device->enclosure_logical_id, sas_device->slot));
780 if (sas_device->connector_name[0] != '\0')
781 dewtprintk(ioc, pr_info(MPT3SAS_FMT
782 "%s: enclosure level(0x%04x), connector name( %s)\n",
784 sas_device->enclosure_level, sas_device->connector_name));
786 spin_lock_irqsave(&ioc->sas_device_lock, flags);
787 sas_device_get(sas_device);
788 list_add_tail(&sas_device->list, &ioc->sas_device_list);
789 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
791 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
792 sas_device->sas_address_parent)) {
793 _scsih_sas_device_remove(ioc, sas_device);
794 } else if (!sas_device->starget) {
796 * When asyn scanning is enabled, its not possible to remove
797 * devices while scanning is turned on due to an oops in
798 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
800 if (!ioc->is_driver_loading) {
801 mpt3sas_transport_port_remove(ioc,
802 sas_device->sas_address,
803 sas_device->sas_address_parent);
804 _scsih_sas_device_remove(ioc, sas_device);
810 * _scsih_sas_device_init_add - insert sas_device to the list.
811 * @ioc: per adapter object
812 * @sas_device: the sas_device object
813 * Context: This function will acquire ioc->sas_device_lock.
815 * Adding new object at driver load time to the ioc->sas_device_init_list.
818 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER *ioc,
819 struct _sas_device *sas_device)
823 dewtprintk(ioc, pr_info(MPT3SAS_FMT
824 "%s: handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
825 __func__, sas_device->handle,
826 (unsigned long long)sas_device->sas_address));
828 if (sas_device->enclosure_handle != 0)
829 dewtprintk(ioc, pr_info(MPT3SAS_FMT
830 "%s: enclosure logical id(0x%016llx), slot( %d)\n",
831 ioc->name, __func__, (unsigned long long)
832 sas_device->enclosure_logical_id, sas_device->slot));
834 if (sas_device->connector_name[0] != '\0')
835 dewtprintk(ioc, pr_info(MPT3SAS_FMT
836 "%s: enclosure level(0x%04x), connector name( %s)\n",
837 ioc->name, __func__, sas_device->enclosure_level,
838 sas_device->connector_name));
840 spin_lock_irqsave(&ioc->sas_device_lock, flags);
841 sas_device_get(sas_device);
842 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
843 _scsih_determine_boot_device(ioc, sas_device, 0);
844 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
848 * _scsih_raid_device_find_by_id - raid device search
849 * @ioc: per adapter object
850 * @id: sas device target id
851 * @channel: sas device channel
852 * Context: Calling function should acquire ioc->raid_device_lock
854 * This searches for raid_device based on target id, then return raid_device
857 static struct _raid_device *
858 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER *ioc, int id, int channel)
860 struct _raid_device *raid_device, *r;
863 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
864 if (raid_device->id == id && raid_device->channel == channel) {
875 * mpt3sas_raid_device_find_by_handle - raid device search
876 * @ioc: per adapter object
877 * @handle: sas device handle (assigned by firmware)
878 * Context: Calling function should acquire ioc->raid_device_lock
880 * This searches for raid_device based on handle, then return raid_device
883 struct _raid_device *
884 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
886 struct _raid_device *raid_device, *r;
889 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
890 if (raid_device->handle != handle)
901 * _scsih_raid_device_find_by_wwid - raid device search
902 * @ioc: per adapter object
903 * @handle: sas device handle (assigned by firmware)
904 * Context: Calling function should acquire ioc->raid_device_lock
906 * This searches for raid_device based on wwid, then return raid_device
909 static struct _raid_device *
910 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER *ioc, u64 wwid)
912 struct _raid_device *raid_device, *r;
915 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
916 if (raid_device->wwid != wwid)
927 * _scsih_raid_device_add - add raid_device object
928 * @ioc: per adapter object
929 * @raid_device: raid_device object
931 * This is added to the raid_device_list link list.
934 _scsih_raid_device_add(struct MPT3SAS_ADAPTER *ioc,
935 struct _raid_device *raid_device)
939 dewtprintk(ioc, pr_info(MPT3SAS_FMT
940 "%s: handle(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
941 raid_device->handle, (unsigned long long)raid_device->wwid));
943 spin_lock_irqsave(&ioc->raid_device_lock, flags);
944 list_add_tail(&raid_device->list, &ioc->raid_device_list);
945 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
949 * _scsih_raid_device_remove - delete raid_device object
950 * @ioc: per adapter object
951 * @raid_device: raid_device object
955 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER *ioc,
956 struct _raid_device *raid_device)
960 spin_lock_irqsave(&ioc->raid_device_lock, flags);
961 list_del(&raid_device->list);
963 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
967 * mpt3sas_scsih_expander_find_by_handle - expander device search
968 * @ioc: per adapter object
969 * @handle: expander handle (assigned by firmware)
970 * Context: Calling function should acquire ioc->sas_device_lock
972 * This searches for expander device based on handle, then returns the
976 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
978 struct _sas_node *sas_expander, *r;
981 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
982 if (sas_expander->handle != handle)
992 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
993 * @ioc: per adapter object
994 * @sas_address: sas address
995 * Context: Calling function should acquire ioc->sas_node_lock.
997 * This searches for expander device based on sas_address, then returns the
1001 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER *ioc,
1004 struct _sas_node *sas_expander, *r;
1007 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
1008 if (sas_expander->sas_address != sas_address)
1018 * _scsih_expander_node_add - insert expander device to the list.
1019 * @ioc: per adapter object
1020 * @sas_expander: the sas_device object
1021 * Context: This function will acquire ioc->sas_node_lock.
1023 * Adding new object to the ioc->sas_expander_list.
1028 _scsih_expander_node_add(struct MPT3SAS_ADAPTER *ioc,
1029 struct _sas_node *sas_expander)
1031 unsigned long flags;
1033 spin_lock_irqsave(&ioc->sas_node_lock, flags);
1034 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
1035 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
1039 * _scsih_is_end_device - determines if device is an end device
1040 * @device_info: bitfield providing information about the device.
1043 * Returns 1 if end device.
1046 _scsih_is_end_device(u32 device_info)
1048 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
1049 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
1050 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
1051 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
1058 * _scsih_scsi_lookup_get - returns scmd entry
1059 * @ioc: per adapter object
1060 * @smid: system request message index
1062 * Returns the smid stored scmd pointer.
1064 static struct scsi_cmnd *
1065 _scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1067 return ioc->scsi_lookup[smid - 1].scmd;
1071 * _scsih_scsi_lookup_get_clear - returns scmd entry
1072 * @ioc: per adapter object
1073 * @smid: system request message index
1075 * Returns the smid stored scmd pointer.
1076 * Then will derefrence the stored scmd pointer.
1078 static inline struct scsi_cmnd *
1079 _scsih_scsi_lookup_get_clear(struct MPT3SAS_ADAPTER *ioc, u16 smid)
1081 unsigned long flags;
1082 struct scsi_cmnd *scmd;
1084 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1085 scmd = ioc->scsi_lookup[smid - 1].scmd;
1086 ioc->scsi_lookup[smid - 1].scmd = NULL;
1087 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1093 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1094 * @ioc: per adapter object
1095 * @smid: system request message index
1096 * @scmd: pointer to scsi command object
1097 * Context: This function will acquire ioc->scsi_lookup_lock.
1099 * This will search for a scmd pointer in the scsi_lookup array,
1100 * returning the revelent smid. A returned value of zero means invalid.
1103 _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd
1107 unsigned long flags;
1110 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1112 for (i = 0; i < ioc->scsiio_depth; i++) {
1113 if (ioc->scsi_lookup[i].scmd == scmd) {
1114 smid = ioc->scsi_lookup[i].smid;
1119 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1124 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1125 * @ioc: per adapter object
1128 * Context: This function will acquire ioc->scsi_lookup_lock.
1130 * This will search for a matching channel:id in the scsi_lookup array,
1131 * returning 1 if found.
1134 _scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id,
1138 unsigned long flags;
1141 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1143 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1144 if (ioc->scsi_lookup[i].scmd &&
1145 (ioc->scsi_lookup[i].scmd->device->id == id &&
1146 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1152 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1157 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1158 * @ioc: per adapter object
1162 * Context: This function will acquire ioc->scsi_lookup_lock.
1164 * This will search for a matching channel:id:lun in the scsi_lookup array,
1165 * returning 1 if found.
1168 _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1169 unsigned int lun, int channel)
1172 unsigned long flags;
1175 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1177 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1178 if (ioc->scsi_lookup[i].scmd &&
1179 (ioc->scsi_lookup[i].scmd->device->id == id &&
1180 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1181 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1187 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1192 * scsih_change_queue_depth - setting device queue depth
1193 * @sdev: scsi device struct
1194 * @qdepth: requested queue depth
1196 * Returns queue depth.
1199 scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1201 struct Scsi_Host *shost = sdev->host;
1203 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1204 struct MPT3SAS_DEVICE *sas_device_priv_data;
1205 struct MPT3SAS_TARGET *sas_target_priv_data;
1206 struct _sas_device *sas_device;
1207 unsigned long flags;
1209 max_depth = shost->can_queue;
1211 /* limit max device queue for SATA to 32 */
1212 sas_device_priv_data = sdev->hostdata;
1213 if (!sas_device_priv_data)
1215 sas_target_priv_data = sas_device_priv_data->sas_target;
1216 if (!sas_target_priv_data)
1218 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1221 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1222 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1224 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1225 max_depth = MPT3SAS_SATA_QUEUE_DEPTH;
1227 sas_device_put(sas_device);
1229 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1233 if (!sdev->tagged_supported)
1235 if (qdepth > max_depth)
1237 return scsi_change_queue_depth(sdev, qdepth);
1241 * scsih_target_alloc - target add routine
1242 * @starget: scsi target struct
1244 * Returns 0 if ok. Any other return is assumed to be an error and
1245 * the device is ignored.
1248 scsih_target_alloc(struct scsi_target *starget)
1250 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1251 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1252 struct MPT3SAS_TARGET *sas_target_priv_data;
1253 struct _sas_device *sas_device;
1254 struct _raid_device *raid_device;
1255 unsigned long flags;
1256 struct sas_rphy *rphy;
1258 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1260 if (!sas_target_priv_data)
1263 starget->hostdata = sas_target_priv_data;
1264 sas_target_priv_data->starget = starget;
1265 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
1268 if (starget->channel == RAID_CHANNEL) {
1269 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1270 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1273 sas_target_priv_data->handle = raid_device->handle;
1274 sas_target_priv_data->sas_address = raid_device->wwid;
1275 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1276 sas_target_priv_data->raid_device = raid_device;
1277 if (ioc->is_warpdrive)
1278 raid_device->starget = starget;
1280 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1284 /* sas/sata devices */
1285 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1286 rphy = dev_to_rphy(starget->dev.parent);
1287 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1288 rphy->identify.sas_address);
1291 sas_target_priv_data->handle = sas_device->handle;
1292 sas_target_priv_data->sas_address = sas_device->sas_address;
1293 sas_target_priv_data->sdev = sas_device;
1294 sas_device->starget = starget;
1295 sas_device->id = starget->id;
1296 sas_device->channel = starget->channel;
1297 if (test_bit(sas_device->handle, ioc->pd_handles))
1298 sas_target_priv_data->flags |=
1299 MPT_TARGET_FLAGS_RAID_COMPONENT;
1300 if (sas_device->fast_path)
1301 sas_target_priv_data->flags |= MPT_TARGET_FASTPATH_IO;
1303 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1309 * scsih_target_destroy - target destroy routine
1310 * @starget: scsi target struct
1315 scsih_target_destroy(struct scsi_target *starget)
1317 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1318 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1319 struct MPT3SAS_TARGET *sas_target_priv_data;
1320 struct _sas_device *sas_device;
1321 struct _raid_device *raid_device;
1322 unsigned long flags;
1323 struct sas_rphy *rphy;
1325 sas_target_priv_data = starget->hostdata;
1326 if (!sas_target_priv_data)
1329 if (starget->channel == RAID_CHANNEL) {
1330 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1331 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1334 raid_device->starget = NULL;
1335 raid_device->sdev = NULL;
1337 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1341 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1342 rphy = dev_to_rphy(starget->dev.parent);
1343 sas_device = __mpt3sas_get_sdev_from_target(ioc, sas_target_priv_data);
1344 if (sas_device && (sas_device->starget == starget) &&
1345 (sas_device->id == starget->id) &&
1346 (sas_device->channel == starget->channel))
1347 sas_device->starget = NULL;
1351 * Corresponding get() is in _scsih_target_alloc()
1353 sas_target_priv_data->sdev = NULL;
1354 sas_device_put(sas_device);
1356 sas_device_put(sas_device);
1358 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1361 kfree(sas_target_priv_data);
1362 starget->hostdata = NULL;
1366 * scsih_slave_alloc - device add routine
1367 * @sdev: scsi device struct
1369 * Returns 0 if ok. Any other return is assumed to be an error and
1370 * the device is ignored.
1373 scsih_slave_alloc(struct scsi_device *sdev)
1375 struct Scsi_Host *shost;
1376 struct MPT3SAS_ADAPTER *ioc;
1377 struct MPT3SAS_TARGET *sas_target_priv_data;
1378 struct MPT3SAS_DEVICE *sas_device_priv_data;
1379 struct scsi_target *starget;
1380 struct _raid_device *raid_device;
1381 struct _sas_device *sas_device;
1382 unsigned long flags;
1384 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1386 if (!sas_device_priv_data)
1389 sas_device_priv_data->lun = sdev->lun;
1390 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1392 starget = scsi_target(sdev);
1393 sas_target_priv_data = starget->hostdata;
1394 sas_target_priv_data->num_luns++;
1395 sas_device_priv_data->sas_target = sas_target_priv_data;
1396 sdev->hostdata = sas_device_priv_data;
1397 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1398 sdev->no_uld_attach = 1;
1400 shost = dev_to_shost(&starget->dev);
1401 ioc = shost_priv(shost);
1402 if (starget->channel == RAID_CHANNEL) {
1403 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1404 raid_device = _scsih_raid_device_find_by_id(ioc,
1405 starget->id, starget->channel);
1407 raid_device->sdev = sdev; /* raid is single lun */
1408 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1411 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1412 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1413 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1414 sas_target_priv_data->sas_address);
1415 if (sas_device && (sas_device->starget == NULL)) {
1416 sdev_printk(KERN_INFO, sdev,
1417 "%s : sas_device->starget set to starget @ %d\n",
1418 __func__, __LINE__);
1419 sas_device->starget = starget;
1423 sas_device_put(sas_device);
1425 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1432 * scsih_slave_destroy - device destroy routine
1433 * @sdev: scsi device struct
1438 scsih_slave_destroy(struct scsi_device *sdev)
1440 struct MPT3SAS_TARGET *sas_target_priv_data;
1441 struct scsi_target *starget;
1442 struct Scsi_Host *shost;
1443 struct MPT3SAS_ADAPTER *ioc;
1444 struct _sas_device *sas_device;
1445 unsigned long flags;
1447 if (!sdev->hostdata)
1450 starget = scsi_target(sdev);
1451 sas_target_priv_data = starget->hostdata;
1452 sas_target_priv_data->num_luns--;
1454 shost = dev_to_shost(&starget->dev);
1455 ioc = shost_priv(shost);
1457 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1458 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1459 sas_device = __mpt3sas_get_sdev_from_target(ioc,
1460 sas_target_priv_data);
1461 if (sas_device && !sas_target_priv_data->num_luns)
1462 sas_device->starget = NULL;
1465 sas_device_put(sas_device);
1466 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1469 kfree(sdev->hostdata);
1470 sdev->hostdata = NULL;
1474 * _scsih_display_sata_capabilities - sata capabilities
1475 * @ioc: per adapter object
1476 * @handle: device handle
1477 * @sdev: scsi device struct
1480 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER *ioc,
1481 u16 handle, struct scsi_device *sdev)
1483 Mpi2ConfigReply_t mpi_reply;
1484 Mpi2SasDevicePage0_t sas_device_pg0;
1489 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1490 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1491 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1492 ioc->name, __FILE__, __LINE__, __func__);
1496 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1497 MPI2_IOCSTATUS_MASK;
1498 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1499 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1500 ioc->name, __FILE__, __LINE__, __func__);
1504 flags = le16_to_cpu(sas_device_pg0.Flags);
1505 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1507 sdev_printk(KERN_INFO, sdev,
1508 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1509 "sw_preserve(%s)\n",
1510 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1511 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1512 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1515 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1516 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1520 * raid transport support -
1521 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1522 * unloading the driver followed by a load - I beleive that the subroutine
1523 * raid_class_release() is not cleaning up properly.
1527 * scsih_is_raid - return boolean indicating device is raid volume
1528 * @dev the device struct object
1531 scsih_is_raid(struct device *dev)
1533 struct scsi_device *sdev = to_scsi_device(dev);
1534 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1536 if (ioc->is_warpdrive)
1538 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1542 * scsih_get_resync - get raid volume resync percent complete
1543 * @dev the device struct object
1546 scsih_get_resync(struct device *dev)
1548 struct scsi_device *sdev = to_scsi_device(dev);
1549 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1550 static struct _raid_device *raid_device;
1551 unsigned long flags;
1552 Mpi2RaidVolPage0_t vol_pg0;
1553 Mpi2ConfigReply_t mpi_reply;
1554 u32 volume_status_flags;
1555 u8 percent_complete;
1558 percent_complete = 0;
1560 if (ioc->is_warpdrive)
1563 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1564 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1567 handle = raid_device->handle;
1568 percent_complete = raid_device->percent_complete;
1570 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1575 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1576 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1577 sizeof(Mpi2RaidVolPage0_t))) {
1578 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1579 ioc->name, __FILE__, __LINE__, __func__);
1580 percent_complete = 0;
1584 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1585 if (!(volume_status_flags &
1586 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1587 percent_complete = 0;
1591 switch (ioc->hba_mpi_version_belonged) {
1593 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1597 raid_set_resync(mpt3sas_raid_template, dev, percent_complete);
1603 * scsih_get_state - get raid volume level
1604 * @dev the device struct object
1607 scsih_get_state(struct device *dev)
1609 struct scsi_device *sdev = to_scsi_device(dev);
1610 struct MPT3SAS_ADAPTER *ioc = shost_priv(sdev->host);
1611 static struct _raid_device *raid_device;
1612 unsigned long flags;
1613 Mpi2RaidVolPage0_t vol_pg0;
1614 Mpi2ConfigReply_t mpi_reply;
1616 enum raid_state state = RAID_STATE_UNKNOWN;
1619 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1620 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1623 handle = raid_device->handle;
1624 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1629 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1630 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1631 sizeof(Mpi2RaidVolPage0_t))) {
1632 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1633 ioc->name, __FILE__, __LINE__, __func__);
1637 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1638 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1639 state = RAID_STATE_RESYNCING;
1643 switch (vol_pg0.VolumeState) {
1644 case MPI2_RAID_VOL_STATE_OPTIMAL:
1645 case MPI2_RAID_VOL_STATE_ONLINE:
1646 state = RAID_STATE_ACTIVE;
1648 case MPI2_RAID_VOL_STATE_DEGRADED:
1649 state = RAID_STATE_DEGRADED;
1651 case MPI2_RAID_VOL_STATE_FAILED:
1652 case MPI2_RAID_VOL_STATE_MISSING:
1653 state = RAID_STATE_OFFLINE;
1657 switch (ioc->hba_mpi_version_belonged) {
1659 raid_set_state(mpt2sas_raid_template, dev, state);
1663 raid_set_state(mpt3sas_raid_template, dev, state);
1669 * _scsih_set_level - set raid level
1670 * @sdev: scsi device struct
1671 * @volume_type: volume type
1674 _scsih_set_level(struct MPT3SAS_ADAPTER *ioc,
1675 struct scsi_device *sdev, u8 volume_type)
1677 enum raid_level level = RAID_LEVEL_UNKNOWN;
1679 switch (volume_type) {
1680 case MPI2_RAID_VOL_TYPE_RAID0:
1681 level = RAID_LEVEL_0;
1683 case MPI2_RAID_VOL_TYPE_RAID10:
1684 level = RAID_LEVEL_10;
1686 case MPI2_RAID_VOL_TYPE_RAID1E:
1687 level = RAID_LEVEL_1E;
1689 case MPI2_RAID_VOL_TYPE_RAID1:
1690 level = RAID_LEVEL_1;
1694 switch (ioc->hba_mpi_version_belonged) {
1696 raid_set_level(mpt2sas_raid_template,
1697 &sdev->sdev_gendev, level);
1701 raid_set_level(mpt3sas_raid_template,
1702 &sdev->sdev_gendev, level);
1709 * _scsih_get_volume_capabilities - volume capabilities
1710 * @ioc: per adapter object
1711 * @sas_device: the raid_device object
1713 * Returns 0 for success, else 1
1716 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER *ioc,
1717 struct _raid_device *raid_device)
1719 Mpi2RaidVolPage0_t *vol_pg0;
1720 Mpi2RaidPhysDiskPage0_t pd_pg0;
1721 Mpi2SasDevicePage0_t sas_device_pg0;
1722 Mpi2ConfigReply_t mpi_reply;
1726 if ((mpt3sas_config_get_number_pds(ioc, raid_device->handle,
1727 &num_pds)) || !num_pds) {
1728 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1729 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1734 raid_device->num_pds = num_pds;
1735 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1736 sizeof(Mpi2RaidVol0PhysDisk_t));
1737 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1739 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1740 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1745 if ((mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1746 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1747 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1748 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1754 raid_device->volume_type = vol_pg0->VolumeType;
1756 /* figure out what the underlying devices are by
1757 * obtaining the device_info bits for the 1st device
1759 if (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1760 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1761 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1762 if (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1763 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1764 le16_to_cpu(pd_pg0.DevHandle)))) {
1765 raid_device->device_info =
1766 le32_to_cpu(sas_device_pg0.DeviceInfo);
1775 * _scsih_enable_tlr - setting TLR flags
1776 * @ioc: per adapter object
1777 * @sdev: scsi device struct
1779 * Enabling Transaction Layer Retries for tape devices when
1780 * vpd page 0x90 is present
1784 _scsih_enable_tlr(struct MPT3SAS_ADAPTER *ioc, struct scsi_device *sdev)
1788 if (sdev->type != TYPE_TAPE)
1791 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1794 sas_enable_tlr(sdev);
1795 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1796 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1802 * scsih_slave_configure - device configure routine.
1803 * @sdev: scsi device struct
1805 * Returns 0 if ok. Any other return is assumed to be an error and
1806 * the device is ignored.
1809 scsih_slave_configure(struct scsi_device *sdev)
1811 struct Scsi_Host *shost = sdev->host;
1812 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
1813 struct MPT3SAS_DEVICE *sas_device_priv_data;
1814 struct MPT3SAS_TARGET *sas_target_priv_data;
1815 struct _sas_device *sas_device;
1816 struct _raid_device *raid_device;
1817 unsigned long flags;
1822 u16 handle, volume_handle = 0;
1823 u64 volume_wwid = 0;
1826 sas_device_priv_data = sdev->hostdata;
1827 sas_device_priv_data->configured_lun = 1;
1828 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1829 sas_target_priv_data = sas_device_priv_data->sas_target;
1830 handle = sas_target_priv_data->handle;
1832 /* raid volume handling */
1833 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1835 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1836 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
1837 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1839 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1840 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1841 __LINE__, __func__));
1845 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1846 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1847 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1848 __LINE__, __func__));
1853 * WARPDRIVE: Initialize the required data for Direct IO
1855 mpt3sas_init_warpdrive_properties(ioc, raid_device);
1857 /* RAID Queue Depth Support
1858 * IS volume = underlying qdepth of drive type, either
1859 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
1860 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
1862 if (raid_device->device_info &
1863 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1864 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1867 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1868 if (raid_device->device_info &
1869 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1875 switch (raid_device->volume_type) {
1876 case MPI2_RAID_VOL_TYPE_RAID0:
1879 case MPI2_RAID_VOL_TYPE_RAID1E:
1880 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1881 if (ioc->manu_pg10.OEMIdentifier &&
1882 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1883 MFG10_GF0_R10_DISPLAY) &&
1884 !(raid_device->num_pds % 2))
1889 case MPI2_RAID_VOL_TYPE_RAID1:
1890 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1893 case MPI2_RAID_VOL_TYPE_RAID10:
1894 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1897 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1899 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
1904 if (!ioc->hide_ir_msg)
1905 sdev_printk(KERN_INFO, sdev,
1906 "%s: handle(0x%04x), wwid(0x%016llx),"
1907 " pd_count(%d), type(%s)\n",
1908 r_level, raid_device->handle,
1909 (unsigned long long)raid_device->wwid,
1910 raid_device->num_pds, ds);
1912 scsih_change_queue_depth(sdev, qdepth);
1914 /* raid transport support */
1915 if (!ioc->is_warpdrive)
1916 _scsih_set_level(ioc, sdev, raid_device->volume_type);
1920 /* non-raid handling */
1921 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1922 if (mpt3sas_config_get_volume_handle(ioc, handle,
1924 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1925 "failure at %s:%d/%s()!\n", ioc->name,
1926 __FILE__, __LINE__, __func__));
1929 if (volume_handle && mpt3sas_config_get_volume_wwid(ioc,
1930 volume_handle, &volume_wwid)) {
1931 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1932 "failure at %s:%d/%s()!\n", ioc->name,
1933 __FILE__, __LINE__, __func__));
1938 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1939 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
1940 sas_device_priv_data->sas_target->sas_address);
1942 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1943 dfailprintk(ioc, pr_warn(MPT3SAS_FMT
1944 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1949 sas_device->volume_handle = volume_handle;
1950 sas_device->volume_wwid = volume_wwid;
1951 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1952 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
1954 if (sas_device->device_info &
1955 MPI2_SAS_DEVICE_INFO_SEP) {
1956 sdev_printk(KERN_WARNING, sdev,
1957 "set ignore_delay_remove for handle(0x%04x)\n",
1958 sas_device_priv_data->sas_target->handle);
1959 sas_device_priv_data->ignore_delay_remove = 1;
1964 qdepth = MPT3SAS_SATA_QUEUE_DEPTH;
1965 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
1967 else if (sas_device->device_info &
1968 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1972 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), " \
1973 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
1974 ds, handle, (unsigned long long)sas_device->sas_address,
1975 sas_device->phy, (unsigned long long)sas_device->device_name);
1976 if (sas_device->enclosure_handle != 0)
1977 sdev_printk(KERN_INFO, sdev,
1978 "%s: enclosure_logical_id(0x%016llx), slot(%d)\n",
1979 ds, (unsigned long long)
1980 sas_device->enclosure_logical_id, sas_device->slot);
1981 if (sas_device->connector_name[0] != '\0')
1982 sdev_printk(KERN_INFO, sdev,
1983 "%s: enclosure level(0x%04x), connector name( %s)\n",
1984 ds, sas_device->enclosure_level,
1985 sas_device->connector_name);
1987 sas_device_put(sas_device);
1988 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1991 _scsih_display_sata_capabilities(ioc, handle, sdev);
1994 scsih_change_queue_depth(sdev, qdepth);
1997 sas_read_port_mode_page(sdev);
1998 _scsih_enable_tlr(ioc, sdev);
2005 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2006 * @sdev: scsi device struct
2007 * @bdev: pointer to block device context
2008 * @capacity: device size (in 512 byte sectors)
2009 * @params: three element array to place output:
2010 * params[0] number of heads (max 255)
2011 * params[1] number of sectors (max 63)
2012 * params[2] number of cylinders
2017 scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2018 sector_t capacity, int params[])
2028 dummy = heads * sectors;
2029 cylinders = capacity;
2030 sector_div(cylinders, dummy);
2033 * Handle extended translation size for logical drives
2036 if ((ulong)capacity >= 0x200000) {
2039 dummy = heads * sectors;
2040 cylinders = capacity;
2041 sector_div(cylinders, dummy);
2046 params[1] = sectors;
2047 params[2] = cylinders;
2053 * _scsih_response_code - translation of device response code
2054 * @ioc: per adapter object
2055 * @response_code: response code returned by the device
2060 _scsih_response_code(struct MPT3SAS_ADAPTER *ioc, u8 response_code)
2064 switch (response_code) {
2065 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2066 desc = "task management request completed";
2068 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2069 desc = "invalid frame";
2071 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2072 desc = "task management request not supported";
2074 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2075 desc = "task management request failed";
2077 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2078 desc = "task management request succeeded";
2080 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2081 desc = "invalid lun";
2084 desc = "overlapped tag attempted";
2086 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2087 desc = "task queued, however not sent to target";
2093 pr_warn(MPT3SAS_FMT "response_code(0x%01x): %s\n",
2094 ioc->name, response_code, desc);
2098 * _scsih_tm_done - tm completion routine
2099 * @ioc: per adapter object
2100 * @smid: system request message index
2101 * @msix_index: MSIX table index supplied by the OS
2102 * @reply: reply message frame(lower 32bit addr)
2105 * The callback handler when using scsih_issue_tm.
2107 * Return 1 meaning mf should be freed from _base_interrupt
2108 * 0 means the mf is freed from this function.
2111 _scsih_tm_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2113 MPI2DefaultReply_t *mpi_reply;
2115 if (ioc->tm_cmds.status == MPT3_CMD_NOT_USED)
2117 if (ioc->tm_cmds.smid != smid)
2119 mpt3sas_base_flush_reply_queues(ioc);
2120 ioc->tm_cmds.status |= MPT3_CMD_COMPLETE;
2121 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
2123 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2124 ioc->tm_cmds.status |= MPT3_CMD_REPLY_VALID;
2126 ioc->tm_cmds.status &= ~MPT3_CMD_PENDING;
2127 complete(&ioc->tm_cmds.done);
2132 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2133 * @ioc: per adapter object
2134 * @handle: device handle
2136 * During taskmangement request, we need to freeze the device queue.
2139 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2141 struct MPT3SAS_DEVICE *sas_device_priv_data;
2142 struct scsi_device *sdev;
2145 shost_for_each_device(sdev, ioc->shost) {
2148 sas_device_priv_data = sdev->hostdata;
2149 if (!sas_device_priv_data)
2151 if (sas_device_priv_data->sas_target->handle == handle) {
2152 sas_device_priv_data->sas_target->tm_busy = 1;
2154 ioc->ignore_loginfos = 1;
2160 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2161 * @ioc: per adapter object
2162 * @handle: device handle
2164 * During taskmangement request, we need to freeze the device queue.
2167 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2169 struct MPT3SAS_DEVICE *sas_device_priv_data;
2170 struct scsi_device *sdev;
2173 shost_for_each_device(sdev, ioc->shost) {
2176 sas_device_priv_data = sdev->hostdata;
2177 if (!sas_device_priv_data)
2179 if (sas_device_priv_data->sas_target->handle == handle) {
2180 sas_device_priv_data->sas_target->tm_busy = 0;
2182 ioc->ignore_loginfos = 0;
2188 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2189 * @ioc: per adapter struct
2190 * @device_handle: device handle
2191 * @channel: the channel assigned by the OS
2192 * @id: the id assigned by the OS
2194 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2195 * @smid_task: smid assigned to the task
2196 * @timeout: timeout in seconds
2197 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2200 * A generic API for sending task management requests to firmware.
2202 * The callback index is set inside `ioc->tm_cb_idx`.
2204 * Return SUCCESS or FAILED.
2207 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel,
2208 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2209 enum mutex_type m_type)
2211 Mpi2SCSITaskManagementRequest_t *mpi_request;
2212 Mpi2SCSITaskManagementReply_t *mpi_reply;
2215 unsigned long timeleft;
2216 struct scsiio_tracker *scsi_lookup = NULL;
2220 if (m_type == TM_MUTEX_ON)
2221 mutex_lock(&ioc->tm_cmds.mutex);
2222 if (ioc->tm_cmds.status != MPT3_CMD_NOT_USED) {
2223 pr_info(MPT3SAS_FMT "%s: tm_cmd busy!!!\n",
2224 __func__, ioc->name);
2229 if (ioc->shost_recovery || ioc->remove_host ||
2230 ioc->pci_error_recovery) {
2231 pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
2232 __func__, ioc->name);
2237 ioc_state = mpt3sas_base_get_iocstate(ioc, 0);
2238 if (ioc_state & MPI2_DOORBELL_USED) {
2239 dhsprintk(ioc, pr_info(MPT3SAS_FMT
2240 "unexpected doorbell active!\n", ioc->name));
2241 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2243 rc = (!rc) ? SUCCESS : FAILED;
2247 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2248 mpt3sas_base_fault_info(ioc, ioc_state &
2249 MPI2_DOORBELL_DATA_MASK);
2250 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2252 rc = (!rc) ? SUCCESS : FAILED;
2256 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2258 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2259 ioc->name, __func__);
2264 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2265 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2267 dtmprintk(ioc, pr_info(MPT3SAS_FMT
2268 "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d)\n",
2269 ioc->name, handle, type, smid_task));
2270 ioc->tm_cmds.status = MPT3_CMD_PENDING;
2271 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2272 ioc->tm_cmds.smid = smid;
2273 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2274 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2275 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2276 mpi_request->DevHandle = cpu_to_le16(handle);
2277 mpi_request->TaskType = type;
2278 mpi_request->TaskMID = cpu_to_le16(smid_task);
2279 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2280 mpt3sas_scsih_set_tm_flag(ioc, handle);
2281 init_completion(&ioc->tm_cmds.done);
2282 if ((type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) &&
2283 (scsi_lookup->msix_io < ioc->reply_queue_count))
2284 msix_task = scsi_lookup->msix_io;
2287 mpt3sas_base_put_smid_hi_priority(ioc, smid, msix_task);
2288 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2289 if (!(ioc->tm_cmds.status & MPT3_CMD_COMPLETE)) {
2290 pr_err(MPT3SAS_FMT "%s: timeout\n",
2291 ioc->name, __func__);
2292 _debug_dump_mf(mpi_request,
2293 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2294 if (!(ioc->tm_cmds.status & MPT3_CMD_RESET)) {
2295 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2297 rc = (!rc) ? SUCCESS : FAILED;
2298 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2299 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2304 if (ioc->tm_cmds.status & MPT3_CMD_REPLY_VALID) {
2305 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
2306 mpi_reply = ioc->tm_cmds.reply;
2307 dtmprintk(ioc, pr_info(MPT3SAS_FMT "complete tm: " \
2308 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2309 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2310 le32_to_cpu(mpi_reply->IOCLogInfo),
2311 le32_to_cpu(mpi_reply->TerminationCount)));
2312 if (ioc->logging_level & MPT_DEBUG_TM) {
2313 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2314 if (mpi_reply->IOCStatus)
2315 _debug_dump_mf(mpi_request,
2316 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2321 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2323 if (scsi_lookup->scmd == NULL)
2328 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2329 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2334 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2335 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2336 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2341 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2349 mpt3sas_scsih_clear_tm_flag(ioc, handle);
2350 ioc->tm_cmds.status = MPT3_CMD_NOT_USED;
2351 if (m_type == TM_MUTEX_ON)
2352 mutex_unlock(&ioc->tm_cmds.mutex);
2357 if (m_type == TM_MUTEX_ON)
2358 mutex_unlock(&ioc->tm_cmds.mutex);
2363 * _scsih_tm_display_info - displays info about the device
2364 * @ioc: per adapter struct
2365 * @scmd: pointer to scsi command object
2367 * Called by task management callback handlers.
2370 _scsih_tm_display_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2372 struct scsi_target *starget = scmd->device->sdev_target;
2373 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
2374 struct _sas_device *sas_device = NULL;
2375 unsigned long flags;
2376 char *device_str = NULL;
2380 if (ioc->hide_ir_msg)
2381 device_str = "WarpDrive";
2383 device_str = "volume";
2385 scsi_print_command(scmd);
2386 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2387 starget_printk(KERN_INFO, starget,
2388 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2389 device_str, priv_target->handle,
2390 device_str, (unsigned long long)priv_target->sas_address);
2392 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2393 sas_device = __mpt3sas_get_sdev_from_target(ioc, priv_target);
2395 if (priv_target->flags &
2396 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2397 starget_printk(KERN_INFO, starget,
2398 "volume handle(0x%04x), "
2399 "volume wwid(0x%016llx)\n",
2400 sas_device->volume_handle,
2401 (unsigned long long)sas_device->volume_wwid);
2403 starget_printk(KERN_INFO, starget,
2404 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2406 (unsigned long long)sas_device->sas_address,
2408 if (sas_device->enclosure_handle != 0)
2409 starget_printk(KERN_INFO, starget,
2410 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2411 (unsigned long long)
2412 sas_device->enclosure_logical_id,
2414 if (sas_device->connector_name[0] != '\0')
2415 starget_printk(KERN_INFO, starget,
2416 "enclosure level(0x%04x),connector name(%s)\n",
2417 sas_device->enclosure_level,
2418 sas_device->connector_name);
2420 sas_device_put(sas_device);
2422 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2427 * scsih_abort - eh threads main abort routine
2428 * @scmd: pointer to scsi command object
2430 * Returns SUCCESS if command aborted else FAILED
2433 scsih_abort(struct scsi_cmnd *scmd)
2435 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2436 struct MPT3SAS_DEVICE *sas_device_priv_data;
2441 sdev_printk(KERN_INFO, scmd->device,
2442 "attempting task abort! scmd(%p)\n", scmd);
2443 _scsih_tm_display_info(ioc, scmd);
2445 sas_device_priv_data = scmd->device->hostdata;
2446 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2447 sdev_printk(KERN_INFO, scmd->device,
2448 "device been deleted! scmd(%p)\n", scmd);
2449 scmd->result = DID_NO_CONNECT << 16;
2450 scmd->scsi_done(scmd);
2455 /* search for the command */
2456 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2458 scmd->result = DID_RESET << 16;
2463 /* for hidden raid components and volumes this is not supported */
2464 if (sas_device_priv_data->sas_target->flags &
2465 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2466 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2467 scmd->result = DID_RESET << 16;
2472 mpt3sas_halt_firmware(ioc);
2474 handle = sas_device_priv_data->sas_target->handle;
2475 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2476 scmd->device->id, scmd->device->lun,
2477 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2480 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2481 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2486 * scsih_dev_reset - eh threads main device reset routine
2487 * @scmd: pointer to scsi command object
2489 * Returns SUCCESS if command aborted else FAILED
2492 scsih_dev_reset(struct scsi_cmnd *scmd)
2494 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2495 struct MPT3SAS_DEVICE *sas_device_priv_data;
2496 struct _sas_device *sas_device = NULL;
2500 struct scsi_target *starget = scmd->device->sdev_target;
2501 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2503 sdev_printk(KERN_INFO, scmd->device,
2504 "attempting device reset! scmd(%p)\n", scmd);
2505 _scsih_tm_display_info(ioc, scmd);
2507 sas_device_priv_data = scmd->device->hostdata;
2508 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2509 sdev_printk(KERN_INFO, scmd->device,
2510 "device been deleted! scmd(%p)\n", scmd);
2511 scmd->result = DID_NO_CONNECT << 16;
2512 scmd->scsi_done(scmd);
2517 /* for hidden raid components obtain the volume_handle */
2519 if (sas_device_priv_data->sas_target->flags &
2520 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2521 sas_device = mpt3sas_get_sdev_from_target(ioc,
2524 handle = sas_device->volume_handle;
2526 handle = sas_device_priv_data->sas_target->handle;
2529 scmd->result = DID_RESET << 16;
2534 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2535 scmd->device->id, scmd->device->lun,
2536 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2539 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2540 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2543 sas_device_put(sas_device);
2549 * scsih_target_reset - eh threads main target reset routine
2550 * @scmd: pointer to scsi command object
2552 * Returns SUCCESS if command aborted else FAILED
2555 scsih_target_reset(struct scsi_cmnd *scmd)
2557 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2558 struct MPT3SAS_DEVICE *sas_device_priv_data;
2559 struct _sas_device *sas_device = NULL;
2562 struct scsi_target *starget = scmd->device->sdev_target;
2563 struct MPT3SAS_TARGET *target_priv_data = starget->hostdata;
2565 starget_printk(KERN_INFO, starget, "attempting target reset! scmd(%p)\n",
2567 _scsih_tm_display_info(ioc, scmd);
2569 sas_device_priv_data = scmd->device->hostdata;
2570 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2571 starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n",
2573 scmd->result = DID_NO_CONNECT << 16;
2574 scmd->scsi_done(scmd);
2579 /* for hidden raid components obtain the volume_handle */
2581 if (sas_device_priv_data->sas_target->flags &
2582 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2583 sas_device = mpt3sas_get_sdev_from_target(ioc,
2586 handle = sas_device->volume_handle;
2588 handle = sas_device_priv_data->sas_target->handle;
2591 scmd->result = DID_RESET << 16;
2596 r = mpt3sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2597 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2601 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2602 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2605 sas_device_put(sas_device);
2612 * scsih_host_reset - eh threads main host reset routine
2613 * @scmd: pointer to scsi command object
2615 * Returns SUCCESS if command aborted else FAILED
2618 scsih_host_reset(struct scsi_cmnd *scmd)
2620 struct MPT3SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2623 pr_info(MPT3SAS_FMT "attempting host reset! scmd(%p)\n",
2625 scsi_print_command(scmd);
2627 if (ioc->is_driver_loading) {
2628 pr_info(MPT3SAS_FMT "Blocking the host reset\n",
2634 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2636 r = (retval < 0) ? FAILED : SUCCESS;
2638 pr_info(MPT3SAS_FMT "host reset: %s scmd(%p)\n",
2639 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2645 * _scsih_fw_event_add - insert and queue up fw_event
2646 * @ioc: per adapter object
2647 * @fw_event: object describing the event
2648 * Context: This function will acquire ioc->fw_event_lock.
2650 * This adds the firmware event object into link list, then queues it up to
2651 * be processed from user context.
2656 _scsih_fw_event_add(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2658 unsigned long flags;
2660 if (ioc->firmware_event_thread == NULL)
2663 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2664 fw_event_work_get(fw_event);
2665 INIT_LIST_HEAD(&fw_event->list);
2666 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2667 INIT_WORK(&fw_event->work, _firmware_event_work);
2668 fw_event_work_get(fw_event);
2669 queue_work(ioc->firmware_event_thread, &fw_event->work);
2670 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2674 * _scsih_fw_event_del_from_list - delete fw_event from the list
2675 * @ioc: per adapter object
2676 * @fw_event: object describing the event
2677 * Context: This function will acquire ioc->fw_event_lock.
2679 * If the fw_event is on the fw_event_list, remove it and do a put.
2684 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work
2687 unsigned long flags;
2689 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2690 if (!list_empty(&fw_event->list)) {
2691 list_del_init(&fw_event->list);
2692 fw_event_work_put(fw_event);
2694 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2699 * mpt3sas_send_trigger_data_event - send event for processing trigger data
2700 * @ioc: per adapter object
2701 * @event_data: trigger event data
2706 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER *ioc,
2707 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
2709 struct fw_event_work *fw_event;
2712 if (ioc->is_driver_loading)
2714 sz = sizeof(*event_data);
2715 fw_event = alloc_fw_event_work(sz);
2718 fw_event->event = MPT3SAS_PROCESS_TRIGGER_DIAG;
2719 fw_event->ioc = ioc;
2720 memcpy(fw_event->event_data, event_data, sizeof(*event_data));
2721 _scsih_fw_event_add(ioc, fw_event);
2722 fw_event_work_put(fw_event);
2726 * _scsih_error_recovery_delete_devices - remove devices not responding
2727 * @ioc: per adapter object
2732 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER *ioc)
2734 struct fw_event_work *fw_event;
2736 if (ioc->is_driver_loading)
2738 fw_event = alloc_fw_event_work(0);
2741 fw_event->event = MPT3SAS_REMOVE_UNRESPONDING_DEVICES;
2742 fw_event->ioc = ioc;
2743 _scsih_fw_event_add(ioc, fw_event);
2744 fw_event_work_put(fw_event);
2748 * mpt3sas_port_enable_complete - port enable completed (fake event)
2749 * @ioc: per adapter object
2754 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc)
2756 struct fw_event_work *fw_event;
2758 fw_event = alloc_fw_event_work(0);
2761 fw_event->event = MPT3SAS_PORT_ENABLE_COMPLETE;
2762 fw_event->ioc = ioc;
2763 _scsih_fw_event_add(ioc, fw_event);
2764 fw_event_work_put(fw_event);
2767 static struct fw_event_work *dequeue_next_fw_event(struct MPT3SAS_ADAPTER *ioc)
2769 unsigned long flags;
2770 struct fw_event_work *fw_event = NULL;
2772 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2773 if (!list_empty(&ioc->fw_event_list)) {
2774 fw_event = list_first_entry(&ioc->fw_event_list,
2775 struct fw_event_work, list);
2776 list_del_init(&fw_event->list);
2778 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2784 * _scsih_fw_event_cleanup_queue - cleanup event queue
2785 * @ioc: per adapter object
2787 * Walk the firmware event queue, either killing timers, or waiting
2788 * for outstanding events to complete
2793 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER *ioc)
2795 struct fw_event_work *fw_event;
2797 if (list_empty(&ioc->fw_event_list) ||
2798 !ioc->firmware_event_thread || in_interrupt())
2801 while ((fw_event = dequeue_next_fw_event(ioc))) {
2803 * Wait on the fw_event to complete. If this returns 1, then
2804 * the event was never executed, and we need a put for the
2805 * reference the work had on the fw_event.
2807 * If it did execute, we wait for it to finish, and the put will
2808 * happen from _firmware_event_work()
2810 if (cancel_work_sync(&fw_event->work))
2811 fw_event_work_put(fw_event);
2813 fw_event_work_put(fw_event);
2818 * _scsih_internal_device_block - block the sdev device
2819 * @sdev: per device object
2820 * @sas_device_priv_data : per device driver private data
2822 * make sure device is blocked without error, if not
2826 _scsih_internal_device_block(struct scsi_device *sdev,
2827 struct MPT3SAS_DEVICE *sas_device_priv_data)
2831 sdev_printk(KERN_INFO, sdev, "device_block, handle(0x%04x)\n",
2832 sas_device_priv_data->sas_target->handle);
2833 sas_device_priv_data->block = 1;
2835 r = scsi_internal_device_block(sdev);
2837 sdev_printk(KERN_WARNING, sdev,
2838 "device_block failed with return(%d) for handle(0x%04x)\n",
2839 sas_device_priv_data->sas_target->handle, r);
2843 * _scsih_internal_device_unblock - unblock the sdev device
2844 * @sdev: per device object
2845 * @sas_device_priv_data : per device driver private data
2846 * make sure device is unblocked without error, if not retry
2847 * by blocking and then unblocking
2851 _scsih_internal_device_unblock(struct scsi_device *sdev,
2852 struct MPT3SAS_DEVICE *sas_device_priv_data)
2856 sdev_printk(KERN_WARNING, sdev, "device_unblock and setting to running, "
2857 "handle(0x%04x)\n", sas_device_priv_data->sas_target->handle);
2858 sas_device_priv_data->block = 0;
2859 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2861 /* The device has been set to SDEV_RUNNING by SD layer during
2862 * device addition but the request queue is still stopped by
2863 * our earlier block call. We need to perform a block again
2864 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
2866 sdev_printk(KERN_WARNING, sdev,
2867 "device_unblock failed with return(%d) for handle(0x%04x) "
2868 "performing a block followed by an unblock\n",
2869 sas_device_priv_data->sas_target->handle, r);
2870 sas_device_priv_data->block = 1;
2871 r = scsi_internal_device_block(sdev);
2873 sdev_printk(KERN_WARNING, sdev, "retried device_block "
2874 "failed with return(%d) for handle(0x%04x)\n",
2875 sas_device_priv_data->sas_target->handle, r);
2877 sas_device_priv_data->block = 0;
2878 r = scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2880 sdev_printk(KERN_WARNING, sdev, "retried device_unblock"
2881 " failed with return(%d) for handle(0x%04x)\n",
2882 sas_device_priv_data->sas_target->handle, r);
2887 * _scsih_ublock_io_all_device - unblock every device
2888 * @ioc: per adapter object
2890 * change the device state from block to running
2893 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2895 struct MPT3SAS_DEVICE *sas_device_priv_data;
2896 struct scsi_device *sdev;
2898 shost_for_each_device(sdev, ioc->shost) {
2899 sas_device_priv_data = sdev->hostdata;
2900 if (!sas_device_priv_data)
2902 if (!sas_device_priv_data->block)
2905 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2906 "device_running, handle(0x%04x)\n",
2907 sas_device_priv_data->sas_target->handle));
2908 _scsih_internal_device_unblock(sdev, sas_device_priv_data);
2914 * _scsih_ublock_io_device - prepare device to be deleted
2915 * @ioc: per adapter object
2916 * @sas_addr: sas address
2918 * unblock then put device in offline state
2921 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
2923 struct MPT3SAS_DEVICE *sas_device_priv_data;
2924 struct scsi_device *sdev;
2926 shost_for_each_device(sdev, ioc->shost) {
2927 sas_device_priv_data = sdev->hostdata;
2928 if (!sas_device_priv_data)
2930 if (sas_device_priv_data->sas_target->sas_address
2933 if (sas_device_priv_data->block)
2934 _scsih_internal_device_unblock(sdev,
2935 sas_device_priv_data);
2940 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2941 * @ioc: per adapter object
2942 * @handle: device handle
2944 * During device pull we need to appropiately set the sdev state.
2947 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER *ioc)
2949 struct MPT3SAS_DEVICE *sas_device_priv_data;
2950 struct scsi_device *sdev;
2952 shost_for_each_device(sdev, ioc->shost) {
2953 sas_device_priv_data = sdev->hostdata;
2954 if (!sas_device_priv_data)
2956 if (sas_device_priv_data->block)
2958 if (sas_device_priv_data->ignore_delay_remove) {
2959 sdev_printk(KERN_INFO, sdev,
2960 "%s skip device_block for SES handle(0x%04x)\n",
2961 __func__, sas_device_priv_data->sas_target->handle);
2964 _scsih_internal_device_block(sdev, sas_device_priv_data);
2969 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2970 * @ioc: per adapter object
2971 * @handle: device handle
2973 * During device pull we need to appropiately set the sdev state.
2976 _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
2978 struct MPT3SAS_DEVICE *sas_device_priv_data;
2979 struct scsi_device *sdev;
2980 struct _sas_device *sas_device;
2982 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
2986 shost_for_each_device(sdev, ioc->shost) {
2987 sas_device_priv_data = sdev->hostdata;
2988 if (!sas_device_priv_data)
2990 if (sas_device_priv_data->sas_target->handle != handle)
2992 if (sas_device_priv_data->block)
2994 if (sas_device->pend_sas_rphy_add)
2996 if (sas_device_priv_data->ignore_delay_remove) {
2997 sdev_printk(KERN_INFO, sdev,
2998 "%s skip device_block for SES handle(0x%04x)\n",
2999 __func__, sas_device_priv_data->sas_target->handle);
3002 _scsih_internal_device_block(sdev, sas_device_priv_data);
3005 sas_device_put(sas_device);
3009 * _scsih_block_io_to_children_attached_to_ex
3010 * @ioc: per adapter object
3011 * @sas_expander: the sas_device object
3013 * This routine set sdev state to SDEV_BLOCK for all devices
3014 * attached to this expander. This function called when expander is
3018 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER *ioc,
3019 struct _sas_node *sas_expander)
3021 struct _sas_port *mpt3sas_port;
3022 struct _sas_device *sas_device;
3023 struct _sas_node *expander_sibling;
3024 unsigned long flags;
3029 list_for_each_entry(mpt3sas_port,
3030 &sas_expander->sas_port_list, port_list) {
3031 if (mpt3sas_port->remote_identify.device_type ==
3033 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3034 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
3035 mpt3sas_port->remote_identify.sas_address);
3037 set_bit(sas_device->handle,
3038 ioc->blocking_handles);
3039 sas_device_put(sas_device);
3041 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3045 list_for_each_entry(mpt3sas_port,
3046 &sas_expander->sas_port_list, port_list) {
3048 if (mpt3sas_port->remote_identify.device_type ==
3049 SAS_EDGE_EXPANDER_DEVICE ||
3050 mpt3sas_port->remote_identify.device_type ==
3051 SAS_FANOUT_EXPANDER_DEVICE) {
3053 mpt3sas_scsih_expander_find_by_sas_address(
3054 ioc, mpt3sas_port->remote_identify.sas_address);
3055 _scsih_block_io_to_children_attached_to_ex(ioc,
3062 * _scsih_block_io_to_children_attached_directly
3063 * @ioc: per adapter object
3064 * @event_data: topology change event data
3066 * This routine set sdev state to SDEV_BLOCK for all devices
3067 * direct attached during device pull.
3070 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER *ioc,
3071 Mpi2EventDataSasTopologyChangeList_t *event_data)
3077 for (i = 0; i < event_data->NumEntries; i++) {
3078 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3081 reason_code = event_data->PHY[i].PhyStatus &
3082 MPI2_EVENT_SAS_TOPO_RC_MASK;
3083 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3084 _scsih_block_io_device(ioc, handle);
3089 * _scsih_tm_tr_send - send task management request
3090 * @ioc: per adapter object
3091 * @handle: device handle
3092 * Context: interrupt time.
3094 * This code is to initiate the device removal handshake protocol
3095 * with controller firmware. This function will issue target reset
3096 * using high priority request queue. It will send a sas iounit
3097 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3099 * This is designed to send muliple task management request at the same
3100 * time to the fifo. If the fifo is full, we will append the request,
3101 * and process it in a future completion.
3104 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3106 Mpi2SCSITaskManagementRequest_t *mpi_request;
3108 struct _sas_device *sas_device = NULL;
3109 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
3110 u64 sas_address = 0;
3111 unsigned long flags;
3112 struct _tr_list *delayed_tr;
3115 if (ioc->remove_host) {
3116 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3117 "%s: host has been removed: handle(0x%04x)\n",
3118 __func__, ioc->name, handle));
3120 } else if (ioc->pci_error_recovery) {
3121 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3122 "%s: host in pci error recovery: handle(0x%04x)\n",
3123 __func__, ioc->name,
3127 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3128 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3129 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3130 "%s: host is not operational: handle(0x%04x)\n",
3131 __func__, ioc->name,
3136 /* if PD, then return */
3137 if (test_bit(handle, ioc->pd_handles))
3140 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3141 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
3142 if (sas_device && sas_device->starget &&
3143 sas_device->starget->hostdata) {
3144 sas_target_priv_data = sas_device->starget->hostdata;
3145 sas_target_priv_data->deleted = 1;
3146 sas_address = sas_device->sas_address;
3148 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3150 if (sas_target_priv_data) {
3151 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3152 "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3154 (unsigned long long)sas_address));
3155 if (sas_device->enclosure_handle != 0)
3156 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3157 "setting delete flag:enclosure logical id(0x%016llx),"
3158 " slot(%d)\n", ioc->name, (unsigned long long)
3159 sas_device->enclosure_logical_id,
3161 if (sas_device->connector_name[0] != '\0')
3162 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3163 "setting delete flag: enclosure level(0x%04x),"
3164 " connector name( %s)\n", ioc->name,
3165 sas_device->enclosure_level,
3166 sas_device->connector_name));
3167 _scsih_ublock_io_device(ioc, sas_address);
3168 sas_target_priv_data->handle = MPT3SAS_INVALID_DEVICE_HANDLE;
3171 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3173 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3176 INIT_LIST_HEAD(&delayed_tr->list);
3177 delayed_tr->handle = handle;
3178 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3179 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3180 "DELAYED:tr:handle(0x%04x), (open)\n",
3181 ioc->name, handle));
3185 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3186 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3187 ioc->name, handle, smid,
3188 ioc->tm_tr_cb_idx));
3189 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3190 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3191 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3192 mpi_request->DevHandle = cpu_to_le16(handle);
3193 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3194 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3195 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_DEVICE_REMOVAL);
3199 sas_device_put(sas_device);
3203 * _scsih_tm_tr_complete -
3204 * @ioc: per adapter object
3205 * @smid: system request message index
3206 * @msix_index: MSIX table index supplied by the OS
3207 * @reply: reply message frame(lower 32bit addr)
3208 * Context: interrupt time.
3210 * This is the target reset completion routine.
3211 * This code is part of the code to initiate the device removal
3212 * handshake protocol with controller firmware.
3213 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3215 * Return 1 meaning mf should be freed from _base_interrupt
3216 * 0 means the mf is freed from this function.
3219 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3223 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3224 Mpi2SCSITaskManagementReply_t *mpi_reply =
3225 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3226 Mpi2SasIoUnitControlRequest_t *mpi_request;
3229 struct _sc_list *delayed_sc;
3231 if (ioc->remove_host) {
3232 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3233 "%s: host has been removed\n", __func__, ioc->name));
3235 } else if (ioc->pci_error_recovery) {
3236 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3237 "%s: host in pci error recovery\n", __func__,
3241 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3242 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3243 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3244 "%s: host is not operational\n", __func__, ioc->name));
3247 if (unlikely(!mpi_reply)) {
3248 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3249 ioc->name, __FILE__, __LINE__, __func__);
3252 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3253 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3254 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3255 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3256 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3258 le16_to_cpu(mpi_reply->DevHandle), smid));
3262 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
3263 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3264 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3265 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3266 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3267 le32_to_cpu(mpi_reply->IOCLogInfo),
3268 le32_to_cpu(mpi_reply->TerminationCount)));
3270 smid_sas_ctrl = mpt3sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3271 if (!smid_sas_ctrl) {
3272 delayed_sc = kzalloc(sizeof(*delayed_sc), GFP_ATOMIC);
3274 return _scsih_check_for_pending_tm(ioc, smid);
3275 INIT_LIST_HEAD(&delayed_sc->list);
3276 delayed_sc->handle = mpi_request_tm->DevHandle;
3277 list_add_tail(&delayed_sc->list, &ioc->delayed_sc_list);
3278 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3279 "DELAYED:sc:handle(0x%04x), (open)\n",
3280 ioc->name, handle));
3281 return _scsih_check_for_pending_tm(ioc, smid);
3284 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3285 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3286 ioc->name, handle, smid_sas_ctrl,
3287 ioc->tm_sas_control_cb_idx));
3288 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3289 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3290 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3291 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3292 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3293 mpt3sas_base_put_smid_default(ioc, smid_sas_ctrl);
3295 return _scsih_check_for_pending_tm(ioc, smid);
3300 * _scsih_sas_control_complete - completion routine
3301 * @ioc: per adapter object
3302 * @smid: system request message index
3303 * @msix_index: MSIX table index supplied by the OS
3304 * @reply: reply message frame(lower 32bit addr)
3305 * Context: interrupt time.
3307 * This is the sas iounit control completion routine.
3308 * This code is part of the code to initiate the device removal
3309 * handshake protocol with controller firmware.
3311 * Return 1 meaning mf should be freed from _base_interrupt
3312 * 0 means the mf is freed from this function.
3315 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3316 u8 msix_index, u32 reply)
3318 Mpi2SasIoUnitControlReply_t *mpi_reply =
3319 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3321 if (likely(mpi_reply)) {
3322 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3323 "sc_complete:handle(0x%04x), (open) "
3324 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3325 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3326 le16_to_cpu(mpi_reply->IOCStatus),
3327 le32_to_cpu(mpi_reply->IOCLogInfo)));
3329 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3330 ioc->name, __FILE__, __LINE__, __func__);
3332 return mpt3sas_check_for_pending_internal_cmds(ioc, smid);
3336 * _scsih_tm_tr_volume_send - send target reset request for volumes
3337 * @ioc: per adapter object
3338 * @handle: device handle
3339 * Context: interrupt time.
3341 * This is designed to send muliple task management request at the same
3342 * time to the fifo. If the fifo is full, we will append the request,
3343 * and process it in a future completion.
3346 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3348 Mpi2SCSITaskManagementRequest_t *mpi_request;
3350 struct _tr_list *delayed_tr;
3352 if (ioc->shost_recovery || ioc->remove_host ||
3353 ioc->pci_error_recovery) {
3354 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3355 "%s: host reset in progress!\n",
3356 __func__, ioc->name));
3360 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3362 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3365 INIT_LIST_HEAD(&delayed_tr->list);
3366 delayed_tr->handle = handle;
3367 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3368 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3369 "DELAYED:tr:handle(0x%04x), (open)\n",
3370 ioc->name, handle));
3374 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3375 "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3376 ioc->name, handle, smid,
3377 ioc->tm_tr_volume_cb_idx));
3378 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3379 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3380 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3381 mpi_request->DevHandle = cpu_to_le16(handle);
3382 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3383 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
3387 * _scsih_tm_volume_tr_complete - target reset completion
3388 * @ioc: per adapter object
3389 * @smid: system request message index
3390 * @msix_index: MSIX table index supplied by the OS
3391 * @reply: reply message frame(lower 32bit addr)
3392 * Context: interrupt time.
3394 * Return 1 meaning mf should be freed from _base_interrupt
3395 * 0 means the mf is freed from this function.
3398 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid,
3399 u8 msix_index, u32 reply)
3402 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3403 Mpi2SCSITaskManagementReply_t *mpi_reply =
3404 mpt3sas_base_get_reply_virt_addr(ioc, reply);
3406 if (ioc->shost_recovery || ioc->remove_host ||
3407 ioc->pci_error_recovery) {
3408 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3409 "%s: host reset in progress!\n",
3410 __func__, ioc->name));
3413 if (unlikely(!mpi_reply)) {
3414 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3415 ioc->name, __FILE__, __LINE__, __func__);
3419 mpi_request_tm = mpt3sas_base_get_msg_frame(ioc, smid);
3420 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3421 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3422 dewtprintk(ioc, pr_err(MPT3SAS_FMT
3423 "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3425 le16_to_cpu(mpi_reply->DevHandle), smid));
3429 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3430 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3431 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3432 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3433 le32_to_cpu(mpi_reply->IOCLogInfo),
3434 le32_to_cpu(mpi_reply->TerminationCount)));
3436 return _scsih_check_for_pending_tm(ioc, smid);
3440 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3441 * @ioc: per adapter object
3442 * @smid: system request message index
3444 * @event_context: used to track events uniquely
3446 * Context - processed in interrupt context.
3449 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 event,
3452 Mpi2EventAckRequest_t *ack_request;
3453 int i = smid - ioc->internal_smid;
3454 unsigned long flags;
3456 /* Without releasing the smid just update the
3457 * call back index and reuse the same smid for
3458 * processing this delayed request
3460 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3461 ioc->internal_lookup[i].cb_idx = ioc->base_cb_idx;
3462 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3464 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3465 "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
3466 ioc->name, le16_to_cpu(event), smid,
3468 ack_request = mpt3sas_base_get_msg_frame(ioc, smid);
3469 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
3470 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
3471 ack_request->Event = event;
3472 ack_request->EventContext = event_context;
3473 ack_request->VF_ID = 0; /* TODO */
3474 ack_request->VP_ID = 0;
3475 mpt3sas_base_put_smid_default(ioc, smid);
3479 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
3480 * sas_io_unit_ctrl messages
3481 * @ioc: per adapter object
3482 * @smid: system request message index
3483 * @handle: device handle
3485 * Context - processed in interrupt context.
3488 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER *ioc,
3489 u16 smid, u16 handle)
3491 Mpi2SasIoUnitControlRequest_t *mpi_request;
3493 int i = smid - ioc->internal_smid;
3494 unsigned long flags;
3496 if (ioc->remove_host) {
3497 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3498 "%s: host has been removed\n",
3499 __func__, ioc->name));
3501 } else if (ioc->pci_error_recovery) {
3502 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3503 "%s: host in pci error recovery\n",
3504 __func__, ioc->name));
3507 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
3508 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3509 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3510 "%s: host is not operational\n",
3511 __func__, ioc->name));
3515 /* Without releasing the smid just update the
3516 * call back index and reuse the same smid for
3517 * processing this delayed request
3519 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3520 ioc->internal_lookup[i].cb_idx = ioc->tm_sas_control_cb_idx;
3521 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
3523 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3524 "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3525 ioc->name, le16_to_cpu(handle), smid,
3526 ioc->tm_sas_control_cb_idx));
3527 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
3528 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3529 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3530 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3531 mpi_request->DevHandle = handle;
3532 mpt3sas_base_put_smid_default(ioc, smid);
3536 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
3537 * @ioc: per adapter object
3538 * @smid: system request message index
3540 * Context: Executed in interrupt context
3542 * This will check delayed internal messages list, and process the
3545 * Return 1 meaning mf should be freed from _base_interrupt
3546 * 0 means the mf is freed from this function.
3549 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3551 struct _sc_list *delayed_sc;
3552 struct _event_ack_list *delayed_event_ack;
3554 if (!list_empty(&ioc->delayed_event_ack_list)) {
3555 delayed_event_ack = list_entry(ioc->delayed_event_ack_list.next,
3556 struct _event_ack_list, list);
3557 _scsih_issue_delayed_event_ack(ioc, smid,
3558 delayed_event_ack->Event, delayed_event_ack->EventContext);
3559 list_del(&delayed_event_ack->list);
3560 kfree(delayed_event_ack);
3564 if (!list_empty(&ioc->delayed_sc_list)) {
3565 delayed_sc = list_entry(ioc->delayed_sc_list.next,
3566 struct _sc_list, list);
3567 _scsih_issue_delayed_sas_io_unit_ctrl(ioc, smid,
3568 delayed_sc->handle);
3569 list_del(&delayed_sc->list);
3577 * _scsih_check_for_pending_tm - check for pending task management
3578 * @ioc: per adapter object
3579 * @smid: system request message index
3581 * This will check delayed target reset list, and feed the
3584 * Return 1 meaning mf should be freed from _base_interrupt
3585 * 0 means the mf is freed from this function.
3588 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER *ioc, u16 smid)
3590 struct _tr_list *delayed_tr;
3592 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3593 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3594 struct _tr_list, list);
3595 mpt3sas_base_free_smid(ioc, smid);
3596 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3597 list_del(&delayed_tr->list);
3602 if (!list_empty(&ioc->delayed_tr_list)) {
3603 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3604 struct _tr_list, list);
3605 mpt3sas_base_free_smid(ioc, smid);
3606 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3607 list_del(&delayed_tr->list);
3616 * _scsih_check_topo_delete_events - sanity check on topo events
3617 * @ioc: per adapter object
3618 * @event_data: the event data payload
3620 * This routine added to better handle cable breaker.
3622 * This handles the case where driver receives multiple expander
3623 * add and delete events in a single shot. When there is a delete event
3624 * the routine will void any pending add events waiting in the event queue.
3629 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER *ioc,
3630 Mpi2EventDataSasTopologyChangeList_t *event_data)
3632 struct fw_event_work *fw_event;
3633 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3634 u16 expander_handle;
3635 struct _sas_node *sas_expander;
3636 unsigned long flags;
3640 for (i = 0 ; i < event_data->NumEntries; i++) {
3641 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3644 reason_code = event_data->PHY[i].PhyStatus &
3645 MPI2_EVENT_SAS_TOPO_RC_MASK;
3646 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3647 _scsih_tm_tr_send(ioc, handle);
3650 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3651 if (expander_handle < ioc->sas_hba.num_phys) {
3652 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3655 if (event_data->ExpStatus ==
3656 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3657 /* put expander attached devices into blocking state */
3658 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3659 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
3661 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3662 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3664 handle = find_first_bit(ioc->blocking_handles,
3665 ioc->facts.MaxDevHandle);
3666 if (handle < ioc->facts.MaxDevHandle)
3667 _scsih_block_io_device(ioc, handle);
3668 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3669 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3670 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3672 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3675 /* mark ignore flag for pending events */
3676 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3677 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3678 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3681 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3682 fw_event->event_data;
3683 if (local_event_data->ExpStatus ==
3684 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3685 local_event_data->ExpStatus ==
3686 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3687 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3689 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3690 "setting ignoring flag\n", ioc->name));
3691 fw_event->ignore = 1;
3695 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3699 * _scsih_set_volume_delete_flag - setting volume delete flag
3700 * @ioc: per adapter object
3701 * @handle: device handle
3703 * This returns nothing.
3706 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER *ioc, u16 handle)
3708 struct _raid_device *raid_device;
3709 struct MPT3SAS_TARGET *sas_target_priv_data;
3710 unsigned long flags;
3712 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3713 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
3714 if (raid_device && raid_device->starget &&
3715 raid_device->starget->hostdata) {
3716 sas_target_priv_data =
3717 raid_device->starget->hostdata;
3718 sas_target_priv_data->deleted = 1;
3719 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3720 "setting delete flag: handle(0x%04x), "
3721 "wwid(0x%016llx)\n", ioc->name, handle,
3722 (unsigned long long) raid_device->wwid));
3724 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3728 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3729 * @handle: input handle
3730 * @a: handle for volume a
3731 * @b: handle for volume b
3733 * IR firmware only supports two raid volumes. The purpose of this
3734 * routine is to set the volume handle in either a or b. When the given
3735 * input handle is non-zero, or when a and b have not been set before.
3738 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3740 if (!handle || handle == *a || handle == *b)
3749 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3750 * @ioc: per adapter object
3751 * @event_data: the event data payload
3752 * Context: interrupt time.
3754 * This routine will send target reset to volume, followed by target
3755 * resets to the PDs. This is called when a PD has been removed, or
3756 * volume has been deleted or removed. When the target reset is sent
3757 * to volume, the PD target resets need to be queued to start upon
3758 * completion of the volume target reset.
3763 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER *ioc,
3764 Mpi2EventDataIrConfigChangeList_t *event_data)
3766 Mpi2EventIrConfigElement_t *element;
3768 u16 handle, volume_handle, a, b;
3769 struct _tr_list *delayed_tr;
3774 if (ioc->is_warpdrive)
3777 /* Volume Resets for Deleted or Removed */
3778 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3779 for (i = 0; i < event_data->NumElements; i++, element++) {
3780 if (le32_to_cpu(event_data->Flags) &
3781 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3783 if (element->ReasonCode ==
3784 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3785 element->ReasonCode ==
3786 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3787 volume_handle = le16_to_cpu(element->VolDevHandle);
3788 _scsih_set_volume_delete_flag(ioc, volume_handle);
3789 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3793 /* Volume Resets for UNHIDE events */
3794 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3795 for (i = 0; i < event_data->NumElements; i++, element++) {
3796 if (le32_to_cpu(event_data->Flags) &
3797 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3799 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3800 volume_handle = le16_to_cpu(element->VolDevHandle);
3801 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3806 _scsih_tm_tr_volume_send(ioc, a);
3808 _scsih_tm_tr_volume_send(ioc, b);
3810 /* PD target resets */
3811 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3812 for (i = 0; i < event_data->NumElements; i++, element++) {
3813 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3815 handle = le16_to_cpu(element->PhysDiskDevHandle);
3816 volume_handle = le16_to_cpu(element->VolDevHandle);
3817 clear_bit(handle, ioc->pd_handles);
3819 _scsih_tm_tr_send(ioc, handle);
3820 else if (volume_handle == a || volume_handle == b) {
3821 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3822 BUG_ON(!delayed_tr);
3823 INIT_LIST_HEAD(&delayed_tr->list);
3824 delayed_tr->handle = handle;
3825 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3826 dewtprintk(ioc, pr_info(MPT3SAS_FMT
3827 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3830 _scsih_tm_tr_send(ioc, handle);
3836 * _scsih_check_volume_delete_events - set delete flag for volumes
3837 * @ioc: per adapter object
3838 * @event_data: the event data payload
3839 * Context: interrupt time.
3841 * This will handle the case when the cable connected to entire volume is
3842 * pulled. We will take care of setting the deleted flag so normal IO will
3848 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER *ioc,
3849 Mpi2EventDataIrVolume_t *event_data)
3853 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3855 state = le32_to_cpu(event_data->NewValue);
3856 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3857 MPI2_RAID_VOL_STATE_FAILED)
3858 _scsih_set_volume_delete_flag(ioc,
3859 le16_to_cpu(event_data->VolDevHandle));
3863 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3864 * @ioc: per adapter object
3865 * @event_data: the temp threshold event data
3866 * Context: interrupt time.
3871 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3872 Mpi2EventDataTemperature_t *event_data)
3874 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3875 pr_err(MPT3SAS_FMT "Temperature Threshold flags %s%s%s%s"
3876 " exceeded for Sensor: %d !!!\n", ioc->name,
3877 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3878 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3879 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3880 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3881 event_data->SensorNum);
3882 pr_err(MPT3SAS_FMT "Current Temp In Celsius: %d\n",
3883 ioc->name, event_data->CurrentTemperature);
3888 * _scsih_flush_running_cmds - completing outstanding commands.
3889 * @ioc: per adapter object
3891 * The flushing out of all pending scmd commands following host reset,
3892 * where all IO is dropped to the floor.
3897 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3899 struct scsi_cmnd *scmd;
3903 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3904 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3908 mpt3sas_base_free_smid(ioc, smid);
3909 scsi_dma_unmap(scmd);
3910 if (ioc->pci_error_recovery)
3911 scmd->result = DID_NO_CONNECT << 16;
3913 scmd->result = DID_RESET << 16;
3914 scmd->scsi_done(scmd);
3916 dtmprintk(ioc, pr_info(MPT3SAS_FMT "completing %d cmds\n",
3921 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3922 * @ioc: per adapter object
3923 * @scmd: pointer to scsi command object
3924 * @mpi_request: pointer to the SCSI_IO reqest message frame
3926 * Supporting protection 1 and 3.
3931 _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3932 Mpi2SCSIIORequest_t *mpi_request)
3935 unsigned char prot_op = scsi_get_prot_op(scmd);
3936 unsigned char prot_type = scsi_get_prot_type(scmd);
3937 Mpi25SCSIIORequest_t *mpi_request_3v =
3938 (Mpi25SCSIIORequest_t *)mpi_request;
3940 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3943 if (prot_op == SCSI_PROT_READ_STRIP)
3944 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3945 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3946 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3950 switch (prot_type) {
3951 case SCSI_PROT_DIF_TYPE1:
3952 case SCSI_PROT_DIF_TYPE2:
3955 * enable ref/guard checking
3956 * auto increment ref tag
3958 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3959 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3960 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3961 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3962 cpu_to_be32(scsi_get_lba(scmd));
3965 case SCSI_PROT_DIF_TYPE3:
3968 * enable guard checking
3970 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3975 mpi_request_3v->EEDPBlockSize =
3976 cpu_to_le16(scmd->device->sector_size);
3977 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3981 * _scsih_eedp_error_handling - return sense code for EEDP errors
3982 * @scmd: pointer to scsi command object
3983 * @ioc_status: ioc status
3988 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3992 switch (ioc_status) {
3993 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3996 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3999 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4006 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
4008 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
4009 SAM_STAT_CHECK_CONDITION;
4015 * scsih_qcmd - main scsi request entry point
4016 * @scmd: pointer to scsi command object
4017 * @done: function pointer to be invoked on completion
4019 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4021 * Returns 0 on success. If there's a failure, return either:
4022 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4023 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4026 scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4028 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
4029 struct MPT3SAS_DEVICE *sas_device_priv_data;
4030 struct MPT3SAS_TARGET *sas_target_priv_data;
4031 struct _raid_device *raid_device;
4032 Mpi2SCSIIORequest_t *mpi_request;
4037 if (ioc->logging_level & MPT_DEBUG_SCSI)
4038 scsi_print_command(scmd);
4040 sas_device_priv_data = scmd->device->hostdata;
4041 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4042 scmd->result = DID_NO_CONNECT << 16;
4043 scmd->scsi_done(scmd);
4047 if (ioc->pci_error_recovery || ioc->remove_host) {
4048 scmd->result = DID_NO_CONNECT << 16;
4049 scmd->scsi_done(scmd);
4053 sas_target_priv_data = sas_device_priv_data->sas_target;
4055 /* invalid device handle */
4056 handle = sas_target_priv_data->handle;
4057 if (handle == MPT3SAS_INVALID_DEVICE_HANDLE) {
4058 scmd->result = DID_NO_CONNECT << 16;
4059 scmd->scsi_done(scmd);
4064 /* host recovery or link resets sent via IOCTLs */
4065 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4066 return SCSI_MLQUEUE_HOST_BUSY;
4068 /* device has been deleted */
4069 else if (sas_target_priv_data->deleted) {
4070 scmd->result = DID_NO_CONNECT << 16;
4071 scmd->scsi_done(scmd);
4073 /* device busy with task managment */
4074 } else if (sas_target_priv_data->tm_busy ||
4075 sas_device_priv_data->block)
4076 return SCSI_MLQUEUE_DEVICE_BUSY;
4078 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4079 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4080 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4081 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4083 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4086 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4088 /* Make sure Device is not raid volume.
4089 * We do not expose raid functionality to upper layer for warpdrive.
4091 if (!ioc->is_warpdrive && !scsih_is_raid(&scmd->device->sdev_gendev)
4092 && sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4093 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4095 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4097 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
4098 ioc->name, __func__);
4101 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4102 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4103 _scsih_setup_eedp(ioc, scmd, mpi_request);
4105 if (scmd->cmd_len == 32)
4106 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4107 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4108 if (sas_device_priv_data->sas_target->flags &
4109 MPT_TARGET_FLAGS_RAID_COMPONENT)
4110 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4112 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4113 mpi_request->DevHandle = cpu_to_le16(handle);
4114 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4115 mpi_request->Control = cpu_to_le32(mpi_control);
4116 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4117 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4118 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4119 mpi_request->SenseBufferLowAddress =
4120 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
4121 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4122 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4124 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4126 if (mpi_request->DataLength) {
4127 if (ioc->build_sg_scmd(ioc, scmd, smid)) {
4128 mpt3sas_base_free_smid(ioc, smid);
4132 ioc->build_zero_len_sge(ioc, &mpi_request->SGL);
4134 raid_device = sas_target_priv_data->raid_device;
4135 if (raid_device && raid_device->direct_io_enabled)
4136 mpt3sas_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4139 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)) {
4140 if (sas_target_priv_data->flags & MPT_TARGET_FASTPATH_IO) {
4141 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len |
4142 MPI25_SCSIIO_IOFLAGS_FAST_PATH);
4143 mpt3sas_base_put_smid_fast_path(ioc, smid, handle);
4145 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4146 le16_to_cpu(mpi_request->DevHandle));
4148 mpt3sas_base_put_smid_default(ioc, smid);
4152 return SCSI_MLQUEUE_HOST_BUSY;
4156 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4157 * @sense_buffer: sense data returned by target
4158 * @data: normalized skey/asc/ascq
4163 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4165 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4166 /* descriptor format */
4167 data->skey = sense_buffer[1] & 0x0F;
4168 data->asc = sense_buffer[2];
4169 data->ascq = sense_buffer[3];
4172 data->skey = sense_buffer[2] & 0x0F;
4173 data->asc = sense_buffer[12];
4174 data->ascq = sense_buffer[13];
4179 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4180 * @ioc: per adapter object
4181 * @scmd: pointer to scsi command object
4182 * @mpi_reply: reply mf payload returned from firmware
4184 * scsi_status - SCSI Status code returned from target device
4185 * scsi_state - state info associated with SCSI_IO determined by ioc
4186 * ioc_status - ioc supplied status info
4191 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4192 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4196 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4197 MPI2_IOCSTATUS_MASK;
4198 u8 scsi_state = mpi_reply->SCSIState;
4199 u8 scsi_status = mpi_reply->SCSIStatus;
4200 char *desc_ioc_state = NULL;
4201 char *desc_scsi_status = NULL;
4202 char *desc_scsi_state = ioc->tmp_string;
4203 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4204 struct _sas_device *sas_device = NULL;
4205 struct scsi_target *starget = scmd->device->sdev_target;
4206 struct MPT3SAS_TARGET *priv_target = starget->hostdata;
4207 char *device_str = NULL;
4211 if (ioc->hide_ir_msg)
4212 device_str = "WarpDrive";
4214 device_str = "volume";
4216 if (log_info == 0x31170000)
4219 switch (ioc_status) {
4220 case MPI2_IOCSTATUS_SUCCESS:
4221 desc_ioc_state = "success";
4223 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4224 desc_ioc_state = "invalid function";
4226 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4227 desc_ioc_state = "scsi recovered error";
4229 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4230 desc_ioc_state = "scsi invalid dev handle";
4232 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4233 desc_ioc_state = "scsi device not there";
4235 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4236 desc_ioc_state = "scsi data overrun";
4238 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4239 desc_ioc_state = "scsi data underrun";
4241 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4242 desc_ioc_state = "scsi io data error";
4244 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4245 desc_ioc_state = "scsi protocol error";
4247 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4248 desc_ioc_state = "scsi task terminated";
4250 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4251 desc_ioc_state = "scsi residual mismatch";
4253 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4254 desc_ioc_state = "scsi task mgmt failed";
4256 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4257 desc_ioc_state = "scsi ioc terminated";
4259 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4260 desc_ioc_state = "scsi ext terminated";
4262 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4263 desc_ioc_state = "eedp guard error";
4265 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4266 desc_ioc_state = "eedp ref tag error";
4268 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4269 desc_ioc_state = "eedp app tag error";
4271 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4272 desc_ioc_state = "insufficient power";
4275 desc_ioc_state = "unknown";
4279 switch (scsi_status) {
4280 case MPI2_SCSI_STATUS_GOOD:
4281 desc_scsi_status = "good";
4283 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4284 desc_scsi_status = "check condition";
4286 case MPI2_SCSI_STATUS_CONDITION_MET:
4287 desc_scsi_status = "condition met";
4289 case MPI2_SCSI_STATUS_BUSY:
4290 desc_scsi_status = "busy";
4292 case MPI2_SCSI_STATUS_INTERMEDIATE:
4293 desc_scsi_status = "intermediate";
4295 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4296 desc_scsi_status = "intermediate condmet";
4298 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4299 desc_scsi_status = "reservation conflict";
4301 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4302 desc_scsi_status = "command terminated";
4304 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4305 desc_scsi_status = "task set full";
4307 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4308 desc_scsi_status = "aca active";
4310 case MPI2_SCSI_STATUS_TASK_ABORTED:
4311 desc_scsi_status = "task aborted";
4314 desc_scsi_status = "unknown";
4318 desc_scsi_state[0] = '\0';
4320 desc_scsi_state = " ";
4321 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4322 strcat(desc_scsi_state, "response info ");
4323 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4324 strcat(desc_scsi_state, "state terminated ");
4325 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4326 strcat(desc_scsi_state, "no status ");
4327 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4328 strcat(desc_scsi_state, "autosense failed ");
4329 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4330 strcat(desc_scsi_state, "autosense valid ");
4332 scsi_print_command(scmd);
4334 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4335 pr_warn(MPT3SAS_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4336 device_str, (unsigned long long)priv_target->sas_address);
4338 sas_device = mpt3sas_get_sdev_from_target(ioc, priv_target);
4341 "\tsas_address(0x%016llx), phy(%d)\n",
4342 ioc->name, (unsigned long long)
4343 sas_device->sas_address, sas_device->phy);
4344 if (sas_device->enclosure_handle != 0)
4346 "\tenclosure_logical_id(0x%016llx),"
4347 "slot(%d)\n", ioc->name,
4348 (unsigned long long)
4349 sas_device->enclosure_logical_id,
4351 if (sas_device->connector_name[0])
4353 "\tenclosure level(0x%04x),"
4354 " connector name( %s)\n", ioc->name,
4355 sas_device->enclosure_level,
4356 sas_device->connector_name);
4358 sas_device_put(sas_device);
4363 "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4364 ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4365 desc_ioc_state, ioc_status, smid);
4367 "\trequest_len(%d), underflow(%d), resid(%d)\n",
4368 ioc->name, scsi_bufflen(scmd), scmd->underflow,
4369 scsi_get_resid(scmd));
4371 "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
4372 ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4373 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4375 "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
4376 ioc->name, desc_scsi_status,
4377 scsi_status, desc_scsi_state, scsi_state);
4379 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4380 struct sense_info data;
4381 _scsih_normalize_sense(scmd->sense_buffer, &data);
4383 "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
4384 ioc->name, data.skey,
4385 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4388 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4389 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4390 response_bytes = (u8 *)&response_info;
4391 _scsih_response_code(ioc, response_bytes[0]);
4396 * _scsih_turn_on_pfa_led - illuminate PFA LED
4397 * @ioc: per adapter object
4398 * @handle: device handle
4404 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4406 Mpi2SepReply_t mpi_reply;
4407 Mpi2SepRequest_t mpi_request;
4408 struct _sas_device *sas_device;
4410 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
4414 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4415 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4416 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4417 mpi_request.SlotStatus =
4418 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4419 mpi_request.DevHandle = cpu_to_le16(handle);
4420 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4421 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4422 &mpi_request)) != 0) {
4423 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4424 __FILE__, __LINE__, __func__);
4427 sas_device->pfa_led_on = 1;
4429 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4430 dewtprintk(ioc, pr_info(MPT3SAS_FMT
4431 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4432 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4433 le32_to_cpu(mpi_reply.IOCLogInfo)));
4437 sas_device_put(sas_device);
4441 * _scsih_turn_off_pfa_led - turn off Fault LED
4442 * @ioc: per adapter object
4443 * @sas_device: sas device whose PFA LED has to turned off
4449 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER *ioc,
4450 struct _sas_device *sas_device)
4452 Mpi2SepReply_t mpi_reply;
4453 Mpi2SepRequest_t mpi_request;
4455 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4456 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4457 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4458 mpi_request.SlotStatus = 0;
4459 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4460 mpi_request.DevHandle = 0;
4461 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4462 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4463 if ((mpt3sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4464 &mpi_request)) != 0) {
4465 printk(MPT3SAS_FMT "failure at %s:%d/%s()!\n", ioc->name,
4466 __FILE__, __LINE__, __func__);
4470 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4471 dewtprintk(ioc, printk(MPT3SAS_FMT
4472 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4473 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4474 le32_to_cpu(mpi_reply.IOCLogInfo)));
4480 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4481 * @ioc: per adapter object
4482 * @handle: device handle
4483 * Context: interrupt.
4488 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4490 struct fw_event_work *fw_event;
4492 fw_event = alloc_fw_event_work(0);
4495 fw_event->event = MPT3SAS_TURN_ON_PFA_LED;
4496 fw_event->device_handle = handle;
4497 fw_event->ioc = ioc;
4498 _scsih_fw_event_add(ioc, fw_event);
4499 fw_event_work_put(fw_event);
4503 * _scsih_smart_predicted_fault - process smart errors
4504 * @ioc: per adapter object
4505 * @handle: device handle
4506 * Context: interrupt.
4511 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER *ioc, u16 handle)
4513 struct scsi_target *starget;
4514 struct MPT3SAS_TARGET *sas_target_priv_data;
4515 Mpi2EventNotificationReply_t *event_reply;
4516 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4517 struct _sas_device *sas_device;
4519 unsigned long flags;
4521 /* only handle non-raid devices */
4522 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4523 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
4527 starget = sas_device->starget;
4528 sas_target_priv_data = starget->hostdata;
4530 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4531 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4534 if (sas_device->enclosure_handle != 0)
4535 starget_printk(KERN_INFO, starget, "predicted fault, "
4536 "enclosure logical id(0x%016llx), slot(%d)\n",
4537 (unsigned long long)sas_device->enclosure_logical_id,
4539 if (sas_device->connector_name[0] != '\0')
4540 starget_printk(KERN_WARNING, starget, "predicted fault, "
4541 "enclosure level(0x%04x), connector name( %s)\n",
4542 sas_device->enclosure_level,
4543 sas_device->connector_name);
4544 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4546 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4547 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4549 /* insert into event log */
4550 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4551 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4552 event_reply = kzalloc(sz, GFP_KERNEL);
4554 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4555 ioc->name, __FILE__, __LINE__, __func__);
4559 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4560 event_reply->Event =
4561 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4562 event_reply->MsgLength = sz/4;
4563 event_reply->EventDataLength =
4564 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4565 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4566 event_reply->EventData;
4567 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4568 event_data->ASC = 0x5D;
4569 event_data->DevHandle = cpu_to_le16(handle);
4570 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4571 mpt3sas_ctl_add_to_event_log(ioc, event_reply);
4575 sas_device_put(sas_device);
4579 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4584 * _scsih_io_done - scsi request callback
4585 * @ioc: per adapter object
4586 * @smid: system request message index
4587 * @msix_index: MSIX table index supplied by the OS
4588 * @reply: reply message frame(lower 32bit addr)
4590 * Callback handler when using _scsih_qcmd.
4592 * Return 1 meaning mf should be freed from _base_interrupt
4593 * 0 means the mf is freed from this function.
4596 _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4598 Mpi2SCSIIORequest_t *mpi_request;
4599 Mpi2SCSIIOReply_t *mpi_reply;
4600 struct scsi_cmnd *scmd;
4606 struct MPT3SAS_DEVICE *sas_device_priv_data;
4607 u32 response_code = 0;
4608 unsigned long flags;
4610 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
4611 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4615 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4617 if (mpi_reply == NULL) {
4618 scmd->result = DID_OK << 16;
4622 sas_device_priv_data = scmd->device->hostdata;
4623 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4624 sas_device_priv_data->sas_target->deleted) {
4625 scmd->result = DID_NO_CONNECT << 16;
4628 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4631 * WARPDRIVE: If direct_io is set then it is directIO,
4632 * the failed direct I/O should be redirected to volume
4634 if (mpt3sas_scsi_direct_io_get(ioc, smid) &&
4635 ((ioc_status & MPI2_IOCSTATUS_MASK)
4636 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4637 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4638 ioc->scsi_lookup[smid - 1].scmd = scmd;
4639 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4640 mpt3sas_scsi_direct_io_set(ioc, smid, 0);
4641 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4642 mpi_request->DevHandle =
4643 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4644 mpt3sas_base_put_smid_scsi_io(ioc, smid,
4645 sas_device_priv_data->sas_target->handle);
4648 /* turning off TLR */
4649 scsi_state = mpi_reply->SCSIState;
4650 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4652 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4653 if (!sas_device_priv_data->tlr_snoop_check) {
4654 sas_device_priv_data->tlr_snoop_check++;
4655 if (!ioc->is_warpdrive &&
4656 !scsih_is_raid(&scmd->device->sdev_gendev) &&
4657 sas_is_tlr_enabled(scmd->device) &&
4658 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4659 sas_disable_tlr(scmd->device);
4660 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4664 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4665 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4666 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4667 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4670 ioc_status &= MPI2_IOCSTATUS_MASK;
4671 scsi_status = mpi_reply->SCSIStatus;
4673 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4674 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4675 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4676 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4677 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4680 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4681 struct sense_info data;
4682 const void *sense_data = mpt3sas_base_get_sense_buffer(ioc,
4684 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4685 le32_to_cpu(mpi_reply->SenseCount));
4686 memcpy(scmd->sense_buffer, sense_data, sz);
4687 _scsih_normalize_sense(scmd->sense_buffer, &data);
4688 /* failure prediction threshold exceeded */
4689 if (data.asc == 0x5D)
4690 _scsih_smart_predicted_fault(ioc,
4691 le16_to_cpu(mpi_reply->DevHandle));
4692 mpt3sas_trigger_scsi(ioc, data.skey, data.asc, data.ascq);
4694 if (!(ioc->logging_level & MPT_DEBUG_REPLY) &&
4695 ((scmd->sense_buffer[2] == UNIT_ATTENTION) ||
4696 (scmd->sense_buffer[2] == MEDIUM_ERROR) ||
4697 (scmd->sense_buffer[2] == HARDWARE_ERROR)))
4698 _scsih_scsi_ioc_info(ioc, scmd, mpi_reply, smid);
4700 switch (ioc_status) {
4701 case MPI2_IOCSTATUS_BUSY:
4702 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4703 scmd->result = SAM_STAT_BUSY;
4706 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4707 scmd->result = DID_NO_CONNECT << 16;
4710 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4711 if (sas_device_priv_data->block) {
4712 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4715 if (log_info == 0x31110630) {
4716 if (scmd->retries > 2) {
4717 scmd->result = DID_NO_CONNECT << 16;
4718 scsi_device_set_state(scmd->device,
4721 scmd->result = DID_SOFT_ERROR << 16;
4722 scmd->device->expecting_cc_ua = 1;
4725 } else if (log_info == VIRTUAL_IO_FAILED_RETRY) {
4726 scmd->result = DID_RESET << 16;
4729 scmd->result = DID_SOFT_ERROR << 16;
4731 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4732 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4733 scmd->result = DID_RESET << 16;
4736 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4737 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4738 scmd->result = DID_SOFT_ERROR << 16;
4740 scmd->result = (DID_OK << 16) | scsi_status;
4743 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4744 scmd->result = (DID_OK << 16) | scsi_status;
4746 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4749 if (xfer_cnt < scmd->underflow) {
4750 if (scsi_status == SAM_STAT_BUSY)
4751 scmd->result = SAM_STAT_BUSY;
4753 scmd->result = DID_SOFT_ERROR << 16;
4754 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4755 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4756 scmd->result = DID_SOFT_ERROR << 16;
4757 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4758 scmd->result = DID_RESET << 16;
4759 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4760 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4761 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4762 scmd->result = (DRIVER_SENSE << 24) |
4763 SAM_STAT_CHECK_CONDITION;
4764 scmd->sense_buffer[0] = 0x70;
4765 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4766 scmd->sense_buffer[12] = 0x20;
4767 scmd->sense_buffer[13] = 0;
4771 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4772 scsi_set_resid(scmd, 0);
4773 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4774 case MPI2_IOCSTATUS_SUCCESS:
4775 scmd->result = (DID_OK << 16) | scsi_status;
4776 if (response_code ==
4777 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4778 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4779 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4780 scmd->result = DID_SOFT_ERROR << 16;
4781 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4782 scmd->result = DID_RESET << 16;
4785 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4786 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4787 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4788 _scsih_eedp_error_handling(scmd, ioc_status);
4791 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4792 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4793 case MPI2_IOCSTATUS_INVALID_SGL:
4794 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4795 case MPI2_IOCSTATUS_INVALID_FIELD:
4796 case MPI2_IOCSTATUS_INVALID_STATE:
4797 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4798 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4799 case MPI2_IOCSTATUS_INSUFFICIENT_POWER:
4801 scmd->result = DID_SOFT_ERROR << 16;
4806 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4807 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4811 scsi_dma_unmap(scmd);
4813 scmd->scsi_done(scmd);
4818 * _scsih_sas_host_refresh - refreshing sas host object contents
4819 * @ioc: per adapter object
4822 * During port enable, fw will send topology events for every device. Its
4823 * possible that the handles may change from the previous setting, so this
4824 * code keeping handles updating if changed.
4829 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER *ioc)
4834 Mpi2ConfigReply_t mpi_reply;
4835 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4836 u16 attached_handle;
4839 dtmprintk(ioc, pr_info(MPT3SAS_FMT
4840 "updating handles for sas_host(0x%016llx)\n",
4841 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4843 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4844 * sizeof(Mpi2SasIOUnit0PhyData_t));
4845 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4846 if (!sas_iounit_pg0) {
4847 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4848 ioc->name, __FILE__, __LINE__, __func__);
4852 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4853 sas_iounit_pg0, sz)) != 0)
4855 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4856 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4858 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4859 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4861 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4862 PhyData[0].ControllerDevHandle);
4863 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4864 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4866 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4867 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4868 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4869 attached_handle, i, link_rate);
4872 kfree(sas_iounit_pg0);
4876 * _scsih_sas_host_add - create sas host object
4877 * @ioc: per adapter object
4879 * Creating host side data object, stored in ioc->sas_hba
4884 _scsih_sas_host_add(struct MPT3SAS_ADAPTER *ioc)
4887 Mpi2ConfigReply_t mpi_reply;
4888 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4889 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4890 Mpi2SasPhyPage0_t phy_pg0;
4891 Mpi2SasDevicePage0_t sas_device_pg0;
4892 Mpi2SasEnclosurePage0_t enclosure_pg0;
4895 u8 device_missing_delay;
4897 mpt3sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4898 if (!ioc->sas_hba.num_phys) {
4899 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4900 ioc->name, __FILE__, __LINE__, __func__);
4904 /* sas_iounit page 0 */
4905 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4906 sizeof(Mpi2SasIOUnit0PhyData_t));
4907 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4908 if (!sas_iounit_pg0) {
4909 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4910 ioc->name, __FILE__, __LINE__, __func__);
4913 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4914 sas_iounit_pg0, sz))) {
4915 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4916 ioc->name, __FILE__, __LINE__, __func__);
4919 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4920 MPI2_IOCSTATUS_MASK;
4921 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4922 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4923 ioc->name, __FILE__, __LINE__, __func__);
4927 /* sas_iounit page 1 */
4928 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4929 sizeof(Mpi2SasIOUnit1PhyData_t));
4930 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4931 if (!sas_iounit_pg1) {
4932 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4933 ioc->name, __FILE__, __LINE__, __func__);
4936 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4937 sas_iounit_pg1, sz))) {
4938 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4939 ioc->name, __FILE__, __LINE__, __func__);
4942 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4943 MPI2_IOCSTATUS_MASK;
4944 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4945 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4946 ioc->name, __FILE__, __LINE__, __func__);
4950 ioc->io_missing_delay =
4951 sas_iounit_pg1->IODeviceMissingDelay;
4952 device_missing_delay =
4953 sas_iounit_pg1->ReportDeviceMissingDelay;
4954 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4955 ioc->device_missing_delay = (device_missing_delay &
4956 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4958 ioc->device_missing_delay = device_missing_delay &
4959 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4961 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4962 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4963 sizeof(struct _sas_phy), GFP_KERNEL);
4964 if (!ioc->sas_hba.phy) {
4965 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4966 ioc->name, __FILE__, __LINE__, __func__);
4969 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4970 if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4972 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4973 ioc->name, __FILE__, __LINE__, __func__);
4976 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4977 MPI2_IOCSTATUS_MASK;
4978 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4979 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4980 ioc->name, __FILE__, __LINE__, __func__);
4985 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4986 PhyData[0].ControllerDevHandle);
4987 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4988 ioc->sas_hba.phy[i].phy_id = i;
4989 mpt3sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4990 phy_pg0, ioc->sas_hba.parent_dev);
4992 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4993 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4994 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
4995 ioc->name, __FILE__, __LINE__, __func__);
4998 ioc->sas_hba.enclosure_handle =
4999 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5000 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5002 "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5003 ioc->name, ioc->sas_hba.handle,
5004 (unsigned long long) ioc->sas_hba.sas_address,
5005 ioc->sas_hba.num_phys) ;
5007 if (ioc->sas_hba.enclosure_handle) {
5008 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5009 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5010 ioc->sas_hba.enclosure_handle)))
5011 ioc->sas_hba.enclosure_logical_id =
5012 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5016 kfree(sas_iounit_pg1);
5017 kfree(sas_iounit_pg0);
5021 * _scsih_expander_add - creating expander object
5022 * @ioc: per adapter object
5023 * @handle: expander handle
5025 * Creating expander object, stored in ioc->sas_expander_list.
5027 * Return 0 for success, else error.
5030 _scsih_expander_add(struct MPT3SAS_ADAPTER *ioc, u16 handle)
5032 struct _sas_node *sas_expander;
5033 Mpi2ConfigReply_t mpi_reply;
5034 Mpi2ExpanderPage0_t expander_pg0;
5035 Mpi2ExpanderPage1_t expander_pg1;
5036 Mpi2SasEnclosurePage0_t enclosure_pg0;
5039 u64 sas_address, sas_address_parent = 0;
5041 unsigned long flags;
5042 struct _sas_port *mpt3sas_port = NULL;
5049 if (ioc->shost_recovery || ioc->pci_error_recovery)
5052 if ((mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5053 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5054 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5055 ioc->name, __FILE__, __LINE__, __func__);
5059 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5060 MPI2_IOCSTATUS_MASK;
5061 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5062 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5063 ioc->name, __FILE__, __LINE__, __func__);
5067 /* handle out of order topology events */
5068 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5069 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5071 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5072 ioc->name, __FILE__, __LINE__, __func__);
5075 if (sas_address_parent != ioc->sas_hba.sas_address) {
5076 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5077 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5078 sas_address_parent);
5079 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5080 if (!sas_expander) {
5081 rc = _scsih_expander_add(ioc, parent_handle);
5087 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5088 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5089 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5091 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5096 sas_expander = kzalloc(sizeof(struct _sas_node),
5098 if (!sas_expander) {
5099 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5100 ioc->name, __FILE__, __LINE__, __func__);
5104 sas_expander->handle = handle;
5105 sas_expander->num_phys = expander_pg0.NumPhys;
5106 sas_expander->sas_address_parent = sas_address_parent;
5107 sas_expander->sas_address = sas_address;
5109 pr_info(MPT3SAS_FMT "expander_add: handle(0x%04x)," \
5110 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5111 handle, parent_handle, (unsigned long long)
5112 sas_expander->sas_address, sas_expander->num_phys);
5114 if (!sas_expander->num_phys)
5116 sas_expander->phy = kcalloc(sas_expander->num_phys,
5117 sizeof(struct _sas_phy), GFP_KERNEL);
5118 if (!sas_expander->phy) {
5119 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5120 ioc->name, __FILE__, __LINE__, __func__);
5125 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5126 mpt3sas_port = mpt3sas_transport_port_add(ioc, handle,
5127 sas_address_parent);
5128 if (!mpt3sas_port) {
5129 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5130 ioc->name, __FILE__, __LINE__, __func__);
5134 sas_expander->parent_dev = &mpt3sas_port->rphy->dev;
5136 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5137 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
5138 &expander_pg1, i, handle))) {
5139 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5140 ioc->name, __FILE__, __LINE__, __func__);
5144 sas_expander->phy[i].handle = handle;
5145 sas_expander->phy[i].phy_id = i;
5147 if ((mpt3sas_transport_add_expander_phy(ioc,
5148 &sas_expander->phy[i], expander_pg1,
5149 sas_expander->parent_dev))) {
5150 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5151 ioc->name, __FILE__, __LINE__, __func__);
5157 if (sas_expander->enclosure_handle) {
5158 if (!(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5159 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5160 sas_expander->enclosure_handle)))
5161 sas_expander->enclosure_logical_id =
5162 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5165 _scsih_expander_node_add(ioc, sas_expander);
5171 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
5172 sas_address_parent);
5173 kfree(sas_expander);
5178 * mpt3sas_expander_remove - removing expander object
5179 * @ioc: per adapter object
5180 * @sas_address: expander sas_address
5185 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address)
5187 struct _sas_node *sas_expander;
5188 unsigned long flags;
5190 if (ioc->shost_recovery)
5193 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5194 sas_expander = mpt3sas_scsih_expander_find_by_sas_address(ioc,
5197 list_del(&sas_expander->list);
5198 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5200 _scsih_expander_node_remove(ioc, sas_expander);
5204 * _scsih_done - internal SCSI_IO callback handler.
5205 * @ioc: per adapter object
5206 * @smid: system request message index
5207 * @msix_index: MSIX table index supplied by the OS
5208 * @reply: reply message frame(lower 32bit addr)
5210 * Callback handler when sending internal generated SCSI_IO.
5211 * The callback index passed is `ioc->scsih_cb_idx`
5213 * Return 1 meaning mf should be freed from _base_interrupt
5214 * 0 means the mf is freed from this function.
5217 _scsih_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5219 MPI2DefaultReply_t *mpi_reply;
5221 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
5222 if (ioc->scsih_cmds.status == MPT3_CMD_NOT_USED)
5224 if (ioc->scsih_cmds.smid != smid)
5226 ioc->scsih_cmds.status |= MPT3_CMD_COMPLETE;
5228 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5229 mpi_reply->MsgLength*4);
5230 ioc->scsih_cmds.status |= MPT3_CMD_REPLY_VALID;
5232 ioc->scsih_cmds.status &= ~MPT3_CMD_PENDING;
5233 complete(&ioc->scsih_cmds.done);
5240 #define MPT3_MAX_LUNS (255)
5244 * _scsih_check_access_status - check access flags
5245 * @ioc: per adapter object
5246 * @sas_address: sas address
5247 * @handle: sas device handle
5248 * @access_flags: errors returned during discovery of the device
5250 * Return 0 for success, else failure
5253 _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
5254 u16 handle, u8 access_status)
5259 switch (access_status) {
5260 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5261 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5264 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5265 desc = "sata capability failed";
5267 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5268 desc = "sata affiliation conflict";
5270 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5271 desc = "route not addressable";
5273 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5274 desc = "smp error not addressable";
5276 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5277 desc = "device blocked";
5279 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5280 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5281 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5282 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5283 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5284 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5285 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5286 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5287 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5288 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5289 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5290 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5291 desc = "sata initialization failed";
5302 "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5303 ioc->name, desc, (unsigned long long)sas_address, handle);
5308 * _scsih_check_device - checking device responsiveness
5309 * @ioc: per adapter object
5310 * @parent_sas_address: sas address of parent expander or sas host
5311 * @handle: attached device handle
5312 * @phy_numberv: phy number
5313 * @link_rate: new link rate
5318 _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
5319 u64 parent_sas_address, u16 handle, u8 phy_number, u8 link_rate)
5321 Mpi2ConfigReply_t mpi_reply;
5322 Mpi2SasDevicePage0_t sas_device_pg0;
5323 struct _sas_device *sas_device;
5325 unsigned long flags;
5327 struct scsi_target *starget;
5328 struct MPT3SAS_TARGET *sas_target_priv_data;
5332 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5333 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5336 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5337 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5340 /* wide port handling ~ we need only handle device once for the phy that
5341 * is matched in sas device page zero
5343 if (phy_number != sas_device_pg0.PhyNum)
5346 /* check if this is end device */
5347 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5348 if (!(_scsih_is_end_device(device_info)))
5351 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5352 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5353 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5359 if (unlikely(sas_device->handle != handle)) {
5360 starget = sas_device->starget;
5361 sas_target_priv_data = starget->hostdata;
5362 starget_printk(KERN_INFO, starget,
5363 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5364 sas_device->handle, handle);
5365 sas_target_priv_data->handle = handle;
5366 sas_device->handle = handle;
5367 if (sas_device_pg0.Flags &
5368 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5369 sas_device->enclosure_level =
5370 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5371 memcpy(&sas_device->connector_name[0],
5372 &sas_device_pg0.ConnectorName[0], 4);
5374 sas_device->enclosure_level = 0;
5375 sas_device->connector_name[0] = '\0';
5379 /* check if device is present */
5380 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5381 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5383 "device is not present handle(0x%04x), flags!!!\n",
5388 /* check if there were any issues with discovery */
5389 if (_scsih_check_access_status(ioc, sas_address, handle,
5390 sas_device_pg0.AccessStatus))
5393 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5394 _scsih_ublock_io_device(ioc, sas_address);
5397 sas_device_put(sas_device);
5401 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5403 sas_device_put(sas_device);
5407 * _scsih_add_device - creating sas device object
5408 * @ioc: per adapter object
5409 * @handle: sas device handle
5410 * @phy_num: phy number end device attached to
5411 * @is_pd: is this hidden raid component
5413 * Creating end device object, stored in ioc->sas_device_list.
5415 * Returns 0 for success, non-zero for failure.
5418 _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
5421 Mpi2ConfigReply_t mpi_reply;
5422 Mpi2SasDevicePage0_t sas_device_pg0;
5423 Mpi2SasEnclosurePage0_t enclosure_pg0;
5424 struct _sas_device *sas_device;
5429 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5430 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5431 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5432 ioc->name, __FILE__, __LINE__, __func__);
5436 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5437 MPI2_IOCSTATUS_MASK;
5438 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5439 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5440 ioc->name, __FILE__, __LINE__, __func__);
5444 /* check if this is end device */
5445 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5446 if (!(_scsih_is_end_device(device_info)))
5448 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5450 /* check if device is present */
5451 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5452 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5453 pr_err(MPT3SAS_FMT "device is not present handle(0x04%x)!!!\n",
5458 /* check if there were any issues with discovery */
5459 if (_scsih_check_access_status(ioc, sas_address, handle,
5460 sas_device_pg0.AccessStatus))
5463 sas_device = mpt3sas_get_sdev_by_addr(ioc,
5466 sas_device_put(sas_device);
5470 sas_device = kzalloc(sizeof(struct _sas_device),
5473 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5474 ioc->name, __FILE__, __LINE__, __func__);
5478 kref_init(&sas_device->refcount);
5479 sas_device->handle = handle;
5480 if (_scsih_get_sas_address(ioc,
5481 le16_to_cpu(sas_device_pg0.ParentDevHandle),
5482 &sas_device->sas_address_parent) != 0)
5483 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
5484 ioc->name, __FILE__, __LINE__, __func__);
5485 sas_device->enclosure_handle =
5486 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5487 if (sas_device->enclosure_handle != 0)
5489 le16_to_cpu(sas_device_pg0.Slot);
5490 sas_device->device_info = device_info;
5491 sas_device->sas_address = sas_address;
5492 sas_device->phy = sas_device_pg0.PhyNum;
5493 sas_device->fast_path = (le16_to_cpu(sas_device_pg0.Flags) &
5494 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE) ? 1 : 0;
5496 if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
5497 sas_device->enclosure_level =
5498 le16_to_cpu(sas_device_pg0.EnclosureLevel);
5499 memcpy(&sas_device->connector_name[0],
5500 &sas_device_pg0.ConnectorName[0], 4);
5502 sas_device->enclosure_level = 0;
5503 sas_device->connector_name[0] = '\0';
5505 /* get enclosure_logical_id */
5506 if (sas_device->enclosure_handle && !(mpt3sas_config_get_enclosure_pg0(
5507 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5508 sas_device->enclosure_handle)))
5509 sas_device->enclosure_logical_id =
5510 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5512 /* get device name */
5513 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5515 if (ioc->wait_for_discovery_to_complete)
5516 _scsih_sas_device_init_add(ioc, sas_device);
5518 _scsih_sas_device_add(ioc, sas_device);
5520 sas_device_put(sas_device);
5525 * _scsih_remove_device - removing sas device object
5526 * @ioc: per adapter object
5527 * @sas_device_delete: the sas_device object
5532 _scsih_remove_device(struct MPT3SAS_ADAPTER *ioc,
5533 struct _sas_device *sas_device)
5535 struct MPT3SAS_TARGET *sas_target_priv_data;
5537 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5538 (sas_device->pfa_led_on)) {
5539 _scsih_turn_off_pfa_led(ioc, sas_device);
5540 sas_device->pfa_led_on = 0;
5542 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5543 "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
5544 ioc->name, __func__,
5545 sas_device->handle, (unsigned long long)
5546 sas_device->sas_address));
5547 if (sas_device->enclosure_handle != 0)
5548 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5549 "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
5550 ioc->name, __func__,
5551 (unsigned long long)sas_device->enclosure_logical_id,
5553 if (sas_device->connector_name[0] != '\0')
5554 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5555 "%s: enter: enclosure level(0x%04x), connector name( %s)\n",
5556 ioc->name, __func__,
5557 sas_device->enclosure_level,
5558 sas_device->connector_name));
5560 if (sas_device->starget && sas_device->starget->hostdata) {
5561 sas_target_priv_data = sas_device->starget->hostdata;
5562 sas_target_priv_data->deleted = 1;
5563 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5564 sas_target_priv_data->handle =
5565 MPT3SAS_INVALID_DEVICE_HANDLE;
5568 if (!ioc->hide_drives)
5569 mpt3sas_transport_port_remove(ioc,
5570 sas_device->sas_address,
5571 sas_device->sas_address_parent);
5574 "removing handle(0x%04x), sas_addr(0x%016llx)\n",
5575 ioc->name, sas_device->handle,
5576 (unsigned long long) sas_device->sas_address);
5577 if (sas_device->enclosure_handle != 0)
5579 "removing : enclosure logical id(0x%016llx), slot(%d)\n",
5581 (unsigned long long)sas_device->enclosure_logical_id,
5583 if (sas_device->connector_name[0] != '\0')
5585 "removing enclosure level(0x%04x), connector name( %s)\n",
5586 ioc->name, sas_device->enclosure_level,
5587 sas_device->connector_name);
5589 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5590 "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
5591 ioc->name, __func__,
5592 sas_device->handle, (unsigned long long)
5593 sas_device->sas_address));
5594 if (sas_device->enclosure_handle != 0)
5595 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5596 "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
5597 ioc->name, __func__,
5598 (unsigned long long)sas_device->enclosure_logical_id,
5600 if (sas_device->connector_name[0] != '\0')
5601 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5602 "%s: exit: enclosure level(0x%04x), connector name(%s)\n",
5603 ioc->name, __func__, sas_device->enclosure_level,
5604 sas_device->connector_name));
5608 * _scsih_sas_topology_change_event_debug - debug for topology event
5609 * @ioc: per adapter object
5610 * @event_data: event data payload
5614 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5615 Mpi2EventDataSasTopologyChangeList_t *event_data)
5621 char *status_str = NULL;
5622 u8 link_rate, prev_link_rate;
5624 switch (event_data->ExpStatus) {
5625 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5628 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5629 status_str = "remove";
5631 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5633 status_str = "responding";
5635 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5636 status_str = "remove delay";
5639 status_str = "unknown status";
5642 pr_info(MPT3SAS_FMT "sas topology change: (%s)\n",
5643 ioc->name, status_str);
5644 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
5645 "start_phy(%02d), count(%d)\n",
5646 le16_to_cpu(event_data->ExpanderDevHandle),
5647 le16_to_cpu(event_data->EnclosureHandle),
5648 event_data->StartPhyNum, event_data->NumEntries);
5649 for (i = 0; i < event_data->NumEntries; i++) {
5650 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5653 phy_number = event_data->StartPhyNum + i;
5654 reason_code = event_data->PHY[i].PhyStatus &
5655 MPI2_EVENT_SAS_TOPO_RC_MASK;
5656 switch (reason_code) {
5657 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5658 status_str = "target add";
5660 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5661 status_str = "target remove";
5663 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5664 status_str = "delay target remove";
5666 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5667 status_str = "link rate change";
5669 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5670 status_str = "target responding";
5673 status_str = "unknown";
5676 link_rate = event_data->PHY[i].LinkRate >> 4;
5677 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5678 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
5679 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5680 handle, status_str, link_rate, prev_link_rate);
5686 * _scsih_sas_topology_change_event - handle topology changes
5687 * @ioc: per adapter object
5688 * @fw_event: The fw_event_work object
5693 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER *ioc,
5694 struct fw_event_work *fw_event)
5697 u16 parent_handle, handle;
5699 u8 phy_number, max_phys;
5700 struct _sas_node *sas_expander;
5702 unsigned long flags;
5703 u8 link_rate, prev_link_rate;
5704 Mpi2EventDataSasTopologyChangeList_t *event_data =
5705 (Mpi2EventDataSasTopologyChangeList_t *)
5706 fw_event->event_data;
5708 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5709 _scsih_sas_topology_change_event_debug(ioc, event_data);
5711 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5714 if (!ioc->sas_hba.num_phys)
5715 _scsih_sas_host_add(ioc);
5717 _scsih_sas_host_refresh(ioc);
5719 if (fw_event->ignore) {
5720 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5721 "ignoring expander event\n", ioc->name));
5725 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5727 /* handle expander add */
5728 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5729 if (_scsih_expander_add(ioc, parent_handle) != 0)
5732 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5733 sas_expander = mpt3sas_scsih_expander_find_by_handle(ioc,
5736 sas_address = sas_expander->sas_address;
5737 max_phys = sas_expander->num_phys;
5738 } else if (parent_handle < ioc->sas_hba.num_phys) {
5739 sas_address = ioc->sas_hba.sas_address;
5740 max_phys = ioc->sas_hba.num_phys;
5742 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5745 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5747 /* handle siblings events */
5748 for (i = 0; i < event_data->NumEntries; i++) {
5749 if (fw_event->ignore) {
5750 dewtprintk(ioc, pr_info(MPT3SAS_FMT
5751 "ignoring expander event\n", ioc->name));
5754 if (ioc->remove_host || ioc->pci_error_recovery)
5756 phy_number = event_data->StartPhyNum + i;
5757 if (phy_number >= max_phys)
5759 reason_code = event_data->PHY[i].PhyStatus &
5760 MPI2_EVENT_SAS_TOPO_RC_MASK;
5761 if ((event_data->PHY[i].PhyStatus &
5762 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5763 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5765 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5768 link_rate = event_data->PHY[i].LinkRate >> 4;
5769 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5770 switch (reason_code) {
5771 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5773 if (ioc->shost_recovery)
5776 if (link_rate == prev_link_rate)
5779 mpt3sas_transport_update_links(ioc, sas_address,
5780 handle, phy_number, link_rate);
5782 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5785 _scsih_check_device(ioc, sas_address, handle,
5786 phy_number, link_rate);
5789 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5791 if (ioc->shost_recovery)
5794 mpt3sas_transport_update_links(ioc, sas_address,
5795 handle, phy_number, link_rate);
5797 _scsih_add_device(ioc, handle, phy_number, 0);
5800 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5802 _scsih_device_remove_by_handle(ioc, handle);
5807 /* handle expander removal */
5808 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5810 mpt3sas_expander_remove(ioc, sas_address);
5816 * _scsih_sas_device_status_change_event_debug - debug for device event
5817 * @event_data: event data payload
5823 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5824 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5826 char *reason_str = NULL;
5828 switch (event_data->ReasonCode) {
5829 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5830 reason_str = "smart data";
5832 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5833 reason_str = "unsupported device discovered";
5835 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5836 reason_str = "internal device reset";
5838 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5839 reason_str = "internal task abort";
5841 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5842 reason_str = "internal task abort set";
5844 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5845 reason_str = "internal clear task set";
5847 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5848 reason_str = "internal query task";
5850 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5851 reason_str = "sata init failure";
5853 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5854 reason_str = "internal device reset complete";
5856 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5857 reason_str = "internal task abort complete";
5859 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5860 reason_str = "internal async notification";
5862 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5863 reason_str = "expander reduced functionality";
5865 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5866 reason_str = "expander reduced functionality complete";
5869 reason_str = "unknown reason";
5872 pr_info(MPT3SAS_FMT "device status change: (%s)\n"
5873 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5874 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5875 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5876 le16_to_cpu(event_data->TaskTag));
5877 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5878 pr_info(MPT3SAS_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5879 event_data->ASC, event_data->ASCQ);
5884 * _scsih_sas_device_status_change_event - handle device status change
5885 * @ioc: per adapter object
5886 * @fw_event: The fw_event_work object
5892 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5893 struct fw_event_work *fw_event)
5895 struct MPT3SAS_TARGET *target_priv_data;
5896 struct _sas_device *sas_device;
5898 unsigned long flags;
5899 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5900 (Mpi2EventDataSasDeviceStatusChange_t *)
5901 fw_event->event_data;
5903 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5904 _scsih_sas_device_status_change_event_debug(ioc,
5907 /* In MPI Revision K (0xC), the internal device reset complete was
5908 * implemented, so avoid setting tm_busy flag for older firmware.
5910 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5913 if (event_data->ReasonCode !=
5914 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5915 event_data->ReasonCode !=
5916 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5919 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5920 sas_address = le64_to_cpu(event_data->SASAddress);
5921 sas_device = __mpt3sas_get_sdev_by_addr(ioc,
5924 if (!sas_device || !sas_device->starget)
5927 target_priv_data = sas_device->starget->hostdata;
5928 if (!target_priv_data)
5931 if (event_data->ReasonCode ==
5932 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5933 target_priv_data->tm_busy = 1;
5935 target_priv_data->tm_busy = 0;
5939 sas_device_put(sas_device);
5941 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5946 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
5948 * @ioc: per adapter object
5949 * @event_data: event data payload
5955 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
5956 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5958 char *reason_str = NULL;
5960 switch (event_data->ReasonCode) {
5961 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5962 reason_str = "enclosure add";
5964 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5965 reason_str = "enclosure remove";
5968 reason_str = "unknown reason";
5972 pr_info(MPT3SAS_FMT "enclosure status change: (%s)\n"
5973 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5974 " number slots(%d)\n", ioc->name, reason_str,
5975 le16_to_cpu(event_data->EnclosureHandle),
5976 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5977 le16_to_cpu(event_data->StartSlot));
5981 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5982 * @ioc: per adapter object
5983 * @fw_event: The fw_event_work object
5989 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER *ioc,
5990 struct fw_event_work *fw_event)
5992 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5993 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5994 (Mpi2EventDataSasEnclDevStatusChange_t *)
5995 fw_event->event_data);
5999 * _scsih_sas_broadcast_primitive_event - handle broadcast events
6000 * @ioc: per adapter object
6001 * @fw_event: The fw_event_work object
6007 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER *ioc,
6008 struct fw_event_work *fw_event)
6010 struct scsi_cmnd *scmd;
6011 struct scsi_device *sdev;
6014 struct MPT3SAS_DEVICE *sas_device_priv_data;
6015 u32 termination_count;
6017 Mpi2SCSITaskManagementReply_t *mpi_reply;
6018 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
6019 (Mpi2EventDataSasBroadcastPrimitive_t *)
6020 fw_event->event_data;
6022 unsigned long flags;
6025 u8 task_abort_retries;
6027 mutex_lock(&ioc->tm_cmds.mutex);
6029 "%s: enter: phy number(%d), width(%d)\n",
6030 ioc->name, __func__, event_data->PhyNum,
6031 event_data->PortWidth);
6033 _scsih_block_io_all_device(ioc);
6035 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6036 mpi_reply = ioc->tm_cmds.reply;
6037 broadcast_aen_retry:
6039 /* sanity checks for retrying this loop */
6040 if (max_retries++ == 5) {
6041 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: giving up\n",
6042 ioc->name, __func__));
6044 } else if (max_retries > 1)
6045 dewtprintk(ioc, pr_info(MPT3SAS_FMT "%s: %d retry\n",
6046 ioc->name, __func__, max_retries - 1));
6048 termination_count = 0;
6050 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
6051 if (ioc->shost_recovery)
6053 scmd = _scsih_scsi_lookup_get(ioc, smid);
6056 sdev = scmd->device;
6057 sas_device_priv_data = sdev->hostdata;
6058 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
6060 /* skip hidden raid components */
6061 if (sas_device_priv_data->sas_target->flags &
6062 MPT_TARGET_FLAGS_RAID_COMPONENT)
6065 if (sas_device_priv_data->sas_target->flags &
6066 MPT_TARGET_FLAGS_VOLUME)
6069 handle = sas_device_priv_data->sas_target->handle;
6070 lun = sas_device_priv_data->lun;
6073 if (ioc->shost_recovery)
6076 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6077 r = mpt3sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6078 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
6081 sdev_printk(KERN_WARNING, sdev,
6082 "mpt3sas_scsih_issue_tm: FAILED when sending "
6083 "QUERY_TASK: scmd(%p)\n", scmd);
6084 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6085 goto broadcast_aen_retry;
6087 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6088 & MPI2_IOCSTATUS_MASK;
6089 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6090 sdev_printk(KERN_WARNING, sdev,
6091 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
6093 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6094 goto broadcast_aen_retry;
6097 /* see if IO is still owned by IOC and target */
6098 if (mpi_reply->ResponseCode ==
6099 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6100 mpi_reply->ResponseCode ==
6101 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6102 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6105 task_abort_retries = 0;
6107 if (task_abort_retries++ == 60) {
6108 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6109 "%s: ABORT_TASK: giving up\n", ioc->name,
6111 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6112 goto broadcast_aen_retry;
6115 if (ioc->shost_recovery)
6118 r = mpt3sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6119 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
6122 sdev_printk(KERN_WARNING, sdev,
6123 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6124 "scmd(%p)\n", scmd);
6128 if (task_abort_retries > 1)
6129 sdev_printk(KERN_WARNING, sdev,
6130 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6132 task_abort_retries - 1, scmd);
6134 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6135 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6138 if (ioc->broadcast_aen_pending) {
6139 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6140 "%s: loop back due to pending AEN\n",
6141 ioc->name, __func__));
6142 ioc->broadcast_aen_pending = 0;
6143 goto broadcast_aen_retry;
6147 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6150 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6151 "%s - exit, query_count = %d termination_count = %d\n",
6152 ioc->name, __func__, query_count, termination_count));
6154 ioc->broadcast_aen_busy = 0;
6155 if (!ioc->shost_recovery)
6156 _scsih_ublock_io_all_device(ioc);
6157 mutex_unlock(&ioc->tm_cmds.mutex);
6161 * _scsih_sas_discovery_event - handle discovery events
6162 * @ioc: per adapter object
6163 * @fw_event: The fw_event_work object
6169 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER *ioc,
6170 struct fw_event_work *fw_event)
6172 Mpi2EventDataSasDiscovery_t *event_data =
6173 (Mpi2EventDataSasDiscovery_t *) fw_event->event_data;
6175 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6176 pr_info(MPT3SAS_FMT "discovery event: (%s)", ioc->name,
6177 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6179 if (event_data->DiscoveryStatus)
6180 pr_info("discovery_status(0x%08x)",
6181 le32_to_cpu(event_data->DiscoveryStatus));
6185 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6186 !ioc->sas_hba.num_phys) {
6187 if (disable_discovery > 0 && ioc->shost_recovery) {
6188 /* Wait for the reset to complete */
6189 while (ioc->shost_recovery)
6192 _scsih_sas_host_add(ioc);
6197 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
6198 * @ioc: per adapter object
6199 * @handle: device handle for physical disk
6200 * @phys_disk_num: physical disk number
6202 * Return 0 for success, else failure.
6205 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phys_disk_num)
6207 Mpi2RaidActionRequest_t *mpi_request;
6208 Mpi2RaidActionReply_t *mpi_reply;
6215 if (ioc->hba_mpi_version_belonged == MPI2_VERSION)
6218 mutex_lock(&ioc->scsih_cmds.mutex);
6220 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
6221 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
6222 ioc->name, __func__);
6226 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
6228 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
6230 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
6231 ioc->name, __func__);
6232 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6237 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
6238 ioc->scsih_cmds.smid = smid;
6239 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
6241 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
6242 mpi_request->Action = MPI2_RAID_ACTION_PHYSDISK_HIDDEN;
6243 mpi_request->PhysDiskNum = phys_disk_num;
6245 dewtprintk(ioc, pr_info(MPT3SAS_FMT "IR RAID_ACTION: turning fast "\
6246 "path on for handle(0x%04x), phys_disk_num (0x%02x)\n", ioc->name,
6247 handle, phys_disk_num));
6249 init_completion(&ioc->scsih_cmds.done);
6250 mpt3sas_base_put_smid_default(ioc, smid);
6251 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
6253 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
6254 pr_err(MPT3SAS_FMT "%s: timeout\n",
6255 ioc->name, __func__);
6256 if (!(ioc->scsih_cmds.status & MPT3_CMD_RESET))
6262 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
6264 mpi_reply = ioc->scsih_cmds.reply;
6265 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
6266 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
6267 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
6270 ioc_status &= MPI2_IOCSTATUS_MASK;
6271 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6272 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6273 "IR RAID_ACTION: failed: ioc_status(0x%04x), "
6274 "loginfo(0x%08x)!!!\n", ioc->name, ioc_status,
6278 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6279 "IR RAID_ACTION: completed successfully\n",
6284 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
6285 mutex_unlock(&ioc->scsih_cmds.mutex);
6288 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
6294 * _scsih_reprobe_lun - reprobing lun
6295 * @sdev: scsi device struct
6296 * @no_uld_attach: sdev->no_uld_attach flag setting
6300 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6303 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6304 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6305 sdev->no_uld_attach ? "hidding" : "exposing");
6306 rc = scsi_device_reprobe(sdev);
6310 * _scsih_sas_volume_add - add new volume
6311 * @ioc: per adapter object
6312 * @element: IR config element data
6318 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER *ioc,
6319 Mpi2EventIrConfigElement_t *element)
6321 struct _raid_device *raid_device;
6322 unsigned long flags;
6324 u16 handle = le16_to_cpu(element->VolDevHandle);
6327 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6330 "failure at %s:%d/%s()!\n", ioc->name,
6331 __FILE__, __LINE__, __func__);
6335 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6336 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6337 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6342 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6345 "failure at %s:%d/%s()!\n", ioc->name,
6346 __FILE__, __LINE__, __func__);
6350 raid_device->id = ioc->sas_id++;
6351 raid_device->channel = RAID_CHANNEL;
6352 raid_device->handle = handle;
6353 raid_device->wwid = wwid;
6354 _scsih_raid_device_add(ioc, raid_device);
6355 if (!ioc->wait_for_discovery_to_complete) {
6356 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6357 raid_device->id, 0);
6359 _scsih_raid_device_remove(ioc, raid_device);
6361 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6362 _scsih_determine_boot_device(ioc, raid_device, 1);
6363 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6368 * _scsih_sas_volume_delete - delete volume
6369 * @ioc: per adapter object
6370 * @handle: volume device handle
6376 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER *ioc, u16 handle)
6378 struct _raid_device *raid_device;
6379 unsigned long flags;
6380 struct MPT3SAS_TARGET *sas_target_priv_data;
6381 struct scsi_target *starget = NULL;
6383 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6384 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6386 if (raid_device->starget) {
6387 starget = raid_device->starget;
6388 sas_target_priv_data = starget->hostdata;
6389 sas_target_priv_data->deleted = 1;
6391 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
6392 ioc->name, raid_device->handle,
6393 (unsigned long long) raid_device->wwid);
6394 list_del(&raid_device->list);
6397 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6399 scsi_remove_target(&starget->dev);
6403 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6404 * @ioc: per adapter object
6405 * @element: IR config element data
6411 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER *ioc,
6412 Mpi2EventIrConfigElement_t *element)
6414 struct _sas_device *sas_device;
6415 struct scsi_target *starget = NULL;
6416 struct MPT3SAS_TARGET *sas_target_priv_data;
6417 unsigned long flags;
6418 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6420 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6421 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6423 sas_device->volume_handle = 0;
6424 sas_device->volume_wwid = 0;
6425 clear_bit(handle, ioc->pd_handles);
6426 if (sas_device->starget && sas_device->starget->hostdata) {
6427 starget = sas_device->starget;
6428 sas_target_priv_data = starget->hostdata;
6429 sas_target_priv_data->flags &=
6430 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6433 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6437 /* exposing raid component */
6439 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6441 sas_device_put(sas_device);
6445 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6446 * @ioc: per adapter object
6447 * @element: IR config element data
6453 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER *ioc,
6454 Mpi2EventIrConfigElement_t *element)
6456 struct _sas_device *sas_device;
6457 struct scsi_target *starget = NULL;
6458 struct MPT3SAS_TARGET *sas_target_priv_data;
6459 unsigned long flags;
6460 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6461 u16 volume_handle = 0;
6462 u64 volume_wwid = 0;
6464 mpt3sas_config_get_volume_handle(ioc, handle, &volume_handle);
6466 mpt3sas_config_get_volume_wwid(ioc, volume_handle,
6469 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6470 sas_device = __mpt3sas_get_sdev_by_handle(ioc, handle);
6472 set_bit(handle, ioc->pd_handles);
6473 if (sas_device->starget && sas_device->starget->hostdata) {
6474 starget = sas_device->starget;
6475 sas_target_priv_data = starget->hostdata;
6476 sas_target_priv_data->flags |=
6477 MPT_TARGET_FLAGS_RAID_COMPONENT;
6478 sas_device->volume_handle = volume_handle;
6479 sas_device->volume_wwid = volume_wwid;
6482 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6486 /* hiding raid component */
6487 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6490 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6492 sas_device_put(sas_device);
6496 * _scsih_sas_pd_delete - delete pd component
6497 * @ioc: per adapter object
6498 * @element: IR config element data
6504 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER *ioc,
6505 Mpi2EventIrConfigElement_t *element)
6507 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6509 _scsih_device_remove_by_handle(ioc, handle);
6513 * _scsih_sas_pd_add - remove pd component
6514 * @ioc: per adapter object
6515 * @element: IR config element data
6521 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER *ioc,
6522 Mpi2EventIrConfigElement_t *element)
6524 struct _sas_device *sas_device;
6525 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6526 Mpi2ConfigReply_t mpi_reply;
6527 Mpi2SasDevicePage0_t sas_device_pg0;
6532 set_bit(handle, ioc->pd_handles);
6534 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6536 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6537 sas_device_put(sas_device);
6541 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6542 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6543 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6544 ioc->name, __FILE__, __LINE__, __func__);
6548 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6549 MPI2_IOCSTATUS_MASK;
6550 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6551 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6552 ioc->name, __FILE__, __LINE__, __func__);
6556 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6557 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6558 mpt3sas_transport_update_links(ioc, sas_address, handle,
6559 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6561 _scsih_ir_fastpath(ioc, handle, element->PhysDiskNum);
6562 _scsih_add_device(ioc, handle, 0, 1);
6566 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6567 * @ioc: per adapter object
6568 * @event_data: event data payload
6574 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER *ioc,
6575 Mpi2EventDataIrConfigChangeList_t *event_data)
6577 Mpi2EventIrConfigElement_t *element;
6580 char *reason_str = NULL, *element_str = NULL;
6582 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6584 pr_info(MPT3SAS_FMT "raid config change: (%s), elements(%d)\n",
6585 ioc->name, (le32_to_cpu(event_data->Flags) &
6586 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6587 "foreign" : "native", event_data->NumElements);
6588 for (i = 0; i < event_data->NumElements; i++, element++) {
6589 switch (element->ReasonCode) {
6590 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6593 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6594 reason_str = "remove";
6596 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6597 reason_str = "no change";
6599 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6600 reason_str = "hide";
6602 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6603 reason_str = "unhide";
6605 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6606 reason_str = "volume_created";
6608 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6609 reason_str = "volume_deleted";
6611 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6612 reason_str = "pd_created";
6614 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6615 reason_str = "pd_deleted";
6618 reason_str = "unknown reason";
6621 element_type = le16_to_cpu(element->ElementFlags) &
6622 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6623 switch (element_type) {
6624 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6625 element_str = "volume";
6627 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6628 element_str = "phys disk";
6630 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6631 element_str = "hot spare";
6634 element_str = "unknown element";
6637 pr_info("\t(%s:%s), vol handle(0x%04x), " \
6638 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6639 reason_str, le16_to_cpu(element->VolDevHandle),
6640 le16_to_cpu(element->PhysDiskDevHandle),
6641 element->PhysDiskNum);
6646 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6647 * @ioc: per adapter object
6648 * @fw_event: The fw_event_work object
6654 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER *ioc,
6655 struct fw_event_work *fw_event)
6657 Mpi2EventIrConfigElement_t *element;
6660 Mpi2EventDataIrConfigChangeList_t *event_data =
6661 (Mpi2EventDataIrConfigChangeList_t *)
6662 fw_event->event_data;
6664 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6665 (!ioc->hide_ir_msg))
6666 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6668 foreign_config = (le32_to_cpu(event_data->Flags) &
6669 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6671 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6672 if (ioc->shost_recovery &&
6673 ioc->hba_mpi_version_belonged != MPI2_VERSION) {
6674 for (i = 0; i < event_data->NumElements; i++, element++) {
6675 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_HIDE)
6676 _scsih_ir_fastpath(ioc,
6677 le16_to_cpu(element->PhysDiskDevHandle),
6678 element->PhysDiskNum);
6683 for (i = 0; i < event_data->NumElements; i++, element++) {
6685 switch (element->ReasonCode) {
6686 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6687 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6688 if (!foreign_config)
6689 _scsih_sas_volume_add(ioc, element);
6691 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6692 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6693 if (!foreign_config)
6694 _scsih_sas_volume_delete(ioc,
6695 le16_to_cpu(element->VolDevHandle));
6697 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6698 if (!ioc->is_warpdrive)
6699 _scsih_sas_pd_hide(ioc, element);
6701 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6702 if (!ioc->is_warpdrive)
6703 _scsih_sas_pd_expose(ioc, element);
6705 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6706 if (!ioc->is_warpdrive)
6707 _scsih_sas_pd_add(ioc, element);
6709 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6710 if (!ioc->is_warpdrive)
6711 _scsih_sas_pd_delete(ioc, element);
6718 * _scsih_sas_ir_volume_event - IR volume event
6719 * @ioc: per adapter object
6720 * @fw_event: The fw_event_work object
6726 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER *ioc,
6727 struct fw_event_work *fw_event)
6730 unsigned long flags;
6731 struct _raid_device *raid_device;
6735 Mpi2EventDataIrVolume_t *event_data =
6736 (Mpi2EventDataIrVolume_t *) fw_event->event_data;
6738 if (ioc->shost_recovery)
6741 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6744 handle = le16_to_cpu(event_data->VolDevHandle);
6745 state = le32_to_cpu(event_data->NewValue);
6746 if (!ioc->hide_ir_msg)
6747 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6748 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6749 ioc->name, __func__, handle,
6750 le32_to_cpu(event_data->PreviousValue), state));
6752 case MPI2_RAID_VOL_STATE_MISSING:
6753 case MPI2_RAID_VOL_STATE_FAILED:
6754 _scsih_sas_volume_delete(ioc, handle);
6757 case MPI2_RAID_VOL_STATE_ONLINE:
6758 case MPI2_RAID_VOL_STATE_DEGRADED:
6759 case MPI2_RAID_VOL_STATE_OPTIMAL:
6761 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6762 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6763 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6768 mpt3sas_config_get_volume_wwid(ioc, handle, &wwid);
6771 "failure at %s:%d/%s()!\n", ioc->name,
6772 __FILE__, __LINE__, __func__);
6776 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6779 "failure at %s:%d/%s()!\n", ioc->name,
6780 __FILE__, __LINE__, __func__);
6784 raid_device->id = ioc->sas_id++;
6785 raid_device->channel = RAID_CHANNEL;
6786 raid_device->handle = handle;
6787 raid_device->wwid = wwid;
6788 _scsih_raid_device_add(ioc, raid_device);
6789 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6790 raid_device->id, 0);
6792 _scsih_raid_device_remove(ioc, raid_device);
6795 case MPI2_RAID_VOL_STATE_INITIALIZING:
6802 * _scsih_sas_ir_physical_disk_event - PD event
6803 * @ioc: per adapter object
6804 * @fw_event: The fw_event_work object
6810 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER *ioc,
6811 struct fw_event_work *fw_event)
6813 u16 handle, parent_handle;
6815 struct _sas_device *sas_device;
6816 Mpi2ConfigReply_t mpi_reply;
6817 Mpi2SasDevicePage0_t sas_device_pg0;
6819 Mpi2EventDataIrPhysicalDisk_t *event_data =
6820 (Mpi2EventDataIrPhysicalDisk_t *) fw_event->event_data;
6823 if (ioc->shost_recovery)
6826 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6829 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6830 state = le32_to_cpu(event_data->NewValue);
6832 if (!ioc->hide_ir_msg)
6833 dewtprintk(ioc, pr_info(MPT3SAS_FMT
6834 "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
6835 ioc->name, __func__, handle,
6836 le32_to_cpu(event_data->PreviousValue), state));
6839 case MPI2_RAID_PD_STATE_ONLINE:
6840 case MPI2_RAID_PD_STATE_DEGRADED:
6841 case MPI2_RAID_PD_STATE_REBUILDING:
6842 case MPI2_RAID_PD_STATE_OPTIMAL:
6843 case MPI2_RAID_PD_STATE_HOT_SPARE:
6845 if (!ioc->is_warpdrive)
6846 set_bit(handle, ioc->pd_handles);
6848 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
6850 sas_device_put(sas_device);
6854 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6855 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6857 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6858 ioc->name, __FILE__, __LINE__, __func__);
6862 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6863 MPI2_IOCSTATUS_MASK;
6864 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6865 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
6866 ioc->name, __FILE__, __LINE__, __func__);
6870 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6871 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6872 mpt3sas_transport_update_links(ioc, sas_address, handle,
6873 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6875 _scsih_add_device(ioc, handle, 0, 1);
6879 case MPI2_RAID_PD_STATE_OFFLINE:
6880 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6881 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6888 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6889 * @ioc: per adapter object
6890 * @event_data: event data payload
6896 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER *ioc,
6897 Mpi2EventDataIrOperationStatus_t *event_data)
6899 char *reason_str = NULL;
6901 switch (event_data->RAIDOperation) {
6902 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6903 reason_str = "resync";
6905 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6906 reason_str = "online capacity expansion";
6908 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6909 reason_str = "consistency check";
6911 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6912 reason_str = "background init";
6914 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6915 reason_str = "make data consistent";
6922 pr_info(MPT3SAS_FMT "raid operational status: (%s)" \
6923 "\thandle(0x%04x), percent complete(%d)\n",
6924 ioc->name, reason_str,
6925 le16_to_cpu(event_data->VolDevHandle),
6926 event_data->PercentComplete);
6930 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6931 * @ioc: per adapter object
6932 * @fw_event: The fw_event_work object
6938 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER *ioc,
6939 struct fw_event_work *fw_event)
6941 Mpi2EventDataIrOperationStatus_t *event_data =
6942 (Mpi2EventDataIrOperationStatus_t *)
6943 fw_event->event_data;
6944 static struct _raid_device *raid_device;
6945 unsigned long flags;
6948 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) &&
6949 (!ioc->hide_ir_msg))
6950 _scsih_sas_ir_operation_status_event_debug(ioc,
6953 /* code added for raid transport support */
6954 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6956 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6957 handle = le16_to_cpu(event_data->VolDevHandle);
6958 raid_device = mpt3sas_raid_device_find_by_handle(ioc, handle);
6960 raid_device->percent_complete =
6961 event_data->PercentComplete;
6962 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6967 * _scsih_prep_device_scan - initialize parameters prior to device scan
6968 * @ioc: per adapter object
6970 * Set the deleted flag prior to device scan. If the device is found during
6971 * the scan, then we clear the deleted flag.
6974 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER *ioc)
6976 struct MPT3SAS_DEVICE *sas_device_priv_data;
6977 struct scsi_device *sdev;
6979 shost_for_each_device(sdev, ioc->shost) {
6980 sas_device_priv_data = sdev->hostdata;
6981 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6982 sas_device_priv_data->sas_target->deleted = 1;
6987 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6988 * @ioc: per adapter object
6989 * @sas_device_pg0: SAS Device page 0
6991 * After host reset, find out whether devices are still responding.
6992 * Used in _scsih_remove_unresponsive_sas_devices.
6997 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER *ioc,
6998 Mpi2SasDevicePage0_t *sas_device_pg0)
7000 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7001 struct scsi_target *starget;
7002 struct _sas_device *sas_device;
7003 unsigned long flags;
7005 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7006 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
7007 if ((sas_device->sas_address == sas_device_pg0->SASAddress) &&
7008 (sas_device->slot == sas_device_pg0->Slot)) {
7009 sas_device->responding = 1;
7010 starget = sas_device->starget;
7011 if (starget && starget->hostdata) {
7012 sas_target_priv_data = starget->hostdata;
7013 sas_target_priv_data->tm_busy = 0;
7014 sas_target_priv_data->deleted = 0;
7016 sas_target_priv_data = NULL;
7018 starget_printk(KERN_INFO, starget,
7019 "handle(0x%04x), sas_addr(0x%016llx)\n",
7020 sas_device_pg0->DevHandle,
7021 (unsigned long long)
7022 sas_device->sas_address);
7024 if (sas_device->enclosure_handle != 0)
7025 starget_printk(KERN_INFO, starget,
7026 "enclosure logical id(0x%016llx),"
7028 (unsigned long long)
7029 sas_device->enclosure_logical_id,
7032 if (sas_device_pg0->Flags &
7033 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
7034 sas_device->enclosure_level =
7035 le16_to_cpu(sas_device_pg0->EnclosureLevel);
7036 memcpy(&sas_device->connector_name[0],
7037 &sas_device_pg0->ConnectorName[0], 4);
7039 sas_device->enclosure_level = 0;
7040 sas_device->connector_name[0] = '\0';
7043 if (sas_device->handle == sas_device_pg0->DevHandle)
7045 pr_info("\thandle changed from(0x%04x)!!!\n",
7046 sas_device->handle);
7047 sas_device->handle = sas_device_pg0->DevHandle;
7048 if (sas_target_priv_data)
7049 sas_target_priv_data->handle =
7050 sas_device_pg0->DevHandle;
7055 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7059 * _scsih_search_responding_sas_devices -
7060 * @ioc: per adapter object
7062 * After host reset, find out whether devices are still responding.
7068 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7070 Mpi2SasDevicePage0_t sas_device_pg0;
7071 Mpi2ConfigReply_t mpi_reply;
7076 pr_info(MPT3SAS_FMT "search for end-devices: start\n", ioc->name);
7078 if (list_empty(&ioc->sas_device_list))
7082 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7083 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7085 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7086 MPI2_IOCSTATUS_MASK;
7087 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7089 handle = sas_device_pg0.DevHandle =
7090 le16_to_cpu(sas_device_pg0.DevHandle);
7091 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
7092 if (!(_scsih_is_end_device(device_info)))
7094 sas_device_pg0.SASAddress =
7095 le64_to_cpu(sas_device_pg0.SASAddress);
7096 sas_device_pg0.Slot = le16_to_cpu(sas_device_pg0.Slot);
7097 _scsih_mark_responding_sas_device(ioc, &sas_device_pg0);
7101 pr_info(MPT3SAS_FMT "search for end-devices: complete\n",
7106 * _scsih_mark_responding_raid_device - mark a raid_device as responding
7107 * @ioc: per adapter object
7108 * @wwid: world wide identifier for raid volume
7109 * @handle: device handle
7111 * After host reset, find out whether devices are still responding.
7112 * Used in _scsih_remove_unresponsive_raid_devices.
7117 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER *ioc, u64 wwid,
7120 struct MPT3SAS_TARGET *sas_target_priv_data = NULL;
7121 struct scsi_target *starget;
7122 struct _raid_device *raid_device;
7123 unsigned long flags;
7125 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7126 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
7127 if (raid_device->wwid == wwid && raid_device->starget) {
7128 starget = raid_device->starget;
7129 if (starget && starget->hostdata) {
7130 sas_target_priv_data = starget->hostdata;
7131 sas_target_priv_data->deleted = 0;
7133 sas_target_priv_data = NULL;
7134 raid_device->responding = 1;
7135 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7136 starget_printk(KERN_INFO, raid_device->starget,
7137 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7138 (unsigned long long)raid_device->wwid);
7141 * WARPDRIVE: The handles of the PDs might have changed
7142 * across the host reset so re-initialize the
7143 * required data for Direct IO
7145 mpt3sas_init_warpdrive_properties(ioc, raid_device);
7146 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7147 if (raid_device->handle == handle) {
7148 spin_unlock_irqrestore(&ioc->raid_device_lock,
7152 pr_info("\thandle changed from(0x%04x)!!!\n",
7153 raid_device->handle);
7154 raid_device->handle = handle;
7155 if (sas_target_priv_data)
7156 sas_target_priv_data->handle = handle;
7157 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7161 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7165 * _scsih_search_responding_raid_devices -
7166 * @ioc: per adapter object
7168 * After host reset, find out whether devices are still responding.
7174 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc)
7176 Mpi2RaidVolPage1_t volume_pg1;
7177 Mpi2RaidVolPage0_t volume_pg0;
7178 Mpi2RaidPhysDiskPage0_t pd_pg0;
7179 Mpi2ConfigReply_t mpi_reply;
7184 if (!ioc->ir_firmware)
7187 pr_info(MPT3SAS_FMT "search for raid volumes: start\n",
7190 if (list_empty(&ioc->raid_device_list))
7194 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7195 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7196 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7197 MPI2_IOCSTATUS_MASK;
7198 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7200 handle = le16_to_cpu(volume_pg1.DevHandle);
7202 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7203 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7204 sizeof(Mpi2RaidVolPage0_t)))
7207 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7208 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7209 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7210 _scsih_mark_responding_raid_device(ioc,
7211 le64_to_cpu(volume_pg1.WWID), handle);
7214 /* refresh the pd_handles */
7215 if (!ioc->is_warpdrive) {
7216 phys_disk_num = 0xFF;
7217 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7218 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7219 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7221 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7222 MPI2_IOCSTATUS_MASK;
7223 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7225 phys_disk_num = pd_pg0.PhysDiskNum;
7226 handle = le16_to_cpu(pd_pg0.DevHandle);
7227 set_bit(handle, ioc->pd_handles);
7231 pr_info(MPT3SAS_FMT "search for responding raid volumes: complete\n",
7236 * _scsih_mark_responding_expander - mark a expander as responding
7237 * @ioc: per adapter object
7238 * @sas_address: sas address
7241 * After host reset, find out whether devices are still responding.
7242 * Used in _scsih_remove_unresponsive_expanders.
7247 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
7250 struct _sas_node *sas_expander;
7251 unsigned long flags;
7254 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7255 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7256 if (sas_expander->sas_address != sas_address)
7258 sas_expander->responding = 1;
7259 if (sas_expander->handle == handle)
7261 pr_info("\texpander(0x%016llx): handle changed" \
7262 " from(0x%04x) to (0x%04x)!!!\n",
7263 (unsigned long long)sas_expander->sas_address,
7264 sas_expander->handle, handle);
7265 sas_expander->handle = handle;
7266 for (i = 0 ; i < sas_expander->num_phys ; i++)
7267 sas_expander->phy[i].handle = handle;
7271 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7275 * _scsih_search_responding_expanders -
7276 * @ioc: per adapter object
7278 * After host reset, find out whether devices are still responding.
7284 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc)
7286 Mpi2ExpanderPage0_t expander_pg0;
7287 Mpi2ConfigReply_t mpi_reply;
7292 pr_info(MPT3SAS_FMT "search for expanders: start\n", ioc->name);
7294 if (list_empty(&ioc->sas_expander_list))
7298 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7299 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7301 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7302 MPI2_IOCSTATUS_MASK;
7303 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7306 handle = le16_to_cpu(expander_pg0.DevHandle);
7307 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7308 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
7310 (unsigned long long)sas_address);
7311 _scsih_mark_responding_expander(ioc, sas_address, handle);
7315 pr_info(MPT3SAS_FMT "search for expanders: complete\n", ioc->name);
7319 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7320 * @ioc: per adapter object
7325 _scsih_remove_unresponding_sas_devices(struct MPT3SAS_ADAPTER *ioc)
7327 struct _sas_device *sas_device, *sas_device_next;
7328 struct _sas_node *sas_expander, *sas_expander_next;
7329 struct _raid_device *raid_device, *raid_device_next;
7330 struct list_head tmp_list;
7331 unsigned long flags;
7334 pr_info(MPT3SAS_FMT "removing unresponding devices: start\n",
7337 /* removing unresponding end devices */
7338 pr_info(MPT3SAS_FMT "removing unresponding devices: end-devices\n",
7341 * Iterate, pulling off devices marked as non-responding. We become the
7342 * owner for the reference the list had on any object we prune.
7344 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7345 list_for_each_entry_safe(sas_device, sas_device_next,
7346 &ioc->sas_device_list, list) {
7347 if (!sas_device->responding)
7348 list_move_tail(&sas_device->list, &head);
7350 sas_device->responding = 0;
7352 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7355 * Now, uninitialize and remove the unresponding devices we pruned.
7357 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7358 _scsih_remove_device(ioc, sas_device);
7359 list_del_init(&sas_device->list);
7360 sas_device_put(sas_device);
7363 /* removing unresponding volumes */
7364 if (ioc->ir_firmware) {
7365 pr_info(MPT3SAS_FMT "removing unresponding devices: volumes\n",
7367 list_for_each_entry_safe(raid_device, raid_device_next,
7368 &ioc->raid_device_list, list) {
7369 if (!raid_device->responding)
7370 _scsih_sas_volume_delete(ioc,
7371 raid_device->handle);
7373 raid_device->responding = 0;
7377 /* removing unresponding expanders */
7378 pr_info(MPT3SAS_FMT "removing unresponding devices: expanders\n",
7380 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7381 INIT_LIST_HEAD(&tmp_list);
7382 list_for_each_entry_safe(sas_expander, sas_expander_next,
7383 &ioc->sas_expander_list, list) {
7384 if (!sas_expander->responding)
7385 list_move_tail(&sas_expander->list, &tmp_list);
7387 sas_expander->responding = 0;
7389 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7390 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7392 list_del(&sas_expander->list);
7393 _scsih_expander_node_remove(ioc, sas_expander);
7396 pr_info(MPT3SAS_FMT "removing unresponding devices: complete\n",
7399 /* unblock devices */
7400 _scsih_ublock_io_all_device(ioc);
7404 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER *ioc,
7405 struct _sas_node *sas_expander, u16 handle)
7407 Mpi2ExpanderPage1_t expander_pg1;
7408 Mpi2ConfigReply_t mpi_reply;
7411 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7412 if ((mpt3sas_config_get_expander_pg1(ioc, &mpi_reply,
7413 &expander_pg1, i, handle))) {
7414 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7415 ioc->name, __FILE__, __LINE__, __func__);
7419 mpt3sas_transport_update_links(ioc, sas_expander->sas_address,
7420 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7421 expander_pg1.NegotiatedLinkRate >> 4);
7426 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7427 * @ioc: per adapter object
7432 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER *ioc)
7434 Mpi2ExpanderPage0_t expander_pg0;
7435 Mpi2SasDevicePage0_t sas_device_pg0;
7436 Mpi2RaidVolPage1_t volume_pg1;
7437 Mpi2RaidVolPage0_t volume_pg0;
7438 Mpi2RaidPhysDiskPage0_t pd_pg0;
7439 Mpi2EventIrConfigElement_t element;
7440 Mpi2ConfigReply_t mpi_reply;
7443 u16 handle, parent_handle;
7445 struct _sas_device *sas_device;
7446 struct _sas_node *expander_device;
7447 static struct _raid_device *raid_device;
7449 unsigned long flags;
7451 pr_info(MPT3SAS_FMT "scan devices: start\n", ioc->name);
7453 _scsih_sas_host_refresh(ioc);
7455 pr_info(MPT3SAS_FMT "\tscan devices: expanders start\n", ioc->name);
7459 while (!(mpt3sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7460 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7461 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7462 MPI2_IOCSTATUS_MASK;
7463 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7464 pr_info(MPT3SAS_FMT "\tbreak from expander scan: " \
7465 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7466 ioc->name, ioc_status,
7467 le32_to_cpu(mpi_reply.IOCLogInfo));
7470 handle = le16_to_cpu(expander_pg0.DevHandle);
7471 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7472 expander_device = mpt3sas_scsih_expander_find_by_sas_address(
7473 ioc, le64_to_cpu(expander_pg0.SASAddress));
7474 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7475 if (expander_device)
7476 _scsih_refresh_expander_links(ioc, expander_device,
7479 pr_info(MPT3SAS_FMT "\tBEFORE adding expander: " \
7480 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7481 handle, (unsigned long long)
7482 le64_to_cpu(expander_pg0.SASAddress));
7483 _scsih_expander_add(ioc, handle);
7484 pr_info(MPT3SAS_FMT "\tAFTER adding expander: " \
7485 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7486 handle, (unsigned long long)
7487 le64_to_cpu(expander_pg0.SASAddress));
7491 pr_info(MPT3SAS_FMT "\tscan devices: expanders complete\n",
7494 if (!ioc->ir_firmware)
7497 pr_info(MPT3SAS_FMT "\tscan devices: phys disk start\n", ioc->name);
7500 phys_disk_num = 0xFF;
7501 while (!(mpt3sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7502 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7504 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7505 MPI2_IOCSTATUS_MASK;
7506 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7507 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan: "\
7508 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7509 ioc->name, ioc_status,
7510 le32_to_cpu(mpi_reply.IOCLogInfo));
7513 phys_disk_num = pd_pg0.PhysDiskNum;
7514 handle = le16_to_cpu(pd_pg0.DevHandle);
7515 sas_device = mpt3sas_get_sdev_by_handle(ioc, handle);
7517 sas_device_put(sas_device);
7520 if (mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7521 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7524 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7525 MPI2_IOCSTATUS_MASK;
7526 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7527 pr_info(MPT3SAS_FMT "\tbreak from phys disk scan " \
7528 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7529 ioc->name, ioc_status,
7530 le32_to_cpu(mpi_reply.IOCLogInfo));
7533 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7534 if (!_scsih_get_sas_address(ioc, parent_handle,
7536 pr_info(MPT3SAS_FMT "\tBEFORE adding phys disk: " \
7537 " handle (0x%04x), sas_addr(0x%016llx)\n",
7538 ioc->name, handle, (unsigned long long)
7539 le64_to_cpu(sas_device_pg0.SASAddress));
7540 mpt3sas_transport_update_links(ioc, sas_address,
7541 handle, sas_device_pg0.PhyNum,
7542 MPI2_SAS_NEG_LINK_RATE_1_5);
7543 set_bit(handle, ioc->pd_handles);
7545 /* This will retry adding the end device.
7546 * _scsih_add_device() will decide on retries and
7547 * return "1" when it should be retried
7549 while (_scsih_add_device(ioc, handle, retry_count++,
7553 pr_info(MPT3SAS_FMT "\tAFTER adding phys disk: " \
7554 " handle (0x%04x), sas_addr(0x%016llx)\n",
7555 ioc->name, handle, (unsigned long long)
7556 le64_to_cpu(sas_device_pg0.SASAddress));
7560 pr_info(MPT3SAS_FMT "\tscan devices: phys disk complete\n",
7563 pr_info(MPT3SAS_FMT "\tscan devices: volumes start\n", ioc->name);
7567 while (!(mpt3sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7568 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7569 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7570 MPI2_IOCSTATUS_MASK;
7571 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7572 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7573 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7574 ioc->name, ioc_status,
7575 le32_to_cpu(mpi_reply.IOCLogInfo));
7578 handle = le16_to_cpu(volume_pg1.DevHandle);
7579 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7580 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7581 le64_to_cpu(volume_pg1.WWID));
7582 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7585 if (mpt3sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7586 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7587 sizeof(Mpi2RaidVolPage0_t)))
7589 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7590 MPI2_IOCSTATUS_MASK;
7591 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7592 pr_info(MPT3SAS_FMT "\tbreak from volume scan: " \
7593 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7594 ioc->name, ioc_status,
7595 le32_to_cpu(mpi_reply.IOCLogInfo));
7598 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7599 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7600 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7601 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7602 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7603 element.VolDevHandle = volume_pg1.DevHandle;
7605 "\tBEFORE adding volume: handle (0x%04x)\n",
7606 ioc->name, volume_pg1.DevHandle);
7607 _scsih_sas_volume_add(ioc, &element);
7609 "\tAFTER adding volume: handle (0x%04x)\n",
7610 ioc->name, volume_pg1.DevHandle);
7614 pr_info(MPT3SAS_FMT "\tscan devices: volumes complete\n",
7619 pr_info(MPT3SAS_FMT "\tscan devices: end devices start\n",
7624 while (!(mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7625 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7627 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7628 MPI2_IOCSTATUS_MASK;
7629 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7630 pr_info(MPT3SAS_FMT "\tbreak from end device scan:"\
7631 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7632 ioc->name, ioc_status,
7633 le32_to_cpu(mpi_reply.IOCLogInfo));
7636 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7637 if (!(_scsih_is_end_device(
7638 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7640 sas_device = mpt3sas_get_sdev_by_addr(ioc,
7641 le64_to_cpu(sas_device_pg0.SASAddress));
7643 sas_device_put(sas_device);
7646 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7647 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7648 pr_info(MPT3SAS_FMT "\tBEFORE adding end device: " \
7649 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7650 handle, (unsigned long long)
7651 le64_to_cpu(sas_device_pg0.SASAddress));
7652 mpt3sas_transport_update_links(ioc, sas_address, handle,
7653 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7655 /* This will retry adding the end device.
7656 * _scsih_add_device() will decide on retries and
7657 * return "1" when it should be retried
7659 while (_scsih_add_device(ioc, handle, retry_count++,
7663 pr_info(MPT3SAS_FMT "\tAFTER adding end device: " \
7664 "handle (0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7665 handle, (unsigned long long)
7666 le64_to_cpu(sas_device_pg0.SASAddress));
7669 pr_info(MPT3SAS_FMT "\tscan devices: end devices complete\n",
7672 pr_info(MPT3SAS_FMT "scan devices: complete\n", ioc->name);
7675 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
7676 * @ioc: per adapter object
7677 * @reset_phase: phase
7679 * The handler for doing any required cleanup or initialization.
7681 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
7682 * MPT3_IOC_DONE_RESET
7687 mpt3sas_scsih_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
7689 switch (reset_phase) {
7690 case MPT3_IOC_PRE_RESET:
7691 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7692 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
7694 case MPT3_IOC_AFTER_RESET:
7695 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7696 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
7697 if (ioc->scsih_cmds.status & MPT3_CMD_PENDING) {
7698 ioc->scsih_cmds.status |= MPT3_CMD_RESET;
7699 mpt3sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7700 complete(&ioc->scsih_cmds.done);
7702 if (ioc->tm_cmds.status & MPT3_CMD_PENDING) {
7703 ioc->tm_cmds.status |= MPT3_CMD_RESET;
7704 mpt3sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7705 complete(&ioc->tm_cmds.done);
7708 _scsih_fw_event_cleanup_queue(ioc);
7709 _scsih_flush_running_cmds(ioc);
7711 case MPT3_IOC_DONE_RESET:
7712 dtmprintk(ioc, pr_info(MPT3SAS_FMT
7713 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
7714 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7715 !ioc->sas_hba.num_phys)) {
7716 _scsih_prep_device_scan(ioc);
7717 _scsih_search_responding_sas_devices(ioc);
7718 _scsih_search_responding_raid_devices(ioc);
7719 _scsih_search_responding_expanders(ioc);
7720 _scsih_error_recovery_delete_devices(ioc);
7727 * _mpt3sas_fw_work - delayed task for processing firmware events
7728 * @ioc: per adapter object
7729 * @fw_event: The fw_event_work object
7735 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
7737 _scsih_fw_event_del_from_list(ioc, fw_event);
7739 /* the queue is being flushed so ignore this event */
7740 if (ioc->remove_host || ioc->pci_error_recovery) {
7741 fw_event_work_put(fw_event);
7745 switch (fw_event->event) {
7746 case MPT3SAS_PROCESS_TRIGGER_DIAG:
7747 mpt3sas_process_trigger_data(ioc,
7748 (struct SL_WH_TRIGGERS_EVENT_DATA_T *)
7749 fw_event->event_data);
7751 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES:
7752 while (scsi_host_in_recovery(ioc->shost) ||
7753 ioc->shost_recovery) {
7755 * If we're unloading, bail. Otherwise, this can become
7758 if (ioc->remove_host)
7762 _scsih_remove_unresponding_sas_devices(ioc);
7763 _scsih_scan_for_devices_after_reset(ioc);
7765 case MPT3SAS_PORT_ENABLE_COMPLETE:
7766 ioc->start_scan = 0;
7767 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7768 mpt3sas_base_update_missing_delay(ioc, missing_delay[0],
7770 dewtprintk(ioc, pr_info(MPT3SAS_FMT
7771 "port enable: complete from worker thread\n",
7774 case MPT3SAS_TURN_ON_PFA_LED:
7775 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7777 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7778 _scsih_sas_topology_change_event(ioc, fw_event);
7780 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7781 _scsih_sas_device_status_change_event(ioc, fw_event);
7783 case MPI2_EVENT_SAS_DISCOVERY:
7784 _scsih_sas_discovery_event(ioc, fw_event);
7786 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7787 _scsih_sas_broadcast_primitive_event(ioc, fw_event);
7789 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7790 _scsih_sas_enclosure_dev_status_change_event(ioc,
7793 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7794 _scsih_sas_ir_config_change_event(ioc, fw_event);
7796 case MPI2_EVENT_IR_VOLUME:
7797 _scsih_sas_ir_volume_event(ioc, fw_event);
7799 case MPI2_EVENT_IR_PHYSICAL_DISK:
7800 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7802 case MPI2_EVENT_IR_OPERATION_STATUS:
7803 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7807 fw_event_work_put(fw_event);
7811 * _firmware_event_work
7812 * @ioc: per adapter object
7813 * @work: The fw_event_work object
7816 * wrappers for the work thread handling firmware events
7822 _firmware_event_work(struct work_struct *work)
7824 struct fw_event_work *fw_event = container_of(work,
7825 struct fw_event_work, work);
7827 _mpt3sas_fw_work(fw_event->ioc, fw_event);
7831 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
7832 * @ioc: per adapter object
7833 * @msix_index: MSIX table index supplied by the OS
7834 * @reply: reply message frame(lower 32bit addr)
7835 * Context: interrupt.
7837 * This function merely adds a new work task into ioc->firmware_event_thread.
7838 * The tasks are worked from _firmware_event_work in user context.
7840 * Return 1 meaning mf should be freed from _base_interrupt
7841 * 0 means the mf is freed from this function.
7844 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
7847 struct fw_event_work *fw_event;
7848 Mpi2EventNotificationReply_t *mpi_reply;
7852 /* events turned off due to host reset or driver unloading */
7853 if (ioc->remove_host || ioc->pci_error_recovery)
7856 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
7858 if (unlikely(!mpi_reply)) {
7859 pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7860 ioc->name, __FILE__, __LINE__, __func__);
7864 event = le16_to_cpu(mpi_reply->Event);
7866 if (event != MPI2_EVENT_LOG_ENTRY_ADDED)
7867 mpt3sas_trigger_event(ioc, event, 0);
7871 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7873 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7874 (Mpi2EventDataSasBroadcastPrimitive_t *)
7875 mpi_reply->EventData;
7877 if (baen_data->Primitive !=
7878 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7881 if (ioc->broadcast_aen_busy) {
7882 ioc->broadcast_aen_pending++;
7885 ioc->broadcast_aen_busy = 1;
7889 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7890 _scsih_check_topo_delete_events(ioc,
7891 (Mpi2EventDataSasTopologyChangeList_t *)
7892 mpi_reply->EventData);
7894 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7895 _scsih_check_ir_config_unhide_events(ioc,
7896 (Mpi2EventDataIrConfigChangeList_t *)
7897 mpi_reply->EventData);
7899 case MPI2_EVENT_IR_VOLUME:
7900 _scsih_check_volume_delete_events(ioc,
7901 (Mpi2EventDataIrVolume_t *)
7902 mpi_reply->EventData);
7904 case MPI2_EVENT_LOG_ENTRY_ADDED:
7906 Mpi2EventDataLogEntryAdded_t *log_entry;
7909 if (!ioc->is_warpdrive)
7912 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7913 mpi_reply->EventData;
7914 log_code = (u32 *)log_entry->LogData;
7916 if (le16_to_cpu(log_entry->LogEntryQualifier)
7917 != MPT2_WARPDRIVE_LOGENTRY)
7920 switch (le32_to_cpu(*log_code)) {
7921 case MPT2_WARPDRIVE_LC_SSDT:
7922 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7923 "IO Throttling has occurred in the WarpDrive "
7924 "subsystem. Check WarpDrive documentation for "
7925 "additional details.\n", ioc->name);
7927 case MPT2_WARPDRIVE_LC_SSDLW:
7928 pr_warn(MPT3SAS_FMT "WarpDrive Warning: "
7929 "Program/Erase Cycles for the WarpDrive subsystem "
7930 "in degraded range. Check WarpDrive documentation "
7931 "for additional details.\n", ioc->name);
7933 case MPT2_WARPDRIVE_LC_SSDLF:
7934 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7935 "There are no Program/Erase Cycles for the "
7936 "WarpDrive subsystem. The storage device will be "
7937 "in read-only mode. Check WarpDrive documentation "
7938 "for additional details.\n", ioc->name);
7940 case MPT2_WARPDRIVE_LC_BRMF:
7941 pr_err(MPT3SAS_FMT "WarpDrive Fatal Error: "
7942 "The Backup Rail Monitor has failed on the "
7943 "WarpDrive subsystem. Check WarpDrive "
7944 "documentation for additional details.\n",
7951 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7952 case MPI2_EVENT_IR_OPERATION_STATUS:
7953 case MPI2_EVENT_SAS_DISCOVERY:
7954 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7955 case MPI2_EVENT_IR_PHYSICAL_DISK:
7958 case MPI2_EVENT_TEMP_THRESHOLD:
7959 _scsih_temp_threshold_events(ioc,
7960 (Mpi2EventDataTemperature_t *)
7961 mpi_reply->EventData);
7964 default: /* ignore the rest */
7968 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7969 fw_event = alloc_fw_event_work(sz);
7971 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
7972 ioc->name, __FILE__, __LINE__, __func__);
7976 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7977 fw_event->ioc = ioc;
7978 fw_event->VF_ID = mpi_reply->VF_ID;
7979 fw_event->VP_ID = mpi_reply->VP_ID;
7980 fw_event->event = event;
7981 _scsih_fw_event_add(ioc, fw_event);
7982 fw_event_work_put(fw_event);
7987 * _scsih_expander_node_remove - removing expander device from list.
7988 * @ioc: per adapter object
7989 * @sas_expander: the sas_device object
7990 * Context: Calling function should acquire ioc->sas_node_lock.
7992 * Removing object and freeing associated memory from the
7993 * ioc->sas_expander_list.
7998 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
7999 struct _sas_node *sas_expander)
8001 struct _sas_port *mpt3sas_port, *next;
8003 /* remove sibling ports attached to this expander */
8004 list_for_each_entry_safe(mpt3sas_port, next,
8005 &sas_expander->sas_port_list, port_list) {
8006 if (ioc->shost_recovery)
8008 if (mpt3sas_port->remote_identify.device_type ==
8010 mpt3sas_device_remove_by_sas_address(ioc,
8011 mpt3sas_port->remote_identify.sas_address);
8012 else if (mpt3sas_port->remote_identify.device_type ==
8013 SAS_EDGE_EXPANDER_DEVICE ||
8014 mpt3sas_port->remote_identify.device_type ==
8015 SAS_FANOUT_EXPANDER_DEVICE)
8016 mpt3sas_expander_remove(ioc,
8017 mpt3sas_port->remote_identify.sas_address);
8020 mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
8021 sas_expander->sas_address_parent);
8024 "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
8026 sas_expander->handle, (unsigned long long)
8027 sas_expander->sas_address);
8029 kfree(sas_expander->phy);
8030 kfree(sas_expander);
8034 * _scsih_ir_shutdown - IR shutdown notification
8035 * @ioc: per adapter object
8037 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
8038 * the host system is shutting down.
8043 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc)
8045 Mpi2RaidActionRequest_t *mpi_request;
8046 Mpi2RaidActionReply_t *mpi_reply;
8049 /* is IR firmware build loaded ? */
8050 if (!ioc->ir_firmware)
8053 /* are there any volumes ? */
8054 if (list_empty(&ioc->raid_device_list))
8057 mutex_lock(&ioc->scsih_cmds.mutex);
8059 if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {
8060 pr_err(MPT3SAS_FMT "%s: scsih_cmd in use\n",
8061 ioc->name, __func__);
8064 ioc->scsih_cmds.status = MPT3_CMD_PENDING;
8066 smid = mpt3sas_base_get_smid(ioc, ioc->scsih_cb_idx);
8068 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
8069 ioc->name, __func__);
8070 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8074 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
8075 ioc->scsih_cmds.smid = smid;
8076 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
8078 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
8079 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
8081 if (!ioc->hide_ir_msg)
8082 pr_info(MPT3SAS_FMT "IR shutdown (sending)\n", ioc->name);
8083 init_completion(&ioc->scsih_cmds.done);
8084 mpt3sas_base_put_smid_default(ioc, smid);
8085 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
8087 if (!(ioc->scsih_cmds.status & MPT3_CMD_COMPLETE)) {
8088 pr_err(MPT3SAS_FMT "%s: timeout\n",
8089 ioc->name, __func__);
8093 if (ioc->scsih_cmds.status & MPT3_CMD_REPLY_VALID) {
8094 mpi_reply = ioc->scsih_cmds.reply;
8095 if (!ioc->hide_ir_msg)
8096 pr_info(MPT3SAS_FMT "IR shutdown "
8097 "(complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
8098 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
8099 le32_to_cpu(mpi_reply->IOCLogInfo));
8103 ioc->scsih_cmds.status = MPT3_CMD_NOT_USED;
8104 mutex_unlock(&ioc->scsih_cmds.mutex);
8108 * scsih_remove - detach and remove add host
8109 * @pdev: PCI device struct
8111 * Routine called when unloading the driver.
8114 void scsih_remove(struct pci_dev *pdev)
8116 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8117 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8118 struct _sas_port *mpt3sas_port, *next_port;
8119 struct _raid_device *raid_device, *next;
8120 struct MPT3SAS_TARGET *sas_target_priv_data;
8121 struct workqueue_struct *wq;
8122 unsigned long flags;
8124 ioc->remove_host = 1;
8125 _scsih_fw_event_cleanup_queue(ioc);
8127 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8128 wq = ioc->firmware_event_thread;
8129 ioc->firmware_event_thread = NULL;
8130 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8132 destroy_workqueue(wq);
8134 /* release all the volumes */
8135 _scsih_ir_shutdown(ioc);
8136 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8138 if (raid_device->starget) {
8139 sas_target_priv_data =
8140 raid_device->starget->hostdata;
8141 sas_target_priv_data->deleted = 1;
8142 scsi_remove_target(&raid_device->starget->dev);
8144 pr_info(MPT3SAS_FMT "removing handle(0x%04x), wwid(0x%016llx)\n",
8145 ioc->name, raid_device->handle,
8146 (unsigned long long) raid_device->wwid);
8147 _scsih_raid_device_remove(ioc, raid_device);
8150 /* free ports attached to the sas_host */
8151 list_for_each_entry_safe(mpt3sas_port, next_port,
8152 &ioc->sas_hba.sas_port_list, port_list) {
8153 if (mpt3sas_port->remote_identify.device_type ==
8155 mpt3sas_device_remove_by_sas_address(ioc,
8156 mpt3sas_port->remote_identify.sas_address);
8157 else if (mpt3sas_port->remote_identify.device_type ==
8158 SAS_EDGE_EXPANDER_DEVICE ||
8159 mpt3sas_port->remote_identify.device_type ==
8160 SAS_FANOUT_EXPANDER_DEVICE)
8161 mpt3sas_expander_remove(ioc,
8162 mpt3sas_port->remote_identify.sas_address);
8165 /* free phys attached to the sas_host */
8166 if (ioc->sas_hba.num_phys) {
8167 kfree(ioc->sas_hba.phy);
8168 ioc->sas_hba.phy = NULL;
8169 ioc->sas_hba.num_phys = 0;
8172 sas_remove_host(shost);
8173 scsi_remove_host(shost);
8174 mpt3sas_base_detach(ioc);
8175 spin_lock(&gioc_lock);
8176 list_del(&ioc->list);
8177 spin_unlock(&gioc_lock);
8178 scsi_host_put(shost);
8182 * scsih_shutdown - routine call during system shutdown
8183 * @pdev: PCI device struct
8188 scsih_shutdown(struct pci_dev *pdev)
8190 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8191 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8192 struct workqueue_struct *wq;
8193 unsigned long flags;
8195 ioc->remove_host = 1;
8196 _scsih_fw_event_cleanup_queue(ioc);
8198 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8199 wq = ioc->firmware_event_thread;
8200 ioc->firmware_event_thread = NULL;
8201 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8203 destroy_workqueue(wq);
8205 _scsih_ir_shutdown(ioc);
8206 mpt3sas_base_detach(ioc);
8211 * _scsih_probe_boot_devices - reports 1st device
8212 * @ioc: per adapter object
8214 * If specified in bios page 2, this routine reports the 1st
8215 * device scsi-ml or sas transport for persistent boot device
8216 * purposes. Please refer to function _scsih_determine_boot_device()
8219 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER *ioc)
8223 struct _sas_device *sas_device;
8224 struct _raid_device *raid_device;
8226 u64 sas_address_parent;
8228 unsigned long flags;
8231 /* no Bios, return immediately */
8232 if (!ioc->bios_pg3.BiosVersion)
8237 if (ioc->req_boot_device.device) {
8238 device = ioc->req_boot_device.device;
8239 is_raid = ioc->req_boot_device.is_raid;
8240 } else if (ioc->req_alt_boot_device.device) {
8241 device = ioc->req_alt_boot_device.device;
8242 is_raid = ioc->req_alt_boot_device.is_raid;
8243 } else if (ioc->current_boot_device.device) {
8244 device = ioc->current_boot_device.device;
8245 is_raid = ioc->current_boot_device.is_raid;
8252 raid_device = device;
8253 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8254 raid_device->id, 0);
8256 _scsih_raid_device_remove(ioc, raid_device);
8258 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8259 sas_device = device;
8260 handle = sas_device->handle;
8261 sas_address_parent = sas_device->sas_address_parent;
8262 sas_address = sas_device->sas_address;
8263 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8264 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8266 if (ioc->hide_drives)
8268 if (!mpt3sas_transport_port_add(ioc, handle,
8269 sas_address_parent)) {
8270 _scsih_sas_device_remove(ioc, sas_device);
8271 } else if (!sas_device->starget) {
8272 if (!ioc->is_driver_loading) {
8273 mpt3sas_transport_port_remove(ioc,
8275 sas_address_parent);
8276 _scsih_sas_device_remove(ioc, sas_device);
8283 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8284 * @ioc: per adapter object
8286 * Called during initial loading of the driver.
8289 _scsih_probe_raid(struct MPT3SAS_ADAPTER *ioc)
8291 struct _raid_device *raid_device, *raid_next;
8294 list_for_each_entry_safe(raid_device, raid_next,
8295 &ioc->raid_device_list, list) {
8296 if (raid_device->starget)
8298 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8299 raid_device->id, 0);
8301 _scsih_raid_device_remove(ioc, raid_device);
8305 static struct _sas_device *get_next_sas_device(struct MPT3SAS_ADAPTER *ioc)
8307 struct _sas_device *sas_device = NULL;
8308 unsigned long flags;
8310 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8311 if (!list_empty(&ioc->sas_device_init_list)) {
8312 sas_device = list_first_entry(&ioc->sas_device_init_list,
8313 struct _sas_device, list);
8314 sas_device_get(sas_device);
8316 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8321 static void sas_device_make_active(struct MPT3SAS_ADAPTER *ioc,
8322 struct _sas_device *sas_device)
8324 unsigned long flags;
8326 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8329 * Since we dropped the lock during the call to port_add(), we need to
8330 * be careful here that somebody else didn't move or delete this item
8331 * while we were busy with other things.
8333 * If it was on the list, we need a put() for the reference the list
8334 * had. Either way, we need a get() for the destination list.
8336 if (!list_empty(&sas_device->list)) {
8337 list_del_init(&sas_device->list);
8338 sas_device_put(sas_device);
8341 sas_device_get(sas_device);
8342 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8344 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8348 * _scsih_probe_sas - reporting sas devices to sas transport
8349 * @ioc: per adapter object
8351 * Called during initial loading of the driver.
8354 _scsih_probe_sas(struct MPT3SAS_ADAPTER *ioc)
8356 struct _sas_device *sas_device;
8358 if (ioc->hide_drives)
8361 while ((sas_device = get_next_sas_device(ioc))) {
8362 if (!mpt3sas_transport_port_add(ioc, sas_device->handle,
8363 sas_device->sas_address_parent)) {
8364 _scsih_sas_device_remove(ioc, sas_device);
8365 sas_device_put(sas_device);
8367 } else if (!sas_device->starget) {
8369 * When asyn scanning is enabled, its not possible to
8370 * remove devices while scanning is turned on due to an
8371 * oops in scsi_sysfs_add_sdev()->add_device()->
8372 * sysfs_addrm_start()
8374 if (!ioc->is_driver_loading) {
8375 mpt3sas_transport_port_remove(ioc,
8376 sas_device->sas_address,
8377 sas_device->sas_address_parent);
8378 _scsih_sas_device_remove(ioc, sas_device);
8379 sas_device_put(sas_device);
8383 sas_device_make_active(ioc, sas_device);
8384 sas_device_put(sas_device);
8389 * _scsih_probe_devices - probing for devices
8390 * @ioc: per adapter object
8392 * Called during initial loading of the driver.
8395 _scsih_probe_devices(struct MPT3SAS_ADAPTER *ioc)
8397 u16 volume_mapping_flags;
8399 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8400 return; /* return when IOC doesn't support initiator mode */
8402 _scsih_probe_boot_devices(ioc);
8404 if (ioc->ir_firmware) {
8405 volume_mapping_flags =
8406 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8407 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8408 if (volume_mapping_flags ==
8409 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8410 _scsih_probe_raid(ioc);
8411 _scsih_probe_sas(ioc);
8413 _scsih_probe_sas(ioc);
8414 _scsih_probe_raid(ioc);
8417 _scsih_probe_sas(ioc);
8421 * scsih_scan_start - scsi lld callback for .scan_start
8422 * @shost: SCSI host pointer
8424 * The shost has the ability to discover targets on its own instead
8425 * of scanning the entire bus. In our implemention, we will kick off
8426 * firmware discovery.
8429 scsih_scan_start(struct Scsi_Host *shost)
8431 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8433 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8434 mpt3sas_enable_diag_buffer(ioc, diag_buffer_enable);
8436 if (disable_discovery > 0)
8439 ioc->start_scan = 1;
8440 rc = mpt3sas_port_enable(ioc);
8443 pr_info(MPT3SAS_FMT "port enable: FAILED\n", ioc->name);
8447 * scsih_scan_finished - scsi lld callback for .scan_finished
8448 * @shost: SCSI host pointer
8449 * @time: elapsed time of the scan in jiffies
8451 * This function will be called periodicallyn until it returns 1 with the
8452 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8453 * we wait for firmware discovery to complete, then return 1.
8456 scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8458 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8460 if (disable_discovery > 0) {
8461 ioc->is_driver_loading = 0;
8462 ioc->wait_for_discovery_to_complete = 0;
8466 if (time >= (300 * HZ)) {
8467 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8469 "port enable: FAILED with timeout (timeout=300s)\n",
8471 ioc->is_driver_loading = 0;
8475 if (ioc->start_scan)
8478 if (ioc->start_scan_failed) {
8480 "port enable: FAILED with (ioc_status=0x%08x)\n",
8481 ioc->name, ioc->start_scan_failed);
8482 ioc->is_driver_loading = 0;
8483 ioc->wait_for_discovery_to_complete = 0;
8484 ioc->remove_host = 1;
8488 pr_info(MPT3SAS_FMT "port enable: SUCCESS\n", ioc->name);
8489 ioc->base_cmds.status = MPT3_CMD_NOT_USED;
8491 if (ioc->wait_for_discovery_to_complete) {
8492 ioc->wait_for_discovery_to_complete = 0;
8493 _scsih_probe_devices(ioc);
8495 mpt3sas_base_start_watchdog(ioc);
8496 ioc->is_driver_loading = 0;
8500 /* shost template for SAS 2.0 HBA devices */
8501 static struct scsi_host_template mpt2sas_driver_template = {
8502 .module = THIS_MODULE,
8503 .name = "Fusion MPT SAS Host",
8504 .proc_name = MPT2SAS_DRIVER_NAME,
8505 .queuecommand = scsih_qcmd,
8506 .target_alloc = scsih_target_alloc,
8507 .slave_alloc = scsih_slave_alloc,
8508 .slave_configure = scsih_slave_configure,
8509 .target_destroy = scsih_target_destroy,
8510 .slave_destroy = scsih_slave_destroy,
8511 .scan_finished = scsih_scan_finished,
8512 .scan_start = scsih_scan_start,
8513 .change_queue_depth = scsih_change_queue_depth,
8514 .eh_abort_handler = scsih_abort,
8515 .eh_device_reset_handler = scsih_dev_reset,
8516 .eh_target_reset_handler = scsih_target_reset,
8517 .eh_host_reset_handler = scsih_host_reset,
8518 .bios_param = scsih_bios_param,
8521 .sg_tablesize = MPT2SAS_SG_DEPTH,
8522 .max_sectors = 32767,
8524 .use_clustering = ENABLE_CLUSTERING,
8525 .shost_attrs = mpt3sas_host_attrs,
8526 .sdev_attrs = mpt3sas_dev_attrs,
8527 .track_queue_depth = 1,
8530 /* raid transport support for SAS 2.0 HBA devices */
8531 static struct raid_function_template mpt2sas_raid_functions = {
8532 .cookie = &mpt2sas_driver_template,
8533 .is_raid = scsih_is_raid,
8534 .get_resync = scsih_get_resync,
8535 .get_state = scsih_get_state,
8538 /* shost template for SAS 3.0 HBA devices */
8539 static struct scsi_host_template mpt3sas_driver_template = {
8540 .module = THIS_MODULE,
8541 .name = "Fusion MPT SAS Host",
8542 .proc_name = MPT3SAS_DRIVER_NAME,
8543 .queuecommand = scsih_qcmd,
8544 .target_alloc = scsih_target_alloc,
8545 .slave_alloc = scsih_slave_alloc,
8546 .slave_configure = scsih_slave_configure,
8547 .target_destroy = scsih_target_destroy,
8548 .slave_destroy = scsih_slave_destroy,
8549 .scan_finished = scsih_scan_finished,
8550 .scan_start = scsih_scan_start,
8551 .change_queue_depth = scsih_change_queue_depth,
8552 .eh_abort_handler = scsih_abort,
8553 .eh_device_reset_handler = scsih_dev_reset,
8554 .eh_target_reset_handler = scsih_target_reset,
8555 .eh_host_reset_handler = scsih_host_reset,
8556 .bios_param = scsih_bios_param,
8559 .sg_tablesize = MPT3SAS_SG_DEPTH,
8560 .max_sectors = 32767,
8562 .use_clustering = ENABLE_CLUSTERING,
8563 .shost_attrs = mpt3sas_host_attrs,
8564 .sdev_attrs = mpt3sas_dev_attrs,
8565 .track_queue_depth = 1,
8568 /* raid transport support for SAS 3.0 HBA devices */
8569 static struct raid_function_template mpt3sas_raid_functions = {
8570 .cookie = &mpt3sas_driver_template,
8571 .is_raid = scsih_is_raid,
8572 .get_resync = scsih_get_resync,
8573 .get_state = scsih_get_state,
8577 * _scsih_determine_hba_mpi_version - determine in which MPI version class
8578 * this device belongs to.
8579 * @pdev: PCI device struct
8581 * return MPI2_VERSION for SAS 2.0 HBA devices,
8582 * MPI25_VERSION for SAS 3.0 HBA devices, and
8583 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
8586 _scsih_determine_hba_mpi_version(struct pci_dev *pdev)
8589 switch (pdev->device) {
8590 case MPI2_MFGPAGE_DEVID_SSS6200:
8591 case MPI2_MFGPAGE_DEVID_SAS2004:
8592 case MPI2_MFGPAGE_DEVID_SAS2008:
8593 case MPI2_MFGPAGE_DEVID_SAS2108_1:
8594 case MPI2_MFGPAGE_DEVID_SAS2108_2:
8595 case MPI2_MFGPAGE_DEVID_SAS2108_3:
8596 case MPI2_MFGPAGE_DEVID_SAS2116_1:
8597 case MPI2_MFGPAGE_DEVID_SAS2116_2:
8598 case MPI2_MFGPAGE_DEVID_SAS2208_1:
8599 case MPI2_MFGPAGE_DEVID_SAS2208_2:
8600 case MPI2_MFGPAGE_DEVID_SAS2208_3:
8601 case MPI2_MFGPAGE_DEVID_SAS2208_4:
8602 case MPI2_MFGPAGE_DEVID_SAS2208_5:
8603 case MPI2_MFGPAGE_DEVID_SAS2208_6:
8604 case MPI2_MFGPAGE_DEVID_SAS2308_1:
8605 case MPI2_MFGPAGE_DEVID_SAS2308_2:
8606 case MPI2_MFGPAGE_DEVID_SAS2308_3:
8607 return MPI2_VERSION;
8608 case MPI25_MFGPAGE_DEVID_SAS3004:
8609 case MPI25_MFGPAGE_DEVID_SAS3008:
8610 case MPI25_MFGPAGE_DEVID_SAS3108_1:
8611 case MPI25_MFGPAGE_DEVID_SAS3108_2:
8612 case MPI25_MFGPAGE_DEVID_SAS3108_5:
8613 case MPI25_MFGPAGE_DEVID_SAS3108_6:
8614 return MPI25_VERSION;
8615 case MPI26_MFGPAGE_DEVID_SAS3216:
8616 case MPI26_MFGPAGE_DEVID_SAS3224:
8617 case MPI26_MFGPAGE_DEVID_SAS3316_1:
8618 case MPI26_MFGPAGE_DEVID_SAS3316_2:
8619 case MPI26_MFGPAGE_DEVID_SAS3316_3:
8620 case MPI26_MFGPAGE_DEVID_SAS3316_4:
8621 case MPI26_MFGPAGE_DEVID_SAS3324_1:
8622 case MPI26_MFGPAGE_DEVID_SAS3324_2:
8623 case MPI26_MFGPAGE_DEVID_SAS3324_3:
8624 case MPI26_MFGPAGE_DEVID_SAS3324_4:
8625 return MPI26_VERSION;
8631 * _scsih_probe - attach and add scsi host
8632 * @pdev: PCI device struct
8633 * @id: pci device id
8635 * Returns 0 success, anything else error.
8638 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8640 struct MPT3SAS_ADAPTER *ioc;
8641 struct Scsi_Host *shost = NULL;
8643 u16 hba_mpi_version;
8645 /* Determine in which MPI version class this pci device belongs */
8646 hba_mpi_version = _scsih_determine_hba_mpi_version(pdev);
8647 if (hba_mpi_version == 0)
8650 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
8651 * for other generation HBA's return with -ENODEV
8653 if ((hbas_to_enumerate == 1) && (hba_mpi_version != MPI2_VERSION))
8656 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
8657 * for other generation HBA's return with -ENODEV
8659 if ((hbas_to_enumerate == 2) && (!(hba_mpi_version == MPI25_VERSION
8660 || hba_mpi_version == MPI26_VERSION)))
8663 switch (hba_mpi_version) {
8665 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
8666 shost = scsi_host_alloc(&mpt2sas_driver_template,
8667 sizeof(struct MPT3SAS_ADAPTER));
8670 ioc = shost_priv(shost);
8671 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8672 ioc->hba_mpi_version_belonged = hba_mpi_version;
8673 ioc->id = mpt2_ids++;
8674 sprintf(ioc->driver_name, "%s", MPT2SAS_DRIVER_NAME);
8675 if (pdev->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8676 ioc->is_warpdrive = 1;
8677 ioc->hide_ir_msg = 1;
8679 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8683 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
8684 shost = scsi_host_alloc(&mpt3sas_driver_template,
8685 sizeof(struct MPT3SAS_ADAPTER));
8688 ioc = shost_priv(shost);
8689 memset(ioc, 0, sizeof(struct MPT3SAS_ADAPTER));
8690 ioc->hba_mpi_version_belonged = hba_mpi_version;
8691 ioc->id = mpt3_ids++;
8692 sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
8693 if ((ioc->hba_mpi_version_belonged == MPI25_VERSION &&
8694 pdev->revision >= SAS3_PCI_DEVICE_C0_REVISION) ||
8695 (ioc->hba_mpi_version_belonged == MPI26_VERSION))
8696 ioc->msix96_vector = 1;
8702 INIT_LIST_HEAD(&ioc->list);
8703 spin_lock(&gioc_lock);
8704 list_add_tail(&ioc->list, &mpt3sas_ioc_list);
8705 spin_unlock(&gioc_lock);
8708 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8709 ioc->tm_cb_idx = tm_cb_idx;
8710 ioc->ctl_cb_idx = ctl_cb_idx;
8711 ioc->base_cb_idx = base_cb_idx;
8712 ioc->port_enable_cb_idx = port_enable_cb_idx;
8713 ioc->transport_cb_idx = transport_cb_idx;
8714 ioc->scsih_cb_idx = scsih_cb_idx;
8715 ioc->config_cb_idx = config_cb_idx;
8716 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8717 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8718 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8719 ioc->logging_level = logging_level;
8720 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8721 /* misc semaphores and spin locks */
8722 mutex_init(&ioc->reset_in_progress_mutex);
8723 /* initializing pci_access_mutex lock */
8724 mutex_init(&ioc->pci_access_mutex);
8725 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8726 spin_lock_init(&ioc->scsi_lookup_lock);
8727 spin_lock_init(&ioc->sas_device_lock);
8728 spin_lock_init(&ioc->sas_node_lock);
8729 spin_lock_init(&ioc->fw_event_lock);
8730 spin_lock_init(&ioc->raid_device_lock);
8731 spin_lock_init(&ioc->diag_trigger_lock);
8733 INIT_LIST_HEAD(&ioc->sas_device_list);
8734 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8735 INIT_LIST_HEAD(&ioc->sas_expander_list);
8736 INIT_LIST_HEAD(&ioc->fw_event_list);
8737 INIT_LIST_HEAD(&ioc->raid_device_list);
8738 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8739 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8740 INIT_LIST_HEAD(&ioc->delayed_sc_list);
8741 INIT_LIST_HEAD(&ioc->delayed_event_ack_list);
8742 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8743 INIT_LIST_HEAD(&ioc->reply_queue_list);
8745 sprintf(ioc->name, "%s_cm%d", ioc->driver_name, ioc->id);
8747 /* init shost parameters */
8748 shost->max_cmd_len = 32;
8749 shost->max_lun = max_lun;
8750 shost->transportt = mpt3sas_transport_template;
8751 shost->unique_id = ioc->id;
8753 if (max_sectors != 0xFFFF) {
8754 if (max_sectors < 64) {
8755 shost->max_sectors = 64;
8756 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8757 "for max_sectors, range is 64 to 32767. Assigning "
8758 "value of 64.\n", ioc->name, max_sectors);
8759 } else if (max_sectors > 32767) {
8760 shost->max_sectors = 32767;
8761 pr_warn(MPT3SAS_FMT "Invalid value %d passed " \
8762 "for max_sectors, range is 64 to 32767. Assigning "
8763 "default value of 32767.\n", ioc->name,
8766 shost->max_sectors = max_sectors & 0xFFFE;
8768 "The max_sectors value is set to %d\n",
8769 ioc->name, shost->max_sectors);
8773 /* register EEDP capabilities with SCSI layer */
8775 scsi_host_set_prot(shost, prot_mask);
8777 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8778 | SHOST_DIF_TYPE2_PROTECTION
8779 | SHOST_DIF_TYPE3_PROTECTION);
8781 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8784 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8785 "fw_event_%s%d", ioc->driver_name, ioc->id);
8786 ioc->firmware_event_thread = alloc_ordered_workqueue(
8787 ioc->firmware_event_name, WQ_MEM_RECLAIM);
8788 if (!ioc->firmware_event_thread) {
8789 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8790 ioc->name, __FILE__, __LINE__, __func__);
8792 goto out_thread_fail;
8795 ioc->is_driver_loading = 1;
8796 if ((mpt3sas_base_attach(ioc))) {
8797 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8798 ioc->name, __FILE__, __LINE__, __func__);
8800 goto out_attach_fail;
8803 if (ioc->is_warpdrive) {
8804 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8805 ioc->hide_drives = 0;
8806 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8807 ioc->hide_drives = 1;
8809 if (mpt3sas_get_num_volumes(ioc))
8810 ioc->hide_drives = 1;
8812 ioc->hide_drives = 0;
8815 ioc->hide_drives = 0;
8817 rv = scsi_add_host(shost, &pdev->dev);
8819 pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
8820 ioc->name, __FILE__, __LINE__, __func__);
8821 goto out_add_shost_fail;
8824 scsi_scan_host(shost);
8827 mpt3sas_base_detach(ioc);
8829 destroy_workqueue(ioc->firmware_event_thread);
8831 spin_lock(&gioc_lock);
8832 list_del(&ioc->list);
8833 spin_unlock(&gioc_lock);
8834 scsi_host_put(shost);
8840 * scsih_suspend - power management suspend main entry point
8841 * @pdev: PCI device struct
8842 * @state: PM state change to (usually PCI_D3)
8844 * Returns 0 success, anything else error.
8847 scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8849 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8850 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8851 pci_power_t device_state;
8853 mpt3sas_base_stop_watchdog(ioc);
8854 flush_scheduled_work();
8855 scsi_block_requests(shost);
8856 device_state = pci_choose_state(pdev, state);
8858 "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
8859 ioc->name, pdev, pci_name(pdev), device_state);
8861 pci_save_state(pdev);
8862 mpt3sas_base_free_resources(ioc);
8863 pci_set_power_state(pdev, device_state);
8868 * scsih_resume - power management resume main entry point
8869 * @pdev: PCI device struct
8871 * Returns 0 success, anything else error.
8874 scsih_resume(struct pci_dev *pdev)
8876 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8877 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8878 pci_power_t device_state = pdev->current_state;
8882 "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
8883 ioc->name, pdev, pci_name(pdev), device_state);
8885 pci_set_power_state(pdev, PCI_D0);
8886 pci_enable_wake(pdev, PCI_D0, 0);
8887 pci_restore_state(pdev);
8889 r = mpt3sas_base_map_resources(ioc);
8893 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8894 scsi_unblock_requests(shost);
8895 mpt3sas_base_start_watchdog(ioc);
8898 #endif /* CONFIG_PM */
8901 * scsih_pci_error_detected - Called when a PCI error is detected.
8902 * @pdev: PCI device struct
8903 * @state: PCI channel state
8905 * Description: Called when a PCI error is detected.
8908 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8911 scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8913 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8914 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8916 pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n",
8920 case pci_channel_io_normal:
8921 return PCI_ERS_RESULT_CAN_RECOVER;
8922 case pci_channel_io_frozen:
8923 /* Fatal error, prepare for slot reset */
8924 ioc->pci_error_recovery = 1;
8925 scsi_block_requests(ioc->shost);
8926 mpt3sas_base_stop_watchdog(ioc);
8927 mpt3sas_base_free_resources(ioc);
8928 return PCI_ERS_RESULT_NEED_RESET;
8929 case pci_channel_io_perm_failure:
8930 /* Permanent error, prepare for device removal */
8931 ioc->pci_error_recovery = 1;
8932 mpt3sas_base_stop_watchdog(ioc);
8933 _scsih_flush_running_cmds(ioc);
8934 return PCI_ERS_RESULT_DISCONNECT;
8936 return PCI_ERS_RESULT_NEED_RESET;
8940 * scsih_pci_slot_reset - Called when PCI slot has been reset.
8941 * @pdev: PCI device struct
8943 * Description: This routine is called by the pci error recovery
8944 * code after the PCI slot has been reset, just before we
8945 * should resume normal operations.
8948 scsih_pci_slot_reset(struct pci_dev *pdev)
8950 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8951 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8954 pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n",
8957 ioc->pci_error_recovery = 0;
8959 pci_restore_state(pdev);
8960 rc = mpt3sas_base_map_resources(ioc);
8962 return PCI_ERS_RESULT_DISCONNECT;
8964 rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8967 pr_warn(MPT3SAS_FMT "hard reset: %s\n", ioc->name,
8968 (rc == 0) ? "success" : "failed");
8971 return PCI_ERS_RESULT_RECOVERED;
8973 return PCI_ERS_RESULT_DISCONNECT;
8977 * scsih_pci_resume() - resume normal ops after PCI reset
8978 * @pdev: pointer to PCI device
8980 * Called when the error recovery driver tells us that its
8981 * OK to resume normal operation. Use completion to allow
8982 * halted scsi ops to resume.
8985 scsih_pci_resume(struct pci_dev *pdev)
8987 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8988 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
8990 pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name);
8992 pci_cleanup_aer_uncorrect_error_status(pdev);
8993 mpt3sas_base_start_watchdog(ioc);
8994 scsi_unblock_requests(ioc->shost);
8998 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8999 * @pdev: pointer to PCI device
9002 scsih_pci_mmio_enabled(struct pci_dev *pdev)
9004 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9005 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
9007 pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n",
9010 /* TODO - dump whatever for debugging purposes */
9012 /* Request a slot reset. */
9013 return PCI_ERS_RESULT_NEED_RESET;
9017 * The pci device ids are defined in mpi/mpi2_cnfg.h.
9019 static const struct pci_device_id mpt3sas_pci_table[] = {
9020 /* Spitfire ~ 2004 */
9021 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
9022 PCI_ANY_ID, PCI_ANY_ID },
9024 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
9025 PCI_ANY_ID, PCI_ANY_ID },
9026 /* Liberator ~ 2108 */
9027 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
9028 PCI_ANY_ID, PCI_ANY_ID },
9029 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
9030 PCI_ANY_ID, PCI_ANY_ID },
9031 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
9032 PCI_ANY_ID, PCI_ANY_ID },
9034 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
9035 PCI_ANY_ID, PCI_ANY_ID },
9036 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
9037 PCI_ANY_ID, PCI_ANY_ID },
9038 /* Thunderbolt ~ 2208 */
9039 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
9040 PCI_ANY_ID, PCI_ANY_ID },
9041 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
9042 PCI_ANY_ID, PCI_ANY_ID },
9043 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
9044 PCI_ANY_ID, PCI_ANY_ID },
9045 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
9046 PCI_ANY_ID, PCI_ANY_ID },
9047 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
9048 PCI_ANY_ID, PCI_ANY_ID },
9049 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
9050 PCI_ANY_ID, PCI_ANY_ID },
9051 /* Mustang ~ 2308 */
9052 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
9053 PCI_ANY_ID, PCI_ANY_ID },
9054 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
9055 PCI_ANY_ID, PCI_ANY_ID },
9056 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
9057 PCI_ANY_ID, PCI_ANY_ID },
9059 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
9060 PCI_ANY_ID, PCI_ANY_ID },
9061 /* Fury ~ 3004 and 3008 */
9062 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3004,
9063 PCI_ANY_ID, PCI_ANY_ID },
9064 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3008,
9065 PCI_ANY_ID, PCI_ANY_ID },
9066 /* Invader ~ 3108 */
9067 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_1,
9068 PCI_ANY_ID, PCI_ANY_ID },
9069 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_2,
9070 PCI_ANY_ID, PCI_ANY_ID },
9071 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_5,
9072 PCI_ANY_ID, PCI_ANY_ID },
9073 { MPI2_MFGPAGE_VENDORID_LSI, MPI25_MFGPAGE_DEVID_SAS3108_6,
9074 PCI_ANY_ID, PCI_ANY_ID },
9075 /* Cutlass ~ 3216 and 3224 */
9076 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3216,
9077 PCI_ANY_ID, PCI_ANY_ID },
9078 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3224,
9079 PCI_ANY_ID, PCI_ANY_ID },
9080 /* Intruder ~ 3316 and 3324 */
9081 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_1,
9082 PCI_ANY_ID, PCI_ANY_ID },
9083 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_2,
9084 PCI_ANY_ID, PCI_ANY_ID },
9085 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_3,
9086 PCI_ANY_ID, PCI_ANY_ID },
9087 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3316_4,
9088 PCI_ANY_ID, PCI_ANY_ID },
9089 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_1,
9090 PCI_ANY_ID, PCI_ANY_ID },
9091 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_2,
9092 PCI_ANY_ID, PCI_ANY_ID },
9093 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_3,
9094 PCI_ANY_ID, PCI_ANY_ID },
9095 { MPI2_MFGPAGE_VENDORID_LSI, MPI26_MFGPAGE_DEVID_SAS3324_4,
9096 PCI_ANY_ID, PCI_ANY_ID },
9097 {0} /* Terminating entry */
9099 MODULE_DEVICE_TABLE(pci, mpt3sas_pci_table);
9101 static struct pci_error_handlers _mpt3sas_err_handler = {
9102 .error_detected = scsih_pci_error_detected,
9103 .mmio_enabled = scsih_pci_mmio_enabled,
9104 .slot_reset = scsih_pci_slot_reset,
9105 .resume = scsih_pci_resume,
9108 static struct pci_driver mpt3sas_driver = {
9109 .name = MPT3SAS_DRIVER_NAME,
9110 .id_table = mpt3sas_pci_table,
9111 .probe = _scsih_probe,
9112 .remove = scsih_remove,
9113 .shutdown = scsih_shutdown,
9114 .err_handler = &_mpt3sas_err_handler,
9116 .suspend = scsih_suspend,
9117 .resume = scsih_resume,
9122 * scsih_init - main entry point for this driver.
9124 * Returns 0 success, anything else error.
9132 mpt3sas_base_initialize_callback_handler();
9134 /* queuecommand callback hander */
9135 scsi_io_cb_idx = mpt3sas_base_register_callback_handler(_scsih_io_done);
9137 /* task managment callback handler */
9138 tm_cb_idx = mpt3sas_base_register_callback_handler(_scsih_tm_done);
9140 /* base internal commands callback handler */
9141 base_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_base_done);
9142 port_enable_cb_idx = mpt3sas_base_register_callback_handler(
9143 mpt3sas_port_enable_done);
9145 /* transport internal commands callback handler */
9146 transport_cb_idx = mpt3sas_base_register_callback_handler(
9147 mpt3sas_transport_done);
9149 /* scsih internal commands callback handler */
9150 scsih_cb_idx = mpt3sas_base_register_callback_handler(_scsih_done);
9152 /* configuration page API internal commands callback handler */
9153 config_cb_idx = mpt3sas_base_register_callback_handler(
9154 mpt3sas_config_done);
9156 /* ctl module callback handler */
9157 ctl_cb_idx = mpt3sas_base_register_callback_handler(mpt3sas_ctl_done);
9159 tm_tr_cb_idx = mpt3sas_base_register_callback_handler(
9160 _scsih_tm_tr_complete);
9162 tm_tr_volume_cb_idx = mpt3sas_base_register_callback_handler(
9163 _scsih_tm_volume_tr_complete);
9165 tm_sas_control_cb_idx = mpt3sas_base_register_callback_handler(
9166 _scsih_sas_control_complete);
9172 * scsih_exit - exit point for this driver (when it is a module).
9174 * Returns 0 success, anything else error.
9180 mpt3sas_base_release_callback_handler(scsi_io_cb_idx);
9181 mpt3sas_base_release_callback_handler(tm_cb_idx);
9182 mpt3sas_base_release_callback_handler(base_cb_idx);
9183 mpt3sas_base_release_callback_handler(port_enable_cb_idx);
9184 mpt3sas_base_release_callback_handler(transport_cb_idx);
9185 mpt3sas_base_release_callback_handler(scsih_cb_idx);
9186 mpt3sas_base_release_callback_handler(config_cb_idx);
9187 mpt3sas_base_release_callback_handler(ctl_cb_idx);
9189 mpt3sas_base_release_callback_handler(tm_tr_cb_idx);
9190 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx);
9191 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx);
9193 /* raid transport support */
9194 if (hbas_to_enumerate != 1)
9195 raid_class_release(mpt3sas_raid_template);
9196 if (hbas_to_enumerate != 2)
9197 raid_class_release(mpt2sas_raid_template);
9198 sas_release_transport(mpt3sas_transport_template);
9202 * _mpt3sas_init - main entry point for this driver.
9204 * Returns 0 success, anything else error.
9211 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME,
9212 MPT3SAS_DRIVER_VERSION);
9214 mpt3sas_transport_template =
9215 sas_attach_transport(&mpt3sas_transport_functions);
9216 if (!mpt3sas_transport_template)
9219 /* No need attach mpt3sas raid functions template
9220 * if hbas_to_enumarate value is one.
9222 if (hbas_to_enumerate != 1) {
9223 mpt3sas_raid_template =
9224 raid_class_attach(&mpt3sas_raid_functions);
9225 if (!mpt3sas_raid_template) {
9226 sas_release_transport(mpt3sas_transport_template);
9231 /* No need to attach mpt2sas raid functions template
9232 * if hbas_to_enumarate value is two
9234 if (hbas_to_enumerate != 2) {
9235 mpt2sas_raid_template =
9236 raid_class_attach(&mpt2sas_raid_functions);
9237 if (!mpt2sas_raid_template) {
9238 sas_release_transport(mpt3sas_transport_template);
9243 error = scsih_init();
9249 mpt3sas_ctl_init(hbas_to_enumerate);
9251 error = pci_register_driver(&mpt3sas_driver);
9259 * _mpt3sas_exit - exit point for this driver (when it is a module).
9265 pr_info("mpt3sas version %s unloading\n",
9266 MPT3SAS_DRIVER_VERSION);
9268 pci_unregister_driver(&mpt3sas_driver);
9270 mpt3sas_ctl_exit(hbas_to_enumerate);
9275 module_init(_mpt3sas_init);
9276 module_exit(_mpt3sas_exit);