2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2014 LSI Corporation
6 * (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 <asm/unaligned.h>
60 #include "mpt2sas_base.h"
62 MODULE_AUTHOR(MPT2SAS_AUTHOR);
63 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
64 MODULE_LICENSE("GPL");
65 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
67 #define RAID_CHANNEL 1
70 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
71 struct _sas_node *sas_expander);
72 static void _firmware_event_work(struct work_struct *work);
74 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
76 static void _scsih_scan_start(struct Scsi_Host *shost);
77 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
79 /* global parameters */
80 LIST_HEAD(mpt2sas_ioc_list);
82 /* local parameters */
83 static u8 scsi_io_cb_idx = -1;
84 static u8 tm_cb_idx = -1;
85 static u8 ctl_cb_idx = -1;
86 static u8 base_cb_idx = -1;
87 static u8 port_enable_cb_idx = -1;
88 static u8 transport_cb_idx = -1;
89 static u8 scsih_cb_idx = -1;
90 static u8 config_cb_idx = -1;
93 static u8 tm_tr_cb_idx = -1 ;
94 static u8 tm_tr_volume_cb_idx = -1 ;
95 static u8 tm_sas_control_cb_idx = -1;
97 /* command line options */
98 static u32 logging_level;
99 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
102 static ushort max_sectors = 0xFFFF;
103 module_param(max_sectors, ushort, 0);
104 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
106 static int missing_delay[2] = {-1, -1};
107 module_param_array(missing_delay, int, NULL, 0);
108 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
110 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
111 #define MPT2SAS_MAX_LUN (16895)
112 static int max_lun = MPT2SAS_MAX_LUN;
113 module_param(max_lun, int, 0);
114 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
116 /* diag_buffer_enable is bitwise
118 * bit 1 set = SNAPSHOT
119 * bit 2 set = EXTENDED
121 * Either bit can be set, or both
123 static int diag_buffer_enable = -1;
124 module_param(diag_buffer_enable, int, 0);
125 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
126 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
128 static int disable_discovery = -1;
129 module_param(disable_discovery, int, 0);
130 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
132 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
133 static int prot_mask = 0;
134 module_param(prot_mask, int, 0);
135 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
138 * struct sense_info - common structure for obtaining sense keys
140 * @asc: additional sense code
141 * @ascq: additional sense code qualifier
150 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
151 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
152 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
154 * struct fw_event_work - firmware event struct
155 * @list: link list framework
156 * @work: work object (ioc->fault_reset_work_q)
157 * @cancel_pending_work: flag set during reset handling
158 * @ioc: per adapter object
159 * @device_handle: device handle
160 * @VF_ID: virtual function id
161 * @VP_ID: virtual port id
162 * @ignore: flag meaning this event has been marked to ignore
163 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
164 * @event_data: reply event data payload follows
166 * This object stored on ioc->fw_event_list.
168 struct fw_event_work {
169 struct list_head list;
170 u8 cancel_pending_work;
171 struct delayed_work delayed_work;
172 struct MPT2SAS_ADAPTER *ioc;
178 char event_data[0] __aligned(4);
181 /* raid transport support */
182 static struct raid_template *mpt2sas_raid_template;
185 * struct _scsi_io_transfer - scsi io transfer
186 * @handle: sas device handle (assigned by firmware)
187 * @is_raid: flag set for hidden raid components
188 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
189 * @data_length: data transfer length
190 * @data_dma: dma pointer to data
193 * @cdb_length: cdb length
195 * @timeout: timeout for this command
196 * @VF_ID: virtual function id
197 * @VP_ID: virtual port id
198 * @valid_reply: flag set for reply message
199 * @sense_length: sense length
200 * @ioc_status: ioc status
201 * @scsi_state: scsi state
202 * @scsi_status: scsi staus
203 * @log_info: log information
204 * @transfer_length: data length transfer when there is a reply message
206 * Used for sending internal scsi commands to devices within this module.
207 * Refer to _scsi_send_scsi_io().
209 struct _scsi_io_transfer {
212 enum dma_data_direction dir;
215 u8 sense[SCSI_SENSE_BUFFERSIZE];
223 /* the following bits are only valid when 'valid_reply = 1' */
233 * The pci device ids are defined in mpi/mpi2_cnfg.h.
235 static struct pci_device_id scsih_pci_table[] = {
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
237 PCI_ANY_ID, PCI_ANY_ID },
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
240 PCI_ANY_ID, PCI_ANY_ID },
241 /* Liberator ~ 2108 */
242 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
245 PCI_ANY_ID, PCI_ANY_ID },
246 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
247 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
250 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
252 PCI_ANY_ID, PCI_ANY_ID },
253 /* Thunderbolt ~ 2208 */
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
265 PCI_ANY_ID, PCI_ANY_ID },
267 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
268 PCI_ANY_ID, PCI_ANY_ID },
269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
270 PCI_ANY_ID, PCI_ANY_ID },
271 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
272 PCI_ANY_ID, PCI_ANY_ID },
274 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
275 PCI_ANY_ID, PCI_ANY_ID },
276 {0} /* Terminating entry */
278 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
281 * _scsih_set_debug_level - global setting of ioc->logging_level.
283 * Note: The logging levels are defined in mpt2sas_debug.h.
286 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
288 int ret = param_set_int(val, kp);
289 struct MPT2SAS_ADAPTER *ioc;
294 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
295 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
296 ioc->logging_level = logging_level;
299 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
300 &logging_level, 0644);
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
307 * Returns 1 when there's a match, 0 means no match.
310 _scsih_srch_boot_sas_address(u64 sas_address,
311 Mpi2BootDeviceSasWwid_t *boot_device)
313 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_device_name(u64 device_name,
325 Mpi2BootDeviceDeviceName_t *boot_device)
327 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
336 * Returns 1 when there's a match, 0 means no match.
339 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
340 Mpi2BootDeviceEnclosureSlot_t *boot_device)
342 return (enclosure_logical_id == le64_to_cpu(boot_device->
343 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
344 SlotNumber)) ? 1 : 0;
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
356 * Returns 1 when there's a match, 0 means no match.
359 _scsih_is_boot_device(u64 sas_address, u64 device_name,
360 u64 enclosure_logical_id, u16 slot, u8 form,
361 Mpi2BiosPage2BootDevice_t *boot_device)
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
369 rc = _scsih_srch_boot_sas_address(
370 sas_address, &boot_device->SasWwid);
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
373 if (!enclosure_logical_id)
375 rc = _scsih_srch_boot_encl_slot(
376 enclosure_logical_id,
377 slot, &boot_device->EnclosureSlot);
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
382 rc = _scsih_srch_boot_device_name(
383 device_name, &boot_device->DeviceName);
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
397 * Returns 0 success, non-zero when failure
400 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
403 Mpi2SasDevicePage0_t sas_device_pg0;
404 Mpi2ConfigReply_t mpi_reply;
408 if (handle <= ioc->sas_hba.num_phys) {
409 *sas_address = ioc->sas_hba.sas_address;
413 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
415 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
416 __FILE__, __LINE__, __func__);
420 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
421 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
422 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
429 /* else error case */
430 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
431 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
432 __FILE__, __LINE__, __func__);
437 * _scsih_determine_boot_device - determine boot device.
438 * @ioc: per adapter object
439 * @device: either sas_device or raid_device object
440 * @is_raid: [flag] 1 = raid object, 0 = sas object
442 * Determines whether this device should be first reported device to
443 * to scsi-ml or sas transport, this purpose is for persistent boot device.
444 * There are primary, alternate, and current entries in bios page 2. The order
445 * priority is primary, alternate, then current. This routine saves
446 * the corresponding device object and is_raid flag in the ioc object.
447 * The saved data to be used later in _scsih_probe_boot_devices().
450 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
451 void *device, u8 is_raid)
453 struct _sas_device *sas_device;
454 struct _raid_device *raid_device;
457 u64 enclosure_logical_id;
460 /* only process this function when driver loads */
461 if (!ioc->is_driver_loading)
464 /* no Bios, return immediately */
465 if (!ioc->bios_pg3.BiosVersion)
470 sas_address = sas_device->sas_address;
471 device_name = sas_device->device_name;
472 enclosure_logical_id = sas_device->enclosure_logical_id;
473 slot = sas_device->slot;
475 raid_device = device;
476 sas_address = raid_device->wwid;
478 enclosure_logical_id = 0;
482 if (!ioc->req_boot_device.device) {
483 if (_scsih_is_boot_device(sas_address, device_name,
484 enclosure_logical_id, slot,
485 (ioc->bios_pg2.ReqBootDeviceForm &
486 MPI2_BIOSPAGE2_FORM_MASK),
487 &ioc->bios_pg2.RequestedBootDevice)) {
488 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
489 "%s: req_boot_device(0x%016llx)\n",
491 (unsigned long long)sas_address));
492 ioc->req_boot_device.device = device;
493 ioc->req_boot_device.is_raid = is_raid;
497 if (!ioc->req_alt_boot_device.device) {
498 if (_scsih_is_boot_device(sas_address, device_name,
499 enclosure_logical_id, slot,
500 (ioc->bios_pg2.ReqAltBootDeviceForm &
501 MPI2_BIOSPAGE2_FORM_MASK),
502 &ioc->bios_pg2.RequestedAltBootDevice)) {
503 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
504 "%s: req_alt_boot_device(0x%016llx)\n",
506 (unsigned long long)sas_address));
507 ioc->req_alt_boot_device.device = device;
508 ioc->req_alt_boot_device.is_raid = is_raid;
512 if (!ioc->current_boot_device.device) {
513 if (_scsih_is_boot_device(sas_address, device_name,
514 enclosure_logical_id, slot,
515 (ioc->bios_pg2.CurrentBootDeviceForm &
516 MPI2_BIOSPAGE2_FORM_MASK),
517 &ioc->bios_pg2.CurrentBootDevice)) {
518 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
519 "%s: current_boot_device(0x%016llx)\n",
521 (unsigned long long)sas_address));
522 ioc->current_boot_device.device = device;
523 ioc->current_boot_device.is_raid = is_raid;
529 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
530 * @ioc: per adapter object
531 * @sas_address: sas address
532 * Context: Calling function should acquire ioc->sas_device_lock
534 * This searches for sas_device based on sas_address, then return sas_device
538 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
541 struct _sas_device *sas_device;
543 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
544 if (sas_device->sas_address == sas_address)
547 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
548 if (sas_device->sas_address == sas_address)
555 * _scsih_sas_device_find_by_handle - sas device search
556 * @ioc: per adapter object
557 * @handle: sas device handle (assigned by firmware)
558 * Context: Calling function should acquire ioc->sas_device_lock
560 * This searches for sas_device based on sas_address, then return sas_device
563 static struct _sas_device *
564 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
566 struct _sas_device *sas_device;
568 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
569 if (sas_device->handle == handle)
572 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
573 if (sas_device->handle == handle)
580 * _scsih_sas_device_remove - remove sas_device from list.
581 * @ioc: per adapter object
582 * @sas_device: the sas_device object
583 * Context: This function will acquire ioc->sas_device_lock.
585 * Removing object and freeing associated memory from the ioc->sas_device_list.
588 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
589 struct _sas_device *sas_device)
596 spin_lock_irqsave(&ioc->sas_device_lock, flags);
597 list_del(&sas_device->list);
599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
604 * _scsih_sas_device_add - insert sas_device to the list.
605 * @ioc: per adapter object
606 * @sas_device: the sas_device object
607 * Context: This function will acquire ioc->sas_device_lock.
609 * Adding new object to the ioc->sas_device_list.
612 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
613 struct _sas_device *sas_device)
617 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
618 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
619 sas_device->handle, (unsigned long long)sas_device->sas_address));
621 spin_lock_irqsave(&ioc->sas_device_lock, flags);
622 list_add_tail(&sas_device->list, &ioc->sas_device_list);
623 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
625 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
626 sas_device->sas_address_parent)) {
627 _scsih_sas_device_remove(ioc, sas_device);
628 } else if (!sas_device->starget) {
629 /* When asyn scanning is enabled, its not possible to remove
630 * devices while scanning is turned on due to an oops in
631 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
633 if (!ioc->is_driver_loading) {
634 mpt2sas_transport_port_remove(ioc,
635 sas_device->sas_address,
636 sas_device->sas_address_parent);
637 _scsih_sas_device_remove(ioc, sas_device);
643 * _scsih_sas_device_init_add - insert sas_device to the list.
644 * @ioc: per adapter object
645 * @sas_device: the sas_device object
646 * Context: This function will acquire ioc->sas_device_lock.
648 * Adding new object at driver load time to the ioc->sas_device_init_list.
651 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
652 struct _sas_device *sas_device)
656 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
657 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
658 sas_device->handle, (unsigned long long)sas_device->sas_address));
660 spin_lock_irqsave(&ioc->sas_device_lock, flags);
661 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
662 _scsih_determine_boot_device(ioc, sas_device, 0);
663 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
667 * _scsih_raid_device_find_by_id - raid device search
668 * @ioc: per adapter object
669 * @id: sas device target id
670 * @channel: sas device channel
671 * Context: Calling function should acquire ioc->raid_device_lock
673 * This searches for raid_device based on target id, then return raid_device
676 static struct _raid_device *
677 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
679 struct _raid_device *raid_device, *r;
682 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
683 if (raid_device->id == id && raid_device->channel == channel) {
694 * _scsih_raid_device_find_by_handle - raid device search
695 * @ioc: per adapter object
696 * @handle: sas device handle (assigned by firmware)
697 * Context: Calling function should acquire ioc->raid_device_lock
699 * This searches for raid_device based on handle, then return raid_device
702 static struct _raid_device *
703 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
705 struct _raid_device *raid_device, *r;
708 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
709 if (raid_device->handle != handle)
720 * _scsih_raid_device_find_by_wwid - raid device search
721 * @ioc: per adapter object
722 * @handle: sas device handle (assigned by firmware)
723 * Context: Calling function should acquire ioc->raid_device_lock
725 * This searches for raid_device based on wwid, then return raid_device
728 static struct _raid_device *
729 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
731 struct _raid_device *raid_device, *r;
734 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
735 if (raid_device->wwid != wwid)
746 * _scsih_raid_device_add - add raid_device object
747 * @ioc: per adapter object
748 * @raid_device: raid_device object
750 * This is added to the raid_device_list link list.
753 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
754 struct _raid_device *raid_device)
758 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
759 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
760 raid_device->handle, (unsigned long long)raid_device->wwid));
762 spin_lock_irqsave(&ioc->raid_device_lock, flags);
763 list_add_tail(&raid_device->list, &ioc->raid_device_list);
764 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
768 * _scsih_raid_device_remove - delete raid_device object
769 * @ioc: per adapter object
770 * @raid_device: raid_device object
774 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
775 struct _raid_device *raid_device)
779 spin_lock_irqsave(&ioc->raid_device_lock, flags);
780 list_del(&raid_device->list);
782 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
786 * mpt2sas_scsih_expander_find_by_handle - expander device search
787 * @ioc: per adapter object
788 * @handle: expander handle (assigned by firmware)
789 * Context: Calling function should acquire ioc->sas_device_lock
791 * This searches for expander device based on handle, then returns the
795 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
797 struct _sas_node *sas_expander, *r;
800 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
801 if (sas_expander->handle != handle)
811 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
812 * @ioc: per adapter object
813 * @sas_address: sas address
814 * Context: Calling function should acquire ioc->sas_node_lock.
816 * This searches for expander device based on sas_address, then returns the
820 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
823 struct _sas_node *sas_expander, *r;
826 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
827 if (sas_expander->sas_address != sas_address)
837 * _scsih_expander_node_add - insert expander device to the list.
838 * @ioc: per adapter object
839 * @sas_expander: the sas_device object
840 * Context: This function will acquire ioc->sas_node_lock.
842 * Adding new object to the ioc->sas_expander_list.
847 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
848 struct _sas_node *sas_expander)
852 spin_lock_irqsave(&ioc->sas_node_lock, flags);
853 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
854 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
858 * _scsih_is_end_device - determines if device is an end device
859 * @device_info: bitfield providing information about the device.
862 * Returns 1 if end device.
865 _scsih_is_end_device(u32 device_info)
867 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
868 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
869 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
870 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
877 * _scsih_scsi_lookup_get - returns scmd entry
878 * @ioc: per adapter object
879 * @smid: system request message index
881 * Returns the smid stored scmd pointer.
883 static struct scsi_cmnd *
884 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
886 return ioc->scsi_lookup[smid - 1].scmd;
890 * _scsih_scsi_lookup_get_clear - returns scmd entry
891 * @ioc: per adapter object
892 * @smid: system request message index
894 * Returns the smid stored scmd pointer.
895 * Then will derefrence the stored scmd pointer.
897 static inline struct scsi_cmnd *
898 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
901 struct scsi_cmnd *scmd;
903 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
904 scmd = ioc->scsi_lookup[smid - 1].scmd;
905 ioc->scsi_lookup[smid - 1].scmd = NULL;
906 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
912 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
913 * @ioc: per adapter object
914 * @smid: system request message index
915 * @scmd: pointer to scsi command object
916 * Context: This function will acquire ioc->scsi_lookup_lock.
918 * This will search for a scmd pointer in the scsi_lookup array,
919 * returning the revelent smid. A returned value of zero means invalid.
922 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
929 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
931 for (i = 0; i < ioc->scsiio_depth; i++) {
932 if (ioc->scsi_lookup[i].scmd == scmd) {
933 smid = ioc->scsi_lookup[i].smid;
938 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
943 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
944 * @ioc: per adapter object
947 * Context: This function will acquire ioc->scsi_lookup_lock.
949 * This will search for a matching channel:id in the scsi_lookup array,
950 * returning 1 if found.
953 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
960 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
962 for (i = 0 ; i < ioc->scsiio_depth; i++) {
963 if (ioc->scsi_lookup[i].scmd &&
964 (ioc->scsi_lookup[i].scmd->device->id == id &&
965 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
971 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
976 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
977 * @ioc: per adapter object
981 * Context: This function will acquire ioc->scsi_lookup_lock.
983 * This will search for a matching channel:id:lun in the scsi_lookup array,
984 * returning 1 if found.
987 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
988 unsigned int lun, int channel)
994 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
996 for (i = 0 ; i < ioc->scsiio_depth; i++) {
997 if (ioc->scsi_lookup[i].scmd &&
998 (ioc->scsi_lookup[i].scmd->device->id == id &&
999 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1000 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1006 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1011 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1012 * @ioc: per adapter object
1013 * @smid: smid associated to an IO request
1015 * Returns chain tracker(from ioc->free_chain_list)
1017 static struct chain_tracker *
1018 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1020 struct chain_tracker *chain_req;
1021 unsigned long flags;
1023 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1024 if (list_empty(&ioc->free_chain_list)) {
1025 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1026 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1027 "available\n", ioc->name));
1030 chain_req = list_entry(ioc->free_chain_list.next,
1031 struct chain_tracker, tracker_list);
1032 list_del_init(&chain_req->tracker_list);
1033 list_add_tail(&chain_req->tracker_list,
1034 &ioc->scsi_lookup[smid - 1].chain_list);
1035 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1040 * _scsih_build_scatter_gather - main sg creation routine
1041 * @ioc: per adapter object
1042 * @scmd: scsi command
1043 * @smid: system request message index
1046 * The main routine that builds scatter gather table from a given
1047 * scsi request sent via the .queuecommand main handler.
1049 * Returns 0 success, anything else error
1052 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1053 struct scsi_cmnd *scmd, u16 smid)
1055 Mpi2SCSIIORequest_t *mpi_request;
1056 dma_addr_t chain_dma;
1057 struct scatterlist *sg_scmd;
1058 void *sg_local, *chain;
1063 u32 sges_in_segment;
1065 u32 sgl_flags_last_element;
1066 u32 sgl_flags_end_buffer;
1067 struct chain_tracker *chain_req;
1069 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1071 /* init scatter gather flags */
1072 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1073 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1074 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1075 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1076 << MPI2_SGE_FLAGS_SHIFT;
1077 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1078 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1079 << MPI2_SGE_FLAGS_SHIFT;
1080 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1082 sg_scmd = scsi_sglist(scmd);
1083 sges_left = scsi_dma_map(scmd);
1084 if (sges_left < 0) {
1085 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1086 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1090 sg_local = &mpi_request->SGL;
1091 sges_in_segment = ioc->max_sges_in_main_message;
1092 if (sges_left <= sges_in_segment)
1093 goto fill_in_last_segment;
1095 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1096 (sges_in_segment * ioc->sge_size))/4;
1098 /* fill in main message segment when there is a chain following */
1099 while (sges_in_segment) {
1100 if (sges_in_segment == 1)
1101 ioc->base_add_sg_single(sg_local,
1102 sgl_flags_last_element | sg_dma_len(sg_scmd),
1103 sg_dma_address(sg_scmd));
1105 ioc->base_add_sg_single(sg_local, sgl_flags |
1106 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1107 sg_scmd = sg_next(sg_scmd);
1108 sg_local += ioc->sge_size;
1113 /* initializing the chain flags and pointers */
1114 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1115 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1118 chain = chain_req->chain_buffer;
1119 chain_dma = chain_req->chain_buffer_dma;
1121 sges_in_segment = (sges_left <=
1122 ioc->max_sges_in_chain_message) ? sges_left :
1123 ioc->max_sges_in_chain_message;
1124 chain_offset = (sges_left == sges_in_segment) ?
1125 0 : (sges_in_segment * ioc->sge_size)/4;
1126 chain_length = sges_in_segment * ioc->sge_size;
1128 chain_offset = chain_offset <<
1129 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1130 chain_length += ioc->sge_size;
1132 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1133 chain_length, chain_dma);
1136 goto fill_in_last_segment;
1138 /* fill in chain segments */
1139 while (sges_in_segment) {
1140 if (sges_in_segment == 1)
1141 ioc->base_add_sg_single(sg_local,
1142 sgl_flags_last_element |
1143 sg_dma_len(sg_scmd),
1144 sg_dma_address(sg_scmd));
1146 ioc->base_add_sg_single(sg_local, sgl_flags |
1147 sg_dma_len(sg_scmd),
1148 sg_dma_address(sg_scmd));
1149 sg_scmd = sg_next(sg_scmd);
1150 sg_local += ioc->sge_size;
1155 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1158 chain = chain_req->chain_buffer;
1159 chain_dma = chain_req->chain_buffer_dma;
1163 fill_in_last_segment:
1165 /* fill the last segment */
1168 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1169 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1171 ioc->base_add_sg_single(sg_local, sgl_flags |
1172 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1173 sg_scmd = sg_next(sg_scmd);
1174 sg_local += ioc->sge_size;
1182 * _scsih_adjust_queue_depth - setting device queue depth
1183 * @sdev: scsi device struct
1184 * @qdepth: requested queue depth
1190 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1192 struct Scsi_Host *shost = sdev->host;
1194 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1195 struct MPT2SAS_DEVICE *sas_device_priv_data;
1196 struct MPT2SAS_TARGET *sas_target_priv_data;
1197 struct _sas_device *sas_device;
1198 unsigned long flags;
1200 max_depth = shost->can_queue;
1202 /* limit max device queue for SATA to 32 */
1203 sas_device_priv_data = sdev->hostdata;
1204 if (!sas_device_priv_data)
1206 sas_target_priv_data = sas_device_priv_data->sas_target;
1207 if (!sas_target_priv_data)
1209 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1211 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1212 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1213 sas_device_priv_data->sas_target->sas_address);
1214 if (sas_device && sas_device->device_info &
1215 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1216 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1221 if (!sdev->tagged_supported)
1223 if (qdepth > max_depth)
1225 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1229 * _scsih_change_queue_depth - setting device queue depth
1230 * @sdev: scsi device struct
1231 * @qdepth: requested queue depth
1232 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1233 * (see include/scsi/scsi_host.h for definition)
1235 * Returns queue depth.
1238 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1240 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1241 _scsih_adjust_queue_depth(sdev, qdepth);
1242 else if (reason == SCSI_QDEPTH_QFULL)
1243 scsi_track_queue_full(sdev, qdepth);
1247 if (sdev->inquiry_len > 7)
1248 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1249 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1250 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1251 sdev->ordered_tags, sdev->scsi_level,
1252 (sdev->inquiry[7] & 2) >> 1);
1254 return sdev->queue_depth;
1258 * _scsih_target_alloc - target add routine
1259 * @starget: scsi target struct
1261 * Returns 0 if ok. Any other return is assumed to be an error and
1262 * the device is ignored.
1265 _scsih_target_alloc(struct scsi_target *starget)
1267 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1268 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1269 struct MPT2SAS_TARGET *sas_target_priv_data;
1270 struct _sas_device *sas_device;
1271 struct _raid_device *raid_device;
1272 unsigned long flags;
1273 struct sas_rphy *rphy;
1275 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1277 if (!sas_target_priv_data)
1280 starget->hostdata = sas_target_priv_data;
1281 sas_target_priv_data->starget = starget;
1282 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1285 if (starget->channel == RAID_CHANNEL) {
1286 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1287 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1290 sas_target_priv_data->handle = raid_device->handle;
1291 sas_target_priv_data->sas_address = raid_device->wwid;
1292 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1293 if (ioc->is_warpdrive)
1294 sas_target_priv_data->raid_device = raid_device;
1295 raid_device->starget = starget;
1297 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1301 /* sas/sata devices */
1302 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1303 rphy = dev_to_rphy(starget->dev.parent);
1304 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1305 rphy->identify.sas_address);
1308 sas_target_priv_data->handle = sas_device->handle;
1309 sas_target_priv_data->sas_address = sas_device->sas_address;
1310 sas_device->starget = starget;
1311 sas_device->id = starget->id;
1312 sas_device->channel = starget->channel;
1313 if (test_bit(sas_device->handle, ioc->pd_handles))
1314 sas_target_priv_data->flags |=
1315 MPT_TARGET_FLAGS_RAID_COMPONENT;
1317 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1323 * _scsih_target_destroy - target destroy routine
1324 * @starget: scsi target struct
1329 _scsih_target_destroy(struct scsi_target *starget)
1331 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1332 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1333 struct MPT2SAS_TARGET *sas_target_priv_data;
1334 struct _sas_device *sas_device;
1335 struct _raid_device *raid_device;
1336 unsigned long flags;
1337 struct sas_rphy *rphy;
1339 sas_target_priv_data = starget->hostdata;
1340 if (!sas_target_priv_data)
1343 if (starget->channel == RAID_CHANNEL) {
1344 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1345 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1348 raid_device->starget = NULL;
1349 raid_device->sdev = NULL;
1351 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1355 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1356 rphy = dev_to_rphy(starget->dev.parent);
1357 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1358 rphy->identify.sas_address);
1359 if (sas_device && (sas_device->starget == starget) &&
1360 (sas_device->id == starget->id) &&
1361 (sas_device->channel == starget->channel))
1362 sas_device->starget = NULL;
1364 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1367 kfree(sas_target_priv_data);
1368 starget->hostdata = NULL;
1372 * _scsih_slave_alloc - device add routine
1373 * @sdev: scsi device struct
1375 * Returns 0 if ok. Any other return is assumed to be an error and
1376 * the device is ignored.
1379 _scsih_slave_alloc(struct scsi_device *sdev)
1381 struct Scsi_Host *shost;
1382 struct MPT2SAS_ADAPTER *ioc;
1383 struct MPT2SAS_TARGET *sas_target_priv_data;
1384 struct MPT2SAS_DEVICE *sas_device_priv_data;
1385 struct scsi_target *starget;
1386 struct _raid_device *raid_device;
1387 struct _sas_device *sas_device;
1388 unsigned long flags;
1390 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1392 if (!sas_device_priv_data)
1395 sas_device_priv_data->lun = sdev->lun;
1396 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1398 starget = scsi_target(sdev);
1399 sas_target_priv_data = starget->hostdata;
1400 sas_target_priv_data->num_luns++;
1401 sas_device_priv_data->sas_target = sas_target_priv_data;
1402 sdev->hostdata = sas_device_priv_data;
1403 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1404 sdev->no_uld_attach = 1;
1406 shost = dev_to_shost(&starget->dev);
1407 ioc = shost_priv(shost);
1408 if (starget->channel == RAID_CHANNEL) {
1409 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1410 raid_device = _scsih_raid_device_find_by_id(ioc,
1411 starget->id, starget->channel);
1413 raid_device->sdev = sdev; /* raid is single lun */
1414 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1417 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1418 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1419 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1420 sas_target_priv_data->sas_address);
1421 if (sas_device && (sas_device->starget == NULL)) {
1422 sdev_printk(KERN_INFO, sdev,
1423 "%s : sas_device->starget set to starget @ %d\n",
1424 __func__, __LINE__);
1425 sas_device->starget = starget;
1427 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1434 * _scsih_slave_destroy - device destroy routine
1435 * @sdev: scsi device struct
1440 _scsih_slave_destroy(struct scsi_device *sdev)
1442 struct MPT2SAS_TARGET *sas_target_priv_data;
1443 struct scsi_target *starget;
1444 struct Scsi_Host *shost;
1445 struct MPT2SAS_ADAPTER *ioc;
1446 struct _sas_device *sas_device;
1447 unsigned long flags;
1449 if (!sdev->hostdata)
1452 starget = scsi_target(sdev);
1453 sas_target_priv_data = starget->hostdata;
1454 sas_target_priv_data->num_luns--;
1456 shost = dev_to_shost(&starget->dev);
1457 ioc = shost_priv(shost);
1459 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1460 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1461 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1462 sas_target_priv_data->sas_address);
1463 if (sas_device && !sas_target_priv_data->num_luns)
1464 sas_device->starget = NULL;
1465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1468 kfree(sdev->hostdata);
1469 sdev->hostdata = NULL;
1473 * _scsih_display_sata_capabilities - sata capabilities
1474 * @ioc: per adapter object
1475 * @handle: device handle
1476 * @sdev: scsi device struct
1479 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1480 u16 handle, struct scsi_device *sdev)
1482 Mpi2ConfigReply_t mpi_reply;
1483 Mpi2SasDevicePage0_t sas_device_pg0;
1488 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1489 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1490 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1491 ioc->name, __FILE__, __LINE__, __func__);
1495 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1496 MPI2_IOCSTATUS_MASK;
1497 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1498 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1499 ioc->name, __FILE__, __LINE__, __func__);
1503 flags = le16_to_cpu(sas_device_pg0.Flags);
1504 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1506 sdev_printk(KERN_INFO, sdev,
1507 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1508 "sw_preserve(%s)\n",
1509 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1510 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1511 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1513 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1514 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1515 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1519 * _scsih_is_raid - return boolean indicating device is raid volume
1520 * @dev the device struct object
1523 _scsih_is_raid(struct device *dev)
1525 struct scsi_device *sdev = to_scsi_device(dev);
1526 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1528 if (ioc->is_warpdrive)
1530 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1534 * _scsih_get_resync - get raid volume resync percent complete
1535 * @dev the device struct object
1538 _scsih_get_resync(struct device *dev)
1540 struct scsi_device *sdev = to_scsi_device(dev);
1541 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1542 static struct _raid_device *raid_device;
1543 unsigned long flags;
1544 Mpi2RaidVolPage0_t vol_pg0;
1545 Mpi2ConfigReply_t mpi_reply;
1546 u32 volume_status_flags;
1547 u8 percent_complete;
1550 percent_complete = 0;
1552 if (ioc->is_warpdrive)
1555 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1556 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1559 handle = raid_device->handle;
1560 percent_complete = raid_device->percent_complete;
1562 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1567 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1568 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1569 sizeof(Mpi2RaidVolPage0_t))) {
1570 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1571 ioc->name, __FILE__, __LINE__, __func__);
1572 percent_complete = 0;
1576 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1577 if (!(volume_status_flags &
1578 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1579 percent_complete = 0;
1582 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1586 * _scsih_get_state - get raid volume level
1587 * @dev the device struct object
1590 _scsih_get_state(struct device *dev)
1592 struct scsi_device *sdev = to_scsi_device(dev);
1593 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1594 static struct _raid_device *raid_device;
1595 unsigned long flags;
1596 Mpi2RaidVolPage0_t vol_pg0;
1597 Mpi2ConfigReply_t mpi_reply;
1599 enum raid_state state = RAID_STATE_UNKNOWN;
1602 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1603 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1606 handle = raid_device->handle;
1607 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1612 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1613 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1614 sizeof(Mpi2RaidVolPage0_t))) {
1615 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1616 ioc->name, __FILE__, __LINE__, __func__);
1620 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1621 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1622 state = RAID_STATE_RESYNCING;
1626 switch (vol_pg0.VolumeState) {
1627 case MPI2_RAID_VOL_STATE_OPTIMAL:
1628 case MPI2_RAID_VOL_STATE_ONLINE:
1629 state = RAID_STATE_ACTIVE;
1631 case MPI2_RAID_VOL_STATE_DEGRADED:
1632 state = RAID_STATE_DEGRADED;
1634 case MPI2_RAID_VOL_STATE_FAILED:
1635 case MPI2_RAID_VOL_STATE_MISSING:
1636 state = RAID_STATE_OFFLINE;
1640 raid_set_state(mpt2sas_raid_template, dev, state);
1644 * _scsih_set_level - set raid level
1645 * @sdev: scsi device struct
1646 * @volume_type: volume type
1649 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1651 enum raid_level level = RAID_LEVEL_UNKNOWN;
1653 switch (volume_type) {
1654 case MPI2_RAID_VOL_TYPE_RAID0:
1655 level = RAID_LEVEL_0;
1657 case MPI2_RAID_VOL_TYPE_RAID10:
1658 level = RAID_LEVEL_10;
1660 case MPI2_RAID_VOL_TYPE_RAID1E:
1661 level = RAID_LEVEL_1E;
1663 case MPI2_RAID_VOL_TYPE_RAID1:
1664 level = RAID_LEVEL_1;
1668 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1672 * _scsih_get_volume_capabilities - volume capabilities
1673 * @ioc: per adapter object
1674 * @sas_device: the raid_device object
1676 * Returns 0 for success, else 1
1679 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1680 struct _raid_device *raid_device)
1682 Mpi2RaidVolPage0_t *vol_pg0;
1683 Mpi2RaidPhysDiskPage0_t pd_pg0;
1684 Mpi2SasDevicePage0_t sas_device_pg0;
1685 Mpi2ConfigReply_t mpi_reply;
1689 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1690 &num_pds)) || !num_pds) {
1691 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1692 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1697 raid_device->num_pds = num_pds;
1698 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1699 sizeof(Mpi2RaidVol0PhysDisk_t));
1700 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1702 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1703 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1708 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1709 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1710 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1711 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1717 raid_device->volume_type = vol_pg0->VolumeType;
1719 /* figure out what the underlying devices are by
1720 * obtaining the device_info bits for the 1st device
1722 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1723 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1724 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1725 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1726 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1727 le16_to_cpu(pd_pg0.DevHandle)))) {
1728 raid_device->device_info =
1729 le32_to_cpu(sas_device_pg0.DeviceInfo);
1737 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1738 * @ioc: per adapter object
1741 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1743 Mpi2RaidVolPage1_t vol_pg1;
1744 Mpi2ConfigReply_t mpi_reply;
1745 struct _raid_device *raid_device;
1748 unsigned long flags;
1751 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1752 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1753 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1754 MPI2_IOCSTATUS_MASK;
1755 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1757 handle = le16_to_cpu(vol_pg1.DevHandle);
1758 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1759 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1761 raid_device->direct_io_enabled = 0;
1762 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1769 * _scsih_get_num_volumes - Get number of volumes in the ioc
1770 * @ioc: per adapter object
1773 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1775 Mpi2RaidVolPage1_t vol_pg1;
1776 Mpi2ConfigReply_t mpi_reply;
1782 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1783 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1784 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1785 MPI2_IOCSTATUS_MASK;
1786 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1789 handle = le16_to_cpu(vol_pg1.DevHandle);
1796 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1797 * @ioc: per adapter object
1798 * @raid_device: the raid_device object
1801 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1802 struct _raid_device *raid_device)
1804 Mpi2RaidVolPage0_t *vol_pg0;
1805 Mpi2RaidPhysDiskPage0_t pd_pg0;
1806 Mpi2ConfigReply_t mpi_reply;
1809 unsigned long stripe_sz, block_sz;
1810 u8 stripe_exp, block_exp;
1813 if (!ioc->is_warpdrive)
1816 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1817 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1818 "globally as drives are exposed\n", ioc->name);
1821 if (_scsih_get_num_volumes(ioc) > 1) {
1822 _scsih_disable_ddio(ioc);
1823 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1824 "globally as number of drives > 1\n", ioc->name);
1827 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1828 &num_pds)) || !num_pds) {
1829 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1830 "Failure in computing number of drives\n", ioc->name);
1834 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1835 sizeof(Mpi2RaidVol0PhysDisk_t));
1836 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1838 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1839 "Memory allocation failure for RVPG0\n", ioc->name);
1843 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1844 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1845 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1846 "Failure in retrieving RVPG0\n", ioc->name);
1852 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1853 * assumed for WARPDRIVE, disable direct I/O
1855 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1856 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1857 "for the drive with handle(0x%04x): num_mem=%d, "
1858 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1859 num_pds, MPT_MAX_WARPDRIVE_PDS);
1863 for (count = 0; count < num_pds; count++) {
1864 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1865 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1866 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1867 le16_to_cpu(pd_pg0.DevHandle) ==
1868 MPT2SAS_INVALID_DEVICE_HANDLE) {
1869 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1870 "disabled for the drive with handle(0x%04x) member"
1871 "handle retrieval failed for member number=%d\n",
1872 ioc->name, raid_device->handle,
1873 vol_pg0->PhysDisk[count].PhysDiskNum);
1876 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1877 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1878 if (dev_max_lba >> 32) {
1879 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1880 "disabled for the drive with handle(0x%04x) member"
1881 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1882 ioc->name, raid_device->handle,
1883 le16_to_cpu(pd_pg0.DevHandle),
1884 (unsigned long long)dev_max_lba);
1888 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1892 * Assumption for WD: Direct I/O is not supported if the volume is
1895 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
1896 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1897 "for the drive with handle(0x%04x): type=%d, "
1898 "s_sz=%uK, blk_size=%u\n", ioc->name,
1899 raid_device->handle, raid_device->volume_type,
1900 (le32_to_cpu(vol_pg0->StripeSize) *
1901 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
1902 le16_to_cpu(vol_pg0->BlockSize));
1906 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1907 stripe_exp = find_first_bit(&stripe_sz, 32);
1908 if (stripe_exp == 32) {
1909 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1910 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1911 ioc->name, raid_device->handle,
1912 (le32_to_cpu(vol_pg0->StripeSize) *
1913 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
1916 raid_device->stripe_exponent = stripe_exp;
1917 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1918 block_exp = find_first_bit(&block_sz, 16);
1919 if (block_exp == 16) {
1920 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1921 "for the drive with handle(0x%04x) invalid block sz %u\n",
1922 ioc->name, raid_device->handle,
1923 le16_to_cpu(vol_pg0->BlockSize));
1926 raid_device->block_exponent = block_exp;
1927 raid_device->direct_io_enabled = 1;
1929 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1930 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1932 * WARPDRIVE: Though the following fields are not used for direct IO,
1933 * stored for future purpose:
1935 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1936 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1937 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1944 raid_device->direct_io_enabled = 0;
1945 for (count = 0; count < num_pds; count++)
1946 raid_device->pd_handle[count] = 0;
1952 * _scsih_enable_tlr - setting TLR flags
1953 * @ioc: per adapter object
1954 * @sdev: scsi device struct
1956 * Enabling Transaction Layer Retries for tape devices when
1957 * vpd page 0x90 is present
1961 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1964 if (sdev->type != TYPE_TAPE)
1967 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1970 sas_enable_tlr(sdev);
1971 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1972 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1978 * _scsih_slave_configure - device configure routine.
1979 * @sdev: scsi device struct
1981 * Returns 0 if ok. Any other return is assumed to be an error and
1982 * the device is ignored.
1985 _scsih_slave_configure(struct scsi_device *sdev)
1987 struct Scsi_Host *shost = sdev->host;
1988 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1989 struct MPT2SAS_DEVICE *sas_device_priv_data;
1990 struct MPT2SAS_TARGET *sas_target_priv_data;
1991 struct _sas_device *sas_device;
1992 struct _raid_device *raid_device;
1993 unsigned long flags;
1998 u16 handle, volume_handle = 0;
1999 u64 volume_wwid = 0;
2002 sas_device_priv_data = sdev->hostdata;
2003 sas_device_priv_data->configured_lun = 1;
2004 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2005 sas_target_priv_data = sas_device_priv_data->sas_target;
2006 handle = sas_target_priv_data->handle;
2008 /* raid volume handling */
2009 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2011 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2012 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
2013 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2015 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2016 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2017 __LINE__, __func__));
2021 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2022 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2023 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2024 __LINE__, __func__));
2028 * WARPDRIVE: Initialize the required data for Direct IO
2030 _scsih_init_warpdrive_properties(ioc, raid_device);
2032 /* RAID Queue Depth Support
2033 * IS volume = underlying qdepth of drive type, either
2034 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2035 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2037 if (raid_device->device_info &
2038 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2039 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2042 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2043 if (raid_device->device_info &
2044 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2050 switch (raid_device->volume_type) {
2051 case MPI2_RAID_VOL_TYPE_RAID0:
2054 case MPI2_RAID_VOL_TYPE_RAID1E:
2055 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2056 if (ioc->manu_pg10.OEMIdentifier &&
2057 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2058 MFG10_GF0_R10_DISPLAY) &&
2059 !(raid_device->num_pds % 2))
2064 case MPI2_RAID_VOL_TYPE_RAID1:
2065 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2068 case MPI2_RAID_VOL_TYPE_RAID10:
2069 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2072 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2074 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2079 if (!ioc->hide_ir_msg)
2080 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2081 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2082 r_level, raid_device->handle,
2083 (unsigned long long)raid_device->wwid,
2084 raid_device->num_pds, ds);
2085 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2086 /* raid transport support */
2087 if (!ioc->is_warpdrive)
2088 _scsih_set_level(sdev, raid_device->volume_type);
2092 /* non-raid handling */
2093 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2094 if (mpt2sas_config_get_volume_handle(ioc, handle,
2096 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2097 "failure at %s:%d/%s()!\n", ioc->name,
2098 __FILE__, __LINE__, __func__));
2101 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2102 volume_handle, &volume_wwid)) {
2103 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2104 "failure at %s:%d/%s()!\n", ioc->name,
2105 __FILE__, __LINE__, __func__));
2110 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2111 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2112 sas_device_priv_data->sas_target->sas_address);
2114 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2115 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2116 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2117 __LINE__, __func__));
2120 sas_device->volume_handle = volume_handle;
2121 sas_device->volume_wwid = volume_wwid;
2122 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2123 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2127 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2128 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2130 else if (sas_device->device_info &
2131 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2134 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2135 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2136 ds, sas_device->handle,
2137 (unsigned long long)sas_device->sas_address,
2139 (unsigned long long)sas_device->device_name);
2140 sdev_printk(KERN_INFO, sdev, "%s: "
2141 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2142 (unsigned long long) sas_device->enclosure_logical_id,
2145 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2147 _scsih_display_sata_capabilities(ioc, handle, sdev);
2150 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2153 sas_read_port_mode_page(sdev);
2154 _scsih_enable_tlr(ioc, sdev);
2160 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2161 * @sdev: scsi device struct
2162 * @bdev: pointer to block device context
2163 * @capacity: device size (in 512 byte sectors)
2164 * @params: three element array to place output:
2165 * params[0] number of heads (max 255)
2166 * params[1] number of sectors (max 63)
2167 * params[2] number of cylinders
2172 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2173 sector_t capacity, int params[])
2183 dummy = heads * sectors;
2184 cylinders = capacity;
2185 sector_div(cylinders, dummy);
2188 * Handle extended translation size for logical drives
2191 if ((ulong)capacity >= 0x200000) {
2194 dummy = heads * sectors;
2195 cylinders = capacity;
2196 sector_div(cylinders, dummy);
2201 params[1] = sectors;
2202 params[2] = cylinders;
2208 * _scsih_response_code - translation of device response code
2209 * @ioc: per adapter object
2210 * @response_code: response code returned by the device
2215 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2219 switch (response_code) {
2220 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2221 desc = "task management request completed";
2223 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2224 desc = "invalid frame";
2226 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2227 desc = "task management request not supported";
2229 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2230 desc = "task management request failed";
2232 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2233 desc = "task management request succeeded";
2235 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2236 desc = "invalid lun";
2239 desc = "overlapped tag attempted";
2241 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2242 desc = "task queued, however not sent to target";
2248 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2249 ioc->name, response_code, desc);
2253 * _scsih_tm_done - tm completion routine
2254 * @ioc: per adapter object
2255 * @smid: system request message index
2256 * @msix_index: MSIX table index supplied by the OS
2257 * @reply: reply message frame(lower 32bit addr)
2260 * The callback handler when using scsih_issue_tm.
2262 * Return 1 meaning mf should be freed from _base_interrupt
2263 * 0 means the mf is freed from this function.
2266 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2268 MPI2DefaultReply_t *mpi_reply;
2270 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2272 if (ioc->tm_cmds.smid != smid)
2274 mpt2sas_base_flush_reply_queues(ioc);
2275 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2276 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2278 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2279 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2281 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2282 complete(&ioc->tm_cmds.done);
2287 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2288 * @ioc: per adapter object
2289 * @handle: device handle
2291 * During taskmangement request, we need to freeze the device queue.
2294 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2296 struct MPT2SAS_DEVICE *sas_device_priv_data;
2297 struct scsi_device *sdev;
2300 shost_for_each_device(sdev, ioc->shost) {
2303 sas_device_priv_data = sdev->hostdata;
2304 if (!sas_device_priv_data)
2306 if (sas_device_priv_data->sas_target->handle == handle) {
2307 sas_device_priv_data->sas_target->tm_busy = 1;
2309 ioc->ignore_loginfos = 1;
2315 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2316 * @ioc: per adapter object
2317 * @handle: device handle
2319 * During taskmangement request, we need to freeze the device queue.
2322 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2324 struct MPT2SAS_DEVICE *sas_device_priv_data;
2325 struct scsi_device *sdev;
2328 shost_for_each_device(sdev, ioc->shost) {
2331 sas_device_priv_data = sdev->hostdata;
2332 if (!sas_device_priv_data)
2334 if (sas_device_priv_data->sas_target->handle == handle) {
2335 sas_device_priv_data->sas_target->tm_busy = 0;
2337 ioc->ignore_loginfos = 0;
2344 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2345 * @ioc: per adapter struct
2346 * @device_handle: device handle
2347 * @channel: the channel assigned by the OS
2348 * @id: the id assigned by the OS
2350 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2351 * @smid_task: smid assigned to the task
2352 * @timeout: timeout in seconds
2353 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2356 * A generic API for sending task management requests to firmware.
2358 * The callback index is set inside `ioc->tm_cb_idx`.
2360 * Return SUCCESS or FAILED.
2363 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2364 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2365 enum mutex_type m_type)
2367 Mpi2SCSITaskManagementRequest_t *mpi_request;
2368 Mpi2SCSITaskManagementReply_t *mpi_reply;
2371 unsigned long timeleft;
2372 struct scsiio_tracker *scsi_lookup = NULL;
2375 if (m_type == TM_MUTEX_ON)
2376 mutex_lock(&ioc->tm_cmds.mutex);
2377 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2378 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2379 __func__, ioc->name);
2384 if (ioc->shost_recovery || ioc->remove_host ||
2385 ioc->pci_error_recovery) {
2386 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2387 __func__, ioc->name);
2392 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2393 if (ioc_state & MPI2_DOORBELL_USED) {
2394 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2395 "active!\n", ioc->name));
2396 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2398 rc = (!rc) ? SUCCESS : FAILED;
2402 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2403 mpt2sas_base_fault_info(ioc, ioc_state &
2404 MPI2_DOORBELL_DATA_MASK);
2405 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2407 rc = (!rc) ? SUCCESS : FAILED;
2411 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2413 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2414 ioc->name, __func__);
2419 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2420 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2422 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2423 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2425 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2426 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2427 ioc->tm_cmds.smid = smid;
2428 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2429 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2430 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2431 mpi_request->DevHandle = cpu_to_le16(handle);
2432 mpi_request->TaskType = type;
2433 mpi_request->TaskMID = cpu_to_le16(smid_task);
2434 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2435 mpt2sas_scsih_set_tm_flag(ioc, handle);
2436 init_completion(&ioc->tm_cmds.done);
2437 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2438 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2439 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2440 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2441 ioc->name, __func__);
2442 _debug_dump_mf(mpi_request,
2443 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2444 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2445 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2447 rc = (!rc) ? SUCCESS : FAILED;
2448 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2449 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2454 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2455 mpi_reply = ioc->tm_cmds.reply;
2456 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2457 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2458 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2459 le32_to_cpu(mpi_reply->IOCLogInfo),
2460 le32_to_cpu(mpi_reply->TerminationCount)));
2461 if (ioc->logging_level & MPT_DEBUG_TM) {
2462 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2463 if (mpi_reply->IOCStatus)
2464 _debug_dump_mf(mpi_request,
2465 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2470 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2472 if (scsi_lookup->scmd == NULL)
2477 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2478 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2484 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2485 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2486 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2491 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2499 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2500 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2501 if (m_type == TM_MUTEX_ON)
2502 mutex_unlock(&ioc->tm_cmds.mutex);
2507 if (m_type == TM_MUTEX_ON)
2508 mutex_unlock(&ioc->tm_cmds.mutex);
2513 * _scsih_tm_display_info - displays info about the device
2514 * @ioc: per adapter struct
2515 * @scmd: pointer to scsi command object
2517 * Called by task management callback handlers.
2520 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2522 struct scsi_target *starget = scmd->device->sdev_target;
2523 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2524 struct _sas_device *sas_device = NULL;
2525 unsigned long flags;
2526 char *device_str = NULL;
2530 if (ioc->hide_ir_msg)
2531 device_str = "WarpDrive";
2533 device_str = "volume";
2535 scsi_print_command(scmd);
2536 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2537 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2538 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2539 device_str, (unsigned long long)priv_target->sas_address);
2541 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2542 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2543 priv_target->sas_address);
2545 if (priv_target->flags &
2546 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2547 starget_printk(KERN_INFO, starget,
2548 "volume handle(0x%04x), "
2549 "volume wwid(0x%016llx)\n",
2550 sas_device->volume_handle,
2551 (unsigned long long)sas_device->volume_wwid);
2553 starget_printk(KERN_INFO, starget,
2554 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2556 (unsigned long long)sas_device->sas_address,
2558 starget_printk(KERN_INFO, starget,
2559 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2560 (unsigned long long)sas_device->enclosure_logical_id,
2563 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2568 * _scsih_abort - eh threads main abort routine
2569 * @scmd: pointer to scsi command object
2571 * Returns SUCCESS if command aborted else FAILED
2574 _scsih_abort(struct scsi_cmnd *scmd)
2576 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2577 struct MPT2SAS_DEVICE *sas_device_priv_data;
2582 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2583 "scmd(%p)\n", scmd);
2584 _scsih_tm_display_info(ioc, scmd);
2586 sas_device_priv_data = scmd->device->hostdata;
2587 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2588 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2589 "scmd(%p)\n", scmd);
2590 scmd->result = DID_NO_CONNECT << 16;
2591 scmd->scsi_done(scmd);
2596 /* search for the command */
2597 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2599 scmd->result = DID_RESET << 16;
2604 /* for hidden raid components and volumes this is not supported */
2605 if (sas_device_priv_data->sas_target->flags &
2606 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2607 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2608 scmd->result = DID_RESET << 16;
2613 mpt2sas_halt_firmware(ioc);
2615 handle = sas_device_priv_data->sas_target->handle;
2616 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2617 scmd->device->id, scmd->device->lun,
2618 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2621 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2622 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2627 * _scsih_dev_reset - eh threads main device reset routine
2628 * @scmd: pointer to scsi command object
2630 * Returns SUCCESS if command aborted else FAILED
2633 _scsih_dev_reset(struct scsi_cmnd *scmd)
2635 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2636 struct MPT2SAS_DEVICE *sas_device_priv_data;
2637 struct _sas_device *sas_device;
2638 unsigned long flags;
2642 struct scsi_target *starget = scmd->device->sdev_target;
2644 starget_printk(KERN_INFO, starget, "attempting device reset! "
2645 "scmd(%p)\n", scmd);
2646 _scsih_tm_display_info(ioc, scmd);
2648 sas_device_priv_data = scmd->device->hostdata;
2649 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2650 starget_printk(KERN_INFO, starget, "device been deleted! "
2651 "scmd(%p)\n", scmd);
2652 scmd->result = DID_NO_CONNECT << 16;
2653 scmd->scsi_done(scmd);
2658 /* for hidden raid components obtain the volume_handle */
2660 if (sas_device_priv_data->sas_target->flags &
2661 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2662 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2663 sas_device = _scsih_sas_device_find_by_handle(ioc,
2664 sas_device_priv_data->sas_target->handle);
2666 handle = sas_device->volume_handle;
2667 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2669 handle = sas_device_priv_data->sas_target->handle;
2672 scmd->result = DID_RESET << 16;
2677 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2678 scmd->device->id, scmd->device->lun,
2679 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2682 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2683 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2688 * _scsih_target_reset - eh threads main target reset routine
2689 * @scmd: pointer to scsi command object
2691 * Returns SUCCESS if command aborted else FAILED
2694 _scsih_target_reset(struct scsi_cmnd *scmd)
2696 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2697 struct MPT2SAS_DEVICE *sas_device_priv_data;
2698 struct _sas_device *sas_device;
2699 unsigned long flags;
2702 struct scsi_target *starget = scmd->device->sdev_target;
2704 starget_printk(KERN_INFO, starget, "attempting target reset! "
2705 "scmd(%p)\n", scmd);
2706 _scsih_tm_display_info(ioc, scmd);
2708 sas_device_priv_data = scmd->device->hostdata;
2709 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2710 starget_printk(KERN_INFO, starget, "target been deleted! "
2711 "scmd(%p)\n", scmd);
2712 scmd->result = DID_NO_CONNECT << 16;
2713 scmd->scsi_done(scmd);
2718 /* for hidden raid components obtain the volume_handle */
2720 if (sas_device_priv_data->sas_target->flags &
2721 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2722 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2723 sas_device = _scsih_sas_device_find_by_handle(ioc,
2724 sas_device_priv_data->sas_target->handle);
2726 handle = sas_device->volume_handle;
2727 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2729 handle = sas_device_priv_data->sas_target->handle;
2732 scmd->result = DID_RESET << 16;
2737 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2738 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2742 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2743 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2748 * _scsih_host_reset - eh threads main host reset routine
2749 * @scmd: pointer to scsi command object
2751 * Returns SUCCESS if command aborted else FAILED
2754 _scsih_host_reset(struct scsi_cmnd *scmd)
2756 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2759 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2761 scsi_print_command(scmd);
2763 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2765 r = (retval < 0) ? FAILED : SUCCESS;
2766 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2767 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2773 * _scsih_fw_event_add - insert and queue up fw_event
2774 * @ioc: per adapter object
2775 * @fw_event: object describing the event
2776 * Context: This function will acquire ioc->fw_event_lock.
2778 * This adds the firmware event object into link list, then queues it up to
2779 * be processed from user context.
2784 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2786 unsigned long flags;
2788 if (ioc->firmware_event_thread == NULL)
2791 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2792 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2793 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2794 queue_delayed_work(ioc->firmware_event_thread,
2795 &fw_event->delayed_work, 0);
2796 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2800 * _scsih_fw_event_free - delete fw_event
2801 * @ioc: per adapter object
2802 * @fw_event: object describing the event
2803 * Context: This function will acquire ioc->fw_event_lock.
2805 * This removes firmware event object from link list, frees associated memory.
2810 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2813 unsigned long flags;
2815 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2816 list_del(&fw_event->list);
2818 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2823 * _scsih_error_recovery_delete_devices - remove devices not responding
2824 * @ioc: per adapter object
2829 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2831 struct fw_event_work *fw_event;
2833 if (ioc->is_driver_loading)
2836 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2840 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2841 fw_event->ioc = ioc;
2842 _scsih_fw_event_add(ioc, fw_event);
2846 * mpt2sas_port_enable_complete - port enable completed (fake event)
2847 * @ioc: per adapter object
2852 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2854 struct fw_event_work *fw_event;
2856 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2859 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2860 fw_event->ioc = ioc;
2861 _scsih_fw_event_add(ioc, fw_event);
2865 * _scsih_fw_event_cleanup_queue - cleanup event queue
2866 * @ioc: per adapter object
2868 * Walk the firmware event queue, either killing timers, or waiting
2869 * for outstanding events to complete
2874 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2876 struct fw_event_work *fw_event, *next;
2878 if (list_empty(&ioc->fw_event_list) ||
2879 !ioc->firmware_event_thread || in_interrupt())
2882 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2883 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2884 _scsih_fw_event_free(ioc, fw_event);
2891 * _scsih_ublock_io_all_device - unblock every device
2892 * @ioc: per adapter object
2894 * change the device state from block to running
2897 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2899 struct MPT2SAS_DEVICE *sas_device_priv_data;
2900 struct scsi_device *sdev;
2902 shost_for_each_device(sdev, ioc->shost) {
2903 sas_device_priv_data = sdev->hostdata;
2904 if (!sas_device_priv_data)
2906 if (!sas_device_priv_data->block)
2908 sas_device_priv_data->block = 0;
2909 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2911 sas_device_priv_data->sas_target->handle));
2912 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2916 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2917 * @ioc: per adapter object
2918 * @handle: device handle
2920 * During device pull we need to appropiately set the sdev state.
2923 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
2925 struct MPT2SAS_DEVICE *sas_device_priv_data;
2926 struct scsi_device *sdev;
2928 shost_for_each_device(sdev, ioc->shost) {
2929 sas_device_priv_data = sdev->hostdata;
2930 if (!sas_device_priv_data)
2932 if (!sas_device_priv_data->block)
2934 if (sas_device_priv_data->sas_target->sas_address ==
2936 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2937 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2938 "sas address(0x%016llx)\n", ioc->name,
2939 (unsigned long long)sas_address));
2940 sas_device_priv_data->block = 0;
2941 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2947 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2948 * @ioc: per adapter object
2949 * @handle: device handle
2951 * During device pull we need to appropiately set the sdev state.
2954 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2956 struct MPT2SAS_DEVICE *sas_device_priv_data;
2957 struct scsi_device *sdev;
2959 shost_for_each_device(sdev, ioc->shost) {
2960 sas_device_priv_data = sdev->hostdata;
2961 if (!sas_device_priv_data)
2963 if (sas_device_priv_data->block)
2965 sas_device_priv_data->block = 1;
2966 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2968 sas_device_priv_data->sas_target->handle));
2969 scsi_internal_device_block(sdev);
2975 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2976 * @ioc: per adapter object
2977 * @handle: device handle
2979 * During device pull we need to appropiately set the sdev state.
2982 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2984 struct MPT2SAS_DEVICE *sas_device_priv_data;
2985 struct scsi_device *sdev;
2987 shost_for_each_device(sdev, ioc->shost) {
2988 sas_device_priv_data = sdev->hostdata;
2989 if (!sas_device_priv_data)
2991 if (sas_device_priv_data->block)
2993 if (sas_device_priv_data->sas_target->handle == handle) {
2994 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2995 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2996 "handle(0x%04x)\n", ioc->name, handle));
2997 sas_device_priv_data->block = 1;
2998 scsi_internal_device_block(sdev);
3004 * _scsih_block_io_to_children_attached_to_ex
3005 * @ioc: per adapter object
3006 * @sas_expander: the sas_device object
3008 * This routine set sdev state to SDEV_BLOCK for all devices
3009 * attached to this expander. This function called when expander is
3013 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3014 struct _sas_node *sas_expander)
3016 struct _sas_port *mpt2sas_port;
3017 struct _sas_device *sas_device;
3018 struct _sas_node *expander_sibling;
3019 unsigned long flags;
3024 list_for_each_entry(mpt2sas_port,
3025 &sas_expander->sas_port_list, port_list) {
3026 if (mpt2sas_port->remote_identify.device_type ==
3028 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3030 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3031 mpt2sas_port->remote_identify.sas_address);
3033 set_bit(sas_device->handle,
3034 ioc->blocking_handles);
3035 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3039 list_for_each_entry(mpt2sas_port,
3040 &sas_expander->sas_port_list, port_list) {
3042 if (mpt2sas_port->remote_identify.device_type ==
3043 SAS_EDGE_EXPANDER_DEVICE ||
3044 mpt2sas_port->remote_identify.device_type ==
3045 SAS_FANOUT_EXPANDER_DEVICE) {
3047 mpt2sas_scsih_expander_find_by_sas_address(
3048 ioc, mpt2sas_port->remote_identify.sas_address);
3049 _scsih_block_io_to_children_attached_to_ex(ioc,
3056 * _scsih_block_io_to_children_attached_directly
3057 * @ioc: per adapter object
3058 * @event_data: topology change event data
3060 * This routine set sdev state to SDEV_BLOCK for all devices
3061 * direct attached during device pull.
3064 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3065 Mpi2EventDataSasTopologyChangeList_t *event_data)
3072 for (i = 0; i < event_data->NumEntries; i++) {
3073 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3076 phy_number = event_data->StartPhyNum + i;
3077 reason_code = event_data->PHY[i].PhyStatus &
3078 MPI2_EVENT_SAS_TOPO_RC_MASK;
3079 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3080 _scsih_block_io_device(ioc, handle);
3085 * _scsih_tm_tr_send - send task management request
3086 * @ioc: per adapter object
3087 * @handle: device handle
3088 * Context: interrupt time.
3090 * This code is to initiate the device removal handshake protocol
3091 * with controller firmware. This function will issue target reset
3092 * using high priority request queue. It will send a sas iounit
3093 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3095 * This is designed to send muliple task management request at the same
3096 * time to the fifo. If the fifo is full, we will append the request,
3097 * and process it in a future completion.
3100 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3102 Mpi2SCSITaskManagementRequest_t *mpi_request;
3104 struct _sas_device *sas_device;
3105 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3106 u64 sas_address = 0;
3107 unsigned long flags;
3108 struct _tr_list *delayed_tr;
3111 if (ioc->remove_host) {
3112 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3113 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3115 } else if (ioc->pci_error_recovery) {
3116 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3117 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3121 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3122 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3123 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3124 "operational: handle(0x%04x)\n", __func__, ioc->name,
3129 /* if PD, then return */
3130 if (test_bit(handle, ioc->pd_handles))
3133 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3134 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3135 if (sas_device && sas_device->starget &&
3136 sas_device->starget->hostdata) {
3137 sas_target_priv_data = sas_device->starget->hostdata;
3138 sas_target_priv_data->deleted = 1;
3139 sas_address = sas_device->sas_address;
3141 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3143 if (sas_target_priv_data) {
3144 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3145 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3146 (unsigned long long)sas_address));
3147 _scsih_ublock_io_device(ioc, sas_address);
3148 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3151 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3153 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3156 INIT_LIST_HEAD(&delayed_tr->list);
3157 delayed_tr->handle = handle;
3158 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3159 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3160 "DELAYED:tr:handle(0x%04x), (open)\n",
3161 ioc->name, handle));
3165 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3166 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3167 ioc->tm_tr_cb_idx));
3168 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3169 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3170 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3171 mpi_request->DevHandle = cpu_to_le16(handle);
3172 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3173 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3179 * _scsih_sas_control_complete - completion routine
3180 * @ioc: per adapter object
3181 * @smid: system request message index
3182 * @msix_index: MSIX table index supplied by the OS
3183 * @reply: reply message frame(lower 32bit addr)
3184 * Context: interrupt time.
3186 * This is the sas iounit control completion routine.
3187 * This code is part of the code to initiate the device removal
3188 * handshake protocol with controller firmware.
3190 * Return 1 meaning mf should be freed from _base_interrupt
3191 * 0 means the mf is freed from this function.
3194 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3195 u8 msix_index, u32 reply)
3197 Mpi2SasIoUnitControlReply_t *mpi_reply =
3198 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3199 if (likely(mpi_reply)) {
3200 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3201 "sc_complete:handle(0x%04x), (open) "
3202 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3203 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3204 le16_to_cpu(mpi_reply->IOCStatus),
3205 le32_to_cpu(mpi_reply->IOCLogInfo)));
3207 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3208 ioc->name, __FILE__, __LINE__, __func__);
3214 * _scsih_tm_tr_volume_send - send target reset request for volumes
3215 * @ioc: per adapter object
3216 * @handle: device handle
3217 * Context: interrupt time.
3219 * This is designed to send muliple task management request at the same
3220 * time to the fifo. If the fifo is full, we will append the request,
3221 * and process it in a future completion.
3224 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3226 Mpi2SCSITaskManagementRequest_t *mpi_request;
3228 struct _tr_list *delayed_tr;
3230 if (ioc->shost_recovery || ioc->remove_host ||
3231 ioc->pci_error_recovery) {
3232 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3233 "progress!\n", __func__, ioc->name));
3237 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3239 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3242 INIT_LIST_HEAD(&delayed_tr->list);
3243 delayed_tr->handle = handle;
3244 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3245 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3246 "DELAYED:tr:handle(0x%04x), (open)\n",
3247 ioc->name, handle));
3251 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3252 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3253 ioc->tm_tr_volume_cb_idx));
3254 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3255 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3256 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3257 mpi_request->DevHandle = cpu_to_le16(handle);
3258 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3259 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3263 * _scsih_tm_volume_tr_complete - target reset completion
3264 * @ioc: per adapter object
3265 * @smid: system request message index
3266 * @msix_index: MSIX table index supplied by the OS
3267 * @reply: reply message frame(lower 32bit addr)
3268 * Context: interrupt time.
3270 * Return 1 meaning mf should be freed from _base_interrupt
3271 * 0 means the mf is freed from this function.
3274 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3275 u8 msix_index, u32 reply)
3278 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3279 Mpi2SCSITaskManagementReply_t *mpi_reply =
3280 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3282 if (ioc->shost_recovery || ioc->remove_host ||
3283 ioc->pci_error_recovery) {
3284 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3285 "progress!\n", __func__, ioc->name));
3288 if (unlikely(!mpi_reply)) {
3289 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3290 ioc->name, __FILE__, __LINE__, __func__);
3293 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3294 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3295 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3296 dewtprintk(ioc, printk("spurious interrupt: "
3297 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3298 le16_to_cpu(mpi_reply->DevHandle), smid));
3302 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3303 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3304 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3305 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3306 le32_to_cpu(mpi_reply->IOCLogInfo),
3307 le32_to_cpu(mpi_reply->TerminationCount)));
3309 return _scsih_check_for_pending_tm(ioc, smid);
3313 * _scsih_tm_tr_complete -
3314 * @ioc: per adapter object
3315 * @smid: system request message index
3316 * @msix_index: MSIX table index supplied by the OS
3317 * @reply: reply message frame(lower 32bit addr)
3318 * Context: interrupt time.
3320 * This is the target reset completion routine.
3321 * This code is part of the code to initiate the device removal
3322 * handshake protocol with controller firmware.
3323 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3325 * Return 1 meaning mf should be freed from _base_interrupt
3326 * 0 means the mf is freed from this function.
3329 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3333 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3334 Mpi2SCSITaskManagementReply_t *mpi_reply =
3335 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3336 Mpi2SasIoUnitControlRequest_t *mpi_request;
3340 if (ioc->remove_host) {
3341 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3342 "removed\n", __func__, ioc->name));
3344 } else if (ioc->pci_error_recovery) {
3345 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3346 "error recovery\n", __func__, ioc->name));
3349 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3350 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3351 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3352 "operational\n", __func__, ioc->name));
3355 if (unlikely(!mpi_reply)) {
3356 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3357 ioc->name, __FILE__, __LINE__, __func__);
3360 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3361 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3362 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3363 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3364 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3365 le16_to_cpu(mpi_reply->DevHandle), smid));
3369 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3370 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3371 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3372 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3373 le32_to_cpu(mpi_reply->IOCLogInfo),
3374 le32_to_cpu(mpi_reply->TerminationCount)));
3376 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3377 if (!smid_sas_ctrl) {
3378 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3379 ioc->name, __func__);
3383 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3384 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3385 ioc->tm_sas_control_cb_idx));
3386 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3387 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3388 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3389 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3390 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3391 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3393 return _scsih_check_for_pending_tm(ioc, smid);
3397 * _scsih_check_for_pending_tm - check for pending task management
3398 * @ioc: per adapter object
3399 * @smid: system request message index
3401 * This will check delayed target reset list, and feed the
3404 * Return 1 meaning mf should be freed from _base_interrupt
3405 * 0 means the mf is freed from this function.
3408 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3410 struct _tr_list *delayed_tr;
3412 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3413 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3414 struct _tr_list, list);
3415 mpt2sas_base_free_smid(ioc, smid);
3416 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3417 list_del(&delayed_tr->list);
3422 if (!list_empty(&ioc->delayed_tr_list)) {
3423 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3424 struct _tr_list, list);
3425 mpt2sas_base_free_smid(ioc, smid);
3426 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3427 list_del(&delayed_tr->list);
3436 * _scsih_check_topo_delete_events - sanity check on topo events
3437 * @ioc: per adapter object
3438 * @event_data: the event data payload
3440 * This routine added to better handle cable breaker.
3442 * This handles the case where driver receives multiple expander
3443 * add and delete events in a single shot. When there is a delete event
3444 * the routine will void any pending add events waiting in the event queue.
3449 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3450 Mpi2EventDataSasTopologyChangeList_t *event_data)
3452 struct fw_event_work *fw_event;
3453 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3454 u16 expander_handle;
3455 struct _sas_node *sas_expander;
3456 unsigned long flags;
3460 for (i = 0 ; i < event_data->NumEntries; i++) {
3461 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3464 reason_code = event_data->PHY[i].PhyStatus &
3465 MPI2_EVENT_SAS_TOPO_RC_MASK;
3466 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3467 _scsih_tm_tr_send(ioc, handle);
3470 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3471 if (expander_handle < ioc->sas_hba.num_phys) {
3472 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3475 if (event_data->ExpStatus ==
3476 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3477 /* put expander attached devices into blocking state */
3478 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3479 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3481 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3482 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3484 handle = find_first_bit(ioc->blocking_handles,
3485 ioc->facts.MaxDevHandle);
3486 if (handle < ioc->facts.MaxDevHandle)
3487 _scsih_block_io_device(ioc, handle);
3488 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3489 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3490 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3492 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3495 /* mark ignore flag for pending events */
3496 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3497 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3498 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3501 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3502 fw_event->event_data;
3503 if (local_event_data->ExpStatus ==
3504 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3505 local_event_data->ExpStatus ==
3506 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3507 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3510 "setting ignoring flag\n", ioc->name));
3511 fw_event->ignore = 1;
3515 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3519 * _scsih_set_volume_delete_flag - setting volume delete flag
3520 * @ioc: per adapter object
3521 * @handle: device handle
3527 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3529 struct _raid_device *raid_device;
3530 struct MPT2SAS_TARGET *sas_target_priv_data;
3531 unsigned long flags;
3533 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3534 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3535 if (raid_device && raid_device->starget &&
3536 raid_device->starget->hostdata) {
3537 sas_target_priv_data =
3538 raid_device->starget->hostdata;
3539 sas_target_priv_data->deleted = 1;
3540 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3541 "setting delete flag: handle(0x%04x), "
3542 "wwid(0x%016llx)\n", ioc->name, handle,
3543 (unsigned long long) raid_device->wwid));
3545 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3549 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3550 * @handle: input handle
3551 * @a: handle for volume a
3552 * @b: handle for volume b
3554 * IR firmware only supports two raid volumes. The purpose of this
3555 * routine is to set the volume handle in either a or b. When the given
3556 * input handle is non-zero, or when a and b have not been set before.
3559 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3561 if (!handle || handle == *a || handle == *b)
3570 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3571 * @ioc: per adapter object
3572 * @event_data: the event data payload
3573 * Context: interrupt time.
3575 * This routine will send target reset to volume, followed by target
3576 * resets to the PDs. This is called when a PD has been removed, or
3577 * volume has been deleted or removed. When the target reset is sent
3578 * to volume, the PD target resets need to be queued to start upon
3579 * completion of the volume target reset.
3584 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3585 Mpi2EventDataIrConfigChangeList_t *event_data)
3587 Mpi2EventIrConfigElement_t *element;
3589 u16 handle, volume_handle, a, b;
3590 struct _tr_list *delayed_tr;
3595 if (ioc->is_warpdrive)
3598 /* Volume Resets for Deleted or Removed */
3599 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3600 for (i = 0; i < event_data->NumElements; i++, element++) {
3601 if (element->ReasonCode ==
3602 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3603 element->ReasonCode ==
3604 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3605 volume_handle = le16_to_cpu(element->VolDevHandle);
3606 _scsih_set_volume_delete_flag(ioc, volume_handle);
3607 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3611 /* Volume Resets for UNHIDE events */
3612 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3613 for (i = 0; i < event_data->NumElements; i++, element++) {
3614 if (le32_to_cpu(event_data->Flags) &
3615 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3617 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3618 volume_handle = le16_to_cpu(element->VolDevHandle);
3619 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3624 _scsih_tm_tr_volume_send(ioc, a);
3626 _scsih_tm_tr_volume_send(ioc, b);
3628 /* PD target resets */
3629 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3630 for (i = 0; i < event_data->NumElements; i++, element++) {
3631 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3633 handle = le16_to_cpu(element->PhysDiskDevHandle);
3634 volume_handle = le16_to_cpu(element->VolDevHandle);
3635 clear_bit(handle, ioc->pd_handles);
3637 _scsih_tm_tr_send(ioc, handle);
3638 else if (volume_handle == a || volume_handle == b) {
3639 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3640 BUG_ON(!delayed_tr);
3641 INIT_LIST_HEAD(&delayed_tr->list);
3642 delayed_tr->handle = handle;
3643 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3644 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3645 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3648 _scsih_tm_tr_send(ioc, handle);
3654 * _scsih_check_volume_delete_events - set delete flag for volumes
3655 * @ioc: per adapter object
3656 * @event_data: the event data payload
3657 * Context: interrupt time.
3659 * This will handle the case when the cable connected to entire volume is
3660 * pulled. We will take care of setting the deleted flag so normal IO will
3666 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3667 Mpi2EventDataIrVolume_t *event_data)
3671 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3673 state = le32_to_cpu(event_data->NewValue);
3674 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3675 MPI2_RAID_VOL_STATE_FAILED)
3676 _scsih_set_volume_delete_flag(ioc,
3677 le16_to_cpu(event_data->VolDevHandle));
3681 * _scsih_flush_running_cmds - completing outstanding commands.
3682 * @ioc: per adapter object
3684 * The flushing out of all pending scmd commands following host reset,
3685 * where all IO is dropped to the floor.
3690 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3692 struct scsi_cmnd *scmd;
3696 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3697 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3701 mpt2sas_base_free_smid(ioc, smid);
3702 scsi_dma_unmap(scmd);
3703 if (ioc->pci_error_recovery)
3704 scmd->result = DID_NO_CONNECT << 16;
3706 scmd->result = DID_RESET << 16;
3707 scmd->scsi_done(scmd);
3709 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3714 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3715 * @scmd: pointer to scsi command object
3716 * @mpi_request: pointer to the SCSI_IO reqest message frame
3718 * Supporting protection 1 and 3.
3723 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3726 unsigned char prot_op = scsi_get_prot_op(scmd);
3727 unsigned char prot_type = scsi_get_prot_type(scmd);
3729 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3732 if (prot_op == SCSI_PROT_READ_STRIP)
3733 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3734 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3735 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3739 switch (prot_type) {
3740 case SCSI_PROT_DIF_TYPE1:
3741 case SCSI_PROT_DIF_TYPE2:
3744 * enable ref/guard checking
3745 * auto increment ref tag
3747 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3748 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3749 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3750 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3751 cpu_to_be32(scsi_get_lba(scmd));
3754 case SCSI_PROT_DIF_TYPE3:
3757 * enable guard checking
3759 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3762 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3763 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3767 * _scsih_eedp_error_handling - return sense code for EEDP errors
3768 * @scmd: pointer to scsi command object
3769 * @ioc_status: ioc status
3774 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3778 switch (ioc_status) {
3779 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3782 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3785 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3793 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3794 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3795 SAM_STAT_CHECK_CONDITION;
3799 * _scsih_scsi_direct_io_get - returns direct io flag
3800 * @ioc: per adapter object
3801 * @smid: system request message index
3803 * Returns the smid stored scmd pointer.
3806 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3808 return ioc->scsi_lookup[smid - 1].direct_io;
3812 * _scsih_scsi_direct_io_set - sets direct io flag
3813 * @ioc: per adapter object
3814 * @smid: system request message index
3815 * @direct_io: Zero or non-zero value to set in the direct_io flag
3820 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3822 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3827 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3828 * @ioc: per adapter object
3829 * @scmd: pointer to scsi command object
3830 * @raid_device: pointer to raid device data structure
3831 * @mpi_request: pointer to the SCSI_IO reqest message frame
3832 * @smid: system request message index
3837 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3838 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3841 sector_t v_lba, p_lba, stripe_off, column, io_size;
3842 u32 stripe_sz, stripe_exp;
3843 u8 num_pds, cmd = scmd->cmnd[0];
3845 if (cmd != READ_10 && cmd != WRITE_10 &&
3846 cmd != READ_16 && cmd != WRITE_16)
3849 if (cmd == READ_10 || cmd == WRITE_10)
3850 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3852 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
3854 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
3856 if (v_lba + io_size - 1 > raid_device->max_lba)
3859 stripe_sz = raid_device->stripe_sz;
3860 stripe_exp = raid_device->stripe_exponent;
3861 stripe_off = v_lba & (stripe_sz - 1);
3863 /* Return unless IO falls within a stripe */
3864 if (stripe_off + io_size > stripe_sz)
3867 num_pds = raid_device->num_pds;
3868 p_lba = v_lba >> stripe_exp;
3869 column = sector_div(p_lba, num_pds);
3870 p_lba = (p_lba << stripe_exp) + stripe_off;
3872 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3874 if (cmd == READ_10 || cmd == WRITE_10)
3875 put_unaligned_be32(lower_32_bits(p_lba),
3876 &mpi_request->CDB.CDB32[2]);
3878 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3880 _scsih_scsi_direct_io_set(ioc, smid, 1);
3884 * _scsih_qcmd - main scsi request entry point
3885 * @scmd: pointer to scsi command object
3886 * @done: function pointer to be invoked on completion
3888 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3890 * Returns 0 on success. If there's a failure, return either:
3891 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3892 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3895 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3897 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
3898 struct MPT2SAS_DEVICE *sas_device_priv_data;
3899 struct MPT2SAS_TARGET *sas_target_priv_data;
3900 struct _raid_device *raid_device;
3901 Mpi2SCSIIORequest_t *mpi_request;
3905 sas_device_priv_data = scmd->device->hostdata;
3906 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3907 scmd->result = DID_NO_CONNECT << 16;
3908 scmd->scsi_done(scmd);
3912 if (ioc->pci_error_recovery || ioc->remove_host) {
3913 scmd->result = DID_NO_CONNECT << 16;
3914 scmd->scsi_done(scmd);
3918 sas_target_priv_data = sas_device_priv_data->sas_target;
3919 /* invalid device handle */
3920 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3921 scmd->result = DID_NO_CONNECT << 16;
3922 scmd->scsi_done(scmd);
3926 /* host recovery or link resets sent via IOCTLs */
3927 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3928 return SCSI_MLQUEUE_HOST_BUSY;
3929 /* device busy with task management */
3930 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3931 return SCSI_MLQUEUE_DEVICE_BUSY;
3932 /* device has been deleted */
3933 else if (sas_target_priv_data->deleted) {
3934 scmd->result = DID_NO_CONNECT << 16;
3935 scmd->scsi_done(scmd);
3939 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3940 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3941 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3942 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3944 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3947 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3948 if (scmd->device->tagged_supported) {
3949 if (scmd->device->ordered_tags)
3950 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3952 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3954 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3956 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3957 /* Make sure Device is not raid volume.
3958 * We do not expose raid functionality to upper layer for warpdrive.
3960 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3961 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3962 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3964 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3966 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3967 ioc->name, __func__);
3970 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3971 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3972 _scsih_setup_eedp(scmd, mpi_request);
3973 if (scmd->cmd_len == 32)
3974 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3975 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3976 if (sas_device_priv_data->sas_target->flags &
3977 MPT_TARGET_FLAGS_RAID_COMPONENT)
3978 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3980 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3981 mpi_request->DevHandle =
3982 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3983 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3984 mpi_request->Control = cpu_to_le32(mpi_control);
3985 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3986 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3987 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3988 mpi_request->SenseBufferLowAddress =
3989 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3990 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3991 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3992 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3993 mpi_request->VF_ID = 0; /* TODO */
3994 mpi_request->VP_ID = 0;
3995 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3997 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3999 if (!mpi_request->DataLength) {
4000 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4002 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4003 mpt2sas_base_free_smid(ioc, smid);
4008 raid_device = sas_target_priv_data->raid_device;
4009 if (raid_device && raid_device->direct_io_enabled)
4010 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4013 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4014 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4015 le16_to_cpu(mpi_request->DevHandle));
4017 mpt2sas_base_put_smid_default(ioc, smid);
4021 return SCSI_MLQUEUE_HOST_BUSY;
4025 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4026 * @sense_buffer: sense data returned by target
4027 * @data: normalized skey/asc/ascq
4032 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4034 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4035 /* descriptor format */
4036 data->skey = sense_buffer[1] & 0x0F;
4037 data->asc = sense_buffer[2];
4038 data->ascq = sense_buffer[3];
4041 data->skey = sense_buffer[2] & 0x0F;
4042 data->asc = sense_buffer[12];
4043 data->ascq = sense_buffer[13];
4047 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4049 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4050 * @ioc: per adapter object
4051 * @scmd: pointer to scsi command object
4052 * @mpi_reply: reply mf payload returned from firmware
4054 * scsi_status - SCSI Status code returned from target device
4055 * scsi_state - state info associated with SCSI_IO determined by ioc
4056 * ioc_status - ioc supplied status info
4061 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4062 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4066 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4067 MPI2_IOCSTATUS_MASK;
4068 u8 scsi_state = mpi_reply->SCSIState;
4069 u8 scsi_status = mpi_reply->SCSIStatus;
4070 char *desc_ioc_state = NULL;
4071 char *desc_scsi_status = NULL;
4072 char *desc_scsi_state = ioc->tmp_string;
4073 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4074 struct _sas_device *sas_device = NULL;
4075 unsigned long flags;
4076 struct scsi_target *starget = scmd->device->sdev_target;
4077 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4078 char *device_str = NULL;
4083 if (ioc->hide_ir_msg)
4084 device_str = "WarpDrive";
4086 device_str = "volume";
4088 if (log_info == 0x31170000)
4091 switch (ioc_status) {
4092 case MPI2_IOCSTATUS_SUCCESS:
4093 desc_ioc_state = "success";
4095 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4096 desc_ioc_state = "invalid function";
4098 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4099 desc_ioc_state = "scsi recovered error";
4101 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4102 desc_ioc_state = "scsi invalid dev handle";
4104 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4105 desc_ioc_state = "scsi device not there";
4107 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4108 desc_ioc_state = "scsi data overrun";
4110 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4111 desc_ioc_state = "scsi data underrun";
4113 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4114 desc_ioc_state = "scsi io data error";
4116 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4117 desc_ioc_state = "scsi protocol error";
4119 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4120 desc_ioc_state = "scsi task terminated";
4122 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4123 desc_ioc_state = "scsi residual mismatch";
4125 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4126 desc_ioc_state = "scsi task mgmt failed";
4128 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4129 desc_ioc_state = "scsi ioc terminated";
4131 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4132 desc_ioc_state = "scsi ext terminated";
4134 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4135 desc_ioc_state = "eedp guard error";
4137 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4138 desc_ioc_state = "eedp ref tag error";
4140 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4141 desc_ioc_state = "eedp app tag error";
4144 desc_ioc_state = "unknown";
4148 switch (scsi_status) {
4149 case MPI2_SCSI_STATUS_GOOD:
4150 desc_scsi_status = "good";
4152 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4153 desc_scsi_status = "check condition";
4155 case MPI2_SCSI_STATUS_CONDITION_MET:
4156 desc_scsi_status = "condition met";
4158 case MPI2_SCSI_STATUS_BUSY:
4159 desc_scsi_status = "busy";
4161 case MPI2_SCSI_STATUS_INTERMEDIATE:
4162 desc_scsi_status = "intermediate";
4164 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4165 desc_scsi_status = "intermediate condmet";
4167 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4168 desc_scsi_status = "reservation conflict";
4170 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4171 desc_scsi_status = "command terminated";
4173 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4174 desc_scsi_status = "task set full";
4176 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4177 desc_scsi_status = "aca active";
4179 case MPI2_SCSI_STATUS_TASK_ABORTED:
4180 desc_scsi_status = "task aborted";
4183 desc_scsi_status = "unknown";
4187 desc_scsi_state[0] = '\0';
4189 desc_scsi_state = " ";
4190 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4191 strcat(desc_scsi_state, "response info ");
4192 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4193 strcat(desc_scsi_state, "state terminated ");
4194 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4195 strcat(desc_scsi_state, "no status ");
4196 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4197 strcat(desc_scsi_state, "autosense failed ");
4198 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4199 strcat(desc_scsi_state, "autosense valid ");
4201 scsi_print_command(scmd);
4203 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4204 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4205 device_str, (unsigned long long)priv_target->sas_address);
4207 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4208 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4209 priv_target->sas_address);
4211 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4212 "phy(%d)\n", ioc->name, sas_device->sas_address,
4214 printk(MPT2SAS_WARN_FMT
4215 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4216 ioc->name, sas_device->enclosure_logical_id,
4219 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4222 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4223 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4224 desc_ioc_state, ioc_status, smid);
4225 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4226 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4227 scsi_get_resid(scmd));
4228 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4229 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4230 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4231 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4232 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4233 scsi_status, desc_scsi_state, scsi_state);
4235 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4236 struct sense_info data;
4237 _scsih_normalize_sense(scmd->sense_buffer, &data);
4238 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4239 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4240 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4243 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4244 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4245 response_bytes = (u8 *)&response_info;
4246 _scsih_response_code(ioc, response_bytes[0]);
4252 * _scsih_turn_on_pfa_led - illuminate PFA LED
4253 * @ioc: per adapter object
4254 * @handle: device handle
4260 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4262 Mpi2SepReply_t mpi_reply;
4263 Mpi2SepRequest_t mpi_request;
4264 struct _sas_device *sas_device;
4266 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4270 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4271 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4272 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4273 mpi_request.SlotStatus =
4274 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4275 mpi_request.DevHandle = cpu_to_le16(handle);
4276 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4277 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4278 &mpi_request)) != 0) {
4279 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4280 __FILE__, __LINE__, __func__);
4283 sas_device->pfa_led_on = 1;
4286 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4287 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4288 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4289 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4290 le32_to_cpu(mpi_reply.IOCLogInfo)));
4296 * _scsih_turn_off_pfa_led - turn off PFA LED
4297 * @ioc: per adapter object
4298 * @sas_device: sas device whose PFA LED has to turned off
4304 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4305 struct _sas_device *sas_device)
4307 Mpi2SepReply_t mpi_reply;
4308 Mpi2SepRequest_t mpi_request;
4310 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4311 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4312 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4313 mpi_request.SlotStatus = 0;
4314 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4315 mpi_request.DevHandle = 0;
4316 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4317 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4318 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4319 &mpi_request)) != 0) {
4320 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4321 __FILE__, __LINE__, __func__);
4325 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4326 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4327 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4328 le16_to_cpu(mpi_reply.IOCStatus),
4329 le32_to_cpu(mpi_reply.IOCLogInfo)));
4335 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4336 * @ioc: per adapter object
4337 * @handle: device handle
4338 * Context: interrupt.
4343 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4345 struct fw_event_work *fw_event;
4347 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4350 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
4351 fw_event->device_handle = handle;
4352 fw_event->ioc = ioc;
4353 _scsih_fw_event_add(ioc, fw_event);
4357 * _scsih_smart_predicted_fault - process smart errors
4358 * @ioc: per adapter object
4359 * @handle: device handle
4360 * Context: interrupt.
4365 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4367 struct scsi_target *starget;
4368 struct MPT2SAS_TARGET *sas_target_priv_data;
4369 Mpi2EventNotificationReply_t *event_reply;
4370 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4371 struct _sas_device *sas_device;
4373 unsigned long flags;
4375 /* only handle non-raid devices */
4376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4377 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4379 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4382 starget = sas_device->starget;
4383 sas_target_priv_data = starget->hostdata;
4385 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4386 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4387 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4390 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4391 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4393 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4394 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4396 /* insert into event log */
4397 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4398 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4399 event_reply = kzalloc(sz, GFP_ATOMIC);
4401 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4402 ioc->name, __FILE__, __LINE__, __func__);
4406 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4407 event_reply->Event =
4408 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4409 event_reply->MsgLength = sz/4;
4410 event_reply->EventDataLength =
4411 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4412 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4413 event_reply->EventData;
4414 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4415 event_data->ASC = 0x5D;
4416 event_data->DevHandle = cpu_to_le16(handle);
4417 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4418 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4423 * _scsih_io_done - scsi request callback
4424 * @ioc: per adapter object
4425 * @smid: system request message index
4426 * @msix_index: MSIX table index supplied by the OS
4427 * @reply: reply message frame(lower 32bit addr)
4429 * Callback handler when using _scsih_qcmd.
4431 * Return 1 meaning mf should be freed from _base_interrupt
4432 * 0 means the mf is freed from this function.
4435 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4437 Mpi2SCSIIORequest_t *mpi_request;
4438 Mpi2SCSIIOReply_t *mpi_reply;
4439 struct scsi_cmnd *scmd;
4445 struct MPT2SAS_DEVICE *sas_device_priv_data;
4446 u32 response_code = 0;
4447 unsigned long flags;
4449 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4450 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4454 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4456 if (mpi_reply == NULL) {
4457 scmd->result = DID_OK << 16;
4461 sas_device_priv_data = scmd->device->hostdata;
4462 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4463 sas_device_priv_data->sas_target->deleted) {
4464 scmd->result = DID_NO_CONNECT << 16;
4467 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4469 * WARPDRIVE: If direct_io is set then it is directIO,
4470 * the failed direct I/O should be redirected to volume
4472 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4473 ((ioc_status & MPI2_IOCSTATUS_MASK)
4474 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4475 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4476 ioc->scsi_lookup[smid - 1].scmd = scmd;
4477 _scsih_scsi_direct_io_set(ioc, smid, 0);
4478 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4479 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4480 mpi_request->DevHandle =
4481 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4482 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4483 sas_device_priv_data->sas_target->handle);
4488 /* turning off TLR */
4489 scsi_state = mpi_reply->SCSIState;
4490 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4492 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4493 if (!sas_device_priv_data->tlr_snoop_check) {
4494 sas_device_priv_data->tlr_snoop_check++;
4495 /* Make sure Device is not raid volume.
4496 * We do not expose raid functionality to upper layer for warpdrive.
4498 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4499 sas_is_tlr_enabled(scmd->device) &&
4500 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4501 sas_disable_tlr(scmd->device);
4502 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4506 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4507 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4508 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4509 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4512 ioc_status &= MPI2_IOCSTATUS_MASK;
4513 scsi_status = mpi_reply->SCSIStatus;
4515 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4516 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4517 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4518 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4519 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4522 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4523 struct sense_info data;
4524 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4526 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4527 le32_to_cpu(mpi_reply->SenseCount));
4528 memcpy(scmd->sense_buffer, sense_data, sz);
4529 _scsih_normalize_sense(scmd->sense_buffer, &data);
4530 /* failure prediction threshold exceeded */
4531 if (data.asc == 0x5D)
4532 _scsih_smart_predicted_fault(ioc,
4533 le16_to_cpu(mpi_reply->DevHandle));
4536 switch (ioc_status) {
4537 case MPI2_IOCSTATUS_BUSY:
4538 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4539 scmd->result = SAM_STAT_BUSY;
4542 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4543 scmd->result = DID_NO_CONNECT << 16;
4546 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4547 if (sas_device_priv_data->block) {
4548 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4551 scmd->result = DID_SOFT_ERROR << 16;
4553 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4554 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4555 scmd->result = DID_RESET << 16;
4558 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4559 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4560 scmd->result = DID_SOFT_ERROR << 16;
4562 scmd->result = (DID_OK << 16) | scsi_status;
4565 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4566 scmd->result = (DID_OK << 16) | scsi_status;
4568 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4571 if (xfer_cnt < scmd->underflow) {
4572 if (scsi_status == SAM_STAT_BUSY)
4573 scmd->result = SAM_STAT_BUSY;
4575 scmd->result = DID_SOFT_ERROR << 16;
4576 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4577 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4578 scmd->result = DID_SOFT_ERROR << 16;
4579 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4580 scmd->result = DID_RESET << 16;
4581 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4582 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4583 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4584 scmd->result = (DRIVER_SENSE << 24) |
4585 SAM_STAT_CHECK_CONDITION;
4586 scmd->sense_buffer[0] = 0x70;
4587 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4588 scmd->sense_buffer[12] = 0x20;
4589 scmd->sense_buffer[13] = 0;
4593 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4594 scsi_set_resid(scmd, 0);
4595 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4596 case MPI2_IOCSTATUS_SUCCESS:
4597 scmd->result = (DID_OK << 16) | scsi_status;
4598 if (response_code ==
4599 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4600 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4601 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4602 scmd->result = DID_SOFT_ERROR << 16;
4603 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4604 scmd->result = DID_RESET << 16;
4607 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4608 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4609 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4610 _scsih_eedp_error_handling(scmd, ioc_status);
4612 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4613 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4614 case MPI2_IOCSTATUS_INVALID_SGL:
4615 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4616 case MPI2_IOCSTATUS_INVALID_FIELD:
4617 case MPI2_IOCSTATUS_INVALID_STATE:
4618 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4619 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4621 scmd->result = DID_SOFT_ERROR << 16;
4626 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4627 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4628 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4632 scsi_dma_unmap(scmd);
4633 scmd->scsi_done(scmd);
4638 * _scsih_sas_host_refresh - refreshing sas host object contents
4639 * @ioc: per adapter object
4642 * During port enable, fw will send topology events for every device. Its
4643 * possible that the handles may change from the previous setting, so this
4644 * code keeping handles updating if changed.
4649 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4654 Mpi2ConfigReply_t mpi_reply;
4655 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4656 u16 attached_handle;
4659 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4660 "updating handles for sas_host(0x%016llx)\n",
4661 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4663 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4664 * sizeof(Mpi2SasIOUnit0PhyData_t));
4665 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4666 if (!sas_iounit_pg0) {
4667 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4668 ioc->name, __FILE__, __LINE__, __func__);
4672 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4673 sas_iounit_pg0, sz)) != 0)
4675 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4676 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4678 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4679 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4681 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4682 PhyData[0].ControllerDevHandle);
4683 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4684 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4686 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4687 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4688 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4689 attached_handle, i, link_rate);
4692 kfree(sas_iounit_pg0);
4696 * _scsih_sas_host_add - create sas host object
4697 * @ioc: per adapter object
4699 * Creating host side data object, stored in ioc->sas_hba
4704 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4707 Mpi2ConfigReply_t mpi_reply;
4708 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4709 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4710 Mpi2SasPhyPage0_t phy_pg0;
4711 Mpi2SasDevicePage0_t sas_device_pg0;
4712 Mpi2SasEnclosurePage0_t enclosure_pg0;
4715 u16 device_missing_delay;
4717 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4718 if (!ioc->sas_hba.num_phys) {
4719 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4720 ioc->name, __FILE__, __LINE__, __func__);
4724 /* sas_iounit page 0 */
4725 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4726 sizeof(Mpi2SasIOUnit0PhyData_t));
4727 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4728 if (!sas_iounit_pg0) {
4729 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4730 ioc->name, __FILE__, __LINE__, __func__);
4733 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4734 sas_iounit_pg0, sz))) {
4735 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4736 ioc->name, __FILE__, __LINE__, __func__);
4739 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4740 MPI2_IOCSTATUS_MASK;
4741 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4742 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4743 ioc->name, __FILE__, __LINE__, __func__);
4747 /* sas_iounit page 1 */
4748 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4749 sizeof(Mpi2SasIOUnit1PhyData_t));
4750 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4751 if (!sas_iounit_pg1) {
4752 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4753 ioc->name, __FILE__, __LINE__, __func__);
4756 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4757 sas_iounit_pg1, sz))) {
4758 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4759 ioc->name, __FILE__, __LINE__, __func__);
4762 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4763 MPI2_IOCSTATUS_MASK;
4764 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4765 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4766 ioc->name, __FILE__, __LINE__, __func__);
4770 ioc->io_missing_delay =
4771 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4772 device_missing_delay =
4773 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4774 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4775 ioc->device_missing_delay = (device_missing_delay &
4776 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4778 ioc->device_missing_delay = device_missing_delay &
4779 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4781 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4782 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4783 sizeof(struct _sas_phy), GFP_KERNEL);
4784 if (!ioc->sas_hba.phy) {
4785 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4786 ioc->name, __FILE__, __LINE__, __func__);
4789 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4790 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4792 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4793 ioc->name, __FILE__, __LINE__, __func__);
4796 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4797 MPI2_IOCSTATUS_MASK;
4798 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4799 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4800 ioc->name, __FILE__, __LINE__, __func__);
4805 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4806 PhyData[0].ControllerDevHandle);
4807 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4808 ioc->sas_hba.phy[i].phy_id = i;
4809 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4810 phy_pg0, ioc->sas_hba.parent_dev);
4812 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4813 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4814 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4815 ioc->name, __FILE__, __LINE__, __func__);
4818 ioc->sas_hba.enclosure_handle =
4819 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4820 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4821 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4822 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4823 (unsigned long long) ioc->sas_hba.sas_address,
4824 ioc->sas_hba.num_phys) ;
4826 if (ioc->sas_hba.enclosure_handle) {
4827 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4829 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4830 ioc->sas_hba.enclosure_handle))) {
4831 ioc->sas_hba.enclosure_logical_id =
4832 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4837 kfree(sas_iounit_pg1);
4838 kfree(sas_iounit_pg0);
4842 * _scsih_expander_add - creating expander object
4843 * @ioc: per adapter object
4844 * @handle: expander handle
4846 * Creating expander object, stored in ioc->sas_expander_list.
4848 * Return 0 for success, else error.
4851 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4853 struct _sas_node *sas_expander;
4854 Mpi2ConfigReply_t mpi_reply;
4855 Mpi2ExpanderPage0_t expander_pg0;
4856 Mpi2ExpanderPage1_t expander_pg1;
4857 Mpi2SasEnclosurePage0_t enclosure_pg0;
4860 u64 sas_address, sas_address_parent = 0;
4862 unsigned long flags;
4863 struct _sas_port *mpt2sas_port = NULL;
4869 if (ioc->shost_recovery || ioc->pci_error_recovery)
4872 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4873 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4879 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4880 MPI2_IOCSTATUS_MASK;
4881 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4882 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4883 ioc->name, __FILE__, __LINE__, __func__);
4887 /* handle out of order topology events */
4888 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4889 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4891 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4892 ioc->name, __FILE__, __LINE__, __func__);
4895 if (sas_address_parent != ioc->sas_hba.sas_address) {
4896 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4897 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4898 sas_address_parent);
4899 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4900 if (!sas_expander) {
4901 rc = _scsih_expander_add(ioc, parent_handle);
4907 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4908 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4909 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4911 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4916 sas_expander = kzalloc(sizeof(struct _sas_node),
4918 if (!sas_expander) {
4919 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4920 ioc->name, __FILE__, __LINE__, __func__);
4924 sas_expander->handle = handle;
4925 sas_expander->num_phys = expander_pg0.NumPhys;
4926 sas_expander->sas_address_parent = sas_address_parent;
4927 sas_expander->sas_address = sas_address;
4929 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4930 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4931 handle, parent_handle, (unsigned long long)
4932 sas_expander->sas_address, sas_expander->num_phys);
4934 if (!sas_expander->num_phys)
4936 sas_expander->phy = kcalloc(sas_expander->num_phys,
4937 sizeof(struct _sas_phy), GFP_KERNEL);
4938 if (!sas_expander->phy) {
4939 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4940 ioc->name, __FILE__, __LINE__, __func__);
4945 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4946 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4947 sas_address_parent);
4948 if (!mpt2sas_port) {
4949 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4950 ioc->name, __FILE__, __LINE__, __func__);
4954 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4956 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4957 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4958 &expander_pg1, i, handle))) {
4959 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4960 ioc->name, __FILE__, __LINE__, __func__);
4964 sas_expander->phy[i].handle = handle;
4965 sas_expander->phy[i].phy_id = i;
4967 if ((mpt2sas_transport_add_expander_phy(ioc,
4968 &sas_expander->phy[i], expander_pg1,
4969 sas_expander->parent_dev))) {
4970 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4971 ioc->name, __FILE__, __LINE__, __func__);
4977 if (sas_expander->enclosure_handle) {
4978 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4979 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4980 sas_expander->enclosure_handle))) {
4981 sas_expander->enclosure_logical_id =
4982 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4986 _scsih_expander_node_add(ioc, sas_expander);
4992 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4993 sas_address_parent);
4994 kfree(sas_expander);
4999 * _scsih_done - scsih callback handler.
5000 * @ioc: per adapter object
5001 * @smid: system request message index
5002 * @msix_index: MSIX table index supplied by the OS
5003 * @reply: reply message frame(lower 32bit addr)
5005 * Callback handler when sending internal generated message frames.
5006 * The callback index passed is `ioc->scsih_cb_idx`
5008 * Return 1 meaning mf should be freed from _base_interrupt
5009 * 0 means the mf is freed from this function.
5012 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5014 MPI2DefaultReply_t *mpi_reply;
5016 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5017 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5019 if (ioc->scsih_cmds.smid != smid)
5021 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5023 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5024 mpi_reply->MsgLength*4);
5025 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5027 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5028 complete(&ioc->scsih_cmds.done);
5033 * mpt2sas_expander_remove - removing expander object
5034 * @ioc: per adapter object
5035 * @sas_address: expander sas_address
5040 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5042 struct _sas_node *sas_expander;
5043 unsigned long flags;
5045 if (ioc->shost_recovery)
5048 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5049 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5052 list_del(&sas_expander->list);
5053 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5055 _scsih_expander_node_remove(ioc, sas_expander);
5059 * _scsih_check_access_status - check access flags
5060 * @ioc: per adapter object
5061 * @sas_address: sas address
5062 * @handle: sas device handle
5063 * @access_flags: errors returned during discovery of the device
5065 * Return 0 for success, else failure
5068 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5069 u16 handle, u8 access_status)
5074 switch (access_status) {
5075 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5076 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5080 desc = "sata capability failed";
5082 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5083 desc = "sata affiliation conflict";
5085 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5086 desc = "route not addressable";
5088 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5089 desc = "smp error not addressable";
5091 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5092 desc = "device blocked";
5094 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5104 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5105 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5106 desc = "sata initialization failed";
5116 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5117 "handle(0x%04x)\n", ioc->name, desc,
5118 (unsigned long long)sas_address, handle);
5123 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5125 Mpi2ConfigReply_t mpi_reply;
5126 Mpi2SasDevicePage0_t sas_device_pg0;
5127 struct _sas_device *sas_device;
5129 unsigned long flags;
5131 struct scsi_target *starget;
5132 struct MPT2SAS_TARGET *sas_target_priv_data;
5136 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5137 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5140 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5141 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5144 /* check if this is end device */
5145 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5146 if (!(_scsih_is_end_device(device_info)))
5149 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5150 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5151 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5155 printk(MPT2SAS_ERR_FMT "device is not present "
5156 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5157 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5161 if (unlikely(sas_device->handle != handle)) {
5162 starget = sas_device->starget;
5163 sas_target_priv_data = starget->hostdata;
5164 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5165 " to (0x%04x)!!!\n", sas_device->handle, handle);
5166 sas_target_priv_data->handle = handle;
5167 sas_device->handle = handle;
5170 /* check if device is present */
5171 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5172 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5173 printk(MPT2SAS_ERR_FMT "device is not present "
5174 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5175 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5179 /* check if there were any issues with discovery */
5180 if (_scsih_check_access_status(ioc, sas_address, handle,
5181 sas_device_pg0.AccessStatus)) {
5182 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5186 _scsih_ublock_io_device(ioc, sas_address);
5191 * _scsih_add_device - creating sas device object
5192 * @ioc: per adapter object
5193 * @handle: sas device handle
5194 * @phy_num: phy number end device attached to
5195 * @is_pd: is this hidden raid component
5197 * Creating end device object, stored in ioc->sas_device_list.
5199 * Returns 0 for success, non-zero for failure.
5202 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5204 Mpi2ConfigReply_t mpi_reply;
5205 Mpi2SasDevicePage0_t sas_device_pg0;
5206 Mpi2SasEnclosurePage0_t enclosure_pg0;
5207 struct _sas_device *sas_device;
5211 unsigned long flags;
5213 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5214 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5215 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5216 ioc->name, __FILE__, __LINE__, __func__);
5220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5221 MPI2_IOCSTATUS_MASK;
5222 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5223 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5224 ioc->name, __FILE__, __LINE__, __func__);
5228 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5230 /* check if device is present */
5231 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5232 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5233 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5234 ioc->name, __FILE__, __LINE__, __func__);
5235 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5236 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5240 /* check if there were any issues with discovery */
5241 if (_scsih_check_access_status(ioc, sas_address, handle,
5242 sas_device_pg0.AccessStatus))
5245 /* check if this is end device */
5246 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5247 if (!(_scsih_is_end_device(device_info))) {
5248 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5249 ioc->name, __FILE__, __LINE__, __func__);
5254 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5255 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5257 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5262 sas_device = kzalloc(sizeof(struct _sas_device),
5265 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5266 ioc->name, __FILE__, __LINE__, __func__);
5270 sas_device->handle = handle;
5271 if (_scsih_get_sas_address(ioc, le16_to_cpu
5272 (sas_device_pg0.ParentDevHandle),
5273 &sas_device->sas_address_parent) != 0)
5274 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5275 ioc->name, __FILE__, __LINE__, __func__);
5276 sas_device->enclosure_handle =
5277 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5279 le16_to_cpu(sas_device_pg0.Slot);
5280 sas_device->device_info = device_info;
5281 sas_device->sas_address = sas_address;
5282 sas_device->phy = sas_device_pg0.PhyNum;
5284 /* get enclosure_logical_id */
5285 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5286 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5287 sas_device->enclosure_handle)))
5288 sas_device->enclosure_logical_id =
5289 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5291 /* get device name */
5292 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5294 if (ioc->wait_for_discovery_to_complete)
5295 _scsih_sas_device_init_add(ioc, sas_device);
5297 _scsih_sas_device_add(ioc, sas_device);
5303 * _scsih_remove_device - removing sas device object
5304 * @ioc: per adapter object
5305 * @sas_device_delete: the sas_device object
5310 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5311 struct _sas_device *sas_device)
5313 struct MPT2SAS_TARGET *sas_target_priv_data;
5315 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5316 (sas_device->pfa_led_on)) {
5317 _scsih_turn_off_pfa_led(ioc, sas_device);
5318 sas_device->pfa_led_on = 0;
5321 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5322 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5323 sas_device->handle, (unsigned long long)
5324 sas_device->sas_address));
5326 if (sas_device->starget && sas_device->starget->hostdata) {
5327 sas_target_priv_data = sas_device->starget->hostdata;
5328 sas_target_priv_data->deleted = 1;
5329 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5330 sas_target_priv_data->handle =
5331 MPT2SAS_INVALID_DEVICE_HANDLE;
5334 if (!ioc->hide_drives)
5335 mpt2sas_transport_port_remove(ioc,
5336 sas_device->sas_address,
5337 sas_device->sas_address_parent);
5339 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5340 "(0x%016llx)\n", ioc->name, sas_device->handle,
5341 (unsigned long long) sas_device->sas_address);
5343 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5344 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5345 sas_device->handle, (unsigned long long)
5346 sas_device->sas_address));
5350 * _scsih_device_remove_by_handle - removing device object by handle
5351 * @ioc: per adapter object
5352 * @handle: device handle
5357 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5359 struct _sas_device *sas_device;
5360 unsigned long flags;
5362 if (ioc->shost_recovery)
5365 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5366 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5368 list_del(&sas_device->list);
5369 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5371 _scsih_remove_device(ioc, sas_device);
5375 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5376 * @ioc: per adapter object
5377 * @sas_address: device sas_address
5382 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5385 struct _sas_device *sas_device;
5386 unsigned long flags;
5388 if (ioc->shost_recovery)
5391 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5392 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5395 list_del(&sas_device->list);
5396 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5398 _scsih_remove_device(ioc, sas_device);
5400 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5402 * _scsih_sas_topology_change_event_debug - debug for topology event
5403 * @ioc: per adapter object
5404 * @event_data: event data payload
5408 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5409 Mpi2EventDataSasTopologyChangeList_t *event_data)
5415 char *status_str = NULL;
5416 u8 link_rate, prev_link_rate;
5418 switch (event_data->ExpStatus) {
5419 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5422 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5423 status_str = "remove";
5425 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5427 status_str = "responding";
5429 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5430 status_str = "remove delay";
5433 status_str = "unknown status";
5436 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5437 ioc->name, status_str);
5438 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5439 "start_phy(%02d), count(%d)\n",
5440 le16_to_cpu(event_data->ExpanderDevHandle),
5441 le16_to_cpu(event_data->EnclosureHandle),
5442 event_data->StartPhyNum, event_data->NumEntries);
5443 for (i = 0; i < event_data->NumEntries; i++) {
5444 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5447 phy_number = event_data->StartPhyNum + i;
5448 reason_code = event_data->PHY[i].PhyStatus &
5449 MPI2_EVENT_SAS_TOPO_RC_MASK;
5450 switch (reason_code) {
5451 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5452 status_str = "target add";
5454 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5455 status_str = "target remove";
5457 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5458 status_str = "delay target remove";
5460 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5461 status_str = "link rate change";
5463 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5464 status_str = "target responding";
5467 status_str = "unknown";
5470 link_rate = event_data->PHY[i].LinkRate >> 4;
5471 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5472 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5473 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5474 handle, status_str, link_rate, prev_link_rate);
5481 * _scsih_sas_topology_change_event - handle topology changes
5482 * @ioc: per adapter object
5483 * @fw_event: The fw_event_work object
5488 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5489 struct fw_event_work *fw_event)
5492 u16 parent_handle, handle;
5494 u8 phy_number, max_phys;
5495 struct _sas_node *sas_expander;
5497 unsigned long flags;
5498 u8 link_rate, prev_link_rate;
5499 Mpi2EventDataSasTopologyChangeList_t *event_data =
5500 (Mpi2EventDataSasTopologyChangeList_t *)
5501 fw_event->event_data;
5503 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5504 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5505 _scsih_sas_topology_change_event_debug(ioc, event_data);
5508 if (ioc->remove_host || ioc->pci_error_recovery)
5511 if (!ioc->sas_hba.num_phys)
5512 _scsih_sas_host_add(ioc);
5514 _scsih_sas_host_refresh(ioc);
5516 if (fw_event->ignore) {
5517 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5518 "event\n", ioc->name));
5522 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5524 /* handle expander add */
5525 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5526 if (_scsih_expander_add(ioc, parent_handle) != 0)
5529 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5530 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5533 sas_address = sas_expander->sas_address;
5534 max_phys = sas_expander->num_phys;
5535 } else if (parent_handle < ioc->sas_hba.num_phys) {
5536 sas_address = ioc->sas_hba.sas_address;
5537 max_phys = ioc->sas_hba.num_phys;
5539 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5542 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5544 /* handle siblings events */
5545 for (i = 0; i < event_data->NumEntries; i++) {
5546 if (fw_event->ignore) {
5547 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5548 "expander event\n", ioc->name));
5551 if (ioc->shost_recovery || ioc->remove_host ||
5552 ioc->pci_error_recovery)
5554 phy_number = event_data->StartPhyNum + i;
5555 if (phy_number >= max_phys)
5557 reason_code = event_data->PHY[i].PhyStatus &
5558 MPI2_EVENT_SAS_TOPO_RC_MASK;
5559 if ((event_data->PHY[i].PhyStatus &
5560 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5561 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5563 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5566 link_rate = event_data->PHY[i].LinkRate >> 4;
5567 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5568 switch (reason_code) {
5569 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5571 if (ioc->shost_recovery)
5574 if (link_rate == prev_link_rate)
5577 mpt2sas_transport_update_links(ioc, sas_address,
5578 handle, phy_number, link_rate);
5580 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5583 _scsih_check_device(ioc, handle);
5585 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5587 if (ioc->shost_recovery)
5590 mpt2sas_transport_update_links(ioc, sas_address,
5591 handle, phy_number, link_rate);
5593 _scsih_add_device(ioc, handle, phy_number, 0);
5595 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5597 _scsih_device_remove_by_handle(ioc, handle);
5602 /* handle expander removal */
5603 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5605 mpt2sas_expander_remove(ioc, sas_address);
5609 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5611 * _scsih_sas_device_status_change_event_debug - debug for device event
5612 * @event_data: event data payload
5618 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5619 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5621 char *reason_str = NULL;
5623 switch (event_data->ReasonCode) {
5624 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5625 reason_str = "smart data";
5627 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5628 reason_str = "unsupported device discovered";
5630 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5631 reason_str = "internal device reset";
5633 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5634 reason_str = "internal task abort";
5636 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5637 reason_str = "internal task abort set";
5639 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5640 reason_str = "internal clear task set";
5642 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5643 reason_str = "internal query task";
5645 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5646 reason_str = "sata init failure";
5648 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5649 reason_str = "internal device reset complete";
5651 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5652 reason_str = "internal task abort complete";
5654 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5655 reason_str = "internal async notification";
5657 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5658 reason_str = "expander reduced functionality";
5660 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5661 reason_str = "expander reduced functionality complete";
5664 reason_str = "unknown reason";
5667 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5668 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5669 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5670 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5671 le16_to_cpu(event_data->TaskTag));
5672 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5673 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5674 event_data->ASC, event_data->ASCQ);
5675 printk(KERN_INFO "\n");
5680 * _scsih_sas_device_status_change_event - handle device status change
5681 * @ioc: per adapter object
5682 * @fw_event: The fw_event_work object
5688 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5689 struct fw_event_work *fw_event)
5691 struct MPT2SAS_TARGET *target_priv_data;
5692 struct _sas_device *sas_device;
5694 unsigned long flags;
5695 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5696 (Mpi2EventDataSasDeviceStatusChange_t *)
5697 fw_event->event_data;
5699 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5700 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5701 _scsih_sas_device_status_change_event_debug(ioc,
5705 /* In MPI Revision K (0xC), the internal device reset complete was
5706 * implemented, so avoid setting tm_busy flag for older firmware.
5708 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5711 if (event_data->ReasonCode !=
5712 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5713 event_data->ReasonCode !=
5714 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5717 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5718 sas_address = le64_to_cpu(event_data->SASAddress);
5719 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5722 if (!sas_device || !sas_device->starget) {
5723 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5727 target_priv_data = sas_device->starget->hostdata;
5728 if (!target_priv_data) {
5729 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5733 if (event_data->ReasonCode ==
5734 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5735 target_priv_data->tm_busy = 1;
5737 target_priv_data->tm_busy = 0;
5738 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5741 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5743 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5744 * @ioc: per adapter object
5745 * @event_data: event data payload
5751 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5752 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5754 char *reason_str = NULL;
5756 switch (event_data->ReasonCode) {
5757 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5758 reason_str = "enclosure add";
5760 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5761 reason_str = "enclosure remove";
5764 reason_str = "unknown reason";
5768 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5769 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5770 " number slots(%d)\n", ioc->name, reason_str,
5771 le16_to_cpu(event_data->EnclosureHandle),
5772 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5773 le16_to_cpu(event_data->StartSlot));
5778 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5779 * @ioc: per adapter object
5780 * @fw_event: The fw_event_work object
5786 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5787 struct fw_event_work *fw_event)
5789 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5790 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5791 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5792 (Mpi2EventDataSasEnclDevStatusChange_t *)
5793 fw_event->event_data);
5798 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5799 * @ioc: per adapter object
5800 * @fw_event: The fw_event_work object
5806 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5807 struct fw_event_work *fw_event)
5809 struct scsi_cmnd *scmd;
5810 struct scsi_device *sdev;
5813 struct MPT2SAS_DEVICE *sas_device_priv_data;
5814 u32 termination_count;
5816 Mpi2SCSITaskManagementReply_t *mpi_reply;
5817 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5818 (Mpi2EventDataSasBroadcastPrimitive_t *)
5819 fw_event->event_data;
5821 unsigned long flags;
5824 u8 task_abort_retries;
5826 mutex_lock(&ioc->tm_cmds.mutex);
5828 "%s: enter: phy number(%d), width(%d)\n",
5829 ioc->name, __func__, event_data->PhyNum,
5830 event_data->PortWidth);
5832 _scsih_block_io_all_device(ioc);
5834 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5835 mpi_reply = ioc->tm_cmds.reply;
5836 broadcast_aen_retry:
5838 /* sanity checks for retrying this loop */
5839 if (max_retries++ == 5) {
5840 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5841 ioc->name, __func__));
5843 } else if (max_retries > 1)
5844 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5845 ioc->name, __func__, max_retries - 1));
5847 termination_count = 0;
5849 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5850 if (ioc->shost_recovery)
5852 scmd = _scsih_scsi_lookup_get(ioc, smid);
5855 sdev = scmd->device;
5856 sas_device_priv_data = sdev->hostdata;
5857 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5859 /* skip hidden raid components */
5860 if (sas_device_priv_data->sas_target->flags &
5861 MPT_TARGET_FLAGS_RAID_COMPONENT)
5864 if (sas_device_priv_data->sas_target->flags &
5865 MPT_TARGET_FLAGS_VOLUME)
5868 handle = sas_device_priv_data->sas_target->handle;
5869 lun = sas_device_priv_data->lun;
5872 if (ioc->shost_recovery)
5875 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5876 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5877 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5880 sdev_printk(KERN_WARNING, sdev,
5881 "mpt2sas_scsih_issue_tm: FAILED when sending "
5882 "QUERY_TASK: scmd(%p)\n", scmd);
5883 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5884 goto broadcast_aen_retry;
5886 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5887 & MPI2_IOCSTATUS_MASK;
5888 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5889 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5890 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5892 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5893 goto broadcast_aen_retry;
5896 /* see if IO is still owned by IOC and target */
5897 if (mpi_reply->ResponseCode ==
5898 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5899 mpi_reply->ResponseCode ==
5900 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5901 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5904 task_abort_retries = 0;
5906 if (task_abort_retries++ == 60) {
5907 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5908 "%s: ABORT_TASK: giving up\n", ioc->name,
5910 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5911 goto broadcast_aen_retry;
5914 if (ioc->shost_recovery)
5917 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5918 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5921 sdev_printk(KERN_WARNING, sdev,
5922 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5923 "scmd(%p)\n", scmd);
5927 if (task_abort_retries > 1)
5928 sdev_printk(KERN_WARNING, sdev,
5929 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5931 task_abort_retries - 1, scmd);
5933 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5934 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5937 if (ioc->broadcast_aen_pending) {
5938 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5939 " pending AEN\n", ioc->name, __func__));
5940 ioc->broadcast_aen_pending = 0;
5941 goto broadcast_aen_retry;
5945 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5948 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5949 "%s - exit, query_count = %d termination_count = %d\n",
5950 ioc->name, __func__, query_count, termination_count));
5952 ioc->broadcast_aen_busy = 0;
5953 if (!ioc->shost_recovery)
5954 _scsih_ublock_io_all_device(ioc);
5955 mutex_unlock(&ioc->tm_cmds.mutex);
5959 * _scsih_sas_discovery_event - handle discovery events
5960 * @ioc: per adapter object
5961 * @fw_event: The fw_event_work object
5967 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5968 struct fw_event_work *fw_event)
5970 Mpi2EventDataSasDiscovery_t *event_data =
5971 (Mpi2EventDataSasDiscovery_t *)
5972 fw_event->event_data;
5974 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5975 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5976 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5977 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5979 if (event_data->DiscoveryStatus)
5980 printk("discovery_status(0x%08x)",
5981 le32_to_cpu(event_data->DiscoveryStatus));
5986 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5987 !ioc->sas_hba.num_phys) {
5988 if (disable_discovery > 0 && ioc->shost_recovery) {
5989 /* Wait for the reset to complete */
5990 while (ioc->shost_recovery)
5993 _scsih_sas_host_add(ioc);
5998 * _scsih_reprobe_lun - reprobing lun
5999 * @sdev: scsi device struct
6000 * @no_uld_attach: sdev->no_uld_attach flag setting
6004 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6008 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6009 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6010 sdev->no_uld_attach ? "hidding" : "exposing");
6011 rc = scsi_device_reprobe(sdev);
6015 * _scsih_sas_volume_add - add new volume
6016 * @ioc: per adapter object
6017 * @element: IR config element data
6023 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6024 Mpi2EventIrConfigElement_t *element)
6026 struct _raid_device *raid_device;
6027 unsigned long flags;
6029 u16 handle = le16_to_cpu(element->VolDevHandle);
6032 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6034 printk(MPT2SAS_ERR_FMT
6035 "failure at %s:%d/%s()!\n", ioc->name,
6036 __FILE__, __LINE__, __func__);
6040 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6041 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6042 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6047 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6049 printk(MPT2SAS_ERR_FMT
6050 "failure at %s:%d/%s()!\n", ioc->name,
6051 __FILE__, __LINE__, __func__);
6055 raid_device->id = ioc->sas_id++;
6056 raid_device->channel = RAID_CHANNEL;
6057 raid_device->handle = handle;
6058 raid_device->wwid = wwid;
6059 _scsih_raid_device_add(ioc, raid_device);
6060 if (!ioc->wait_for_discovery_to_complete) {
6061 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6062 raid_device->id, 0);
6064 _scsih_raid_device_remove(ioc, raid_device);
6066 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6067 _scsih_determine_boot_device(ioc, raid_device, 1);
6068 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6073 * _scsih_sas_volume_delete - delete volume
6074 * @ioc: per adapter object
6075 * @handle: volume device handle
6081 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6083 struct _raid_device *raid_device;
6084 unsigned long flags;
6085 struct MPT2SAS_TARGET *sas_target_priv_data;
6086 struct scsi_target *starget = NULL;
6088 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6089 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6091 if (raid_device->starget) {
6092 starget = raid_device->starget;
6093 sas_target_priv_data = starget->hostdata;
6094 sas_target_priv_data->deleted = 1;
6096 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6097 "(0x%016llx)\n", ioc->name, raid_device->handle,
6098 (unsigned long long) raid_device->wwid);
6099 list_del(&raid_device->list);
6102 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6104 scsi_remove_target(&starget->dev);
6108 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6109 * @ioc: per adapter object
6110 * @element: IR config element data
6116 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6117 Mpi2EventIrConfigElement_t *element)
6119 struct _sas_device *sas_device;
6120 struct scsi_target *starget = NULL;
6121 struct MPT2SAS_TARGET *sas_target_priv_data;
6122 unsigned long flags;
6123 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6125 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6126 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6128 sas_device->volume_handle = 0;
6129 sas_device->volume_wwid = 0;
6130 clear_bit(handle, ioc->pd_handles);
6131 if (sas_device->starget && sas_device->starget->hostdata) {
6132 starget = sas_device->starget;
6133 sas_target_priv_data = starget->hostdata;
6134 sas_target_priv_data->flags &=
6135 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6138 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6142 /* exposing raid component */
6144 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6148 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6149 * @ioc: per adapter object
6150 * @element: IR config element data
6156 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6157 Mpi2EventIrConfigElement_t *element)
6159 struct _sas_device *sas_device;
6160 struct scsi_target *starget = NULL;
6161 struct MPT2SAS_TARGET *sas_target_priv_data;
6162 unsigned long flags;
6163 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6164 u16 volume_handle = 0;
6165 u64 volume_wwid = 0;
6167 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6169 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6172 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6173 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6175 set_bit(handle, ioc->pd_handles);
6176 if (sas_device->starget && sas_device->starget->hostdata) {
6177 starget = sas_device->starget;
6178 sas_target_priv_data = starget->hostdata;
6179 sas_target_priv_data->flags |=
6180 MPT_TARGET_FLAGS_RAID_COMPONENT;
6181 sas_device->volume_handle = volume_handle;
6182 sas_device->volume_wwid = volume_wwid;
6185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6189 /* hiding raid component */
6191 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6195 * _scsih_sas_pd_delete - delete pd component
6196 * @ioc: per adapter object
6197 * @element: IR config element data
6203 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6204 Mpi2EventIrConfigElement_t *element)
6206 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6208 _scsih_device_remove_by_handle(ioc, handle);
6212 * _scsih_sas_pd_add - remove pd component
6213 * @ioc: per adapter object
6214 * @element: IR config element data
6220 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6221 Mpi2EventIrConfigElement_t *element)
6223 struct _sas_device *sas_device;
6224 unsigned long flags;
6225 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6226 Mpi2ConfigReply_t mpi_reply;
6227 Mpi2SasDevicePage0_t sas_device_pg0;
6232 set_bit(handle, ioc->pd_handles);
6234 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6235 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6236 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6240 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6241 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6242 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6243 ioc->name, __FILE__, __LINE__, __func__);
6247 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6248 MPI2_IOCSTATUS_MASK;
6249 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6250 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6251 ioc->name, __FILE__, __LINE__, __func__);
6255 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6256 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6257 mpt2sas_transport_update_links(ioc, sas_address, handle,
6258 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6260 _scsih_add_device(ioc, handle, 0, 1);
6263 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6265 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6266 * @ioc: per adapter object
6267 * @event_data: event data payload
6273 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6274 Mpi2EventDataIrConfigChangeList_t *event_data)
6276 Mpi2EventIrConfigElement_t *element;
6279 char *reason_str = NULL, *element_str = NULL;
6281 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6283 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6284 ioc->name, (le32_to_cpu(event_data->Flags) &
6285 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6286 "foreign" : "native", event_data->NumElements);
6287 for (i = 0; i < event_data->NumElements; i++, element++) {
6288 switch (element->ReasonCode) {
6289 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6292 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6293 reason_str = "remove";
6295 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6296 reason_str = "no change";
6298 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6299 reason_str = "hide";
6301 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6302 reason_str = "unhide";
6304 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6305 reason_str = "volume_created";
6307 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6308 reason_str = "volume_deleted";
6310 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6311 reason_str = "pd_created";
6313 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6314 reason_str = "pd_deleted";
6317 reason_str = "unknown reason";
6320 element_type = le16_to_cpu(element->ElementFlags) &
6321 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6322 switch (element_type) {
6323 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6324 element_str = "volume";
6326 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6327 element_str = "phys disk";
6329 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6330 element_str = "hot spare";
6333 element_str = "unknown element";
6336 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6337 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6338 reason_str, le16_to_cpu(element->VolDevHandle),
6339 le16_to_cpu(element->PhysDiskDevHandle),
6340 element->PhysDiskNum);
6346 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6347 * @ioc: per adapter object
6348 * @fw_event: The fw_event_work object
6354 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6355 struct fw_event_work *fw_event)
6357 Mpi2EventIrConfigElement_t *element;
6360 Mpi2EventDataIrConfigChangeList_t *event_data =
6361 (Mpi2EventDataIrConfigChangeList_t *)
6362 fw_event->event_data;
6364 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6365 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6366 && !ioc->hide_ir_msg)
6367 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6371 if (ioc->shost_recovery)
6374 foreign_config = (le32_to_cpu(event_data->Flags) &
6375 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6377 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6378 for (i = 0; i < event_data->NumElements; i++, element++) {
6380 switch (element->ReasonCode) {
6381 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6382 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6383 if (!foreign_config)
6384 _scsih_sas_volume_add(ioc, element);
6386 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6387 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6388 if (!foreign_config)
6389 _scsih_sas_volume_delete(ioc,
6390 le16_to_cpu(element->VolDevHandle));
6392 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6393 if (!ioc->is_warpdrive)
6394 _scsih_sas_pd_hide(ioc, element);
6396 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6397 if (!ioc->is_warpdrive)
6398 _scsih_sas_pd_expose(ioc, element);
6400 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6401 if (!ioc->is_warpdrive)
6402 _scsih_sas_pd_add(ioc, element);
6404 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6405 if (!ioc->is_warpdrive)
6406 _scsih_sas_pd_delete(ioc, element);
6413 * _scsih_sas_ir_volume_event - IR volume event
6414 * @ioc: per adapter object
6415 * @fw_event: The fw_event_work object
6421 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6422 struct fw_event_work *fw_event)
6425 unsigned long flags;
6426 struct _raid_device *raid_device;
6430 Mpi2EventDataIrVolume_t *event_data =
6431 (Mpi2EventDataIrVolume_t *)
6432 fw_event->event_data;
6434 if (ioc->shost_recovery)
6437 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6440 handle = le16_to_cpu(event_data->VolDevHandle);
6441 state = le32_to_cpu(event_data->NewValue);
6442 if (!ioc->hide_ir_msg)
6443 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6444 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6445 le32_to_cpu(event_data->PreviousValue), state));
6448 case MPI2_RAID_VOL_STATE_MISSING:
6449 case MPI2_RAID_VOL_STATE_FAILED:
6450 _scsih_sas_volume_delete(ioc, handle);
6453 case MPI2_RAID_VOL_STATE_ONLINE:
6454 case MPI2_RAID_VOL_STATE_DEGRADED:
6455 case MPI2_RAID_VOL_STATE_OPTIMAL:
6457 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6458 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6459 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6464 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6466 printk(MPT2SAS_ERR_FMT
6467 "failure at %s:%d/%s()!\n", ioc->name,
6468 __FILE__, __LINE__, __func__);
6472 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6474 printk(MPT2SAS_ERR_FMT
6475 "failure at %s:%d/%s()!\n", ioc->name,
6476 __FILE__, __LINE__, __func__);
6480 raid_device->id = ioc->sas_id++;
6481 raid_device->channel = RAID_CHANNEL;
6482 raid_device->handle = handle;
6483 raid_device->wwid = wwid;
6484 _scsih_raid_device_add(ioc, raid_device);
6485 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6486 raid_device->id, 0);
6488 _scsih_raid_device_remove(ioc, raid_device);
6491 case MPI2_RAID_VOL_STATE_INITIALIZING:
6498 * _scsih_sas_ir_physical_disk_event - PD event
6499 * @ioc: per adapter object
6500 * @fw_event: The fw_event_work object
6506 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6507 struct fw_event_work *fw_event)
6509 u16 handle, parent_handle;
6511 struct _sas_device *sas_device;
6512 unsigned long flags;
6513 Mpi2ConfigReply_t mpi_reply;
6514 Mpi2SasDevicePage0_t sas_device_pg0;
6516 Mpi2EventDataIrPhysicalDisk_t *event_data =
6517 (Mpi2EventDataIrPhysicalDisk_t *)
6518 fw_event->event_data;
6521 if (ioc->shost_recovery)
6524 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6527 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6528 state = le32_to_cpu(event_data->NewValue);
6530 if (!ioc->hide_ir_msg)
6531 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6532 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6533 le32_to_cpu(event_data->PreviousValue), state));
6536 case MPI2_RAID_PD_STATE_ONLINE:
6537 case MPI2_RAID_PD_STATE_DEGRADED:
6538 case MPI2_RAID_PD_STATE_REBUILDING:
6539 case MPI2_RAID_PD_STATE_OPTIMAL:
6540 case MPI2_RAID_PD_STATE_HOT_SPARE:
6542 if (!ioc->is_warpdrive)
6543 set_bit(handle, ioc->pd_handles);
6545 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6546 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6547 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6552 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6553 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6555 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6556 ioc->name, __FILE__, __LINE__, __func__);
6560 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6561 MPI2_IOCSTATUS_MASK;
6562 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6563 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6564 ioc->name, __FILE__, __LINE__, __func__);
6568 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6569 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6570 mpt2sas_transport_update_links(ioc, sas_address, handle,
6571 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6573 _scsih_add_device(ioc, handle, 0, 1);
6577 case MPI2_RAID_PD_STATE_OFFLINE:
6578 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6579 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6585 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6587 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6588 * @ioc: per adapter object
6589 * @event_data: event data payload
6595 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6596 Mpi2EventDataIrOperationStatus_t *event_data)
6598 char *reason_str = NULL;
6600 switch (event_data->RAIDOperation) {
6601 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6602 reason_str = "resync";
6604 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6605 reason_str = "online capacity expansion";
6607 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6608 reason_str = "consistency check";
6610 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6611 reason_str = "background init";
6613 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6614 reason_str = "make data consistent";
6621 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6622 "\thandle(0x%04x), percent complete(%d)\n",
6623 ioc->name, reason_str,
6624 le16_to_cpu(event_data->VolDevHandle),
6625 event_data->PercentComplete);
6630 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6631 * @ioc: per adapter object
6632 * @fw_event: The fw_event_work object
6638 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6639 struct fw_event_work *fw_event)
6641 Mpi2EventDataIrOperationStatus_t *event_data =
6642 (Mpi2EventDataIrOperationStatus_t *)
6643 fw_event->event_data;
6644 static struct _raid_device *raid_device;
6645 unsigned long flags;
6648 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6649 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6650 && !ioc->hide_ir_msg)
6651 _scsih_sas_ir_operation_status_event_debug(ioc,
6655 /* code added for raid transport support */
6656 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6658 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6659 handle = le16_to_cpu(event_data->VolDevHandle);
6660 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6662 raid_device->percent_complete =
6663 event_data->PercentComplete;
6664 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6669 * _scsih_prep_device_scan - initialize parameters prior to device scan
6670 * @ioc: per adapter object
6672 * Set the deleted flag prior to device scan. If the device is found during
6673 * the scan, then we clear the deleted flag.
6676 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6678 struct MPT2SAS_DEVICE *sas_device_priv_data;
6679 struct scsi_device *sdev;
6681 shost_for_each_device(sdev, ioc->shost) {
6682 sas_device_priv_data = sdev->hostdata;
6683 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6684 sas_device_priv_data->sas_target->deleted = 1;
6689 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6690 * @ioc: per adapter object
6691 * @sas_address: sas address
6692 * @slot: enclosure slot id
6693 * @handle: device handle
6695 * After host reset, find out whether devices are still responding.
6696 * Used in _scsi_remove_unresponsive_sas_devices.
6701 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6702 u16 slot, u16 handle)
6704 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6705 struct scsi_target *starget;
6706 struct _sas_device *sas_device;
6707 unsigned long flags;
6709 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6710 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6711 if (sas_device->sas_address == sas_address &&
6712 sas_device->slot == slot) {
6713 sas_device->responding = 1;
6714 starget = sas_device->starget;
6715 if (starget && starget->hostdata) {
6716 sas_target_priv_data = starget->hostdata;
6717 sas_target_priv_data->tm_busy = 0;
6718 sas_target_priv_data->deleted = 0;
6720 sas_target_priv_data = NULL;
6722 starget_printk(KERN_INFO, starget,
6723 "handle(0x%04x), sas_addr(0x%016llx), "
6724 "enclosure logical id(0x%016llx), "
6725 "slot(%d)\n", handle,
6726 (unsigned long long)sas_device->sas_address,
6727 (unsigned long long)
6728 sas_device->enclosure_logical_id,
6730 if (sas_device->handle == handle)
6732 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6733 sas_device->handle);
6734 sas_device->handle = handle;
6735 if (sas_target_priv_data)
6736 sas_target_priv_data->handle = handle;
6741 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6745 * _scsih_search_responding_sas_devices -
6746 * @ioc: per adapter object
6748 * After host reset, find out whether devices are still responding.
6754 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6756 Mpi2SasDevicePage0_t sas_device_pg0;
6757 Mpi2ConfigReply_t mpi_reply;
6764 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6766 if (list_empty(&ioc->sas_device_list))
6770 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6771 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6773 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6774 MPI2_IOCSTATUS_MASK;
6775 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6777 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6778 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6779 if (!(_scsih_is_end_device(device_info)))
6781 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6782 slot = le16_to_cpu(sas_device_pg0.Slot);
6783 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6787 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6792 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6793 * @ioc: per adapter object
6794 * @wwid: world wide identifier for raid volume
6795 * @handle: device handle
6797 * After host reset, find out whether devices are still responding.
6798 * Used in _scsi_remove_unresponsive_raid_devices.
6803 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6806 struct MPT2SAS_TARGET *sas_target_priv_data;
6807 struct scsi_target *starget;
6808 struct _raid_device *raid_device;
6809 unsigned long flags;
6811 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6812 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6813 if (raid_device->wwid == wwid && raid_device->starget) {
6814 starget = raid_device->starget;
6815 if (starget && starget->hostdata) {
6816 sas_target_priv_data = starget->hostdata;
6817 sas_target_priv_data->deleted = 0;
6819 sas_target_priv_data = NULL;
6820 raid_device->responding = 1;
6821 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6822 starget_printk(KERN_INFO, raid_device->starget,
6823 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6824 (unsigned long long)raid_device->wwid);
6826 * WARPDRIVE: The handles of the PDs might have changed
6827 * across the host reset so re-initialize the
6828 * required data for Direct IO
6830 _scsih_init_warpdrive_properties(ioc, raid_device);
6831 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6832 if (raid_device->handle == handle) {
6833 spin_unlock_irqrestore(&ioc->raid_device_lock,
6837 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6838 raid_device->handle);
6839 raid_device->handle = handle;
6840 if (sas_target_priv_data)
6841 sas_target_priv_data->handle = handle;
6842 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6847 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6851 * _scsih_search_responding_raid_devices -
6852 * @ioc: per adapter object
6854 * After host reset, find out whether devices are still responding.
6860 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6862 Mpi2RaidVolPage1_t volume_pg1;
6863 Mpi2RaidVolPage0_t volume_pg0;
6864 Mpi2RaidPhysDiskPage0_t pd_pg0;
6865 Mpi2ConfigReply_t mpi_reply;
6870 if (!ioc->ir_firmware)
6873 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6876 if (list_empty(&ioc->raid_device_list))
6880 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6881 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6882 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6883 MPI2_IOCSTATUS_MASK;
6884 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6886 handle = le16_to_cpu(volume_pg1.DevHandle);
6888 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6889 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6890 sizeof(Mpi2RaidVolPage0_t)))
6893 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6894 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6895 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6896 _scsih_mark_responding_raid_device(ioc,
6897 le64_to_cpu(volume_pg1.WWID), handle);
6900 /* refresh the pd_handles */
6901 if (!ioc->is_warpdrive) {
6902 phys_disk_num = 0xFF;
6903 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6904 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6905 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6907 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6908 MPI2_IOCSTATUS_MASK;
6909 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6911 phys_disk_num = pd_pg0.PhysDiskNum;
6912 handle = le16_to_cpu(pd_pg0.DevHandle);
6913 set_bit(handle, ioc->pd_handles);
6917 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6918 "complete\n", ioc->name);
6922 * _scsih_mark_responding_expander - mark a expander as responding
6923 * @ioc: per adapter object
6924 * @sas_address: sas address
6927 * After host reset, find out whether devices are still responding.
6928 * Used in _scsi_remove_unresponsive_expanders.
6933 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6936 struct _sas_node *sas_expander;
6937 unsigned long flags;
6940 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6941 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6942 if (sas_expander->sas_address != sas_address)
6944 sas_expander->responding = 1;
6945 if (sas_expander->handle == handle)
6947 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6948 " from(0x%04x) to (0x%04x)!!!\n",
6949 (unsigned long long)sas_expander->sas_address,
6950 sas_expander->handle, handle);
6951 sas_expander->handle = handle;
6952 for (i = 0 ; i < sas_expander->num_phys ; i++)
6953 sas_expander->phy[i].handle = handle;
6957 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6961 * _scsih_search_responding_expanders -
6962 * @ioc: per adapter object
6964 * After host reset, find out whether devices are still responding.
6970 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6972 Mpi2ExpanderPage0_t expander_pg0;
6973 Mpi2ConfigReply_t mpi_reply;
6978 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6980 if (list_empty(&ioc->sas_expander_list))
6984 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6985 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6987 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6988 MPI2_IOCSTATUS_MASK;
6989 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6992 handle = le16_to_cpu(expander_pg0.DevHandle);
6993 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6994 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6995 "sas_addr(0x%016llx)\n", handle,
6996 (unsigned long long)sas_address);
6997 _scsih_mark_responding_expander(ioc, sas_address, handle);
7001 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
7005 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7006 * @ioc: per adapter object
7011 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
7013 struct _sas_device *sas_device, *sas_device_next;
7014 struct _sas_node *sas_expander, *sas_expander_next;
7015 struct _raid_device *raid_device, *raid_device_next;
7016 struct list_head tmp_list;
7017 unsigned long flags;
7019 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7022 /* removing unresponding end devices */
7023 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7025 list_for_each_entry_safe(sas_device, sas_device_next,
7026 &ioc->sas_device_list, list) {
7027 if (!sas_device->responding)
7028 mpt2sas_device_remove_by_sas_address(ioc,
7029 sas_device->sas_address);
7031 sas_device->responding = 0;
7034 /* removing unresponding volumes */
7035 if (ioc->ir_firmware) {
7036 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7037 "volumes\n", ioc->name);
7038 list_for_each_entry_safe(raid_device, raid_device_next,
7039 &ioc->raid_device_list, list) {
7040 if (!raid_device->responding)
7041 _scsih_sas_volume_delete(ioc,
7042 raid_device->handle);
7044 raid_device->responding = 0;
7047 /* removing unresponding expanders */
7048 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7050 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7051 INIT_LIST_HEAD(&tmp_list);
7052 list_for_each_entry_safe(sas_expander, sas_expander_next,
7053 &ioc->sas_expander_list, list) {
7054 if (!sas_expander->responding)
7055 list_move_tail(&sas_expander->list, &tmp_list);
7057 sas_expander->responding = 0;
7059 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7060 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7062 list_del(&sas_expander->list);
7063 _scsih_expander_node_remove(ioc, sas_expander);
7065 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7067 /* unblock devices */
7068 _scsih_ublock_io_all_device(ioc);
7072 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7073 struct _sas_node *sas_expander, u16 handle)
7075 Mpi2ExpanderPage1_t expander_pg1;
7076 Mpi2ConfigReply_t mpi_reply;
7079 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7080 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7081 &expander_pg1, i, handle))) {
7082 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7083 ioc->name, __FILE__, __LINE__, __func__);
7087 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7088 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7089 expander_pg1.NegotiatedLinkRate >> 4);
7094 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7095 * @ioc: per adapter object
7100 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7102 Mpi2ExpanderPage0_t expander_pg0;
7103 Mpi2SasDevicePage0_t sas_device_pg0;
7104 Mpi2RaidVolPage1_t volume_pg1;
7105 Mpi2RaidVolPage0_t volume_pg0;
7106 Mpi2RaidPhysDiskPage0_t pd_pg0;
7107 Mpi2EventIrConfigElement_t element;
7108 Mpi2ConfigReply_t mpi_reply;
7111 u16 handle, parent_handle;
7113 struct _sas_device *sas_device;
7114 struct _sas_node *expander_device;
7115 static struct _raid_device *raid_device;
7117 unsigned long flags;
7119 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7121 _scsih_sas_host_refresh(ioc);
7123 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7127 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7128 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7129 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7130 MPI2_IOCSTATUS_MASK;
7131 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7132 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7133 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7134 ioc->name, ioc_status,
7135 le32_to_cpu(mpi_reply.IOCLogInfo));
7138 handle = le16_to_cpu(expander_pg0.DevHandle);
7139 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7140 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7141 ioc, le64_to_cpu(expander_pg0.SASAddress));
7142 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7143 if (expander_device)
7144 _scsih_refresh_expander_links(ioc, expander_device,
7147 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7148 "handle (0x%04x), sas_addr(0x%016llx)\n",
7149 ioc->name, handle, (unsigned long long)
7150 le64_to_cpu(expander_pg0.SASAddress));
7151 _scsih_expander_add(ioc, handle);
7152 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7153 "handle (0x%04x), sas_addr(0x%016llx)\n",
7154 ioc->name, handle, (unsigned long long)
7155 le64_to_cpu(expander_pg0.SASAddress));
7159 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7162 if (!ioc->ir_firmware)
7165 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7167 phys_disk_num = 0xFF;
7168 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7169 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7171 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7172 MPI2_IOCSTATUS_MASK;
7173 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7174 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7175 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7176 ioc->name, ioc_status,
7177 le32_to_cpu(mpi_reply.IOCLogInfo));
7180 phys_disk_num = pd_pg0.PhysDiskNum;
7181 handle = le16_to_cpu(pd_pg0.DevHandle);
7182 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7183 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7184 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7187 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7188 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7191 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7192 MPI2_IOCSTATUS_MASK;
7193 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7194 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7195 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7196 ioc->name, ioc_status,
7197 le32_to_cpu(mpi_reply.IOCLogInfo));
7200 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7201 if (!_scsih_get_sas_address(ioc, parent_handle,
7203 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7204 " handle (0x%04x), sas_addr(0x%016llx)\n",
7205 ioc->name, handle, (unsigned long long)
7206 le64_to_cpu(sas_device_pg0.SASAddress));
7207 mpt2sas_transport_update_links(ioc, sas_address,
7208 handle, sas_device_pg0.PhyNum,
7209 MPI2_SAS_NEG_LINK_RATE_1_5);
7210 set_bit(handle, ioc->pd_handles);
7212 /* This will retry adding the end device.
7213 * _scsih_add_device() will decide on retries and
7214 * return "1" when it should be retried
7216 while (_scsih_add_device(ioc, handle, retry_count++,
7220 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7221 " handle (0x%04x), sas_addr(0x%016llx)\n",
7222 ioc->name, handle, (unsigned long long)
7223 le64_to_cpu(sas_device_pg0.SASAddress));
7227 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7230 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7233 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7234 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7235 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7236 MPI2_IOCSTATUS_MASK;
7237 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7238 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7239 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7240 ioc->name, ioc_status,
7241 le32_to_cpu(mpi_reply.IOCLogInfo));
7244 handle = le16_to_cpu(volume_pg1.DevHandle);
7245 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7246 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7247 le64_to_cpu(volume_pg1.WWID));
7248 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7251 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7252 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7253 sizeof(Mpi2RaidVolPage0_t)))
7255 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7256 MPI2_IOCSTATUS_MASK;
7257 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7258 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7259 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7260 ioc->name, ioc_status,
7261 le32_to_cpu(mpi_reply.IOCLogInfo));
7264 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7265 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7266 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7267 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7268 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7269 element.VolDevHandle = volume_pg1.DevHandle;
7270 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7271 " handle (0x%04x)\n", ioc->name,
7272 volume_pg1.DevHandle);
7273 _scsih_sas_volume_add(ioc, &element);
7274 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7275 " handle (0x%04x)\n", ioc->name,
7276 volume_pg1.DevHandle);
7280 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7285 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7289 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7290 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7292 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7293 MPI2_IOCSTATUS_MASK;
7294 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7295 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7296 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7297 ioc->name, ioc_status,
7298 le32_to_cpu(mpi_reply.IOCLogInfo));
7301 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7302 if (!(_scsih_is_end_device(
7303 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7305 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7306 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7307 le64_to_cpu(sas_device_pg0.SASAddress));
7308 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7311 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7312 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7313 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7314 "handle (0x%04x), sas_addr(0x%016llx)\n",
7315 ioc->name, handle, (unsigned long long)
7316 le64_to_cpu(sas_device_pg0.SASAddress));
7317 mpt2sas_transport_update_links(ioc, sas_address, handle,
7318 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7320 /* This will retry adding the end device.
7321 * _scsih_add_device() will decide on retries and
7322 * return "1" when it should be retried
7324 while (_scsih_add_device(ioc, handle, retry_count++,
7328 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7329 "handle (0x%04x), sas_addr(0x%016llx)\n",
7330 ioc->name, handle, (unsigned long long)
7331 le64_to_cpu(sas_device_pg0.SASAddress));
7335 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7338 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7343 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7344 * @ioc: per adapter object
7345 * @reset_phase: phase
7347 * The handler for doing any required cleanup or initialization.
7349 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7350 * MPT2_IOC_DONE_RESET
7355 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7357 switch (reset_phase) {
7358 case MPT2_IOC_PRE_RESET:
7359 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7360 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7362 case MPT2_IOC_AFTER_RESET:
7363 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7364 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7365 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7366 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7367 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7368 complete(&ioc->scsih_cmds.done);
7370 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7371 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7372 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7373 complete(&ioc->tm_cmds.done);
7375 _scsih_fw_event_cleanup_queue(ioc);
7376 _scsih_flush_running_cmds(ioc);
7378 case MPT2_IOC_DONE_RESET:
7379 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7380 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7381 _scsih_sas_host_refresh(ioc);
7382 _scsih_prep_device_scan(ioc);
7383 _scsih_search_responding_sas_devices(ioc);
7384 _scsih_search_responding_raid_devices(ioc);
7385 _scsih_search_responding_expanders(ioc);
7386 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7387 !ioc->sas_hba.num_phys)) {
7388 _scsih_prep_device_scan(ioc);
7389 _scsih_search_responding_sas_devices(ioc);
7390 _scsih_search_responding_raid_devices(ioc);
7391 _scsih_search_responding_expanders(ioc);
7392 _scsih_error_recovery_delete_devices(ioc);
7399 * _firmware_event_work - delayed task for processing firmware events
7400 * @ioc: per adapter object
7401 * @work: equal to the fw_event_work object
7407 _firmware_event_work(struct work_struct *work)
7409 struct fw_event_work *fw_event = container_of(work,
7410 struct fw_event_work, delayed_work.work);
7411 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7413 /* the queue is being flushed so ignore this event */
7414 if (ioc->remove_host ||
7415 ioc->pci_error_recovery) {
7416 _scsih_fw_event_free(ioc, fw_event);
7420 switch (fw_event->event) {
7421 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7422 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7424 _scsih_remove_unresponding_sas_devices(ioc);
7425 _scsih_scan_for_devices_after_reset(ioc);
7427 case MPT2SAS_PORT_ENABLE_COMPLETE:
7428 ioc->start_scan = 0;
7430 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7431 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7434 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7435 "from worker thread\n", ioc->name));
7437 case MPT2SAS_TURN_ON_PFA_LED:
7438 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7440 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7441 _scsih_sas_topology_change_event(ioc, fw_event);
7443 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7444 _scsih_sas_device_status_change_event(ioc,
7447 case MPI2_EVENT_SAS_DISCOVERY:
7448 _scsih_sas_discovery_event(ioc,
7451 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7452 _scsih_sas_broadcast_primitive_event(ioc,
7455 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7456 _scsih_sas_enclosure_dev_status_change_event(ioc,
7459 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7460 _scsih_sas_ir_config_change_event(ioc, fw_event);
7462 case MPI2_EVENT_IR_VOLUME:
7463 _scsih_sas_ir_volume_event(ioc, fw_event);
7465 case MPI2_EVENT_IR_PHYSICAL_DISK:
7466 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7468 case MPI2_EVENT_IR_OPERATION_STATUS:
7469 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7472 _scsih_fw_event_free(ioc, fw_event);
7476 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7477 * @ioc: per adapter object
7478 * @msix_index: MSIX table index supplied by the OS
7479 * @reply: reply message frame(lower 32bit addr)
7480 * Context: interrupt.
7482 * This function merely adds a new work task into ioc->firmware_event_thread.
7483 * The tasks are worked from _firmware_event_work in user context.
7488 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7491 struct fw_event_work *fw_event;
7492 Mpi2EventNotificationReply_t *mpi_reply;
7496 /* events turned off due to host reset or driver unloading */
7497 if (ioc->remove_host || ioc->pci_error_recovery)
7500 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7502 if (unlikely(!mpi_reply)) {
7503 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7504 ioc->name, __FILE__, __LINE__, __func__);
7508 event = le16_to_cpu(mpi_reply->Event);
7512 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7514 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7515 (Mpi2EventDataSasBroadcastPrimitive_t *)
7516 mpi_reply->EventData;
7518 if (baen_data->Primitive !=
7519 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7522 if (ioc->broadcast_aen_busy) {
7523 ioc->broadcast_aen_pending++;
7526 ioc->broadcast_aen_busy = 1;
7530 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7531 _scsih_check_topo_delete_events(ioc,
7532 (Mpi2EventDataSasTopologyChangeList_t *)
7533 mpi_reply->EventData);
7535 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7536 _scsih_check_ir_config_unhide_events(ioc,
7537 (Mpi2EventDataIrConfigChangeList_t *)
7538 mpi_reply->EventData);
7540 case MPI2_EVENT_IR_VOLUME:
7541 _scsih_check_volume_delete_events(ioc,
7542 (Mpi2EventDataIrVolume_t *)
7543 mpi_reply->EventData);
7545 case MPI2_EVENT_LOG_ENTRY_ADDED:
7547 Mpi2EventDataLogEntryAdded_t *log_entry;
7550 if (!ioc->is_warpdrive)
7553 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7554 mpi_reply->EventData;
7555 log_code = (__le32 *)log_entry->LogData;
7557 if (le16_to_cpu(log_entry->LogEntryQualifier)
7558 != MPT2_WARPDRIVE_LOGENTRY)
7561 switch (le32_to_cpu(*log_code)) {
7562 case MPT2_WARPDRIVE_LC_SSDT:
7563 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7564 "IO Throttling has occurred in the WarpDrive "
7565 "subsystem. Check WarpDrive documentation for "
7566 "additional details.\n", ioc->name);
7568 case MPT2_WARPDRIVE_LC_SSDLW:
7569 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7570 "Program/Erase Cycles for the WarpDrive subsystem "
7571 "in degraded range. Check WarpDrive documentation "
7572 "for additional details.\n", ioc->name);
7574 case MPT2_WARPDRIVE_LC_SSDLF:
7575 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7576 "There are no Program/Erase Cycles for the "
7577 "WarpDrive subsystem. The storage device will be "
7578 "in read-only mode. Check WarpDrive documentation "
7579 "for additional details.\n", ioc->name);
7581 case MPT2_WARPDRIVE_LC_BRMF:
7582 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7583 "The Backup Rail Monitor has failed on the "
7584 "WarpDrive subsystem. Check WarpDrive "
7585 "documentation for additional details.\n",
7592 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7593 case MPI2_EVENT_IR_OPERATION_STATUS:
7594 case MPI2_EVENT_SAS_DISCOVERY:
7595 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7596 case MPI2_EVENT_IR_PHYSICAL_DISK:
7599 default: /* ignore the rest */
7603 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7604 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7606 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7607 ioc->name, __FILE__, __LINE__, __func__);
7611 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7612 fw_event->ioc = ioc;
7613 fw_event->VF_ID = mpi_reply->VF_ID;
7614 fw_event->VP_ID = mpi_reply->VP_ID;
7615 fw_event->event = event;
7616 _scsih_fw_event_add(ioc, fw_event);
7620 /* shost template */
7621 static struct scsi_host_template scsih_driver_template = {
7622 .module = THIS_MODULE,
7623 .name = "Fusion MPT SAS Host",
7624 .proc_name = MPT2SAS_DRIVER_NAME,
7625 .queuecommand = _scsih_qcmd,
7626 .target_alloc = _scsih_target_alloc,
7627 .slave_alloc = _scsih_slave_alloc,
7628 .slave_configure = _scsih_slave_configure,
7629 .target_destroy = _scsih_target_destroy,
7630 .slave_destroy = _scsih_slave_destroy,
7631 .scan_finished = _scsih_scan_finished,
7632 .scan_start = _scsih_scan_start,
7633 .change_queue_depth = _scsih_change_queue_depth,
7634 .change_queue_type = scsi_change_queue_type,
7635 .eh_abort_handler = _scsih_abort,
7636 .eh_device_reset_handler = _scsih_dev_reset,
7637 .eh_target_reset_handler = _scsih_target_reset,
7638 .eh_host_reset_handler = _scsih_host_reset,
7639 .bios_param = _scsih_bios_param,
7642 .sg_tablesize = MPT2SAS_SG_DEPTH,
7643 .max_sectors = 32767,
7645 .use_clustering = ENABLE_CLUSTERING,
7646 .shost_attrs = mpt2sas_host_attrs,
7647 .sdev_attrs = mpt2sas_dev_attrs,
7651 * _scsih_expander_node_remove - removing expander device from list.
7652 * @ioc: per adapter object
7653 * @sas_expander: the sas_device object
7654 * Context: Calling function should acquire ioc->sas_node_lock.
7656 * Removing object and freeing associated memory from the
7657 * ioc->sas_expander_list.
7662 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7663 struct _sas_node *sas_expander)
7665 struct _sas_port *mpt2sas_port, *next;
7667 /* remove sibling ports attached to this expander */
7668 list_for_each_entry_safe(mpt2sas_port, next,
7669 &sas_expander->sas_port_list, port_list) {
7670 if (ioc->shost_recovery)
7672 if (mpt2sas_port->remote_identify.device_type ==
7674 mpt2sas_device_remove_by_sas_address(ioc,
7675 mpt2sas_port->remote_identify.sas_address);
7676 else if (mpt2sas_port->remote_identify.device_type ==
7677 SAS_EDGE_EXPANDER_DEVICE ||
7678 mpt2sas_port->remote_identify.device_type ==
7679 SAS_FANOUT_EXPANDER_DEVICE)
7680 mpt2sas_expander_remove(ioc,
7681 mpt2sas_port->remote_identify.sas_address);
7684 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7685 sas_expander->sas_address_parent);
7687 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7688 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7689 sas_expander->handle, (unsigned long long)
7690 sas_expander->sas_address);
7692 kfree(sas_expander->phy);
7693 kfree(sas_expander);
7697 * _scsih_ir_shutdown - IR shutdown notification
7698 * @ioc: per adapter object
7700 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7701 * the host system is shutting down.
7706 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7708 Mpi2RaidActionRequest_t *mpi_request;
7709 Mpi2RaidActionReply_t *mpi_reply;
7712 /* is IR firmware build loaded ? */
7713 if (!ioc->ir_firmware)
7716 mutex_lock(&ioc->scsih_cmds.mutex);
7718 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7719 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7720 ioc->name, __func__);
7723 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7725 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7727 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7728 ioc->name, __func__);
7729 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7733 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7734 ioc->scsih_cmds.smid = smid;
7735 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7737 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7738 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7740 if (!ioc->hide_ir_msg)
7741 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7742 init_completion(&ioc->scsih_cmds.done);
7743 mpt2sas_base_put_smid_default(ioc, smid);
7744 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7746 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7747 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7748 ioc->name, __func__);
7752 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7753 mpi_reply = ioc->scsih_cmds.reply;
7755 if (!ioc->hide_ir_msg)
7756 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7757 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7758 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7759 le32_to_cpu(mpi_reply->IOCLogInfo));
7763 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7764 mutex_unlock(&ioc->scsih_cmds.mutex);
7768 * _scsih_shutdown - routine call during system shutdown
7769 * @pdev: PCI device struct
7774 _scsih_shutdown(struct pci_dev *pdev)
7776 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7777 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7778 struct workqueue_struct *wq;
7779 unsigned long flags;
7781 ioc->remove_host = 1;
7782 _scsih_fw_event_cleanup_queue(ioc);
7784 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7785 wq = ioc->firmware_event_thread;
7786 ioc->firmware_event_thread = NULL;
7787 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7789 destroy_workqueue(wq);
7791 _scsih_ir_shutdown(ioc);
7792 mpt2sas_base_detach(ioc);
7796 * _scsih_remove - detach and remove add host
7797 * @pdev: PCI device struct
7799 * Routine called when unloading the driver.
7803 _scsih_remove(struct pci_dev *pdev)
7805 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7806 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7807 struct _sas_port *mpt2sas_port, *next_port;
7808 struct _raid_device *raid_device, *next;
7809 struct MPT2SAS_TARGET *sas_target_priv_data;
7810 struct workqueue_struct *wq;
7811 unsigned long flags;
7813 ioc->remove_host = 1;
7814 _scsih_fw_event_cleanup_queue(ioc);
7816 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7817 wq = ioc->firmware_event_thread;
7818 ioc->firmware_event_thread = NULL;
7819 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7821 destroy_workqueue(wq);
7823 /* release all the volumes */
7824 _scsih_ir_shutdown(ioc);
7825 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7827 if (raid_device->starget) {
7828 sas_target_priv_data =
7829 raid_device->starget->hostdata;
7830 sas_target_priv_data->deleted = 1;
7831 scsi_remove_target(&raid_device->starget->dev);
7833 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7834 "(0x%016llx)\n", ioc->name, raid_device->handle,
7835 (unsigned long long) raid_device->wwid);
7836 _scsih_raid_device_remove(ioc, raid_device);
7839 /* free ports attached to the sas_host */
7840 list_for_each_entry_safe(mpt2sas_port, next_port,
7841 &ioc->sas_hba.sas_port_list, port_list) {
7842 if (mpt2sas_port->remote_identify.device_type ==
7844 mpt2sas_device_remove_by_sas_address(ioc,
7845 mpt2sas_port->remote_identify.sas_address);
7846 else if (mpt2sas_port->remote_identify.device_type ==
7847 SAS_EDGE_EXPANDER_DEVICE ||
7848 mpt2sas_port->remote_identify.device_type ==
7849 SAS_FANOUT_EXPANDER_DEVICE)
7850 mpt2sas_expander_remove(ioc,
7851 mpt2sas_port->remote_identify.sas_address);
7854 /* free phys attached to the sas_host */
7855 if (ioc->sas_hba.num_phys) {
7856 kfree(ioc->sas_hba.phy);
7857 ioc->sas_hba.phy = NULL;
7858 ioc->sas_hba.num_phys = 0;
7861 sas_remove_host(shost);
7862 scsi_remove_host(shost);
7863 mpt2sas_base_detach(ioc);
7864 list_del(&ioc->list);
7865 scsi_host_put(shost);
7869 * _scsih_probe_boot_devices - reports 1st device
7870 * @ioc: per adapter object
7872 * If specified in bios page 2, this routine reports the 1st
7873 * device scsi-ml or sas transport for persistent boot device
7874 * purposes. Please refer to function _scsih_determine_boot_device()
7877 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7881 struct _sas_device *sas_device;
7882 struct _raid_device *raid_device;
7884 u64 sas_address_parent;
7886 unsigned long flags;
7889 /* no Bios, return immediately */
7890 if (!ioc->bios_pg3.BiosVersion)
7895 if (ioc->req_boot_device.device) {
7896 device = ioc->req_boot_device.device;
7897 is_raid = ioc->req_boot_device.is_raid;
7898 } else if (ioc->req_alt_boot_device.device) {
7899 device = ioc->req_alt_boot_device.device;
7900 is_raid = ioc->req_alt_boot_device.is_raid;
7901 } else if (ioc->current_boot_device.device) {
7902 device = ioc->current_boot_device.device;
7903 is_raid = ioc->current_boot_device.is_raid;
7910 raid_device = device;
7911 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7912 raid_device->id, 0);
7914 _scsih_raid_device_remove(ioc, raid_device);
7916 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7917 sas_device = device;
7918 handle = sas_device->handle;
7919 sas_address_parent = sas_device->sas_address_parent;
7920 sas_address = sas_device->sas_address;
7921 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7922 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7924 if (ioc->hide_drives)
7926 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7927 sas_device->sas_address_parent)) {
7928 _scsih_sas_device_remove(ioc, sas_device);
7929 } else if (!sas_device->starget) {
7930 if (!ioc->is_driver_loading) {
7931 mpt2sas_transport_port_remove(ioc,
7933 sas_address_parent);
7934 _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;
8130 shost = scsi_host_alloc(&scsih_driver_template,
8131 sizeof(struct MPT2SAS_ADAPTER));
8135 /* init local params */
8136 ioc = shost_priv(shost);
8137 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8138 INIT_LIST_HEAD(&ioc->list);
8139 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8141 ioc->id = mpt_ids++;
8142 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8144 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8145 ioc->is_warpdrive = 1;
8146 ioc->hide_ir_msg = 1;
8148 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8149 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8150 ioc->tm_cb_idx = tm_cb_idx;
8151 ioc->ctl_cb_idx = ctl_cb_idx;
8152 ioc->base_cb_idx = base_cb_idx;
8153 ioc->port_enable_cb_idx = port_enable_cb_idx;
8154 ioc->transport_cb_idx = transport_cb_idx;
8155 ioc->scsih_cb_idx = scsih_cb_idx;
8156 ioc->config_cb_idx = config_cb_idx;
8157 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8158 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8159 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8160 ioc->logging_level = logging_level;
8161 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8162 /* misc semaphores and spin locks */
8163 mutex_init(&ioc->reset_in_progress_mutex);
8164 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8165 spin_lock_init(&ioc->scsi_lookup_lock);
8166 spin_lock_init(&ioc->sas_device_lock);
8167 spin_lock_init(&ioc->sas_node_lock);
8168 spin_lock_init(&ioc->fw_event_lock);
8169 spin_lock_init(&ioc->raid_device_lock);
8171 INIT_LIST_HEAD(&ioc->sas_device_list);
8172 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8173 INIT_LIST_HEAD(&ioc->sas_expander_list);
8174 INIT_LIST_HEAD(&ioc->fw_event_list);
8175 INIT_LIST_HEAD(&ioc->raid_device_list);
8176 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8177 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8178 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8179 INIT_LIST_HEAD(&ioc->reply_queue_list);
8181 /* init shost parameters */
8182 shost->max_cmd_len = 32;
8183 shost->max_lun = max_lun;
8184 shost->transportt = mpt2sas_transport_template;
8185 shost->unique_id = ioc->id;
8187 if (max_sectors != 0xFFFF) {
8188 if (max_sectors < 64) {
8189 shost->max_sectors = 64;
8190 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8191 "for max_sectors, range is 64 to 32767. Assigning "
8192 "value of 64.\n", ioc->name, max_sectors);
8193 } else if (max_sectors > 32767) {
8194 shost->max_sectors = 32767;
8195 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8196 "for max_sectors, range is 64 to 8192. Assigning "
8197 "default value of 32767.\n", ioc->name,
8200 shost->max_sectors = max_sectors & 0xFFFE;
8201 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8202 "set to %d\n", ioc->name, shost->max_sectors);
8206 /* register EEDP capabilities with SCSI layer */
8208 scsi_host_set_prot(shost, prot_mask);
8210 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8211 | SHOST_DIF_TYPE2_PROTECTION
8212 | SHOST_DIF_TYPE3_PROTECTION);
8214 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8217 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8218 "fw_event%d", ioc->id);
8219 ioc->firmware_event_thread = create_singlethread_workqueue(
8220 ioc->firmware_event_name);
8221 if (!ioc->firmware_event_thread) {
8222 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8223 ioc->name, __FILE__, __LINE__, __func__);
8225 goto out_thread_fail;
8228 ioc->is_driver_loading = 1;
8229 if ((mpt2sas_base_attach(ioc))) {
8230 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8231 ioc->name, __FILE__, __LINE__, __func__);
8233 goto out_attach_fail;
8236 if (ioc->is_warpdrive) {
8237 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8238 ioc->hide_drives = 0;
8239 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8240 ioc->hide_drives = 1;
8242 if (_scsih_get_num_volumes(ioc))
8243 ioc->hide_drives = 1;
8245 ioc->hide_drives = 0;
8248 ioc->hide_drives = 0;
8250 rv = scsi_add_host(shost, &pdev->dev);
8252 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8253 ioc->name, __FILE__, __LINE__, __func__);
8254 goto out_add_shost_fail;
8257 scsi_scan_host(shost);
8262 mpt2sas_base_detach(ioc);
8264 destroy_workqueue(ioc->firmware_event_thread);
8266 list_del(&ioc->list);
8267 scsi_host_put(shost);
8273 * _scsih_suspend - power management suspend main entry point
8274 * @pdev: PCI device struct
8275 * @state: PM state change to (usually PCI_D3)
8277 * Returns 0 success, anything else error.
8280 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8282 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8283 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8284 pci_power_t device_state;
8286 mpt2sas_base_stop_watchdog(ioc);
8287 scsi_block_requests(shost);
8288 _scsih_ir_shutdown(ioc);
8289 device_state = pci_choose_state(pdev, state);
8290 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8291 "operating state [D%d]\n", ioc->name, pdev,
8292 pci_name(pdev), device_state);
8294 mpt2sas_base_free_resources(ioc);
8295 pci_save_state(pdev);
8296 pci_set_power_state(pdev, device_state);
8301 * _scsih_resume - power management resume main entry point
8302 * @pdev: PCI device struct
8304 * Returns 0 success, anything else error.
8307 _scsih_resume(struct pci_dev *pdev)
8309 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8310 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8311 pci_power_t device_state = pdev->current_state;
8314 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8315 "operating state [D%d]\n", ioc->name, pdev,
8316 pci_name(pdev), device_state);
8318 pci_set_power_state(pdev, PCI_D0);
8319 pci_enable_wake(pdev, PCI_D0, 0);
8320 pci_restore_state(pdev);
8322 r = mpt2sas_base_map_resources(ioc);
8326 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8327 scsi_unblock_requests(shost);
8328 mpt2sas_base_start_watchdog(ioc);
8331 #endif /* CONFIG_PM */
8334 * _scsih_pci_error_detected - Called when a PCI error is detected.
8335 * @pdev: PCI device struct
8336 * @state: PCI channel state
8338 * Description: Called when a PCI error is detected.
8341 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8343 static pci_ers_result_t
8344 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8346 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8347 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8349 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8353 case pci_channel_io_normal:
8354 return PCI_ERS_RESULT_CAN_RECOVER;
8355 case pci_channel_io_frozen:
8356 /* Fatal error, prepare for slot reset */
8357 ioc->pci_error_recovery = 1;
8358 scsi_block_requests(ioc->shost);
8359 mpt2sas_base_stop_watchdog(ioc);
8360 mpt2sas_base_free_resources(ioc);
8361 return PCI_ERS_RESULT_NEED_RESET;
8362 case pci_channel_io_perm_failure:
8363 /* Permanent error, prepare for device removal */
8364 ioc->pci_error_recovery = 1;
8365 mpt2sas_base_stop_watchdog(ioc);
8366 _scsih_flush_running_cmds(ioc);
8367 return PCI_ERS_RESULT_DISCONNECT;
8369 return PCI_ERS_RESULT_NEED_RESET;
8373 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8374 * @pdev: PCI device struct
8376 * Description: This routine is called by the pci error recovery
8377 * code after the PCI slot has been reset, just before we
8378 * should resume normal operations.
8380 static pci_ers_result_t
8381 _scsih_pci_slot_reset(struct pci_dev *pdev)
8383 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8384 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8387 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8390 ioc->pci_error_recovery = 0;
8392 pci_restore_state(pdev);
8393 rc = mpt2sas_base_map_resources(ioc);
8395 return PCI_ERS_RESULT_DISCONNECT;
8398 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8401 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8402 (rc == 0) ? "success" : "failed");
8405 return PCI_ERS_RESULT_RECOVERED;
8407 return PCI_ERS_RESULT_DISCONNECT;
8411 * _scsih_pci_resume() - resume normal ops after PCI reset
8412 * @pdev: pointer to PCI device
8414 * Called when the error recovery driver tells us that its
8415 * OK to resume normal operation. Use completion to allow
8416 * halted scsi ops to resume.
8419 _scsih_pci_resume(struct pci_dev *pdev)
8421 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8422 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8424 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8426 pci_cleanup_aer_uncorrect_error_status(pdev);
8427 mpt2sas_base_start_watchdog(ioc);
8428 scsi_unblock_requests(ioc->shost);
8432 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8433 * @pdev: pointer to PCI device
8435 static pci_ers_result_t
8436 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8438 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8439 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8441 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8444 /* TODO - dump whatever for debugging purposes */
8446 /* Request a slot reset. */
8447 return PCI_ERS_RESULT_NEED_RESET;
8450 static const struct pci_error_handlers _scsih_err_handler = {
8451 .error_detected = _scsih_pci_error_detected,
8452 .mmio_enabled = _scsih_pci_mmio_enabled,
8453 .slot_reset = _scsih_pci_slot_reset,
8454 .resume = _scsih_pci_resume,
8457 static struct pci_driver scsih_driver = {
8458 .name = MPT2SAS_DRIVER_NAME,
8459 .id_table = scsih_pci_table,
8460 .probe = _scsih_probe,
8461 .remove = _scsih_remove,
8462 .shutdown = _scsih_shutdown,
8463 .err_handler = &_scsih_err_handler,
8465 .suspend = _scsih_suspend,
8466 .resume = _scsih_resume,
8470 /* raid transport support */
8471 static struct raid_function_template mpt2sas_raid_functions = {
8472 .cookie = &scsih_driver_template,
8473 .is_raid = _scsih_is_raid,
8474 .get_resync = _scsih_get_resync,
8475 .get_state = _scsih_get_state,
8479 * _scsih_init - main entry point for this driver.
8481 * Returns 0 success, anything else error.
8489 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8490 MPT2SAS_DRIVER_VERSION);
8492 mpt2sas_transport_template =
8493 sas_attach_transport(&mpt2sas_transport_functions);
8494 if (!mpt2sas_transport_template)
8496 /* raid transport support */
8497 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8498 if (!mpt2sas_raid_template) {
8499 sas_release_transport(mpt2sas_transport_template);
8503 mpt2sas_base_initialize_callback_handler();
8505 /* queuecommand callback hander */
8506 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8508 /* task management callback handler */
8509 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8511 /* base internal commands callback handler */
8512 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8513 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8514 mpt2sas_port_enable_done);
8516 /* transport internal commands callback handler */
8517 transport_cb_idx = mpt2sas_base_register_callback_handler(
8518 mpt2sas_transport_done);
8520 /* scsih internal commands callback handler */
8521 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8523 /* configuration page API internal commands callback handler */
8524 config_cb_idx = mpt2sas_base_register_callback_handler(
8525 mpt2sas_config_done);
8527 /* ctl module callback handler */
8528 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8530 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8531 _scsih_tm_tr_complete);
8533 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8534 _scsih_tm_volume_tr_complete);
8536 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8537 _scsih_sas_control_complete);
8541 error = pci_register_driver(&scsih_driver);
8543 /* raid transport support */
8544 raid_class_release(mpt2sas_raid_template);
8545 sas_release_transport(mpt2sas_transport_template);
8552 * _scsih_exit - exit point for this driver (when it is a module).
8554 * Returns 0 success, anything else error.
8559 printk(KERN_INFO "mpt2sas version %s unloading\n",
8560 MPT2SAS_DRIVER_VERSION);
8562 pci_unregister_driver(&scsih_driver);
8566 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8567 mpt2sas_base_release_callback_handler(tm_cb_idx);
8568 mpt2sas_base_release_callback_handler(base_cb_idx);
8569 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8570 mpt2sas_base_release_callback_handler(transport_cb_idx);
8571 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8572 mpt2sas_base_release_callback_handler(config_cb_idx);
8573 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8575 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8576 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8577 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8579 /* raid transport support */
8580 raid_class_release(mpt2sas_raid_template);
8581 sas_release_transport(mpt2sas_transport_template);
8585 module_init(_scsih_init);
8586 module_exit(_scsih_exit);