2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2014 LSI Corporation
6 * Copyright (C) 20013-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 <linux/slab.h>
59 #include <asm/unaligned.h>
61 #include "mpt2sas_base.h"
63 MODULE_AUTHOR(MPT2SAS_AUTHOR);
64 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
65 MODULE_LICENSE("GPL");
66 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
68 #define RAID_CHANNEL 1
71 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
72 struct _sas_node *sas_expander);
73 static void _firmware_event_work(struct work_struct *work);
75 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
77 static void _scsih_scan_start(struct Scsi_Host *shost);
78 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
80 /* global parameters */
81 LIST_HEAD(mpt2sas_ioc_list);
82 /* global ioc lock for list operations */
83 DEFINE_SPINLOCK(gioc_lock);
84 /* local parameters */
85 static u8 scsi_io_cb_idx = -1;
86 static u8 tm_cb_idx = -1;
87 static u8 ctl_cb_idx = -1;
88 static u8 base_cb_idx = -1;
89 static u8 port_enable_cb_idx = -1;
90 static u8 transport_cb_idx = -1;
91 static u8 scsih_cb_idx = -1;
92 static u8 config_cb_idx = -1;
95 static u8 tm_tr_cb_idx = -1 ;
96 static u8 tm_tr_volume_cb_idx = -1 ;
97 static u8 tm_sas_control_cb_idx = -1;
99 /* command line options */
100 static u32 logging_level;
101 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
104 static ushort max_sectors = 0xFFFF;
105 module_param(max_sectors, ushort, 0);
106 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
108 static int missing_delay[2] = {-1, -1};
109 module_param_array(missing_delay, int, NULL, 0);
110 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
112 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
113 #define MPT2SAS_MAX_LUN (16895)
114 static int max_lun = MPT2SAS_MAX_LUN;
115 module_param(max_lun, int, 0);
116 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
118 /* diag_buffer_enable is bitwise
120 * bit 1 set = SNAPSHOT
121 * bit 2 set = EXTENDED
123 * Either bit can be set, or both
125 static int diag_buffer_enable = -1;
126 module_param(diag_buffer_enable, int, 0);
127 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
128 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
130 static int disable_discovery = -1;
131 module_param(disable_discovery, int, 0);
132 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
134 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
135 static int prot_mask = 0;
136 module_param(prot_mask, int, 0);
137 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
140 * struct sense_info - common structure for obtaining sense keys
142 * @asc: additional sense code
143 * @ascq: additional sense code qualifier
152 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
153 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
154 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
156 * struct fw_event_work - firmware event struct
157 * @list: link list framework
158 * @work: work object (ioc->fault_reset_work_q)
159 * @cancel_pending_work: flag set during reset handling
160 * @ioc: per adapter object
161 * @device_handle: device handle
162 * @VF_ID: virtual function id
163 * @VP_ID: virtual port id
164 * @ignore: flag meaning this event has been marked to ignore
165 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
166 * @event_data: reply event data payload follows
168 * This object stored on ioc->fw_event_list.
170 struct fw_event_work {
171 struct list_head list;
172 u8 cancel_pending_work;
173 struct delayed_work delayed_work;
174 struct MPT2SAS_ADAPTER *ioc;
180 struct kref refcount;
181 char event_data[0] __aligned(4);
184 static void fw_event_work_free(struct kref *r)
186 kfree(container_of(r, struct fw_event_work, refcount));
189 static void fw_event_work_get(struct fw_event_work *fw_work)
191 kref_get(&fw_work->refcount);
194 static void fw_event_work_put(struct fw_event_work *fw_work)
196 kref_put(&fw_work->refcount, fw_event_work_free);
199 static struct fw_event_work *alloc_fw_event_work(int len)
201 struct fw_event_work *fw_event;
203 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
207 kref_init(&fw_event->refcount);
211 /* raid transport support */
212 static struct raid_template *mpt2sas_raid_template;
215 * struct _scsi_io_transfer - scsi io transfer
216 * @handle: sas device handle (assigned by firmware)
217 * @is_raid: flag set for hidden raid components
218 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
219 * @data_length: data transfer length
220 * @data_dma: dma pointer to data
223 * @cdb_length: cdb length
225 * @timeout: timeout for this command
226 * @VF_ID: virtual function id
227 * @VP_ID: virtual port id
228 * @valid_reply: flag set for reply message
229 * @sense_length: sense length
230 * @ioc_status: ioc status
231 * @scsi_state: scsi state
232 * @scsi_status: scsi staus
233 * @log_info: log information
234 * @transfer_length: data length transfer when there is a reply message
236 * Used for sending internal scsi commands to devices within this module.
237 * Refer to _scsi_send_scsi_io().
239 struct _scsi_io_transfer {
242 enum dma_data_direction dir;
245 u8 sense[SCSI_SENSE_BUFFERSIZE];
253 /* the following bits are only valid when 'valid_reply = 1' */
263 * The pci device ids are defined in mpi/mpi2_cnfg.h.
265 static struct pci_device_id scsih_pci_table[] = {
266 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
267 PCI_ANY_ID, PCI_ANY_ID },
269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
270 PCI_ANY_ID, PCI_ANY_ID },
271 /* Liberator ~ 2108 */
272 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
273 PCI_ANY_ID, PCI_ANY_ID },
274 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
275 PCI_ANY_ID, PCI_ANY_ID },
276 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
277 PCI_ANY_ID, PCI_ANY_ID },
279 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
280 PCI_ANY_ID, PCI_ANY_ID },
281 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
282 PCI_ANY_ID, PCI_ANY_ID },
283 /* Thunderbolt ~ 2208 */
284 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
285 PCI_ANY_ID, PCI_ANY_ID },
286 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
287 PCI_ANY_ID, PCI_ANY_ID },
288 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
289 PCI_ANY_ID, PCI_ANY_ID },
290 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
291 PCI_ANY_ID, PCI_ANY_ID },
292 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
293 PCI_ANY_ID, PCI_ANY_ID },
294 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
295 PCI_ANY_ID, PCI_ANY_ID },
297 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
298 PCI_ANY_ID, PCI_ANY_ID },
299 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
300 PCI_ANY_ID, PCI_ANY_ID },
301 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
302 PCI_ANY_ID, PCI_ANY_ID },
304 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
305 PCI_ANY_ID, PCI_ANY_ID },
306 {0} /* Terminating entry */
308 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
311 * _scsih_set_debug_level - global setting of ioc->logging_level.
313 * Note: The logging levels are defined in mpt2sas_debug.h.
316 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
318 int ret = param_set_int(val, kp);
319 struct MPT2SAS_ADAPTER *ioc;
324 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
325 spin_lock(&gioc_lock);
326 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
327 ioc->logging_level = logging_level;
328 spin_unlock(&gioc_lock);
331 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
332 &logging_level, 0644);
335 * _scsih_srch_boot_sas_address - search based on sas_address
336 * @sas_address: sas address
337 * @boot_device: boot device object from bios page 2
339 * Returns 1 when there's a match, 0 means no match.
342 _scsih_srch_boot_sas_address(u64 sas_address,
343 Mpi2BootDeviceSasWwid_t *boot_device)
345 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
349 * _scsih_srch_boot_device_name - search based on device name
350 * @device_name: device name specified in INDENTIFY fram
351 * @boot_device: boot device object from bios page 2
353 * Returns 1 when there's a match, 0 means no match.
356 _scsih_srch_boot_device_name(u64 device_name,
357 Mpi2BootDeviceDeviceName_t *boot_device)
359 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
363 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
364 * @enclosure_logical_id: enclosure logical id
365 * @slot_number: slot number
366 * @boot_device: boot device object from bios page 2
368 * Returns 1 when there's a match, 0 means no match.
371 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
372 Mpi2BootDeviceEnclosureSlot_t *boot_device)
374 return (enclosure_logical_id == le64_to_cpu(boot_device->
375 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
376 SlotNumber)) ? 1 : 0;
380 * _scsih_is_boot_device - search for matching boot device.
381 * @sas_address: sas address
382 * @device_name: device name specified in INDENTIFY fram
383 * @enclosure_logical_id: enclosure logical id
384 * @slot_number: slot number
385 * @form: specifies boot device form
386 * @boot_device: boot device object from bios page 2
388 * Returns 1 when there's a match, 0 means no match.
391 _scsih_is_boot_device(u64 sas_address, u64 device_name,
392 u64 enclosure_logical_id, u16 slot, u8 form,
393 Mpi2BiosPage2BootDevice_t *boot_device)
398 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
401 rc = _scsih_srch_boot_sas_address(
402 sas_address, &boot_device->SasWwid);
404 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
405 if (!enclosure_logical_id)
407 rc = _scsih_srch_boot_encl_slot(
408 enclosure_logical_id,
409 slot, &boot_device->EnclosureSlot);
411 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
414 rc = _scsih_srch_boot_device_name(
415 device_name, &boot_device->DeviceName);
417 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
425 * _scsih_get_sas_address - set the sas_address for given device handle
426 * @handle: device handle
427 * @sas_address: sas address
429 * Returns 0 success, non-zero when failure
432 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
435 Mpi2SasDevicePage0_t sas_device_pg0;
436 Mpi2ConfigReply_t mpi_reply;
440 if (handle <= ioc->sas_hba.num_phys) {
441 *sas_address = ioc->sas_hba.sas_address;
445 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
446 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
447 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
448 __FILE__, __LINE__, __func__);
452 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
453 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
454 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
458 /* we hit this becuase the given parent handle doesn't exist */
459 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
461 /* else error case */
462 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
463 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
464 __FILE__, __LINE__, __func__);
469 * _scsih_determine_boot_device - determine boot device.
470 * @ioc: per adapter object
471 * @device: either sas_device or raid_device object
472 * @is_raid: [flag] 1 = raid object, 0 = sas object
474 * Determines whether this device should be first reported device to
475 * to scsi-ml or sas transport, this purpose is for persistent boot device.
476 * There are primary, alternate, and current entries in bios page 2. The order
477 * priority is primary, alternate, then current. This routine saves
478 * the corresponding device object and is_raid flag in the ioc object.
479 * The saved data to be used later in _scsih_probe_boot_devices().
482 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
483 void *device, u8 is_raid)
485 struct _sas_device *sas_device;
486 struct _raid_device *raid_device;
489 u64 enclosure_logical_id;
492 /* only process this function when driver loads */
493 if (!ioc->is_driver_loading)
496 /* no Bios, return immediately */
497 if (!ioc->bios_pg3.BiosVersion)
502 sas_address = sas_device->sas_address;
503 device_name = sas_device->device_name;
504 enclosure_logical_id = sas_device->enclosure_logical_id;
505 slot = sas_device->slot;
507 raid_device = device;
508 sas_address = raid_device->wwid;
510 enclosure_logical_id = 0;
514 if (!ioc->req_boot_device.device) {
515 if (_scsih_is_boot_device(sas_address, device_name,
516 enclosure_logical_id, slot,
517 (ioc->bios_pg2.ReqBootDeviceForm &
518 MPI2_BIOSPAGE2_FORM_MASK),
519 &ioc->bios_pg2.RequestedBootDevice)) {
520 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
521 "%s: req_boot_device(0x%016llx)\n",
523 (unsigned long long)sas_address));
524 ioc->req_boot_device.device = device;
525 ioc->req_boot_device.is_raid = is_raid;
529 if (!ioc->req_alt_boot_device.device) {
530 if (_scsih_is_boot_device(sas_address, device_name,
531 enclosure_logical_id, slot,
532 (ioc->bios_pg2.ReqAltBootDeviceForm &
533 MPI2_BIOSPAGE2_FORM_MASK),
534 &ioc->bios_pg2.RequestedAltBootDevice)) {
535 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
536 "%s: req_alt_boot_device(0x%016llx)\n",
538 (unsigned long long)sas_address));
539 ioc->req_alt_boot_device.device = device;
540 ioc->req_alt_boot_device.is_raid = is_raid;
544 if (!ioc->current_boot_device.device) {
545 if (_scsih_is_boot_device(sas_address, device_name,
546 enclosure_logical_id, slot,
547 (ioc->bios_pg2.CurrentBootDeviceForm &
548 MPI2_BIOSPAGE2_FORM_MASK),
549 &ioc->bios_pg2.CurrentBootDevice)) {
550 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
551 "%s: current_boot_device(0x%016llx)\n",
553 (unsigned long long)sas_address));
554 ioc->current_boot_device.device = device;
555 ioc->current_boot_device.is_raid = is_raid;
560 static struct _sas_device *
561 __mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc,
562 struct MPT2SAS_TARGET *tgt_priv)
564 struct _sas_device *ret;
566 assert_spin_locked(&ioc->sas_device_lock);
568 ret = tgt_priv->sdev;
575 static struct _sas_device *
576 mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc,
577 struct MPT2SAS_TARGET *tgt_priv)
579 struct _sas_device *ret;
582 spin_lock_irqsave(&ioc->sas_device_lock, flags);
583 ret = __mpt2sas_get_sdev_from_target(ioc, tgt_priv);
584 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
591 __mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc,
594 struct _sas_device *sas_device;
596 assert_spin_locked(&ioc->sas_device_lock);
598 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
599 if (sas_device->sas_address == sas_address)
602 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
603 if (sas_device->sas_address == sas_address)
609 sas_device_get(sas_device);
614 * mpt2sas_get_sdev_by_addr - sas device search
615 * @ioc: per adapter object
616 * @sas_address: sas address
617 * Context: Calling function should acquire ioc->sas_device_lock
619 * This searches for sas_device based on sas_address, then return sas_device
623 mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc,
626 struct _sas_device *sas_device;
629 spin_lock_irqsave(&ioc->sas_device_lock, flags);
630 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
632 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
637 static struct _sas_device *
638 __mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
640 struct _sas_device *sas_device;
642 assert_spin_locked(&ioc->sas_device_lock);
644 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
645 if (sas_device->handle == handle)
648 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
649 if (sas_device->handle == handle)
655 sas_device_get(sas_device);
660 * mpt2sas_get_sdev_by_handle - sas device search
661 * @ioc: per adapter object
662 * @handle: sas device handle (assigned by firmware)
663 * Context: Calling function should acquire ioc->sas_device_lock
665 * This searches for sas_device based on sas_address, then return sas_device
668 static struct _sas_device *
669 mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
671 struct _sas_device *sas_device;
674 spin_lock_irqsave(&ioc->sas_device_lock, flags);
675 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
676 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
682 * _scsih_sas_device_remove - remove sas_device from list.
683 * @ioc: per adapter object
684 * @sas_device: the sas_device object
685 * Context: This function will acquire ioc->sas_device_lock.
687 * If sas_device is on the list, remove it and decrement its reference count.
690 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
691 struct _sas_device *sas_device)
699 * The lock serializes access to the list, but we still need to verify
700 * that nobody removed the entry while we were waiting on the lock.
702 spin_lock_irqsave(&ioc->sas_device_lock, flags);
703 if (!list_empty(&sas_device->list)) {
704 list_del_init(&sas_device->list);
705 sas_device_put(sas_device);
707 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
712 * _scsih_sas_device_add - insert sas_device to the list.
713 * @ioc: per adapter object
714 * @sas_device: the sas_device object
715 * Context: This function will acquire ioc->sas_device_lock.
717 * Adding new object to the ioc->sas_device_list.
720 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
721 struct _sas_device *sas_device)
725 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
726 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
727 sas_device->handle, (unsigned long long)sas_device->sas_address));
729 spin_lock_irqsave(&ioc->sas_device_lock, flags);
730 sas_device_get(sas_device);
731 list_add_tail(&sas_device->list, &ioc->sas_device_list);
732 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
734 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
735 sas_device->sas_address_parent)) {
736 _scsih_sas_device_remove(ioc, sas_device);
737 } else if (!sas_device->starget) {
738 /* When asyn scanning is enabled, its not possible to remove
739 * devices while scanning is turned on due to an oops in
740 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
742 if (!ioc->is_driver_loading) {
743 mpt2sas_transport_port_remove(ioc,
744 sas_device->sas_address,
745 sas_device->sas_address_parent);
746 _scsih_sas_device_remove(ioc, sas_device);
752 * _scsih_sas_device_init_add - insert sas_device to the list.
753 * @ioc: per adapter object
754 * @sas_device: the sas_device object
755 * Context: This function will acquire ioc->sas_device_lock.
757 * Adding new object at driver load time to the ioc->sas_device_init_list.
760 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
761 struct _sas_device *sas_device)
765 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
766 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
767 sas_device->handle, (unsigned long long)sas_device->sas_address));
769 spin_lock_irqsave(&ioc->sas_device_lock, flags);
770 sas_device_get(sas_device);
771 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
772 _scsih_determine_boot_device(ioc, sas_device, 0);
773 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
777 * _scsih_raid_device_find_by_id - raid device search
778 * @ioc: per adapter object
779 * @id: sas device target id
780 * @channel: sas device channel
781 * Context: Calling function should acquire ioc->raid_device_lock
783 * This searches for raid_device based on target id, then return raid_device
786 static struct _raid_device *
787 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
789 struct _raid_device *raid_device, *r;
792 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
793 if (raid_device->id == id && raid_device->channel == channel) {
804 * _scsih_raid_device_find_by_handle - raid device search
805 * @ioc: per adapter object
806 * @handle: sas device handle (assigned by firmware)
807 * Context: Calling function should acquire ioc->raid_device_lock
809 * This searches for raid_device based on handle, then return raid_device
812 static struct _raid_device *
813 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
815 struct _raid_device *raid_device, *r;
818 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
819 if (raid_device->handle != handle)
830 * _scsih_raid_device_find_by_wwid - raid device search
831 * @ioc: per adapter object
832 * @handle: sas device handle (assigned by firmware)
833 * Context: Calling function should acquire ioc->raid_device_lock
835 * This searches for raid_device based on wwid, then return raid_device
838 static struct _raid_device *
839 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
841 struct _raid_device *raid_device, *r;
844 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
845 if (raid_device->wwid != wwid)
856 * _scsih_raid_device_add - add raid_device object
857 * @ioc: per adapter object
858 * @raid_device: raid_device object
860 * This is added to the raid_device_list link list.
863 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
864 struct _raid_device *raid_device)
868 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
869 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
870 raid_device->handle, (unsigned long long)raid_device->wwid));
872 spin_lock_irqsave(&ioc->raid_device_lock, flags);
873 list_add_tail(&raid_device->list, &ioc->raid_device_list);
874 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
878 * _scsih_raid_device_remove - delete raid_device object
879 * @ioc: per adapter object
880 * @raid_device: raid_device object
884 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
885 struct _raid_device *raid_device)
889 spin_lock_irqsave(&ioc->raid_device_lock, flags);
890 list_del(&raid_device->list);
892 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
896 * mpt2sas_scsih_expander_find_by_handle - expander device search
897 * @ioc: per adapter object
898 * @handle: expander handle (assigned by firmware)
899 * Context: Calling function should acquire ioc->sas_device_lock
901 * This searches for expander device based on handle, then returns the
905 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
907 struct _sas_node *sas_expander, *r;
910 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
911 if (sas_expander->handle != handle)
921 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
922 * @ioc: per adapter object
923 * @sas_address: sas address
924 * Context: Calling function should acquire ioc->sas_node_lock.
926 * This searches for expander device based on sas_address, then returns the
930 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
933 struct _sas_node *sas_expander, *r;
936 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
937 if (sas_expander->sas_address != sas_address)
947 * _scsih_expander_node_add - insert expander device to the list.
948 * @ioc: per adapter object
949 * @sas_expander: the sas_device object
950 * Context: This function will acquire ioc->sas_node_lock.
952 * Adding new object to the ioc->sas_expander_list.
957 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
958 struct _sas_node *sas_expander)
962 spin_lock_irqsave(&ioc->sas_node_lock, flags);
963 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
964 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
968 * _scsih_is_end_device - determines if device is an end device
969 * @device_info: bitfield providing information about the device.
972 * Returns 1 if end device.
975 _scsih_is_end_device(u32 device_info)
977 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
978 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
979 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
980 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
987 * _scsih_scsi_lookup_get - returns scmd entry
988 * @ioc: per adapter object
989 * @smid: system request message index
991 * Returns the smid stored scmd pointer.
993 static struct scsi_cmnd *
994 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
996 return ioc->scsi_lookup[smid - 1].scmd;
1000 * _scsih_scsi_lookup_get_clear - returns scmd entry
1001 * @ioc: per adapter object
1002 * @smid: system request message index
1004 * Returns the smid stored scmd pointer.
1005 * Then will derefrence the stored scmd pointer.
1007 static inline struct scsi_cmnd *
1008 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1010 unsigned long flags;
1011 struct scsi_cmnd *scmd;
1013 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1014 scmd = ioc->scsi_lookup[smid - 1].scmd;
1015 ioc->scsi_lookup[smid - 1].scmd = NULL;
1016 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1022 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1023 * @ioc: per adapter object
1024 * @smid: system request message index
1025 * @scmd: pointer to scsi command object
1026 * Context: This function will acquire ioc->scsi_lookup_lock.
1028 * This will search for a scmd pointer in the scsi_lookup array,
1029 * returning the revelent smid. A returned value of zero means invalid.
1032 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
1036 unsigned long flags;
1039 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1041 for (i = 0; i < ioc->scsiio_depth; i++) {
1042 if (ioc->scsi_lookup[i].scmd == scmd) {
1043 smid = ioc->scsi_lookup[i].smid;
1048 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1053 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1054 * @ioc: per adapter object
1057 * Context: This function will acquire ioc->scsi_lookup_lock.
1059 * This will search for a matching channel:id in the scsi_lookup array,
1060 * returning 1 if found.
1063 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
1067 unsigned long flags;
1070 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1072 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1073 if (ioc->scsi_lookup[i].scmd &&
1074 (ioc->scsi_lookup[i].scmd->device->id == id &&
1075 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1081 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1086 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1087 * @ioc: per adapter object
1091 * Context: This function will acquire ioc->scsi_lookup_lock.
1093 * This will search for a matching channel:id:lun in the scsi_lookup array,
1094 * returning 1 if found.
1097 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
1098 unsigned int lun, int channel)
1101 unsigned long flags;
1104 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1106 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1107 if (ioc->scsi_lookup[i].scmd &&
1108 (ioc->scsi_lookup[i].scmd->device->id == id &&
1109 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1110 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1116 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1121 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1122 * @ioc: per adapter object
1123 * @smid: smid associated to an IO request
1125 * Returns chain tracker(from ioc->free_chain_list)
1127 static struct chain_tracker *
1128 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1130 struct chain_tracker *chain_req;
1131 unsigned long flags;
1133 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1134 if (list_empty(&ioc->free_chain_list)) {
1135 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1136 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1137 "available\n", ioc->name));
1140 chain_req = list_entry(ioc->free_chain_list.next,
1141 struct chain_tracker, tracker_list);
1142 list_del_init(&chain_req->tracker_list);
1143 list_add_tail(&chain_req->tracker_list,
1144 &ioc->scsi_lookup[smid - 1].chain_list);
1145 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1150 * _scsih_build_scatter_gather - main sg creation routine
1151 * @ioc: per adapter object
1152 * @scmd: scsi command
1153 * @smid: system request message index
1156 * The main routine that builds scatter gather table from a given
1157 * scsi request sent via the .queuecommand main handler.
1159 * Returns 0 success, anything else error
1162 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1163 struct scsi_cmnd *scmd, u16 smid)
1165 Mpi2SCSIIORequest_t *mpi_request;
1166 dma_addr_t chain_dma;
1167 struct scatterlist *sg_scmd;
1168 void *sg_local, *chain;
1173 u32 sges_in_segment;
1175 u32 sgl_flags_last_element;
1176 u32 sgl_flags_end_buffer;
1177 struct chain_tracker *chain_req;
1179 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1181 /* init scatter gather flags */
1182 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1183 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1184 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1185 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1186 << MPI2_SGE_FLAGS_SHIFT;
1187 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1188 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1189 << MPI2_SGE_FLAGS_SHIFT;
1190 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1192 sg_scmd = scsi_sglist(scmd);
1193 sges_left = scsi_dma_map(scmd);
1194 if (sges_left < 0) {
1195 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1196 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1200 sg_local = &mpi_request->SGL;
1201 sges_in_segment = ioc->max_sges_in_main_message;
1202 if (sges_left <= sges_in_segment)
1203 goto fill_in_last_segment;
1205 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1206 (sges_in_segment * ioc->sge_size))/4;
1208 /* fill in main message segment when there is a chain following */
1209 while (sges_in_segment) {
1210 if (sges_in_segment == 1)
1211 ioc->base_add_sg_single(sg_local,
1212 sgl_flags_last_element | sg_dma_len(sg_scmd),
1213 sg_dma_address(sg_scmd));
1215 ioc->base_add_sg_single(sg_local, sgl_flags |
1216 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1217 sg_scmd = sg_next(sg_scmd);
1218 sg_local += ioc->sge_size;
1223 /* initializing the chain flags and pointers */
1224 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1225 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1228 chain = chain_req->chain_buffer;
1229 chain_dma = chain_req->chain_buffer_dma;
1231 sges_in_segment = (sges_left <=
1232 ioc->max_sges_in_chain_message) ? sges_left :
1233 ioc->max_sges_in_chain_message;
1234 chain_offset = (sges_left == sges_in_segment) ?
1235 0 : (sges_in_segment * ioc->sge_size)/4;
1236 chain_length = sges_in_segment * ioc->sge_size;
1238 chain_offset = chain_offset <<
1239 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1240 chain_length += ioc->sge_size;
1242 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1243 chain_length, chain_dma);
1246 goto fill_in_last_segment;
1248 /* fill in chain segments */
1249 while (sges_in_segment) {
1250 if (sges_in_segment == 1)
1251 ioc->base_add_sg_single(sg_local,
1252 sgl_flags_last_element |
1253 sg_dma_len(sg_scmd),
1254 sg_dma_address(sg_scmd));
1256 ioc->base_add_sg_single(sg_local, sgl_flags |
1257 sg_dma_len(sg_scmd),
1258 sg_dma_address(sg_scmd));
1259 sg_scmd = sg_next(sg_scmd);
1260 sg_local += ioc->sge_size;
1265 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1268 chain = chain_req->chain_buffer;
1269 chain_dma = chain_req->chain_buffer_dma;
1273 fill_in_last_segment:
1275 /* fill the last segment */
1278 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1279 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1281 ioc->base_add_sg_single(sg_local, sgl_flags |
1282 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1283 sg_scmd = sg_next(sg_scmd);
1284 sg_local += ioc->sge_size;
1292 * _scsih_change_queue_depth - setting device queue depth
1293 * @sdev: scsi device struct
1294 * @qdepth: requested queue depth
1296 * Returns queue depth.
1299 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1301 struct Scsi_Host *shost = sdev->host;
1303 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1304 struct MPT2SAS_DEVICE *sas_device_priv_data;
1305 struct MPT2SAS_TARGET *sas_target_priv_data;
1306 struct _sas_device *sas_device;
1307 unsigned long flags;
1309 max_depth = shost->can_queue;
1311 /* limit max device queue for SATA to 32 */
1312 sas_device_priv_data = sdev->hostdata;
1313 if (!sas_device_priv_data)
1315 sas_target_priv_data = sas_device_priv_data->sas_target;
1316 if (!sas_target_priv_data)
1318 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1321 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1322 sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data);
1324 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1325 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1327 sas_device_put(sas_device);
1329 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1332 if (!sdev->tagged_supported)
1334 if (qdepth > max_depth)
1336 return scsi_change_queue_depth(sdev, qdepth);
1340 * _scsih_target_alloc - target add routine
1341 * @starget: scsi target struct
1343 * Returns 0 if ok. Any other return is assumed to be an error and
1344 * the device is ignored.
1347 _scsih_target_alloc(struct scsi_target *starget)
1349 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1350 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1351 struct MPT2SAS_TARGET *sas_target_priv_data;
1352 struct _sas_device *sas_device;
1353 struct _raid_device *raid_device;
1354 unsigned long flags;
1355 struct sas_rphy *rphy;
1357 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1359 if (!sas_target_priv_data)
1362 starget->hostdata = sas_target_priv_data;
1363 sas_target_priv_data->starget = starget;
1364 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1367 if (starget->channel == RAID_CHANNEL) {
1368 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1369 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1372 sas_target_priv_data->handle = raid_device->handle;
1373 sas_target_priv_data->sas_address = raid_device->wwid;
1374 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1375 if (ioc->is_warpdrive)
1376 sas_target_priv_data->raid_device = raid_device;
1377 raid_device->starget = starget;
1379 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1383 /* sas/sata devices */
1384 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1385 rphy = dev_to_rphy(starget->dev.parent);
1386 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
1387 rphy->identify.sas_address);
1390 sas_target_priv_data->handle = sas_device->handle;
1391 sas_target_priv_data->sas_address = sas_device->sas_address;
1392 sas_target_priv_data->sdev = sas_device;
1393 sas_device->starget = starget;
1394 sas_device->id = starget->id;
1395 sas_device->channel = starget->channel;
1396 if (test_bit(sas_device->handle, ioc->pd_handles))
1397 sas_target_priv_data->flags |=
1398 MPT_TARGET_FLAGS_RAID_COMPONENT;
1401 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1407 * _scsih_target_destroy - target destroy routine
1408 * @starget: scsi target struct
1413 _scsih_target_destroy(struct scsi_target *starget)
1415 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1416 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1417 struct MPT2SAS_TARGET *sas_target_priv_data;
1418 struct _sas_device *sas_device;
1419 struct _raid_device *raid_device;
1420 unsigned long flags;
1421 struct sas_rphy *rphy;
1423 sas_target_priv_data = starget->hostdata;
1424 if (!sas_target_priv_data)
1427 if (starget->channel == RAID_CHANNEL) {
1428 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1429 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1432 raid_device->starget = NULL;
1433 raid_device->sdev = NULL;
1435 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1439 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1440 rphy = dev_to_rphy(starget->dev.parent);
1441 sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data);
1442 if (sas_device && (sas_device->starget == starget) &&
1443 (sas_device->id == starget->id) &&
1444 (sas_device->channel == starget->channel))
1445 sas_device->starget = NULL;
1449 * Corresponding get() is in _scsih_target_alloc()
1451 sas_target_priv_data->sdev = NULL;
1452 sas_device_put(sas_device);
1454 sas_device_put(sas_device);
1456 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1459 kfree(sas_target_priv_data);
1460 starget->hostdata = NULL;
1464 * _scsih_slave_alloc - device add routine
1465 * @sdev: scsi device struct
1467 * Returns 0 if ok. Any other return is assumed to be an error and
1468 * the device is ignored.
1471 _scsih_slave_alloc(struct scsi_device *sdev)
1473 struct Scsi_Host *shost;
1474 struct MPT2SAS_ADAPTER *ioc;
1475 struct MPT2SAS_TARGET *sas_target_priv_data;
1476 struct MPT2SAS_DEVICE *sas_device_priv_data;
1477 struct scsi_target *starget;
1478 struct _raid_device *raid_device;
1479 struct _sas_device *sas_device;
1480 unsigned long flags;
1482 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1484 if (!sas_device_priv_data)
1487 sas_device_priv_data->lun = sdev->lun;
1488 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1490 starget = scsi_target(sdev);
1491 sas_target_priv_data = starget->hostdata;
1492 sas_target_priv_data->num_luns++;
1493 sas_device_priv_data->sas_target = sas_target_priv_data;
1494 sdev->hostdata = sas_device_priv_data;
1495 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1496 sdev->no_uld_attach = 1;
1498 shost = dev_to_shost(&starget->dev);
1499 ioc = shost_priv(shost);
1500 if (starget->channel == RAID_CHANNEL) {
1501 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1502 raid_device = _scsih_raid_device_find_by_id(ioc,
1503 starget->id, starget->channel);
1505 raid_device->sdev = sdev; /* raid is single lun */
1506 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1509 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1510 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1511 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
1512 sas_target_priv_data->sas_address);
1513 if (sas_device && (sas_device->starget == NULL)) {
1514 sdev_printk(KERN_INFO, sdev,
1515 "%s : sas_device->starget set to starget @ %d\n",
1516 __func__, __LINE__);
1517 sas_device->starget = starget;
1521 sas_device_put(sas_device);
1523 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1530 * _scsih_slave_destroy - device destroy routine
1531 * @sdev: scsi device struct
1536 _scsih_slave_destroy(struct scsi_device *sdev)
1538 struct MPT2SAS_TARGET *sas_target_priv_data;
1539 struct scsi_target *starget;
1540 struct Scsi_Host *shost;
1541 struct MPT2SAS_ADAPTER *ioc;
1542 struct _sas_device *sas_device;
1543 unsigned long flags;
1545 if (!sdev->hostdata)
1548 starget = scsi_target(sdev);
1549 sas_target_priv_data = starget->hostdata;
1550 sas_target_priv_data->num_luns--;
1552 shost = dev_to_shost(&starget->dev);
1553 ioc = shost_priv(shost);
1555 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1556 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1557 sas_device = __mpt2sas_get_sdev_from_target(ioc,
1558 sas_target_priv_data);
1559 if (sas_device && !sas_target_priv_data->num_luns)
1560 sas_device->starget = NULL;
1563 sas_device_put(sas_device);
1564 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1567 kfree(sdev->hostdata);
1568 sdev->hostdata = NULL;
1572 * _scsih_display_sata_capabilities - sata capabilities
1573 * @ioc: per adapter object
1574 * @handle: device handle
1575 * @sdev: scsi device struct
1578 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1579 u16 handle, struct scsi_device *sdev)
1581 Mpi2ConfigReply_t mpi_reply;
1582 Mpi2SasDevicePage0_t sas_device_pg0;
1587 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1588 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1589 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1590 ioc->name, __FILE__, __LINE__, __func__);
1594 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1595 MPI2_IOCSTATUS_MASK;
1596 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1597 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1598 ioc->name, __FILE__, __LINE__, __func__);
1602 flags = le16_to_cpu(sas_device_pg0.Flags);
1603 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1605 sdev_printk(KERN_INFO, sdev,
1606 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1607 "sw_preserve(%s)\n",
1608 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1609 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1610 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1612 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1613 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1614 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1618 * _scsih_is_raid - return boolean indicating device is raid volume
1619 * @dev the device struct object
1622 _scsih_is_raid(struct device *dev)
1624 struct scsi_device *sdev = to_scsi_device(dev);
1625 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1627 if (ioc->is_warpdrive)
1629 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1633 * _scsih_get_resync - get raid volume resync percent complete
1634 * @dev the device struct object
1637 _scsih_get_resync(struct device *dev)
1639 struct scsi_device *sdev = to_scsi_device(dev);
1640 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1641 static struct _raid_device *raid_device;
1642 unsigned long flags;
1643 Mpi2RaidVolPage0_t vol_pg0;
1644 Mpi2ConfigReply_t mpi_reply;
1645 u32 volume_status_flags;
1646 u8 percent_complete;
1649 percent_complete = 0;
1651 if (ioc->is_warpdrive)
1654 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1655 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1658 handle = raid_device->handle;
1659 percent_complete = raid_device->percent_complete;
1661 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1666 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1667 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1668 sizeof(Mpi2RaidVolPage0_t))) {
1669 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1670 ioc->name, __FILE__, __LINE__, __func__);
1671 percent_complete = 0;
1675 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1676 if (!(volume_status_flags &
1677 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1678 percent_complete = 0;
1681 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1685 * _scsih_get_state - get raid volume level
1686 * @dev the device struct object
1689 _scsih_get_state(struct device *dev)
1691 struct scsi_device *sdev = to_scsi_device(dev);
1692 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1693 static struct _raid_device *raid_device;
1694 unsigned long flags;
1695 Mpi2RaidVolPage0_t vol_pg0;
1696 Mpi2ConfigReply_t mpi_reply;
1698 enum raid_state state = RAID_STATE_UNKNOWN;
1701 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1702 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1705 handle = raid_device->handle;
1706 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1711 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1712 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1713 sizeof(Mpi2RaidVolPage0_t))) {
1714 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1715 ioc->name, __FILE__, __LINE__, __func__);
1719 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1720 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1721 state = RAID_STATE_RESYNCING;
1725 switch (vol_pg0.VolumeState) {
1726 case MPI2_RAID_VOL_STATE_OPTIMAL:
1727 case MPI2_RAID_VOL_STATE_ONLINE:
1728 state = RAID_STATE_ACTIVE;
1730 case MPI2_RAID_VOL_STATE_DEGRADED:
1731 state = RAID_STATE_DEGRADED;
1733 case MPI2_RAID_VOL_STATE_FAILED:
1734 case MPI2_RAID_VOL_STATE_MISSING:
1735 state = RAID_STATE_OFFLINE;
1739 raid_set_state(mpt2sas_raid_template, dev, state);
1743 * _scsih_set_level - set raid level
1744 * @sdev: scsi device struct
1745 * @volume_type: volume type
1748 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1750 enum raid_level level = RAID_LEVEL_UNKNOWN;
1752 switch (volume_type) {
1753 case MPI2_RAID_VOL_TYPE_RAID0:
1754 level = RAID_LEVEL_0;
1756 case MPI2_RAID_VOL_TYPE_RAID10:
1757 level = RAID_LEVEL_10;
1759 case MPI2_RAID_VOL_TYPE_RAID1E:
1760 level = RAID_LEVEL_1E;
1762 case MPI2_RAID_VOL_TYPE_RAID1:
1763 level = RAID_LEVEL_1;
1767 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1771 * _scsih_get_volume_capabilities - volume capabilities
1772 * @ioc: per adapter object
1773 * @sas_device: the raid_device object
1775 * Returns 0 for success, else 1
1778 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1779 struct _raid_device *raid_device)
1781 Mpi2RaidVolPage0_t *vol_pg0;
1782 Mpi2RaidPhysDiskPage0_t pd_pg0;
1783 Mpi2SasDevicePage0_t sas_device_pg0;
1784 Mpi2ConfigReply_t mpi_reply;
1788 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1789 &num_pds)) || !num_pds) {
1790 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1791 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1796 raid_device->num_pds = num_pds;
1797 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1798 sizeof(Mpi2RaidVol0PhysDisk_t));
1799 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1801 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1802 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1807 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1808 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1809 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1810 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1816 raid_device->volume_type = vol_pg0->VolumeType;
1818 /* figure out what the underlying devices are by
1819 * obtaining the device_info bits for the 1st device
1821 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1822 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1823 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1824 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1825 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1826 le16_to_cpu(pd_pg0.DevHandle)))) {
1827 raid_device->device_info =
1828 le32_to_cpu(sas_device_pg0.DeviceInfo);
1836 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1837 * @ioc: per adapter object
1840 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1842 Mpi2RaidVolPage1_t vol_pg1;
1843 Mpi2ConfigReply_t mpi_reply;
1844 struct _raid_device *raid_device;
1847 unsigned long flags;
1850 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1851 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1852 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1853 MPI2_IOCSTATUS_MASK;
1854 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1856 handle = le16_to_cpu(vol_pg1.DevHandle);
1857 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1858 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1860 raid_device->direct_io_enabled = 0;
1861 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1868 * _scsih_get_num_volumes - Get number of volumes in the ioc
1869 * @ioc: per adapter object
1872 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1874 Mpi2RaidVolPage1_t vol_pg1;
1875 Mpi2ConfigReply_t mpi_reply;
1881 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1882 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1883 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1884 MPI2_IOCSTATUS_MASK;
1885 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1888 handle = le16_to_cpu(vol_pg1.DevHandle);
1895 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1896 * @ioc: per adapter object
1897 * @raid_device: the raid_device object
1900 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1901 struct _raid_device *raid_device)
1903 Mpi2RaidVolPage0_t *vol_pg0;
1904 Mpi2RaidPhysDiskPage0_t pd_pg0;
1905 Mpi2ConfigReply_t mpi_reply;
1908 unsigned long stripe_sz, block_sz;
1909 u8 stripe_exp, block_exp;
1912 if (!ioc->is_warpdrive)
1915 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1916 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1917 "globally as drives are exposed\n", ioc->name);
1920 if (_scsih_get_num_volumes(ioc) > 1) {
1921 _scsih_disable_ddio(ioc);
1922 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1923 "globally as number of drives > 1\n", ioc->name);
1926 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1927 &num_pds)) || !num_pds) {
1928 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1929 "Failure in computing number of drives\n", ioc->name);
1933 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1934 sizeof(Mpi2RaidVol0PhysDisk_t));
1935 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1937 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1938 "Memory allocation failure for RVPG0\n", ioc->name);
1942 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1943 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1944 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1945 "Failure in retrieving RVPG0\n", ioc->name);
1951 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1952 * assumed for WARPDRIVE, disable direct I/O
1954 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1955 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1956 "for the drive with handle(0x%04x): num_mem=%d, "
1957 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1958 num_pds, MPT_MAX_WARPDRIVE_PDS);
1962 for (count = 0; count < num_pds; count++) {
1963 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1964 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1965 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1966 le16_to_cpu(pd_pg0.DevHandle) ==
1967 MPT2SAS_INVALID_DEVICE_HANDLE) {
1968 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1969 "disabled for the drive with handle(0x%04x) member"
1970 "handle retrieval failed for member number=%d\n",
1971 ioc->name, raid_device->handle,
1972 vol_pg0->PhysDisk[count].PhysDiskNum);
1975 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1976 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1977 if (dev_max_lba >> 32) {
1978 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1979 "disabled for the drive with handle(0x%04x) member"
1980 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1981 ioc->name, raid_device->handle,
1982 le16_to_cpu(pd_pg0.DevHandle),
1983 (unsigned long long)dev_max_lba);
1987 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1991 * Assumption for WD: Direct I/O is not supported if the volume is
1994 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
1995 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1996 "for the drive with handle(0x%04x): type=%d, "
1997 "s_sz=%uK, blk_size=%u\n", ioc->name,
1998 raid_device->handle, raid_device->volume_type,
1999 (le32_to_cpu(vol_pg0->StripeSize) *
2000 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
2001 le16_to_cpu(vol_pg0->BlockSize));
2005 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
2006 stripe_exp = find_first_bit(&stripe_sz, 32);
2007 if (stripe_exp == 32) {
2008 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
2009 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
2010 ioc->name, raid_device->handle,
2011 (le32_to_cpu(vol_pg0->StripeSize) *
2012 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
2015 raid_device->stripe_exponent = stripe_exp;
2016 block_sz = le16_to_cpu(vol_pg0->BlockSize);
2017 block_exp = find_first_bit(&block_sz, 16);
2018 if (block_exp == 16) {
2019 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
2020 "for the drive with handle(0x%04x) invalid block sz %u\n",
2021 ioc->name, raid_device->handle,
2022 le16_to_cpu(vol_pg0->BlockSize));
2025 raid_device->block_exponent = block_exp;
2026 raid_device->direct_io_enabled = 1;
2028 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
2029 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
2031 * WARPDRIVE: Though the following fields are not used for direct IO,
2032 * stored for future purpose:
2034 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
2035 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
2036 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
2043 raid_device->direct_io_enabled = 0;
2044 for (count = 0; count < num_pds; count++)
2045 raid_device->pd_handle[count] = 0;
2051 * _scsih_enable_tlr - setting TLR flags
2052 * @ioc: per adapter object
2053 * @sdev: scsi device struct
2055 * Enabling Transaction Layer Retries for tape devices when
2056 * vpd page 0x90 is present
2060 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
2063 if (sdev->type != TYPE_TAPE)
2066 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2069 sas_enable_tlr(sdev);
2070 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2071 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2077 * _scsih_slave_configure - device configure routine.
2078 * @sdev: scsi device struct
2080 * Returns 0 if ok. Any other return is assumed to be an error and
2081 * the device is ignored.
2084 _scsih_slave_configure(struct scsi_device *sdev)
2086 struct Scsi_Host *shost = sdev->host;
2087 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2088 struct MPT2SAS_DEVICE *sas_device_priv_data;
2089 struct MPT2SAS_TARGET *sas_target_priv_data;
2090 struct _sas_device *sas_device;
2091 struct _raid_device *raid_device;
2092 unsigned long flags;
2097 u16 handle, volume_handle = 0;
2098 u64 volume_wwid = 0;
2101 sas_device_priv_data = sdev->hostdata;
2102 sas_device_priv_data->configured_lun = 1;
2103 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2104 sas_target_priv_data = sas_device_priv_data->sas_target;
2105 handle = sas_target_priv_data->handle;
2107 /* raid volume handling */
2108 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2110 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2111 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
2112 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2114 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2115 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2116 __LINE__, __func__));
2120 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2121 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2122 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2123 __LINE__, __func__));
2127 * WARPDRIVE: Initialize the required data for Direct IO
2129 _scsih_init_warpdrive_properties(ioc, raid_device);
2131 /* RAID Queue Depth Support
2132 * IS volume = underlying qdepth of drive type, either
2133 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2134 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2136 if (raid_device->device_info &
2137 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2138 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2141 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2142 if (raid_device->device_info &
2143 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2149 switch (raid_device->volume_type) {
2150 case MPI2_RAID_VOL_TYPE_RAID0:
2153 case MPI2_RAID_VOL_TYPE_RAID1E:
2154 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2155 if (ioc->manu_pg10.OEMIdentifier &&
2156 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2157 MFG10_GF0_R10_DISPLAY) &&
2158 !(raid_device->num_pds % 2))
2163 case MPI2_RAID_VOL_TYPE_RAID1:
2164 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2167 case MPI2_RAID_VOL_TYPE_RAID10:
2168 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2171 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2173 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2178 if (!ioc->hide_ir_msg)
2179 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2180 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2181 r_level, raid_device->handle,
2182 (unsigned long long)raid_device->wwid,
2183 raid_device->num_pds, ds);
2184 _scsih_change_queue_depth(sdev, qdepth);
2185 /* raid transport support */
2186 if (!ioc->is_warpdrive)
2187 _scsih_set_level(sdev, raid_device->volume_type);
2191 /* non-raid handling */
2192 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2193 if (mpt2sas_config_get_volume_handle(ioc, handle,
2195 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2196 "failure at %s:%d/%s()!\n", ioc->name,
2197 __FILE__, __LINE__, __func__));
2200 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2201 volume_handle, &volume_wwid)) {
2202 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2203 "failure at %s:%d/%s()!\n", ioc->name,
2204 __FILE__, __LINE__, __func__));
2209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2210 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
2211 sas_device_priv_data->sas_target->sas_address);
2213 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2214 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2215 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2216 __LINE__, __func__));
2219 sas_device->volume_handle = volume_handle;
2220 sas_device->volume_wwid = volume_wwid;
2221 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2222 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2226 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2227 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2229 else if (sas_device->device_info &
2230 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2233 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2234 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2235 ds, sas_device->handle,
2236 (unsigned long long)sas_device->sas_address,
2238 (unsigned long long)sas_device->device_name);
2239 sdev_printk(KERN_INFO, sdev, "%s: "
2240 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2241 (unsigned long long) sas_device->enclosure_logical_id,
2244 sas_device_put(sas_device);
2245 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2247 _scsih_display_sata_capabilities(ioc, handle, sdev);
2249 _scsih_change_queue_depth(sdev, qdepth);
2252 sas_read_port_mode_page(sdev);
2253 _scsih_enable_tlr(ioc, sdev);
2260 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2261 * @sdev: scsi device struct
2262 * @bdev: pointer to block device context
2263 * @capacity: device size (in 512 byte sectors)
2264 * @params: three element array to place output:
2265 * params[0] number of heads (max 255)
2266 * params[1] number of sectors (max 63)
2267 * params[2] number of cylinders
2272 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2273 sector_t capacity, int params[])
2283 dummy = heads * sectors;
2284 cylinders = capacity;
2285 sector_div(cylinders, dummy);
2288 * Handle extended translation size for logical drives
2291 if ((ulong)capacity >= 0x200000) {
2294 dummy = heads * sectors;
2295 cylinders = capacity;
2296 sector_div(cylinders, dummy);
2301 params[1] = sectors;
2302 params[2] = cylinders;
2308 * _scsih_response_code - translation of device response code
2309 * @ioc: per adapter object
2310 * @response_code: response code returned by the device
2315 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2319 switch (response_code) {
2320 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2321 desc = "task management request completed";
2323 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2324 desc = "invalid frame";
2326 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2327 desc = "task management request not supported";
2329 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2330 desc = "task management request failed";
2332 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2333 desc = "task management request succeeded";
2335 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2336 desc = "invalid lun";
2339 desc = "overlapped tag attempted";
2341 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2342 desc = "task queued, however not sent to target";
2348 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2349 ioc->name, response_code, desc);
2353 * _scsih_tm_done - tm completion routine
2354 * @ioc: per adapter object
2355 * @smid: system request message index
2356 * @msix_index: MSIX table index supplied by the OS
2357 * @reply: reply message frame(lower 32bit addr)
2360 * The callback handler when using scsih_issue_tm.
2362 * Return 1 meaning mf should be freed from _base_interrupt
2363 * 0 means the mf is freed from this function.
2366 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2368 MPI2DefaultReply_t *mpi_reply;
2370 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2372 if (ioc->tm_cmds.smid != smid)
2374 mpt2sas_base_flush_reply_queues(ioc);
2375 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2376 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2378 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2379 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2381 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2382 complete(&ioc->tm_cmds.done);
2387 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2388 * @ioc: per adapter object
2389 * @handle: device handle
2391 * During taskmangement request, we need to freeze the device queue.
2394 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2396 struct MPT2SAS_DEVICE *sas_device_priv_data;
2397 struct scsi_device *sdev;
2400 shost_for_each_device(sdev, ioc->shost) {
2403 sas_device_priv_data = sdev->hostdata;
2404 if (!sas_device_priv_data)
2406 if (sas_device_priv_data->sas_target->handle == handle) {
2407 sas_device_priv_data->sas_target->tm_busy = 1;
2409 ioc->ignore_loginfos = 1;
2415 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2416 * @ioc: per adapter object
2417 * @handle: device handle
2419 * During taskmangement request, we need to freeze the device queue.
2422 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2424 struct MPT2SAS_DEVICE *sas_device_priv_data;
2425 struct scsi_device *sdev;
2428 shost_for_each_device(sdev, ioc->shost) {
2431 sas_device_priv_data = sdev->hostdata;
2432 if (!sas_device_priv_data)
2434 if (sas_device_priv_data->sas_target->handle == handle) {
2435 sas_device_priv_data->sas_target->tm_busy = 0;
2437 ioc->ignore_loginfos = 0;
2444 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2445 * @ioc: per adapter struct
2446 * @device_handle: device handle
2447 * @channel: the channel assigned by the OS
2448 * @id: the id assigned by the OS
2450 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2451 * @smid_task: smid assigned to the task
2452 * @timeout: timeout in seconds
2453 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2456 * A generic API for sending task management requests to firmware.
2458 * The callback index is set inside `ioc->tm_cb_idx`.
2460 * Return SUCCESS or FAILED.
2463 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2464 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2465 enum mutex_type m_type)
2467 Mpi2SCSITaskManagementRequest_t *mpi_request;
2468 Mpi2SCSITaskManagementReply_t *mpi_reply;
2471 unsigned long timeleft;
2472 struct scsiio_tracker *scsi_lookup = NULL;
2475 if (m_type == TM_MUTEX_ON)
2476 mutex_lock(&ioc->tm_cmds.mutex);
2477 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2478 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2479 __func__, ioc->name);
2484 if (ioc->shost_recovery || ioc->remove_host ||
2485 ioc->pci_error_recovery) {
2486 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2487 __func__, ioc->name);
2492 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2493 if (ioc_state & MPI2_DOORBELL_USED) {
2494 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2495 "active!\n", ioc->name));
2496 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2498 rc = (!rc) ? SUCCESS : FAILED;
2502 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2503 mpt2sas_base_fault_info(ioc, ioc_state &
2504 MPI2_DOORBELL_DATA_MASK);
2505 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2507 rc = (!rc) ? SUCCESS : FAILED;
2511 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2513 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2514 ioc->name, __func__);
2519 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2520 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2522 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2523 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2525 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2526 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2527 ioc->tm_cmds.smid = smid;
2528 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2529 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2530 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2531 mpi_request->DevHandle = cpu_to_le16(handle);
2532 mpi_request->TaskType = type;
2533 mpi_request->TaskMID = cpu_to_le16(smid_task);
2534 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2535 mpt2sas_scsih_set_tm_flag(ioc, handle);
2536 init_completion(&ioc->tm_cmds.done);
2537 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2538 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2539 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2540 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2541 ioc->name, __func__);
2542 _debug_dump_mf(mpi_request,
2543 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2544 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2545 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2547 rc = (!rc) ? SUCCESS : FAILED;
2548 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2549 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2554 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2555 mpi_reply = ioc->tm_cmds.reply;
2556 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2557 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2558 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2559 le32_to_cpu(mpi_reply->IOCLogInfo),
2560 le32_to_cpu(mpi_reply->TerminationCount)));
2561 if (ioc->logging_level & MPT_DEBUG_TM) {
2562 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2563 if (mpi_reply->IOCStatus)
2564 _debug_dump_mf(mpi_request,
2565 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2570 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2572 if (scsi_lookup->scmd == NULL)
2577 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2578 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2584 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2585 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2586 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2591 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2599 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2600 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2601 if (m_type == TM_MUTEX_ON)
2602 mutex_unlock(&ioc->tm_cmds.mutex);
2607 if (m_type == TM_MUTEX_ON)
2608 mutex_unlock(&ioc->tm_cmds.mutex);
2613 * _scsih_tm_display_info - displays info about the device
2614 * @ioc: per adapter struct
2615 * @scmd: pointer to scsi command object
2617 * Called by task management callback handlers.
2620 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2622 struct scsi_target *starget = scmd->device->sdev_target;
2623 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2624 struct _sas_device *sas_device = NULL;
2625 unsigned long flags;
2626 char *device_str = NULL;
2630 if (ioc->hide_ir_msg)
2631 device_str = "WarpDrive";
2633 device_str = "volume";
2635 scsi_print_command(scmd);
2636 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2637 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2638 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2639 device_str, (unsigned long long)priv_target->sas_address);
2641 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2642 sas_device = __mpt2sas_get_sdev_from_target(ioc, priv_target);
2644 if (priv_target->flags &
2645 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2646 starget_printk(KERN_INFO, starget,
2647 "volume handle(0x%04x), "
2648 "volume wwid(0x%016llx)\n",
2649 sas_device->volume_handle,
2650 (unsigned long long)sas_device->volume_wwid);
2652 starget_printk(KERN_INFO, starget,
2653 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2655 (unsigned long long)sas_device->sas_address,
2657 starget_printk(KERN_INFO, starget,
2658 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2659 (unsigned long long)sas_device->enclosure_logical_id,
2662 sas_device_put(sas_device);
2664 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2669 * _scsih_abort - eh threads main abort routine
2670 * @scmd: pointer to scsi command object
2672 * Returns SUCCESS if command aborted else FAILED
2675 _scsih_abort(struct scsi_cmnd *scmd)
2677 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2678 struct MPT2SAS_DEVICE *sas_device_priv_data;
2683 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2684 "scmd(%p)\n", scmd);
2685 _scsih_tm_display_info(ioc, scmd);
2687 sas_device_priv_data = scmd->device->hostdata;
2688 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2689 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2690 "scmd(%p)\n", scmd);
2691 scmd->result = DID_NO_CONNECT << 16;
2692 scmd->scsi_done(scmd);
2697 /* search for the command */
2698 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2700 scmd->result = DID_RESET << 16;
2705 /* for hidden raid components and volumes this is not supported */
2706 if (sas_device_priv_data->sas_target->flags &
2707 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2708 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2709 scmd->result = DID_RESET << 16;
2714 mpt2sas_halt_firmware(ioc);
2716 handle = sas_device_priv_data->sas_target->handle;
2717 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2718 scmd->device->id, scmd->device->lun,
2719 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2722 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2723 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2728 * _scsih_dev_reset - eh threads main device reset routine
2729 * @scmd: pointer to scsi command object
2731 * Returns SUCCESS if command aborted else FAILED
2734 _scsih_dev_reset(struct scsi_cmnd *scmd)
2736 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2737 struct MPT2SAS_DEVICE *sas_device_priv_data;
2738 struct _sas_device *sas_device = NULL;
2742 struct scsi_target *starget = scmd->device->sdev_target;
2743 struct MPT2SAS_TARGET *target_priv_data = starget->hostdata;
2745 starget_printk(KERN_INFO, starget, "attempting device reset! "
2746 "scmd(%p)\n", scmd);
2747 _scsih_tm_display_info(ioc, scmd);
2749 sas_device_priv_data = scmd->device->hostdata;
2750 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2751 starget_printk(KERN_INFO, starget, "device been deleted! "
2752 "scmd(%p)\n", scmd);
2753 scmd->result = DID_NO_CONNECT << 16;
2754 scmd->scsi_done(scmd);
2759 /* for hidden raid components obtain the volume_handle */
2761 if (sas_device_priv_data->sas_target->flags &
2762 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2763 sas_device = mpt2sas_get_sdev_from_target(ioc,
2766 handle = sas_device->volume_handle;
2768 handle = sas_device_priv_data->sas_target->handle;
2771 scmd->result = DID_RESET << 16;
2776 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2777 scmd->device->id, scmd->device->lun,
2778 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2781 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2782 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2785 sas_device_put(sas_device);
2791 * _scsih_target_reset - eh threads main target reset routine
2792 * @scmd: pointer to scsi command object
2794 * Returns SUCCESS if command aborted else FAILED
2797 _scsih_target_reset(struct scsi_cmnd *scmd)
2799 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2800 struct MPT2SAS_DEVICE *sas_device_priv_data;
2801 struct _sas_device *sas_device = NULL;
2804 struct scsi_target *starget = scmd->device->sdev_target;
2805 struct MPT2SAS_TARGET *target_priv_data = starget->hostdata;
2807 starget_printk(KERN_INFO, starget, "attempting target reset! "
2808 "scmd(%p)\n", scmd);
2809 _scsih_tm_display_info(ioc, scmd);
2811 sas_device_priv_data = scmd->device->hostdata;
2812 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2813 starget_printk(KERN_INFO, starget, "target been deleted! "
2814 "scmd(%p)\n", scmd);
2815 scmd->result = DID_NO_CONNECT << 16;
2816 scmd->scsi_done(scmd);
2821 /* for hidden raid components obtain the volume_handle */
2823 if (sas_device_priv_data->sas_target->flags &
2824 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2825 sas_device = mpt2sas_get_sdev_from_target(ioc,
2828 handle = sas_device->volume_handle;
2830 handle = sas_device_priv_data->sas_target->handle;
2833 scmd->result = DID_RESET << 16;
2838 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2839 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2843 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2844 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2847 sas_device_put(sas_device);
2853 * _scsih_host_reset - eh threads main host reset routine
2854 * @scmd: pointer to scsi command object
2856 * Returns SUCCESS if command aborted else FAILED
2859 _scsih_host_reset(struct scsi_cmnd *scmd)
2861 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2864 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2866 scsi_print_command(scmd);
2868 if (ioc->is_driver_loading) {
2869 printk(MPT2SAS_INFO_FMT "Blocking the host reset\n",
2875 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2877 r = (retval < 0) ? FAILED : SUCCESS;
2880 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2881 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2887 * _scsih_fw_event_add - insert and queue up fw_event
2888 * @ioc: per adapter object
2889 * @fw_event: object describing the event
2890 * Context: This function will acquire ioc->fw_event_lock.
2892 * This adds the firmware event object into link list, then queues it up to
2893 * be processed from user context.
2898 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2900 unsigned long flags;
2902 if (ioc->firmware_event_thread == NULL)
2905 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2906 fw_event_work_get(fw_event);
2907 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2908 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2909 fw_event_work_get(fw_event);
2910 queue_delayed_work(ioc->firmware_event_thread,
2911 &fw_event->delayed_work, 0);
2912 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2916 * _scsih_fw_event_del_from_list - delete fw_event from the list
2917 * @ioc: per adapter object
2918 * @fw_event: object describing the event
2919 * Context: This function will acquire ioc->fw_event_lock.
2921 * If the fw_event is on the fw_event_list, remove it and do a put.
2926 _scsih_fw_event_del_from_list(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2929 unsigned long flags;
2931 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2932 if (!list_empty(&fw_event->list)) {
2933 list_del_init(&fw_event->list);
2934 fw_event_work_put(fw_event);
2936 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2940 * _scsih_error_recovery_delete_devices - remove devices not responding
2941 * @ioc: per adapter object
2946 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2948 struct fw_event_work *fw_event;
2950 if (ioc->is_driver_loading)
2953 fw_event = alloc_fw_event_work(0);
2957 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2958 fw_event->ioc = ioc;
2959 _scsih_fw_event_add(ioc, fw_event);
2960 fw_event_work_put(fw_event);
2964 * mpt2sas_port_enable_complete - port enable completed (fake event)
2965 * @ioc: per adapter object
2970 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2972 struct fw_event_work *fw_event;
2974 fw_event = alloc_fw_event_work(0);
2977 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2978 fw_event->ioc = ioc;
2979 _scsih_fw_event_add(ioc, fw_event);
2980 fw_event_work_put(fw_event);
2983 static struct fw_event_work *dequeue_next_fw_event(struct MPT2SAS_ADAPTER *ioc)
2985 unsigned long flags;
2986 struct fw_event_work *fw_event = NULL;
2988 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2989 if (!list_empty(&ioc->fw_event_list)) {
2990 fw_event = list_first_entry(&ioc->fw_event_list,
2991 struct fw_event_work, list);
2992 list_del_init(&fw_event->list);
2994 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3000 * _scsih_fw_event_cleanup_queue - cleanup event queue
3001 * @ioc: per adapter object
3003 * Walk the firmware event queue, either killing timers, or waiting
3004 * for outstanding events to complete
3009 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
3011 struct fw_event_work *fw_event;
3013 if (list_empty(&ioc->fw_event_list) ||
3014 !ioc->firmware_event_thread || in_interrupt())
3017 while ((fw_event = dequeue_next_fw_event(ioc))) {
3019 * Wait on the fw_event to complete. If this returns 1, then
3020 * the event was never executed, and we need a put for the
3021 * reference the delayed_work had on the fw_event.
3023 * If it did execute, we wait for it to finish, and the put will
3024 * happen from _firmware_event_work()
3026 if (cancel_delayed_work_sync(&fw_event->delayed_work))
3027 fw_event_work_put(fw_event);
3029 fw_event_work_put(fw_event);
3034 * _scsih_ublock_io_all_device - unblock every device
3035 * @ioc: per adapter object
3037 * change the device state from block to running
3040 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
3042 struct MPT2SAS_DEVICE *sas_device_priv_data;
3043 struct scsi_device *sdev;
3045 shost_for_each_device(sdev, ioc->shost) {
3046 sas_device_priv_data = sdev->hostdata;
3047 if (!sas_device_priv_data)
3049 if (!sas_device_priv_data->block)
3051 sas_device_priv_data->block = 0;
3052 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
3054 sas_device_priv_data->sas_target->handle));
3055 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
3059 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
3060 * @ioc: per adapter object
3061 * @handle: device handle
3063 * During device pull we need to appropiately set the sdev state.
3066 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
3068 struct MPT2SAS_DEVICE *sas_device_priv_data;
3069 struct scsi_device *sdev;
3071 shost_for_each_device(sdev, ioc->shost) {
3072 sas_device_priv_data = sdev->hostdata;
3073 if (!sas_device_priv_data)
3075 if (!sas_device_priv_data->block)
3077 if (sas_device_priv_data->sas_target->sas_address ==
3079 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3080 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
3081 "sas address(0x%016llx)\n", ioc->name,
3082 (unsigned long long)sas_address));
3083 sas_device_priv_data->block = 0;
3084 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
3090 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3091 * @ioc: per adapter object
3092 * @handle: device handle
3094 * During device pull we need to appropiately set the sdev state.
3097 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
3099 struct MPT2SAS_DEVICE *sas_device_priv_data;
3100 struct scsi_device *sdev;
3102 shost_for_each_device(sdev, ioc->shost) {
3103 sas_device_priv_data = sdev->hostdata;
3104 if (!sas_device_priv_data)
3106 if (sas_device_priv_data->block)
3108 sas_device_priv_data->block = 1;
3109 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
3111 sas_device_priv_data->sas_target->handle));
3112 scsi_internal_device_block(sdev);
3118 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3119 * @ioc: per adapter object
3120 * @handle: device handle
3122 * During device pull we need to appropiately set the sdev state.
3125 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3127 struct MPT2SAS_DEVICE *sas_device_priv_data;
3128 struct scsi_device *sdev;
3130 shost_for_each_device(sdev, ioc->shost) {
3131 sas_device_priv_data = sdev->hostdata;
3132 if (!sas_device_priv_data)
3134 if (sas_device_priv_data->block)
3136 if (sas_device_priv_data->sas_target->handle == handle) {
3137 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3138 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
3139 "handle(0x%04x)\n", ioc->name, handle));
3140 sas_device_priv_data->block = 1;
3141 scsi_internal_device_block(sdev);
3147 * _scsih_block_io_to_children_attached_to_ex
3148 * @ioc: per adapter object
3149 * @sas_expander: the sas_device object
3151 * This routine set sdev state to SDEV_BLOCK for all devices
3152 * attached to this expander. This function called when expander is
3156 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3157 struct _sas_node *sas_expander)
3159 struct _sas_port *mpt2sas_port;
3160 struct _sas_device *sas_device;
3161 struct _sas_node *expander_sibling;
3162 unsigned long flags;
3167 list_for_each_entry(mpt2sas_port,
3168 &sas_expander->sas_port_list, port_list) {
3169 if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) {
3170 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3171 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
3172 mpt2sas_port->remote_identify.sas_address);
3174 set_bit(sas_device->handle,
3175 ioc->blocking_handles);
3176 sas_device_put(sas_device);
3178 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3182 list_for_each_entry(mpt2sas_port,
3183 &sas_expander->sas_port_list, port_list) {
3185 if (mpt2sas_port->remote_identify.device_type ==
3186 SAS_EDGE_EXPANDER_DEVICE ||
3187 mpt2sas_port->remote_identify.device_type ==
3188 SAS_FANOUT_EXPANDER_DEVICE) {
3190 mpt2sas_scsih_expander_find_by_sas_address(
3191 ioc, mpt2sas_port->remote_identify.sas_address);
3192 _scsih_block_io_to_children_attached_to_ex(ioc,
3199 * _scsih_block_io_to_children_attached_directly
3200 * @ioc: per adapter object
3201 * @event_data: topology change event data
3203 * This routine set sdev state to SDEV_BLOCK for all devices
3204 * direct attached during device pull.
3207 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3208 Mpi2EventDataSasTopologyChangeList_t *event_data)
3215 for (i = 0; i < event_data->NumEntries; i++) {
3216 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3219 phy_number = event_data->StartPhyNum + i;
3220 reason_code = event_data->PHY[i].PhyStatus &
3221 MPI2_EVENT_SAS_TOPO_RC_MASK;
3222 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3223 _scsih_block_io_device(ioc, handle);
3228 * _scsih_tm_tr_send - send task management request
3229 * @ioc: per adapter object
3230 * @handle: device handle
3231 * Context: interrupt time.
3233 * This code is to initiate the device removal handshake protocol
3234 * with controller firmware. This function will issue target reset
3235 * using high priority request queue. It will send a sas iounit
3236 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3238 * This is designed to send muliple task management request at the same
3239 * time to the fifo. If the fifo is full, we will append the request,
3240 * and process it in a future completion.
3243 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3245 Mpi2SCSITaskManagementRequest_t *mpi_request;
3247 struct _sas_device *sas_device = NULL;
3248 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3249 u64 sas_address = 0;
3250 unsigned long flags;
3251 struct _tr_list *delayed_tr;
3254 if (ioc->remove_host) {
3255 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3256 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3258 } else if (ioc->pci_error_recovery) {
3259 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3260 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3264 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3265 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3266 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3267 "operational: handle(0x%04x)\n", __func__, ioc->name,
3272 /* if PD, then return */
3273 if (test_bit(handle, ioc->pd_handles))
3276 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3277 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
3278 if (sas_device && sas_device->starget &&
3279 sas_device->starget->hostdata) {
3280 sas_target_priv_data = sas_device->starget->hostdata;
3281 sas_target_priv_data->deleted = 1;
3282 sas_address = sas_device->sas_address;
3284 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3286 if (sas_target_priv_data) {
3287 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3288 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3289 (unsigned long long)sas_address));
3290 _scsih_ublock_io_device(ioc, sas_address);
3291 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3294 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3296 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3299 INIT_LIST_HEAD(&delayed_tr->list);
3300 delayed_tr->handle = handle;
3301 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3302 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3303 "DELAYED:tr:handle(0x%04x), (open)\n",
3304 ioc->name, handle));
3308 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3309 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3310 ioc->tm_tr_cb_idx));
3311 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3312 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3313 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3314 mpi_request->DevHandle = cpu_to_le16(handle);
3315 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3316 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3319 sas_device_put(sas_device);
3325 * _scsih_sas_control_complete - completion routine
3326 * @ioc: per adapter object
3327 * @smid: system request message index
3328 * @msix_index: MSIX table index supplied by the OS
3329 * @reply: reply message frame(lower 32bit addr)
3330 * Context: interrupt time.
3332 * This is the sas iounit control completion routine.
3333 * This code is part of the code to initiate the device removal
3334 * handshake protocol with controller firmware.
3336 * Return 1 meaning mf should be freed from _base_interrupt
3337 * 0 means the mf is freed from this function.
3340 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3341 u8 msix_index, u32 reply)
3343 Mpi2SasIoUnitControlReply_t *mpi_reply =
3344 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3345 if (likely(mpi_reply)) {
3346 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3347 "sc_complete:handle(0x%04x), (open) "
3348 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3349 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3350 le16_to_cpu(mpi_reply->IOCStatus),
3351 le32_to_cpu(mpi_reply->IOCLogInfo)));
3353 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3354 ioc->name, __FILE__, __LINE__, __func__);
3360 * _scsih_tm_tr_volume_send - send target reset request for volumes
3361 * @ioc: per adapter object
3362 * @handle: device handle
3363 * Context: interrupt time.
3365 * This is designed to send muliple task management request at the same
3366 * time to the fifo. If the fifo is full, we will append the request,
3367 * and process it in a future completion.
3370 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3372 Mpi2SCSITaskManagementRequest_t *mpi_request;
3374 struct _tr_list *delayed_tr;
3376 if (ioc->shost_recovery || ioc->remove_host ||
3377 ioc->pci_error_recovery) {
3378 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3379 "progress!\n", __func__, ioc->name));
3383 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3385 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3388 INIT_LIST_HEAD(&delayed_tr->list);
3389 delayed_tr->handle = handle;
3390 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3391 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3392 "DELAYED:tr:handle(0x%04x), (open)\n",
3393 ioc->name, handle));
3397 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3398 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3399 ioc->tm_tr_volume_cb_idx));
3400 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3401 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3402 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3403 mpi_request->DevHandle = cpu_to_le16(handle);
3404 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3405 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3409 * _scsih_tm_volume_tr_complete - target reset completion
3410 * @ioc: per adapter object
3411 * @smid: system request message index
3412 * @msix_index: MSIX table index supplied by the OS
3413 * @reply: reply message frame(lower 32bit addr)
3414 * Context: interrupt time.
3416 * Return 1 meaning mf should be freed from _base_interrupt
3417 * 0 means the mf is freed from this function.
3420 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3421 u8 msix_index, u32 reply)
3424 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3425 Mpi2SCSITaskManagementReply_t *mpi_reply =
3426 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3428 if (ioc->shost_recovery || ioc->remove_host ||
3429 ioc->pci_error_recovery) {
3430 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3431 "progress!\n", __func__, ioc->name));
3434 if (unlikely(!mpi_reply)) {
3435 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3436 ioc->name, __FILE__, __LINE__, __func__);
3439 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3440 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3441 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3442 dewtprintk(ioc, printk("spurious interrupt: "
3443 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3444 le16_to_cpu(mpi_reply->DevHandle), smid));
3448 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3449 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3450 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3451 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3452 le32_to_cpu(mpi_reply->IOCLogInfo),
3453 le32_to_cpu(mpi_reply->TerminationCount)));
3455 return _scsih_check_for_pending_tm(ioc, smid);
3459 * _scsih_tm_tr_complete -
3460 * @ioc: per adapter object
3461 * @smid: system request message index
3462 * @msix_index: MSIX table index supplied by the OS
3463 * @reply: reply message frame(lower 32bit addr)
3464 * Context: interrupt time.
3466 * This is the target reset completion routine.
3467 * This code is part of the code to initiate the device removal
3468 * handshake protocol with controller firmware.
3469 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3471 * Return 1 meaning mf should be freed from _base_interrupt
3472 * 0 means the mf is freed from this function.
3475 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3479 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3480 Mpi2SCSITaskManagementReply_t *mpi_reply =
3481 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3482 Mpi2SasIoUnitControlRequest_t *mpi_request;
3486 if (ioc->remove_host) {
3487 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3488 "removed\n", __func__, ioc->name));
3490 } else if (ioc->pci_error_recovery) {
3491 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3492 "error recovery\n", __func__, ioc->name));
3495 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3496 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3497 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3498 "operational\n", __func__, ioc->name));
3501 if (unlikely(!mpi_reply)) {
3502 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3503 ioc->name, __FILE__, __LINE__, __func__);
3506 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3507 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3508 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3510 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3511 le16_to_cpu(mpi_reply->DevHandle), smid));
3515 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3516 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3517 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3518 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3519 le32_to_cpu(mpi_reply->IOCLogInfo),
3520 le32_to_cpu(mpi_reply->TerminationCount)));
3522 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3523 if (!smid_sas_ctrl) {
3524 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3525 ioc->name, __func__);
3529 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3530 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3531 ioc->tm_sas_control_cb_idx));
3532 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3533 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3534 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3535 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3536 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3537 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3539 return _scsih_check_for_pending_tm(ioc, smid);
3543 * _scsih_check_for_pending_tm - check for pending task management
3544 * @ioc: per adapter object
3545 * @smid: system request message index
3547 * This will check delayed target reset list, and feed the
3550 * Return 1 meaning mf should be freed from _base_interrupt
3551 * 0 means the mf is freed from this function.
3554 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3556 struct _tr_list *delayed_tr;
3558 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3559 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3560 struct _tr_list, list);
3561 mpt2sas_base_free_smid(ioc, smid);
3562 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3563 list_del(&delayed_tr->list);
3568 if (!list_empty(&ioc->delayed_tr_list)) {
3569 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3570 struct _tr_list, list);
3571 mpt2sas_base_free_smid(ioc, smid);
3572 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3573 list_del(&delayed_tr->list);
3582 * _scsih_check_topo_delete_events - sanity check on topo events
3583 * @ioc: per adapter object
3584 * @event_data: the event data payload
3586 * This routine added to better handle cable breaker.
3588 * This handles the case where driver receives multiple expander
3589 * add and delete events in a single shot. When there is a delete event
3590 * the routine will void any pending add events waiting in the event queue.
3595 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3596 Mpi2EventDataSasTopologyChangeList_t *event_data)
3598 struct fw_event_work *fw_event;
3599 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3600 u16 expander_handle;
3601 struct _sas_node *sas_expander;
3602 unsigned long flags;
3606 for (i = 0 ; i < event_data->NumEntries; i++) {
3607 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3610 reason_code = event_data->PHY[i].PhyStatus &
3611 MPI2_EVENT_SAS_TOPO_RC_MASK;
3612 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3613 _scsih_tm_tr_send(ioc, handle);
3616 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3617 if (expander_handle < ioc->sas_hba.num_phys) {
3618 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3621 if (event_data->ExpStatus ==
3622 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3623 /* put expander attached devices into blocking state */
3624 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3625 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3627 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3628 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3630 handle = find_first_bit(ioc->blocking_handles,
3631 ioc->facts.MaxDevHandle);
3632 if (handle < ioc->facts.MaxDevHandle)
3633 _scsih_block_io_device(ioc, handle);
3634 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3635 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3636 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3638 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3641 /* mark ignore flag for pending events */
3642 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3643 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3644 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3647 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3648 fw_event->event_data;
3649 if (local_event_data->ExpStatus ==
3650 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3651 local_event_data->ExpStatus ==
3652 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3653 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3655 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3656 "setting ignoring flag\n", ioc->name));
3657 fw_event->ignore = 1;
3661 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3665 * _scsih_set_volume_delete_flag - setting volume delete flag
3666 * @ioc: per adapter object
3667 * @handle: device handle
3673 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3675 struct _raid_device *raid_device;
3676 struct MPT2SAS_TARGET *sas_target_priv_data;
3677 unsigned long flags;
3679 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3680 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3681 if (raid_device && raid_device->starget &&
3682 raid_device->starget->hostdata) {
3683 sas_target_priv_data =
3684 raid_device->starget->hostdata;
3685 sas_target_priv_data->deleted = 1;
3686 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3687 "setting delete flag: handle(0x%04x), "
3688 "wwid(0x%016llx)\n", ioc->name, handle,
3689 (unsigned long long) raid_device->wwid));
3691 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3695 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3696 * @handle: input handle
3697 * @a: handle for volume a
3698 * @b: handle for volume b
3700 * IR firmware only supports two raid volumes. The purpose of this
3701 * routine is to set the volume handle in either a or b. When the given
3702 * input handle is non-zero, or when a and b have not been set before.
3705 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3707 if (!handle || handle == *a || handle == *b)
3716 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3717 * @ioc: per adapter object
3718 * @event_data: the event data payload
3719 * Context: interrupt time.
3721 * This routine will send target reset to volume, followed by target
3722 * resets to the PDs. This is called when a PD has been removed, or
3723 * volume has been deleted or removed. When the target reset is sent
3724 * to volume, the PD target resets need to be queued to start upon
3725 * completion of the volume target reset.
3730 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3731 Mpi2EventDataIrConfigChangeList_t *event_data)
3733 Mpi2EventIrConfigElement_t *element;
3735 u16 handle, volume_handle, a, b;
3736 struct _tr_list *delayed_tr;
3741 if (ioc->is_warpdrive)
3744 /* Volume Resets for Deleted or Removed */
3745 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3746 for (i = 0; i < event_data->NumElements; i++, element++) {
3747 if (element->ReasonCode ==
3748 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3749 element->ReasonCode ==
3750 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3751 volume_handle = le16_to_cpu(element->VolDevHandle);
3752 _scsih_set_volume_delete_flag(ioc, volume_handle);
3753 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3757 /* Volume Resets for UNHIDE events */
3758 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3759 for (i = 0; i < event_data->NumElements; i++, element++) {
3760 if (le32_to_cpu(event_data->Flags) &
3761 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3763 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3764 volume_handle = le16_to_cpu(element->VolDevHandle);
3765 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3770 _scsih_tm_tr_volume_send(ioc, a);
3772 _scsih_tm_tr_volume_send(ioc, b);
3774 /* PD target resets */
3775 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3776 for (i = 0; i < event_data->NumElements; i++, element++) {
3777 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3779 handle = le16_to_cpu(element->PhysDiskDevHandle);
3780 volume_handle = le16_to_cpu(element->VolDevHandle);
3781 clear_bit(handle, ioc->pd_handles);
3783 _scsih_tm_tr_send(ioc, handle);
3784 else if (volume_handle == a || volume_handle == b) {
3785 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3786 BUG_ON(!delayed_tr);
3787 INIT_LIST_HEAD(&delayed_tr->list);
3788 delayed_tr->handle = handle;
3789 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3790 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3791 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3794 _scsih_tm_tr_send(ioc, handle);
3800 * _scsih_check_volume_delete_events - set delete flag for volumes
3801 * @ioc: per adapter object
3802 * @event_data: the event data payload
3803 * Context: interrupt time.
3805 * This will handle the case when the cable connected to entire volume is
3806 * pulled. We will take care of setting the deleted flag so normal IO will
3812 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3813 Mpi2EventDataIrVolume_t *event_data)
3817 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3819 state = le32_to_cpu(event_data->NewValue);
3820 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3821 MPI2_RAID_VOL_STATE_FAILED)
3822 _scsih_set_volume_delete_flag(ioc,
3823 le16_to_cpu(event_data->VolDevHandle));
3827 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3828 * @ioc: per adapter object
3829 * @event_data: the temp threshold event data
3830 * Context: interrupt time.
3835 _scsih_temp_threshold_events(struct MPT2SAS_ADAPTER *ioc,
3836 Mpi2EventDataTemperature_t *event_data)
3838 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3839 printk(MPT2SAS_ERR_FMT "Temperature Threshold flags %s%s%s%s"
3840 " exceeded for Sensor: %d !!!\n", ioc->name,
3841 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3842 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3843 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3844 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3845 event_data->SensorNum);
3846 printk(MPT2SAS_ERR_FMT "Current Temp In Celsius: %d\n",
3847 ioc->name, event_data->CurrentTemperature);
3852 * _scsih_flush_running_cmds - completing outstanding commands.
3853 * @ioc: per adapter object
3855 * The flushing out of all pending scmd commands following host reset,
3856 * where all IO is dropped to the floor.
3861 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3863 struct scsi_cmnd *scmd;
3867 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3868 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3872 mpt2sas_base_free_smid(ioc, smid);
3873 scsi_dma_unmap(scmd);
3874 if (ioc->pci_error_recovery)
3875 scmd->result = DID_NO_CONNECT << 16;
3877 scmd->result = DID_RESET << 16;
3878 scmd->scsi_done(scmd);
3880 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3885 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3886 * @scmd: pointer to scsi command object
3887 * @mpi_request: pointer to the SCSI_IO reqest message frame
3889 * Supporting protection 1 and 3.
3894 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3897 unsigned char prot_op = scsi_get_prot_op(scmd);
3898 unsigned char prot_type = scsi_get_prot_type(scmd);
3900 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3903 if (prot_op == SCSI_PROT_READ_STRIP)
3904 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3905 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3906 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3910 switch (prot_type) {
3911 case SCSI_PROT_DIF_TYPE1:
3912 case SCSI_PROT_DIF_TYPE2:
3915 * enable ref/guard checking
3916 * auto increment ref tag
3918 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3919 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3920 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3921 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3922 cpu_to_be32(scsi_get_lba(scmd));
3925 case SCSI_PROT_DIF_TYPE3:
3928 * enable guard checking
3930 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3933 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3934 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3938 * _scsih_eedp_error_handling - return sense code for EEDP errors
3939 * @scmd: pointer to scsi command object
3940 * @ioc_status: ioc status
3945 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3949 switch (ioc_status) {
3950 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3953 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3956 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3964 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3965 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3966 SAM_STAT_CHECK_CONDITION;
3970 * _scsih_scsi_direct_io_get - returns direct io flag
3971 * @ioc: per adapter object
3972 * @smid: system request message index
3974 * Returns the smid stored scmd pointer.
3977 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3979 return ioc->scsi_lookup[smid - 1].direct_io;
3983 * _scsih_scsi_direct_io_set - sets direct io flag
3984 * @ioc: per adapter object
3985 * @smid: system request message index
3986 * @direct_io: Zero or non-zero value to set in the direct_io flag
3991 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3993 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3998 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3999 * @ioc: per adapter object
4000 * @scmd: pointer to scsi command object
4001 * @raid_device: pointer to raid device data structure
4002 * @mpi_request: pointer to the SCSI_IO reqest message frame
4003 * @smid: system request message index
4008 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4009 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
4012 sector_t v_lba, p_lba, stripe_off, column, io_size;
4013 u32 stripe_sz, stripe_exp;
4014 u8 num_pds, cmd = scmd->cmnd[0];
4016 if (cmd != READ_10 && cmd != WRITE_10 &&
4017 cmd != READ_16 && cmd != WRITE_16)
4020 if (cmd == READ_10 || cmd == WRITE_10)
4021 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
4023 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
4025 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
4027 if (v_lba + io_size - 1 > raid_device->max_lba)
4030 stripe_sz = raid_device->stripe_sz;
4031 stripe_exp = raid_device->stripe_exponent;
4032 stripe_off = v_lba & (stripe_sz - 1);
4034 /* Return unless IO falls within a stripe */
4035 if (stripe_off + io_size > stripe_sz)
4038 num_pds = raid_device->num_pds;
4039 p_lba = v_lba >> stripe_exp;
4040 column = sector_div(p_lba, num_pds);
4041 p_lba = (p_lba << stripe_exp) + stripe_off;
4043 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
4045 if (cmd == READ_10 || cmd == WRITE_10)
4046 put_unaligned_be32(lower_32_bits(p_lba),
4047 &mpi_request->CDB.CDB32[2]);
4049 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
4051 _scsih_scsi_direct_io_set(ioc, smid, 1);
4055 * _scsih_qcmd - main scsi request entry point
4056 * @scmd: pointer to scsi command object
4057 * @done: function pointer to be invoked on completion
4059 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4061 * Returns 0 on success. If there's a failure, return either:
4062 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4063 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4066 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4068 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
4069 struct MPT2SAS_DEVICE *sas_device_priv_data;
4070 struct MPT2SAS_TARGET *sas_target_priv_data;
4071 struct _raid_device *raid_device;
4072 Mpi2SCSIIORequest_t *mpi_request;
4076 sas_device_priv_data = scmd->device->hostdata;
4077 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4078 scmd->result = DID_NO_CONNECT << 16;
4079 scmd->scsi_done(scmd);
4083 if (ioc->pci_error_recovery || ioc->remove_host) {
4084 scmd->result = DID_NO_CONNECT << 16;
4085 scmd->scsi_done(scmd);
4089 sas_target_priv_data = sas_device_priv_data->sas_target;
4090 /* invalid device handle */
4091 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
4092 scmd->result = DID_NO_CONNECT << 16;
4093 scmd->scsi_done(scmd);
4097 /* host recovery or link resets sent via IOCTLs */
4098 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4099 return SCSI_MLQUEUE_HOST_BUSY;
4100 /* device busy with task management */
4101 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
4102 return SCSI_MLQUEUE_DEVICE_BUSY;
4103 /* device has been deleted */
4104 else if (sas_target_priv_data->deleted) {
4105 scmd->result = DID_NO_CONNECT << 16;
4106 scmd->scsi_done(scmd);
4110 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4111 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4112 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4113 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4115 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4118 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4120 /* Make sure Device is not raid volume.
4121 * We do not expose raid functionality to upper layer for warpdrive.
4123 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4124 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4125 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4127 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4129 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4130 ioc->name, __func__);
4133 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4134 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4135 _scsih_setup_eedp(scmd, mpi_request);
4136 if (scmd->cmd_len == 32)
4137 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4138 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4139 if (sas_device_priv_data->sas_target->flags &
4140 MPT_TARGET_FLAGS_RAID_COMPONENT)
4141 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4143 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4144 mpi_request->DevHandle =
4145 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4146 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4147 mpi_request->Control = cpu_to_le32(mpi_control);
4148 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4149 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4150 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4151 mpi_request->SenseBufferLowAddress =
4152 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
4153 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4154 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4155 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
4156 mpi_request->VF_ID = 0; /* TODO */
4157 mpi_request->VP_ID = 0;
4158 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4160 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4162 if (!mpi_request->DataLength) {
4163 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4165 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4166 mpt2sas_base_free_smid(ioc, smid);
4171 raid_device = sas_target_priv_data->raid_device;
4172 if (raid_device && raid_device->direct_io_enabled)
4173 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4176 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4177 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4178 le16_to_cpu(mpi_request->DevHandle));
4180 mpt2sas_base_put_smid_default(ioc, smid);
4184 return SCSI_MLQUEUE_HOST_BUSY;
4188 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4189 * @sense_buffer: sense data returned by target
4190 * @data: normalized skey/asc/ascq
4195 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4197 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4198 /* descriptor format */
4199 data->skey = sense_buffer[1] & 0x0F;
4200 data->asc = sense_buffer[2];
4201 data->ascq = sense_buffer[3];
4204 data->skey = sense_buffer[2] & 0x0F;
4205 data->asc = sense_buffer[12];
4206 data->ascq = sense_buffer[13];
4210 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4212 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4213 * @ioc: per adapter object
4214 * @scmd: pointer to scsi command object
4215 * @mpi_reply: reply mf payload returned from firmware
4217 * scsi_status - SCSI Status code returned from target device
4218 * scsi_state - state info associated with SCSI_IO determined by ioc
4219 * ioc_status - ioc supplied status info
4224 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4225 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4229 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4230 MPI2_IOCSTATUS_MASK;
4231 u8 scsi_state = mpi_reply->SCSIState;
4232 u8 scsi_status = mpi_reply->SCSIStatus;
4233 char *desc_ioc_state = NULL;
4234 char *desc_scsi_status = NULL;
4235 char *desc_scsi_state = ioc->tmp_string;
4236 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4237 struct _sas_device *sas_device = NULL;
4238 struct scsi_target *starget = scmd->device->sdev_target;
4239 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4240 char *device_str = NULL;
4245 if (ioc->hide_ir_msg)
4246 device_str = "WarpDrive";
4248 device_str = "volume";
4250 if (log_info == 0x31170000)
4253 switch (ioc_status) {
4254 case MPI2_IOCSTATUS_SUCCESS:
4255 desc_ioc_state = "success";
4257 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4258 desc_ioc_state = "invalid function";
4260 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4261 desc_ioc_state = "scsi recovered error";
4263 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4264 desc_ioc_state = "scsi invalid dev handle";
4266 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4267 desc_ioc_state = "scsi device not there";
4269 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4270 desc_ioc_state = "scsi data overrun";
4272 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4273 desc_ioc_state = "scsi data underrun";
4275 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4276 desc_ioc_state = "scsi io data error";
4278 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4279 desc_ioc_state = "scsi protocol error";
4281 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4282 desc_ioc_state = "scsi task terminated";
4284 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4285 desc_ioc_state = "scsi residual mismatch";
4287 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4288 desc_ioc_state = "scsi task mgmt failed";
4290 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4291 desc_ioc_state = "scsi ioc terminated";
4293 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4294 desc_ioc_state = "scsi ext terminated";
4296 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4297 desc_ioc_state = "eedp guard error";
4299 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4300 desc_ioc_state = "eedp ref tag error";
4302 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4303 desc_ioc_state = "eedp app tag error";
4306 desc_ioc_state = "unknown";
4310 switch (scsi_status) {
4311 case MPI2_SCSI_STATUS_GOOD:
4312 desc_scsi_status = "good";
4314 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4315 desc_scsi_status = "check condition";
4317 case MPI2_SCSI_STATUS_CONDITION_MET:
4318 desc_scsi_status = "condition met";
4320 case MPI2_SCSI_STATUS_BUSY:
4321 desc_scsi_status = "busy";
4323 case MPI2_SCSI_STATUS_INTERMEDIATE:
4324 desc_scsi_status = "intermediate";
4326 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4327 desc_scsi_status = "intermediate condmet";
4329 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4330 desc_scsi_status = "reservation conflict";
4332 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4333 desc_scsi_status = "command terminated";
4335 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4336 desc_scsi_status = "task set full";
4338 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4339 desc_scsi_status = "aca active";
4341 case MPI2_SCSI_STATUS_TASK_ABORTED:
4342 desc_scsi_status = "task aborted";
4345 desc_scsi_status = "unknown";
4349 desc_scsi_state[0] = '\0';
4351 desc_scsi_state = " ";
4352 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4353 strcat(desc_scsi_state, "response info ");
4354 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4355 strcat(desc_scsi_state, "state terminated ");
4356 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4357 strcat(desc_scsi_state, "no status ");
4358 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4359 strcat(desc_scsi_state, "autosense failed ");
4360 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4361 strcat(desc_scsi_state, "autosense valid ");
4363 scsi_print_command(scmd);
4365 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4366 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4367 device_str, (unsigned long long)priv_target->sas_address);
4369 sas_device = mpt2sas_get_sdev_from_target(ioc, priv_target);
4371 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4372 "phy(%d)\n", ioc->name, sas_device->sas_address,
4374 printk(MPT2SAS_WARN_FMT
4375 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4376 ioc->name, sas_device->enclosure_logical_id,
4379 sas_device_put(sas_device);
4383 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4384 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4385 desc_ioc_state, ioc_status, smid);
4386 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4387 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4388 scsi_get_resid(scmd));
4389 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4390 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4391 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4392 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4393 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4394 scsi_status, desc_scsi_state, scsi_state);
4396 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4397 struct sense_info data;
4398 _scsih_normalize_sense(scmd->sense_buffer, &data);
4399 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4400 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4401 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4404 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4405 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4406 response_bytes = (u8 *)&response_info;
4407 _scsih_response_code(ioc, response_bytes[0]);
4413 * _scsih_turn_on_pfa_led - illuminate PFA LED
4414 * @ioc: per adapter object
4415 * @handle: device handle
4421 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4423 Mpi2SepReply_t mpi_reply;
4424 Mpi2SepRequest_t mpi_request;
4425 struct _sas_device *sas_device;
4427 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
4431 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4432 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4433 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4434 mpi_request.SlotStatus =
4435 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4436 mpi_request.DevHandle = cpu_to_le16(handle);
4437 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4438 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4439 &mpi_request)) != 0) {
4440 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4441 __FILE__, __LINE__, __func__);
4444 sas_device->pfa_led_on = 1;
4447 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4448 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4449 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4450 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4451 le32_to_cpu(mpi_reply.IOCLogInfo)));
4455 sas_device_put(sas_device);
4459 * _scsih_turn_off_pfa_led - turn off PFA LED
4460 * @ioc: per adapter object
4461 * @sas_device: sas device whose PFA LED has to turned off
4467 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4468 struct _sas_device *sas_device)
4470 Mpi2SepReply_t mpi_reply;
4471 Mpi2SepRequest_t mpi_request;
4473 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4474 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4475 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4476 mpi_request.SlotStatus = 0;
4477 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4478 mpi_request.DevHandle = 0;
4479 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4480 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4481 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4482 &mpi_request)) != 0) {
4483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4484 __FILE__, __LINE__, __func__);
4488 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4489 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4490 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4491 le16_to_cpu(mpi_reply.IOCStatus),
4492 le32_to_cpu(mpi_reply.IOCLogInfo)));
4498 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4499 * @ioc: per adapter object
4500 * @handle: device handle
4501 * Context: interrupt.
4506 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4508 struct fw_event_work *fw_event;
4510 fw_event = alloc_fw_event_work(0);
4513 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
4514 fw_event->device_handle = handle;
4515 fw_event->ioc = ioc;
4516 _scsih_fw_event_add(ioc, fw_event);
4517 fw_event_work_put(fw_event);
4521 * _scsih_smart_predicted_fault - process smart errors
4522 * @ioc: per adapter object
4523 * @handle: device handle
4524 * Context: interrupt.
4529 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4531 struct scsi_target *starget;
4532 struct MPT2SAS_TARGET *sas_target_priv_data;
4533 Mpi2EventNotificationReply_t *event_reply;
4534 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4535 struct _sas_device *sas_device;
4537 unsigned long flags;
4539 /* only handle non-raid devices */
4540 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4541 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
4545 starget = sas_device->starget;
4546 sas_target_priv_data = starget->hostdata;
4548 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4549 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4552 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4553 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4555 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4556 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4558 /* insert into event log */
4559 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4560 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4561 event_reply = kzalloc(sz, GFP_ATOMIC);
4563 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4564 ioc->name, __FILE__, __LINE__, __func__);
4568 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4569 event_reply->Event =
4570 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4571 event_reply->MsgLength = sz/4;
4572 event_reply->EventDataLength =
4573 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4574 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4575 event_reply->EventData;
4576 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4577 event_data->ASC = 0x5D;
4578 event_data->DevHandle = cpu_to_le16(handle);
4579 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4580 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4584 sas_device_put(sas_device);
4588 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4593 * _scsih_io_done - scsi request callback
4594 * @ioc: per adapter object
4595 * @smid: system request message index
4596 * @msix_index: MSIX table index supplied by the OS
4597 * @reply: reply message frame(lower 32bit addr)
4599 * Callback handler when using _scsih_qcmd.
4601 * Return 1 meaning mf should be freed from _base_interrupt
4602 * 0 means the mf is freed from this function.
4605 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4607 Mpi2SCSIIORequest_t *mpi_request;
4608 Mpi2SCSIIOReply_t *mpi_reply;
4609 struct scsi_cmnd *scmd;
4615 struct MPT2SAS_DEVICE *sas_device_priv_data;
4616 u32 response_code = 0;
4617 unsigned long flags;
4619 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4620 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4624 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4626 if (mpi_reply == NULL) {
4627 scmd->result = DID_OK << 16;
4631 sas_device_priv_data = scmd->device->hostdata;
4632 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4633 sas_device_priv_data->sas_target->deleted) {
4634 scmd->result = DID_NO_CONNECT << 16;
4637 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4639 * WARPDRIVE: If direct_io is set then it is directIO,
4640 * the failed direct I/O should be redirected to volume
4642 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4643 ((ioc_status & MPI2_IOCSTATUS_MASK)
4644 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4645 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4646 ioc->scsi_lookup[smid - 1].scmd = scmd;
4647 _scsih_scsi_direct_io_set(ioc, smid, 0);
4648 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4649 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4650 mpi_request->DevHandle =
4651 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4652 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4653 sas_device_priv_data->sas_target->handle);
4658 /* turning off TLR */
4659 scsi_state = mpi_reply->SCSIState;
4660 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4662 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4663 if (!sas_device_priv_data->tlr_snoop_check) {
4664 sas_device_priv_data->tlr_snoop_check++;
4665 /* Make sure Device is not raid volume.
4666 * We do not expose raid functionality to upper layer for warpdrive.
4668 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4669 sas_is_tlr_enabled(scmd->device) &&
4670 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4671 sas_disable_tlr(scmd->device);
4672 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4676 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4677 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4678 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4679 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4682 ioc_status &= MPI2_IOCSTATUS_MASK;
4683 scsi_status = mpi_reply->SCSIStatus;
4685 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4686 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4687 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4688 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4689 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4692 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4693 struct sense_info data;
4694 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4696 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4697 le32_to_cpu(mpi_reply->SenseCount));
4698 memcpy(scmd->sense_buffer, sense_data, sz);
4699 _scsih_normalize_sense(scmd->sense_buffer, &data);
4700 /* failure prediction threshold exceeded */
4701 if (data.asc == 0x5D)
4702 _scsih_smart_predicted_fault(ioc,
4703 le16_to_cpu(mpi_reply->DevHandle));
4706 switch (ioc_status) {
4707 case MPI2_IOCSTATUS_BUSY:
4708 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4709 scmd->result = SAM_STAT_BUSY;
4712 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4713 scmd->result = DID_NO_CONNECT << 16;
4716 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4717 if (sas_device_priv_data->block) {
4718 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4721 if (log_info == 0x32010081) {
4722 scmd->result = DID_RESET << 16;
4725 scmd->result = DID_SOFT_ERROR << 16;
4727 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4728 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4729 scmd->result = DID_RESET << 16;
4732 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4733 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4734 scmd->result = DID_SOFT_ERROR << 16;
4736 scmd->result = (DID_OK << 16) | scsi_status;
4739 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4740 scmd->result = (DID_OK << 16) | scsi_status;
4742 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4745 if (xfer_cnt < scmd->underflow) {
4746 if (scsi_status == SAM_STAT_BUSY)
4747 scmd->result = SAM_STAT_BUSY;
4749 scmd->result = DID_SOFT_ERROR << 16;
4750 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4751 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4752 scmd->result = DID_SOFT_ERROR << 16;
4753 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4754 scmd->result = DID_RESET << 16;
4755 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4756 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4757 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4758 scmd->result = (DRIVER_SENSE << 24) |
4759 SAM_STAT_CHECK_CONDITION;
4760 scmd->sense_buffer[0] = 0x70;
4761 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4762 scmd->sense_buffer[12] = 0x20;
4763 scmd->sense_buffer[13] = 0;
4767 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4768 scsi_set_resid(scmd, 0);
4769 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4770 case MPI2_IOCSTATUS_SUCCESS:
4771 scmd->result = (DID_OK << 16) | scsi_status;
4772 if (response_code ==
4773 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4774 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4775 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4776 scmd->result = DID_SOFT_ERROR << 16;
4777 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4778 scmd->result = DID_RESET << 16;
4781 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4782 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4783 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4784 _scsih_eedp_error_handling(scmd, ioc_status);
4786 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4787 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4788 case MPI2_IOCSTATUS_INVALID_SGL:
4789 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4790 case MPI2_IOCSTATUS_INVALID_FIELD:
4791 case MPI2_IOCSTATUS_INVALID_STATE:
4792 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4793 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4795 scmd->result = DID_SOFT_ERROR << 16;
4800 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4801 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4802 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4806 scsi_dma_unmap(scmd);
4807 scmd->scsi_done(scmd);
4812 * _scsih_sas_host_refresh - refreshing sas host object contents
4813 * @ioc: per adapter object
4816 * During port enable, fw will send topology events for every device. Its
4817 * possible that the handles may change from the previous setting, so this
4818 * code keeping handles updating if changed.
4823 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4828 Mpi2ConfigReply_t mpi_reply;
4829 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4830 u16 attached_handle;
4833 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4834 "updating handles for sas_host(0x%016llx)\n",
4835 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4837 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4838 * sizeof(Mpi2SasIOUnit0PhyData_t));
4839 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4840 if (!sas_iounit_pg0) {
4841 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4842 ioc->name, __FILE__, __LINE__, __func__);
4846 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4847 sas_iounit_pg0, sz)) != 0)
4849 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4850 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4852 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4853 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4855 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4856 PhyData[0].ControllerDevHandle);
4857 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4858 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4860 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4861 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4862 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4863 attached_handle, i, link_rate);
4866 kfree(sas_iounit_pg0);
4870 * _scsih_sas_host_add - create sas host object
4871 * @ioc: per adapter object
4873 * Creating host side data object, stored in ioc->sas_hba
4878 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4881 Mpi2ConfigReply_t mpi_reply;
4882 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4883 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4884 Mpi2SasPhyPage0_t phy_pg0;
4885 Mpi2SasDevicePage0_t sas_device_pg0;
4886 Mpi2SasEnclosurePage0_t enclosure_pg0;
4889 u16 device_missing_delay;
4891 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4892 if (!ioc->sas_hba.num_phys) {
4893 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4894 ioc->name, __FILE__, __LINE__, __func__);
4898 /* sas_iounit page 0 */
4899 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4900 sizeof(Mpi2SasIOUnit0PhyData_t));
4901 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4902 if (!sas_iounit_pg0) {
4903 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4904 ioc->name, __FILE__, __LINE__, __func__);
4907 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4908 sas_iounit_pg0, sz))) {
4909 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4910 ioc->name, __FILE__, __LINE__, __func__);
4913 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4914 MPI2_IOCSTATUS_MASK;
4915 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4916 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4917 ioc->name, __FILE__, __LINE__, __func__);
4921 /* sas_iounit page 1 */
4922 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4923 sizeof(Mpi2SasIOUnit1PhyData_t));
4924 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4925 if (!sas_iounit_pg1) {
4926 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4927 ioc->name, __FILE__, __LINE__, __func__);
4930 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4931 sas_iounit_pg1, sz))) {
4932 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4933 ioc->name, __FILE__, __LINE__, __func__);
4936 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4937 MPI2_IOCSTATUS_MASK;
4938 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4939 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4940 ioc->name, __FILE__, __LINE__, __func__);
4944 ioc->io_missing_delay =
4945 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4946 device_missing_delay =
4947 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4948 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4949 ioc->device_missing_delay = (device_missing_delay &
4950 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4952 ioc->device_missing_delay = device_missing_delay &
4953 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4955 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4956 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4957 sizeof(struct _sas_phy), GFP_KERNEL);
4958 if (!ioc->sas_hba.phy) {
4959 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4960 ioc->name, __FILE__, __LINE__, __func__);
4963 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4964 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4966 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4967 ioc->name, __FILE__, __LINE__, __func__);
4970 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4971 MPI2_IOCSTATUS_MASK;
4972 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4973 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4974 ioc->name, __FILE__, __LINE__, __func__);
4979 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4980 PhyData[0].ControllerDevHandle);
4981 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4982 ioc->sas_hba.phy[i].phy_id = i;
4983 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4984 phy_pg0, ioc->sas_hba.parent_dev);
4986 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4987 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4988 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4989 ioc->name, __FILE__, __LINE__, __func__);
4992 ioc->sas_hba.enclosure_handle =
4993 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4994 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4995 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4996 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4997 (unsigned long long) ioc->sas_hba.sas_address,
4998 ioc->sas_hba.num_phys) ;
5000 if (ioc->sas_hba.enclosure_handle) {
5001 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5003 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5004 ioc->sas_hba.enclosure_handle))) {
5005 ioc->sas_hba.enclosure_logical_id =
5006 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5011 kfree(sas_iounit_pg1);
5012 kfree(sas_iounit_pg0);
5016 * _scsih_expander_add - creating expander object
5017 * @ioc: per adapter object
5018 * @handle: expander handle
5020 * Creating expander object, stored in ioc->sas_expander_list.
5022 * Return 0 for success, else error.
5025 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5027 struct _sas_node *sas_expander;
5028 Mpi2ConfigReply_t mpi_reply;
5029 Mpi2ExpanderPage0_t expander_pg0;
5030 Mpi2ExpanderPage1_t expander_pg1;
5031 Mpi2SasEnclosurePage0_t enclosure_pg0;
5034 u64 sas_address, sas_address_parent = 0;
5036 unsigned long flags;
5037 struct _sas_port *mpt2sas_port = NULL;
5043 if (ioc->shost_recovery || ioc->pci_error_recovery)
5046 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5047 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5048 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5049 ioc->name, __FILE__, __LINE__, __func__);
5053 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5054 MPI2_IOCSTATUS_MASK;
5055 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5056 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5057 ioc->name, __FILE__, __LINE__, __func__);
5061 /* handle out of order topology events */
5062 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5063 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5065 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5066 ioc->name, __FILE__, __LINE__, __func__);
5069 if (sas_address_parent != ioc->sas_hba.sas_address) {
5070 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5071 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5072 sas_address_parent);
5073 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5074 if (!sas_expander) {
5075 rc = _scsih_expander_add(ioc, parent_handle);
5081 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5082 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5083 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5085 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5090 sas_expander = kzalloc(sizeof(struct _sas_node),
5092 if (!sas_expander) {
5093 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5094 ioc->name, __FILE__, __LINE__, __func__);
5098 sas_expander->handle = handle;
5099 sas_expander->num_phys = expander_pg0.NumPhys;
5100 sas_expander->sas_address_parent = sas_address_parent;
5101 sas_expander->sas_address = sas_address;
5103 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
5104 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5105 handle, parent_handle, (unsigned long long)
5106 sas_expander->sas_address, sas_expander->num_phys);
5108 if (!sas_expander->num_phys)
5110 sas_expander->phy = kcalloc(sas_expander->num_phys,
5111 sizeof(struct _sas_phy), GFP_KERNEL);
5112 if (!sas_expander->phy) {
5113 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5114 ioc->name, __FILE__, __LINE__, __func__);
5119 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5120 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
5121 sas_address_parent);
5122 if (!mpt2sas_port) {
5123 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5124 ioc->name, __FILE__, __LINE__, __func__);
5128 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
5130 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5131 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
5132 &expander_pg1, i, handle))) {
5133 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5134 ioc->name, __FILE__, __LINE__, __func__);
5138 sas_expander->phy[i].handle = handle;
5139 sas_expander->phy[i].phy_id = i;
5141 if ((mpt2sas_transport_add_expander_phy(ioc,
5142 &sas_expander->phy[i], expander_pg1,
5143 sas_expander->parent_dev))) {
5144 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5145 ioc->name, __FILE__, __LINE__, __func__);
5151 if (sas_expander->enclosure_handle) {
5152 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5153 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5154 sas_expander->enclosure_handle))) {
5155 sas_expander->enclosure_logical_id =
5156 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5160 _scsih_expander_node_add(ioc, sas_expander);
5166 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5167 sas_address_parent);
5168 kfree(sas_expander);
5173 * _scsih_done - scsih callback handler.
5174 * @ioc: per adapter object
5175 * @smid: system request message index
5176 * @msix_index: MSIX table index supplied by the OS
5177 * @reply: reply message frame(lower 32bit addr)
5179 * Callback handler when sending internal generated message frames.
5180 * The callback index passed is `ioc->scsih_cb_idx`
5182 * Return 1 meaning mf should be freed from _base_interrupt
5183 * 0 means the mf is freed from this function.
5186 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5188 MPI2DefaultReply_t *mpi_reply;
5190 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5191 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5193 if (ioc->scsih_cmds.smid != smid)
5195 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5197 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5198 mpi_reply->MsgLength*4);
5199 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5201 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5202 complete(&ioc->scsih_cmds.done);
5207 * mpt2sas_expander_remove - removing expander object
5208 * @ioc: per adapter object
5209 * @sas_address: expander sas_address
5214 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5216 struct _sas_node *sas_expander;
5217 unsigned long flags;
5219 if (ioc->shost_recovery)
5222 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5223 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5226 list_del(&sas_expander->list);
5227 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5229 _scsih_expander_node_remove(ioc, sas_expander);
5233 * _scsih_check_access_status - check access flags
5234 * @ioc: per adapter object
5235 * @sas_address: sas address
5236 * @handle: sas device handle
5237 * @access_flags: errors returned during discovery of the device
5239 * Return 0 for success, else failure
5242 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5243 u16 handle, u8 access_status)
5248 switch (access_status) {
5249 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5250 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5253 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5254 desc = "sata capability failed";
5256 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5257 desc = "sata affiliation conflict";
5259 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5260 desc = "route not addressable";
5262 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5263 desc = "smp error not addressable";
5265 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5266 desc = "device blocked";
5268 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5269 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5270 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5271 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5272 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5273 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5274 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5275 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5276 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5277 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5278 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5279 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5280 desc = "sata initialization failed";
5290 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5291 "handle(0x%04x)\n", ioc->name, desc,
5292 (unsigned long long)sas_address, handle);
5297 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5299 Mpi2ConfigReply_t mpi_reply;
5300 Mpi2SasDevicePage0_t sas_device_pg0;
5301 struct _sas_device *sas_device;
5303 unsigned long flags;
5305 struct scsi_target *starget;
5306 struct MPT2SAS_TARGET *sas_target_priv_data;
5310 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5311 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5314 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5315 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5318 /* check if this is end device */
5319 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5320 if (!(_scsih_is_end_device(device_info)))
5323 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5324 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5325 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
5329 printk(MPT2SAS_ERR_FMT "device is not present "
5330 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5334 if (unlikely(sas_device->handle != handle)) {
5335 starget = sas_device->starget;
5336 sas_target_priv_data = starget->hostdata;
5337 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5338 " to (0x%04x)!!!\n", sas_device->handle, handle);
5339 sas_target_priv_data->handle = handle;
5340 sas_device->handle = handle;
5343 /* check if device is present */
5344 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5345 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5346 printk(MPT2SAS_ERR_FMT "device is not present "
5347 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5351 /* check if there were any issues with discovery */
5352 if (_scsih_check_access_status(ioc, sas_address, handle,
5353 sas_device_pg0.AccessStatus))
5356 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5357 _scsih_ublock_io_device(ioc, sas_address);
5359 sas_device_put(sas_device);
5363 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5365 sas_device_put(sas_device);
5369 * _scsih_add_device - creating sas device object
5370 * @ioc: per adapter object
5371 * @handle: sas device handle
5372 * @phy_num: phy number end device attached to
5373 * @is_pd: is this hidden raid component
5375 * Creating end device object, stored in ioc->sas_device_list.
5377 * Returns 0 for success, non-zero for failure.
5380 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5382 Mpi2ConfigReply_t mpi_reply;
5383 Mpi2SasDevicePage0_t sas_device_pg0;
5384 Mpi2SasEnclosurePage0_t enclosure_pg0;
5385 struct _sas_device *sas_device;
5390 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5391 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5392 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5393 ioc->name, __FILE__, __LINE__, __func__);
5397 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5398 MPI2_IOCSTATUS_MASK;
5399 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5400 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5401 ioc->name, __FILE__, __LINE__, __func__);
5405 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5407 /* check if device is present */
5408 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5409 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5410 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5411 ioc->name, __FILE__, __LINE__, __func__);
5412 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5413 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5417 /* check if there were any issues with discovery */
5418 if (_scsih_check_access_status(ioc, sas_address, handle,
5419 sas_device_pg0.AccessStatus))
5422 /* check if this is end device */
5423 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5424 if (!(_scsih_is_end_device(device_info))) {
5425 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5426 ioc->name, __FILE__, __LINE__, __func__);
5430 sas_device = mpt2sas_get_sdev_by_addr(ioc,
5434 sas_device_put(sas_device);
5438 sas_device = kzalloc(sizeof(struct _sas_device),
5441 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5442 ioc->name, __FILE__, __LINE__, __func__);
5446 kref_init(&sas_device->refcount);
5447 sas_device->handle = handle;
5448 if (_scsih_get_sas_address(ioc, le16_to_cpu
5449 (sas_device_pg0.ParentDevHandle),
5450 &sas_device->sas_address_parent) != 0)
5451 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5452 ioc->name, __FILE__, __LINE__, __func__);
5453 sas_device->enclosure_handle =
5454 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5456 le16_to_cpu(sas_device_pg0.Slot);
5457 sas_device->device_info = device_info;
5458 sas_device->sas_address = sas_address;
5459 sas_device->phy = sas_device_pg0.PhyNum;
5461 /* get enclosure_logical_id */
5462 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5463 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5464 sas_device->enclosure_handle)))
5465 sas_device->enclosure_logical_id =
5466 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5468 /* get device name */
5469 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5471 if (ioc->wait_for_discovery_to_complete)
5472 _scsih_sas_device_init_add(ioc, sas_device);
5474 _scsih_sas_device_add(ioc, sas_device);
5476 sas_device_put(sas_device);
5481 * _scsih_remove_device - removing sas device object
5482 * @ioc: per adapter object
5483 * @sas_device_delete: the sas_device object
5488 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5489 struct _sas_device *sas_device)
5491 struct MPT2SAS_TARGET *sas_target_priv_data;
5493 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5494 (sas_device->pfa_led_on)) {
5495 _scsih_turn_off_pfa_led(ioc, sas_device);
5496 sas_device->pfa_led_on = 0;
5499 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5500 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5501 sas_device->handle, (unsigned long long)
5502 sas_device->sas_address));
5504 if (sas_device->starget && sas_device->starget->hostdata) {
5505 sas_target_priv_data = sas_device->starget->hostdata;
5506 sas_target_priv_data->deleted = 1;
5507 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5508 sas_target_priv_data->handle =
5509 MPT2SAS_INVALID_DEVICE_HANDLE;
5512 if (!ioc->hide_drives)
5513 mpt2sas_transport_port_remove(ioc,
5514 sas_device->sas_address,
5515 sas_device->sas_address_parent);
5517 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5518 "(0x%016llx)\n", ioc->name, sas_device->handle,
5519 (unsigned long long) sas_device->sas_address);
5521 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5522 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5523 sas_device->handle, (unsigned long long)
5524 sas_device->sas_address));
5527 * _scsih_device_remove_by_handle - removing device object by handle
5528 * @ioc: per adapter object
5529 * @handle: device handle
5534 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5536 struct _sas_device *sas_device;
5537 unsigned long flags;
5539 if (ioc->shost_recovery)
5542 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5543 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
5545 list_del_init(&sas_device->list);
5546 sas_device_put(sas_device);
5548 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5551 _scsih_remove_device(ioc, sas_device);
5552 sas_device_put(sas_device);
5557 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5558 * @ioc: per adapter object
5559 * @sas_address: device sas_address
5564 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5567 struct _sas_device *sas_device;
5568 unsigned long flags;
5570 if (ioc->shost_recovery)
5573 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5574 sas_device = __mpt2sas_get_sdev_by_addr(ioc, sas_address);
5576 list_del_init(&sas_device->list);
5577 sas_device_put(sas_device);
5579 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5582 _scsih_remove_device(ioc, sas_device);
5583 sas_device_put(sas_device);
5586 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5588 * _scsih_sas_topology_change_event_debug - debug for topology event
5589 * @ioc: per adapter object
5590 * @event_data: event data payload
5594 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5595 Mpi2EventDataSasTopologyChangeList_t *event_data)
5601 char *status_str = NULL;
5602 u8 link_rate, prev_link_rate;
5604 switch (event_data->ExpStatus) {
5605 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5608 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5609 status_str = "remove";
5611 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5613 status_str = "responding";
5615 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5616 status_str = "remove delay";
5619 status_str = "unknown status";
5622 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5623 ioc->name, status_str);
5624 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5625 "start_phy(%02d), count(%d)\n",
5626 le16_to_cpu(event_data->ExpanderDevHandle),
5627 le16_to_cpu(event_data->EnclosureHandle),
5628 event_data->StartPhyNum, event_data->NumEntries);
5629 for (i = 0; i < event_data->NumEntries; i++) {
5630 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5633 phy_number = event_data->StartPhyNum + i;
5634 reason_code = event_data->PHY[i].PhyStatus &
5635 MPI2_EVENT_SAS_TOPO_RC_MASK;
5636 switch (reason_code) {
5637 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5638 status_str = "target add";
5640 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5641 status_str = "target remove";
5643 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5644 status_str = "delay target remove";
5646 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5647 status_str = "link rate change";
5649 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5650 status_str = "target responding";
5653 status_str = "unknown";
5656 link_rate = event_data->PHY[i].LinkRate >> 4;
5657 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5658 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5659 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5660 handle, status_str, link_rate, prev_link_rate);
5667 * _scsih_sas_topology_change_event - handle topology changes
5668 * @ioc: per adapter object
5669 * @fw_event: The fw_event_work object
5674 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5675 struct fw_event_work *fw_event)
5678 u16 parent_handle, handle;
5680 u8 phy_number, max_phys;
5681 struct _sas_node *sas_expander;
5683 unsigned long flags;
5684 u8 link_rate, prev_link_rate;
5685 Mpi2EventDataSasTopologyChangeList_t *event_data =
5686 (Mpi2EventDataSasTopologyChangeList_t *)
5687 fw_event->event_data;
5689 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5690 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5691 _scsih_sas_topology_change_event_debug(ioc, event_data);
5694 if (ioc->remove_host || ioc->pci_error_recovery)
5697 if (!ioc->sas_hba.num_phys)
5698 _scsih_sas_host_add(ioc);
5700 _scsih_sas_host_refresh(ioc);
5702 if (fw_event->ignore) {
5703 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5704 "event\n", ioc->name));
5708 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5710 /* handle expander add */
5711 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5712 if (_scsih_expander_add(ioc, parent_handle) != 0)
5715 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5716 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5719 sas_address = sas_expander->sas_address;
5720 max_phys = sas_expander->num_phys;
5721 } else if (parent_handle < ioc->sas_hba.num_phys) {
5722 sas_address = ioc->sas_hba.sas_address;
5723 max_phys = ioc->sas_hba.num_phys;
5725 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5728 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5730 /* handle siblings events */
5731 for (i = 0; i < event_data->NumEntries; i++) {
5732 if (fw_event->ignore) {
5733 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5734 "expander event\n", ioc->name));
5737 if (ioc->shost_recovery || ioc->remove_host ||
5738 ioc->pci_error_recovery)
5740 phy_number = event_data->StartPhyNum + i;
5741 if (phy_number >= max_phys)
5743 reason_code = event_data->PHY[i].PhyStatus &
5744 MPI2_EVENT_SAS_TOPO_RC_MASK;
5745 if ((event_data->PHY[i].PhyStatus &
5746 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5747 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5749 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5752 link_rate = event_data->PHY[i].LinkRate >> 4;
5753 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5754 switch (reason_code) {
5755 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5757 if (ioc->shost_recovery)
5760 if (link_rate == prev_link_rate)
5763 mpt2sas_transport_update_links(ioc, sas_address,
5764 handle, phy_number, link_rate);
5766 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5769 _scsih_check_device(ioc, handle);
5771 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5773 if (ioc->shost_recovery)
5776 mpt2sas_transport_update_links(ioc, sas_address,
5777 handle, phy_number, link_rate);
5779 _scsih_add_device(ioc, handle, phy_number, 0);
5781 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5783 _scsih_device_remove_by_handle(ioc, handle);
5788 /* handle expander removal */
5789 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5791 mpt2sas_expander_remove(ioc, sas_address);
5795 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5797 * _scsih_sas_device_status_change_event_debug - debug for device event
5798 * @event_data: event data payload
5804 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5805 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5807 char *reason_str = NULL;
5809 switch (event_data->ReasonCode) {
5810 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5811 reason_str = "smart data";
5813 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5814 reason_str = "unsupported device discovered";
5816 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5817 reason_str = "internal device reset";
5819 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5820 reason_str = "internal task abort";
5822 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5823 reason_str = "internal task abort set";
5825 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5826 reason_str = "internal clear task set";
5828 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5829 reason_str = "internal query task";
5831 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5832 reason_str = "sata init failure";
5834 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5835 reason_str = "internal device reset complete";
5837 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5838 reason_str = "internal task abort complete";
5840 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5841 reason_str = "internal async notification";
5843 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5844 reason_str = "expander reduced functionality";
5846 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5847 reason_str = "expander reduced functionality complete";
5850 reason_str = "unknown reason";
5853 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5854 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5855 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5856 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5857 le16_to_cpu(event_data->TaskTag));
5858 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5859 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5860 event_data->ASC, event_data->ASCQ);
5861 printk(KERN_INFO "\n");
5866 * _scsih_sas_device_status_change_event - handle device status change
5867 * @ioc: per adapter object
5868 * @fw_event: The fw_event_work object
5874 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5875 struct fw_event_work *fw_event)
5877 struct MPT2SAS_TARGET *target_priv_data;
5878 struct _sas_device *sas_device;
5880 unsigned long flags;
5881 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5882 (Mpi2EventDataSasDeviceStatusChange_t *)
5883 fw_event->event_data;
5885 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5886 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5887 _scsih_sas_device_status_change_event_debug(ioc,
5891 /* In MPI Revision K (0xC), the internal device reset complete was
5892 * implemented, so avoid setting tm_busy flag for older firmware.
5894 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5897 if (event_data->ReasonCode !=
5898 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5899 event_data->ReasonCode !=
5900 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5903 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5904 sas_address = le64_to_cpu(event_data->SASAddress);
5905 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
5908 if (!sas_device || !sas_device->starget)
5911 target_priv_data = sas_device->starget->hostdata;
5912 if (!target_priv_data)
5915 if (event_data->ReasonCode ==
5916 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5917 target_priv_data->tm_busy = 1;
5919 target_priv_data->tm_busy = 0;
5923 sas_device_put(sas_device);
5925 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5929 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5931 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5932 * @ioc: per adapter object
5933 * @event_data: event data payload
5939 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5940 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5942 char *reason_str = NULL;
5944 switch (event_data->ReasonCode) {
5945 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5946 reason_str = "enclosure add";
5948 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5949 reason_str = "enclosure remove";
5952 reason_str = "unknown reason";
5956 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5957 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5958 " number slots(%d)\n", ioc->name, reason_str,
5959 le16_to_cpu(event_data->EnclosureHandle),
5960 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5961 le16_to_cpu(event_data->StartSlot));
5966 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5967 * @ioc: per adapter object
5968 * @fw_event: The fw_event_work object
5974 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5975 struct fw_event_work *fw_event)
5977 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5978 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5979 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5980 (Mpi2EventDataSasEnclDevStatusChange_t *)
5981 fw_event->event_data);
5986 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5987 * @ioc: per adapter object
5988 * @fw_event: The fw_event_work object
5994 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5995 struct fw_event_work *fw_event)
5997 struct scsi_cmnd *scmd;
5998 struct scsi_device *sdev;
6001 struct MPT2SAS_DEVICE *sas_device_priv_data;
6002 u32 termination_count;
6004 Mpi2SCSITaskManagementReply_t *mpi_reply;
6005 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
6006 (Mpi2EventDataSasBroadcastPrimitive_t *)
6007 fw_event->event_data;
6009 unsigned long flags;
6012 u8 task_abort_retries;
6014 mutex_lock(&ioc->tm_cmds.mutex);
6016 "%s: enter: phy number(%d), width(%d)\n",
6017 ioc->name, __func__, event_data->PhyNum,
6018 event_data->PortWidth);
6020 _scsih_block_io_all_device(ioc);
6022 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6023 mpi_reply = ioc->tm_cmds.reply;
6024 broadcast_aen_retry:
6026 /* sanity checks for retrying this loop */
6027 if (max_retries++ == 5) {
6028 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
6029 ioc->name, __func__));
6031 } else if (max_retries > 1)
6032 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
6033 ioc->name, __func__, max_retries - 1));
6035 termination_count = 0;
6037 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
6038 if (ioc->shost_recovery)
6040 scmd = _scsih_scsi_lookup_get(ioc, smid);
6043 sdev = scmd->device;
6044 sas_device_priv_data = sdev->hostdata;
6045 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
6047 /* skip hidden raid components */
6048 if (sas_device_priv_data->sas_target->flags &
6049 MPT_TARGET_FLAGS_RAID_COMPONENT)
6052 if (sas_device_priv_data->sas_target->flags &
6053 MPT_TARGET_FLAGS_VOLUME)
6056 handle = sas_device_priv_data->sas_target->handle;
6057 lun = sas_device_priv_data->lun;
6060 if (ioc->shost_recovery)
6063 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6064 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6065 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
6068 sdev_printk(KERN_WARNING, sdev,
6069 "mpt2sas_scsih_issue_tm: FAILED when sending "
6070 "QUERY_TASK: scmd(%p)\n", scmd);
6071 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6072 goto broadcast_aen_retry;
6074 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6075 & MPI2_IOCSTATUS_MASK;
6076 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6077 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
6078 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
6080 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6081 goto broadcast_aen_retry;
6084 /* see if IO is still owned by IOC and target */
6085 if (mpi_reply->ResponseCode ==
6086 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6087 mpi_reply->ResponseCode ==
6088 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6089 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6092 task_abort_retries = 0;
6094 if (task_abort_retries++ == 60) {
6095 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
6096 "%s: ABORT_TASK: giving up\n", ioc->name,
6098 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6099 goto broadcast_aen_retry;
6102 if (ioc->shost_recovery)
6105 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6106 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
6109 sdev_printk(KERN_WARNING, sdev,
6110 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6111 "scmd(%p)\n", scmd);
6115 if (task_abort_retries > 1)
6116 sdev_printk(KERN_WARNING, sdev,
6117 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6119 task_abort_retries - 1, scmd);
6121 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6122 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6125 if (ioc->broadcast_aen_pending) {
6126 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
6127 " pending AEN\n", ioc->name, __func__));
6128 ioc->broadcast_aen_pending = 0;
6129 goto broadcast_aen_retry;
6133 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6136 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
6137 "%s - exit, query_count = %d termination_count = %d\n",
6138 ioc->name, __func__, query_count, termination_count));
6140 ioc->broadcast_aen_busy = 0;
6141 if (!ioc->shost_recovery)
6142 _scsih_ublock_io_all_device(ioc);
6143 mutex_unlock(&ioc->tm_cmds.mutex);
6147 * _scsih_sas_discovery_event - handle discovery events
6148 * @ioc: per adapter object
6149 * @fw_event: The fw_event_work object
6155 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
6156 struct fw_event_work *fw_event)
6158 Mpi2EventDataSasDiscovery_t *event_data =
6159 (Mpi2EventDataSasDiscovery_t *)
6160 fw_event->event_data;
6162 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6163 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6164 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
6165 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6167 if (event_data->DiscoveryStatus)
6168 printk("discovery_status(0x%08x)",
6169 le32_to_cpu(event_data->DiscoveryStatus));
6174 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6175 !ioc->sas_hba.num_phys) {
6176 if (disable_discovery > 0 && ioc->shost_recovery) {
6177 /* Wait for the reset to complete */
6178 while (ioc->shost_recovery)
6181 _scsih_sas_host_add(ioc);
6186 * _scsih_reprobe_lun - reprobing lun
6187 * @sdev: scsi device struct
6188 * @no_uld_attach: sdev->no_uld_attach flag setting
6192 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6196 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6197 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6198 sdev->no_uld_attach ? "hidding" : "exposing");
6199 rc = scsi_device_reprobe(sdev);
6203 * _scsih_sas_volume_add - add new volume
6204 * @ioc: per adapter object
6205 * @element: IR config element data
6211 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6212 Mpi2EventIrConfigElement_t *element)
6214 struct _raid_device *raid_device;
6215 unsigned long flags;
6217 u16 handle = le16_to_cpu(element->VolDevHandle);
6220 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6222 printk(MPT2SAS_ERR_FMT
6223 "failure at %s:%d/%s()!\n", ioc->name,
6224 __FILE__, __LINE__, __func__);
6228 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6229 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6230 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6235 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6237 printk(MPT2SAS_ERR_FMT
6238 "failure at %s:%d/%s()!\n", ioc->name,
6239 __FILE__, __LINE__, __func__);
6243 raid_device->id = ioc->sas_id++;
6244 raid_device->channel = RAID_CHANNEL;
6245 raid_device->handle = handle;
6246 raid_device->wwid = wwid;
6247 _scsih_raid_device_add(ioc, raid_device);
6248 if (!ioc->wait_for_discovery_to_complete) {
6249 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6250 raid_device->id, 0);
6252 _scsih_raid_device_remove(ioc, raid_device);
6254 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6255 _scsih_determine_boot_device(ioc, raid_device, 1);
6256 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6261 * _scsih_sas_volume_delete - delete volume
6262 * @ioc: per adapter object
6263 * @handle: volume device handle
6269 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6271 struct _raid_device *raid_device;
6272 unsigned long flags;
6273 struct MPT2SAS_TARGET *sas_target_priv_data;
6274 struct scsi_target *starget = NULL;
6276 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6277 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6279 if (raid_device->starget) {
6280 starget = raid_device->starget;
6281 sas_target_priv_data = starget->hostdata;
6282 sas_target_priv_data->deleted = 1;
6284 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6285 "(0x%016llx)\n", ioc->name, raid_device->handle,
6286 (unsigned long long) raid_device->wwid);
6287 list_del(&raid_device->list);
6290 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6292 scsi_remove_target(&starget->dev);
6296 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6297 * @ioc: per adapter object
6298 * @element: IR config element data
6304 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6305 Mpi2EventIrConfigElement_t *element)
6307 struct _sas_device *sas_device;
6308 struct scsi_target *starget = NULL;
6309 struct MPT2SAS_TARGET *sas_target_priv_data;
6310 unsigned long flags;
6311 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6313 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6314 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
6316 sas_device->volume_handle = 0;
6317 sas_device->volume_wwid = 0;
6318 clear_bit(handle, ioc->pd_handles);
6319 if (sas_device->starget && sas_device->starget->hostdata) {
6320 starget = sas_device->starget;
6321 sas_target_priv_data = starget->hostdata;
6322 sas_target_priv_data->flags &=
6323 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6326 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6330 /* exposing raid component */
6332 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6334 sas_device_put(sas_device);
6338 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6339 * @ioc: per adapter object
6340 * @element: IR config element data
6346 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6347 Mpi2EventIrConfigElement_t *element)
6349 struct _sas_device *sas_device;
6350 struct scsi_target *starget = NULL;
6351 struct MPT2SAS_TARGET *sas_target_priv_data;
6352 unsigned long flags;
6353 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6354 u16 volume_handle = 0;
6355 u64 volume_wwid = 0;
6357 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6359 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6362 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6363 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
6365 set_bit(handle, ioc->pd_handles);
6366 if (sas_device->starget && sas_device->starget->hostdata) {
6367 starget = sas_device->starget;
6368 sas_target_priv_data = starget->hostdata;
6369 sas_target_priv_data->flags |=
6370 MPT_TARGET_FLAGS_RAID_COMPONENT;
6371 sas_device->volume_handle = volume_handle;
6372 sas_device->volume_wwid = volume_wwid;
6375 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6379 /* hiding raid component */
6381 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6383 sas_device_put(sas_device);
6387 * _scsih_sas_pd_delete - delete pd component
6388 * @ioc: per adapter object
6389 * @element: IR config element data
6395 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6396 Mpi2EventIrConfigElement_t *element)
6398 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6400 _scsih_device_remove_by_handle(ioc, handle);
6404 * _scsih_sas_pd_add - remove pd component
6405 * @ioc: per adapter object
6406 * @element: IR config element data
6412 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6413 Mpi2EventIrConfigElement_t *element)
6415 struct _sas_device *sas_device;
6416 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6417 Mpi2ConfigReply_t mpi_reply;
6418 Mpi2SasDevicePage0_t sas_device_pg0;
6423 set_bit(handle, ioc->pd_handles);
6425 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
6427 sas_device_put(sas_device);
6431 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6432 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6433 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6434 ioc->name, __FILE__, __LINE__, __func__);
6438 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6439 MPI2_IOCSTATUS_MASK;
6440 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6441 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6442 ioc->name, __FILE__, __LINE__, __func__);
6446 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6447 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6448 mpt2sas_transport_update_links(ioc, sas_address, handle,
6449 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6451 _scsih_add_device(ioc, handle, 0, 1);
6454 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6456 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6457 * @ioc: per adapter object
6458 * @event_data: event data payload
6464 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6465 Mpi2EventDataIrConfigChangeList_t *event_data)
6467 Mpi2EventIrConfigElement_t *element;
6470 char *reason_str = NULL, *element_str = NULL;
6472 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6474 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6475 ioc->name, (le32_to_cpu(event_data->Flags) &
6476 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6477 "foreign" : "native", event_data->NumElements);
6478 for (i = 0; i < event_data->NumElements; i++, element++) {
6479 switch (element->ReasonCode) {
6480 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6483 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6484 reason_str = "remove";
6486 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6487 reason_str = "no change";
6489 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6490 reason_str = "hide";
6492 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6493 reason_str = "unhide";
6495 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6496 reason_str = "volume_created";
6498 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6499 reason_str = "volume_deleted";
6501 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6502 reason_str = "pd_created";
6504 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6505 reason_str = "pd_deleted";
6508 reason_str = "unknown reason";
6511 element_type = le16_to_cpu(element->ElementFlags) &
6512 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6513 switch (element_type) {
6514 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6515 element_str = "volume";
6517 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6518 element_str = "phys disk";
6520 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6521 element_str = "hot spare";
6524 element_str = "unknown element";
6527 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6528 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6529 reason_str, le16_to_cpu(element->VolDevHandle),
6530 le16_to_cpu(element->PhysDiskDevHandle),
6531 element->PhysDiskNum);
6537 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6538 * @ioc: per adapter object
6539 * @fw_event: The fw_event_work object
6545 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6546 struct fw_event_work *fw_event)
6548 Mpi2EventIrConfigElement_t *element;
6551 Mpi2EventDataIrConfigChangeList_t *event_data =
6552 (Mpi2EventDataIrConfigChangeList_t *)
6553 fw_event->event_data;
6555 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6556 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6557 && !ioc->hide_ir_msg)
6558 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6562 if (ioc->shost_recovery)
6565 foreign_config = (le32_to_cpu(event_data->Flags) &
6566 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6568 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6569 for (i = 0; i < event_data->NumElements; i++, element++) {
6571 switch (element->ReasonCode) {
6572 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6573 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6574 if (!foreign_config)
6575 _scsih_sas_volume_add(ioc, element);
6577 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6578 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6579 if (!foreign_config)
6580 _scsih_sas_volume_delete(ioc,
6581 le16_to_cpu(element->VolDevHandle));
6583 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6584 if (!ioc->is_warpdrive)
6585 _scsih_sas_pd_hide(ioc, element);
6587 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6588 if (!ioc->is_warpdrive)
6589 _scsih_sas_pd_expose(ioc, element);
6591 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6592 if (!ioc->is_warpdrive)
6593 _scsih_sas_pd_add(ioc, element);
6595 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6596 if (!ioc->is_warpdrive)
6597 _scsih_sas_pd_delete(ioc, element);
6604 * _scsih_sas_ir_volume_event - IR volume event
6605 * @ioc: per adapter object
6606 * @fw_event: The fw_event_work object
6612 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6613 struct fw_event_work *fw_event)
6616 unsigned long flags;
6617 struct _raid_device *raid_device;
6621 Mpi2EventDataIrVolume_t *event_data =
6622 (Mpi2EventDataIrVolume_t *)
6623 fw_event->event_data;
6625 if (ioc->shost_recovery)
6628 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6631 handle = le16_to_cpu(event_data->VolDevHandle);
6632 state = le32_to_cpu(event_data->NewValue);
6633 if (!ioc->hide_ir_msg)
6634 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6635 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6636 le32_to_cpu(event_data->PreviousValue), state));
6639 case MPI2_RAID_VOL_STATE_MISSING:
6640 case MPI2_RAID_VOL_STATE_FAILED:
6641 _scsih_sas_volume_delete(ioc, handle);
6644 case MPI2_RAID_VOL_STATE_ONLINE:
6645 case MPI2_RAID_VOL_STATE_DEGRADED:
6646 case MPI2_RAID_VOL_STATE_OPTIMAL:
6648 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6649 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6650 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6655 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6657 printk(MPT2SAS_ERR_FMT
6658 "failure at %s:%d/%s()!\n", ioc->name,
6659 __FILE__, __LINE__, __func__);
6663 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6665 printk(MPT2SAS_ERR_FMT
6666 "failure at %s:%d/%s()!\n", ioc->name,
6667 __FILE__, __LINE__, __func__);
6671 raid_device->id = ioc->sas_id++;
6672 raid_device->channel = RAID_CHANNEL;
6673 raid_device->handle = handle;
6674 raid_device->wwid = wwid;
6675 _scsih_raid_device_add(ioc, raid_device);
6676 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6677 raid_device->id, 0);
6679 _scsih_raid_device_remove(ioc, raid_device);
6682 case MPI2_RAID_VOL_STATE_INITIALIZING:
6689 * _scsih_sas_ir_physical_disk_event - PD event
6690 * @ioc: per adapter object
6691 * @fw_event: The fw_event_work object
6697 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6698 struct fw_event_work *fw_event)
6700 u16 handle, parent_handle;
6702 struct _sas_device *sas_device;
6703 Mpi2ConfigReply_t mpi_reply;
6704 Mpi2SasDevicePage0_t sas_device_pg0;
6706 Mpi2EventDataIrPhysicalDisk_t *event_data =
6707 (Mpi2EventDataIrPhysicalDisk_t *)
6708 fw_event->event_data;
6711 if (ioc->shost_recovery)
6714 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6717 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6718 state = le32_to_cpu(event_data->NewValue);
6720 if (!ioc->hide_ir_msg)
6721 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6722 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6723 le32_to_cpu(event_data->PreviousValue), state));
6726 case MPI2_RAID_PD_STATE_ONLINE:
6727 case MPI2_RAID_PD_STATE_DEGRADED:
6728 case MPI2_RAID_PD_STATE_REBUILDING:
6729 case MPI2_RAID_PD_STATE_OPTIMAL:
6730 case MPI2_RAID_PD_STATE_HOT_SPARE:
6732 if (!ioc->is_warpdrive)
6733 set_bit(handle, ioc->pd_handles);
6735 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
6737 sas_device_put(sas_device);
6741 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6742 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6744 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6745 ioc->name, __FILE__, __LINE__, __func__);
6749 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6750 MPI2_IOCSTATUS_MASK;
6751 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6752 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6753 ioc->name, __FILE__, __LINE__, __func__);
6757 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6758 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6759 mpt2sas_transport_update_links(ioc, sas_address, handle,
6760 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6762 _scsih_add_device(ioc, handle, 0, 1);
6766 case MPI2_RAID_PD_STATE_OFFLINE:
6767 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6768 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6774 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6776 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6777 * @ioc: per adapter object
6778 * @event_data: event data payload
6784 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6785 Mpi2EventDataIrOperationStatus_t *event_data)
6787 char *reason_str = NULL;
6789 switch (event_data->RAIDOperation) {
6790 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6791 reason_str = "resync";
6793 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6794 reason_str = "online capacity expansion";
6796 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6797 reason_str = "consistency check";
6799 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6800 reason_str = "background init";
6802 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6803 reason_str = "make data consistent";
6810 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6811 "\thandle(0x%04x), percent complete(%d)\n",
6812 ioc->name, reason_str,
6813 le16_to_cpu(event_data->VolDevHandle),
6814 event_data->PercentComplete);
6819 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6820 * @ioc: per adapter object
6821 * @fw_event: The fw_event_work object
6827 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6828 struct fw_event_work *fw_event)
6830 Mpi2EventDataIrOperationStatus_t *event_data =
6831 (Mpi2EventDataIrOperationStatus_t *)
6832 fw_event->event_data;
6833 static struct _raid_device *raid_device;
6834 unsigned long flags;
6837 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6838 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6839 && !ioc->hide_ir_msg)
6840 _scsih_sas_ir_operation_status_event_debug(ioc,
6844 /* code added for raid transport support */
6845 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6847 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6848 handle = le16_to_cpu(event_data->VolDevHandle);
6849 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6851 raid_device->percent_complete =
6852 event_data->PercentComplete;
6853 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6858 * _scsih_prep_device_scan - initialize parameters prior to device scan
6859 * @ioc: per adapter object
6861 * Set the deleted flag prior to device scan. If the device is found during
6862 * the scan, then we clear the deleted flag.
6865 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6867 struct MPT2SAS_DEVICE *sas_device_priv_data;
6868 struct scsi_device *sdev;
6870 shost_for_each_device(sdev, ioc->shost) {
6871 sas_device_priv_data = sdev->hostdata;
6872 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6873 sas_device_priv_data->sas_target->deleted = 1;
6878 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6879 * @ioc: per adapter object
6880 * @sas_address: sas address
6881 * @slot: enclosure slot id
6882 * @handle: device handle
6884 * After host reset, find out whether devices are still responding.
6885 * Used in _scsi_remove_unresponsive_sas_devices.
6890 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6891 u16 slot, u16 handle)
6893 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6894 struct scsi_target *starget;
6895 struct _sas_device *sas_device;
6896 unsigned long flags;
6898 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6899 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6900 if (sas_device->sas_address == sas_address &&
6901 sas_device->slot == slot) {
6902 sas_device->responding = 1;
6903 starget = sas_device->starget;
6904 if (starget && starget->hostdata) {
6905 sas_target_priv_data = starget->hostdata;
6906 sas_target_priv_data->tm_busy = 0;
6907 sas_target_priv_data->deleted = 0;
6909 sas_target_priv_data = NULL;
6911 starget_printk(KERN_INFO, starget,
6912 "handle(0x%04x), sas_addr(0x%016llx), "
6913 "enclosure logical id(0x%016llx), "
6914 "slot(%d)\n", handle,
6915 (unsigned long long)sas_device->sas_address,
6916 (unsigned long long)
6917 sas_device->enclosure_logical_id,
6919 if (sas_device->handle == handle)
6921 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6922 sas_device->handle);
6923 sas_device->handle = handle;
6924 if (sas_target_priv_data)
6925 sas_target_priv_data->handle = handle;
6930 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6934 * _scsih_search_responding_sas_devices -
6935 * @ioc: per adapter object
6937 * After host reset, find out whether devices are still responding.
6943 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6945 Mpi2SasDevicePage0_t sas_device_pg0;
6946 Mpi2ConfigReply_t mpi_reply;
6953 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6955 if (list_empty(&ioc->sas_device_list))
6959 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6960 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6962 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6963 MPI2_IOCSTATUS_MASK;
6964 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6966 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6967 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6968 if (!(_scsih_is_end_device(device_info)))
6970 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6971 slot = le16_to_cpu(sas_device_pg0.Slot);
6972 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6976 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6981 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6982 * @ioc: per adapter object
6983 * @wwid: world wide identifier for raid volume
6984 * @handle: device handle
6986 * After host reset, find out whether devices are still responding.
6987 * Used in _scsi_remove_unresponsive_raid_devices.
6992 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6995 struct MPT2SAS_TARGET *sas_target_priv_data;
6996 struct scsi_target *starget;
6997 struct _raid_device *raid_device;
6998 unsigned long flags;
7000 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7001 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
7002 if (raid_device->wwid == wwid && raid_device->starget) {
7003 starget = raid_device->starget;
7004 if (starget && starget->hostdata) {
7005 sas_target_priv_data = starget->hostdata;
7006 sas_target_priv_data->deleted = 0;
7008 sas_target_priv_data = NULL;
7009 raid_device->responding = 1;
7010 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7011 starget_printk(KERN_INFO, raid_device->starget,
7012 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7013 (unsigned long long)raid_device->wwid);
7015 * WARPDRIVE: The handles of the PDs might have changed
7016 * across the host reset so re-initialize the
7017 * required data for Direct IO
7019 _scsih_init_warpdrive_properties(ioc, raid_device);
7020 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7021 if (raid_device->handle == handle) {
7022 spin_unlock_irqrestore(&ioc->raid_device_lock,
7026 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
7027 raid_device->handle);
7028 raid_device->handle = handle;
7029 if (sas_target_priv_data)
7030 sas_target_priv_data->handle = handle;
7031 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7036 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7040 * _scsih_search_responding_raid_devices -
7041 * @ioc: per adapter object
7043 * After host reset, find out whether devices are still responding.
7049 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
7051 Mpi2RaidVolPage1_t volume_pg1;
7052 Mpi2RaidVolPage0_t volume_pg0;
7053 Mpi2RaidPhysDiskPage0_t pd_pg0;
7054 Mpi2ConfigReply_t mpi_reply;
7059 if (!ioc->ir_firmware)
7062 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
7065 if (list_empty(&ioc->raid_device_list))
7069 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7070 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7071 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7072 MPI2_IOCSTATUS_MASK;
7073 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7075 handle = le16_to_cpu(volume_pg1.DevHandle);
7077 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7078 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7079 sizeof(Mpi2RaidVolPage0_t)))
7082 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7083 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7084 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7085 _scsih_mark_responding_raid_device(ioc,
7086 le64_to_cpu(volume_pg1.WWID), handle);
7089 /* refresh the pd_handles */
7090 if (!ioc->is_warpdrive) {
7091 phys_disk_num = 0xFF;
7092 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7093 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7094 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7096 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7097 MPI2_IOCSTATUS_MASK;
7098 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7100 phys_disk_num = pd_pg0.PhysDiskNum;
7101 handle = le16_to_cpu(pd_pg0.DevHandle);
7102 set_bit(handle, ioc->pd_handles);
7106 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
7107 "complete\n", ioc->name);
7111 * _scsih_mark_responding_expander - mark a expander as responding
7112 * @ioc: per adapter object
7113 * @sas_address: sas address
7116 * After host reset, find out whether devices are still responding.
7117 * Used in _scsi_remove_unresponsive_expanders.
7122 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
7125 struct _sas_node *sas_expander;
7126 unsigned long flags;
7129 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7130 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7131 if (sas_expander->sas_address != sas_address)
7133 sas_expander->responding = 1;
7134 if (sas_expander->handle == handle)
7136 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
7137 " from(0x%04x) to (0x%04x)!!!\n",
7138 (unsigned long long)sas_expander->sas_address,
7139 sas_expander->handle, handle);
7140 sas_expander->handle = handle;
7141 for (i = 0 ; i < sas_expander->num_phys ; i++)
7142 sas_expander->phy[i].handle = handle;
7146 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7150 * _scsih_search_responding_expanders -
7151 * @ioc: per adapter object
7153 * After host reset, find out whether devices are still responding.
7159 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
7161 Mpi2ExpanderPage0_t expander_pg0;
7162 Mpi2ConfigReply_t mpi_reply;
7167 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
7169 if (list_empty(&ioc->sas_expander_list))
7173 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7174 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7176 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7177 MPI2_IOCSTATUS_MASK;
7178 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7181 handle = le16_to_cpu(expander_pg0.DevHandle);
7182 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7183 printk(KERN_INFO "\texpander present: handle(0x%04x), "
7184 "sas_addr(0x%016llx)\n", handle,
7185 (unsigned long long)sas_address);
7186 _scsih_mark_responding_expander(ioc, sas_address, handle);
7190 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
7194 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7195 * @ioc: per adapter object
7200 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
7202 struct _sas_device *sas_device, *sas_device_next;
7203 struct _sas_node *sas_expander, *sas_expander_next;
7204 struct _raid_device *raid_device, *raid_device_next;
7205 struct list_head tmp_list;
7206 unsigned long flags;
7209 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7212 /* removing unresponding end devices */
7213 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7217 * Iterate, pulling off devices marked as non-responding. We become the
7218 * owner for the reference the list had on any object we prune.
7220 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7221 list_for_each_entry_safe(sas_device, sas_device_next,
7222 &ioc->sas_device_list, list) {
7223 if (!sas_device->responding)
7224 list_move_tail(&sas_device->list, &head);
7226 sas_device->responding = 0;
7228 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7231 * Now, uninitialize and remove the unresponding devices we pruned.
7233 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7234 _scsih_remove_device(ioc, sas_device);
7235 list_del_init(&sas_device->list);
7236 sas_device_put(sas_device);
7239 /* removing unresponding volumes */
7240 if (ioc->ir_firmware) {
7241 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7242 "volumes\n", ioc->name);
7243 list_for_each_entry_safe(raid_device, raid_device_next,
7244 &ioc->raid_device_list, list) {
7245 if (!raid_device->responding)
7246 _scsih_sas_volume_delete(ioc,
7247 raid_device->handle);
7249 raid_device->responding = 0;
7252 /* removing unresponding expanders */
7253 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7255 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7256 INIT_LIST_HEAD(&tmp_list);
7257 list_for_each_entry_safe(sas_expander, sas_expander_next,
7258 &ioc->sas_expander_list, list) {
7259 if (!sas_expander->responding)
7260 list_move_tail(&sas_expander->list, &tmp_list);
7262 sas_expander->responding = 0;
7264 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7265 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7267 list_del(&sas_expander->list);
7268 _scsih_expander_node_remove(ioc, sas_expander);
7270 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7272 /* unblock devices */
7273 _scsih_ublock_io_all_device(ioc);
7277 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7278 struct _sas_node *sas_expander, u16 handle)
7280 Mpi2ExpanderPage1_t expander_pg1;
7281 Mpi2ConfigReply_t mpi_reply;
7284 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7285 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7286 &expander_pg1, i, handle))) {
7287 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7288 ioc->name, __FILE__, __LINE__, __func__);
7292 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7293 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7294 expander_pg1.NegotiatedLinkRate >> 4);
7299 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7300 * @ioc: per adapter object
7305 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7307 Mpi2ExpanderPage0_t expander_pg0;
7308 Mpi2SasDevicePage0_t sas_device_pg0;
7309 Mpi2RaidVolPage1_t volume_pg1;
7310 Mpi2RaidVolPage0_t volume_pg0;
7311 Mpi2RaidPhysDiskPage0_t pd_pg0;
7312 Mpi2EventIrConfigElement_t element;
7313 Mpi2ConfigReply_t mpi_reply;
7316 u16 handle, parent_handle;
7318 struct _sas_device *sas_device;
7319 struct _sas_node *expander_device;
7320 static struct _raid_device *raid_device;
7322 unsigned long flags;
7324 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7326 _scsih_sas_host_refresh(ioc);
7328 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7332 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7333 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7334 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7335 MPI2_IOCSTATUS_MASK;
7336 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7337 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7338 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7339 ioc->name, ioc_status,
7340 le32_to_cpu(mpi_reply.IOCLogInfo));
7343 handle = le16_to_cpu(expander_pg0.DevHandle);
7344 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7345 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7346 ioc, le64_to_cpu(expander_pg0.SASAddress));
7347 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7348 if (expander_device)
7349 _scsih_refresh_expander_links(ioc, expander_device,
7352 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7353 "handle (0x%04x), sas_addr(0x%016llx)\n",
7354 ioc->name, handle, (unsigned long long)
7355 le64_to_cpu(expander_pg0.SASAddress));
7356 _scsih_expander_add(ioc, handle);
7357 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7358 "handle (0x%04x), sas_addr(0x%016llx)\n",
7359 ioc->name, handle, (unsigned long long)
7360 le64_to_cpu(expander_pg0.SASAddress));
7364 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7367 if (!ioc->ir_firmware)
7370 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7372 phys_disk_num = 0xFF;
7373 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7374 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7376 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7377 MPI2_IOCSTATUS_MASK;
7378 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7379 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7380 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7381 ioc->name, ioc_status,
7382 le32_to_cpu(mpi_reply.IOCLogInfo));
7385 phys_disk_num = pd_pg0.PhysDiskNum;
7386 handle = le16_to_cpu(pd_pg0.DevHandle);
7387 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
7389 sas_device_put(sas_device);
7392 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7393 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7396 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7397 MPI2_IOCSTATUS_MASK;
7398 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7399 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7400 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7401 ioc->name, ioc_status,
7402 le32_to_cpu(mpi_reply.IOCLogInfo));
7405 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7406 if (!_scsih_get_sas_address(ioc, parent_handle,
7408 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7409 " handle (0x%04x), sas_addr(0x%016llx)\n",
7410 ioc->name, handle, (unsigned long long)
7411 le64_to_cpu(sas_device_pg0.SASAddress));
7412 mpt2sas_transport_update_links(ioc, sas_address,
7413 handle, sas_device_pg0.PhyNum,
7414 MPI2_SAS_NEG_LINK_RATE_1_5);
7415 set_bit(handle, ioc->pd_handles);
7417 /* This will retry adding the end device.
7418 * _scsih_add_device() will decide on retries and
7419 * return "1" when it should be retried
7421 while (_scsih_add_device(ioc, handle, retry_count++,
7425 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7426 " handle (0x%04x), sas_addr(0x%016llx)\n",
7427 ioc->name, handle, (unsigned long long)
7428 le64_to_cpu(sas_device_pg0.SASAddress));
7432 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7435 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7438 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7439 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7440 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7441 MPI2_IOCSTATUS_MASK;
7442 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7443 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7444 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7445 ioc->name, ioc_status,
7446 le32_to_cpu(mpi_reply.IOCLogInfo));
7449 handle = le16_to_cpu(volume_pg1.DevHandle);
7450 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7451 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7452 le64_to_cpu(volume_pg1.WWID));
7453 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7456 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7457 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7458 sizeof(Mpi2RaidVolPage0_t)))
7460 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7461 MPI2_IOCSTATUS_MASK;
7462 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7463 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7464 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7465 ioc->name, ioc_status,
7466 le32_to_cpu(mpi_reply.IOCLogInfo));
7469 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7470 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7471 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7472 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7473 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7474 element.VolDevHandle = volume_pg1.DevHandle;
7475 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7476 " handle (0x%04x)\n", ioc->name,
7477 volume_pg1.DevHandle);
7478 _scsih_sas_volume_add(ioc, &element);
7479 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7480 " handle (0x%04x)\n", ioc->name,
7481 volume_pg1.DevHandle);
7485 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7490 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7494 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7495 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7497 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7498 MPI2_IOCSTATUS_MASK;
7499 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7500 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7501 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7502 ioc->name, ioc_status,
7503 le32_to_cpu(mpi_reply.IOCLogInfo));
7506 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7507 if (!(_scsih_is_end_device(
7508 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7510 sas_device = mpt2sas_get_sdev_by_addr(ioc,
7511 le64_to_cpu(sas_device_pg0.SASAddress));
7513 sas_device_put(sas_device);
7516 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7517 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7518 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7519 "handle (0x%04x), sas_addr(0x%016llx)\n",
7520 ioc->name, handle, (unsigned long long)
7521 le64_to_cpu(sas_device_pg0.SASAddress));
7522 mpt2sas_transport_update_links(ioc, sas_address, handle,
7523 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7525 /* This will retry adding the end device.
7526 * _scsih_add_device() will decide on retries and
7527 * return "1" when it should be retried
7529 while (_scsih_add_device(ioc, handle, retry_count++,
7533 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7534 "handle (0x%04x), sas_addr(0x%016llx)\n",
7535 ioc->name, handle, (unsigned long long)
7536 le64_to_cpu(sas_device_pg0.SASAddress));
7540 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7543 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7548 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7549 * @ioc: per adapter object
7550 * @reset_phase: phase
7552 * The handler for doing any required cleanup or initialization.
7554 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7555 * MPT2_IOC_DONE_RESET
7560 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7562 switch (reset_phase) {
7563 case MPT2_IOC_PRE_RESET:
7564 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7565 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7567 case MPT2_IOC_AFTER_RESET:
7568 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7569 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7570 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7571 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7572 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7573 complete(&ioc->scsih_cmds.done);
7575 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7576 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7577 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7578 complete(&ioc->tm_cmds.done);
7580 _scsih_fw_event_cleanup_queue(ioc);
7581 _scsih_flush_running_cmds(ioc);
7583 case MPT2_IOC_DONE_RESET:
7584 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7585 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7586 _scsih_sas_host_refresh(ioc);
7587 _scsih_prep_device_scan(ioc);
7588 _scsih_search_responding_sas_devices(ioc);
7589 _scsih_search_responding_raid_devices(ioc);
7590 _scsih_search_responding_expanders(ioc);
7591 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7592 !ioc->sas_hba.num_phys)) {
7593 _scsih_prep_device_scan(ioc);
7594 _scsih_search_responding_sas_devices(ioc);
7595 _scsih_search_responding_raid_devices(ioc);
7596 _scsih_search_responding_expanders(ioc);
7597 _scsih_error_recovery_delete_devices(ioc);
7604 * _firmware_event_work - delayed task for processing firmware events
7605 * @ioc: per adapter object
7606 * @work: equal to the fw_event_work object
7612 _firmware_event_work(struct work_struct *work)
7614 struct fw_event_work *fw_event = container_of(work,
7615 struct fw_event_work, delayed_work.work);
7616 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7618 _scsih_fw_event_del_from_list(ioc, fw_event);
7620 /* the queue is being flushed so ignore this event */
7621 if (ioc->remove_host || ioc->pci_error_recovery) {
7622 fw_event_work_put(fw_event);
7626 switch (fw_event->event) {
7627 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7628 while (scsi_host_in_recovery(ioc->shost) ||
7629 ioc->shost_recovery) {
7631 * If we're unloading, bail. Otherwise, this can become
7634 if (ioc->remove_host)
7639 _scsih_remove_unresponding_sas_devices(ioc);
7640 _scsih_scan_for_devices_after_reset(ioc);
7642 case MPT2SAS_PORT_ENABLE_COMPLETE:
7643 ioc->start_scan = 0;
7645 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7646 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7649 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7650 "from worker thread\n", ioc->name));
7652 case MPT2SAS_TURN_ON_PFA_LED:
7653 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7655 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7656 _scsih_sas_topology_change_event(ioc, fw_event);
7658 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7659 _scsih_sas_device_status_change_event(ioc,
7662 case MPI2_EVENT_SAS_DISCOVERY:
7663 _scsih_sas_discovery_event(ioc,
7666 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7667 _scsih_sas_broadcast_primitive_event(ioc,
7670 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7671 _scsih_sas_enclosure_dev_status_change_event(ioc,
7674 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7675 _scsih_sas_ir_config_change_event(ioc, fw_event);
7677 case MPI2_EVENT_IR_VOLUME:
7678 _scsih_sas_ir_volume_event(ioc, fw_event);
7680 case MPI2_EVENT_IR_PHYSICAL_DISK:
7681 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7683 case MPI2_EVENT_IR_OPERATION_STATUS:
7684 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7688 fw_event_work_put(fw_event);
7692 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7693 * @ioc: per adapter object
7694 * @msix_index: MSIX table index supplied by the OS
7695 * @reply: reply message frame(lower 32bit addr)
7696 * Context: interrupt.
7698 * This function merely adds a new work task into ioc->firmware_event_thread.
7699 * The tasks are worked from _firmware_event_work in user context.
7704 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7707 struct fw_event_work *fw_event;
7708 Mpi2EventNotificationReply_t *mpi_reply;
7712 /* events turned off due to host reset or driver unloading */
7713 if (ioc->remove_host || ioc->pci_error_recovery)
7716 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7718 if (unlikely(!mpi_reply)) {
7719 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7720 ioc->name, __FILE__, __LINE__, __func__);
7724 event = le16_to_cpu(mpi_reply->Event);
7728 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7730 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7731 (Mpi2EventDataSasBroadcastPrimitive_t *)
7732 mpi_reply->EventData;
7734 if (baen_data->Primitive !=
7735 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7738 if (ioc->broadcast_aen_busy) {
7739 ioc->broadcast_aen_pending++;
7742 ioc->broadcast_aen_busy = 1;
7746 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7747 _scsih_check_topo_delete_events(ioc,
7748 (Mpi2EventDataSasTopologyChangeList_t *)
7749 mpi_reply->EventData);
7751 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7752 _scsih_check_ir_config_unhide_events(ioc,
7753 (Mpi2EventDataIrConfigChangeList_t *)
7754 mpi_reply->EventData);
7756 case MPI2_EVENT_IR_VOLUME:
7757 _scsih_check_volume_delete_events(ioc,
7758 (Mpi2EventDataIrVolume_t *)
7759 mpi_reply->EventData);
7761 case MPI2_EVENT_LOG_ENTRY_ADDED:
7763 Mpi2EventDataLogEntryAdded_t *log_entry;
7766 if (!ioc->is_warpdrive)
7769 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7770 mpi_reply->EventData;
7771 log_code = (__le32 *)log_entry->LogData;
7773 if (le16_to_cpu(log_entry->LogEntryQualifier)
7774 != MPT2_WARPDRIVE_LOGENTRY)
7777 switch (le32_to_cpu(*log_code)) {
7778 case MPT2_WARPDRIVE_LC_SSDT:
7779 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7780 "IO Throttling has occurred in the WarpDrive "
7781 "subsystem. Check WarpDrive documentation for "
7782 "additional details.\n", ioc->name);
7784 case MPT2_WARPDRIVE_LC_SSDLW:
7785 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7786 "Program/Erase Cycles for the WarpDrive subsystem "
7787 "in degraded range. Check WarpDrive documentation "
7788 "for additional details.\n", ioc->name);
7790 case MPT2_WARPDRIVE_LC_SSDLF:
7791 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7792 "There are no Program/Erase Cycles for the "
7793 "WarpDrive subsystem. The storage device will be "
7794 "in read-only mode. Check WarpDrive documentation "
7795 "for additional details.\n", ioc->name);
7797 case MPT2_WARPDRIVE_LC_BRMF:
7798 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7799 "The Backup Rail Monitor has failed on the "
7800 "WarpDrive subsystem. Check WarpDrive "
7801 "documentation for additional details.\n",
7808 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7809 case MPI2_EVENT_IR_OPERATION_STATUS:
7810 case MPI2_EVENT_SAS_DISCOVERY:
7811 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7812 case MPI2_EVENT_IR_PHYSICAL_DISK:
7815 case MPI2_EVENT_TEMP_THRESHOLD:
7816 _scsih_temp_threshold_events(ioc,
7817 (Mpi2EventDataTemperature_t *)
7818 mpi_reply->EventData);
7821 default: /* ignore the rest */
7825 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7826 fw_event = alloc_fw_event_work(sz);
7828 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7829 ioc->name, __FILE__, __LINE__, __func__);
7833 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7834 fw_event->ioc = ioc;
7835 fw_event->VF_ID = mpi_reply->VF_ID;
7836 fw_event->VP_ID = mpi_reply->VP_ID;
7837 fw_event->event = event;
7838 _scsih_fw_event_add(ioc, fw_event);
7839 fw_event_work_put(fw_event);
7843 /* shost template */
7844 static struct scsi_host_template scsih_driver_template = {
7845 .module = THIS_MODULE,
7846 .name = "Fusion MPT SAS Host",
7847 .proc_name = MPT2SAS_DRIVER_NAME,
7848 .queuecommand = _scsih_qcmd,
7849 .target_alloc = _scsih_target_alloc,
7850 .slave_alloc = _scsih_slave_alloc,
7851 .slave_configure = _scsih_slave_configure,
7852 .target_destroy = _scsih_target_destroy,
7853 .slave_destroy = _scsih_slave_destroy,
7854 .scan_finished = _scsih_scan_finished,
7855 .scan_start = _scsih_scan_start,
7856 .change_queue_depth = _scsih_change_queue_depth,
7857 .eh_abort_handler = _scsih_abort,
7858 .eh_device_reset_handler = _scsih_dev_reset,
7859 .eh_target_reset_handler = _scsih_target_reset,
7860 .eh_host_reset_handler = _scsih_host_reset,
7861 .bios_param = _scsih_bios_param,
7864 .sg_tablesize = MPT2SAS_SG_DEPTH,
7865 .max_sectors = 32767,
7867 .use_clustering = ENABLE_CLUSTERING,
7868 .shost_attrs = mpt2sas_host_attrs,
7869 .sdev_attrs = mpt2sas_dev_attrs,
7870 .track_queue_depth = 1,
7874 * _scsih_expander_node_remove - removing expander device from list.
7875 * @ioc: per adapter object
7876 * @sas_expander: the sas_device object
7877 * Context: Calling function should acquire ioc->sas_node_lock.
7879 * Removing object and freeing associated memory from the
7880 * ioc->sas_expander_list.
7885 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7886 struct _sas_node *sas_expander)
7888 struct _sas_port *mpt2sas_port, *next;
7890 /* remove sibling ports attached to this expander */
7891 list_for_each_entry_safe(mpt2sas_port, next,
7892 &sas_expander->sas_port_list, port_list) {
7893 if (ioc->shost_recovery)
7895 if (mpt2sas_port->remote_identify.device_type ==
7897 mpt2sas_device_remove_by_sas_address(ioc,
7898 mpt2sas_port->remote_identify.sas_address);
7899 else if (mpt2sas_port->remote_identify.device_type ==
7900 SAS_EDGE_EXPANDER_DEVICE ||
7901 mpt2sas_port->remote_identify.device_type ==
7902 SAS_FANOUT_EXPANDER_DEVICE)
7903 mpt2sas_expander_remove(ioc,
7904 mpt2sas_port->remote_identify.sas_address);
7907 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7908 sas_expander->sas_address_parent);
7910 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7911 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7912 sas_expander->handle, (unsigned long long)
7913 sas_expander->sas_address);
7915 kfree(sas_expander->phy);
7916 kfree(sas_expander);
7920 * _scsih_ir_shutdown - IR shutdown notification
7921 * @ioc: per adapter object
7923 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7924 * the host system is shutting down.
7929 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7931 Mpi2RaidActionRequest_t *mpi_request;
7932 Mpi2RaidActionReply_t *mpi_reply;
7935 /* is IR firmware build loaded ? */
7936 if (!ioc->ir_firmware)
7939 mutex_lock(&ioc->scsih_cmds.mutex);
7941 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7942 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7943 ioc->name, __func__);
7946 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7948 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7950 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7951 ioc->name, __func__);
7952 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7956 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7957 ioc->scsih_cmds.smid = smid;
7958 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7960 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7961 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7963 if (!ioc->hide_ir_msg)
7964 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7965 init_completion(&ioc->scsih_cmds.done);
7966 mpt2sas_base_put_smid_default(ioc, smid);
7967 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7969 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7970 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7971 ioc->name, __func__);
7975 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7976 mpi_reply = ioc->scsih_cmds.reply;
7978 if (!ioc->hide_ir_msg)
7979 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7980 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7981 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7982 le32_to_cpu(mpi_reply->IOCLogInfo));
7986 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7987 mutex_unlock(&ioc->scsih_cmds.mutex);
7991 * _scsih_shutdown - routine call during system shutdown
7992 * @pdev: PCI device struct
7997 _scsih_shutdown(struct pci_dev *pdev)
7999 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8000 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8001 struct workqueue_struct *wq;
8002 unsigned long flags;
8004 ioc->remove_host = 1;
8005 _scsih_fw_event_cleanup_queue(ioc);
8007 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8008 wq = ioc->firmware_event_thread;
8009 ioc->firmware_event_thread = NULL;
8010 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8012 destroy_workqueue(wq);
8014 _scsih_ir_shutdown(ioc);
8015 mpt2sas_base_detach(ioc);
8019 * _scsih_remove - detach and remove add host
8020 * @pdev: PCI device struct
8022 * Routine called when unloading the driver.
8026 _scsih_remove(struct pci_dev *pdev)
8028 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8029 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8030 struct _sas_port *mpt2sas_port, *next_port;
8031 struct _raid_device *raid_device, *next;
8032 struct MPT2SAS_TARGET *sas_target_priv_data;
8033 struct workqueue_struct *wq;
8034 unsigned long flags;
8036 ioc->remove_host = 1;
8037 _scsih_fw_event_cleanup_queue(ioc);
8039 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8040 wq = ioc->firmware_event_thread;
8041 ioc->firmware_event_thread = NULL;
8042 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8044 destroy_workqueue(wq);
8046 /* release all the volumes */
8047 _scsih_ir_shutdown(ioc);
8048 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8050 if (raid_device->starget) {
8051 sas_target_priv_data =
8052 raid_device->starget->hostdata;
8053 sas_target_priv_data->deleted = 1;
8054 scsi_remove_target(&raid_device->starget->dev);
8056 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
8057 "(0x%016llx)\n", ioc->name, raid_device->handle,
8058 (unsigned long long) raid_device->wwid);
8059 _scsih_raid_device_remove(ioc, raid_device);
8062 /* free ports attached to the sas_host */
8063 list_for_each_entry_safe(mpt2sas_port, next_port,
8064 &ioc->sas_hba.sas_port_list, port_list) {
8065 if (mpt2sas_port->remote_identify.device_type ==
8067 mpt2sas_device_remove_by_sas_address(ioc,
8068 mpt2sas_port->remote_identify.sas_address);
8069 else if (mpt2sas_port->remote_identify.device_type ==
8070 SAS_EDGE_EXPANDER_DEVICE ||
8071 mpt2sas_port->remote_identify.device_type ==
8072 SAS_FANOUT_EXPANDER_DEVICE)
8073 mpt2sas_expander_remove(ioc,
8074 mpt2sas_port->remote_identify.sas_address);
8077 /* free phys attached to the sas_host */
8078 if (ioc->sas_hba.num_phys) {
8079 kfree(ioc->sas_hba.phy);
8080 ioc->sas_hba.phy = NULL;
8081 ioc->sas_hba.num_phys = 0;
8084 sas_remove_host(shost);
8085 scsi_remove_host(shost);
8086 mpt2sas_base_detach(ioc);
8087 spin_lock(&gioc_lock);
8088 list_del(&ioc->list);
8089 spin_unlock(&gioc_lock);
8090 scsi_host_put(shost);
8094 * _scsih_probe_boot_devices - reports 1st device
8095 * @ioc: per adapter object
8097 * If specified in bios page 2, this routine reports the 1st
8098 * device scsi-ml or sas transport for persistent boot device
8099 * purposes. Please refer to function _scsih_determine_boot_device()
8102 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
8106 struct _sas_device *sas_device;
8107 struct _raid_device *raid_device;
8109 u64 sas_address_parent;
8111 unsigned long flags;
8114 /* no Bios, return immediately */
8115 if (!ioc->bios_pg3.BiosVersion)
8120 if (ioc->req_boot_device.device) {
8121 device = ioc->req_boot_device.device;
8122 is_raid = ioc->req_boot_device.is_raid;
8123 } else if (ioc->req_alt_boot_device.device) {
8124 device = ioc->req_alt_boot_device.device;
8125 is_raid = ioc->req_alt_boot_device.is_raid;
8126 } else if (ioc->current_boot_device.device) {
8127 device = ioc->current_boot_device.device;
8128 is_raid = ioc->current_boot_device.is_raid;
8135 raid_device = device;
8136 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8137 raid_device->id, 0);
8139 _scsih_raid_device_remove(ioc, raid_device);
8141 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8142 sas_device = device;
8143 handle = sas_device->handle;
8144 sas_address_parent = sas_device->sas_address_parent;
8145 sas_address = sas_device->sas_address;
8146 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8147 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8149 if (ioc->hide_drives)
8151 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
8152 sas_device->sas_address_parent)) {
8153 _scsih_sas_device_remove(ioc, sas_device);
8154 } else if (!sas_device->starget) {
8155 if (!ioc->is_driver_loading) {
8156 mpt2sas_transport_port_remove(ioc,
8158 sas_address_parent);
8159 _scsih_sas_device_remove(ioc, sas_device);
8166 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8167 * @ioc: per adapter object
8169 * Called during initial loading of the driver.
8172 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
8174 struct _raid_device *raid_device, *raid_next;
8177 list_for_each_entry_safe(raid_device, raid_next,
8178 &ioc->raid_device_list, list) {
8179 if (raid_device->starget)
8181 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8182 raid_device->id, 0);
8184 _scsih_raid_device_remove(ioc, raid_device);
8188 static struct _sas_device *get_next_sas_device(struct MPT2SAS_ADAPTER *ioc)
8190 struct _sas_device *sas_device = NULL;
8191 unsigned long flags;
8193 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8194 if (!list_empty(&ioc->sas_device_init_list)) {
8195 sas_device = list_first_entry(&ioc->sas_device_init_list,
8196 struct _sas_device, list);
8197 sas_device_get(sas_device);
8199 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8204 static void sas_device_make_active(struct MPT2SAS_ADAPTER *ioc,
8205 struct _sas_device *sas_device)
8207 unsigned long flags;
8209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8212 * Since we dropped the lock during the call to port_add(), we need to
8213 * be careful here that somebody else didn't move or delete this item
8214 * while we were busy with other things.
8216 * If it was on the list, we need a put() for the reference the list
8217 * had. Either way, we need a get() for the destination list.
8219 if (!list_empty(&sas_device->list)) {
8220 list_del_init(&sas_device->list);
8221 sas_device_put(sas_device);
8224 sas_device_get(sas_device);
8225 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8227 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8231 * _scsih_probe_sas - reporting sas devices to sas transport
8232 * @ioc: per adapter object
8234 * Called during initial loading of the driver.
8237 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
8239 struct _sas_device *sas_device;
8241 if (ioc->hide_drives)
8244 while ((sas_device = get_next_sas_device(ioc))) {
8245 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
8246 sas_device->sas_address_parent)) {
8247 _scsih_sas_device_remove(ioc, sas_device);
8248 sas_device_put(sas_device);
8250 } else if (!sas_device->starget) {
8251 if (!ioc->is_driver_loading) {
8252 mpt2sas_transport_port_remove(ioc,
8253 sas_device->sas_address,
8254 sas_device->sas_address_parent);
8255 _scsih_sas_device_remove(ioc, sas_device);
8256 sas_device_put(sas_device);
8261 sas_device_make_active(ioc, sas_device);
8262 sas_device_put(sas_device);
8267 * _scsih_probe_devices - probing for devices
8268 * @ioc: per adapter object
8270 * Called during initial loading of the driver.
8273 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8275 u16 volume_mapping_flags;
8277 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8278 return; /* return when IOC doesn't support initiator mode */
8280 _scsih_probe_boot_devices(ioc);
8282 if (ioc->ir_firmware) {
8283 volume_mapping_flags =
8284 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8285 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8286 if (volume_mapping_flags ==
8287 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8288 _scsih_probe_raid(ioc);
8289 _scsih_probe_sas(ioc);
8291 _scsih_probe_sas(ioc);
8292 _scsih_probe_raid(ioc);
8295 _scsih_probe_sas(ioc);
8300 * _scsih_scan_start - scsi lld callback for .scan_start
8301 * @shost: SCSI host pointer
8303 * The shost has the ability to discover targets on its own instead
8304 * of scanning the entire bus. In our implemention, we will kick off
8305 * firmware discovery.
8308 _scsih_scan_start(struct Scsi_Host *shost)
8310 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8313 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8314 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8316 if (disable_discovery > 0)
8319 ioc->start_scan = 1;
8320 rc = mpt2sas_port_enable(ioc);
8323 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8327 * _scsih_scan_finished - scsi lld callback for .scan_finished
8328 * @shost: SCSI host pointer
8329 * @time: elapsed time of the scan in jiffies
8331 * This function will be called periodically until it returns 1 with the
8332 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8333 * we wait for firmware discovery to complete, then return 1.
8336 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8338 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8340 if (disable_discovery > 0) {
8341 ioc->is_driver_loading = 0;
8342 ioc->wait_for_discovery_to_complete = 0;
8346 if (time >= (300 * HZ)) {
8347 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8348 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8349 "(timeout=300s)\n", ioc->name);
8350 ioc->is_driver_loading = 0;
8354 if (ioc->start_scan)
8357 if (ioc->start_scan_failed) {
8358 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8359 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8360 ioc->is_driver_loading = 0;
8361 ioc->wait_for_discovery_to_complete = 0;
8362 ioc->remove_host = 1;
8366 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8367 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8369 if (ioc->wait_for_discovery_to_complete) {
8370 ioc->wait_for_discovery_to_complete = 0;
8371 _scsih_probe_devices(ioc);
8373 mpt2sas_base_start_watchdog(ioc);
8374 ioc->is_driver_loading = 0;
8380 * _scsih_probe - attach and add scsi host
8381 * @pdev: PCI device struct
8382 * @id: pci device id
8384 * Returns 0 success, anything else error.
8387 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8389 struct MPT2SAS_ADAPTER *ioc;
8390 struct Scsi_Host *shost;
8393 shost = scsi_host_alloc(&scsih_driver_template,
8394 sizeof(struct MPT2SAS_ADAPTER));
8398 /* init local params */
8399 ioc = shost_priv(shost);
8400 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8401 INIT_LIST_HEAD(&ioc->list);
8402 spin_lock(&gioc_lock);
8403 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8404 spin_unlock(&gioc_lock);
8406 ioc->id = mpt_ids++;
8407 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8409 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8410 ioc->is_warpdrive = 1;
8411 ioc->hide_ir_msg = 1;
8413 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8414 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8415 ioc->tm_cb_idx = tm_cb_idx;
8416 ioc->ctl_cb_idx = ctl_cb_idx;
8417 ioc->base_cb_idx = base_cb_idx;
8418 ioc->port_enable_cb_idx = port_enable_cb_idx;
8419 ioc->transport_cb_idx = transport_cb_idx;
8420 ioc->scsih_cb_idx = scsih_cb_idx;
8421 ioc->config_cb_idx = config_cb_idx;
8422 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8423 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8424 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8425 ioc->logging_level = logging_level;
8426 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8427 /* misc semaphores and spin locks */
8428 mutex_init(&ioc->reset_in_progress_mutex);
8429 /* initializing pci_access_mutex lock */
8430 mutex_init(&ioc->pci_access_mutex);
8431 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8432 spin_lock_init(&ioc->scsi_lookup_lock);
8433 spin_lock_init(&ioc->sas_device_lock);
8434 spin_lock_init(&ioc->sas_node_lock);
8435 spin_lock_init(&ioc->fw_event_lock);
8436 spin_lock_init(&ioc->raid_device_lock);
8438 INIT_LIST_HEAD(&ioc->sas_device_list);
8439 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8440 INIT_LIST_HEAD(&ioc->sas_expander_list);
8441 INIT_LIST_HEAD(&ioc->fw_event_list);
8442 INIT_LIST_HEAD(&ioc->raid_device_list);
8443 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8444 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8445 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8446 INIT_LIST_HEAD(&ioc->reply_queue_list);
8448 /* init shost parameters */
8449 shost->max_cmd_len = 32;
8450 shost->max_lun = max_lun;
8451 shost->transportt = mpt2sas_transport_template;
8452 shost->unique_id = ioc->id;
8454 if (max_sectors != 0xFFFF) {
8455 if (max_sectors < 64) {
8456 shost->max_sectors = 64;
8457 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8458 "for max_sectors, range is 64 to 32767. Assigning "
8459 "value of 64.\n", ioc->name, max_sectors);
8460 } else if (max_sectors > 32767) {
8461 shost->max_sectors = 32767;
8462 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8463 "for max_sectors, range is 64 to 8192. Assigning "
8464 "default value of 32767.\n", ioc->name,
8467 shost->max_sectors = max_sectors & 0xFFFE;
8468 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8469 "set to %d\n", ioc->name, shost->max_sectors);
8473 /* register EEDP capabilities with SCSI layer */
8475 scsi_host_set_prot(shost, prot_mask);
8477 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8478 | SHOST_DIF_TYPE2_PROTECTION
8479 | SHOST_DIF_TYPE3_PROTECTION);
8481 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8484 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8485 "fw_event%d", ioc->id);
8486 ioc->firmware_event_thread = create_singlethread_workqueue(
8487 ioc->firmware_event_name);
8488 if (!ioc->firmware_event_thread) {
8489 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8490 ioc->name, __FILE__, __LINE__, __func__);
8492 goto out_thread_fail;
8495 ioc->is_driver_loading = 1;
8496 if ((mpt2sas_base_attach(ioc))) {
8497 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8498 ioc->name, __FILE__, __LINE__, __func__);
8500 goto out_attach_fail;
8503 if (ioc->is_warpdrive) {
8504 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8505 ioc->hide_drives = 0;
8506 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8507 ioc->hide_drives = 1;
8509 if (_scsih_get_num_volumes(ioc))
8510 ioc->hide_drives = 1;
8512 ioc->hide_drives = 0;
8515 ioc->hide_drives = 0;
8517 rv = scsi_add_host(shost, &pdev->dev);
8519 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8520 ioc->name, __FILE__, __LINE__, __func__);
8521 goto out_add_shost_fail;
8524 scsi_scan_host(shost);
8529 mpt2sas_base_detach(ioc);
8531 destroy_workqueue(ioc->firmware_event_thread);
8533 spin_lock(&gioc_lock);
8534 list_del(&ioc->list);
8535 spin_unlock(&gioc_lock);
8536 scsi_host_put(shost);
8542 * _scsih_suspend - power management suspend main entry point
8543 * @pdev: PCI device struct
8544 * @state: PM state change to (usually PCI_D3)
8546 * Returns 0 success, anything else error.
8549 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8551 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8552 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8553 pci_power_t device_state;
8555 mpt2sas_base_stop_watchdog(ioc);
8556 scsi_block_requests(shost);
8557 _scsih_ir_shutdown(ioc);
8558 device_state = pci_choose_state(pdev, state);
8559 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8560 "operating state [D%d]\n", ioc->name, pdev,
8561 pci_name(pdev), device_state);
8563 mpt2sas_base_free_resources(ioc);
8564 pci_save_state(pdev);
8565 pci_set_power_state(pdev, device_state);
8570 * _scsih_resume - power management resume main entry point
8571 * @pdev: PCI device struct
8573 * Returns 0 success, anything else error.
8576 _scsih_resume(struct pci_dev *pdev)
8578 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8579 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8580 pci_power_t device_state = pdev->current_state;
8583 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8584 "operating state [D%d]\n", ioc->name, pdev,
8585 pci_name(pdev), device_state);
8587 pci_set_power_state(pdev, PCI_D0);
8588 pci_enable_wake(pdev, PCI_D0, 0);
8589 pci_restore_state(pdev);
8591 r = mpt2sas_base_map_resources(ioc);
8595 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8596 scsi_unblock_requests(shost);
8597 mpt2sas_base_start_watchdog(ioc);
8600 #endif /* CONFIG_PM */
8603 * _scsih_pci_error_detected - Called when a PCI error is detected.
8604 * @pdev: PCI device struct
8605 * @state: PCI channel state
8607 * Description: Called when a PCI error is detected.
8610 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8612 static pci_ers_result_t
8613 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8615 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8616 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8618 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8622 case pci_channel_io_normal:
8623 return PCI_ERS_RESULT_CAN_RECOVER;
8624 case pci_channel_io_frozen:
8625 /* Fatal error, prepare for slot reset */
8626 ioc->pci_error_recovery = 1;
8627 scsi_block_requests(ioc->shost);
8628 mpt2sas_base_stop_watchdog(ioc);
8629 mpt2sas_base_free_resources(ioc);
8630 return PCI_ERS_RESULT_NEED_RESET;
8631 case pci_channel_io_perm_failure:
8632 /* Permanent error, prepare for device removal */
8633 ioc->pci_error_recovery = 1;
8634 mpt2sas_base_stop_watchdog(ioc);
8635 _scsih_flush_running_cmds(ioc);
8636 return PCI_ERS_RESULT_DISCONNECT;
8638 return PCI_ERS_RESULT_NEED_RESET;
8642 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8643 * @pdev: PCI device struct
8645 * Description: This routine is called by the pci error recovery
8646 * code after the PCI slot has been reset, just before we
8647 * should resume normal operations.
8649 static pci_ers_result_t
8650 _scsih_pci_slot_reset(struct pci_dev *pdev)
8652 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8653 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8656 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8659 ioc->pci_error_recovery = 0;
8661 pci_restore_state(pdev);
8662 rc = mpt2sas_base_map_resources(ioc);
8664 return PCI_ERS_RESULT_DISCONNECT;
8667 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8670 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8671 (rc == 0) ? "success" : "failed");
8674 return PCI_ERS_RESULT_RECOVERED;
8676 return PCI_ERS_RESULT_DISCONNECT;
8680 * _scsih_pci_resume() - resume normal ops after PCI reset
8681 * @pdev: pointer to PCI device
8683 * Called when the error recovery driver tells us that its
8684 * OK to resume normal operation. Use completion to allow
8685 * halted scsi ops to resume.
8688 _scsih_pci_resume(struct pci_dev *pdev)
8690 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8691 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8693 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8695 pci_cleanup_aer_uncorrect_error_status(pdev);
8696 mpt2sas_base_start_watchdog(ioc);
8697 scsi_unblock_requests(ioc->shost);
8701 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8702 * @pdev: pointer to PCI device
8704 static pci_ers_result_t
8705 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8707 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8708 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8710 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8713 /* TODO - dump whatever for debugging purposes */
8715 /* Request a slot reset. */
8716 return PCI_ERS_RESULT_NEED_RESET;
8719 static const struct pci_error_handlers _scsih_err_handler = {
8720 .error_detected = _scsih_pci_error_detected,
8721 .mmio_enabled = _scsih_pci_mmio_enabled,
8722 .slot_reset = _scsih_pci_slot_reset,
8723 .resume = _scsih_pci_resume,
8726 static struct pci_driver scsih_driver = {
8727 .name = MPT2SAS_DRIVER_NAME,
8728 .id_table = scsih_pci_table,
8729 .probe = _scsih_probe,
8730 .remove = _scsih_remove,
8731 .shutdown = _scsih_shutdown,
8732 .err_handler = &_scsih_err_handler,
8734 .suspend = _scsih_suspend,
8735 .resume = _scsih_resume,
8739 /* raid transport support */
8740 static struct raid_function_template mpt2sas_raid_functions = {
8741 .cookie = &scsih_driver_template,
8742 .is_raid = _scsih_is_raid,
8743 .get_resync = _scsih_get_resync,
8744 .get_state = _scsih_get_state,
8748 * _scsih_init - main entry point for this driver.
8750 * Returns 0 success, anything else error.
8758 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8759 MPT2SAS_DRIVER_VERSION);
8761 mpt2sas_transport_template =
8762 sas_attach_transport(&mpt2sas_transport_functions);
8763 if (!mpt2sas_transport_template)
8765 /* raid transport support */
8766 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8767 if (!mpt2sas_raid_template) {
8768 sas_release_transport(mpt2sas_transport_template);
8772 mpt2sas_base_initialize_callback_handler();
8774 /* queuecommand callback hander */
8775 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8777 /* task management callback handler */
8778 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8780 /* base internal commands callback handler */
8781 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8782 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8783 mpt2sas_port_enable_done);
8785 /* transport internal commands callback handler */
8786 transport_cb_idx = mpt2sas_base_register_callback_handler(
8787 mpt2sas_transport_done);
8789 /* scsih internal commands callback handler */
8790 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8792 /* configuration page API internal commands callback handler */
8793 config_cb_idx = mpt2sas_base_register_callback_handler(
8794 mpt2sas_config_done);
8796 /* ctl module callback handler */
8797 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8799 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8800 _scsih_tm_tr_complete);
8802 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8803 _scsih_tm_volume_tr_complete);
8805 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8806 _scsih_sas_control_complete);
8810 error = pci_register_driver(&scsih_driver);
8812 /* raid transport support */
8813 raid_class_release(mpt2sas_raid_template);
8814 sas_release_transport(mpt2sas_transport_template);
8821 * _scsih_exit - exit point for this driver (when it is a module).
8823 * Returns 0 success, anything else error.
8828 printk(KERN_INFO "mpt2sas version %s unloading\n",
8829 MPT2SAS_DRIVER_VERSION);
8831 pci_unregister_driver(&scsih_driver);
8835 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8836 mpt2sas_base_release_callback_handler(tm_cb_idx);
8837 mpt2sas_base_release_callback_handler(base_cb_idx);
8838 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8839 mpt2sas_base_release_callback_handler(transport_cb_idx);
8840 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8841 mpt2sas_base_release_callback_handler(config_cb_idx);
8842 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8844 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8845 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8846 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8848 /* raid transport support */
8849 raid_class_release(mpt2sas_raid_template);
8850 sas_release_transport(mpt2sas_transport_template);
8854 module_init(_scsih_init);
8855 module_exit(_scsih_exit);