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, 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), scsi_level(%d), cmd_que(%d)\n",
1250 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
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 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3949 /* Make sure Device is not raid volume.
3950 * We do not expose raid functionality to upper layer for warpdrive.
3952 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3953 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3954 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3956 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3958 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3959 ioc->name, __func__);
3962 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3963 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3964 _scsih_setup_eedp(scmd, mpi_request);
3965 if (scmd->cmd_len == 32)
3966 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3967 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3968 if (sas_device_priv_data->sas_target->flags &
3969 MPT_TARGET_FLAGS_RAID_COMPONENT)
3970 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3972 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3973 mpi_request->DevHandle =
3974 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3975 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3976 mpi_request->Control = cpu_to_le32(mpi_control);
3977 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3978 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3979 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3980 mpi_request->SenseBufferLowAddress =
3981 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3982 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3983 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3984 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3985 mpi_request->VF_ID = 0; /* TODO */
3986 mpi_request->VP_ID = 0;
3987 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3989 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3991 if (!mpi_request->DataLength) {
3992 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3994 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3995 mpt2sas_base_free_smid(ioc, smid);
4000 raid_device = sas_target_priv_data->raid_device;
4001 if (raid_device && raid_device->direct_io_enabled)
4002 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4005 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4006 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4007 le16_to_cpu(mpi_request->DevHandle));
4009 mpt2sas_base_put_smid_default(ioc, smid);
4013 return SCSI_MLQUEUE_HOST_BUSY;
4017 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4018 * @sense_buffer: sense data returned by target
4019 * @data: normalized skey/asc/ascq
4024 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4026 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4027 /* descriptor format */
4028 data->skey = sense_buffer[1] & 0x0F;
4029 data->asc = sense_buffer[2];
4030 data->ascq = sense_buffer[3];
4033 data->skey = sense_buffer[2] & 0x0F;
4034 data->asc = sense_buffer[12];
4035 data->ascq = sense_buffer[13];
4039 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4041 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4042 * @ioc: per adapter object
4043 * @scmd: pointer to scsi command object
4044 * @mpi_reply: reply mf payload returned from firmware
4046 * scsi_status - SCSI Status code returned from target device
4047 * scsi_state - state info associated with SCSI_IO determined by ioc
4048 * ioc_status - ioc supplied status info
4053 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4054 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4058 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4059 MPI2_IOCSTATUS_MASK;
4060 u8 scsi_state = mpi_reply->SCSIState;
4061 u8 scsi_status = mpi_reply->SCSIStatus;
4062 char *desc_ioc_state = NULL;
4063 char *desc_scsi_status = NULL;
4064 char *desc_scsi_state = ioc->tmp_string;
4065 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4066 struct _sas_device *sas_device = NULL;
4067 unsigned long flags;
4068 struct scsi_target *starget = scmd->device->sdev_target;
4069 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4070 char *device_str = NULL;
4075 if (ioc->hide_ir_msg)
4076 device_str = "WarpDrive";
4078 device_str = "volume";
4080 if (log_info == 0x31170000)
4083 switch (ioc_status) {
4084 case MPI2_IOCSTATUS_SUCCESS:
4085 desc_ioc_state = "success";
4087 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4088 desc_ioc_state = "invalid function";
4090 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4091 desc_ioc_state = "scsi recovered error";
4093 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4094 desc_ioc_state = "scsi invalid dev handle";
4096 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4097 desc_ioc_state = "scsi device not there";
4099 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4100 desc_ioc_state = "scsi data overrun";
4102 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4103 desc_ioc_state = "scsi data underrun";
4105 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4106 desc_ioc_state = "scsi io data error";
4108 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4109 desc_ioc_state = "scsi protocol error";
4111 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4112 desc_ioc_state = "scsi task terminated";
4114 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4115 desc_ioc_state = "scsi residual mismatch";
4117 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4118 desc_ioc_state = "scsi task mgmt failed";
4120 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4121 desc_ioc_state = "scsi ioc terminated";
4123 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4124 desc_ioc_state = "scsi ext terminated";
4126 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4127 desc_ioc_state = "eedp guard error";
4129 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4130 desc_ioc_state = "eedp ref tag error";
4132 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4133 desc_ioc_state = "eedp app tag error";
4136 desc_ioc_state = "unknown";
4140 switch (scsi_status) {
4141 case MPI2_SCSI_STATUS_GOOD:
4142 desc_scsi_status = "good";
4144 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4145 desc_scsi_status = "check condition";
4147 case MPI2_SCSI_STATUS_CONDITION_MET:
4148 desc_scsi_status = "condition met";
4150 case MPI2_SCSI_STATUS_BUSY:
4151 desc_scsi_status = "busy";
4153 case MPI2_SCSI_STATUS_INTERMEDIATE:
4154 desc_scsi_status = "intermediate";
4156 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4157 desc_scsi_status = "intermediate condmet";
4159 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4160 desc_scsi_status = "reservation conflict";
4162 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4163 desc_scsi_status = "command terminated";
4165 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4166 desc_scsi_status = "task set full";
4168 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4169 desc_scsi_status = "aca active";
4171 case MPI2_SCSI_STATUS_TASK_ABORTED:
4172 desc_scsi_status = "task aborted";
4175 desc_scsi_status = "unknown";
4179 desc_scsi_state[0] = '\0';
4181 desc_scsi_state = " ";
4182 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4183 strcat(desc_scsi_state, "response info ");
4184 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4185 strcat(desc_scsi_state, "state terminated ");
4186 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4187 strcat(desc_scsi_state, "no status ");
4188 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4189 strcat(desc_scsi_state, "autosense failed ");
4190 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4191 strcat(desc_scsi_state, "autosense valid ");
4193 scsi_print_command(scmd);
4195 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4196 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4197 device_str, (unsigned long long)priv_target->sas_address);
4199 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4200 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4201 priv_target->sas_address);
4203 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4204 "phy(%d)\n", ioc->name, sas_device->sas_address,
4206 printk(MPT2SAS_WARN_FMT
4207 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4208 ioc->name, sas_device->enclosure_logical_id,
4211 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4214 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4215 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4216 desc_ioc_state, ioc_status, smid);
4217 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4218 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4219 scsi_get_resid(scmd));
4220 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4221 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4222 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4223 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4224 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4225 scsi_status, desc_scsi_state, scsi_state);
4227 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4228 struct sense_info data;
4229 _scsih_normalize_sense(scmd->sense_buffer, &data);
4230 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4231 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4232 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4235 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4236 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4237 response_bytes = (u8 *)&response_info;
4238 _scsih_response_code(ioc, response_bytes[0]);
4244 * _scsih_turn_on_pfa_led - illuminate PFA LED
4245 * @ioc: per adapter object
4246 * @handle: device handle
4252 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4254 Mpi2SepReply_t mpi_reply;
4255 Mpi2SepRequest_t mpi_request;
4256 struct _sas_device *sas_device;
4258 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4262 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4263 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4264 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4265 mpi_request.SlotStatus =
4266 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4267 mpi_request.DevHandle = cpu_to_le16(handle);
4268 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4269 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4270 &mpi_request)) != 0) {
4271 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4272 __FILE__, __LINE__, __func__);
4275 sas_device->pfa_led_on = 1;
4278 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4279 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4280 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4281 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4282 le32_to_cpu(mpi_reply.IOCLogInfo)));
4288 * _scsih_turn_off_pfa_led - turn off PFA LED
4289 * @ioc: per adapter object
4290 * @sas_device: sas device whose PFA LED has to turned off
4296 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4297 struct _sas_device *sas_device)
4299 Mpi2SepReply_t mpi_reply;
4300 Mpi2SepRequest_t mpi_request;
4302 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4303 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4304 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4305 mpi_request.SlotStatus = 0;
4306 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4307 mpi_request.DevHandle = 0;
4308 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4309 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4310 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4311 &mpi_request)) != 0) {
4312 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4313 __FILE__, __LINE__, __func__);
4317 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4318 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4319 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4320 le16_to_cpu(mpi_reply.IOCStatus),
4321 le32_to_cpu(mpi_reply.IOCLogInfo)));
4327 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4328 * @ioc: per adapter object
4329 * @handle: device handle
4330 * Context: interrupt.
4335 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4337 struct fw_event_work *fw_event;
4339 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4342 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
4343 fw_event->device_handle = handle;
4344 fw_event->ioc = ioc;
4345 _scsih_fw_event_add(ioc, fw_event);
4349 * _scsih_smart_predicted_fault - process smart errors
4350 * @ioc: per adapter object
4351 * @handle: device handle
4352 * Context: interrupt.
4357 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4359 struct scsi_target *starget;
4360 struct MPT2SAS_TARGET *sas_target_priv_data;
4361 Mpi2EventNotificationReply_t *event_reply;
4362 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4363 struct _sas_device *sas_device;
4365 unsigned long flags;
4367 /* only handle non-raid devices */
4368 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4369 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4371 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4374 starget = sas_device->starget;
4375 sas_target_priv_data = starget->hostdata;
4377 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4378 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4379 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4382 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4383 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4385 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4386 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4388 /* insert into event log */
4389 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4390 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4391 event_reply = kzalloc(sz, GFP_ATOMIC);
4393 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4394 ioc->name, __FILE__, __LINE__, __func__);
4398 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4399 event_reply->Event =
4400 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4401 event_reply->MsgLength = sz/4;
4402 event_reply->EventDataLength =
4403 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4404 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4405 event_reply->EventData;
4406 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4407 event_data->ASC = 0x5D;
4408 event_data->DevHandle = cpu_to_le16(handle);
4409 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4410 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4415 * _scsih_io_done - scsi request callback
4416 * @ioc: per adapter object
4417 * @smid: system request message index
4418 * @msix_index: MSIX table index supplied by the OS
4419 * @reply: reply message frame(lower 32bit addr)
4421 * Callback handler when using _scsih_qcmd.
4423 * Return 1 meaning mf should be freed from _base_interrupt
4424 * 0 means the mf is freed from this function.
4427 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4429 Mpi2SCSIIORequest_t *mpi_request;
4430 Mpi2SCSIIOReply_t *mpi_reply;
4431 struct scsi_cmnd *scmd;
4437 struct MPT2SAS_DEVICE *sas_device_priv_data;
4438 u32 response_code = 0;
4439 unsigned long flags;
4441 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4442 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4446 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4448 if (mpi_reply == NULL) {
4449 scmd->result = DID_OK << 16;
4453 sas_device_priv_data = scmd->device->hostdata;
4454 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4455 sas_device_priv_data->sas_target->deleted) {
4456 scmd->result = DID_NO_CONNECT << 16;
4459 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4461 * WARPDRIVE: If direct_io is set then it is directIO,
4462 * the failed direct I/O should be redirected to volume
4464 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4465 ((ioc_status & MPI2_IOCSTATUS_MASK)
4466 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4467 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4468 ioc->scsi_lookup[smid - 1].scmd = scmd;
4469 _scsih_scsi_direct_io_set(ioc, smid, 0);
4470 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4471 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4472 mpi_request->DevHandle =
4473 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4474 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4475 sas_device_priv_data->sas_target->handle);
4480 /* turning off TLR */
4481 scsi_state = mpi_reply->SCSIState;
4482 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4484 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4485 if (!sas_device_priv_data->tlr_snoop_check) {
4486 sas_device_priv_data->tlr_snoop_check++;
4487 /* Make sure Device is not raid volume.
4488 * We do not expose raid functionality to upper layer for warpdrive.
4490 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4491 sas_is_tlr_enabled(scmd->device) &&
4492 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4493 sas_disable_tlr(scmd->device);
4494 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4498 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4499 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4500 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4501 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4504 ioc_status &= MPI2_IOCSTATUS_MASK;
4505 scsi_status = mpi_reply->SCSIStatus;
4507 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4508 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4509 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4510 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4511 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4514 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4515 struct sense_info data;
4516 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4518 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4519 le32_to_cpu(mpi_reply->SenseCount));
4520 memcpy(scmd->sense_buffer, sense_data, sz);
4521 _scsih_normalize_sense(scmd->sense_buffer, &data);
4522 /* failure prediction threshold exceeded */
4523 if (data.asc == 0x5D)
4524 _scsih_smart_predicted_fault(ioc,
4525 le16_to_cpu(mpi_reply->DevHandle));
4528 switch (ioc_status) {
4529 case MPI2_IOCSTATUS_BUSY:
4530 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4531 scmd->result = SAM_STAT_BUSY;
4534 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4535 scmd->result = DID_NO_CONNECT << 16;
4538 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4539 if (sas_device_priv_data->block) {
4540 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4543 scmd->result = DID_SOFT_ERROR << 16;
4545 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4546 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4547 scmd->result = DID_RESET << 16;
4550 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4551 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4552 scmd->result = DID_SOFT_ERROR << 16;
4554 scmd->result = (DID_OK << 16) | scsi_status;
4557 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4558 scmd->result = (DID_OK << 16) | scsi_status;
4560 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4563 if (xfer_cnt < scmd->underflow) {
4564 if (scsi_status == SAM_STAT_BUSY)
4565 scmd->result = SAM_STAT_BUSY;
4567 scmd->result = DID_SOFT_ERROR << 16;
4568 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4569 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4570 scmd->result = DID_SOFT_ERROR << 16;
4571 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4572 scmd->result = DID_RESET << 16;
4573 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4574 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4575 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4576 scmd->result = (DRIVER_SENSE << 24) |
4577 SAM_STAT_CHECK_CONDITION;
4578 scmd->sense_buffer[0] = 0x70;
4579 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4580 scmd->sense_buffer[12] = 0x20;
4581 scmd->sense_buffer[13] = 0;
4585 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4586 scsi_set_resid(scmd, 0);
4587 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4588 case MPI2_IOCSTATUS_SUCCESS:
4589 scmd->result = (DID_OK << 16) | scsi_status;
4590 if (response_code ==
4591 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4592 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4593 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4594 scmd->result = DID_SOFT_ERROR << 16;
4595 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4596 scmd->result = DID_RESET << 16;
4599 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4600 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4601 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4602 _scsih_eedp_error_handling(scmd, ioc_status);
4604 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4605 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4606 case MPI2_IOCSTATUS_INVALID_SGL:
4607 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4608 case MPI2_IOCSTATUS_INVALID_FIELD:
4609 case MPI2_IOCSTATUS_INVALID_STATE:
4610 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4611 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4613 scmd->result = DID_SOFT_ERROR << 16;
4618 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4619 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4620 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4624 scsi_dma_unmap(scmd);
4625 scmd->scsi_done(scmd);
4630 * _scsih_sas_host_refresh - refreshing sas host object contents
4631 * @ioc: per adapter object
4634 * During port enable, fw will send topology events for every device. Its
4635 * possible that the handles may change from the previous setting, so this
4636 * code keeping handles updating if changed.
4641 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4646 Mpi2ConfigReply_t mpi_reply;
4647 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4648 u16 attached_handle;
4651 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4652 "updating handles for sas_host(0x%016llx)\n",
4653 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4655 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4656 * sizeof(Mpi2SasIOUnit0PhyData_t));
4657 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4658 if (!sas_iounit_pg0) {
4659 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4660 ioc->name, __FILE__, __LINE__, __func__);
4664 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4665 sas_iounit_pg0, sz)) != 0)
4667 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4668 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4670 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4671 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4673 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4674 PhyData[0].ControllerDevHandle);
4675 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4676 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4678 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4679 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4680 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4681 attached_handle, i, link_rate);
4684 kfree(sas_iounit_pg0);
4688 * _scsih_sas_host_add - create sas host object
4689 * @ioc: per adapter object
4691 * Creating host side data object, stored in ioc->sas_hba
4696 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4699 Mpi2ConfigReply_t mpi_reply;
4700 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4701 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4702 Mpi2SasPhyPage0_t phy_pg0;
4703 Mpi2SasDevicePage0_t sas_device_pg0;
4704 Mpi2SasEnclosurePage0_t enclosure_pg0;
4707 u16 device_missing_delay;
4709 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4710 if (!ioc->sas_hba.num_phys) {
4711 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4712 ioc->name, __FILE__, __LINE__, __func__);
4716 /* sas_iounit page 0 */
4717 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4718 sizeof(Mpi2SasIOUnit0PhyData_t));
4719 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4720 if (!sas_iounit_pg0) {
4721 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4722 ioc->name, __FILE__, __LINE__, __func__);
4725 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4726 sas_iounit_pg0, sz))) {
4727 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4731 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4732 MPI2_IOCSTATUS_MASK;
4733 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4734 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4735 ioc->name, __FILE__, __LINE__, __func__);
4739 /* sas_iounit page 1 */
4740 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4741 sizeof(Mpi2SasIOUnit1PhyData_t));
4742 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4743 if (!sas_iounit_pg1) {
4744 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4745 ioc->name, __FILE__, __LINE__, __func__);
4748 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4749 sas_iounit_pg1, sz))) {
4750 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4755 MPI2_IOCSTATUS_MASK;
4756 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4757 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4758 ioc->name, __FILE__, __LINE__, __func__);
4762 ioc->io_missing_delay =
4763 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4764 device_missing_delay =
4765 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4766 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4767 ioc->device_missing_delay = (device_missing_delay &
4768 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4770 ioc->device_missing_delay = device_missing_delay &
4771 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4773 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4774 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4775 sizeof(struct _sas_phy), GFP_KERNEL);
4776 if (!ioc->sas_hba.phy) {
4777 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4778 ioc->name, __FILE__, __LINE__, __func__);
4781 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4782 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4784 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4785 ioc->name, __FILE__, __LINE__, __func__);
4788 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4789 MPI2_IOCSTATUS_MASK;
4790 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4791 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4792 ioc->name, __FILE__, __LINE__, __func__);
4797 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4798 PhyData[0].ControllerDevHandle);
4799 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4800 ioc->sas_hba.phy[i].phy_id = i;
4801 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4802 phy_pg0, ioc->sas_hba.parent_dev);
4804 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4805 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4806 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4807 ioc->name, __FILE__, __LINE__, __func__);
4810 ioc->sas_hba.enclosure_handle =
4811 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4812 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4813 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4814 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4815 (unsigned long long) ioc->sas_hba.sas_address,
4816 ioc->sas_hba.num_phys) ;
4818 if (ioc->sas_hba.enclosure_handle) {
4819 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4821 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4822 ioc->sas_hba.enclosure_handle))) {
4823 ioc->sas_hba.enclosure_logical_id =
4824 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4829 kfree(sas_iounit_pg1);
4830 kfree(sas_iounit_pg0);
4834 * _scsih_expander_add - creating expander object
4835 * @ioc: per adapter object
4836 * @handle: expander handle
4838 * Creating expander object, stored in ioc->sas_expander_list.
4840 * Return 0 for success, else error.
4843 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4845 struct _sas_node *sas_expander;
4846 Mpi2ConfigReply_t mpi_reply;
4847 Mpi2ExpanderPage0_t expander_pg0;
4848 Mpi2ExpanderPage1_t expander_pg1;
4849 Mpi2SasEnclosurePage0_t enclosure_pg0;
4852 u64 sas_address, sas_address_parent = 0;
4854 unsigned long flags;
4855 struct _sas_port *mpt2sas_port = NULL;
4861 if (ioc->shost_recovery || ioc->pci_error_recovery)
4864 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4865 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4866 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4867 ioc->name, __FILE__, __LINE__, __func__);
4871 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4872 MPI2_IOCSTATUS_MASK;
4873 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4879 /* handle out of order topology events */
4880 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4881 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4883 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4884 ioc->name, __FILE__, __LINE__, __func__);
4887 if (sas_address_parent != ioc->sas_hba.sas_address) {
4888 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4889 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4890 sas_address_parent);
4891 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4892 if (!sas_expander) {
4893 rc = _scsih_expander_add(ioc, parent_handle);
4899 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4900 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4901 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4903 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4908 sas_expander = kzalloc(sizeof(struct _sas_node),
4910 if (!sas_expander) {
4911 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4912 ioc->name, __FILE__, __LINE__, __func__);
4916 sas_expander->handle = handle;
4917 sas_expander->num_phys = expander_pg0.NumPhys;
4918 sas_expander->sas_address_parent = sas_address_parent;
4919 sas_expander->sas_address = sas_address;
4921 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4922 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4923 handle, parent_handle, (unsigned long long)
4924 sas_expander->sas_address, sas_expander->num_phys);
4926 if (!sas_expander->num_phys)
4928 sas_expander->phy = kcalloc(sas_expander->num_phys,
4929 sizeof(struct _sas_phy), GFP_KERNEL);
4930 if (!sas_expander->phy) {
4931 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4932 ioc->name, __FILE__, __LINE__, __func__);
4937 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4938 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4939 sas_address_parent);
4940 if (!mpt2sas_port) {
4941 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4942 ioc->name, __FILE__, __LINE__, __func__);
4946 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4948 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4949 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4950 &expander_pg1, i, handle))) {
4951 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4952 ioc->name, __FILE__, __LINE__, __func__);
4956 sas_expander->phy[i].handle = handle;
4957 sas_expander->phy[i].phy_id = i;
4959 if ((mpt2sas_transport_add_expander_phy(ioc,
4960 &sas_expander->phy[i], expander_pg1,
4961 sas_expander->parent_dev))) {
4962 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4963 ioc->name, __FILE__, __LINE__, __func__);
4969 if (sas_expander->enclosure_handle) {
4970 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4971 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4972 sas_expander->enclosure_handle))) {
4973 sas_expander->enclosure_logical_id =
4974 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4978 _scsih_expander_node_add(ioc, sas_expander);
4984 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4985 sas_address_parent);
4986 kfree(sas_expander);
4991 * _scsih_done - scsih callback handler.
4992 * @ioc: per adapter object
4993 * @smid: system request message index
4994 * @msix_index: MSIX table index supplied by the OS
4995 * @reply: reply message frame(lower 32bit addr)
4997 * Callback handler when sending internal generated message frames.
4998 * The callback index passed is `ioc->scsih_cb_idx`
5000 * Return 1 meaning mf should be freed from _base_interrupt
5001 * 0 means the mf is freed from this function.
5004 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5006 MPI2DefaultReply_t *mpi_reply;
5008 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5009 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5011 if (ioc->scsih_cmds.smid != smid)
5013 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5015 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5016 mpi_reply->MsgLength*4);
5017 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5019 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5020 complete(&ioc->scsih_cmds.done);
5025 * mpt2sas_expander_remove - removing expander object
5026 * @ioc: per adapter object
5027 * @sas_address: expander sas_address
5032 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5034 struct _sas_node *sas_expander;
5035 unsigned long flags;
5037 if (ioc->shost_recovery)
5040 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5041 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5044 list_del(&sas_expander->list);
5045 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5047 _scsih_expander_node_remove(ioc, sas_expander);
5051 * _scsih_check_access_status - check access flags
5052 * @ioc: per adapter object
5053 * @sas_address: sas address
5054 * @handle: sas device handle
5055 * @access_flags: errors returned during discovery of the device
5057 * Return 0 for success, else failure
5060 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5061 u16 handle, u8 access_status)
5066 switch (access_status) {
5067 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5068 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5071 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5072 desc = "sata capability failed";
5074 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5075 desc = "sata affiliation conflict";
5077 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5078 desc = "route not addressable";
5080 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5081 desc = "smp error not addressable";
5083 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5084 desc = "device blocked";
5086 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5087 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5090 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5091 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5092 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5093 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5094 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5098 desc = "sata initialization failed";
5108 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5109 "handle(0x%04x)\n", ioc->name, desc,
5110 (unsigned long long)sas_address, handle);
5115 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5117 Mpi2ConfigReply_t mpi_reply;
5118 Mpi2SasDevicePage0_t sas_device_pg0;
5119 struct _sas_device *sas_device;
5121 unsigned long flags;
5123 struct scsi_target *starget;
5124 struct MPT2SAS_TARGET *sas_target_priv_data;
5128 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5129 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5132 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5133 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5136 /* check if this is end device */
5137 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5138 if (!(_scsih_is_end_device(device_info)))
5141 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5142 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5143 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5147 printk(MPT2SAS_ERR_FMT "device is not present "
5148 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5149 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5153 if (unlikely(sas_device->handle != handle)) {
5154 starget = sas_device->starget;
5155 sas_target_priv_data = starget->hostdata;
5156 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5157 " to (0x%04x)!!!\n", sas_device->handle, handle);
5158 sas_target_priv_data->handle = handle;
5159 sas_device->handle = handle;
5162 /* check if device is present */
5163 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5164 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5165 printk(MPT2SAS_ERR_FMT "device is not present "
5166 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5167 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5171 /* check if there were any issues with discovery */
5172 if (_scsih_check_access_status(ioc, sas_address, handle,
5173 sas_device_pg0.AccessStatus)) {
5174 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5177 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5178 _scsih_ublock_io_device(ioc, sas_address);
5183 * _scsih_add_device - creating sas device object
5184 * @ioc: per adapter object
5185 * @handle: sas device handle
5186 * @phy_num: phy number end device attached to
5187 * @is_pd: is this hidden raid component
5189 * Creating end device object, stored in ioc->sas_device_list.
5191 * Returns 0 for success, non-zero for failure.
5194 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5196 Mpi2ConfigReply_t mpi_reply;
5197 Mpi2SasDevicePage0_t sas_device_pg0;
5198 Mpi2SasEnclosurePage0_t enclosure_pg0;
5199 struct _sas_device *sas_device;
5203 unsigned long flags;
5205 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5206 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5207 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5208 ioc->name, __FILE__, __LINE__, __func__);
5212 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5213 MPI2_IOCSTATUS_MASK;
5214 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5215 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5216 ioc->name, __FILE__, __LINE__, __func__);
5220 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5222 /* check if device is present */
5223 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5224 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5225 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5226 ioc->name, __FILE__, __LINE__, __func__);
5227 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5228 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5232 /* check if there were any issues with discovery */
5233 if (_scsih_check_access_status(ioc, sas_address, handle,
5234 sas_device_pg0.AccessStatus))
5237 /* check if this is end device */
5238 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5239 if (!(_scsih_is_end_device(device_info))) {
5240 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5241 ioc->name, __FILE__, __LINE__, __func__);
5246 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5247 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5249 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5254 sas_device = kzalloc(sizeof(struct _sas_device),
5257 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5258 ioc->name, __FILE__, __LINE__, __func__);
5262 sas_device->handle = handle;
5263 if (_scsih_get_sas_address(ioc, le16_to_cpu
5264 (sas_device_pg0.ParentDevHandle),
5265 &sas_device->sas_address_parent) != 0)
5266 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5267 ioc->name, __FILE__, __LINE__, __func__);
5268 sas_device->enclosure_handle =
5269 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5271 le16_to_cpu(sas_device_pg0.Slot);
5272 sas_device->device_info = device_info;
5273 sas_device->sas_address = sas_address;
5274 sas_device->phy = sas_device_pg0.PhyNum;
5276 /* get enclosure_logical_id */
5277 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5278 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5279 sas_device->enclosure_handle)))
5280 sas_device->enclosure_logical_id =
5281 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5283 /* get device name */
5284 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5286 if (ioc->wait_for_discovery_to_complete)
5287 _scsih_sas_device_init_add(ioc, sas_device);
5289 _scsih_sas_device_add(ioc, sas_device);
5295 * _scsih_remove_device - removing sas device object
5296 * @ioc: per adapter object
5297 * @sas_device_delete: the sas_device object
5302 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5303 struct _sas_device *sas_device)
5305 struct MPT2SAS_TARGET *sas_target_priv_data;
5307 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5308 (sas_device->pfa_led_on)) {
5309 _scsih_turn_off_pfa_led(ioc, sas_device);
5310 sas_device->pfa_led_on = 0;
5313 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5314 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5315 sas_device->handle, (unsigned long long)
5316 sas_device->sas_address));
5318 if (sas_device->starget && sas_device->starget->hostdata) {
5319 sas_target_priv_data = sas_device->starget->hostdata;
5320 sas_target_priv_data->deleted = 1;
5321 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5322 sas_target_priv_data->handle =
5323 MPT2SAS_INVALID_DEVICE_HANDLE;
5326 if (!ioc->hide_drives)
5327 mpt2sas_transport_port_remove(ioc,
5328 sas_device->sas_address,
5329 sas_device->sas_address_parent);
5331 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5332 "(0x%016llx)\n", ioc->name, sas_device->handle,
5333 (unsigned long long) sas_device->sas_address);
5335 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5336 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5337 sas_device->handle, (unsigned long long)
5338 sas_device->sas_address));
5342 * _scsih_device_remove_by_handle - removing device object by handle
5343 * @ioc: per adapter object
5344 * @handle: device handle
5349 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5351 struct _sas_device *sas_device;
5352 unsigned long flags;
5354 if (ioc->shost_recovery)
5357 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5358 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5360 list_del(&sas_device->list);
5361 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5363 _scsih_remove_device(ioc, sas_device);
5367 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5368 * @ioc: per adapter object
5369 * @sas_address: device sas_address
5374 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5377 struct _sas_device *sas_device;
5378 unsigned long flags;
5380 if (ioc->shost_recovery)
5383 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5384 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5387 list_del(&sas_device->list);
5388 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5390 _scsih_remove_device(ioc, sas_device);
5392 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5394 * _scsih_sas_topology_change_event_debug - debug for topology event
5395 * @ioc: per adapter object
5396 * @event_data: event data payload
5400 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5401 Mpi2EventDataSasTopologyChangeList_t *event_data)
5407 char *status_str = NULL;
5408 u8 link_rate, prev_link_rate;
5410 switch (event_data->ExpStatus) {
5411 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5414 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5415 status_str = "remove";
5417 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5419 status_str = "responding";
5421 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5422 status_str = "remove delay";
5425 status_str = "unknown status";
5428 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5429 ioc->name, status_str);
5430 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5431 "start_phy(%02d), count(%d)\n",
5432 le16_to_cpu(event_data->ExpanderDevHandle),
5433 le16_to_cpu(event_data->EnclosureHandle),
5434 event_data->StartPhyNum, event_data->NumEntries);
5435 for (i = 0; i < event_data->NumEntries; i++) {
5436 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5439 phy_number = event_data->StartPhyNum + i;
5440 reason_code = event_data->PHY[i].PhyStatus &
5441 MPI2_EVENT_SAS_TOPO_RC_MASK;
5442 switch (reason_code) {
5443 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5444 status_str = "target add";
5446 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5447 status_str = "target remove";
5449 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5450 status_str = "delay target remove";
5452 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5453 status_str = "link rate change";
5455 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5456 status_str = "target responding";
5459 status_str = "unknown";
5462 link_rate = event_data->PHY[i].LinkRate >> 4;
5463 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5464 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5465 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5466 handle, status_str, link_rate, prev_link_rate);
5473 * _scsih_sas_topology_change_event - handle topology changes
5474 * @ioc: per adapter object
5475 * @fw_event: The fw_event_work object
5480 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5481 struct fw_event_work *fw_event)
5484 u16 parent_handle, handle;
5486 u8 phy_number, max_phys;
5487 struct _sas_node *sas_expander;
5489 unsigned long flags;
5490 u8 link_rate, prev_link_rate;
5491 Mpi2EventDataSasTopologyChangeList_t *event_data =
5492 (Mpi2EventDataSasTopologyChangeList_t *)
5493 fw_event->event_data;
5495 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5496 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5497 _scsih_sas_topology_change_event_debug(ioc, event_data);
5500 if (ioc->remove_host || ioc->pci_error_recovery)
5503 if (!ioc->sas_hba.num_phys)
5504 _scsih_sas_host_add(ioc);
5506 _scsih_sas_host_refresh(ioc);
5508 if (fw_event->ignore) {
5509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5510 "event\n", ioc->name));
5514 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5516 /* handle expander add */
5517 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5518 if (_scsih_expander_add(ioc, parent_handle) != 0)
5521 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5522 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5525 sas_address = sas_expander->sas_address;
5526 max_phys = sas_expander->num_phys;
5527 } else if (parent_handle < ioc->sas_hba.num_phys) {
5528 sas_address = ioc->sas_hba.sas_address;
5529 max_phys = ioc->sas_hba.num_phys;
5531 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5534 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5536 /* handle siblings events */
5537 for (i = 0; i < event_data->NumEntries; i++) {
5538 if (fw_event->ignore) {
5539 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5540 "expander event\n", ioc->name));
5543 if (ioc->shost_recovery || ioc->remove_host ||
5544 ioc->pci_error_recovery)
5546 phy_number = event_data->StartPhyNum + i;
5547 if (phy_number >= max_phys)
5549 reason_code = event_data->PHY[i].PhyStatus &
5550 MPI2_EVENT_SAS_TOPO_RC_MASK;
5551 if ((event_data->PHY[i].PhyStatus &
5552 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5553 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5555 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5558 link_rate = event_data->PHY[i].LinkRate >> 4;
5559 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5560 switch (reason_code) {
5561 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5563 if (ioc->shost_recovery)
5566 if (link_rate == prev_link_rate)
5569 mpt2sas_transport_update_links(ioc, sas_address,
5570 handle, phy_number, link_rate);
5572 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5575 _scsih_check_device(ioc, handle);
5577 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5579 if (ioc->shost_recovery)
5582 mpt2sas_transport_update_links(ioc, sas_address,
5583 handle, phy_number, link_rate);
5585 _scsih_add_device(ioc, handle, phy_number, 0);
5587 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5589 _scsih_device_remove_by_handle(ioc, handle);
5594 /* handle expander removal */
5595 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5597 mpt2sas_expander_remove(ioc, sas_address);
5601 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5603 * _scsih_sas_device_status_change_event_debug - debug for device event
5604 * @event_data: event data payload
5610 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5611 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5613 char *reason_str = NULL;
5615 switch (event_data->ReasonCode) {
5616 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5617 reason_str = "smart data";
5619 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5620 reason_str = "unsupported device discovered";
5622 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5623 reason_str = "internal device reset";
5625 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5626 reason_str = "internal task abort";
5628 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5629 reason_str = "internal task abort set";
5631 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5632 reason_str = "internal clear task set";
5634 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5635 reason_str = "internal query task";
5637 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5638 reason_str = "sata init failure";
5640 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5641 reason_str = "internal device reset complete";
5643 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5644 reason_str = "internal task abort complete";
5646 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5647 reason_str = "internal async notification";
5649 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5650 reason_str = "expander reduced functionality";
5652 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5653 reason_str = "expander reduced functionality complete";
5656 reason_str = "unknown reason";
5659 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5660 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5661 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5662 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5663 le16_to_cpu(event_data->TaskTag));
5664 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5665 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5666 event_data->ASC, event_data->ASCQ);
5667 printk(KERN_INFO "\n");
5672 * _scsih_sas_device_status_change_event - handle device status change
5673 * @ioc: per adapter object
5674 * @fw_event: The fw_event_work object
5680 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5681 struct fw_event_work *fw_event)
5683 struct MPT2SAS_TARGET *target_priv_data;
5684 struct _sas_device *sas_device;
5686 unsigned long flags;
5687 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5688 (Mpi2EventDataSasDeviceStatusChange_t *)
5689 fw_event->event_data;
5691 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5692 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5693 _scsih_sas_device_status_change_event_debug(ioc,
5697 /* In MPI Revision K (0xC), the internal device reset complete was
5698 * implemented, so avoid setting tm_busy flag for older firmware.
5700 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5703 if (event_data->ReasonCode !=
5704 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5705 event_data->ReasonCode !=
5706 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5709 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5710 sas_address = le64_to_cpu(event_data->SASAddress);
5711 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5714 if (!sas_device || !sas_device->starget) {
5715 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5719 target_priv_data = sas_device->starget->hostdata;
5720 if (!target_priv_data) {
5721 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5725 if (event_data->ReasonCode ==
5726 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5727 target_priv_data->tm_busy = 1;
5729 target_priv_data->tm_busy = 0;
5730 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5733 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5735 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5736 * @ioc: per adapter object
5737 * @event_data: event data payload
5743 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5744 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5746 char *reason_str = NULL;
5748 switch (event_data->ReasonCode) {
5749 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5750 reason_str = "enclosure add";
5752 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5753 reason_str = "enclosure remove";
5756 reason_str = "unknown reason";
5760 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5761 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5762 " number slots(%d)\n", ioc->name, reason_str,
5763 le16_to_cpu(event_data->EnclosureHandle),
5764 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5765 le16_to_cpu(event_data->StartSlot));
5770 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5771 * @ioc: per adapter object
5772 * @fw_event: The fw_event_work object
5778 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5779 struct fw_event_work *fw_event)
5781 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5782 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5783 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5784 (Mpi2EventDataSasEnclDevStatusChange_t *)
5785 fw_event->event_data);
5790 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5791 * @ioc: per adapter object
5792 * @fw_event: The fw_event_work object
5798 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5799 struct fw_event_work *fw_event)
5801 struct scsi_cmnd *scmd;
5802 struct scsi_device *sdev;
5805 struct MPT2SAS_DEVICE *sas_device_priv_data;
5806 u32 termination_count;
5808 Mpi2SCSITaskManagementReply_t *mpi_reply;
5809 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5810 (Mpi2EventDataSasBroadcastPrimitive_t *)
5811 fw_event->event_data;
5813 unsigned long flags;
5816 u8 task_abort_retries;
5818 mutex_lock(&ioc->tm_cmds.mutex);
5820 "%s: enter: phy number(%d), width(%d)\n",
5821 ioc->name, __func__, event_data->PhyNum,
5822 event_data->PortWidth);
5824 _scsih_block_io_all_device(ioc);
5826 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5827 mpi_reply = ioc->tm_cmds.reply;
5828 broadcast_aen_retry:
5830 /* sanity checks for retrying this loop */
5831 if (max_retries++ == 5) {
5832 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5833 ioc->name, __func__));
5835 } else if (max_retries > 1)
5836 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5837 ioc->name, __func__, max_retries - 1));
5839 termination_count = 0;
5841 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5842 if (ioc->shost_recovery)
5844 scmd = _scsih_scsi_lookup_get(ioc, smid);
5847 sdev = scmd->device;
5848 sas_device_priv_data = sdev->hostdata;
5849 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5851 /* skip hidden raid components */
5852 if (sas_device_priv_data->sas_target->flags &
5853 MPT_TARGET_FLAGS_RAID_COMPONENT)
5856 if (sas_device_priv_data->sas_target->flags &
5857 MPT_TARGET_FLAGS_VOLUME)
5860 handle = sas_device_priv_data->sas_target->handle;
5861 lun = sas_device_priv_data->lun;
5864 if (ioc->shost_recovery)
5867 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5868 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5869 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5872 sdev_printk(KERN_WARNING, sdev,
5873 "mpt2sas_scsih_issue_tm: FAILED when sending "
5874 "QUERY_TASK: scmd(%p)\n", scmd);
5875 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5876 goto broadcast_aen_retry;
5878 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5879 & MPI2_IOCSTATUS_MASK;
5880 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5881 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5882 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5884 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5885 goto broadcast_aen_retry;
5888 /* see if IO is still owned by IOC and target */
5889 if (mpi_reply->ResponseCode ==
5890 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5891 mpi_reply->ResponseCode ==
5892 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5893 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5896 task_abort_retries = 0;
5898 if (task_abort_retries++ == 60) {
5899 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5900 "%s: ABORT_TASK: giving up\n", ioc->name,
5902 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5903 goto broadcast_aen_retry;
5906 if (ioc->shost_recovery)
5909 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5910 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5913 sdev_printk(KERN_WARNING, sdev,
5914 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5915 "scmd(%p)\n", scmd);
5919 if (task_abort_retries > 1)
5920 sdev_printk(KERN_WARNING, sdev,
5921 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5923 task_abort_retries - 1, scmd);
5925 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5926 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5929 if (ioc->broadcast_aen_pending) {
5930 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5931 " pending AEN\n", ioc->name, __func__));
5932 ioc->broadcast_aen_pending = 0;
5933 goto broadcast_aen_retry;
5937 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5940 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5941 "%s - exit, query_count = %d termination_count = %d\n",
5942 ioc->name, __func__, query_count, termination_count));
5944 ioc->broadcast_aen_busy = 0;
5945 if (!ioc->shost_recovery)
5946 _scsih_ublock_io_all_device(ioc);
5947 mutex_unlock(&ioc->tm_cmds.mutex);
5951 * _scsih_sas_discovery_event - handle discovery events
5952 * @ioc: per adapter object
5953 * @fw_event: The fw_event_work object
5959 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5960 struct fw_event_work *fw_event)
5962 Mpi2EventDataSasDiscovery_t *event_data =
5963 (Mpi2EventDataSasDiscovery_t *)
5964 fw_event->event_data;
5966 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5967 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5968 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5969 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5971 if (event_data->DiscoveryStatus)
5972 printk("discovery_status(0x%08x)",
5973 le32_to_cpu(event_data->DiscoveryStatus));
5978 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5979 !ioc->sas_hba.num_phys) {
5980 if (disable_discovery > 0 && ioc->shost_recovery) {
5981 /* Wait for the reset to complete */
5982 while (ioc->shost_recovery)
5985 _scsih_sas_host_add(ioc);
5990 * _scsih_reprobe_lun - reprobing lun
5991 * @sdev: scsi device struct
5992 * @no_uld_attach: sdev->no_uld_attach flag setting
5996 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6000 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6001 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6002 sdev->no_uld_attach ? "hidding" : "exposing");
6003 rc = scsi_device_reprobe(sdev);
6007 * _scsih_sas_volume_add - add new volume
6008 * @ioc: per adapter object
6009 * @element: IR config element data
6015 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6016 Mpi2EventIrConfigElement_t *element)
6018 struct _raid_device *raid_device;
6019 unsigned long flags;
6021 u16 handle = le16_to_cpu(element->VolDevHandle);
6024 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6026 printk(MPT2SAS_ERR_FMT
6027 "failure at %s:%d/%s()!\n", ioc->name,
6028 __FILE__, __LINE__, __func__);
6032 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6033 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6034 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6039 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6041 printk(MPT2SAS_ERR_FMT
6042 "failure at %s:%d/%s()!\n", ioc->name,
6043 __FILE__, __LINE__, __func__);
6047 raid_device->id = ioc->sas_id++;
6048 raid_device->channel = RAID_CHANNEL;
6049 raid_device->handle = handle;
6050 raid_device->wwid = wwid;
6051 _scsih_raid_device_add(ioc, raid_device);
6052 if (!ioc->wait_for_discovery_to_complete) {
6053 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6054 raid_device->id, 0);
6056 _scsih_raid_device_remove(ioc, raid_device);
6058 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6059 _scsih_determine_boot_device(ioc, raid_device, 1);
6060 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6065 * _scsih_sas_volume_delete - delete volume
6066 * @ioc: per adapter object
6067 * @handle: volume device handle
6073 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6075 struct _raid_device *raid_device;
6076 unsigned long flags;
6077 struct MPT2SAS_TARGET *sas_target_priv_data;
6078 struct scsi_target *starget = NULL;
6080 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6081 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6083 if (raid_device->starget) {
6084 starget = raid_device->starget;
6085 sas_target_priv_data = starget->hostdata;
6086 sas_target_priv_data->deleted = 1;
6088 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6089 "(0x%016llx)\n", ioc->name, raid_device->handle,
6090 (unsigned long long) raid_device->wwid);
6091 list_del(&raid_device->list);
6094 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6096 scsi_remove_target(&starget->dev);
6100 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6101 * @ioc: per adapter object
6102 * @element: IR config element data
6108 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6109 Mpi2EventIrConfigElement_t *element)
6111 struct _sas_device *sas_device;
6112 struct scsi_target *starget = NULL;
6113 struct MPT2SAS_TARGET *sas_target_priv_data;
6114 unsigned long flags;
6115 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6117 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6118 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6120 sas_device->volume_handle = 0;
6121 sas_device->volume_wwid = 0;
6122 clear_bit(handle, ioc->pd_handles);
6123 if (sas_device->starget && sas_device->starget->hostdata) {
6124 starget = sas_device->starget;
6125 sas_target_priv_data = starget->hostdata;
6126 sas_target_priv_data->flags &=
6127 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6130 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6134 /* exposing raid component */
6136 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6140 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6141 * @ioc: per adapter object
6142 * @element: IR config element data
6148 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6149 Mpi2EventIrConfigElement_t *element)
6151 struct _sas_device *sas_device;
6152 struct scsi_target *starget = NULL;
6153 struct MPT2SAS_TARGET *sas_target_priv_data;
6154 unsigned long flags;
6155 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6156 u16 volume_handle = 0;
6157 u64 volume_wwid = 0;
6159 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6161 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6164 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6165 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6167 set_bit(handle, ioc->pd_handles);
6168 if (sas_device->starget && sas_device->starget->hostdata) {
6169 starget = sas_device->starget;
6170 sas_target_priv_data = starget->hostdata;
6171 sas_target_priv_data->flags |=
6172 MPT_TARGET_FLAGS_RAID_COMPONENT;
6173 sas_device->volume_handle = volume_handle;
6174 sas_device->volume_wwid = volume_wwid;
6177 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6181 /* hiding raid component */
6183 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6187 * _scsih_sas_pd_delete - delete pd component
6188 * @ioc: per adapter object
6189 * @element: IR config element data
6195 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6196 Mpi2EventIrConfigElement_t *element)
6198 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6200 _scsih_device_remove_by_handle(ioc, handle);
6204 * _scsih_sas_pd_add - remove pd component
6205 * @ioc: per adapter object
6206 * @element: IR config element data
6212 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6213 Mpi2EventIrConfigElement_t *element)
6215 struct _sas_device *sas_device;
6216 unsigned long flags;
6217 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6218 Mpi2ConfigReply_t mpi_reply;
6219 Mpi2SasDevicePage0_t sas_device_pg0;
6224 set_bit(handle, ioc->pd_handles);
6226 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6227 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6228 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6232 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6233 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6234 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6235 ioc->name, __FILE__, __LINE__, __func__);
6239 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6240 MPI2_IOCSTATUS_MASK;
6241 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6242 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6243 ioc->name, __FILE__, __LINE__, __func__);
6247 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6248 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6249 mpt2sas_transport_update_links(ioc, sas_address, handle,
6250 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6252 _scsih_add_device(ioc, handle, 0, 1);
6255 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6257 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6258 * @ioc: per adapter object
6259 * @event_data: event data payload
6265 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6266 Mpi2EventDataIrConfigChangeList_t *event_data)
6268 Mpi2EventIrConfigElement_t *element;
6271 char *reason_str = NULL, *element_str = NULL;
6273 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6275 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6276 ioc->name, (le32_to_cpu(event_data->Flags) &
6277 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6278 "foreign" : "native", event_data->NumElements);
6279 for (i = 0; i < event_data->NumElements; i++, element++) {
6280 switch (element->ReasonCode) {
6281 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6284 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6285 reason_str = "remove";
6287 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6288 reason_str = "no change";
6290 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6291 reason_str = "hide";
6293 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6294 reason_str = "unhide";
6296 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6297 reason_str = "volume_created";
6299 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6300 reason_str = "volume_deleted";
6302 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6303 reason_str = "pd_created";
6305 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6306 reason_str = "pd_deleted";
6309 reason_str = "unknown reason";
6312 element_type = le16_to_cpu(element->ElementFlags) &
6313 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6314 switch (element_type) {
6315 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6316 element_str = "volume";
6318 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6319 element_str = "phys disk";
6321 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6322 element_str = "hot spare";
6325 element_str = "unknown element";
6328 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6329 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6330 reason_str, le16_to_cpu(element->VolDevHandle),
6331 le16_to_cpu(element->PhysDiskDevHandle),
6332 element->PhysDiskNum);
6338 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6339 * @ioc: per adapter object
6340 * @fw_event: The fw_event_work object
6346 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6347 struct fw_event_work *fw_event)
6349 Mpi2EventIrConfigElement_t *element;
6352 Mpi2EventDataIrConfigChangeList_t *event_data =
6353 (Mpi2EventDataIrConfigChangeList_t *)
6354 fw_event->event_data;
6356 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6357 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6358 && !ioc->hide_ir_msg)
6359 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6363 if (ioc->shost_recovery)
6366 foreign_config = (le32_to_cpu(event_data->Flags) &
6367 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6369 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6370 for (i = 0; i < event_data->NumElements; i++, element++) {
6372 switch (element->ReasonCode) {
6373 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6374 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6375 if (!foreign_config)
6376 _scsih_sas_volume_add(ioc, element);
6378 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6379 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6380 if (!foreign_config)
6381 _scsih_sas_volume_delete(ioc,
6382 le16_to_cpu(element->VolDevHandle));
6384 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6385 if (!ioc->is_warpdrive)
6386 _scsih_sas_pd_hide(ioc, element);
6388 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6389 if (!ioc->is_warpdrive)
6390 _scsih_sas_pd_expose(ioc, element);
6392 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6393 if (!ioc->is_warpdrive)
6394 _scsih_sas_pd_add(ioc, element);
6396 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6397 if (!ioc->is_warpdrive)
6398 _scsih_sas_pd_delete(ioc, element);
6405 * _scsih_sas_ir_volume_event - IR volume event
6406 * @ioc: per adapter object
6407 * @fw_event: The fw_event_work object
6413 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6414 struct fw_event_work *fw_event)
6417 unsigned long flags;
6418 struct _raid_device *raid_device;
6422 Mpi2EventDataIrVolume_t *event_data =
6423 (Mpi2EventDataIrVolume_t *)
6424 fw_event->event_data;
6426 if (ioc->shost_recovery)
6429 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6432 handle = le16_to_cpu(event_data->VolDevHandle);
6433 state = le32_to_cpu(event_data->NewValue);
6434 if (!ioc->hide_ir_msg)
6435 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6436 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6437 le32_to_cpu(event_data->PreviousValue), state));
6440 case MPI2_RAID_VOL_STATE_MISSING:
6441 case MPI2_RAID_VOL_STATE_FAILED:
6442 _scsih_sas_volume_delete(ioc, handle);
6445 case MPI2_RAID_VOL_STATE_ONLINE:
6446 case MPI2_RAID_VOL_STATE_DEGRADED:
6447 case MPI2_RAID_VOL_STATE_OPTIMAL:
6449 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6450 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6451 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6456 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6458 printk(MPT2SAS_ERR_FMT
6459 "failure at %s:%d/%s()!\n", ioc->name,
6460 __FILE__, __LINE__, __func__);
6464 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6466 printk(MPT2SAS_ERR_FMT
6467 "failure at %s:%d/%s()!\n", ioc->name,
6468 __FILE__, __LINE__, __func__);
6472 raid_device->id = ioc->sas_id++;
6473 raid_device->channel = RAID_CHANNEL;
6474 raid_device->handle = handle;
6475 raid_device->wwid = wwid;
6476 _scsih_raid_device_add(ioc, raid_device);
6477 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6478 raid_device->id, 0);
6480 _scsih_raid_device_remove(ioc, raid_device);
6483 case MPI2_RAID_VOL_STATE_INITIALIZING:
6490 * _scsih_sas_ir_physical_disk_event - PD event
6491 * @ioc: per adapter object
6492 * @fw_event: The fw_event_work object
6498 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6499 struct fw_event_work *fw_event)
6501 u16 handle, parent_handle;
6503 struct _sas_device *sas_device;
6504 unsigned long flags;
6505 Mpi2ConfigReply_t mpi_reply;
6506 Mpi2SasDevicePage0_t sas_device_pg0;
6508 Mpi2EventDataIrPhysicalDisk_t *event_data =
6509 (Mpi2EventDataIrPhysicalDisk_t *)
6510 fw_event->event_data;
6513 if (ioc->shost_recovery)
6516 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6519 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6520 state = le32_to_cpu(event_data->NewValue);
6522 if (!ioc->hide_ir_msg)
6523 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6524 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6525 le32_to_cpu(event_data->PreviousValue), state));
6528 case MPI2_RAID_PD_STATE_ONLINE:
6529 case MPI2_RAID_PD_STATE_DEGRADED:
6530 case MPI2_RAID_PD_STATE_REBUILDING:
6531 case MPI2_RAID_PD_STATE_OPTIMAL:
6532 case MPI2_RAID_PD_STATE_HOT_SPARE:
6534 if (!ioc->is_warpdrive)
6535 set_bit(handle, ioc->pd_handles);
6537 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6538 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6539 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6544 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6545 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6547 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6548 ioc->name, __FILE__, __LINE__, __func__);
6552 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6553 MPI2_IOCSTATUS_MASK;
6554 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6555 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6556 ioc->name, __FILE__, __LINE__, __func__);
6560 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6561 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6562 mpt2sas_transport_update_links(ioc, sas_address, handle,
6563 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6565 _scsih_add_device(ioc, handle, 0, 1);
6569 case MPI2_RAID_PD_STATE_OFFLINE:
6570 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6571 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6577 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6579 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6580 * @ioc: per adapter object
6581 * @event_data: event data payload
6587 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6588 Mpi2EventDataIrOperationStatus_t *event_data)
6590 char *reason_str = NULL;
6592 switch (event_data->RAIDOperation) {
6593 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6594 reason_str = "resync";
6596 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6597 reason_str = "online capacity expansion";
6599 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6600 reason_str = "consistency check";
6602 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6603 reason_str = "background init";
6605 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6606 reason_str = "make data consistent";
6613 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6614 "\thandle(0x%04x), percent complete(%d)\n",
6615 ioc->name, reason_str,
6616 le16_to_cpu(event_data->VolDevHandle),
6617 event_data->PercentComplete);
6622 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6623 * @ioc: per adapter object
6624 * @fw_event: The fw_event_work object
6630 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6631 struct fw_event_work *fw_event)
6633 Mpi2EventDataIrOperationStatus_t *event_data =
6634 (Mpi2EventDataIrOperationStatus_t *)
6635 fw_event->event_data;
6636 static struct _raid_device *raid_device;
6637 unsigned long flags;
6640 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6641 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6642 && !ioc->hide_ir_msg)
6643 _scsih_sas_ir_operation_status_event_debug(ioc,
6647 /* code added for raid transport support */
6648 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6650 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6651 handle = le16_to_cpu(event_data->VolDevHandle);
6652 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6654 raid_device->percent_complete =
6655 event_data->PercentComplete;
6656 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6661 * _scsih_prep_device_scan - initialize parameters prior to device scan
6662 * @ioc: per adapter object
6664 * Set the deleted flag prior to device scan. If the device is found during
6665 * the scan, then we clear the deleted flag.
6668 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6670 struct MPT2SAS_DEVICE *sas_device_priv_data;
6671 struct scsi_device *sdev;
6673 shost_for_each_device(sdev, ioc->shost) {
6674 sas_device_priv_data = sdev->hostdata;
6675 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6676 sas_device_priv_data->sas_target->deleted = 1;
6681 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6682 * @ioc: per adapter object
6683 * @sas_address: sas address
6684 * @slot: enclosure slot id
6685 * @handle: device handle
6687 * After host reset, find out whether devices are still responding.
6688 * Used in _scsi_remove_unresponsive_sas_devices.
6693 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6694 u16 slot, u16 handle)
6696 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6697 struct scsi_target *starget;
6698 struct _sas_device *sas_device;
6699 unsigned long flags;
6701 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6702 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6703 if (sas_device->sas_address == sas_address &&
6704 sas_device->slot == slot) {
6705 sas_device->responding = 1;
6706 starget = sas_device->starget;
6707 if (starget && starget->hostdata) {
6708 sas_target_priv_data = starget->hostdata;
6709 sas_target_priv_data->tm_busy = 0;
6710 sas_target_priv_data->deleted = 0;
6712 sas_target_priv_data = NULL;
6714 starget_printk(KERN_INFO, starget,
6715 "handle(0x%04x), sas_addr(0x%016llx), "
6716 "enclosure logical id(0x%016llx), "
6717 "slot(%d)\n", handle,
6718 (unsigned long long)sas_device->sas_address,
6719 (unsigned long long)
6720 sas_device->enclosure_logical_id,
6722 if (sas_device->handle == handle)
6724 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6725 sas_device->handle);
6726 sas_device->handle = handle;
6727 if (sas_target_priv_data)
6728 sas_target_priv_data->handle = handle;
6733 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6737 * _scsih_search_responding_sas_devices -
6738 * @ioc: per adapter object
6740 * After host reset, find out whether devices are still responding.
6746 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6748 Mpi2SasDevicePage0_t sas_device_pg0;
6749 Mpi2ConfigReply_t mpi_reply;
6756 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6758 if (list_empty(&ioc->sas_device_list))
6762 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6763 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6765 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6766 MPI2_IOCSTATUS_MASK;
6767 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6769 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6770 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6771 if (!(_scsih_is_end_device(device_info)))
6773 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6774 slot = le16_to_cpu(sas_device_pg0.Slot);
6775 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6779 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6784 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6785 * @ioc: per adapter object
6786 * @wwid: world wide identifier for raid volume
6787 * @handle: device handle
6789 * After host reset, find out whether devices are still responding.
6790 * Used in _scsi_remove_unresponsive_raid_devices.
6795 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6798 struct MPT2SAS_TARGET *sas_target_priv_data;
6799 struct scsi_target *starget;
6800 struct _raid_device *raid_device;
6801 unsigned long flags;
6803 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6804 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6805 if (raid_device->wwid == wwid && raid_device->starget) {
6806 starget = raid_device->starget;
6807 if (starget && starget->hostdata) {
6808 sas_target_priv_data = starget->hostdata;
6809 sas_target_priv_data->deleted = 0;
6811 sas_target_priv_data = NULL;
6812 raid_device->responding = 1;
6813 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6814 starget_printk(KERN_INFO, raid_device->starget,
6815 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6816 (unsigned long long)raid_device->wwid);
6818 * WARPDRIVE: The handles of the PDs might have changed
6819 * across the host reset so re-initialize the
6820 * required data for Direct IO
6822 _scsih_init_warpdrive_properties(ioc, raid_device);
6823 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6824 if (raid_device->handle == handle) {
6825 spin_unlock_irqrestore(&ioc->raid_device_lock,
6829 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6830 raid_device->handle);
6831 raid_device->handle = handle;
6832 if (sas_target_priv_data)
6833 sas_target_priv_data->handle = handle;
6834 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6839 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6843 * _scsih_search_responding_raid_devices -
6844 * @ioc: per adapter object
6846 * After host reset, find out whether devices are still responding.
6852 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6854 Mpi2RaidVolPage1_t volume_pg1;
6855 Mpi2RaidVolPage0_t volume_pg0;
6856 Mpi2RaidPhysDiskPage0_t pd_pg0;
6857 Mpi2ConfigReply_t mpi_reply;
6862 if (!ioc->ir_firmware)
6865 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6868 if (list_empty(&ioc->raid_device_list))
6872 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6873 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6874 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6875 MPI2_IOCSTATUS_MASK;
6876 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6878 handle = le16_to_cpu(volume_pg1.DevHandle);
6880 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6881 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6882 sizeof(Mpi2RaidVolPage0_t)))
6885 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6886 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6887 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6888 _scsih_mark_responding_raid_device(ioc,
6889 le64_to_cpu(volume_pg1.WWID), handle);
6892 /* refresh the pd_handles */
6893 if (!ioc->is_warpdrive) {
6894 phys_disk_num = 0xFF;
6895 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6896 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6897 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6899 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6900 MPI2_IOCSTATUS_MASK;
6901 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6903 phys_disk_num = pd_pg0.PhysDiskNum;
6904 handle = le16_to_cpu(pd_pg0.DevHandle);
6905 set_bit(handle, ioc->pd_handles);
6909 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6910 "complete\n", ioc->name);
6914 * _scsih_mark_responding_expander - mark a expander as responding
6915 * @ioc: per adapter object
6916 * @sas_address: sas address
6919 * After host reset, find out whether devices are still responding.
6920 * Used in _scsi_remove_unresponsive_expanders.
6925 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6928 struct _sas_node *sas_expander;
6929 unsigned long flags;
6932 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6933 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6934 if (sas_expander->sas_address != sas_address)
6936 sas_expander->responding = 1;
6937 if (sas_expander->handle == handle)
6939 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6940 " from(0x%04x) to (0x%04x)!!!\n",
6941 (unsigned long long)sas_expander->sas_address,
6942 sas_expander->handle, handle);
6943 sas_expander->handle = handle;
6944 for (i = 0 ; i < sas_expander->num_phys ; i++)
6945 sas_expander->phy[i].handle = handle;
6949 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6953 * _scsih_search_responding_expanders -
6954 * @ioc: per adapter object
6956 * After host reset, find out whether devices are still responding.
6962 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6964 Mpi2ExpanderPage0_t expander_pg0;
6965 Mpi2ConfigReply_t mpi_reply;
6970 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6972 if (list_empty(&ioc->sas_expander_list))
6976 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6977 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6979 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6980 MPI2_IOCSTATUS_MASK;
6981 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6984 handle = le16_to_cpu(expander_pg0.DevHandle);
6985 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6986 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6987 "sas_addr(0x%016llx)\n", handle,
6988 (unsigned long long)sas_address);
6989 _scsih_mark_responding_expander(ioc, sas_address, handle);
6993 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6997 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6998 * @ioc: per adapter object
7003 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
7005 struct _sas_device *sas_device, *sas_device_next;
7006 struct _sas_node *sas_expander, *sas_expander_next;
7007 struct _raid_device *raid_device, *raid_device_next;
7008 struct list_head tmp_list;
7009 unsigned long flags;
7011 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7014 /* removing unresponding end devices */
7015 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7017 list_for_each_entry_safe(sas_device, sas_device_next,
7018 &ioc->sas_device_list, list) {
7019 if (!sas_device->responding)
7020 mpt2sas_device_remove_by_sas_address(ioc,
7021 sas_device->sas_address);
7023 sas_device->responding = 0;
7026 /* removing unresponding volumes */
7027 if (ioc->ir_firmware) {
7028 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7029 "volumes\n", ioc->name);
7030 list_for_each_entry_safe(raid_device, raid_device_next,
7031 &ioc->raid_device_list, list) {
7032 if (!raid_device->responding)
7033 _scsih_sas_volume_delete(ioc,
7034 raid_device->handle);
7036 raid_device->responding = 0;
7039 /* removing unresponding expanders */
7040 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7042 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7043 INIT_LIST_HEAD(&tmp_list);
7044 list_for_each_entry_safe(sas_expander, sas_expander_next,
7045 &ioc->sas_expander_list, list) {
7046 if (!sas_expander->responding)
7047 list_move_tail(&sas_expander->list, &tmp_list);
7049 sas_expander->responding = 0;
7051 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7052 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7054 list_del(&sas_expander->list);
7055 _scsih_expander_node_remove(ioc, sas_expander);
7057 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7059 /* unblock devices */
7060 _scsih_ublock_io_all_device(ioc);
7064 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7065 struct _sas_node *sas_expander, u16 handle)
7067 Mpi2ExpanderPage1_t expander_pg1;
7068 Mpi2ConfigReply_t mpi_reply;
7071 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7072 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7073 &expander_pg1, i, handle))) {
7074 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7075 ioc->name, __FILE__, __LINE__, __func__);
7079 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7080 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7081 expander_pg1.NegotiatedLinkRate >> 4);
7086 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7087 * @ioc: per adapter object
7092 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7094 Mpi2ExpanderPage0_t expander_pg0;
7095 Mpi2SasDevicePage0_t sas_device_pg0;
7096 Mpi2RaidVolPage1_t volume_pg1;
7097 Mpi2RaidVolPage0_t volume_pg0;
7098 Mpi2RaidPhysDiskPage0_t pd_pg0;
7099 Mpi2EventIrConfigElement_t element;
7100 Mpi2ConfigReply_t mpi_reply;
7103 u16 handle, parent_handle;
7105 struct _sas_device *sas_device;
7106 struct _sas_node *expander_device;
7107 static struct _raid_device *raid_device;
7109 unsigned long flags;
7111 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7113 _scsih_sas_host_refresh(ioc);
7115 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7119 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7120 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7121 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7122 MPI2_IOCSTATUS_MASK;
7123 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7124 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7125 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7126 ioc->name, ioc_status,
7127 le32_to_cpu(mpi_reply.IOCLogInfo));
7130 handle = le16_to_cpu(expander_pg0.DevHandle);
7131 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7132 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7133 ioc, le64_to_cpu(expander_pg0.SASAddress));
7134 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7135 if (expander_device)
7136 _scsih_refresh_expander_links(ioc, expander_device,
7139 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7140 "handle (0x%04x), sas_addr(0x%016llx)\n",
7141 ioc->name, handle, (unsigned long long)
7142 le64_to_cpu(expander_pg0.SASAddress));
7143 _scsih_expander_add(ioc, handle);
7144 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7145 "handle (0x%04x), sas_addr(0x%016llx)\n",
7146 ioc->name, handle, (unsigned long long)
7147 le64_to_cpu(expander_pg0.SASAddress));
7151 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7154 if (!ioc->ir_firmware)
7157 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7159 phys_disk_num = 0xFF;
7160 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7161 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7163 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7164 MPI2_IOCSTATUS_MASK;
7165 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7166 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7167 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7168 ioc->name, ioc_status,
7169 le32_to_cpu(mpi_reply.IOCLogInfo));
7172 phys_disk_num = pd_pg0.PhysDiskNum;
7173 handle = le16_to_cpu(pd_pg0.DevHandle);
7174 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7175 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7176 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7179 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7180 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7183 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7184 MPI2_IOCSTATUS_MASK;
7185 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7186 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7187 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7188 ioc->name, ioc_status,
7189 le32_to_cpu(mpi_reply.IOCLogInfo));
7192 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7193 if (!_scsih_get_sas_address(ioc, parent_handle,
7195 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7196 " handle (0x%04x), sas_addr(0x%016llx)\n",
7197 ioc->name, handle, (unsigned long long)
7198 le64_to_cpu(sas_device_pg0.SASAddress));
7199 mpt2sas_transport_update_links(ioc, sas_address,
7200 handle, sas_device_pg0.PhyNum,
7201 MPI2_SAS_NEG_LINK_RATE_1_5);
7202 set_bit(handle, ioc->pd_handles);
7204 /* This will retry adding the end device.
7205 * _scsih_add_device() will decide on retries and
7206 * return "1" when it should be retried
7208 while (_scsih_add_device(ioc, handle, retry_count++,
7212 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7213 " handle (0x%04x), sas_addr(0x%016llx)\n",
7214 ioc->name, handle, (unsigned long long)
7215 le64_to_cpu(sas_device_pg0.SASAddress));
7219 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7222 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7225 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7226 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7227 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7228 MPI2_IOCSTATUS_MASK;
7229 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7230 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7231 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7232 ioc->name, ioc_status,
7233 le32_to_cpu(mpi_reply.IOCLogInfo));
7236 handle = le16_to_cpu(volume_pg1.DevHandle);
7237 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7238 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7239 le64_to_cpu(volume_pg1.WWID));
7240 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7243 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7244 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7245 sizeof(Mpi2RaidVolPage0_t)))
7247 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7248 MPI2_IOCSTATUS_MASK;
7249 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7250 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7251 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7252 ioc->name, ioc_status,
7253 le32_to_cpu(mpi_reply.IOCLogInfo));
7256 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7257 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7258 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7259 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7260 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7261 element.VolDevHandle = volume_pg1.DevHandle;
7262 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7263 " handle (0x%04x)\n", ioc->name,
7264 volume_pg1.DevHandle);
7265 _scsih_sas_volume_add(ioc, &element);
7266 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7267 " handle (0x%04x)\n", ioc->name,
7268 volume_pg1.DevHandle);
7272 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7277 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7281 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7282 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7284 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7285 MPI2_IOCSTATUS_MASK;
7286 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7287 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7288 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7289 ioc->name, ioc_status,
7290 le32_to_cpu(mpi_reply.IOCLogInfo));
7293 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7294 if (!(_scsih_is_end_device(
7295 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7297 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7298 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7299 le64_to_cpu(sas_device_pg0.SASAddress));
7300 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7303 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7304 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7305 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7306 "handle (0x%04x), sas_addr(0x%016llx)\n",
7307 ioc->name, handle, (unsigned long long)
7308 le64_to_cpu(sas_device_pg0.SASAddress));
7309 mpt2sas_transport_update_links(ioc, sas_address, handle,
7310 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7312 /* This will retry adding the end device.
7313 * _scsih_add_device() will decide on retries and
7314 * return "1" when it should be retried
7316 while (_scsih_add_device(ioc, handle, retry_count++,
7320 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7321 "handle (0x%04x), sas_addr(0x%016llx)\n",
7322 ioc->name, handle, (unsigned long long)
7323 le64_to_cpu(sas_device_pg0.SASAddress));
7327 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7330 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7335 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7336 * @ioc: per adapter object
7337 * @reset_phase: phase
7339 * The handler for doing any required cleanup or initialization.
7341 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7342 * MPT2_IOC_DONE_RESET
7347 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7349 switch (reset_phase) {
7350 case MPT2_IOC_PRE_RESET:
7351 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7352 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7354 case MPT2_IOC_AFTER_RESET:
7355 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7356 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7357 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7358 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7359 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7360 complete(&ioc->scsih_cmds.done);
7362 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7363 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7364 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7365 complete(&ioc->tm_cmds.done);
7367 _scsih_fw_event_cleanup_queue(ioc);
7368 _scsih_flush_running_cmds(ioc);
7370 case MPT2_IOC_DONE_RESET:
7371 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7372 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7373 _scsih_sas_host_refresh(ioc);
7374 _scsih_prep_device_scan(ioc);
7375 _scsih_search_responding_sas_devices(ioc);
7376 _scsih_search_responding_raid_devices(ioc);
7377 _scsih_search_responding_expanders(ioc);
7378 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7379 !ioc->sas_hba.num_phys)) {
7380 _scsih_prep_device_scan(ioc);
7381 _scsih_search_responding_sas_devices(ioc);
7382 _scsih_search_responding_raid_devices(ioc);
7383 _scsih_search_responding_expanders(ioc);
7384 _scsih_error_recovery_delete_devices(ioc);
7391 * _firmware_event_work - delayed task for processing firmware events
7392 * @ioc: per adapter object
7393 * @work: equal to the fw_event_work object
7399 _firmware_event_work(struct work_struct *work)
7401 struct fw_event_work *fw_event = container_of(work,
7402 struct fw_event_work, delayed_work.work);
7403 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7405 /* the queue is being flushed so ignore this event */
7406 if (ioc->remove_host ||
7407 ioc->pci_error_recovery) {
7408 _scsih_fw_event_free(ioc, fw_event);
7412 switch (fw_event->event) {
7413 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7414 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7416 _scsih_remove_unresponding_sas_devices(ioc);
7417 _scsih_scan_for_devices_after_reset(ioc);
7419 case MPT2SAS_PORT_ENABLE_COMPLETE:
7420 ioc->start_scan = 0;
7422 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7423 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7426 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7427 "from worker thread\n", ioc->name));
7429 case MPT2SAS_TURN_ON_PFA_LED:
7430 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7432 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7433 _scsih_sas_topology_change_event(ioc, fw_event);
7435 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7436 _scsih_sas_device_status_change_event(ioc,
7439 case MPI2_EVENT_SAS_DISCOVERY:
7440 _scsih_sas_discovery_event(ioc,
7443 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7444 _scsih_sas_broadcast_primitive_event(ioc,
7447 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7448 _scsih_sas_enclosure_dev_status_change_event(ioc,
7451 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7452 _scsih_sas_ir_config_change_event(ioc, fw_event);
7454 case MPI2_EVENT_IR_VOLUME:
7455 _scsih_sas_ir_volume_event(ioc, fw_event);
7457 case MPI2_EVENT_IR_PHYSICAL_DISK:
7458 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7460 case MPI2_EVENT_IR_OPERATION_STATUS:
7461 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7464 _scsih_fw_event_free(ioc, fw_event);
7468 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7469 * @ioc: per adapter object
7470 * @msix_index: MSIX table index supplied by the OS
7471 * @reply: reply message frame(lower 32bit addr)
7472 * Context: interrupt.
7474 * This function merely adds a new work task into ioc->firmware_event_thread.
7475 * The tasks are worked from _firmware_event_work in user context.
7480 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7483 struct fw_event_work *fw_event;
7484 Mpi2EventNotificationReply_t *mpi_reply;
7488 /* events turned off due to host reset or driver unloading */
7489 if (ioc->remove_host || ioc->pci_error_recovery)
7492 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7494 if (unlikely(!mpi_reply)) {
7495 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7496 ioc->name, __FILE__, __LINE__, __func__);
7500 event = le16_to_cpu(mpi_reply->Event);
7504 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7506 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7507 (Mpi2EventDataSasBroadcastPrimitive_t *)
7508 mpi_reply->EventData;
7510 if (baen_data->Primitive !=
7511 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7514 if (ioc->broadcast_aen_busy) {
7515 ioc->broadcast_aen_pending++;
7518 ioc->broadcast_aen_busy = 1;
7522 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7523 _scsih_check_topo_delete_events(ioc,
7524 (Mpi2EventDataSasTopologyChangeList_t *)
7525 mpi_reply->EventData);
7527 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7528 _scsih_check_ir_config_unhide_events(ioc,
7529 (Mpi2EventDataIrConfigChangeList_t *)
7530 mpi_reply->EventData);
7532 case MPI2_EVENT_IR_VOLUME:
7533 _scsih_check_volume_delete_events(ioc,
7534 (Mpi2EventDataIrVolume_t *)
7535 mpi_reply->EventData);
7537 case MPI2_EVENT_LOG_ENTRY_ADDED:
7539 Mpi2EventDataLogEntryAdded_t *log_entry;
7542 if (!ioc->is_warpdrive)
7545 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7546 mpi_reply->EventData;
7547 log_code = (__le32 *)log_entry->LogData;
7549 if (le16_to_cpu(log_entry->LogEntryQualifier)
7550 != MPT2_WARPDRIVE_LOGENTRY)
7553 switch (le32_to_cpu(*log_code)) {
7554 case MPT2_WARPDRIVE_LC_SSDT:
7555 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7556 "IO Throttling has occurred in the WarpDrive "
7557 "subsystem. Check WarpDrive documentation for "
7558 "additional details.\n", ioc->name);
7560 case MPT2_WARPDRIVE_LC_SSDLW:
7561 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7562 "Program/Erase Cycles for the WarpDrive subsystem "
7563 "in degraded range. Check WarpDrive documentation "
7564 "for additional details.\n", ioc->name);
7566 case MPT2_WARPDRIVE_LC_SSDLF:
7567 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7568 "There are no Program/Erase Cycles for the "
7569 "WarpDrive subsystem. The storage device will be "
7570 "in read-only mode. Check WarpDrive documentation "
7571 "for additional details.\n", ioc->name);
7573 case MPT2_WARPDRIVE_LC_BRMF:
7574 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7575 "The Backup Rail Monitor has failed on the "
7576 "WarpDrive subsystem. Check WarpDrive "
7577 "documentation for additional details.\n",
7584 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7585 case MPI2_EVENT_IR_OPERATION_STATUS:
7586 case MPI2_EVENT_SAS_DISCOVERY:
7587 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7588 case MPI2_EVENT_IR_PHYSICAL_DISK:
7591 default: /* ignore the rest */
7595 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7596 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7598 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7599 ioc->name, __FILE__, __LINE__, __func__);
7603 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7604 fw_event->ioc = ioc;
7605 fw_event->VF_ID = mpi_reply->VF_ID;
7606 fw_event->VP_ID = mpi_reply->VP_ID;
7607 fw_event->event = event;
7608 _scsih_fw_event_add(ioc, fw_event);
7612 /* shost template */
7613 static struct scsi_host_template scsih_driver_template = {
7614 .module = THIS_MODULE,
7615 .name = "Fusion MPT SAS Host",
7616 .proc_name = MPT2SAS_DRIVER_NAME,
7617 .queuecommand = _scsih_qcmd,
7618 .target_alloc = _scsih_target_alloc,
7619 .slave_alloc = _scsih_slave_alloc,
7620 .slave_configure = _scsih_slave_configure,
7621 .target_destroy = _scsih_target_destroy,
7622 .slave_destroy = _scsih_slave_destroy,
7623 .scan_finished = _scsih_scan_finished,
7624 .scan_start = _scsih_scan_start,
7625 .change_queue_depth = _scsih_change_queue_depth,
7626 .change_queue_type = scsi_change_queue_type,
7627 .eh_abort_handler = _scsih_abort,
7628 .eh_device_reset_handler = _scsih_dev_reset,
7629 .eh_target_reset_handler = _scsih_target_reset,
7630 .eh_host_reset_handler = _scsih_host_reset,
7631 .bios_param = _scsih_bios_param,
7634 .sg_tablesize = MPT2SAS_SG_DEPTH,
7635 .max_sectors = 32767,
7637 .use_clustering = ENABLE_CLUSTERING,
7638 .shost_attrs = mpt2sas_host_attrs,
7639 .sdev_attrs = mpt2sas_dev_attrs,
7643 * _scsih_expander_node_remove - removing expander device from list.
7644 * @ioc: per adapter object
7645 * @sas_expander: the sas_device object
7646 * Context: Calling function should acquire ioc->sas_node_lock.
7648 * Removing object and freeing associated memory from the
7649 * ioc->sas_expander_list.
7654 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7655 struct _sas_node *sas_expander)
7657 struct _sas_port *mpt2sas_port, *next;
7659 /* remove sibling ports attached to this expander */
7660 list_for_each_entry_safe(mpt2sas_port, next,
7661 &sas_expander->sas_port_list, port_list) {
7662 if (ioc->shost_recovery)
7664 if (mpt2sas_port->remote_identify.device_type ==
7666 mpt2sas_device_remove_by_sas_address(ioc,
7667 mpt2sas_port->remote_identify.sas_address);
7668 else if (mpt2sas_port->remote_identify.device_type ==
7669 SAS_EDGE_EXPANDER_DEVICE ||
7670 mpt2sas_port->remote_identify.device_type ==
7671 SAS_FANOUT_EXPANDER_DEVICE)
7672 mpt2sas_expander_remove(ioc,
7673 mpt2sas_port->remote_identify.sas_address);
7676 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7677 sas_expander->sas_address_parent);
7679 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7680 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7681 sas_expander->handle, (unsigned long long)
7682 sas_expander->sas_address);
7684 kfree(sas_expander->phy);
7685 kfree(sas_expander);
7689 * _scsih_ir_shutdown - IR shutdown notification
7690 * @ioc: per adapter object
7692 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7693 * the host system is shutting down.
7698 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7700 Mpi2RaidActionRequest_t *mpi_request;
7701 Mpi2RaidActionReply_t *mpi_reply;
7704 /* is IR firmware build loaded ? */
7705 if (!ioc->ir_firmware)
7708 mutex_lock(&ioc->scsih_cmds.mutex);
7710 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7711 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7712 ioc->name, __func__);
7715 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7717 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7719 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7720 ioc->name, __func__);
7721 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7725 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7726 ioc->scsih_cmds.smid = smid;
7727 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7729 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7730 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7732 if (!ioc->hide_ir_msg)
7733 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7734 init_completion(&ioc->scsih_cmds.done);
7735 mpt2sas_base_put_smid_default(ioc, smid);
7736 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7738 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7739 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7740 ioc->name, __func__);
7744 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7745 mpi_reply = ioc->scsih_cmds.reply;
7747 if (!ioc->hide_ir_msg)
7748 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7749 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7750 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7751 le32_to_cpu(mpi_reply->IOCLogInfo));
7755 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7756 mutex_unlock(&ioc->scsih_cmds.mutex);
7760 * _scsih_shutdown - routine call during system shutdown
7761 * @pdev: PCI device struct
7766 _scsih_shutdown(struct pci_dev *pdev)
7768 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7769 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7770 struct workqueue_struct *wq;
7771 unsigned long flags;
7773 ioc->remove_host = 1;
7774 _scsih_fw_event_cleanup_queue(ioc);
7776 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7777 wq = ioc->firmware_event_thread;
7778 ioc->firmware_event_thread = NULL;
7779 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7781 destroy_workqueue(wq);
7783 _scsih_ir_shutdown(ioc);
7784 mpt2sas_base_detach(ioc);
7788 * _scsih_remove - detach and remove add host
7789 * @pdev: PCI device struct
7791 * Routine called when unloading the driver.
7795 _scsih_remove(struct pci_dev *pdev)
7797 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7798 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7799 struct _sas_port *mpt2sas_port, *next_port;
7800 struct _raid_device *raid_device, *next;
7801 struct MPT2SAS_TARGET *sas_target_priv_data;
7802 struct workqueue_struct *wq;
7803 unsigned long flags;
7805 ioc->remove_host = 1;
7806 _scsih_fw_event_cleanup_queue(ioc);
7808 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7809 wq = ioc->firmware_event_thread;
7810 ioc->firmware_event_thread = NULL;
7811 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7813 destroy_workqueue(wq);
7815 /* release all the volumes */
7816 _scsih_ir_shutdown(ioc);
7817 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7819 if (raid_device->starget) {
7820 sas_target_priv_data =
7821 raid_device->starget->hostdata;
7822 sas_target_priv_data->deleted = 1;
7823 scsi_remove_target(&raid_device->starget->dev);
7825 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7826 "(0x%016llx)\n", ioc->name, raid_device->handle,
7827 (unsigned long long) raid_device->wwid);
7828 _scsih_raid_device_remove(ioc, raid_device);
7831 /* free ports attached to the sas_host */
7832 list_for_each_entry_safe(mpt2sas_port, next_port,
7833 &ioc->sas_hba.sas_port_list, port_list) {
7834 if (mpt2sas_port->remote_identify.device_type ==
7836 mpt2sas_device_remove_by_sas_address(ioc,
7837 mpt2sas_port->remote_identify.sas_address);
7838 else if (mpt2sas_port->remote_identify.device_type ==
7839 SAS_EDGE_EXPANDER_DEVICE ||
7840 mpt2sas_port->remote_identify.device_type ==
7841 SAS_FANOUT_EXPANDER_DEVICE)
7842 mpt2sas_expander_remove(ioc,
7843 mpt2sas_port->remote_identify.sas_address);
7846 /* free phys attached to the sas_host */
7847 if (ioc->sas_hba.num_phys) {
7848 kfree(ioc->sas_hba.phy);
7849 ioc->sas_hba.phy = NULL;
7850 ioc->sas_hba.num_phys = 0;
7853 sas_remove_host(shost);
7854 scsi_remove_host(shost);
7855 mpt2sas_base_detach(ioc);
7856 list_del(&ioc->list);
7857 scsi_host_put(shost);
7861 * _scsih_probe_boot_devices - reports 1st device
7862 * @ioc: per adapter object
7864 * If specified in bios page 2, this routine reports the 1st
7865 * device scsi-ml or sas transport for persistent boot device
7866 * purposes. Please refer to function _scsih_determine_boot_device()
7869 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7873 struct _sas_device *sas_device;
7874 struct _raid_device *raid_device;
7876 u64 sas_address_parent;
7878 unsigned long flags;
7881 /* no Bios, return immediately */
7882 if (!ioc->bios_pg3.BiosVersion)
7887 if (ioc->req_boot_device.device) {
7888 device = ioc->req_boot_device.device;
7889 is_raid = ioc->req_boot_device.is_raid;
7890 } else if (ioc->req_alt_boot_device.device) {
7891 device = ioc->req_alt_boot_device.device;
7892 is_raid = ioc->req_alt_boot_device.is_raid;
7893 } else if (ioc->current_boot_device.device) {
7894 device = ioc->current_boot_device.device;
7895 is_raid = ioc->current_boot_device.is_raid;
7902 raid_device = device;
7903 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7904 raid_device->id, 0);
7906 _scsih_raid_device_remove(ioc, raid_device);
7908 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7909 sas_device = device;
7910 handle = sas_device->handle;
7911 sas_address_parent = sas_device->sas_address_parent;
7912 sas_address = sas_device->sas_address;
7913 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7914 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7916 if (ioc->hide_drives)
7918 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7919 sas_device->sas_address_parent)) {
7920 _scsih_sas_device_remove(ioc, sas_device);
7921 } else if (!sas_device->starget) {
7922 if (!ioc->is_driver_loading) {
7923 mpt2sas_transport_port_remove(ioc,
7925 sas_address_parent);
7926 _scsih_sas_device_remove(ioc, sas_device);
7933 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7934 * @ioc: per adapter object
7936 * Called during initial loading of the driver.
7939 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7941 struct _raid_device *raid_device, *raid_next;
7944 list_for_each_entry_safe(raid_device, raid_next,
7945 &ioc->raid_device_list, list) {
7946 if (raid_device->starget)
7948 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7949 raid_device->id, 0);
7951 _scsih_raid_device_remove(ioc, raid_device);
7956 * _scsih_probe_sas - reporting sas devices to sas transport
7957 * @ioc: per adapter object
7959 * Called during initial loading of the driver.
7962 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7964 struct _sas_device *sas_device, *next;
7965 unsigned long flags;
7967 /* SAS Device List */
7968 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7971 if (ioc->hide_drives)
7974 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7975 sas_device->sas_address_parent)) {
7976 list_del(&sas_device->list);
7979 } else if (!sas_device->starget) {
7980 if (!ioc->is_driver_loading) {
7981 mpt2sas_transport_port_remove(ioc,
7982 sas_device->sas_address,
7983 sas_device->sas_address_parent);
7984 list_del(&sas_device->list);
7989 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7990 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7991 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7996 * _scsih_probe_devices - probing for devices
7997 * @ioc: per adapter object
7999 * Called during initial loading of the driver.
8002 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8004 u16 volume_mapping_flags;
8006 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8007 return; /* return when IOC doesn't support initiator mode */
8009 _scsih_probe_boot_devices(ioc);
8011 if (ioc->ir_firmware) {
8012 volume_mapping_flags =
8013 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8014 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8015 if (volume_mapping_flags ==
8016 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8017 _scsih_probe_raid(ioc);
8018 _scsih_probe_sas(ioc);
8020 _scsih_probe_sas(ioc);
8021 _scsih_probe_raid(ioc);
8024 _scsih_probe_sas(ioc);
8029 * _scsih_scan_start - scsi lld callback for .scan_start
8030 * @shost: SCSI host pointer
8032 * The shost has the ability to discover targets on its own instead
8033 * of scanning the entire bus. In our implemention, we will kick off
8034 * firmware discovery.
8037 _scsih_scan_start(struct Scsi_Host *shost)
8039 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8042 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8043 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8045 if (disable_discovery > 0)
8048 ioc->start_scan = 1;
8049 rc = mpt2sas_port_enable(ioc);
8052 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8056 * _scsih_scan_finished - scsi lld callback for .scan_finished
8057 * @shost: SCSI host pointer
8058 * @time: elapsed time of the scan in jiffies
8060 * This function will be called periodically until it returns 1 with the
8061 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8062 * we wait for firmware discovery to complete, then return 1.
8065 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8067 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8069 if (disable_discovery > 0) {
8070 ioc->is_driver_loading = 0;
8071 ioc->wait_for_discovery_to_complete = 0;
8075 if (time >= (300 * HZ)) {
8076 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8077 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8078 "(timeout=300s)\n", ioc->name);
8079 ioc->is_driver_loading = 0;
8083 if (ioc->start_scan)
8086 if (ioc->start_scan_failed) {
8087 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8088 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8089 ioc->is_driver_loading = 0;
8090 ioc->wait_for_discovery_to_complete = 0;
8091 ioc->remove_host = 1;
8095 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8096 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8098 if (ioc->wait_for_discovery_to_complete) {
8099 ioc->wait_for_discovery_to_complete = 0;
8100 _scsih_probe_devices(ioc);
8102 mpt2sas_base_start_watchdog(ioc);
8103 ioc->is_driver_loading = 0;
8109 * _scsih_probe - attach and add scsi host
8110 * @pdev: PCI device struct
8111 * @id: pci device id
8113 * Returns 0 success, anything else error.
8116 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8118 struct MPT2SAS_ADAPTER *ioc;
8119 struct Scsi_Host *shost;
8122 shost = scsi_host_alloc(&scsih_driver_template,
8123 sizeof(struct MPT2SAS_ADAPTER));
8127 /* init local params */
8128 ioc = shost_priv(shost);
8129 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8130 INIT_LIST_HEAD(&ioc->list);
8131 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8133 ioc->id = mpt_ids++;
8134 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8136 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8137 ioc->is_warpdrive = 1;
8138 ioc->hide_ir_msg = 1;
8140 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8141 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8142 ioc->tm_cb_idx = tm_cb_idx;
8143 ioc->ctl_cb_idx = ctl_cb_idx;
8144 ioc->base_cb_idx = base_cb_idx;
8145 ioc->port_enable_cb_idx = port_enable_cb_idx;
8146 ioc->transport_cb_idx = transport_cb_idx;
8147 ioc->scsih_cb_idx = scsih_cb_idx;
8148 ioc->config_cb_idx = config_cb_idx;
8149 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8150 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8151 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8152 ioc->logging_level = logging_level;
8153 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8154 /* misc semaphores and spin locks */
8155 mutex_init(&ioc->reset_in_progress_mutex);
8156 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8157 spin_lock_init(&ioc->scsi_lookup_lock);
8158 spin_lock_init(&ioc->sas_device_lock);
8159 spin_lock_init(&ioc->sas_node_lock);
8160 spin_lock_init(&ioc->fw_event_lock);
8161 spin_lock_init(&ioc->raid_device_lock);
8163 INIT_LIST_HEAD(&ioc->sas_device_list);
8164 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8165 INIT_LIST_HEAD(&ioc->sas_expander_list);
8166 INIT_LIST_HEAD(&ioc->fw_event_list);
8167 INIT_LIST_HEAD(&ioc->raid_device_list);
8168 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8169 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8170 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8171 INIT_LIST_HEAD(&ioc->reply_queue_list);
8173 /* init shost parameters */
8174 shost->max_cmd_len = 32;
8175 shost->max_lun = max_lun;
8176 shost->transportt = mpt2sas_transport_template;
8177 shost->unique_id = ioc->id;
8179 if (max_sectors != 0xFFFF) {
8180 if (max_sectors < 64) {
8181 shost->max_sectors = 64;
8182 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8183 "for max_sectors, range is 64 to 32767. Assigning "
8184 "value of 64.\n", ioc->name, max_sectors);
8185 } else if (max_sectors > 32767) {
8186 shost->max_sectors = 32767;
8187 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8188 "for max_sectors, range is 64 to 8192. Assigning "
8189 "default value of 32767.\n", ioc->name,
8192 shost->max_sectors = max_sectors & 0xFFFE;
8193 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8194 "set to %d\n", ioc->name, shost->max_sectors);
8198 /* register EEDP capabilities with SCSI layer */
8200 scsi_host_set_prot(shost, prot_mask);
8202 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8203 | SHOST_DIF_TYPE2_PROTECTION
8204 | SHOST_DIF_TYPE3_PROTECTION);
8206 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8209 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8210 "fw_event%d", ioc->id);
8211 ioc->firmware_event_thread = create_singlethread_workqueue(
8212 ioc->firmware_event_name);
8213 if (!ioc->firmware_event_thread) {
8214 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8215 ioc->name, __FILE__, __LINE__, __func__);
8217 goto out_thread_fail;
8220 ioc->is_driver_loading = 1;
8221 if ((mpt2sas_base_attach(ioc))) {
8222 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8223 ioc->name, __FILE__, __LINE__, __func__);
8225 goto out_attach_fail;
8228 if (ioc->is_warpdrive) {
8229 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8230 ioc->hide_drives = 0;
8231 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8232 ioc->hide_drives = 1;
8234 if (_scsih_get_num_volumes(ioc))
8235 ioc->hide_drives = 1;
8237 ioc->hide_drives = 0;
8240 ioc->hide_drives = 0;
8242 rv = scsi_add_host(shost, &pdev->dev);
8244 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8245 ioc->name, __FILE__, __LINE__, __func__);
8246 goto out_add_shost_fail;
8249 scsi_scan_host(shost);
8254 mpt2sas_base_detach(ioc);
8256 destroy_workqueue(ioc->firmware_event_thread);
8258 list_del(&ioc->list);
8259 scsi_host_put(shost);
8265 * _scsih_suspend - power management suspend main entry point
8266 * @pdev: PCI device struct
8267 * @state: PM state change to (usually PCI_D3)
8269 * Returns 0 success, anything else error.
8272 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8274 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8275 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8276 pci_power_t device_state;
8278 mpt2sas_base_stop_watchdog(ioc);
8279 scsi_block_requests(shost);
8280 _scsih_ir_shutdown(ioc);
8281 device_state = pci_choose_state(pdev, state);
8282 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8283 "operating state [D%d]\n", ioc->name, pdev,
8284 pci_name(pdev), device_state);
8286 mpt2sas_base_free_resources(ioc);
8287 pci_save_state(pdev);
8288 pci_set_power_state(pdev, device_state);
8293 * _scsih_resume - power management resume main entry point
8294 * @pdev: PCI device struct
8296 * Returns 0 success, anything else error.
8299 _scsih_resume(struct pci_dev *pdev)
8301 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8302 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8303 pci_power_t device_state = pdev->current_state;
8306 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8307 "operating state [D%d]\n", ioc->name, pdev,
8308 pci_name(pdev), device_state);
8310 pci_set_power_state(pdev, PCI_D0);
8311 pci_enable_wake(pdev, PCI_D0, 0);
8312 pci_restore_state(pdev);
8314 r = mpt2sas_base_map_resources(ioc);
8318 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8319 scsi_unblock_requests(shost);
8320 mpt2sas_base_start_watchdog(ioc);
8323 #endif /* CONFIG_PM */
8326 * _scsih_pci_error_detected - Called when a PCI error is detected.
8327 * @pdev: PCI device struct
8328 * @state: PCI channel state
8330 * Description: Called when a PCI error is detected.
8333 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8335 static pci_ers_result_t
8336 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8338 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8339 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8341 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8345 case pci_channel_io_normal:
8346 return PCI_ERS_RESULT_CAN_RECOVER;
8347 case pci_channel_io_frozen:
8348 /* Fatal error, prepare for slot reset */
8349 ioc->pci_error_recovery = 1;
8350 scsi_block_requests(ioc->shost);
8351 mpt2sas_base_stop_watchdog(ioc);
8352 mpt2sas_base_free_resources(ioc);
8353 return PCI_ERS_RESULT_NEED_RESET;
8354 case pci_channel_io_perm_failure:
8355 /* Permanent error, prepare for device removal */
8356 ioc->pci_error_recovery = 1;
8357 mpt2sas_base_stop_watchdog(ioc);
8358 _scsih_flush_running_cmds(ioc);
8359 return PCI_ERS_RESULT_DISCONNECT;
8361 return PCI_ERS_RESULT_NEED_RESET;
8365 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8366 * @pdev: PCI device struct
8368 * Description: This routine is called by the pci error recovery
8369 * code after the PCI slot has been reset, just before we
8370 * should resume normal operations.
8372 static pci_ers_result_t
8373 _scsih_pci_slot_reset(struct pci_dev *pdev)
8375 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8376 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8379 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8382 ioc->pci_error_recovery = 0;
8384 pci_restore_state(pdev);
8385 rc = mpt2sas_base_map_resources(ioc);
8387 return PCI_ERS_RESULT_DISCONNECT;
8390 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8393 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8394 (rc == 0) ? "success" : "failed");
8397 return PCI_ERS_RESULT_RECOVERED;
8399 return PCI_ERS_RESULT_DISCONNECT;
8403 * _scsih_pci_resume() - resume normal ops after PCI reset
8404 * @pdev: pointer to PCI device
8406 * Called when the error recovery driver tells us that its
8407 * OK to resume normal operation. Use completion to allow
8408 * halted scsi ops to resume.
8411 _scsih_pci_resume(struct pci_dev *pdev)
8413 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8414 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8416 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8418 pci_cleanup_aer_uncorrect_error_status(pdev);
8419 mpt2sas_base_start_watchdog(ioc);
8420 scsi_unblock_requests(ioc->shost);
8424 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8425 * @pdev: pointer to PCI device
8427 static pci_ers_result_t
8428 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8430 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8431 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8433 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8436 /* TODO - dump whatever for debugging purposes */
8438 /* Request a slot reset. */
8439 return PCI_ERS_RESULT_NEED_RESET;
8442 static const struct pci_error_handlers _scsih_err_handler = {
8443 .error_detected = _scsih_pci_error_detected,
8444 .mmio_enabled = _scsih_pci_mmio_enabled,
8445 .slot_reset = _scsih_pci_slot_reset,
8446 .resume = _scsih_pci_resume,
8449 static struct pci_driver scsih_driver = {
8450 .name = MPT2SAS_DRIVER_NAME,
8451 .id_table = scsih_pci_table,
8452 .probe = _scsih_probe,
8453 .remove = _scsih_remove,
8454 .shutdown = _scsih_shutdown,
8455 .err_handler = &_scsih_err_handler,
8457 .suspend = _scsih_suspend,
8458 .resume = _scsih_resume,
8462 /* raid transport support */
8463 static struct raid_function_template mpt2sas_raid_functions = {
8464 .cookie = &scsih_driver_template,
8465 .is_raid = _scsih_is_raid,
8466 .get_resync = _scsih_get_resync,
8467 .get_state = _scsih_get_state,
8471 * _scsih_init - main entry point for this driver.
8473 * Returns 0 success, anything else error.
8481 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8482 MPT2SAS_DRIVER_VERSION);
8484 mpt2sas_transport_template =
8485 sas_attach_transport(&mpt2sas_transport_functions);
8486 if (!mpt2sas_transport_template)
8488 /* raid transport support */
8489 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8490 if (!mpt2sas_raid_template) {
8491 sas_release_transport(mpt2sas_transport_template);
8495 mpt2sas_base_initialize_callback_handler();
8497 /* queuecommand callback hander */
8498 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8500 /* task management callback handler */
8501 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8503 /* base internal commands callback handler */
8504 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8505 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8506 mpt2sas_port_enable_done);
8508 /* transport internal commands callback handler */
8509 transport_cb_idx = mpt2sas_base_register_callback_handler(
8510 mpt2sas_transport_done);
8512 /* scsih internal commands callback handler */
8513 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8515 /* configuration page API internal commands callback handler */
8516 config_cb_idx = mpt2sas_base_register_callback_handler(
8517 mpt2sas_config_done);
8519 /* ctl module callback handler */
8520 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8522 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8523 _scsih_tm_tr_complete);
8525 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8526 _scsih_tm_volume_tr_complete);
8528 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8529 _scsih_sas_control_complete);
8533 error = pci_register_driver(&scsih_driver);
8535 /* raid transport support */
8536 raid_class_release(mpt2sas_raid_template);
8537 sas_release_transport(mpt2sas_transport_template);
8544 * _scsih_exit - exit point for this driver (when it is a module).
8546 * Returns 0 success, anything else error.
8551 printk(KERN_INFO "mpt2sas version %s unloading\n",
8552 MPT2SAS_DRIVER_VERSION);
8554 pci_unregister_driver(&scsih_driver);
8558 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8559 mpt2sas_base_release_callback_handler(tm_cb_idx);
8560 mpt2sas_base_release_callback_handler(base_cb_idx);
8561 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8562 mpt2sas_base_release_callback_handler(transport_cb_idx);
8563 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8564 mpt2sas_base_release_callback_handler(config_cb_idx);
8565 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8567 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8568 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8569 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8571 /* raid transport support */
8572 raid_class_release(mpt2sas_raid_template);
8573 sas_release_transport(mpt2sas_transport_template);
8577 module_init(_scsih_init);
8578 module_exit(_scsih_exit);