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-2012 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
69 struct _sas_node *sas_expander);
70 static void _firmware_event_work(struct work_struct *work);
72 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
74 static void _scsih_scan_start(struct Scsi_Host *shost);
75 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
77 /* global parameters */
78 LIST_HEAD(mpt2sas_ioc_list);
80 /* local parameters */
81 static u8 scsi_io_cb_idx = -1;
82 static u8 tm_cb_idx = -1;
83 static u8 ctl_cb_idx = -1;
84 static u8 base_cb_idx = -1;
85 static u8 port_enable_cb_idx = -1;
86 static u8 transport_cb_idx = -1;
87 static u8 scsih_cb_idx = -1;
88 static u8 config_cb_idx = -1;
91 static u8 tm_tr_cb_idx = -1 ;
92 static u8 tm_tr_volume_cb_idx = -1 ;
93 static u8 tm_sas_control_cb_idx = -1;
95 /* command line options */
96 static u32 logging_level;
97 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
100 static ushort max_sectors = 0xFFFF;
101 module_param(max_sectors, ushort, 0);
102 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
104 static int missing_delay[2] = {-1, -1};
105 module_param_array(missing_delay, int, NULL, 0);
106 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
108 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
109 #define MPT2SAS_MAX_LUN (16895)
110 static int max_lun = MPT2SAS_MAX_LUN;
111 module_param(max_lun, int, 0);
112 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
114 /* diag_buffer_enable is bitwise
116 * bit 1 set = SNAPSHOT
117 * bit 2 set = EXTENDED
119 * Either bit can be set, or both
121 static int diag_buffer_enable = -1;
122 module_param(diag_buffer_enable, int, 0);
123 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
124 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
126 static int disable_discovery = -1;
127 module_param(disable_discovery, int, 0);
128 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
130 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
131 static int prot_mask = 0;
132 module_param(prot_mask, int, 0);
133 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
136 * struct sense_info - common structure for obtaining sense keys
138 * @asc: additional sense code
139 * @ascq: additional sense code qualifier
148 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
149 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
150 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
152 * struct fw_event_work - firmware event struct
153 * @list: link list framework
154 * @work: work object (ioc->fault_reset_work_q)
155 * @cancel_pending_work: flag set during reset handling
156 * @ioc: per adapter object
157 * @device_handle: device handle
158 * @VF_ID: virtual function id
159 * @VP_ID: virtual port id
160 * @ignore: flag meaning this event has been marked to ignore
161 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
162 * @event_data: reply event data payload follows
164 * This object stored on ioc->fw_event_list.
166 struct fw_event_work {
167 struct list_head list;
168 u8 cancel_pending_work;
169 struct delayed_work delayed_work;
170 struct MPT2SAS_ADAPTER *ioc;
179 /* raid transport support */
180 static struct raid_template *mpt2sas_raid_template;
183 * struct _scsi_io_transfer - scsi io transfer
184 * @handle: sas device handle (assigned by firmware)
185 * @is_raid: flag set for hidden raid components
186 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
187 * @data_length: data transfer length
188 * @data_dma: dma pointer to data
191 * @cdb_length: cdb length
193 * @timeout: timeout for this command
194 * @VF_ID: virtual function id
195 * @VP_ID: virtual port id
196 * @valid_reply: flag set for reply message
197 * @sense_length: sense length
198 * @ioc_status: ioc status
199 * @scsi_state: scsi state
200 * @scsi_status: scsi staus
201 * @log_info: log information
202 * @transfer_length: data length transfer when there is a reply message
204 * Used for sending internal scsi commands to devices within this module.
205 * Refer to _scsi_send_scsi_io().
207 struct _scsi_io_transfer {
210 enum dma_data_direction dir;
213 u8 sense[SCSI_SENSE_BUFFERSIZE];
221 /* the following bits are only valid when 'valid_reply = 1' */
231 * The pci device ids are defined in mpi/mpi2_cnfg.h.
233 static struct pci_device_id scsih_pci_table[] = {
234 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
235 PCI_ANY_ID, PCI_ANY_ID },
237 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
238 PCI_ANY_ID, PCI_ANY_ID },
239 /* Liberator ~ 2108 */
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
241 PCI_ANY_ID, PCI_ANY_ID },
242 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
245 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
250 PCI_ANY_ID, PCI_ANY_ID },
251 /* Thunderbolt ~ 2208 */
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
263 PCI_ANY_ID, PCI_ANY_ID },
265 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
266 PCI_ANY_ID, PCI_ANY_ID },
267 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
268 PCI_ANY_ID, PCI_ANY_ID },
269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
270 PCI_ANY_ID, PCI_ANY_ID },
272 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
273 PCI_ANY_ID, PCI_ANY_ID },
274 {0} /* Terminating entry */
276 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
279 * _scsih_set_debug_level - global setting of ioc->logging_level.
281 * Note: The logging levels are defined in mpt2sas_debug.h.
284 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
286 int ret = param_set_int(val, kp);
287 struct MPT2SAS_ADAPTER *ioc;
292 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
293 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
294 ioc->logging_level = logging_level;
297 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
298 &logging_level, 0644);
301 * _scsih_srch_boot_sas_address - search based on sas_address
302 * @sas_address: sas address
303 * @boot_device: boot device object from bios page 2
305 * Returns 1 when there's a match, 0 means no match.
308 _scsih_srch_boot_sas_address(u64 sas_address,
309 Mpi2BootDeviceSasWwid_t *boot_device)
311 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
315 * _scsih_srch_boot_device_name - search based on device name
316 * @device_name: device name specified in INDENTIFY fram
317 * @boot_device: boot device object from bios page 2
319 * Returns 1 when there's a match, 0 means no match.
322 _scsih_srch_boot_device_name(u64 device_name,
323 Mpi2BootDeviceDeviceName_t *boot_device)
325 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
329 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
330 * @enclosure_logical_id: enclosure logical id
331 * @slot_number: slot number
332 * @boot_device: boot device object from bios page 2
334 * Returns 1 when there's a match, 0 means no match.
337 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
338 Mpi2BootDeviceEnclosureSlot_t *boot_device)
340 return (enclosure_logical_id == le64_to_cpu(boot_device->
341 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
342 SlotNumber)) ? 1 : 0;
346 * _scsih_is_boot_device - search for matching boot device.
347 * @sas_address: sas address
348 * @device_name: device name specified in INDENTIFY fram
349 * @enclosure_logical_id: enclosure logical id
350 * @slot_number: slot number
351 * @form: specifies boot device form
352 * @boot_device: boot device object from bios page 2
354 * Returns 1 when there's a match, 0 means no match.
357 _scsih_is_boot_device(u64 sas_address, u64 device_name,
358 u64 enclosure_logical_id, u16 slot, u8 form,
359 Mpi2BiosPage2BootDevice_t *boot_device)
364 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
367 rc = _scsih_srch_boot_sas_address(
368 sas_address, &boot_device->SasWwid);
370 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
371 if (!enclosure_logical_id)
373 rc = _scsih_srch_boot_encl_slot(
374 enclosure_logical_id,
375 slot, &boot_device->EnclosureSlot);
377 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
380 rc = _scsih_srch_boot_device_name(
381 device_name, &boot_device->DeviceName);
383 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
391 * _scsih_get_sas_address - set the sas_address for given device handle
392 * @handle: device handle
393 * @sas_address: sas address
395 * Returns 0 success, non-zero when failure
398 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
401 Mpi2SasDevicePage0_t sas_device_pg0;
402 Mpi2ConfigReply_t mpi_reply;
406 if (handle <= ioc->sas_hba.num_phys) {
407 *sas_address = ioc->sas_hba.sas_address;
411 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
412 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
413 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
414 __FILE__, __LINE__, __func__);
418 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
419 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
420 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
424 /* we hit this becuase the given parent handle doesn't exist */
425 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
427 /* else error case */
428 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
429 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
430 __FILE__, __LINE__, __func__);
435 * _scsih_determine_boot_device - determine boot device.
436 * @ioc: per adapter object
437 * @device: either sas_device or raid_device object
438 * @is_raid: [flag] 1 = raid object, 0 = sas object
440 * Determines whether this device should be first reported device to
441 * to scsi-ml or sas transport, this purpose is for persistent boot device.
442 * There are primary, alternate, and current entries in bios page 2. The order
443 * priority is primary, alternate, then current. This routine saves
444 * the corresponding device object and is_raid flag in the ioc object.
445 * The saved data to be used later in _scsih_probe_boot_devices().
448 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
449 void *device, u8 is_raid)
451 struct _sas_device *sas_device;
452 struct _raid_device *raid_device;
455 u64 enclosure_logical_id;
458 /* only process this function when driver loads */
459 if (!ioc->is_driver_loading)
462 /* no Bios, return immediately */
463 if (!ioc->bios_pg3.BiosVersion)
468 sas_address = sas_device->sas_address;
469 device_name = sas_device->device_name;
470 enclosure_logical_id = sas_device->enclosure_logical_id;
471 slot = sas_device->slot;
473 raid_device = device;
474 sas_address = raid_device->wwid;
476 enclosure_logical_id = 0;
480 if (!ioc->req_boot_device.device) {
481 if (_scsih_is_boot_device(sas_address, device_name,
482 enclosure_logical_id, slot,
483 (ioc->bios_pg2.ReqBootDeviceForm &
484 MPI2_BIOSPAGE2_FORM_MASK),
485 &ioc->bios_pg2.RequestedBootDevice)) {
486 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
487 "%s: req_boot_device(0x%016llx)\n",
489 (unsigned long long)sas_address));
490 ioc->req_boot_device.device = device;
491 ioc->req_boot_device.is_raid = is_raid;
495 if (!ioc->req_alt_boot_device.device) {
496 if (_scsih_is_boot_device(sas_address, device_name,
497 enclosure_logical_id, slot,
498 (ioc->bios_pg2.ReqAltBootDeviceForm &
499 MPI2_BIOSPAGE2_FORM_MASK),
500 &ioc->bios_pg2.RequestedAltBootDevice)) {
501 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
502 "%s: req_alt_boot_device(0x%016llx)\n",
504 (unsigned long long)sas_address));
505 ioc->req_alt_boot_device.device = device;
506 ioc->req_alt_boot_device.is_raid = is_raid;
510 if (!ioc->current_boot_device.device) {
511 if (_scsih_is_boot_device(sas_address, device_name,
512 enclosure_logical_id, slot,
513 (ioc->bios_pg2.CurrentBootDeviceForm &
514 MPI2_BIOSPAGE2_FORM_MASK),
515 &ioc->bios_pg2.CurrentBootDevice)) {
516 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
517 "%s: current_boot_device(0x%016llx)\n",
519 (unsigned long long)sas_address));
520 ioc->current_boot_device.device = device;
521 ioc->current_boot_device.is_raid = is_raid;
527 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
528 * @ioc: per adapter object
529 * @sas_address: sas address
530 * Context: Calling function should acquire ioc->sas_device_lock
532 * This searches for sas_device based on sas_address, then return sas_device
536 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
539 struct _sas_device *sas_device;
541 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
542 if (sas_device->sas_address == sas_address)
545 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
546 if (sas_device->sas_address == sas_address)
553 * _scsih_sas_device_find_by_handle - sas device search
554 * @ioc: per adapter object
555 * @handle: sas device handle (assigned by firmware)
556 * Context: Calling function should acquire ioc->sas_device_lock
558 * This searches for sas_device based on sas_address, then return sas_device
561 static struct _sas_device *
562 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
564 struct _sas_device *sas_device;
566 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
567 if (sas_device->handle == handle)
570 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
571 if (sas_device->handle == handle)
578 * _scsih_sas_device_remove - remove sas_device from list.
579 * @ioc: per adapter object
580 * @sas_device: the sas_device object
581 * Context: This function will acquire ioc->sas_device_lock.
583 * Removing object and freeing associated memory from the ioc->sas_device_list.
586 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
587 struct _sas_device *sas_device)
594 spin_lock_irqsave(&ioc->sas_device_lock, flags);
595 list_del(&sas_device->list);
597 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
602 * _scsih_sas_device_add - insert sas_device to the list.
603 * @ioc: per adapter object
604 * @sas_device: the sas_device object
605 * Context: This function will acquire ioc->sas_device_lock.
607 * Adding new object to the ioc->sas_device_list.
610 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
611 struct _sas_device *sas_device)
615 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
616 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
617 sas_device->handle, (unsigned long long)sas_device->sas_address));
619 spin_lock_irqsave(&ioc->sas_device_lock, flags);
620 list_add_tail(&sas_device->list, &ioc->sas_device_list);
621 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
623 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
624 sas_device->sas_address_parent)) {
625 _scsih_sas_device_remove(ioc, sas_device);
626 } else if (!sas_device->starget) {
627 /* When asyn scanning is enabled, its not possible to remove
628 * devices while scanning is turned on due to an oops in
629 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
631 if (!ioc->is_driver_loading)
632 mpt2sas_transport_port_remove(ioc,
633 sas_device->sas_address,
634 sas_device->sas_address_parent);
635 _scsih_sas_device_remove(ioc, sas_device);
640 * _scsih_sas_device_init_add - insert sas_device to the list.
641 * @ioc: per adapter object
642 * @sas_device: the sas_device object
643 * Context: This function will acquire ioc->sas_device_lock.
645 * Adding new object at driver load time to the ioc->sas_device_init_list.
648 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
649 struct _sas_device *sas_device)
653 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
654 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
655 sas_device->handle, (unsigned long long)sas_device->sas_address));
657 spin_lock_irqsave(&ioc->sas_device_lock, flags);
658 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
659 _scsih_determine_boot_device(ioc, sas_device, 0);
660 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
664 * _scsih_raid_device_find_by_id - raid device search
665 * @ioc: per adapter object
666 * @id: sas device target id
667 * @channel: sas device channel
668 * Context: Calling function should acquire ioc->raid_device_lock
670 * This searches for raid_device based on target id, then return raid_device
673 static struct _raid_device *
674 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
676 struct _raid_device *raid_device, *r;
679 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
680 if (raid_device->id == id && raid_device->channel == channel) {
691 * _scsih_raid_device_find_by_handle - raid device search
692 * @ioc: per adapter object
693 * @handle: sas device handle (assigned by firmware)
694 * Context: Calling function should acquire ioc->raid_device_lock
696 * This searches for raid_device based on handle, then return raid_device
699 static struct _raid_device *
700 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
702 struct _raid_device *raid_device, *r;
705 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
706 if (raid_device->handle != handle)
717 * _scsih_raid_device_find_by_wwid - raid device search
718 * @ioc: per adapter object
719 * @handle: sas device handle (assigned by firmware)
720 * Context: Calling function should acquire ioc->raid_device_lock
722 * This searches for raid_device based on wwid, then return raid_device
725 static struct _raid_device *
726 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
728 struct _raid_device *raid_device, *r;
731 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
732 if (raid_device->wwid != wwid)
743 * _scsih_raid_device_add - add raid_device object
744 * @ioc: per adapter object
745 * @raid_device: raid_device object
747 * This is added to the raid_device_list link list.
750 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
751 struct _raid_device *raid_device)
755 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
756 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
757 raid_device->handle, (unsigned long long)raid_device->wwid));
759 spin_lock_irqsave(&ioc->raid_device_lock, flags);
760 list_add_tail(&raid_device->list, &ioc->raid_device_list);
761 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
765 * _scsih_raid_device_remove - delete raid_device object
766 * @ioc: per adapter object
767 * @raid_device: raid_device object
771 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
772 struct _raid_device *raid_device)
776 spin_lock_irqsave(&ioc->raid_device_lock, flags);
777 list_del(&raid_device->list);
779 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
783 * mpt2sas_scsih_expander_find_by_handle - expander device search
784 * @ioc: per adapter object
785 * @handle: expander handle (assigned by firmware)
786 * Context: Calling function should acquire ioc->sas_device_lock
788 * This searches for expander device based on handle, then returns the
792 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
794 struct _sas_node *sas_expander, *r;
797 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
798 if (sas_expander->handle != handle)
808 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
809 * @ioc: per adapter object
810 * @sas_address: sas address
811 * Context: Calling function should acquire ioc->sas_node_lock.
813 * This searches for expander device based on sas_address, then returns the
817 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
820 struct _sas_node *sas_expander, *r;
823 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
824 if (sas_expander->sas_address != sas_address)
834 * _scsih_expander_node_add - insert expander device to the list.
835 * @ioc: per adapter object
836 * @sas_expander: the sas_device object
837 * Context: This function will acquire ioc->sas_node_lock.
839 * Adding new object to the ioc->sas_expander_list.
844 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
845 struct _sas_node *sas_expander)
849 spin_lock_irqsave(&ioc->sas_node_lock, flags);
850 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
851 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
855 * _scsih_is_end_device - determines if device is an end device
856 * @device_info: bitfield providing information about the device.
859 * Returns 1 if end device.
862 _scsih_is_end_device(u32 device_info)
864 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
865 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
866 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
867 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
874 * _scsih_scsi_lookup_get - returns scmd entry
875 * @ioc: per adapter object
876 * @smid: system request message index
878 * Returns the smid stored scmd pointer.
880 static struct scsi_cmnd *
881 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
883 return ioc->scsi_lookup[smid - 1].scmd;
887 * _scsih_scsi_lookup_get_clear - returns scmd entry
888 * @ioc: per adapter object
889 * @smid: system request message index
891 * Returns the smid stored scmd pointer.
892 * Then will derefrence the stored scmd pointer.
894 static inline struct scsi_cmnd *
895 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
898 struct scsi_cmnd *scmd;
900 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
901 scmd = ioc->scsi_lookup[smid - 1].scmd;
902 ioc->scsi_lookup[smid - 1].scmd = NULL;
903 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
909 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
910 * @ioc: per adapter object
911 * @smid: system request message index
912 * @scmd: pointer to scsi command object
913 * Context: This function will acquire ioc->scsi_lookup_lock.
915 * This will search for a scmd pointer in the scsi_lookup array,
916 * returning the revelent smid. A returned value of zero means invalid.
919 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
926 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
928 for (i = 0; i < ioc->scsiio_depth; i++) {
929 if (ioc->scsi_lookup[i].scmd == scmd) {
930 smid = ioc->scsi_lookup[i].smid;
935 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
940 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
941 * @ioc: per adapter object
944 * Context: This function will acquire ioc->scsi_lookup_lock.
946 * This will search for a matching channel:id in the scsi_lookup array,
947 * returning 1 if found.
950 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
957 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
959 for (i = 0 ; i < ioc->scsiio_depth; i++) {
960 if (ioc->scsi_lookup[i].scmd &&
961 (ioc->scsi_lookup[i].scmd->device->id == id &&
962 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
968 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
973 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
974 * @ioc: per adapter object
978 * Context: This function will acquire ioc->scsi_lookup_lock.
980 * This will search for a matching channel:id:lun in the scsi_lookup array,
981 * returning 1 if found.
984 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
985 unsigned int lun, int channel)
991 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
993 for (i = 0 ; i < ioc->scsiio_depth; i++) {
994 if (ioc->scsi_lookup[i].scmd &&
995 (ioc->scsi_lookup[i].scmd->device->id == id &&
996 ioc->scsi_lookup[i].scmd->device->channel == channel &&
997 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1003 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1008 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1009 * @ioc: per adapter object
1010 * @smid: smid associated to an IO request
1012 * Returns chain tracker(from ioc->free_chain_list)
1014 static struct chain_tracker *
1015 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1017 struct chain_tracker *chain_req;
1018 unsigned long flags;
1020 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1021 if (list_empty(&ioc->free_chain_list)) {
1022 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1023 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1024 "available\n", ioc->name));
1027 chain_req = list_entry(ioc->free_chain_list.next,
1028 struct chain_tracker, tracker_list);
1029 list_del_init(&chain_req->tracker_list);
1030 list_add_tail(&chain_req->tracker_list,
1031 &ioc->scsi_lookup[smid - 1].chain_list);
1032 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1037 * _scsih_build_scatter_gather - main sg creation routine
1038 * @ioc: per adapter object
1039 * @scmd: scsi command
1040 * @smid: system request message index
1043 * The main routine that builds scatter gather table from a given
1044 * scsi request sent via the .queuecommand main handler.
1046 * Returns 0 success, anything else error
1049 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1050 struct scsi_cmnd *scmd, u16 smid)
1052 Mpi2SCSIIORequest_t *mpi_request;
1053 dma_addr_t chain_dma;
1054 struct scatterlist *sg_scmd;
1055 void *sg_local, *chain;
1060 u32 sges_in_segment;
1062 u32 sgl_flags_last_element;
1063 u32 sgl_flags_end_buffer;
1064 struct chain_tracker *chain_req;
1066 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1068 /* init scatter gather flags */
1069 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1070 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1071 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1072 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1073 << MPI2_SGE_FLAGS_SHIFT;
1074 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1075 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1076 << MPI2_SGE_FLAGS_SHIFT;
1077 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1079 sg_scmd = scsi_sglist(scmd);
1080 sges_left = scsi_dma_map(scmd);
1081 if (sges_left < 0) {
1082 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1083 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1087 sg_local = &mpi_request->SGL;
1088 sges_in_segment = ioc->max_sges_in_main_message;
1089 if (sges_left <= sges_in_segment)
1090 goto fill_in_last_segment;
1092 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1093 (sges_in_segment * ioc->sge_size))/4;
1095 /* fill in main message segment when there is a chain following */
1096 while (sges_in_segment) {
1097 if (sges_in_segment == 1)
1098 ioc->base_add_sg_single(sg_local,
1099 sgl_flags_last_element | sg_dma_len(sg_scmd),
1100 sg_dma_address(sg_scmd));
1102 ioc->base_add_sg_single(sg_local, sgl_flags |
1103 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1104 sg_scmd = sg_next(sg_scmd);
1105 sg_local += ioc->sge_size;
1110 /* initializing the chain flags and pointers */
1111 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1112 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1115 chain = chain_req->chain_buffer;
1116 chain_dma = chain_req->chain_buffer_dma;
1118 sges_in_segment = (sges_left <=
1119 ioc->max_sges_in_chain_message) ? sges_left :
1120 ioc->max_sges_in_chain_message;
1121 chain_offset = (sges_left == sges_in_segment) ?
1122 0 : (sges_in_segment * ioc->sge_size)/4;
1123 chain_length = sges_in_segment * ioc->sge_size;
1125 chain_offset = chain_offset <<
1126 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1127 chain_length += ioc->sge_size;
1129 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1130 chain_length, chain_dma);
1133 goto fill_in_last_segment;
1135 /* fill in chain segments */
1136 while (sges_in_segment) {
1137 if (sges_in_segment == 1)
1138 ioc->base_add_sg_single(sg_local,
1139 sgl_flags_last_element |
1140 sg_dma_len(sg_scmd),
1141 sg_dma_address(sg_scmd));
1143 ioc->base_add_sg_single(sg_local, sgl_flags |
1144 sg_dma_len(sg_scmd),
1145 sg_dma_address(sg_scmd));
1146 sg_scmd = sg_next(sg_scmd);
1147 sg_local += ioc->sge_size;
1152 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1155 chain = chain_req->chain_buffer;
1156 chain_dma = chain_req->chain_buffer_dma;
1160 fill_in_last_segment:
1162 /* fill the last segment */
1165 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1166 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1168 ioc->base_add_sg_single(sg_local, sgl_flags |
1169 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1170 sg_scmd = sg_next(sg_scmd);
1171 sg_local += ioc->sge_size;
1179 * _scsih_adjust_queue_depth - setting device queue depth
1180 * @sdev: scsi device struct
1181 * @qdepth: requested queue depth
1187 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1189 struct Scsi_Host *shost = sdev->host;
1191 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1192 struct MPT2SAS_DEVICE *sas_device_priv_data;
1193 struct MPT2SAS_TARGET *sas_target_priv_data;
1194 struct _sas_device *sas_device;
1195 unsigned long flags;
1197 max_depth = shost->can_queue;
1199 /* limit max device queue for SATA to 32 */
1200 sas_device_priv_data = sdev->hostdata;
1201 if (!sas_device_priv_data)
1203 sas_target_priv_data = sas_device_priv_data->sas_target;
1204 if (!sas_target_priv_data)
1206 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1208 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1209 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1210 sas_device_priv_data->sas_target->sas_address);
1211 if (sas_device && sas_device->device_info &
1212 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1213 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1214 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1218 if (!sdev->tagged_supported)
1220 if (qdepth > max_depth)
1222 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1226 * _scsih_change_queue_depth - setting device queue depth
1227 * @sdev: scsi device struct
1228 * @qdepth: requested queue depth
1229 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1230 * (see include/scsi/scsi_host.h for definition)
1232 * Returns queue depth.
1235 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1237 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1238 _scsih_adjust_queue_depth(sdev, qdepth);
1239 else if (reason == SCSI_QDEPTH_QFULL)
1240 scsi_track_queue_full(sdev, qdepth);
1244 if (sdev->inquiry_len > 7)
1245 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1246 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1247 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1248 sdev->ordered_tags, sdev->scsi_level,
1249 (sdev->inquiry[7] & 2) >> 1);
1251 return sdev->queue_depth;
1255 * _scsih_change_queue_type - changing device queue tag type
1256 * @sdev: scsi device struct
1257 * @tag_type: requested tag type
1259 * Returns queue tag type.
1262 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1264 if (sdev->tagged_supported) {
1265 scsi_set_tag_type(sdev, tag_type);
1267 scsi_activate_tcq(sdev, sdev->queue_depth);
1269 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1277 * _scsih_target_alloc - target add routine
1278 * @starget: scsi target struct
1280 * Returns 0 if ok. Any other return is assumed to be an error and
1281 * the device is ignored.
1284 _scsih_target_alloc(struct scsi_target *starget)
1286 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1287 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1288 struct MPT2SAS_TARGET *sas_target_priv_data;
1289 struct _sas_device *sas_device;
1290 struct _raid_device *raid_device;
1291 unsigned long flags;
1292 struct sas_rphy *rphy;
1294 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1295 if (!sas_target_priv_data)
1298 starget->hostdata = sas_target_priv_data;
1299 sas_target_priv_data->starget = starget;
1300 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1303 if (starget->channel == RAID_CHANNEL) {
1304 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1305 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1308 sas_target_priv_data->handle = raid_device->handle;
1309 sas_target_priv_data->sas_address = raid_device->wwid;
1310 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1311 if (ioc->is_warpdrive)
1312 sas_target_priv_data->raid_device = raid_device;
1313 raid_device->starget = starget;
1315 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1319 /* sas/sata devices */
1320 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1321 rphy = dev_to_rphy(starget->dev.parent);
1322 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1323 rphy->identify.sas_address);
1326 sas_target_priv_data->handle = sas_device->handle;
1327 sas_target_priv_data->sas_address = sas_device->sas_address;
1328 sas_device->starget = starget;
1329 sas_device->id = starget->id;
1330 sas_device->channel = starget->channel;
1331 if (test_bit(sas_device->handle, ioc->pd_handles))
1332 sas_target_priv_data->flags |=
1333 MPT_TARGET_FLAGS_RAID_COMPONENT;
1335 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1341 * _scsih_target_destroy - target destroy routine
1342 * @starget: scsi target struct
1347 _scsih_target_destroy(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 = starget->hostdata;
1358 if (!sas_target_priv_data)
1361 if (starget->channel == RAID_CHANNEL) {
1362 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1363 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1366 raid_device->starget = NULL;
1367 raid_device->sdev = NULL;
1369 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1373 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1374 rphy = dev_to_rphy(starget->dev.parent);
1375 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1376 rphy->identify.sas_address);
1377 if (sas_device && (sas_device->starget == starget) &&
1378 (sas_device->id == starget->id) &&
1379 (sas_device->channel == starget->channel))
1380 sas_device->starget = NULL;
1382 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1385 kfree(sas_target_priv_data);
1386 starget->hostdata = NULL;
1390 * _scsih_slave_alloc - device add routine
1391 * @sdev: scsi device struct
1393 * Returns 0 if ok. Any other return is assumed to be an error and
1394 * the device is ignored.
1397 _scsih_slave_alloc(struct scsi_device *sdev)
1399 struct Scsi_Host *shost;
1400 struct MPT2SAS_ADAPTER *ioc;
1401 struct MPT2SAS_TARGET *sas_target_priv_data;
1402 struct MPT2SAS_DEVICE *sas_device_priv_data;
1403 struct scsi_target *starget;
1404 struct _raid_device *raid_device;
1405 unsigned long flags;
1407 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1408 if (!sas_device_priv_data)
1411 sas_device_priv_data->lun = sdev->lun;
1412 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1414 starget = scsi_target(sdev);
1415 sas_target_priv_data = starget->hostdata;
1416 sas_target_priv_data->num_luns++;
1417 sas_device_priv_data->sas_target = sas_target_priv_data;
1418 sdev->hostdata = sas_device_priv_data;
1419 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1420 sdev->no_uld_attach = 1;
1422 shost = dev_to_shost(&starget->dev);
1423 ioc = shost_priv(shost);
1424 if (starget->channel == RAID_CHANNEL) {
1425 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1426 raid_device = _scsih_raid_device_find_by_id(ioc,
1427 starget->id, starget->channel);
1429 raid_device->sdev = sdev; /* raid is single lun */
1430 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1437 * _scsih_slave_destroy - device destroy routine
1438 * @sdev: scsi device struct
1443 _scsih_slave_destroy(struct scsi_device *sdev)
1445 struct MPT2SAS_TARGET *sas_target_priv_data;
1446 struct scsi_target *starget;
1447 struct Scsi_Host *shost;
1448 struct MPT2SAS_ADAPTER *ioc;
1449 struct _sas_device *sas_device;
1450 unsigned long flags;
1452 if (!sdev->hostdata)
1455 starget = scsi_target(sdev);
1456 sas_target_priv_data = starget->hostdata;
1457 sas_target_priv_data->num_luns--;
1459 shost = dev_to_shost(&starget->dev);
1460 ioc = shost_priv(shost);
1462 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1463 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1464 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1465 sas_target_priv_data->sas_address);
1466 if (sas_device && !sas_target_priv_data->num_luns)
1467 sas_device->starget = NULL;
1468 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1471 kfree(sdev->hostdata);
1472 sdev->hostdata = NULL;
1476 * _scsih_display_sata_capabilities - sata capabilities
1477 * @ioc: per adapter object
1478 * @handle: device handle
1479 * @sdev: scsi device struct
1482 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1483 u16 handle, struct scsi_device *sdev)
1485 Mpi2ConfigReply_t mpi_reply;
1486 Mpi2SasDevicePage0_t sas_device_pg0;
1491 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1492 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1493 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1494 ioc->name, __FILE__, __LINE__, __func__);
1498 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1499 MPI2_IOCSTATUS_MASK;
1500 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1501 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1502 ioc->name, __FILE__, __LINE__, __func__);
1506 flags = le16_to_cpu(sas_device_pg0.Flags);
1507 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1509 sdev_printk(KERN_INFO, sdev,
1510 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1511 "sw_preserve(%s)\n",
1512 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1513 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1516 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1517 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1518 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1522 * _scsih_is_raid - return boolean indicating device is raid volume
1523 * @dev the device struct object
1526 _scsih_is_raid(struct device *dev)
1528 struct scsi_device *sdev = to_scsi_device(dev);
1529 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1531 if (ioc->is_warpdrive)
1533 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1537 * _scsih_get_resync - get raid volume resync percent complete
1538 * @dev the device struct object
1541 _scsih_get_resync(struct device *dev)
1543 struct scsi_device *sdev = to_scsi_device(dev);
1544 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1545 static struct _raid_device *raid_device;
1546 unsigned long flags;
1547 Mpi2RaidVolPage0_t vol_pg0;
1548 Mpi2ConfigReply_t mpi_reply;
1549 u32 volume_status_flags;
1550 u8 percent_complete;
1553 percent_complete = 0;
1555 if (ioc->is_warpdrive)
1558 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1559 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1562 handle = raid_device->handle;
1563 percent_complete = raid_device->percent_complete;
1565 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1570 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1571 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1572 sizeof(Mpi2RaidVolPage0_t))) {
1573 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1574 ioc->name, __FILE__, __LINE__, __func__);
1575 percent_complete = 0;
1579 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1580 if (!(volume_status_flags &
1581 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1582 percent_complete = 0;
1585 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1589 * _scsih_get_state - get raid volume level
1590 * @dev the device struct object
1593 _scsih_get_state(struct device *dev)
1595 struct scsi_device *sdev = to_scsi_device(dev);
1596 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1597 static struct _raid_device *raid_device;
1598 unsigned long flags;
1599 Mpi2RaidVolPage0_t vol_pg0;
1600 Mpi2ConfigReply_t mpi_reply;
1602 enum raid_state state = RAID_STATE_UNKNOWN;
1605 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1606 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1609 handle = raid_device->handle;
1610 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1615 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1616 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1617 sizeof(Mpi2RaidVolPage0_t))) {
1618 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1619 ioc->name, __FILE__, __LINE__, __func__);
1623 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1624 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1625 state = RAID_STATE_RESYNCING;
1629 switch (vol_pg0.VolumeState) {
1630 case MPI2_RAID_VOL_STATE_OPTIMAL:
1631 case MPI2_RAID_VOL_STATE_ONLINE:
1632 state = RAID_STATE_ACTIVE;
1634 case MPI2_RAID_VOL_STATE_DEGRADED:
1635 state = RAID_STATE_DEGRADED;
1637 case MPI2_RAID_VOL_STATE_FAILED:
1638 case MPI2_RAID_VOL_STATE_MISSING:
1639 state = RAID_STATE_OFFLINE;
1643 raid_set_state(mpt2sas_raid_template, dev, state);
1647 * _scsih_set_level - set raid level
1648 * @sdev: scsi device struct
1649 * @volume_type: volume type
1652 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1654 enum raid_level level = RAID_LEVEL_UNKNOWN;
1656 switch (volume_type) {
1657 case MPI2_RAID_VOL_TYPE_RAID0:
1658 level = RAID_LEVEL_0;
1660 case MPI2_RAID_VOL_TYPE_RAID10:
1661 level = RAID_LEVEL_10;
1663 case MPI2_RAID_VOL_TYPE_RAID1E:
1664 level = RAID_LEVEL_1E;
1666 case MPI2_RAID_VOL_TYPE_RAID1:
1667 level = RAID_LEVEL_1;
1671 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1675 * _scsih_get_volume_capabilities - volume capabilities
1676 * @ioc: per adapter object
1677 * @sas_device: the raid_device object
1679 * Returns 0 for success, else 1
1682 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1683 struct _raid_device *raid_device)
1685 Mpi2RaidVolPage0_t *vol_pg0;
1686 Mpi2RaidPhysDiskPage0_t pd_pg0;
1687 Mpi2SasDevicePage0_t sas_device_pg0;
1688 Mpi2ConfigReply_t mpi_reply;
1692 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1693 &num_pds)) || !num_pds) {
1694 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1695 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1700 raid_device->num_pds = num_pds;
1701 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1702 sizeof(Mpi2RaidVol0PhysDisk_t));
1703 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1705 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1706 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1711 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1712 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1713 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1714 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1720 raid_device->volume_type = vol_pg0->VolumeType;
1722 /* figure out what the underlying devices are by
1723 * obtaining the device_info bits for the 1st device
1725 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1726 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1727 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1728 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1729 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1730 le16_to_cpu(pd_pg0.DevHandle)))) {
1731 raid_device->device_info =
1732 le32_to_cpu(sas_device_pg0.DeviceInfo);
1740 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1741 * @ioc: per adapter object
1744 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1746 Mpi2RaidVolPage1_t vol_pg1;
1747 Mpi2ConfigReply_t mpi_reply;
1748 struct _raid_device *raid_device;
1751 unsigned long flags;
1754 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1755 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1756 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1757 MPI2_IOCSTATUS_MASK;
1758 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1760 handle = le16_to_cpu(vol_pg1.DevHandle);
1761 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1762 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1764 raid_device->direct_io_enabled = 0;
1765 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1772 * _scsih_get_num_volumes - Get number of volumes in the ioc
1773 * @ioc: per adapter object
1776 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1778 Mpi2RaidVolPage1_t vol_pg1;
1779 Mpi2ConfigReply_t mpi_reply;
1785 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1786 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1787 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1788 MPI2_IOCSTATUS_MASK;
1789 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1792 handle = le16_to_cpu(vol_pg1.DevHandle);
1799 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1800 * @ioc: per adapter object
1801 * @raid_device: the raid_device object
1804 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1805 struct _raid_device *raid_device)
1807 Mpi2RaidVolPage0_t *vol_pg0;
1808 Mpi2RaidPhysDiskPage0_t pd_pg0;
1809 Mpi2ConfigReply_t mpi_reply;
1812 unsigned long stripe_sz, block_sz;
1813 u8 stripe_exp, block_exp;
1816 if (!ioc->is_warpdrive)
1819 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1820 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1821 "globally as drives are exposed\n", ioc->name);
1824 if (_scsih_get_num_volumes(ioc) > 1) {
1825 _scsih_disable_ddio(ioc);
1826 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1827 "globally as number of drives > 1\n", ioc->name);
1830 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1831 &num_pds)) || !num_pds) {
1832 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1833 "Failure in computing number of drives\n", ioc->name);
1837 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1838 sizeof(Mpi2RaidVol0PhysDisk_t));
1839 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1841 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1842 "Memory allocation failure for RVPG0\n", ioc->name);
1846 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1847 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1848 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1849 "Failure in retrieving RVPG0\n", ioc->name);
1855 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1856 * assumed for WARPDRIVE, disable direct I/O
1858 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1859 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1860 "for the drive with handle(0x%04x): num_mem=%d, "
1861 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1862 num_pds, MPT_MAX_WARPDRIVE_PDS);
1866 for (count = 0; count < num_pds; count++) {
1867 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1868 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1869 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1870 le16_to_cpu(pd_pg0.DevHandle) ==
1871 MPT2SAS_INVALID_DEVICE_HANDLE) {
1872 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1873 "disabled for the drive with handle(0x%04x) member"
1874 "handle retrieval failed for member number=%d\n",
1875 ioc->name, raid_device->handle,
1876 vol_pg0->PhysDisk[count].PhysDiskNum);
1879 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1880 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1881 if (dev_max_lba >> 32) {
1882 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1883 "disabled for the drive with handle(0x%04x) member"
1884 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1885 ioc->name, raid_device->handle,
1886 le16_to_cpu(pd_pg0.DevHandle),
1887 (unsigned long long)dev_max_lba);
1891 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1895 * Assumption for WD: Direct I/O is not supported if the volume is
1898 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
1899 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1900 "for the drive with handle(0x%04x): type=%d, "
1901 "s_sz=%uK, blk_size=%u\n", ioc->name,
1902 raid_device->handle, raid_device->volume_type,
1903 (le32_to_cpu(vol_pg0->StripeSize) *
1904 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
1905 le16_to_cpu(vol_pg0->BlockSize));
1909 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1910 stripe_exp = find_first_bit(&stripe_sz, 32);
1911 if (stripe_exp == 32) {
1912 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1913 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1914 ioc->name, raid_device->handle,
1915 (le32_to_cpu(vol_pg0->StripeSize) *
1916 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
1919 raid_device->stripe_exponent = stripe_exp;
1920 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1921 block_exp = find_first_bit(&block_sz, 16);
1922 if (block_exp == 16) {
1923 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1924 "for the drive with handle(0x%04x) invalid block sz %u\n",
1925 ioc->name, raid_device->handle,
1926 le16_to_cpu(vol_pg0->BlockSize));
1929 raid_device->block_exponent = block_exp;
1930 raid_device->direct_io_enabled = 1;
1932 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1933 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1935 * WARPDRIVE: Though the following fields are not used for direct IO,
1936 * stored for future purpose:
1938 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1939 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1940 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1947 raid_device->direct_io_enabled = 0;
1948 for (count = 0; count < num_pds; count++)
1949 raid_device->pd_handle[count] = 0;
1955 * _scsih_enable_tlr - setting TLR flags
1956 * @ioc: per adapter object
1957 * @sdev: scsi device struct
1959 * Enabling Transaction Layer Retries for tape devices when
1960 * vpd page 0x90 is present
1964 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1967 if (sdev->type != TYPE_TAPE)
1970 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1973 sas_enable_tlr(sdev);
1974 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1975 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1981 * _scsih_slave_configure - device configure routine.
1982 * @sdev: scsi device struct
1984 * Returns 0 if ok. Any other return is assumed to be an error and
1985 * the device is ignored.
1988 _scsih_slave_configure(struct scsi_device *sdev)
1990 struct Scsi_Host *shost = sdev->host;
1991 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1992 struct MPT2SAS_DEVICE *sas_device_priv_data;
1993 struct MPT2SAS_TARGET *sas_target_priv_data;
1994 struct _sas_device *sas_device;
1995 struct _raid_device *raid_device;
1996 unsigned long flags;
2001 u16 handle, volume_handle = 0;
2002 u64 volume_wwid = 0;
2005 sas_device_priv_data = sdev->hostdata;
2006 sas_device_priv_data->configured_lun = 1;
2007 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2008 sas_target_priv_data = sas_device_priv_data->sas_target;
2009 handle = sas_target_priv_data->handle;
2011 /* raid volume handling */
2012 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2014 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2015 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
2016 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2018 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2019 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2020 __LINE__, __func__));
2024 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2025 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2026 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2027 __LINE__, __func__));
2031 * WARPDRIVE: Initialize the required data for Direct IO
2033 _scsih_init_warpdrive_properties(ioc, raid_device);
2035 /* RAID Queue Depth Support
2036 * IS volume = underlying qdepth of drive type, either
2037 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2038 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2040 if (raid_device->device_info &
2041 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2042 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2045 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2046 if (raid_device->device_info &
2047 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2053 switch (raid_device->volume_type) {
2054 case MPI2_RAID_VOL_TYPE_RAID0:
2057 case MPI2_RAID_VOL_TYPE_RAID1E:
2058 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2059 if (ioc->manu_pg10.OEMIdentifier &&
2060 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2061 MFG10_GF0_R10_DISPLAY) &&
2062 !(raid_device->num_pds % 2))
2067 case MPI2_RAID_VOL_TYPE_RAID1:
2068 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2071 case MPI2_RAID_VOL_TYPE_RAID10:
2072 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2075 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2077 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2082 if (!ioc->hide_ir_msg)
2083 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2084 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2085 r_level, raid_device->handle,
2086 (unsigned long long)raid_device->wwid,
2087 raid_device->num_pds, ds);
2088 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2089 /* raid transport support */
2090 if (!ioc->is_warpdrive)
2091 _scsih_set_level(sdev, raid_device->volume_type);
2095 /* non-raid handling */
2096 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2097 if (mpt2sas_config_get_volume_handle(ioc, handle,
2099 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2100 "failure at %s:%d/%s()!\n", ioc->name,
2101 __FILE__, __LINE__, __func__));
2104 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2105 volume_handle, &volume_wwid)) {
2106 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2107 "failure at %s:%d/%s()!\n", ioc->name,
2108 __FILE__, __LINE__, __func__));
2113 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2114 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2115 sas_device_priv_data->sas_target->sas_address);
2117 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2118 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2119 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2120 __LINE__, __func__));
2123 sas_device->volume_handle = volume_handle;
2124 sas_device->volume_wwid = volume_wwid;
2125 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2126 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2130 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2131 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2133 else if (sas_device->device_info &
2134 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2137 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2138 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2139 ds, sas_device->handle,
2140 (unsigned long long)sas_device->sas_address,
2142 (unsigned long long)sas_device->device_name);
2143 sdev_printk(KERN_INFO, sdev, "%s: "
2144 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2145 (unsigned long long) sas_device->enclosure_logical_id,
2148 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2150 _scsih_display_sata_capabilities(ioc, handle, sdev);
2153 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2156 sas_read_port_mode_page(sdev);
2157 _scsih_enable_tlr(ioc, sdev);
2163 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2164 * @sdev: scsi device struct
2165 * @bdev: pointer to block device context
2166 * @capacity: device size (in 512 byte sectors)
2167 * @params: three element array to place output:
2168 * params[0] number of heads (max 255)
2169 * params[1] number of sectors (max 63)
2170 * params[2] number of cylinders
2175 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2176 sector_t capacity, int params[])
2186 dummy = heads * sectors;
2187 cylinders = capacity;
2188 sector_div(cylinders, dummy);
2191 * Handle extended translation size for logical drives
2194 if ((ulong)capacity >= 0x200000) {
2197 dummy = heads * sectors;
2198 cylinders = capacity;
2199 sector_div(cylinders, dummy);
2204 params[1] = sectors;
2205 params[2] = cylinders;
2211 * _scsih_response_code - translation of device response code
2212 * @ioc: per adapter object
2213 * @response_code: response code returned by the device
2218 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2222 switch (response_code) {
2223 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2224 desc = "task management request completed";
2226 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2227 desc = "invalid frame";
2229 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2230 desc = "task management request not supported";
2232 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2233 desc = "task management request failed";
2235 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2236 desc = "task management request succeeded";
2238 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2239 desc = "invalid lun";
2242 desc = "overlapped tag attempted";
2244 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2245 desc = "task queued, however not sent to target";
2251 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2252 ioc->name, response_code, desc);
2256 * _scsih_tm_done - tm completion routine
2257 * @ioc: per adapter object
2258 * @smid: system request message index
2259 * @msix_index: MSIX table index supplied by the OS
2260 * @reply: reply message frame(lower 32bit addr)
2263 * The callback handler when using scsih_issue_tm.
2265 * Return 1 meaning mf should be freed from _base_interrupt
2266 * 0 means the mf is freed from this function.
2269 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2271 MPI2DefaultReply_t *mpi_reply;
2273 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2275 if (ioc->tm_cmds.smid != smid)
2277 mpt2sas_base_flush_reply_queues(ioc);
2278 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2279 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2281 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2282 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2284 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2285 complete(&ioc->tm_cmds.done);
2290 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2291 * @ioc: per adapter object
2292 * @handle: device handle
2294 * During taskmangement request, we need to freeze the device queue.
2297 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2299 struct MPT2SAS_DEVICE *sas_device_priv_data;
2300 struct scsi_device *sdev;
2303 shost_for_each_device(sdev, ioc->shost) {
2306 sas_device_priv_data = sdev->hostdata;
2307 if (!sas_device_priv_data)
2309 if (sas_device_priv_data->sas_target->handle == handle) {
2310 sas_device_priv_data->sas_target->tm_busy = 1;
2312 ioc->ignore_loginfos = 1;
2318 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2319 * @ioc: per adapter object
2320 * @handle: device handle
2322 * During taskmangement request, we need to freeze the device queue.
2325 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2327 struct MPT2SAS_DEVICE *sas_device_priv_data;
2328 struct scsi_device *sdev;
2331 shost_for_each_device(sdev, ioc->shost) {
2334 sas_device_priv_data = sdev->hostdata;
2335 if (!sas_device_priv_data)
2337 if (sas_device_priv_data->sas_target->handle == handle) {
2338 sas_device_priv_data->sas_target->tm_busy = 0;
2340 ioc->ignore_loginfos = 0;
2347 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2348 * @ioc: per adapter struct
2349 * @device_handle: device handle
2350 * @channel: the channel assigned by the OS
2351 * @id: the id assigned by the OS
2353 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2354 * @smid_task: smid assigned to the task
2355 * @timeout: timeout in seconds
2356 * @serial_number: the serial_number from scmd
2357 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2360 * A generic API for sending task management requests to firmware.
2362 * The callback index is set inside `ioc->tm_cb_idx`.
2364 * Return SUCCESS or FAILED.
2367 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2368 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2369 unsigned long serial_number, enum mutex_type m_type)
2371 Mpi2SCSITaskManagementRequest_t *mpi_request;
2372 Mpi2SCSITaskManagementReply_t *mpi_reply;
2375 unsigned long timeleft;
2376 struct scsiio_tracker *scsi_lookup = NULL;
2379 if (m_type == TM_MUTEX_ON)
2380 mutex_lock(&ioc->tm_cmds.mutex);
2381 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2382 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2383 __func__, ioc->name);
2388 if (ioc->shost_recovery || ioc->remove_host ||
2389 ioc->pci_error_recovery) {
2390 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2391 __func__, ioc->name);
2396 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2397 if (ioc_state & MPI2_DOORBELL_USED) {
2398 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2399 "active!\n", ioc->name));
2400 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2402 rc = (!rc) ? SUCCESS : FAILED;
2406 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2407 mpt2sas_base_fault_info(ioc, ioc_state &
2408 MPI2_DOORBELL_DATA_MASK);
2409 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2411 rc = (!rc) ? SUCCESS : FAILED;
2415 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2417 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2418 ioc->name, __func__);
2423 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2424 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2426 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2427 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2429 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2430 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2431 ioc->tm_cmds.smid = smid;
2432 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2433 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2434 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2435 mpi_request->DevHandle = cpu_to_le16(handle);
2436 mpi_request->TaskType = type;
2437 mpi_request->TaskMID = cpu_to_le16(smid_task);
2438 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2439 mpt2sas_scsih_set_tm_flag(ioc, handle);
2440 init_completion(&ioc->tm_cmds.done);
2441 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2442 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2443 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2444 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2445 ioc->name, __func__);
2446 _debug_dump_mf(mpi_request,
2447 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2448 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2449 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2451 rc = (!rc) ? SUCCESS : FAILED;
2452 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2453 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2458 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2459 mpi_reply = ioc->tm_cmds.reply;
2460 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2461 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2462 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2463 le32_to_cpu(mpi_reply->IOCLogInfo),
2464 le32_to_cpu(mpi_reply->TerminationCount)));
2465 if (ioc->logging_level & MPT_DEBUG_TM) {
2466 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2467 if (mpi_reply->IOCStatus)
2468 _debug_dump_mf(mpi_request,
2469 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2474 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2476 if (scsi_lookup->scmd == NULL)
2481 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2482 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2488 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2489 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2490 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2495 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2503 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2504 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2505 if (m_type == TM_MUTEX_ON)
2506 mutex_unlock(&ioc->tm_cmds.mutex);
2511 if (m_type == TM_MUTEX_ON)
2512 mutex_unlock(&ioc->tm_cmds.mutex);
2517 * _scsih_tm_display_info - displays info about the device
2518 * @ioc: per adapter struct
2519 * @scmd: pointer to scsi command object
2521 * Called by task management callback handlers.
2524 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2526 struct scsi_target *starget = scmd->device->sdev_target;
2527 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2528 struct _sas_device *sas_device = NULL;
2529 unsigned long flags;
2530 char *device_str = NULL;
2534 if (ioc->hide_ir_msg)
2535 device_str = "WarpDrive";
2537 device_str = "volume";
2539 scsi_print_command(scmd);
2540 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2541 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2542 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2543 device_str, (unsigned long long)priv_target->sas_address);
2545 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2546 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2547 priv_target->sas_address);
2549 if (priv_target->flags &
2550 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2551 starget_printk(KERN_INFO, starget,
2552 "volume handle(0x%04x), "
2553 "volume wwid(0x%016llx)\n",
2554 sas_device->volume_handle,
2555 (unsigned long long)sas_device->volume_wwid);
2557 starget_printk(KERN_INFO, starget,
2558 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2560 (unsigned long long)sas_device->sas_address,
2562 starget_printk(KERN_INFO, starget,
2563 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2564 (unsigned long long)sas_device->enclosure_logical_id,
2567 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2572 * _scsih_abort - eh threads main abort routine
2573 * @scmd: pointer to scsi command object
2575 * Returns SUCCESS if command aborted else FAILED
2578 _scsih_abort(struct scsi_cmnd *scmd)
2580 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2581 struct MPT2SAS_DEVICE *sas_device_priv_data;
2586 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2587 "scmd(%p)\n", scmd);
2588 _scsih_tm_display_info(ioc, scmd);
2590 sas_device_priv_data = scmd->device->hostdata;
2591 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2592 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2593 "scmd(%p)\n", scmd);
2594 scmd->result = DID_NO_CONNECT << 16;
2595 scmd->scsi_done(scmd);
2600 /* search for the command */
2601 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2603 scmd->result = DID_RESET << 16;
2608 /* for hidden raid components and volumes this is not supported */
2609 if (sas_device_priv_data->sas_target->flags &
2610 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2611 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2612 scmd->result = DID_RESET << 16;
2617 mpt2sas_halt_firmware(ioc);
2619 handle = sas_device_priv_data->sas_target->handle;
2620 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2621 scmd->device->id, scmd->device->lun,
2622 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2623 scmd->serial_number, TM_MUTEX_ON);
2626 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2627 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2632 * _scsih_dev_reset - eh threads main device reset routine
2633 * @scmd: pointer to scsi command object
2635 * Returns SUCCESS if command aborted else FAILED
2638 _scsih_dev_reset(struct scsi_cmnd *scmd)
2640 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2641 struct MPT2SAS_DEVICE *sas_device_priv_data;
2642 struct _sas_device *sas_device;
2643 unsigned long flags;
2647 struct scsi_target *starget = scmd->device->sdev_target;
2649 starget_printk(KERN_INFO, starget, "attempting device reset! "
2650 "scmd(%p)\n", scmd);
2651 _scsih_tm_display_info(ioc, scmd);
2653 sas_device_priv_data = scmd->device->hostdata;
2654 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2655 starget_printk(KERN_INFO, starget, "device been deleted! "
2656 "scmd(%p)\n", scmd);
2657 scmd->result = DID_NO_CONNECT << 16;
2658 scmd->scsi_done(scmd);
2663 /* for hidden raid components obtain the volume_handle */
2665 if (sas_device_priv_data->sas_target->flags &
2666 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2667 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2668 sas_device = _scsih_sas_device_find_by_handle(ioc,
2669 sas_device_priv_data->sas_target->handle);
2671 handle = sas_device->volume_handle;
2672 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2674 handle = sas_device_priv_data->sas_target->handle;
2677 scmd->result = DID_RESET << 16;
2682 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2683 scmd->device->id, scmd->device->lun,
2684 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2688 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2689 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2694 * _scsih_target_reset - eh threads main target reset routine
2695 * @scmd: pointer to scsi command object
2697 * Returns SUCCESS if command aborted else FAILED
2700 _scsih_target_reset(struct scsi_cmnd *scmd)
2702 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2703 struct MPT2SAS_DEVICE *sas_device_priv_data;
2704 struct _sas_device *sas_device;
2705 unsigned long flags;
2708 struct scsi_target *starget = scmd->device->sdev_target;
2710 starget_printk(KERN_INFO, starget, "attempting target reset! "
2711 "scmd(%p)\n", scmd);
2712 _scsih_tm_display_info(ioc, scmd);
2714 sas_device_priv_data = scmd->device->hostdata;
2715 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2716 starget_printk(KERN_INFO, starget, "target been deleted! "
2717 "scmd(%p)\n", scmd);
2718 scmd->result = DID_NO_CONNECT << 16;
2719 scmd->scsi_done(scmd);
2724 /* for hidden raid components obtain the volume_handle */
2726 if (sas_device_priv_data->sas_target->flags &
2727 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2728 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2729 sas_device = _scsih_sas_device_find_by_handle(ioc,
2730 sas_device_priv_data->sas_target->handle);
2732 handle = sas_device->volume_handle;
2733 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2735 handle = sas_device_priv_data->sas_target->handle;
2738 scmd->result = DID_RESET << 16;
2743 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2744 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2745 30, 0, TM_MUTEX_ON);
2748 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2749 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2754 * _scsih_host_reset - eh threads main host reset routine
2755 * @scmd: pointer to scsi command object
2757 * Returns SUCCESS if command aborted else FAILED
2760 _scsih_host_reset(struct scsi_cmnd *scmd)
2762 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2765 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2767 scsi_print_command(scmd);
2769 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2771 r = (retval < 0) ? FAILED : SUCCESS;
2772 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2773 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2779 * _scsih_fw_event_add - insert and queue up fw_event
2780 * @ioc: per adapter object
2781 * @fw_event: object describing the event
2782 * Context: This function will acquire ioc->fw_event_lock.
2784 * This adds the firmware event object into link list, then queues it up to
2785 * be processed from user context.
2790 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2792 unsigned long flags;
2794 if (ioc->firmware_event_thread == NULL)
2797 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2798 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2799 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2800 queue_delayed_work(ioc->firmware_event_thread,
2801 &fw_event->delayed_work, 0);
2802 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2806 * _scsih_fw_event_free - delete fw_event
2807 * @ioc: per adapter object
2808 * @fw_event: object describing the event
2809 * Context: This function will acquire ioc->fw_event_lock.
2811 * This removes firmware event object from link list, frees associated memory.
2816 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2819 unsigned long flags;
2821 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2822 list_del(&fw_event->list);
2823 kfree(fw_event->event_data);
2825 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2830 * _scsih_error_recovery_delete_devices - remove devices not responding
2831 * @ioc: per adapter object
2836 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2838 struct fw_event_work *fw_event;
2840 if (ioc->is_driver_loading)
2843 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2847 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2848 fw_event->ioc = ioc;
2849 _scsih_fw_event_add(ioc, fw_event);
2853 * mpt2sas_port_enable_complete - port enable completed (fake event)
2854 * @ioc: per adapter object
2859 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2861 struct fw_event_work *fw_event;
2863 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2866 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2867 fw_event->ioc = ioc;
2868 _scsih_fw_event_add(ioc, fw_event);
2872 * _scsih_fw_event_cleanup_queue - cleanup event queue
2873 * @ioc: per adapter object
2875 * Walk the firmware event queue, either killing timers, or waiting
2876 * for outstanding events to complete
2881 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2883 struct fw_event_work *fw_event, *next;
2885 if (list_empty(&ioc->fw_event_list) ||
2886 !ioc->firmware_event_thread || in_interrupt())
2889 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2890 if (cancel_delayed_work(&fw_event->delayed_work)) {
2891 _scsih_fw_event_free(ioc, fw_event);
2894 fw_event->cancel_pending_work = 1;
2899 * _scsih_ublock_io_all_device - unblock every device
2900 * @ioc: per adapter object
2902 * change the device state from block to running
2905 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2907 struct MPT2SAS_DEVICE *sas_device_priv_data;
2908 struct scsi_device *sdev;
2910 shost_for_each_device(sdev, ioc->shost) {
2911 sas_device_priv_data = sdev->hostdata;
2912 if (!sas_device_priv_data)
2914 if (!sas_device_priv_data->block)
2916 sas_device_priv_data->block = 0;
2917 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2919 sas_device_priv_data->sas_target->handle));
2920 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2924 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2925 * @ioc: per adapter object
2926 * @handle: device handle
2928 * During device pull we need to appropiately set the sdev state.
2931 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
2933 struct MPT2SAS_DEVICE *sas_device_priv_data;
2934 struct scsi_device *sdev;
2936 shost_for_each_device(sdev, ioc->shost) {
2937 sas_device_priv_data = sdev->hostdata;
2938 if (!sas_device_priv_data)
2940 if (!sas_device_priv_data->block)
2942 if (sas_device_priv_data->sas_target->sas_address ==
2944 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2945 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2946 "sas address(0x%016llx)\n", ioc->name,
2947 (unsigned long long)sas_address));
2948 sas_device_priv_data->block = 0;
2949 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2955 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2956 * @ioc: per adapter object
2957 * @handle: device handle
2959 * During device pull we need to appropiately set the sdev state.
2962 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2964 struct MPT2SAS_DEVICE *sas_device_priv_data;
2965 struct scsi_device *sdev;
2967 shost_for_each_device(sdev, ioc->shost) {
2968 sas_device_priv_data = sdev->hostdata;
2969 if (!sas_device_priv_data)
2971 if (sas_device_priv_data->block)
2973 sas_device_priv_data->block = 1;
2974 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2976 sas_device_priv_data->sas_target->handle));
2977 scsi_internal_device_block(sdev);
2983 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2984 * @ioc: per adapter object
2985 * @handle: device handle
2987 * During device pull we need to appropiately set the sdev state.
2990 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2992 struct MPT2SAS_DEVICE *sas_device_priv_data;
2993 struct scsi_device *sdev;
2995 shost_for_each_device(sdev, ioc->shost) {
2996 sas_device_priv_data = sdev->hostdata;
2997 if (!sas_device_priv_data)
2999 if (sas_device_priv_data->block)
3001 if (sas_device_priv_data->sas_target->handle == handle) {
3002 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3003 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
3004 "handle(0x%04x)\n", ioc->name, handle));
3005 sas_device_priv_data->block = 1;
3006 scsi_internal_device_block(sdev);
3012 * _scsih_block_io_to_children_attached_to_ex
3013 * @ioc: per adapter object
3014 * @sas_expander: the sas_device object
3016 * This routine set sdev state to SDEV_BLOCK for all devices
3017 * attached to this expander. This function called when expander is
3021 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3022 struct _sas_node *sas_expander)
3024 struct _sas_port *mpt2sas_port;
3025 struct _sas_device *sas_device;
3026 struct _sas_node *expander_sibling;
3027 unsigned long flags;
3032 list_for_each_entry(mpt2sas_port,
3033 &sas_expander->sas_port_list, port_list) {
3034 if (mpt2sas_port->remote_identify.device_type ==
3036 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3038 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3039 mpt2sas_port->remote_identify.sas_address);
3041 set_bit(sas_device->handle,
3042 ioc->blocking_handles);
3043 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3047 list_for_each_entry(mpt2sas_port,
3048 &sas_expander->sas_port_list, port_list) {
3050 if (mpt2sas_port->remote_identify.device_type ==
3051 SAS_EDGE_EXPANDER_DEVICE ||
3052 mpt2sas_port->remote_identify.device_type ==
3053 SAS_FANOUT_EXPANDER_DEVICE) {
3055 mpt2sas_scsih_expander_find_by_sas_address(
3056 ioc, mpt2sas_port->remote_identify.sas_address);
3057 _scsih_block_io_to_children_attached_to_ex(ioc,
3064 * _scsih_block_io_to_children_attached_directly
3065 * @ioc: per adapter object
3066 * @event_data: topology change event data
3068 * This routine set sdev state to SDEV_BLOCK for all devices
3069 * direct attached during device pull.
3072 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3073 Mpi2EventDataSasTopologyChangeList_t *event_data)
3080 for (i = 0; i < event_data->NumEntries; i++) {
3081 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3084 phy_number = event_data->StartPhyNum + i;
3085 reason_code = event_data->PHY[i].PhyStatus &
3086 MPI2_EVENT_SAS_TOPO_RC_MASK;
3087 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3088 _scsih_block_io_device(ioc, handle);
3093 * _scsih_tm_tr_send - send task management request
3094 * @ioc: per adapter object
3095 * @handle: device handle
3096 * Context: interrupt time.
3098 * This code is to initiate the device removal handshake protocol
3099 * with controller firmware. This function will issue target reset
3100 * using high priority request queue. It will send a sas iounit
3101 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3103 * This is designed to send muliple task management request at the same
3104 * time to the fifo. If the fifo is full, we will append the request,
3105 * and process it in a future completion.
3108 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3110 Mpi2SCSITaskManagementRequest_t *mpi_request;
3112 struct _sas_device *sas_device;
3113 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3114 u64 sas_address = 0;
3115 unsigned long flags;
3116 struct _tr_list *delayed_tr;
3119 if (ioc->remove_host) {
3120 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3121 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3123 } else if (ioc->pci_error_recovery) {
3124 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3125 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3129 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3130 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3131 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3132 "operational: handle(0x%04x)\n", __func__, ioc->name,
3137 /* if PD, then return */
3138 if (test_bit(handle, ioc->pd_handles))
3141 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3142 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3143 if (sas_device && sas_device->starget &&
3144 sas_device->starget->hostdata) {
3145 sas_target_priv_data = sas_device->starget->hostdata;
3146 sas_target_priv_data->deleted = 1;
3147 sas_address = sas_device->sas_address;
3149 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3151 if (sas_target_priv_data) {
3152 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3153 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3154 (unsigned long long)sas_address));
3155 _scsih_ublock_io_device(ioc, sas_address);
3156 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3159 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3161 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3164 INIT_LIST_HEAD(&delayed_tr->list);
3165 delayed_tr->handle = handle;
3166 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3167 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3168 "DELAYED:tr:handle(0x%04x), (open)\n",
3169 ioc->name, handle));
3173 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3174 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3175 ioc->tm_tr_cb_idx));
3176 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3177 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3178 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3179 mpi_request->DevHandle = cpu_to_le16(handle);
3180 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3181 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3187 * _scsih_sas_control_complete - completion routine
3188 * @ioc: per adapter object
3189 * @smid: system request message index
3190 * @msix_index: MSIX table index supplied by the OS
3191 * @reply: reply message frame(lower 32bit addr)
3192 * Context: interrupt time.
3194 * This is the sas iounit control completion routine.
3195 * This code is part of the code to initiate the device removal
3196 * handshake protocol with controller firmware.
3198 * Return 1 meaning mf should be freed from _base_interrupt
3199 * 0 means the mf is freed from this function.
3202 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3203 u8 msix_index, u32 reply)
3205 Mpi2SasIoUnitControlReply_t *mpi_reply =
3206 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3207 if (likely(mpi_reply)) {
3208 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3209 "sc_complete:handle(0x%04x), (open) "
3210 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3211 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3212 le16_to_cpu(mpi_reply->IOCStatus),
3213 le32_to_cpu(mpi_reply->IOCLogInfo)));
3215 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3216 ioc->name, __FILE__, __LINE__, __func__);
3222 * _scsih_tm_tr_volume_send - send target reset request for volumes
3223 * @ioc: per adapter object
3224 * @handle: device handle
3225 * Context: interrupt time.
3227 * This is designed to send muliple task management request at the same
3228 * time to the fifo. If the fifo is full, we will append the request,
3229 * and process it in a future completion.
3232 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3234 Mpi2SCSITaskManagementRequest_t *mpi_request;
3236 struct _tr_list *delayed_tr;
3238 if (ioc->shost_recovery || ioc->remove_host ||
3239 ioc->pci_error_recovery) {
3240 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3241 "progress!\n", __func__, ioc->name));
3245 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3247 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3250 INIT_LIST_HEAD(&delayed_tr->list);
3251 delayed_tr->handle = handle;
3252 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3253 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3254 "DELAYED:tr:handle(0x%04x), (open)\n",
3255 ioc->name, handle));
3259 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3260 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3261 ioc->tm_tr_volume_cb_idx));
3262 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3263 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3264 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3265 mpi_request->DevHandle = cpu_to_le16(handle);
3266 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3267 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3271 * _scsih_tm_volume_tr_complete - target reset completion
3272 * @ioc: per adapter object
3273 * @smid: system request message index
3274 * @msix_index: MSIX table index supplied by the OS
3275 * @reply: reply message frame(lower 32bit addr)
3276 * Context: interrupt time.
3278 * Return 1 meaning mf should be freed from _base_interrupt
3279 * 0 means the mf is freed from this function.
3282 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3283 u8 msix_index, u32 reply)
3286 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3287 Mpi2SCSITaskManagementReply_t *mpi_reply =
3288 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3290 if (ioc->shost_recovery || ioc->remove_host ||
3291 ioc->pci_error_recovery) {
3292 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3293 "progress!\n", __func__, ioc->name));
3296 if (unlikely(!mpi_reply)) {
3297 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3298 ioc->name, __FILE__, __LINE__, __func__);
3301 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3302 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3303 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3304 dewtprintk(ioc, printk("spurious interrupt: "
3305 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3306 le16_to_cpu(mpi_reply->DevHandle), smid));
3310 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3311 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3312 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3313 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3314 le32_to_cpu(mpi_reply->IOCLogInfo),
3315 le32_to_cpu(mpi_reply->TerminationCount)));
3317 return _scsih_check_for_pending_tm(ioc, smid);
3321 * _scsih_tm_tr_complete -
3322 * @ioc: per adapter object
3323 * @smid: system request message index
3324 * @msix_index: MSIX table index supplied by the OS
3325 * @reply: reply message frame(lower 32bit addr)
3326 * Context: interrupt time.
3328 * This is the target reset completion routine.
3329 * This code is part of the code to initiate the device removal
3330 * handshake protocol with controller firmware.
3331 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3333 * Return 1 meaning mf should be freed from _base_interrupt
3334 * 0 means the mf is freed from this function.
3337 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3341 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3342 Mpi2SCSITaskManagementReply_t *mpi_reply =
3343 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3344 Mpi2SasIoUnitControlRequest_t *mpi_request;
3348 if (ioc->remove_host) {
3349 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3350 "removed\n", __func__, ioc->name));
3352 } else if (ioc->pci_error_recovery) {
3353 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3354 "error recovery\n", __func__, ioc->name));
3357 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3358 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3359 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3360 "operational\n", __func__, ioc->name));
3363 if (unlikely(!mpi_reply)) {
3364 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3365 ioc->name, __FILE__, __LINE__, __func__);
3368 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3369 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3370 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3371 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3372 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3373 le16_to_cpu(mpi_reply->DevHandle), smid));
3377 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3378 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3379 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3380 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3381 le32_to_cpu(mpi_reply->IOCLogInfo),
3382 le32_to_cpu(mpi_reply->TerminationCount)));
3384 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3385 if (!smid_sas_ctrl) {
3386 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3387 ioc->name, __func__);
3391 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3392 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3393 ioc->tm_sas_control_cb_idx));
3394 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3395 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3396 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3397 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3398 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3399 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3401 return _scsih_check_for_pending_tm(ioc, smid);
3405 * _scsih_check_for_pending_tm - check for pending task management
3406 * @ioc: per adapter object
3407 * @smid: system request message index
3409 * This will check delayed target reset list, and feed the
3412 * Return 1 meaning mf should be freed from _base_interrupt
3413 * 0 means the mf is freed from this function.
3416 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3418 struct _tr_list *delayed_tr;
3420 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3421 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3422 struct _tr_list, list);
3423 mpt2sas_base_free_smid(ioc, smid);
3424 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3425 list_del(&delayed_tr->list);
3430 if (!list_empty(&ioc->delayed_tr_list)) {
3431 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3432 struct _tr_list, list);
3433 mpt2sas_base_free_smid(ioc, smid);
3434 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3435 list_del(&delayed_tr->list);
3444 * _scsih_check_topo_delete_events - sanity check on topo events
3445 * @ioc: per adapter object
3446 * @event_data: the event data payload
3448 * This routine added to better handle cable breaker.
3450 * This handles the case where driver receives multiple expander
3451 * add and delete events in a single shot. When there is a delete event
3452 * the routine will void any pending add events waiting in the event queue.
3457 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3458 Mpi2EventDataSasTopologyChangeList_t *event_data)
3460 struct fw_event_work *fw_event;
3461 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3462 u16 expander_handle;
3463 struct _sas_node *sas_expander;
3464 unsigned long flags;
3468 for (i = 0 ; i < event_data->NumEntries; i++) {
3469 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3472 reason_code = event_data->PHY[i].PhyStatus &
3473 MPI2_EVENT_SAS_TOPO_RC_MASK;
3474 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3475 _scsih_tm_tr_send(ioc, handle);
3478 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3479 if (expander_handle < ioc->sas_hba.num_phys) {
3480 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3483 if (event_data->ExpStatus ==
3484 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3485 /* put expander attached devices into blocking state */
3486 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3487 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3489 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3490 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3492 handle = find_first_bit(ioc->blocking_handles,
3493 ioc->facts.MaxDevHandle);
3494 if (handle < ioc->facts.MaxDevHandle)
3495 _scsih_block_io_device(ioc, handle);
3496 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3497 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3498 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3500 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3503 /* mark ignore flag for pending events */
3504 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3505 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3506 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3509 local_event_data = fw_event->event_data;
3510 if (local_event_data->ExpStatus ==
3511 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3512 local_event_data->ExpStatus ==
3513 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3514 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3516 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3517 "setting ignoring flag\n", ioc->name));
3518 fw_event->ignore = 1;
3522 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3526 * _scsih_set_volume_delete_flag - setting volume delete flag
3527 * @ioc: per adapter object
3528 * @handle: device handle
3534 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3536 struct _raid_device *raid_device;
3537 struct MPT2SAS_TARGET *sas_target_priv_data;
3538 unsigned long flags;
3540 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3541 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3542 if (raid_device && raid_device->starget &&
3543 raid_device->starget->hostdata) {
3544 sas_target_priv_data =
3545 raid_device->starget->hostdata;
3546 sas_target_priv_data->deleted = 1;
3547 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3548 "setting delete flag: handle(0x%04x), "
3549 "wwid(0x%016llx)\n", ioc->name, handle,
3550 (unsigned long long) raid_device->wwid));
3552 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3556 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3557 * @handle: input handle
3558 * @a: handle for volume a
3559 * @b: handle for volume b
3561 * IR firmware only supports two raid volumes. The purpose of this
3562 * routine is to set the volume handle in either a or b. When the given
3563 * input handle is non-zero, or when a and b have not been set before.
3566 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3568 if (!handle || handle == *a || handle == *b)
3577 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3578 * @ioc: per adapter object
3579 * @event_data: the event data payload
3580 * Context: interrupt time.
3582 * This routine will send target reset to volume, followed by target
3583 * resets to the PDs. This is called when a PD has been removed, or
3584 * volume has been deleted or removed. When the target reset is sent
3585 * to volume, the PD target resets need to be queued to start upon
3586 * completion of the volume target reset.
3591 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3592 Mpi2EventDataIrConfigChangeList_t *event_data)
3594 Mpi2EventIrConfigElement_t *element;
3596 u16 handle, volume_handle, a, b;
3597 struct _tr_list *delayed_tr;
3602 if (ioc->is_warpdrive)
3605 /* Volume Resets for Deleted or Removed */
3606 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3607 for (i = 0; i < event_data->NumElements; i++, element++) {
3608 if (element->ReasonCode ==
3609 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3610 element->ReasonCode ==
3611 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3612 volume_handle = le16_to_cpu(element->VolDevHandle);
3613 _scsih_set_volume_delete_flag(ioc, volume_handle);
3614 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3618 /* Volume Resets for UNHIDE events */
3619 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3620 for (i = 0; i < event_data->NumElements; i++, element++) {
3621 if (le32_to_cpu(event_data->Flags) &
3622 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3624 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3625 volume_handle = le16_to_cpu(element->VolDevHandle);
3626 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3631 _scsih_tm_tr_volume_send(ioc, a);
3633 _scsih_tm_tr_volume_send(ioc, b);
3635 /* PD target resets */
3636 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3637 for (i = 0; i < event_data->NumElements; i++, element++) {
3638 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3640 handle = le16_to_cpu(element->PhysDiskDevHandle);
3641 volume_handle = le16_to_cpu(element->VolDevHandle);
3642 clear_bit(handle, ioc->pd_handles);
3644 _scsih_tm_tr_send(ioc, handle);
3645 else if (volume_handle == a || volume_handle == b) {
3646 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3647 BUG_ON(!delayed_tr);
3648 INIT_LIST_HEAD(&delayed_tr->list);
3649 delayed_tr->handle = handle;
3650 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3651 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3652 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3655 _scsih_tm_tr_send(ioc, handle);
3661 * _scsih_check_volume_delete_events - set delete flag for volumes
3662 * @ioc: per adapter object
3663 * @event_data: the event data payload
3664 * Context: interrupt time.
3666 * This will handle the case when the cable connected to entire volume is
3667 * pulled. We will take care of setting the deleted flag so normal IO will
3673 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3674 Mpi2EventDataIrVolume_t *event_data)
3678 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3680 state = le32_to_cpu(event_data->NewValue);
3681 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3682 MPI2_RAID_VOL_STATE_FAILED)
3683 _scsih_set_volume_delete_flag(ioc,
3684 le16_to_cpu(event_data->VolDevHandle));
3688 * _scsih_flush_running_cmds - completing outstanding commands.
3689 * @ioc: per adapter object
3691 * The flushing out of all pending scmd commands following host reset,
3692 * where all IO is dropped to the floor.
3697 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3699 struct scsi_cmnd *scmd;
3703 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3704 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3708 mpt2sas_base_free_smid(ioc, smid);
3709 scsi_dma_unmap(scmd);
3710 if (ioc->pci_error_recovery)
3711 scmd->result = DID_NO_CONNECT << 16;
3713 scmd->result = DID_RESET << 16;
3714 scmd->scsi_done(scmd);
3716 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3721 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3722 * @scmd: pointer to scsi command object
3723 * @mpi_request: pointer to the SCSI_IO reqest message frame
3725 * Supporting protection 1 and 3.
3730 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3733 unsigned char prot_op = scsi_get_prot_op(scmd);
3734 unsigned char prot_type = scsi_get_prot_type(scmd);
3736 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3739 if (prot_op == SCSI_PROT_READ_STRIP)
3740 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3741 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3742 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3746 switch (prot_type) {
3747 case SCSI_PROT_DIF_TYPE1:
3748 case SCSI_PROT_DIF_TYPE2:
3751 * enable ref/guard checking
3752 * auto increment ref tag
3754 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3755 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3756 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3757 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3758 cpu_to_be32(scsi_get_lba(scmd));
3761 case SCSI_PROT_DIF_TYPE3:
3764 * enable guard checking
3766 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3769 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3770 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3774 * _scsih_eedp_error_handling - return sense code for EEDP errors
3775 * @scmd: pointer to scsi command object
3776 * @ioc_status: ioc status
3781 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3785 switch (ioc_status) {
3786 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3789 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3792 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3800 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3801 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3802 SAM_STAT_CHECK_CONDITION;
3806 * _scsih_scsi_direct_io_get - returns direct io flag
3807 * @ioc: per adapter object
3808 * @smid: system request message index
3810 * Returns the smid stored scmd pointer.
3813 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3815 return ioc->scsi_lookup[smid - 1].direct_io;
3819 * _scsih_scsi_direct_io_set - sets direct io flag
3820 * @ioc: per adapter object
3821 * @smid: system request message index
3822 * @direct_io: Zero or non-zero value to set in the direct_io flag
3827 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3829 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3834 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3835 * @ioc: per adapter object
3836 * @scmd: pointer to scsi command object
3837 * @raid_device: pointer to raid device data structure
3838 * @mpi_request: pointer to the SCSI_IO reqest message frame
3839 * @smid: system request message index
3844 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3845 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3848 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3849 u32 stripe_sz, stripe_exp;
3850 u8 num_pds, *cdb_ptr, i;
3851 u8 cdb0 = scmd->cmnd[0];
3855 * Try Direct I/O to RAID memeber disks
3857 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3858 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3859 cdb_ptr = mpi_request->CDB.CDB32;
3861 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3863 io_size = scsi_bufflen(scmd) >>
3864 raid_device->block_exponent;
3865 i = (cdb0 < READ_16) ? 2 : 6;
3866 /* get virtual lba */
3867 v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i]));
3869 if (((u64)v_lba + (u64)io_size - 1) <=
3870 (u32)raid_device->max_lba) {
3871 stripe_sz = raid_device->stripe_sz;
3872 stripe_exp = raid_device->stripe_exponent;
3873 stripe_off = v_lba & (stripe_sz - 1);
3875 /* Check whether IO falls within a stripe */
3876 if ((stripe_off + io_size) <= stripe_sz) {
3877 num_pds = raid_device->num_pds;
3878 p_lba = v_lba >> stripe_exp;
3879 stripe_unit = p_lba / num_pds;
3880 column = p_lba % num_pds;
3881 p_lba = (stripe_unit << stripe_exp) +
3883 mpi_request->DevHandle =
3884 cpu_to_le16(raid_device->
3886 (*(__be32 *)(&cdb_ptr[i])) =
3889 * WD: To indicate this I/O is directI/O
3891 _scsih_scsi_direct_io_set(ioc, smid, 1);
3895 io_size = scsi_bufflen(scmd) >>
3896 raid_device->block_exponent;
3897 /* get virtual lba */
3898 v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2]));
3900 if ((v_llba + (u64)io_size - 1) <=
3901 raid_device->max_lba) {
3902 stripe_sz = raid_device->stripe_sz;
3903 stripe_exp = raid_device->stripe_exponent;
3904 stripe_off = (u32) (v_llba & (stripe_sz - 1));
3906 /* Check whether IO falls within a stripe */
3907 if ((stripe_off + io_size) <= stripe_sz) {
3908 num_pds = raid_device->num_pds;
3909 p_lba = (u32)(v_llba >> stripe_exp);
3910 stripe_unit = p_lba / num_pds;
3911 column = p_lba % num_pds;
3912 p_lba = (stripe_unit << stripe_exp) +
3914 mpi_request->DevHandle =
3915 cpu_to_le16(raid_device->
3917 (*(__be64 *)(&cdb_ptr[2])) =
3918 cpu_to_be64((u64)p_lba);
3920 * WD: To indicate this I/O is directI/O
3922 _scsih_scsi_direct_io_set(ioc, smid, 1);
3930 * _scsih_qcmd - main scsi request entry point
3931 * @scmd: pointer to scsi command object
3932 * @done: function pointer to be invoked on completion
3934 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3936 * Returns 0 on success. If there's a failure, return either:
3937 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3938 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3941 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3943 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3944 struct MPT2SAS_DEVICE *sas_device_priv_data;
3945 struct MPT2SAS_TARGET *sas_target_priv_data;
3946 struct _raid_device *raid_device;
3947 Mpi2SCSIIORequest_t *mpi_request;
3951 scmd->scsi_done = done;
3952 sas_device_priv_data = scmd->device->hostdata;
3953 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3954 scmd->result = DID_NO_CONNECT << 16;
3955 scmd->scsi_done(scmd);
3959 if (ioc->pci_error_recovery || ioc->remove_host) {
3960 scmd->result = DID_NO_CONNECT << 16;
3961 scmd->scsi_done(scmd);
3965 sas_target_priv_data = sas_device_priv_data->sas_target;
3966 /* invalid device handle */
3967 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3968 scmd->result = DID_NO_CONNECT << 16;
3969 scmd->scsi_done(scmd);
3973 /* host recovery or link resets sent via IOCTLs */
3974 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3975 return SCSI_MLQUEUE_HOST_BUSY;
3976 /* device busy with task management */
3977 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3978 return SCSI_MLQUEUE_DEVICE_BUSY;
3979 /* device has been deleted */
3980 else if (sas_target_priv_data->deleted) {
3981 scmd->result = DID_NO_CONNECT << 16;
3982 scmd->scsi_done(scmd);
3986 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3987 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3988 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3989 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3991 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3994 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3995 if (scmd->device->tagged_supported) {
3996 if (scmd->device->ordered_tags)
3997 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3999 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4001 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4003 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4004 /* Make sure Device is not raid volume.
4005 * We do not expose raid functionality to upper layer for warpdrive.
4007 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4008 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4009 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4011 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4013 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4014 ioc->name, __func__);
4017 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4018 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4019 _scsih_setup_eedp(scmd, mpi_request);
4020 if (scmd->cmd_len == 32)
4021 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4022 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4023 if (sas_device_priv_data->sas_target->flags &
4024 MPT_TARGET_FLAGS_RAID_COMPONENT)
4025 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4027 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4028 mpi_request->DevHandle =
4029 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4030 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4031 mpi_request->Control = cpu_to_le32(mpi_control);
4032 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4033 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4034 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4035 mpi_request->SenseBufferLowAddress =
4036 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
4037 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4038 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4039 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
4040 mpi_request->VF_ID = 0; /* TODO */
4041 mpi_request->VP_ID = 0;
4042 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4044 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4046 if (!mpi_request->DataLength) {
4047 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4049 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4050 mpt2sas_base_free_smid(ioc, smid);
4055 raid_device = sas_target_priv_data->raid_device;
4056 if (raid_device && raid_device->direct_io_enabled)
4057 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4060 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4061 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4062 le16_to_cpu(mpi_request->DevHandle));
4064 mpt2sas_base_put_smid_default(ioc, smid);
4068 return SCSI_MLQUEUE_HOST_BUSY;
4071 static DEF_SCSI_QCMD(_scsih_qcmd)
4074 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4075 * @sense_buffer: sense data returned by target
4076 * @data: normalized skey/asc/ascq
4081 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4083 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4084 /* descriptor format */
4085 data->skey = sense_buffer[1] & 0x0F;
4086 data->asc = sense_buffer[2];
4087 data->ascq = sense_buffer[3];
4090 data->skey = sense_buffer[2] & 0x0F;
4091 data->asc = sense_buffer[12];
4092 data->ascq = sense_buffer[13];
4096 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4098 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4099 * @ioc: per adapter object
4100 * @scmd: pointer to scsi command object
4101 * @mpi_reply: reply mf payload returned from firmware
4103 * scsi_status - SCSI Status code returned from target device
4104 * scsi_state - state info associated with SCSI_IO determined by ioc
4105 * ioc_status - ioc supplied status info
4110 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4111 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4115 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4116 MPI2_IOCSTATUS_MASK;
4117 u8 scsi_state = mpi_reply->SCSIState;
4118 u8 scsi_status = mpi_reply->SCSIStatus;
4119 char *desc_ioc_state = NULL;
4120 char *desc_scsi_status = NULL;
4121 char *desc_scsi_state = ioc->tmp_string;
4122 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4123 struct _sas_device *sas_device = NULL;
4124 unsigned long flags;
4125 struct scsi_target *starget = scmd->device->sdev_target;
4126 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4127 char *device_str = NULL;
4132 if (ioc->hide_ir_msg)
4133 device_str = "WarpDrive";
4135 device_str = "volume";
4137 if (log_info == 0x31170000)
4140 switch (ioc_status) {
4141 case MPI2_IOCSTATUS_SUCCESS:
4142 desc_ioc_state = "success";
4144 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4145 desc_ioc_state = "invalid function";
4147 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4148 desc_ioc_state = "scsi recovered error";
4150 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4151 desc_ioc_state = "scsi invalid dev handle";
4153 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4154 desc_ioc_state = "scsi device not there";
4156 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4157 desc_ioc_state = "scsi data overrun";
4159 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4160 desc_ioc_state = "scsi data underrun";
4162 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4163 desc_ioc_state = "scsi io data error";
4165 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4166 desc_ioc_state = "scsi protocol error";
4168 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4169 desc_ioc_state = "scsi task terminated";
4171 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4172 desc_ioc_state = "scsi residual mismatch";
4174 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4175 desc_ioc_state = "scsi task mgmt failed";
4177 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4178 desc_ioc_state = "scsi ioc terminated";
4180 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4181 desc_ioc_state = "scsi ext terminated";
4183 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4184 desc_ioc_state = "eedp guard error";
4186 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4187 desc_ioc_state = "eedp ref tag error";
4189 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4190 desc_ioc_state = "eedp app tag error";
4193 desc_ioc_state = "unknown";
4197 switch (scsi_status) {
4198 case MPI2_SCSI_STATUS_GOOD:
4199 desc_scsi_status = "good";
4201 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4202 desc_scsi_status = "check condition";
4204 case MPI2_SCSI_STATUS_CONDITION_MET:
4205 desc_scsi_status = "condition met";
4207 case MPI2_SCSI_STATUS_BUSY:
4208 desc_scsi_status = "busy";
4210 case MPI2_SCSI_STATUS_INTERMEDIATE:
4211 desc_scsi_status = "intermediate";
4213 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4214 desc_scsi_status = "intermediate condmet";
4216 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4217 desc_scsi_status = "reservation conflict";
4219 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4220 desc_scsi_status = "command terminated";
4222 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4223 desc_scsi_status = "task set full";
4225 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4226 desc_scsi_status = "aca active";
4228 case MPI2_SCSI_STATUS_TASK_ABORTED:
4229 desc_scsi_status = "task aborted";
4232 desc_scsi_status = "unknown";
4236 desc_scsi_state[0] = '\0';
4238 desc_scsi_state = " ";
4239 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4240 strcat(desc_scsi_state, "response info ");
4241 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4242 strcat(desc_scsi_state, "state terminated ");
4243 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4244 strcat(desc_scsi_state, "no status ");
4245 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4246 strcat(desc_scsi_state, "autosense failed ");
4247 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4248 strcat(desc_scsi_state, "autosense valid ");
4250 scsi_print_command(scmd);
4252 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4253 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4254 device_str, (unsigned long long)priv_target->sas_address);
4256 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4257 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4258 priv_target->sas_address);
4260 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4261 "phy(%d)\n", ioc->name, sas_device->sas_address,
4263 printk(MPT2SAS_WARN_FMT
4264 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4265 ioc->name, sas_device->enclosure_logical_id,
4268 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4271 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4272 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4273 desc_ioc_state, ioc_status, smid);
4274 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4275 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4276 scsi_get_resid(scmd));
4277 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4278 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4279 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4280 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4281 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4282 scsi_status, desc_scsi_state, scsi_state);
4284 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4285 struct sense_info data;
4286 _scsih_normalize_sense(scmd->sense_buffer, &data);
4287 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4288 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4289 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4292 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4293 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4294 response_bytes = (u8 *)&response_info;
4295 _scsih_response_code(ioc, response_bytes[0]);
4301 * _scsih_turn_on_fault_led - illuminate Fault LED
4302 * @ioc: per adapter object
4303 * @handle: device handle
4309 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4311 Mpi2SepReply_t mpi_reply;
4312 Mpi2SepRequest_t mpi_request;
4314 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4315 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4316 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4317 mpi_request.SlotStatus =
4318 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4319 mpi_request.DevHandle = cpu_to_le16(handle);
4320 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4321 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4322 &mpi_request)) != 0) {
4323 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4324 __FILE__, __LINE__, __func__);
4328 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4329 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4330 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4331 le16_to_cpu(mpi_reply.IOCStatus),
4332 le32_to_cpu(mpi_reply.IOCLogInfo)));
4338 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4339 * @ioc: per adapter object
4340 * @handle: device handle
4341 * Context: interrupt.
4346 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4348 struct fw_event_work *fw_event;
4350 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4353 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4354 fw_event->device_handle = handle;
4355 fw_event->ioc = ioc;
4356 _scsih_fw_event_add(ioc, fw_event);
4360 * _scsih_smart_predicted_fault - process smart errors
4361 * @ioc: per adapter object
4362 * @handle: device handle
4363 * Context: interrupt.
4368 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4370 struct scsi_target *starget;
4371 struct MPT2SAS_TARGET *sas_target_priv_data;
4372 Mpi2EventNotificationReply_t *event_reply;
4373 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4374 struct _sas_device *sas_device;
4376 unsigned long flags;
4378 /* only handle non-raid devices */
4379 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4380 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4382 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4385 starget = sas_device->starget;
4386 sas_target_priv_data = starget->hostdata;
4388 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4389 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4390 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4393 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4394 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4396 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4397 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4399 /* insert into event log */
4400 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4401 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4402 event_reply = kzalloc(sz, GFP_ATOMIC);
4404 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4405 ioc->name, __FILE__, __LINE__, __func__);
4409 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4410 event_reply->Event =
4411 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4412 event_reply->MsgLength = sz/4;
4413 event_reply->EventDataLength =
4414 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4415 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4416 event_reply->EventData;
4417 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4418 event_data->ASC = 0x5D;
4419 event_data->DevHandle = cpu_to_le16(handle);
4420 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4421 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4426 * _scsih_io_done - scsi request callback
4427 * @ioc: per adapter object
4428 * @smid: system request message index
4429 * @msix_index: MSIX table index supplied by the OS
4430 * @reply: reply message frame(lower 32bit addr)
4432 * Callback handler when using _scsih_qcmd.
4434 * Return 1 meaning mf should be freed from _base_interrupt
4435 * 0 means the mf is freed from this function.
4438 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4440 Mpi2SCSIIORequest_t *mpi_request;
4441 Mpi2SCSIIOReply_t *mpi_reply;
4442 struct scsi_cmnd *scmd;
4448 struct MPT2SAS_DEVICE *sas_device_priv_data;
4449 u32 response_code = 0;
4450 unsigned long flags;
4452 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4453 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4457 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4459 if (mpi_reply == NULL) {
4460 scmd->result = DID_OK << 16;
4464 sas_device_priv_data = scmd->device->hostdata;
4465 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4466 sas_device_priv_data->sas_target->deleted) {
4467 scmd->result = DID_NO_CONNECT << 16;
4470 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4472 * WARPDRIVE: If direct_io is set then it is directIO,
4473 * the failed direct I/O should be redirected to volume
4475 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4476 ((ioc_status & MPI2_IOCSTATUS_MASK)
4477 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4478 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4479 ioc->scsi_lookup[smid - 1].scmd = scmd;
4480 _scsih_scsi_direct_io_set(ioc, smid, 0);
4481 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4482 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4483 mpi_request->DevHandle =
4484 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4485 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4486 sas_device_priv_data->sas_target->handle);
4491 /* turning off TLR */
4492 scsi_state = mpi_reply->SCSIState;
4493 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4495 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4496 if (!sas_device_priv_data->tlr_snoop_check) {
4497 sas_device_priv_data->tlr_snoop_check++;
4498 /* Make sure Device is not raid volume.
4499 * We do not expose raid functionality to upper layer for warpdrive.
4501 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4502 sas_is_tlr_enabled(scmd->device) &&
4503 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4504 sas_disable_tlr(scmd->device);
4505 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4509 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4510 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4511 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4512 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4515 ioc_status &= MPI2_IOCSTATUS_MASK;
4516 scsi_status = mpi_reply->SCSIStatus;
4518 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4519 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4520 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4521 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4522 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4525 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4526 struct sense_info data;
4527 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4529 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4530 le32_to_cpu(mpi_reply->SenseCount));
4531 memcpy(scmd->sense_buffer, sense_data, sz);
4532 _scsih_normalize_sense(scmd->sense_buffer, &data);
4533 /* failure prediction threshold exceeded */
4534 if (data.asc == 0x5D)
4535 _scsih_smart_predicted_fault(ioc,
4536 le16_to_cpu(mpi_reply->DevHandle));
4539 switch (ioc_status) {
4540 case MPI2_IOCSTATUS_BUSY:
4541 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4542 scmd->result = SAM_STAT_BUSY;
4545 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4546 scmd->result = DID_NO_CONNECT << 16;
4549 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4550 if (sas_device_priv_data->block) {
4551 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4554 scmd->result = DID_SOFT_ERROR << 16;
4556 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4557 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4558 scmd->result = DID_RESET << 16;
4561 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4562 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4563 scmd->result = DID_SOFT_ERROR << 16;
4565 scmd->result = (DID_OK << 16) | scsi_status;
4568 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4569 scmd->result = (DID_OK << 16) | scsi_status;
4571 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4574 if (xfer_cnt < scmd->underflow) {
4575 if (scsi_status == SAM_STAT_BUSY)
4576 scmd->result = SAM_STAT_BUSY;
4578 scmd->result = DID_SOFT_ERROR << 16;
4579 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4580 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4581 scmd->result = DID_SOFT_ERROR << 16;
4582 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4583 scmd->result = DID_RESET << 16;
4584 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4585 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4586 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4587 scmd->result = (DRIVER_SENSE << 24) |
4588 SAM_STAT_CHECK_CONDITION;
4589 scmd->sense_buffer[0] = 0x70;
4590 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4591 scmd->sense_buffer[12] = 0x20;
4592 scmd->sense_buffer[13] = 0;
4596 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4597 scsi_set_resid(scmd, 0);
4598 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4599 case MPI2_IOCSTATUS_SUCCESS:
4600 scmd->result = (DID_OK << 16) | scsi_status;
4601 if (response_code ==
4602 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4603 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4604 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4605 scmd->result = DID_SOFT_ERROR << 16;
4606 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4607 scmd->result = DID_RESET << 16;
4610 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4611 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4612 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4613 _scsih_eedp_error_handling(scmd, ioc_status);
4615 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4616 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4617 case MPI2_IOCSTATUS_INVALID_SGL:
4618 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4619 case MPI2_IOCSTATUS_INVALID_FIELD:
4620 case MPI2_IOCSTATUS_INVALID_STATE:
4621 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4622 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4624 scmd->result = DID_SOFT_ERROR << 16;
4629 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4630 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4631 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4635 scsi_dma_unmap(scmd);
4636 scmd->scsi_done(scmd);
4641 * _scsih_sas_host_refresh - refreshing sas host object contents
4642 * @ioc: per adapter object
4645 * During port enable, fw will send topology events for every device. Its
4646 * possible that the handles may change from the previous setting, so this
4647 * code keeping handles updating if changed.
4652 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4657 Mpi2ConfigReply_t mpi_reply;
4658 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4659 u16 attached_handle;
4662 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4663 "updating handles for sas_host(0x%016llx)\n",
4664 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4666 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4667 * sizeof(Mpi2SasIOUnit0PhyData_t));
4668 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4669 if (!sas_iounit_pg0) {
4670 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4671 ioc->name, __FILE__, __LINE__, __func__);
4675 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4676 sas_iounit_pg0, sz)) != 0)
4678 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4679 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4681 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4682 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4684 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4685 PhyData[0].ControllerDevHandle);
4686 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4687 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4689 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4690 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4691 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4692 attached_handle, i, link_rate);
4695 kfree(sas_iounit_pg0);
4699 * _scsih_sas_host_add - create sas host object
4700 * @ioc: per adapter object
4702 * Creating host side data object, stored in ioc->sas_hba
4707 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4710 Mpi2ConfigReply_t mpi_reply;
4711 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4712 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4713 Mpi2SasPhyPage0_t phy_pg0;
4714 Mpi2SasDevicePage0_t sas_device_pg0;
4715 Mpi2SasEnclosurePage0_t enclosure_pg0;
4718 u16 device_missing_delay;
4720 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4721 if (!ioc->sas_hba.num_phys) {
4722 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4723 ioc->name, __FILE__, __LINE__, __func__);
4727 /* sas_iounit page 0 */
4728 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4729 sizeof(Mpi2SasIOUnit0PhyData_t));
4730 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4731 if (!sas_iounit_pg0) {
4732 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4733 ioc->name, __FILE__, __LINE__, __func__);
4736 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4737 sas_iounit_pg0, sz))) {
4738 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4739 ioc->name, __FILE__, __LINE__, __func__);
4742 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4743 MPI2_IOCSTATUS_MASK;
4744 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4745 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4746 ioc->name, __FILE__, __LINE__, __func__);
4750 /* sas_iounit page 1 */
4751 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4752 sizeof(Mpi2SasIOUnit1PhyData_t));
4753 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4754 if (!sas_iounit_pg1) {
4755 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4756 ioc->name, __FILE__, __LINE__, __func__);
4759 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4760 sas_iounit_pg1, sz))) {
4761 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4762 ioc->name, __FILE__, __LINE__, __func__);
4765 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4766 MPI2_IOCSTATUS_MASK;
4767 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4768 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4769 ioc->name, __FILE__, __LINE__, __func__);
4773 ioc->io_missing_delay =
4774 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4775 device_missing_delay =
4776 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4777 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4778 ioc->device_missing_delay = (device_missing_delay &
4779 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4781 ioc->device_missing_delay = device_missing_delay &
4782 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4784 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4785 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4786 sizeof(struct _sas_phy), GFP_KERNEL);
4787 if (!ioc->sas_hba.phy) {
4788 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4789 ioc->name, __FILE__, __LINE__, __func__);
4792 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4793 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4795 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4796 ioc->name, __FILE__, __LINE__, __func__);
4799 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4800 MPI2_IOCSTATUS_MASK;
4801 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4802 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4803 ioc->name, __FILE__, __LINE__, __func__);
4808 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4809 PhyData[0].ControllerDevHandle);
4810 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4811 ioc->sas_hba.phy[i].phy_id = i;
4812 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4813 phy_pg0, ioc->sas_hba.parent_dev);
4815 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4816 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4817 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4818 ioc->name, __FILE__, __LINE__, __func__);
4821 ioc->sas_hba.enclosure_handle =
4822 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4823 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4824 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4825 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4826 (unsigned long long) ioc->sas_hba.sas_address,
4827 ioc->sas_hba.num_phys) ;
4829 if (ioc->sas_hba.enclosure_handle) {
4830 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4832 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4833 ioc->sas_hba.enclosure_handle))) {
4834 ioc->sas_hba.enclosure_logical_id =
4835 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4840 kfree(sas_iounit_pg1);
4841 kfree(sas_iounit_pg0);
4845 * _scsih_expander_add - creating expander object
4846 * @ioc: per adapter object
4847 * @handle: expander handle
4849 * Creating expander object, stored in ioc->sas_expander_list.
4851 * Return 0 for success, else error.
4854 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4856 struct _sas_node *sas_expander;
4857 Mpi2ConfigReply_t mpi_reply;
4858 Mpi2ExpanderPage0_t expander_pg0;
4859 Mpi2ExpanderPage1_t expander_pg1;
4860 Mpi2SasEnclosurePage0_t enclosure_pg0;
4863 u64 sas_address, sas_address_parent = 0;
4865 unsigned long flags;
4866 struct _sas_port *mpt2sas_port = NULL;
4872 if (ioc->shost_recovery || ioc->pci_error_recovery)
4875 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4876 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4877 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4878 ioc->name, __FILE__, __LINE__, __func__);
4882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4883 MPI2_IOCSTATUS_MASK;
4884 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4885 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4886 ioc->name, __FILE__, __LINE__, __func__);
4890 /* handle out of order topology events */
4891 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4892 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4894 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4895 ioc->name, __FILE__, __LINE__, __func__);
4898 if (sas_address_parent != ioc->sas_hba.sas_address) {
4899 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4900 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4901 sas_address_parent);
4902 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4903 if (!sas_expander) {
4904 rc = _scsih_expander_add(ioc, parent_handle);
4910 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4911 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4912 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4914 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4919 sas_expander = kzalloc(sizeof(struct _sas_node),
4921 if (!sas_expander) {
4922 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4923 ioc->name, __FILE__, __LINE__, __func__);
4927 sas_expander->handle = handle;
4928 sas_expander->num_phys = expander_pg0.NumPhys;
4929 sas_expander->sas_address_parent = sas_address_parent;
4930 sas_expander->sas_address = sas_address;
4932 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4933 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4934 handle, parent_handle, (unsigned long long)
4935 sas_expander->sas_address, sas_expander->num_phys);
4937 if (!sas_expander->num_phys)
4939 sas_expander->phy = kcalloc(sas_expander->num_phys,
4940 sizeof(struct _sas_phy), GFP_KERNEL);
4941 if (!sas_expander->phy) {
4942 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4943 ioc->name, __FILE__, __LINE__, __func__);
4948 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4949 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4950 sas_address_parent);
4951 if (!mpt2sas_port) {
4952 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4953 ioc->name, __FILE__, __LINE__, __func__);
4957 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4959 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4960 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4961 &expander_pg1, i, handle))) {
4962 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4963 ioc->name, __FILE__, __LINE__, __func__);
4967 sas_expander->phy[i].handle = handle;
4968 sas_expander->phy[i].phy_id = i;
4970 if ((mpt2sas_transport_add_expander_phy(ioc,
4971 &sas_expander->phy[i], expander_pg1,
4972 sas_expander->parent_dev))) {
4973 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4974 ioc->name, __FILE__, __LINE__, __func__);
4980 if (sas_expander->enclosure_handle) {
4981 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4982 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4983 sas_expander->enclosure_handle))) {
4984 sas_expander->enclosure_logical_id =
4985 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4989 _scsih_expander_node_add(ioc, sas_expander);
4995 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4996 sas_address_parent);
4997 kfree(sas_expander);
5002 * _scsih_done - scsih callback handler.
5003 * @ioc: per adapter object
5004 * @smid: system request message index
5005 * @msix_index: MSIX table index supplied by the OS
5006 * @reply: reply message frame(lower 32bit addr)
5008 * Callback handler when sending internal generated message frames.
5009 * The callback index passed is `ioc->scsih_cb_idx`
5011 * Return 1 meaning mf should be freed from _base_interrupt
5012 * 0 means the mf is freed from this function.
5015 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5017 MPI2DefaultReply_t *mpi_reply;
5019 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5020 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5022 if (ioc->scsih_cmds.smid != smid)
5024 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5026 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5027 mpi_reply->MsgLength*4);
5028 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5030 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5031 complete(&ioc->scsih_cmds.done);
5036 * mpt2sas_expander_remove - removing expander object
5037 * @ioc: per adapter object
5038 * @sas_address: expander sas_address
5043 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5045 struct _sas_node *sas_expander;
5046 unsigned long flags;
5048 if (ioc->shost_recovery)
5051 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5052 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5055 list_del(&sas_expander->list);
5056 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5058 _scsih_expander_node_remove(ioc, sas_expander);
5062 * _scsih_check_access_status - check access flags
5063 * @ioc: per adapter object
5064 * @sas_address: sas address
5065 * @handle: sas device handle
5066 * @access_flags: errors returned during discovery of the device
5068 * Return 0 for success, else failure
5071 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5072 u16 handle, u8 access_status)
5077 switch (access_status) {
5078 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5082 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5083 desc = "sata capability failed";
5085 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5086 desc = "sata affiliation conflict";
5088 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5089 desc = "route not addressable";
5091 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5092 desc = "smp error not addressable";
5094 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5095 desc = "device blocked";
5097 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5104 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5105 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5106 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5107 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5108 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5109 desc = "sata initialization failed";
5119 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5120 "handle(0x%04x)\n", ioc->name, desc,
5121 (unsigned long long)sas_address, handle);
5126 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5128 Mpi2ConfigReply_t mpi_reply;
5129 Mpi2SasDevicePage0_t sas_device_pg0;
5130 struct _sas_device *sas_device;
5132 unsigned long flags;
5134 struct scsi_target *starget;
5135 struct MPT2SAS_TARGET *sas_target_priv_data;
5139 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5140 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5143 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5144 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5147 /* check if this is end device */
5148 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5149 if (!(_scsih_is_end_device(device_info)))
5152 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5153 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5154 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5158 printk(MPT2SAS_ERR_FMT "device is not present "
5159 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5160 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5164 if (unlikely(sas_device->handle != handle)) {
5165 starget = sas_device->starget;
5166 sas_target_priv_data = starget->hostdata;
5167 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5168 " to (0x%04x)!!!\n", sas_device->handle, handle);
5169 sas_target_priv_data->handle = handle;
5170 sas_device->handle = handle;
5173 /* check if device is present */
5174 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5175 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5176 printk(MPT2SAS_ERR_FMT "device is not present "
5177 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5178 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5182 /* check if there were any issues with discovery */
5183 if (_scsih_check_access_status(ioc, sas_address, handle,
5184 sas_device_pg0.AccessStatus)) {
5185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5188 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5189 _scsih_ublock_io_device(ioc, sas_address);
5194 * _scsih_add_device - creating sas device object
5195 * @ioc: per adapter object
5196 * @handle: sas device handle
5197 * @phy_num: phy number end device attached to
5198 * @is_pd: is this hidden raid component
5200 * Creating end device object, stored in ioc->sas_device_list.
5202 * Returns 0 for success, non-zero for failure.
5205 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5207 Mpi2ConfigReply_t mpi_reply;
5208 Mpi2SasDevicePage0_t sas_device_pg0;
5209 Mpi2SasEnclosurePage0_t enclosure_pg0;
5210 struct _sas_device *sas_device;
5214 unsigned long flags;
5216 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5217 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5218 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5219 ioc->name, __FILE__, __LINE__, __func__);
5223 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5224 MPI2_IOCSTATUS_MASK;
5225 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5226 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5227 ioc->name, __FILE__, __LINE__, __func__);
5231 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5233 /* check if device is present */
5234 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5235 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5236 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5237 ioc->name, __FILE__, __LINE__, __func__);
5238 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5239 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5243 /* check if there were any issues with discovery */
5244 if (_scsih_check_access_status(ioc, sas_address, handle,
5245 sas_device_pg0.AccessStatus))
5248 /* check if this is end device */
5249 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5250 if (!(_scsih_is_end_device(device_info))) {
5251 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5252 ioc->name, __FILE__, __LINE__, __func__);
5257 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5258 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5260 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5265 sas_device = kzalloc(sizeof(struct _sas_device),
5268 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5269 ioc->name, __FILE__, __LINE__, __func__);
5273 sas_device->handle = handle;
5274 if (_scsih_get_sas_address(ioc, le16_to_cpu
5275 (sas_device_pg0.ParentDevHandle),
5276 &sas_device->sas_address_parent) != 0)
5277 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5278 ioc->name, __FILE__, __LINE__, __func__);
5279 sas_device->enclosure_handle =
5280 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5282 le16_to_cpu(sas_device_pg0.Slot);
5283 sas_device->device_info = device_info;
5284 sas_device->sas_address = sas_address;
5285 sas_device->phy = sas_device_pg0.PhyNum;
5287 /* get enclosure_logical_id */
5288 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5289 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5290 sas_device->enclosure_handle)))
5291 sas_device->enclosure_logical_id =
5292 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5294 /* get device name */
5295 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5297 if (ioc->wait_for_discovery_to_complete)
5298 _scsih_sas_device_init_add(ioc, sas_device);
5300 _scsih_sas_device_add(ioc, sas_device);
5306 * _scsih_remove_device - removing sas device object
5307 * @ioc: per adapter object
5308 * @sas_device_delete: the sas_device object
5313 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5314 struct _sas_device *sas_device)
5316 struct MPT2SAS_TARGET *sas_target_priv_data;
5318 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5319 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5320 sas_device->handle, (unsigned long long)
5321 sas_device->sas_address));
5323 if (sas_device->starget && sas_device->starget->hostdata) {
5324 sas_target_priv_data = sas_device->starget->hostdata;
5325 sas_target_priv_data->deleted = 1;
5326 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5327 sas_target_priv_data->handle =
5328 MPT2SAS_INVALID_DEVICE_HANDLE;
5331 if (!ioc->hide_drives)
5332 mpt2sas_transport_port_remove(ioc,
5333 sas_device->sas_address,
5334 sas_device->sas_address_parent);
5336 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5337 "(0x%016llx)\n", ioc->name, sas_device->handle,
5338 (unsigned long long) sas_device->sas_address);
5340 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5341 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5342 sas_device->handle, (unsigned long long)
5343 sas_device->sas_address));
5347 * _scsih_device_remove_by_handle - removing device object by handle
5348 * @ioc: per adapter object
5349 * @handle: device handle
5354 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5356 struct _sas_device *sas_device;
5357 unsigned long flags;
5359 if (ioc->shost_recovery)
5362 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5363 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5365 list_del(&sas_device->list);
5366 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5368 _scsih_remove_device(ioc, sas_device);
5372 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5373 * @ioc: per adapter object
5374 * @sas_address: device sas_address
5379 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5382 struct _sas_device *sas_device;
5383 unsigned long flags;
5385 if (ioc->shost_recovery)
5388 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5389 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5392 list_del(&sas_device->list);
5393 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5395 _scsih_remove_device(ioc, sas_device);
5397 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5399 * _scsih_sas_topology_change_event_debug - debug for topology event
5400 * @ioc: per adapter object
5401 * @event_data: event data payload
5405 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5406 Mpi2EventDataSasTopologyChangeList_t *event_data)
5412 char *status_str = NULL;
5413 u8 link_rate, prev_link_rate;
5415 switch (event_data->ExpStatus) {
5416 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5419 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5420 status_str = "remove";
5422 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5424 status_str = "responding";
5426 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5427 status_str = "remove delay";
5430 status_str = "unknown status";
5433 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5434 ioc->name, status_str);
5435 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5436 "start_phy(%02d), count(%d)\n",
5437 le16_to_cpu(event_data->ExpanderDevHandle),
5438 le16_to_cpu(event_data->EnclosureHandle),
5439 event_data->StartPhyNum, event_data->NumEntries);
5440 for (i = 0; i < event_data->NumEntries; i++) {
5441 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5444 phy_number = event_data->StartPhyNum + i;
5445 reason_code = event_data->PHY[i].PhyStatus &
5446 MPI2_EVENT_SAS_TOPO_RC_MASK;
5447 switch (reason_code) {
5448 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5449 status_str = "target add";
5451 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5452 status_str = "target remove";
5454 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5455 status_str = "delay target remove";
5457 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5458 status_str = "link rate change";
5460 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5461 status_str = "target responding";
5464 status_str = "unknown";
5467 link_rate = event_data->PHY[i].LinkRate >> 4;
5468 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5469 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5470 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5471 handle, status_str, link_rate, prev_link_rate);
5478 * _scsih_sas_topology_change_event - handle topology changes
5479 * @ioc: per adapter object
5480 * @fw_event: The fw_event_work object
5485 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5486 struct fw_event_work *fw_event)
5489 u16 parent_handle, handle;
5491 u8 phy_number, max_phys;
5492 struct _sas_node *sas_expander;
5494 unsigned long flags;
5495 u8 link_rate, prev_link_rate;
5496 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5498 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5499 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5500 _scsih_sas_topology_change_event_debug(ioc, event_data);
5503 if (ioc->remove_host || ioc->pci_error_recovery)
5506 if (!ioc->sas_hba.num_phys)
5507 _scsih_sas_host_add(ioc);
5509 _scsih_sas_host_refresh(ioc);
5511 if (fw_event->ignore) {
5512 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5513 "event\n", ioc->name));
5517 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5519 /* handle expander add */
5520 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5521 if (_scsih_expander_add(ioc, parent_handle) != 0)
5524 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5525 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5528 sas_address = sas_expander->sas_address;
5529 max_phys = sas_expander->num_phys;
5530 } else if (parent_handle < ioc->sas_hba.num_phys) {
5531 sas_address = ioc->sas_hba.sas_address;
5532 max_phys = ioc->sas_hba.num_phys;
5534 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5537 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5539 /* handle siblings events */
5540 for (i = 0; i < event_data->NumEntries; i++) {
5541 if (fw_event->ignore) {
5542 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5543 "expander event\n", ioc->name));
5546 if (ioc->shost_recovery || ioc->remove_host ||
5547 ioc->pci_error_recovery)
5549 phy_number = event_data->StartPhyNum + i;
5550 if (phy_number >= max_phys)
5552 reason_code = event_data->PHY[i].PhyStatus &
5553 MPI2_EVENT_SAS_TOPO_RC_MASK;
5554 if ((event_data->PHY[i].PhyStatus &
5555 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5556 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5558 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5561 link_rate = event_data->PHY[i].LinkRate >> 4;
5562 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5563 switch (reason_code) {
5564 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5566 if (ioc->shost_recovery)
5569 if (link_rate == prev_link_rate)
5572 mpt2sas_transport_update_links(ioc, sas_address,
5573 handle, phy_number, link_rate);
5575 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5578 _scsih_check_device(ioc, handle);
5580 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5582 if (ioc->shost_recovery)
5585 mpt2sas_transport_update_links(ioc, sas_address,
5586 handle, phy_number, link_rate);
5588 _scsih_add_device(ioc, handle, phy_number, 0);
5590 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5592 _scsih_device_remove_by_handle(ioc, handle);
5597 /* handle expander removal */
5598 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5600 mpt2sas_expander_remove(ioc, sas_address);
5604 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5606 * _scsih_sas_device_status_change_event_debug - debug for device event
5607 * @event_data: event data payload
5613 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5614 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5616 char *reason_str = NULL;
5618 switch (event_data->ReasonCode) {
5619 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5620 reason_str = "smart data";
5622 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5623 reason_str = "unsupported device discovered";
5625 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5626 reason_str = "internal device reset";
5628 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5629 reason_str = "internal task abort";
5631 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5632 reason_str = "internal task abort set";
5634 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5635 reason_str = "internal clear task set";
5637 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5638 reason_str = "internal query task";
5640 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5641 reason_str = "sata init failure";
5643 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5644 reason_str = "internal device reset complete";
5646 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5647 reason_str = "internal task abort complete";
5649 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5650 reason_str = "internal async notification";
5652 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5653 reason_str = "expander reduced functionality";
5655 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5656 reason_str = "expander reduced functionality complete";
5659 reason_str = "unknown reason";
5662 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5663 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5664 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5665 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5666 le16_to_cpu(event_data->TaskTag));
5667 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5668 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5669 event_data->ASC, event_data->ASCQ);
5670 printk(KERN_INFO "\n");
5675 * _scsih_sas_device_status_change_event - handle device status change
5676 * @ioc: per adapter object
5677 * @fw_event: The fw_event_work object
5683 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5684 struct fw_event_work *fw_event)
5686 struct MPT2SAS_TARGET *target_priv_data;
5687 struct _sas_device *sas_device;
5689 unsigned long flags;
5690 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5691 fw_event->event_data;
5693 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5694 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5695 _scsih_sas_device_status_change_event_debug(ioc,
5699 /* In MPI Revision K (0xC), the internal device reset complete was
5700 * implemented, so avoid setting tm_busy flag for older firmware.
5702 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5705 if (event_data->ReasonCode !=
5706 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5707 event_data->ReasonCode !=
5708 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5711 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5712 sas_address = le64_to_cpu(event_data->SASAddress);
5713 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5716 if (!sas_device || !sas_device->starget) {
5717 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5721 target_priv_data = sas_device->starget->hostdata;
5722 if (!target_priv_data) {
5723 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5727 if (event_data->ReasonCode ==
5728 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5729 target_priv_data->tm_busy = 1;
5731 target_priv_data->tm_busy = 0;
5732 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5735 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5737 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5738 * @ioc: per adapter object
5739 * @event_data: event data payload
5745 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5746 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5748 char *reason_str = NULL;
5750 switch (event_data->ReasonCode) {
5751 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5752 reason_str = "enclosure add";
5754 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5755 reason_str = "enclosure remove";
5758 reason_str = "unknown reason";
5762 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5763 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5764 " number slots(%d)\n", ioc->name, reason_str,
5765 le16_to_cpu(event_data->EnclosureHandle),
5766 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5767 le16_to_cpu(event_data->StartSlot));
5772 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5773 * @ioc: per adapter object
5774 * @fw_event: The fw_event_work object
5780 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5781 struct fw_event_work *fw_event)
5783 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5784 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5785 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5786 fw_event->event_data);
5791 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5792 * @ioc: per adapter object
5793 * @fw_event: The fw_event_work object
5799 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5800 struct fw_event_work *fw_event)
5802 struct scsi_cmnd *scmd;
5803 struct scsi_device *sdev;
5806 struct MPT2SAS_DEVICE *sas_device_priv_data;
5807 u32 termination_count;
5809 Mpi2SCSITaskManagementReply_t *mpi_reply;
5810 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5812 unsigned long flags;
5815 u8 task_abort_retries;
5817 mutex_lock(&ioc->tm_cmds.mutex);
5819 "%s: enter: phy number(%d), width(%d)\n",
5820 ioc->name, __func__, event_data->PhyNum,
5821 event_data->PortWidth);
5823 _scsih_block_io_all_device(ioc);
5825 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5826 mpi_reply = ioc->tm_cmds.reply;
5827 broadcast_aen_retry:
5829 /* sanity checks for retrying this loop */
5830 if (max_retries++ == 5) {
5831 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5832 ioc->name, __func__));
5834 } else if (max_retries > 1)
5835 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5836 ioc->name, __func__, max_retries - 1));
5838 termination_count = 0;
5840 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5841 if (ioc->shost_recovery)
5843 scmd = _scsih_scsi_lookup_get(ioc, smid);
5846 sdev = scmd->device;
5847 sas_device_priv_data = sdev->hostdata;
5848 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5850 /* skip hidden raid components */
5851 if (sas_device_priv_data->sas_target->flags &
5852 MPT_TARGET_FLAGS_RAID_COMPONENT)
5855 if (sas_device_priv_data->sas_target->flags &
5856 MPT_TARGET_FLAGS_VOLUME)
5859 handle = sas_device_priv_data->sas_target->handle;
5860 lun = sas_device_priv_data->lun;
5863 if (ioc->shost_recovery)
5866 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5867 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5868 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5871 sdev_printk(KERN_WARNING, sdev,
5872 "mpt2sas_scsih_issue_tm: FAILED when sending "
5873 "QUERY_TASK: scmd(%p)\n", scmd);
5874 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5875 goto broadcast_aen_retry;
5877 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5878 & MPI2_IOCSTATUS_MASK;
5879 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5880 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5881 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5883 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5884 goto broadcast_aen_retry;
5887 /* see if IO is still owned by IOC and target */
5888 if (mpi_reply->ResponseCode ==
5889 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5890 mpi_reply->ResponseCode ==
5891 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5892 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5895 task_abort_retries = 0;
5897 if (task_abort_retries++ == 60) {
5898 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5899 "%s: ABORT_TASK: giving up\n", ioc->name,
5901 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5902 goto broadcast_aen_retry;
5905 if (ioc->shost_recovery)
5908 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5909 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5910 scmd->serial_number, TM_MUTEX_OFF);
5912 sdev_printk(KERN_WARNING, sdev,
5913 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5914 "scmd(%p)\n", scmd);
5918 if (task_abort_retries > 1)
5919 sdev_printk(KERN_WARNING, sdev,
5920 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5922 task_abort_retries - 1, scmd);
5924 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5925 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5928 if (ioc->broadcast_aen_pending) {
5929 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5930 " pending AEN\n", ioc->name, __func__));
5931 ioc->broadcast_aen_pending = 0;
5932 goto broadcast_aen_retry;
5936 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5939 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5940 "%s - exit, query_count = %d termination_count = %d\n",
5941 ioc->name, __func__, query_count, termination_count));
5943 ioc->broadcast_aen_busy = 0;
5944 if (!ioc->shost_recovery)
5945 _scsih_ublock_io_all_device(ioc);
5946 mutex_unlock(&ioc->tm_cmds.mutex);
5950 * _scsih_sas_discovery_event - handle discovery events
5951 * @ioc: per adapter object
5952 * @fw_event: The fw_event_work object
5958 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5959 struct fw_event_work *fw_event)
5961 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5963 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5964 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5965 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5966 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5968 if (event_data->DiscoveryStatus)
5969 printk("discovery_status(0x%08x)",
5970 le32_to_cpu(event_data->DiscoveryStatus));
5975 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5976 !ioc->sas_hba.num_phys) {
5977 if (disable_discovery > 0 && ioc->shost_recovery) {
5978 /* Wait for the reset to complete */
5979 while (ioc->shost_recovery)
5982 _scsih_sas_host_add(ioc);
5987 * _scsih_reprobe_lun - reprobing lun
5988 * @sdev: scsi device struct
5989 * @no_uld_attach: sdev->no_uld_attach flag setting
5993 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5997 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5998 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5999 sdev->no_uld_attach ? "hidding" : "exposing");
6000 rc = scsi_device_reprobe(sdev);
6004 * _scsih_sas_volume_add - add new volume
6005 * @ioc: per adapter object
6006 * @element: IR config element data
6012 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6013 Mpi2EventIrConfigElement_t *element)
6015 struct _raid_device *raid_device;
6016 unsigned long flags;
6018 u16 handle = le16_to_cpu(element->VolDevHandle);
6021 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6023 printk(MPT2SAS_ERR_FMT
6024 "failure at %s:%d/%s()!\n", ioc->name,
6025 __FILE__, __LINE__, __func__);
6029 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6030 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6031 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6036 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6038 printk(MPT2SAS_ERR_FMT
6039 "failure at %s:%d/%s()!\n", ioc->name,
6040 __FILE__, __LINE__, __func__);
6044 raid_device->id = ioc->sas_id++;
6045 raid_device->channel = RAID_CHANNEL;
6046 raid_device->handle = handle;
6047 raid_device->wwid = wwid;
6048 _scsih_raid_device_add(ioc, raid_device);
6049 if (!ioc->wait_for_discovery_to_complete) {
6050 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6051 raid_device->id, 0);
6053 _scsih_raid_device_remove(ioc, raid_device);
6055 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6056 _scsih_determine_boot_device(ioc, raid_device, 1);
6057 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6062 * _scsih_sas_volume_delete - delete volume
6063 * @ioc: per adapter object
6064 * @handle: volume device handle
6070 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6072 struct _raid_device *raid_device;
6073 unsigned long flags;
6074 struct MPT2SAS_TARGET *sas_target_priv_data;
6075 struct scsi_target *starget = NULL;
6077 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6078 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6080 if (raid_device->starget) {
6081 starget = raid_device->starget;
6082 sas_target_priv_data = starget->hostdata;
6083 sas_target_priv_data->deleted = 1;
6085 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6086 "(0x%016llx)\n", ioc->name, raid_device->handle,
6087 (unsigned long long) raid_device->wwid);
6088 list_del(&raid_device->list);
6091 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6093 scsi_remove_target(&starget->dev);
6097 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6098 * @ioc: per adapter object
6099 * @element: IR config element data
6105 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6106 Mpi2EventIrConfigElement_t *element)
6108 struct _sas_device *sas_device;
6109 struct scsi_target *starget = NULL;
6110 struct MPT2SAS_TARGET *sas_target_priv_data;
6111 unsigned long flags;
6112 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6114 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6115 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6117 sas_device->volume_handle = 0;
6118 sas_device->volume_wwid = 0;
6119 clear_bit(handle, ioc->pd_handles);
6120 if (sas_device->starget && sas_device->starget->hostdata) {
6121 starget = sas_device->starget;
6122 sas_target_priv_data = starget->hostdata;
6123 sas_target_priv_data->flags &=
6124 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6127 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6131 /* exposing raid component */
6133 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6137 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6138 * @ioc: per adapter object
6139 * @element: IR config element data
6145 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6146 Mpi2EventIrConfigElement_t *element)
6148 struct _sas_device *sas_device;
6149 struct scsi_target *starget = NULL;
6150 struct MPT2SAS_TARGET *sas_target_priv_data;
6151 unsigned long flags;
6152 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6153 u16 volume_handle = 0;
6154 u64 volume_wwid = 0;
6156 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6158 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6161 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6162 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6164 set_bit(handle, ioc->pd_handles);
6165 if (sas_device->starget && sas_device->starget->hostdata) {
6166 starget = sas_device->starget;
6167 sas_target_priv_data = starget->hostdata;
6168 sas_target_priv_data->flags |=
6169 MPT_TARGET_FLAGS_RAID_COMPONENT;
6170 sas_device->volume_handle = volume_handle;
6171 sas_device->volume_wwid = volume_wwid;
6174 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6178 /* hiding raid component */
6180 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6184 * _scsih_sas_pd_delete - delete pd component
6185 * @ioc: per adapter object
6186 * @element: IR config element data
6192 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6193 Mpi2EventIrConfigElement_t *element)
6195 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6197 _scsih_device_remove_by_handle(ioc, handle);
6201 * _scsih_sas_pd_add - remove pd component
6202 * @ioc: per adapter object
6203 * @element: IR config element data
6209 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6210 Mpi2EventIrConfigElement_t *element)
6212 struct _sas_device *sas_device;
6213 unsigned long flags;
6214 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6215 Mpi2ConfigReply_t mpi_reply;
6216 Mpi2SasDevicePage0_t sas_device_pg0;
6221 set_bit(handle, ioc->pd_handles);
6223 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6224 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6225 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6229 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6230 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6231 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6232 ioc->name, __FILE__, __LINE__, __func__);
6236 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6237 MPI2_IOCSTATUS_MASK;
6238 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6239 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6240 ioc->name, __FILE__, __LINE__, __func__);
6244 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6245 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6246 mpt2sas_transport_update_links(ioc, sas_address, handle,
6247 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6249 _scsih_add_device(ioc, handle, 0, 1);
6252 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6254 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6255 * @ioc: per adapter object
6256 * @event_data: event data payload
6262 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6263 Mpi2EventDataIrConfigChangeList_t *event_data)
6265 Mpi2EventIrConfigElement_t *element;
6268 char *reason_str = NULL, *element_str = NULL;
6270 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6272 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6273 ioc->name, (le32_to_cpu(event_data->Flags) &
6274 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6275 "foreign" : "native", event_data->NumElements);
6276 for (i = 0; i < event_data->NumElements; i++, element++) {
6277 switch (element->ReasonCode) {
6278 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6281 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6282 reason_str = "remove";
6284 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6285 reason_str = "no change";
6287 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6288 reason_str = "hide";
6290 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6291 reason_str = "unhide";
6293 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6294 reason_str = "volume_created";
6296 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6297 reason_str = "volume_deleted";
6299 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6300 reason_str = "pd_created";
6302 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6303 reason_str = "pd_deleted";
6306 reason_str = "unknown reason";
6309 element_type = le16_to_cpu(element->ElementFlags) &
6310 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6311 switch (element_type) {
6312 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6313 element_str = "volume";
6315 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6316 element_str = "phys disk";
6318 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6319 element_str = "hot spare";
6322 element_str = "unknown element";
6325 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6326 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6327 reason_str, le16_to_cpu(element->VolDevHandle),
6328 le16_to_cpu(element->PhysDiskDevHandle),
6329 element->PhysDiskNum);
6335 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6336 * @ioc: per adapter object
6337 * @fw_event: The fw_event_work object
6343 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6344 struct fw_event_work *fw_event)
6346 Mpi2EventIrConfigElement_t *element;
6349 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6351 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6352 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6353 && !ioc->hide_ir_msg)
6354 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6358 if (ioc->shost_recovery)
6361 foreign_config = (le32_to_cpu(event_data->Flags) &
6362 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6364 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6365 for (i = 0; i < event_data->NumElements; i++, element++) {
6367 switch (element->ReasonCode) {
6368 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6369 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6370 if (!foreign_config)
6371 _scsih_sas_volume_add(ioc, element);
6373 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6374 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6375 if (!foreign_config)
6376 _scsih_sas_volume_delete(ioc,
6377 le16_to_cpu(element->VolDevHandle));
6379 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6380 if (!ioc->is_warpdrive)
6381 _scsih_sas_pd_hide(ioc, element);
6383 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6384 if (!ioc->is_warpdrive)
6385 _scsih_sas_pd_expose(ioc, element);
6387 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6388 if (!ioc->is_warpdrive)
6389 _scsih_sas_pd_add(ioc, element);
6391 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6392 if (!ioc->is_warpdrive)
6393 _scsih_sas_pd_delete(ioc, element);
6400 * _scsih_sas_ir_volume_event - IR volume event
6401 * @ioc: per adapter object
6402 * @fw_event: The fw_event_work object
6408 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6409 struct fw_event_work *fw_event)
6412 unsigned long flags;
6413 struct _raid_device *raid_device;
6417 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6419 if (ioc->shost_recovery)
6422 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6425 handle = le16_to_cpu(event_data->VolDevHandle);
6426 state = le32_to_cpu(event_data->NewValue);
6427 if (!ioc->hide_ir_msg)
6428 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6429 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6430 le32_to_cpu(event_data->PreviousValue), state));
6433 case MPI2_RAID_VOL_STATE_MISSING:
6434 case MPI2_RAID_VOL_STATE_FAILED:
6435 _scsih_sas_volume_delete(ioc, handle);
6438 case MPI2_RAID_VOL_STATE_ONLINE:
6439 case MPI2_RAID_VOL_STATE_DEGRADED:
6440 case MPI2_RAID_VOL_STATE_OPTIMAL:
6442 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6443 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6444 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6449 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6451 printk(MPT2SAS_ERR_FMT
6452 "failure at %s:%d/%s()!\n", ioc->name,
6453 __FILE__, __LINE__, __func__);
6457 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6459 printk(MPT2SAS_ERR_FMT
6460 "failure at %s:%d/%s()!\n", ioc->name,
6461 __FILE__, __LINE__, __func__);
6465 raid_device->id = ioc->sas_id++;
6466 raid_device->channel = RAID_CHANNEL;
6467 raid_device->handle = handle;
6468 raid_device->wwid = wwid;
6469 _scsih_raid_device_add(ioc, raid_device);
6470 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6471 raid_device->id, 0);
6473 _scsih_raid_device_remove(ioc, raid_device);
6476 case MPI2_RAID_VOL_STATE_INITIALIZING:
6483 * _scsih_sas_ir_physical_disk_event - PD event
6484 * @ioc: per adapter object
6485 * @fw_event: The fw_event_work object
6491 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6492 struct fw_event_work *fw_event)
6494 u16 handle, parent_handle;
6496 struct _sas_device *sas_device;
6497 unsigned long flags;
6498 Mpi2ConfigReply_t mpi_reply;
6499 Mpi2SasDevicePage0_t sas_device_pg0;
6501 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6504 if (ioc->shost_recovery)
6507 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6510 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6511 state = le32_to_cpu(event_data->NewValue);
6513 if (!ioc->hide_ir_msg)
6514 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6515 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6516 le32_to_cpu(event_data->PreviousValue), state));
6519 case MPI2_RAID_PD_STATE_ONLINE:
6520 case MPI2_RAID_PD_STATE_DEGRADED:
6521 case MPI2_RAID_PD_STATE_REBUILDING:
6522 case MPI2_RAID_PD_STATE_OPTIMAL:
6523 case MPI2_RAID_PD_STATE_HOT_SPARE:
6525 if (!ioc->is_warpdrive)
6526 set_bit(handle, ioc->pd_handles);
6528 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6529 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6530 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6535 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6536 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6538 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6539 ioc->name, __FILE__, __LINE__, __func__);
6543 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6544 MPI2_IOCSTATUS_MASK;
6545 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6546 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6547 ioc->name, __FILE__, __LINE__, __func__);
6551 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6552 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6553 mpt2sas_transport_update_links(ioc, sas_address, handle,
6554 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6556 _scsih_add_device(ioc, handle, 0, 1);
6560 case MPI2_RAID_PD_STATE_OFFLINE:
6561 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6562 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6568 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6570 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6571 * @ioc: per adapter object
6572 * @event_data: event data payload
6578 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6579 Mpi2EventDataIrOperationStatus_t *event_data)
6581 char *reason_str = NULL;
6583 switch (event_data->RAIDOperation) {
6584 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6585 reason_str = "resync";
6587 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6588 reason_str = "online capacity expansion";
6590 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6591 reason_str = "consistency check";
6593 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6594 reason_str = "background init";
6596 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6597 reason_str = "make data consistent";
6604 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6605 "\thandle(0x%04x), percent complete(%d)\n",
6606 ioc->name, reason_str,
6607 le16_to_cpu(event_data->VolDevHandle),
6608 event_data->PercentComplete);
6613 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6614 * @ioc: per adapter object
6615 * @fw_event: The fw_event_work object
6621 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6622 struct fw_event_work *fw_event)
6624 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6625 static struct _raid_device *raid_device;
6626 unsigned long flags;
6629 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6630 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6631 && !ioc->hide_ir_msg)
6632 _scsih_sas_ir_operation_status_event_debug(ioc,
6636 /* code added for raid transport support */
6637 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6639 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6640 handle = le16_to_cpu(event_data->VolDevHandle);
6641 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6643 raid_device->percent_complete =
6644 event_data->PercentComplete;
6645 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6650 * _scsih_prep_device_scan - initialize parameters prior to device scan
6651 * @ioc: per adapter object
6653 * Set the deleted flag prior to device scan. If the device is found during
6654 * the scan, then we clear the deleted flag.
6657 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6659 struct MPT2SAS_DEVICE *sas_device_priv_data;
6660 struct scsi_device *sdev;
6662 shost_for_each_device(sdev, ioc->shost) {
6663 sas_device_priv_data = sdev->hostdata;
6664 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6665 sas_device_priv_data->sas_target->deleted = 1;
6670 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6671 * @ioc: per adapter object
6672 * @sas_address: sas address
6673 * @slot: enclosure slot id
6674 * @handle: device handle
6676 * After host reset, find out whether devices are still responding.
6677 * Used in _scsi_remove_unresponsive_sas_devices.
6682 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6683 u16 slot, u16 handle)
6685 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6686 struct scsi_target *starget;
6687 struct _sas_device *sas_device;
6688 unsigned long flags;
6690 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6691 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6692 if (sas_device->sas_address == sas_address &&
6693 sas_device->slot == slot) {
6694 sas_device->responding = 1;
6695 starget = sas_device->starget;
6696 if (starget && starget->hostdata) {
6697 sas_target_priv_data = starget->hostdata;
6698 sas_target_priv_data->tm_busy = 0;
6699 sas_target_priv_data->deleted = 0;
6701 sas_target_priv_data = NULL;
6703 starget_printk(KERN_INFO, starget,
6704 "handle(0x%04x), sas_addr(0x%016llx), "
6705 "enclosure logical id(0x%016llx), "
6706 "slot(%d)\n", handle,
6707 (unsigned long long)sas_device->sas_address,
6708 (unsigned long long)
6709 sas_device->enclosure_logical_id,
6711 if (sas_device->handle == handle)
6713 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6714 sas_device->handle);
6715 sas_device->handle = handle;
6716 if (sas_target_priv_data)
6717 sas_target_priv_data->handle = handle;
6722 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6726 * _scsih_search_responding_sas_devices -
6727 * @ioc: per adapter object
6729 * After host reset, find out whether devices are still responding.
6735 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6737 Mpi2SasDevicePage0_t sas_device_pg0;
6738 Mpi2ConfigReply_t mpi_reply;
6745 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6747 if (list_empty(&ioc->sas_device_list))
6751 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6752 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6755 MPI2_IOCSTATUS_MASK;
6756 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6758 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6759 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6760 if (!(_scsih_is_end_device(device_info)))
6762 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6763 slot = le16_to_cpu(sas_device_pg0.Slot);
6764 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6768 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6773 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6774 * @ioc: per adapter object
6775 * @wwid: world wide identifier for raid volume
6776 * @handle: device handle
6778 * After host reset, find out whether devices are still responding.
6779 * Used in _scsi_remove_unresponsive_raid_devices.
6784 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6787 struct MPT2SAS_TARGET *sas_target_priv_data;
6788 struct scsi_target *starget;
6789 struct _raid_device *raid_device;
6790 unsigned long flags;
6792 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6793 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6794 if (raid_device->wwid == wwid && raid_device->starget) {
6795 starget = raid_device->starget;
6796 if (starget && starget->hostdata) {
6797 sas_target_priv_data = starget->hostdata;
6798 sas_target_priv_data->deleted = 0;
6800 sas_target_priv_data = NULL;
6801 raid_device->responding = 1;
6802 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6803 starget_printk(KERN_INFO, raid_device->starget,
6804 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6805 (unsigned long long)raid_device->wwid);
6807 * WARPDRIVE: The handles of the PDs might have changed
6808 * across the host reset so re-initialize the
6809 * required data for Direct IO
6811 _scsih_init_warpdrive_properties(ioc, raid_device);
6812 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6813 if (raid_device->handle == handle) {
6814 spin_unlock_irqrestore(&ioc->raid_device_lock,
6818 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6819 raid_device->handle);
6820 raid_device->handle = handle;
6821 if (sas_target_priv_data)
6822 sas_target_priv_data->handle = handle;
6823 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6828 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6832 * _scsih_search_responding_raid_devices -
6833 * @ioc: per adapter object
6835 * After host reset, find out whether devices are still responding.
6841 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6843 Mpi2RaidVolPage1_t volume_pg1;
6844 Mpi2RaidVolPage0_t volume_pg0;
6845 Mpi2RaidPhysDiskPage0_t pd_pg0;
6846 Mpi2ConfigReply_t mpi_reply;
6851 if (!ioc->ir_firmware)
6854 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6857 if (list_empty(&ioc->raid_device_list))
6861 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6862 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6863 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6864 MPI2_IOCSTATUS_MASK;
6865 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6867 handle = le16_to_cpu(volume_pg1.DevHandle);
6869 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6870 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6871 sizeof(Mpi2RaidVolPage0_t)))
6874 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6875 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6876 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6877 _scsih_mark_responding_raid_device(ioc,
6878 le64_to_cpu(volume_pg1.WWID), handle);
6881 /* refresh the pd_handles */
6882 if (!ioc->is_warpdrive) {
6883 phys_disk_num = 0xFF;
6884 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6885 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6886 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6888 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6889 MPI2_IOCSTATUS_MASK;
6890 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6892 phys_disk_num = pd_pg0.PhysDiskNum;
6893 handle = le16_to_cpu(pd_pg0.DevHandle);
6894 set_bit(handle, ioc->pd_handles);
6898 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6899 "complete\n", ioc->name);
6903 * _scsih_mark_responding_expander - mark a expander as responding
6904 * @ioc: per adapter object
6905 * @sas_address: sas address
6908 * After host reset, find out whether devices are still responding.
6909 * Used in _scsi_remove_unresponsive_expanders.
6914 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6917 struct _sas_node *sas_expander;
6918 unsigned long flags;
6921 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6922 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6923 if (sas_expander->sas_address != sas_address)
6925 sas_expander->responding = 1;
6926 if (sas_expander->handle == handle)
6928 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6929 " from(0x%04x) to (0x%04x)!!!\n",
6930 (unsigned long long)sas_expander->sas_address,
6931 sas_expander->handle, handle);
6932 sas_expander->handle = handle;
6933 for (i = 0 ; i < sas_expander->num_phys ; i++)
6934 sas_expander->phy[i].handle = handle;
6938 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6942 * _scsih_search_responding_expanders -
6943 * @ioc: per adapter object
6945 * After host reset, find out whether devices are still responding.
6951 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6953 Mpi2ExpanderPage0_t expander_pg0;
6954 Mpi2ConfigReply_t mpi_reply;
6959 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6961 if (list_empty(&ioc->sas_expander_list))
6965 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6966 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6968 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6969 MPI2_IOCSTATUS_MASK;
6970 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6973 handle = le16_to_cpu(expander_pg0.DevHandle);
6974 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6975 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6976 "sas_addr(0x%016llx)\n", handle,
6977 (unsigned long long)sas_address);
6978 _scsih_mark_responding_expander(ioc, sas_address, handle);
6982 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6986 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6987 * @ioc: per adapter object
6992 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6994 struct _sas_device *sas_device, *sas_device_next;
6995 struct _sas_node *sas_expander, *sas_expander_next;
6996 struct _raid_device *raid_device, *raid_device_next;
6997 struct list_head tmp_list;
6998 unsigned long flags;
7000 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7003 /* removing unresponding end devices */
7004 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7006 list_for_each_entry_safe(sas_device, sas_device_next,
7007 &ioc->sas_device_list, list) {
7008 if (!sas_device->responding)
7009 mpt2sas_device_remove_by_sas_address(ioc,
7010 sas_device->sas_address);
7012 sas_device->responding = 0;
7015 /* removing unresponding volumes */
7016 if (ioc->ir_firmware) {
7017 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7018 "volumes\n", ioc->name);
7019 list_for_each_entry_safe(raid_device, raid_device_next,
7020 &ioc->raid_device_list, list) {
7021 if (!raid_device->responding)
7022 _scsih_sas_volume_delete(ioc,
7023 raid_device->handle);
7025 raid_device->responding = 0;
7028 /* removing unresponding expanders */
7029 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7031 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7032 INIT_LIST_HEAD(&tmp_list);
7033 list_for_each_entry_safe(sas_expander, sas_expander_next,
7034 &ioc->sas_expander_list, list) {
7035 if (!sas_expander->responding)
7036 list_move_tail(&sas_expander->list, &tmp_list);
7038 sas_expander->responding = 0;
7040 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7041 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7043 list_del(&sas_expander->list);
7044 _scsih_expander_node_remove(ioc, sas_expander);
7046 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7048 /* unblock devices */
7049 _scsih_ublock_io_all_device(ioc);
7053 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7054 struct _sas_node *sas_expander, u16 handle)
7056 Mpi2ExpanderPage1_t expander_pg1;
7057 Mpi2ConfigReply_t mpi_reply;
7060 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7061 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7062 &expander_pg1, i, handle))) {
7063 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7064 ioc->name, __FILE__, __LINE__, __func__);
7068 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7069 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7070 expander_pg1.NegotiatedLinkRate >> 4);
7075 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7076 * @ioc: per adapter object
7081 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7083 Mpi2ExpanderPage0_t expander_pg0;
7084 Mpi2SasDevicePage0_t sas_device_pg0;
7085 Mpi2RaidVolPage1_t volume_pg1;
7086 Mpi2RaidVolPage0_t volume_pg0;
7087 Mpi2RaidPhysDiskPage0_t pd_pg0;
7088 Mpi2EventIrConfigElement_t element;
7089 Mpi2ConfigReply_t mpi_reply;
7092 u16 handle, parent_handle;
7094 struct _sas_device *sas_device;
7095 struct _sas_node *expander_device;
7096 static struct _raid_device *raid_device;
7098 unsigned long flags;
7100 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7102 _scsih_sas_host_refresh(ioc);
7104 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7108 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7109 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7110 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7111 MPI2_IOCSTATUS_MASK;
7112 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7114 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7115 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7116 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7117 ioc->name, ioc_status,
7118 le32_to_cpu(mpi_reply.IOCLogInfo));
7121 handle = le16_to_cpu(expander_pg0.DevHandle);
7122 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7123 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7124 ioc, le64_to_cpu(expander_pg0.SASAddress));
7125 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7126 if (expander_device)
7127 _scsih_refresh_expander_links(ioc, expander_device,
7130 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7131 "handle (0x%04x), sas_addr(0x%016llx)\n",
7132 ioc->name, handle, (unsigned long long)
7133 le64_to_cpu(expander_pg0.SASAddress));
7134 _scsih_expander_add(ioc, handle);
7135 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7136 "handle (0x%04x), sas_addr(0x%016llx)\n",
7137 ioc->name, handle, (unsigned long long)
7138 le64_to_cpu(expander_pg0.SASAddress));
7142 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7145 if (!ioc->ir_firmware)
7148 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7150 phys_disk_num = 0xFF;
7151 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7152 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7154 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7155 MPI2_IOCSTATUS_MASK;
7156 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7158 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7159 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7160 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7161 ioc->name, ioc_status,
7162 le32_to_cpu(mpi_reply.IOCLogInfo));
7165 phys_disk_num = pd_pg0.PhysDiskNum;
7166 handle = le16_to_cpu(pd_pg0.DevHandle);
7167 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7168 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7169 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7172 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7173 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7176 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7177 MPI2_IOCSTATUS_MASK;
7178 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7179 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7180 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7181 ioc->name, ioc_status,
7182 le32_to_cpu(mpi_reply.IOCLogInfo));
7185 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7186 if (!_scsih_get_sas_address(ioc, parent_handle,
7188 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7189 " handle (0x%04x), sas_addr(0x%016llx)\n",
7190 ioc->name, handle, (unsigned long long)
7191 le64_to_cpu(sas_device_pg0.SASAddress));
7192 mpt2sas_transport_update_links(ioc, sas_address,
7193 handle, sas_device_pg0.PhyNum,
7194 MPI2_SAS_NEG_LINK_RATE_1_5);
7195 set_bit(handle, ioc->pd_handles);
7197 /* This will retry adding the end device.
7198 * _scsih_add_device() will decide on retries and
7199 * return "1" when it should be retried
7201 while (_scsih_add_device(ioc, handle, retry_count++,
7205 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7206 " handle (0x%04x), sas_addr(0x%016llx)\n",
7207 ioc->name, handle, (unsigned long long)
7208 le64_to_cpu(sas_device_pg0.SASAddress));
7212 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7215 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7218 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7219 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7221 MPI2_IOCSTATUS_MASK;
7222 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7224 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7225 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7226 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7227 ioc->name, ioc_status,
7228 le32_to_cpu(mpi_reply.IOCLogInfo));
7231 handle = le16_to_cpu(volume_pg1.DevHandle);
7232 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7233 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7234 le64_to_cpu(volume_pg1.WWID));
7235 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7238 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7239 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7240 sizeof(Mpi2RaidVolPage0_t)))
7242 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7243 MPI2_IOCSTATUS_MASK;
7244 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7245 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7246 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7247 ioc->name, ioc_status,
7248 le32_to_cpu(mpi_reply.IOCLogInfo));
7251 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7252 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7253 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7254 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7255 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7256 element.VolDevHandle = volume_pg1.DevHandle;
7257 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7258 " handle (0x%04x)\n", ioc->name,
7259 volume_pg1.DevHandle);
7260 _scsih_sas_volume_add(ioc, &element);
7261 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7262 " handle (0x%04x)\n", ioc->name,
7263 volume_pg1.DevHandle);
7267 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7272 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7276 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7277 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7279 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7280 MPI2_IOCSTATUS_MASK;
7281 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7283 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7284 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7285 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7286 ioc->name, ioc_status,
7287 le32_to_cpu(mpi_reply.IOCLogInfo));
7290 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7291 if (!(_scsih_is_end_device(
7292 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7294 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7295 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7296 le64_to_cpu(sas_device_pg0.SASAddress));
7297 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7300 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7301 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7302 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7303 "handle (0x%04x), sas_addr(0x%016llx)\n",
7304 ioc->name, handle, (unsigned long long)
7305 le64_to_cpu(sas_device_pg0.SASAddress));
7306 mpt2sas_transport_update_links(ioc, sas_address, handle,
7307 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7309 /* This will retry adding the end device.
7310 * _scsih_add_device() will decide on retries and
7311 * return "1" when it should be retried
7313 while (_scsih_add_device(ioc, handle, retry_count++,
7317 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7318 "handle (0x%04x), sas_addr(0x%016llx)\n",
7319 ioc->name, handle, (unsigned long long)
7320 le64_to_cpu(sas_device_pg0.SASAddress));
7324 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7327 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7332 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7333 * @ioc: per adapter object
7334 * @reset_phase: phase
7336 * The handler for doing any required cleanup or initialization.
7338 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7339 * MPT2_IOC_DONE_RESET
7344 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7346 switch (reset_phase) {
7347 case MPT2_IOC_PRE_RESET:
7348 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7349 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7351 case MPT2_IOC_AFTER_RESET:
7352 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7353 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7354 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7355 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7356 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7357 complete(&ioc->scsih_cmds.done);
7359 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7360 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7361 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7362 complete(&ioc->tm_cmds.done);
7364 _scsih_fw_event_cleanup_queue(ioc);
7365 _scsih_flush_running_cmds(ioc);
7367 case MPT2_IOC_DONE_RESET:
7368 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7369 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7370 _scsih_sas_host_refresh(ioc);
7371 _scsih_prep_device_scan(ioc);
7372 _scsih_search_responding_sas_devices(ioc);
7373 _scsih_search_responding_raid_devices(ioc);
7374 _scsih_search_responding_expanders(ioc);
7375 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7376 !ioc->sas_hba.num_phys)) {
7377 _scsih_prep_device_scan(ioc);
7378 _scsih_search_responding_sas_devices(ioc);
7379 _scsih_search_responding_raid_devices(ioc);
7380 _scsih_search_responding_expanders(ioc);
7381 _scsih_error_recovery_delete_devices(ioc);
7388 * _firmware_event_work - delayed task for processing firmware events
7389 * @ioc: per adapter object
7390 * @work: equal to the fw_event_work object
7396 _firmware_event_work(struct work_struct *work)
7398 struct fw_event_work *fw_event = container_of(work,
7399 struct fw_event_work, delayed_work.work);
7400 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7402 /* the queue is being flushed so ignore this event */
7403 if (ioc->remove_host || fw_event->cancel_pending_work ||
7404 ioc->pci_error_recovery) {
7405 _scsih_fw_event_free(ioc, fw_event);
7409 switch (fw_event->event) {
7410 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7411 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7413 _scsih_remove_unresponding_sas_devices(ioc);
7414 _scsih_scan_for_devices_after_reset(ioc);
7416 case MPT2SAS_PORT_ENABLE_COMPLETE:
7417 ioc->start_scan = 0;
7419 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7420 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7423 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7424 "from worker thread\n", ioc->name));
7426 case MPT2SAS_TURN_ON_FAULT_LED:
7427 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7429 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7430 _scsih_sas_topology_change_event(ioc, fw_event);
7432 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7433 _scsih_sas_device_status_change_event(ioc,
7436 case MPI2_EVENT_SAS_DISCOVERY:
7437 _scsih_sas_discovery_event(ioc,
7440 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7441 _scsih_sas_broadcast_primitive_event(ioc,
7444 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7445 _scsih_sas_enclosure_dev_status_change_event(ioc,
7448 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7449 _scsih_sas_ir_config_change_event(ioc, fw_event);
7451 case MPI2_EVENT_IR_VOLUME:
7452 _scsih_sas_ir_volume_event(ioc, fw_event);
7454 case MPI2_EVENT_IR_PHYSICAL_DISK:
7455 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7457 case MPI2_EVENT_IR_OPERATION_STATUS:
7458 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7461 _scsih_fw_event_free(ioc, fw_event);
7465 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7466 * @ioc: per adapter object
7467 * @msix_index: MSIX table index supplied by the OS
7468 * @reply: reply message frame(lower 32bit addr)
7469 * Context: interrupt.
7471 * This function merely adds a new work task into ioc->firmware_event_thread.
7472 * The tasks are worked from _firmware_event_work in user context.
7474 * Return 1 meaning mf should be freed from _base_interrupt
7475 * 0 means the mf is freed from this function.
7478 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7481 struct fw_event_work *fw_event;
7482 Mpi2EventNotificationReply_t *mpi_reply;
7486 /* events turned off due to host reset or driver unloading */
7487 if (ioc->remove_host || ioc->pci_error_recovery)
7490 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7492 if (unlikely(!mpi_reply)) {
7493 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7494 ioc->name, __FILE__, __LINE__, __func__);
7498 event = le16_to_cpu(mpi_reply->Event);
7502 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7504 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7505 (Mpi2EventDataSasBroadcastPrimitive_t *)
7506 mpi_reply->EventData;
7508 if (baen_data->Primitive !=
7509 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7512 if (ioc->broadcast_aen_busy) {
7513 ioc->broadcast_aen_pending++;
7516 ioc->broadcast_aen_busy = 1;
7520 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7521 _scsih_check_topo_delete_events(ioc,
7522 (Mpi2EventDataSasTopologyChangeList_t *)
7523 mpi_reply->EventData);
7525 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7526 _scsih_check_ir_config_unhide_events(ioc,
7527 (Mpi2EventDataIrConfigChangeList_t *)
7528 mpi_reply->EventData);
7530 case MPI2_EVENT_IR_VOLUME:
7531 _scsih_check_volume_delete_events(ioc,
7532 (Mpi2EventDataIrVolume_t *)
7533 mpi_reply->EventData);
7535 case MPI2_EVENT_LOG_ENTRY_ADDED:
7537 Mpi2EventDataLogEntryAdded_t *log_entry;
7540 if (!ioc->is_warpdrive)
7543 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7544 mpi_reply->EventData;
7545 log_code = (__le32 *)log_entry->LogData;
7547 if (le16_to_cpu(log_entry->LogEntryQualifier)
7548 != MPT2_WARPDRIVE_LOGENTRY)
7551 switch (le32_to_cpu(*log_code)) {
7552 case MPT2_WARPDRIVE_LC_SSDT:
7553 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7554 "IO Throttling has occurred in the WarpDrive "
7555 "subsystem. Check WarpDrive documentation for "
7556 "additional details.\n", ioc->name);
7558 case MPT2_WARPDRIVE_LC_SSDLW:
7559 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7560 "Program/Erase Cycles for the WarpDrive subsystem "
7561 "in degraded range. Check WarpDrive documentation "
7562 "for additional details.\n", ioc->name);
7564 case MPT2_WARPDRIVE_LC_SSDLF:
7565 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7566 "There are no Program/Erase Cycles for the "
7567 "WarpDrive subsystem. The storage device will be "
7568 "in read-only mode. Check WarpDrive documentation "
7569 "for additional details.\n", ioc->name);
7571 case MPT2_WARPDRIVE_LC_BRMF:
7572 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7573 "The Backup Rail Monitor has failed on the "
7574 "WarpDrive subsystem. Check WarpDrive "
7575 "documentation for additional details.\n",
7582 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7583 case MPI2_EVENT_IR_OPERATION_STATUS:
7584 case MPI2_EVENT_SAS_DISCOVERY:
7585 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7586 case MPI2_EVENT_IR_PHYSICAL_DISK:
7589 default: /* ignore the rest */
7593 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7595 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7596 ioc->name, __FILE__, __LINE__, __func__);
7599 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7600 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7601 if (!fw_event->event_data) {
7602 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7603 ioc->name, __FILE__, __LINE__, __func__);
7608 memcpy(fw_event->event_data, mpi_reply->EventData,
7610 fw_event->ioc = ioc;
7611 fw_event->VF_ID = mpi_reply->VF_ID;
7612 fw_event->VP_ID = mpi_reply->VP_ID;
7613 fw_event->event = event;
7614 _scsih_fw_event_add(ioc, fw_event);
7618 /* shost template */
7619 static struct scsi_host_template scsih_driver_template = {
7620 .module = THIS_MODULE,
7621 .name = "Fusion MPT SAS Host",
7622 .proc_name = MPT2SAS_DRIVER_NAME,
7623 .queuecommand = _scsih_qcmd,
7624 .target_alloc = _scsih_target_alloc,
7625 .slave_alloc = _scsih_slave_alloc,
7626 .slave_configure = _scsih_slave_configure,
7627 .target_destroy = _scsih_target_destroy,
7628 .slave_destroy = _scsih_slave_destroy,
7629 .scan_finished = _scsih_scan_finished,
7630 .scan_start = _scsih_scan_start,
7631 .change_queue_depth = _scsih_change_queue_depth,
7632 .change_queue_type = _scsih_change_queue_type,
7633 .eh_abort_handler = _scsih_abort,
7634 .eh_device_reset_handler = _scsih_dev_reset,
7635 .eh_target_reset_handler = _scsih_target_reset,
7636 .eh_host_reset_handler = _scsih_host_reset,
7637 .bios_param = _scsih_bios_param,
7640 .sg_tablesize = MPT2SAS_SG_DEPTH,
7641 .max_sectors = 32767,
7643 .use_clustering = ENABLE_CLUSTERING,
7644 .shost_attrs = mpt2sas_host_attrs,
7645 .sdev_attrs = mpt2sas_dev_attrs,
7649 * _scsih_expander_node_remove - removing expander device from list.
7650 * @ioc: per adapter object
7651 * @sas_expander: the sas_device object
7652 * Context: Calling function should acquire ioc->sas_node_lock.
7654 * Removing object and freeing associated memory from the
7655 * ioc->sas_expander_list.
7660 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7661 struct _sas_node *sas_expander)
7663 struct _sas_port *mpt2sas_port, *next;
7665 /* remove sibling ports attached to this expander */
7666 list_for_each_entry_safe(mpt2sas_port, next,
7667 &sas_expander->sas_port_list, port_list) {
7668 if (ioc->shost_recovery)
7670 if (mpt2sas_port->remote_identify.device_type ==
7672 mpt2sas_device_remove_by_sas_address(ioc,
7673 mpt2sas_port->remote_identify.sas_address);
7674 else if (mpt2sas_port->remote_identify.device_type ==
7675 SAS_EDGE_EXPANDER_DEVICE ||
7676 mpt2sas_port->remote_identify.device_type ==
7677 SAS_FANOUT_EXPANDER_DEVICE)
7678 mpt2sas_expander_remove(ioc,
7679 mpt2sas_port->remote_identify.sas_address);
7682 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7683 sas_expander->sas_address_parent);
7685 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7686 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7687 sas_expander->handle, (unsigned long long)
7688 sas_expander->sas_address);
7690 kfree(sas_expander->phy);
7691 kfree(sas_expander);
7695 * _scsih_ir_shutdown - IR shutdown notification
7696 * @ioc: per adapter object
7698 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7699 * the host system is shutting down.
7704 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7706 Mpi2RaidActionRequest_t *mpi_request;
7707 Mpi2RaidActionReply_t *mpi_reply;
7710 /* is IR firmware build loaded ? */
7711 if (!ioc->ir_firmware)
7714 /* are there any volumes ? */
7715 if (list_empty(&ioc->raid_device_list))
7718 mutex_lock(&ioc->scsih_cmds.mutex);
7720 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7721 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7722 ioc->name, __func__);
7725 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7727 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7729 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7730 ioc->name, __func__);
7731 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7735 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7736 ioc->scsih_cmds.smid = smid;
7737 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7739 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7740 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7742 if (!ioc->hide_ir_msg)
7743 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7744 init_completion(&ioc->scsih_cmds.done);
7745 mpt2sas_base_put_smid_default(ioc, smid);
7746 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7748 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7749 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7750 ioc->name, __func__);
7754 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7755 mpi_reply = ioc->scsih_cmds.reply;
7757 if (!ioc->hide_ir_msg)
7758 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7759 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7760 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7761 le32_to_cpu(mpi_reply->IOCLogInfo));
7765 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7766 mutex_unlock(&ioc->scsih_cmds.mutex);
7770 * _scsih_shutdown - routine call during system shutdown
7771 * @pdev: PCI device struct
7776 _scsih_shutdown(struct pci_dev *pdev)
7778 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7779 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7780 struct workqueue_struct *wq;
7781 unsigned long flags;
7783 ioc->remove_host = 1;
7784 _scsih_fw_event_cleanup_queue(ioc);
7786 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7787 wq = ioc->firmware_event_thread;
7788 ioc->firmware_event_thread = NULL;
7789 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7791 destroy_workqueue(wq);
7793 _scsih_ir_shutdown(ioc);
7794 mpt2sas_base_detach(ioc);
7798 * _scsih_remove - detach and remove add host
7799 * @pdev: PCI device struct
7801 * Routine called when unloading the driver.
7805 _scsih_remove(struct pci_dev *pdev)
7807 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7808 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7809 struct _sas_port *mpt2sas_port, *next_port;
7810 struct _raid_device *raid_device, *next;
7811 struct MPT2SAS_TARGET *sas_target_priv_data;
7812 struct workqueue_struct *wq;
7813 unsigned long flags;
7815 ioc->remove_host = 1;
7816 _scsih_fw_event_cleanup_queue(ioc);
7818 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7819 wq = ioc->firmware_event_thread;
7820 ioc->firmware_event_thread = NULL;
7821 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7823 destroy_workqueue(wq);
7825 /* release all the volumes */
7826 _scsih_ir_shutdown(ioc);
7827 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7829 if (raid_device->starget) {
7830 sas_target_priv_data =
7831 raid_device->starget->hostdata;
7832 sas_target_priv_data->deleted = 1;
7833 scsi_remove_target(&raid_device->starget->dev);
7835 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7836 "(0x%016llx)\n", ioc->name, raid_device->handle,
7837 (unsigned long long) raid_device->wwid);
7838 _scsih_raid_device_remove(ioc, raid_device);
7841 /* free ports attached to the sas_host */
7842 list_for_each_entry_safe(mpt2sas_port, next_port,
7843 &ioc->sas_hba.sas_port_list, port_list) {
7844 if (mpt2sas_port->remote_identify.device_type ==
7846 mpt2sas_device_remove_by_sas_address(ioc,
7847 mpt2sas_port->remote_identify.sas_address);
7848 else if (mpt2sas_port->remote_identify.device_type ==
7849 SAS_EDGE_EXPANDER_DEVICE ||
7850 mpt2sas_port->remote_identify.device_type ==
7851 SAS_FANOUT_EXPANDER_DEVICE)
7852 mpt2sas_expander_remove(ioc,
7853 mpt2sas_port->remote_identify.sas_address);
7856 /* free phys attached to the sas_host */
7857 if (ioc->sas_hba.num_phys) {
7858 kfree(ioc->sas_hba.phy);
7859 ioc->sas_hba.phy = NULL;
7860 ioc->sas_hba.num_phys = 0;
7863 sas_remove_host(shost);
7864 mpt2sas_base_detach(ioc);
7865 list_del(&ioc->list);
7866 scsi_remove_host(shost);
7867 scsi_host_put(shost);
7871 * _scsih_probe_boot_devices - reports 1st device
7872 * @ioc: per adapter object
7874 * If specified in bios page 2, this routine reports the 1st
7875 * device scsi-ml or sas transport for persistent boot device
7876 * purposes. Please refer to function _scsih_determine_boot_device()
7879 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7883 struct _sas_device *sas_device;
7884 struct _raid_device *raid_device;
7886 u64 sas_address_parent;
7888 unsigned long flags;
7891 /* no Bios, return immediately */
7892 if (!ioc->bios_pg3.BiosVersion)
7897 if (ioc->req_boot_device.device) {
7898 device = ioc->req_boot_device.device;
7899 is_raid = ioc->req_boot_device.is_raid;
7900 } else if (ioc->req_alt_boot_device.device) {
7901 device = ioc->req_alt_boot_device.device;
7902 is_raid = ioc->req_alt_boot_device.is_raid;
7903 } else if (ioc->current_boot_device.device) {
7904 device = ioc->current_boot_device.device;
7905 is_raid = ioc->current_boot_device.is_raid;
7912 raid_device = device;
7913 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7914 raid_device->id, 0);
7916 _scsih_raid_device_remove(ioc, raid_device);
7918 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7919 sas_device = device;
7920 handle = sas_device->handle;
7921 sas_address_parent = sas_device->sas_address_parent;
7922 sas_address = sas_device->sas_address;
7923 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7924 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7926 if (ioc->hide_drives)
7928 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7929 sas_device->sas_address_parent)) {
7930 _scsih_sas_device_remove(ioc, sas_device);
7931 } else if (!sas_device->starget) {
7932 if (!ioc->is_driver_loading)
7933 mpt2sas_transport_port_remove(ioc, sas_address,
7934 sas_address_parent);
7935 _scsih_sas_device_remove(ioc, sas_device);
7941 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7942 * @ioc: per adapter object
7944 * Called during initial loading of the driver.
7947 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7949 struct _raid_device *raid_device, *raid_next;
7952 list_for_each_entry_safe(raid_device, raid_next,
7953 &ioc->raid_device_list, list) {
7954 if (raid_device->starget)
7956 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7957 raid_device->id, 0);
7959 _scsih_raid_device_remove(ioc, raid_device);
7964 * _scsih_probe_sas - reporting sas devices to sas transport
7965 * @ioc: per adapter object
7967 * Called during initial loading of the driver.
7970 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7972 struct _sas_device *sas_device, *next;
7973 unsigned long flags;
7975 /* SAS Device List */
7976 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7979 if (ioc->hide_drives)
7982 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7983 sas_device->sas_address_parent)) {
7984 list_del(&sas_device->list);
7987 } else if (!sas_device->starget) {
7988 if (!ioc->is_driver_loading)
7989 mpt2sas_transport_port_remove(ioc,
7990 sas_device->sas_address,
7991 sas_device->sas_address_parent);
7992 list_del(&sas_device->list);
7997 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7998 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7999 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8004 * _scsih_probe_devices - probing for devices
8005 * @ioc: per adapter object
8007 * Called during initial loading of the driver.
8010 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8012 u16 volume_mapping_flags;
8014 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8015 return; /* return when IOC doesn't support initiator mode */
8017 _scsih_probe_boot_devices(ioc);
8019 if (ioc->ir_firmware) {
8020 volume_mapping_flags =
8021 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8022 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8023 if (volume_mapping_flags ==
8024 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8025 _scsih_probe_raid(ioc);
8026 _scsih_probe_sas(ioc);
8028 _scsih_probe_sas(ioc);
8029 _scsih_probe_raid(ioc);
8032 _scsih_probe_sas(ioc);
8037 * _scsih_scan_start - scsi lld callback for .scan_start
8038 * @shost: SCSI host pointer
8040 * The shost has the ability to discover targets on its own instead
8041 * of scanning the entire bus. In our implemention, we will kick off
8042 * firmware discovery.
8045 _scsih_scan_start(struct Scsi_Host *shost)
8047 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8050 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8051 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8053 if (disable_discovery > 0)
8056 ioc->start_scan = 1;
8057 rc = mpt2sas_port_enable(ioc);
8060 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8064 * _scsih_scan_finished - scsi lld callback for .scan_finished
8065 * @shost: SCSI host pointer
8066 * @time: elapsed time of the scan in jiffies
8068 * This function will be called periodically until it returns 1 with the
8069 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8070 * we wait for firmware discovery to complete, then return 1.
8073 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8075 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8077 if (disable_discovery > 0) {
8078 ioc->is_driver_loading = 0;
8079 ioc->wait_for_discovery_to_complete = 0;
8083 if (time >= (300 * HZ)) {
8084 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8085 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8086 "(timeout=300s)\n", ioc->name);
8087 ioc->is_driver_loading = 0;
8091 if (ioc->start_scan)
8094 if (ioc->start_scan_failed) {
8095 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8096 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8097 ioc->is_driver_loading = 0;
8098 ioc->wait_for_discovery_to_complete = 0;
8099 ioc->remove_host = 1;
8103 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8104 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8106 if (ioc->wait_for_discovery_to_complete) {
8107 ioc->wait_for_discovery_to_complete = 0;
8108 _scsih_probe_devices(ioc);
8110 mpt2sas_base_start_watchdog(ioc);
8111 ioc->is_driver_loading = 0;
8117 * _scsih_probe - attach and add scsi host
8118 * @pdev: PCI device struct
8119 * @id: pci device id
8121 * Returns 0 success, anything else error.
8124 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8126 struct MPT2SAS_ADAPTER *ioc;
8127 struct Scsi_Host *shost;
8129 shost = scsi_host_alloc(&scsih_driver_template,
8130 sizeof(struct MPT2SAS_ADAPTER));
8134 /* init local params */
8135 ioc = shost_priv(shost);
8136 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8137 INIT_LIST_HEAD(&ioc->list);
8138 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8140 ioc->id = mpt_ids++;
8141 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8143 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8144 ioc->is_warpdrive = 1;
8145 ioc->hide_ir_msg = 1;
8147 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8148 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8149 ioc->tm_cb_idx = tm_cb_idx;
8150 ioc->ctl_cb_idx = ctl_cb_idx;
8151 ioc->base_cb_idx = base_cb_idx;
8152 ioc->port_enable_cb_idx = port_enable_cb_idx;
8153 ioc->transport_cb_idx = transport_cb_idx;
8154 ioc->scsih_cb_idx = scsih_cb_idx;
8155 ioc->config_cb_idx = config_cb_idx;
8156 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8157 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8158 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8159 ioc->logging_level = logging_level;
8160 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8161 /* misc semaphores and spin locks */
8162 mutex_init(&ioc->reset_in_progress_mutex);
8163 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8164 spin_lock_init(&ioc->scsi_lookup_lock);
8165 spin_lock_init(&ioc->sas_device_lock);
8166 spin_lock_init(&ioc->sas_node_lock);
8167 spin_lock_init(&ioc->fw_event_lock);
8168 spin_lock_init(&ioc->raid_device_lock);
8170 INIT_LIST_HEAD(&ioc->sas_device_list);
8171 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8172 INIT_LIST_HEAD(&ioc->sas_expander_list);
8173 INIT_LIST_HEAD(&ioc->fw_event_list);
8174 INIT_LIST_HEAD(&ioc->raid_device_list);
8175 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8176 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8177 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8179 /* init shost parameters */
8180 shost->max_cmd_len = 32;
8181 shost->max_lun = max_lun;
8182 shost->transportt = mpt2sas_transport_template;
8183 shost->unique_id = ioc->id;
8185 if (max_sectors != 0xFFFF) {
8186 if (max_sectors < 64) {
8187 shost->max_sectors = 64;
8188 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8189 "for max_sectors, range is 64 to 32767. Assigning "
8190 "value of 64.\n", ioc->name, max_sectors);
8191 } else if (max_sectors > 32767) {
8192 shost->max_sectors = 32767;
8193 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8194 "for max_sectors, range is 64 to 8192. Assigning "
8195 "default value of 32767.\n", ioc->name,
8198 shost->max_sectors = max_sectors & 0xFFFE;
8199 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8200 "set to %d\n", ioc->name, shost->max_sectors);
8204 if ((scsi_add_host(shost, &pdev->dev))) {
8205 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8206 ioc->name, __FILE__, __LINE__, __func__);
8207 list_del(&ioc->list);
8208 goto out_add_shost_fail;
8211 /* register EEDP capabilities with SCSI layer */
8213 scsi_host_set_prot(shost, prot_mask);
8215 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8216 | SHOST_DIF_TYPE2_PROTECTION
8217 | SHOST_DIF_TYPE3_PROTECTION);
8219 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8222 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8223 "fw_event%d", ioc->id);
8224 ioc->firmware_event_thread = create_singlethread_workqueue(
8225 ioc->firmware_event_name);
8226 if (!ioc->firmware_event_thread) {
8227 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8228 ioc->name, __FILE__, __LINE__, __func__);
8229 goto out_thread_fail;
8232 ioc->is_driver_loading = 1;
8233 if ((mpt2sas_base_attach(ioc))) {
8234 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8235 ioc->name, __FILE__, __LINE__, __func__);
8236 goto out_attach_fail;
8239 if (ioc->is_warpdrive) {
8240 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8241 ioc->hide_drives = 0;
8242 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8243 ioc->hide_drives = 1;
8245 if (_scsih_get_num_volumes(ioc))
8246 ioc->hide_drives = 1;
8248 ioc->hide_drives = 0;
8251 ioc->hide_drives = 0;
8252 scsi_scan_host(shost);
8257 destroy_workqueue(ioc->firmware_event_thread);
8259 list_del(&ioc->list);
8260 scsi_remove_host(shost);
8262 scsi_host_put(shost);
8268 * _scsih_suspend - power management suspend main entry point
8269 * @pdev: PCI device struct
8270 * @state: PM state change to (usually PCI_D3)
8272 * Returns 0 success, anything else error.
8275 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8277 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8278 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8279 pci_power_t device_state;
8281 mpt2sas_base_stop_watchdog(ioc);
8282 scsi_block_requests(shost);
8283 device_state = pci_choose_state(pdev, state);
8284 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8285 "operating state [D%d]\n", ioc->name, pdev,
8286 pci_name(pdev), device_state);
8288 mpt2sas_base_free_resources(ioc);
8289 pci_save_state(pdev);
8290 pci_disable_device(pdev);
8291 pci_set_power_state(pdev, device_state);
8296 * _scsih_resume - power management resume main entry point
8297 * @pdev: PCI device struct
8299 * Returns 0 success, anything else error.
8302 _scsih_resume(struct pci_dev *pdev)
8304 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8305 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8306 pci_power_t device_state = pdev->current_state;
8309 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8310 "operating state [D%d]\n", ioc->name, pdev,
8311 pci_name(pdev), device_state);
8313 pci_set_power_state(pdev, PCI_D0);
8314 pci_enable_wake(pdev, PCI_D0, 0);
8315 pci_restore_state(pdev);
8317 r = mpt2sas_base_map_resources(ioc);
8321 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8322 scsi_unblock_requests(shost);
8323 mpt2sas_base_start_watchdog(ioc);
8326 #endif /* CONFIG_PM */
8329 * _scsih_pci_error_detected - Called when a PCI error is detected.
8330 * @pdev: PCI device struct
8331 * @state: PCI channel state
8333 * Description: Called when a PCI error is detected.
8336 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8338 static pci_ers_result_t
8339 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8341 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8342 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8344 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8348 case pci_channel_io_normal:
8349 return PCI_ERS_RESULT_CAN_RECOVER;
8350 case pci_channel_io_frozen:
8351 /* Fatal error, prepare for slot reset */
8352 ioc->pci_error_recovery = 1;
8353 scsi_block_requests(ioc->shost);
8354 mpt2sas_base_stop_watchdog(ioc);
8355 mpt2sas_base_free_resources(ioc);
8356 return PCI_ERS_RESULT_NEED_RESET;
8357 case pci_channel_io_perm_failure:
8358 /* Permanent error, prepare for device removal */
8359 ioc->pci_error_recovery = 1;
8360 mpt2sas_base_stop_watchdog(ioc);
8361 _scsih_flush_running_cmds(ioc);
8362 return PCI_ERS_RESULT_DISCONNECT;
8364 return PCI_ERS_RESULT_NEED_RESET;
8368 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8369 * @pdev: PCI device struct
8371 * Description: This routine is called by the pci error recovery
8372 * code after the PCI slot has been reset, just before we
8373 * should resume normal operations.
8375 static pci_ers_result_t
8376 _scsih_pci_slot_reset(struct pci_dev *pdev)
8378 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8379 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8382 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8385 ioc->pci_error_recovery = 0;
8387 pci_restore_state(pdev);
8388 rc = mpt2sas_base_map_resources(ioc);
8390 return PCI_ERS_RESULT_DISCONNECT;
8393 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8396 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8397 (rc == 0) ? "success" : "failed");
8400 return PCI_ERS_RESULT_RECOVERED;
8402 return PCI_ERS_RESULT_DISCONNECT;
8406 * _scsih_pci_resume() - resume normal ops after PCI reset
8407 * @pdev: pointer to PCI device
8409 * Called when the error recovery driver tells us that its
8410 * OK to resume normal operation. Use completion to allow
8411 * halted scsi ops to resume.
8414 _scsih_pci_resume(struct pci_dev *pdev)
8416 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8417 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8419 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8421 pci_cleanup_aer_uncorrect_error_status(pdev);
8422 mpt2sas_base_start_watchdog(ioc);
8423 scsi_unblock_requests(ioc->shost);
8427 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8428 * @pdev: pointer to PCI device
8430 static pci_ers_result_t
8431 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8433 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8434 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8436 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8439 /* TODO - dump whatever for debugging purposes */
8441 /* Request a slot reset. */
8442 return PCI_ERS_RESULT_NEED_RESET;
8445 static const struct pci_error_handlers _scsih_err_handler = {
8446 .error_detected = _scsih_pci_error_detected,
8447 .mmio_enabled = _scsih_pci_mmio_enabled,
8448 .slot_reset = _scsih_pci_slot_reset,
8449 .resume = _scsih_pci_resume,
8452 static struct pci_driver scsih_driver = {
8453 .name = MPT2SAS_DRIVER_NAME,
8454 .id_table = scsih_pci_table,
8455 .probe = _scsih_probe,
8456 .remove = _scsih_remove,
8457 .shutdown = _scsih_shutdown,
8458 .err_handler = &_scsih_err_handler,
8460 .suspend = _scsih_suspend,
8461 .resume = _scsih_resume,
8465 /* raid transport support */
8466 static struct raid_function_template mpt2sas_raid_functions = {
8467 .cookie = &scsih_driver_template,
8468 .is_raid = _scsih_is_raid,
8469 .get_resync = _scsih_get_resync,
8470 .get_state = _scsih_get_state,
8474 * _scsih_init - main entry point for this driver.
8476 * Returns 0 success, anything else error.
8484 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8485 MPT2SAS_DRIVER_VERSION);
8487 mpt2sas_transport_template =
8488 sas_attach_transport(&mpt2sas_transport_functions);
8489 if (!mpt2sas_transport_template)
8491 /* raid transport support */
8492 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8493 if (!mpt2sas_raid_template) {
8494 sas_release_transport(mpt2sas_transport_template);
8498 mpt2sas_base_initialize_callback_handler();
8500 /* queuecommand callback hander */
8501 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8503 /* task management callback handler */
8504 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8506 /* base internal commands callback handler */
8507 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8508 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8509 mpt2sas_port_enable_done);
8511 /* transport internal commands callback handler */
8512 transport_cb_idx = mpt2sas_base_register_callback_handler(
8513 mpt2sas_transport_done);
8515 /* scsih internal commands callback handler */
8516 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8518 /* configuration page API internal commands callback handler */
8519 config_cb_idx = mpt2sas_base_register_callback_handler(
8520 mpt2sas_config_done);
8522 /* ctl module callback handler */
8523 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8525 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8526 _scsih_tm_tr_complete);
8528 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8529 _scsih_tm_volume_tr_complete);
8531 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8532 _scsih_sas_control_complete);
8536 error = pci_register_driver(&scsih_driver);
8538 /* raid transport support */
8539 raid_class_release(mpt2sas_raid_template);
8540 sas_release_transport(mpt2sas_transport_template);
8547 * _scsih_exit - exit point for this driver (when it is a module).
8549 * Returns 0 success, anything else error.
8554 printk(KERN_INFO "mpt2sas version %s unloading\n",
8555 MPT2SAS_DRIVER_VERSION);
8557 pci_unregister_driver(&scsih_driver);
8561 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8562 mpt2sas_base_release_callback_handler(tm_cb_idx);
8563 mpt2sas_base_release_callback_handler(base_cb_idx);
8564 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8565 mpt2sas_base_release_callback_handler(transport_cb_idx);
8566 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8567 mpt2sas_base_release_callback_handler(config_cb_idx);
8568 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8570 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8571 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8572 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8574 /* raid transport support */
8575 raid_class_release(mpt2sas_raid_template);
8576 sas_release_transport(mpt2sas_transport_template);
8580 module_init(_scsih_init);
8581 module_exit(_scsih_exit);