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-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
69 struct _sas_node *sas_expander);
70 static void _firmware_event_work(struct work_struct *work);
72 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
74 /* global parameters */
75 LIST_HEAD(mpt2sas_ioc_list);
77 /* local parameters */
78 static u8 scsi_io_cb_idx = -1;
79 static u8 tm_cb_idx = -1;
80 static u8 ctl_cb_idx = -1;
81 static u8 base_cb_idx = -1;
82 static u8 transport_cb_idx = -1;
83 static u8 scsih_cb_idx = -1;
84 static u8 config_cb_idx = -1;
87 static u8 tm_tr_cb_idx = -1 ;
88 static u8 tm_tr_volume_cb_idx = -1 ;
89 static u8 tm_sas_control_cb_idx = -1;
91 /* command line options */
92 static u32 logging_level;
93 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
96 static ushort max_sectors = 0xFFFF;
97 module_param(max_sectors, ushort, 0);
98 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 8192 default=8192");
100 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
101 #define MPT2SAS_MAX_LUN (16895)
102 static int max_lun = MPT2SAS_MAX_LUN;
103 module_param(max_lun, int, 0);
104 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
107 * struct sense_info - common structure for obtaining sense keys
109 * @asc: additional sense code
110 * @ascq: additional sense code qualifier
119 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
120 #define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF)
123 * struct fw_event_work - firmware event struct
124 * @list: link list framework
125 * @work: work object (ioc->fault_reset_work_q)
126 * @cancel_pending_work: flag set during reset handling
127 * @ioc: per adapter object
128 * @device_handle: device handle
129 * @VF_ID: virtual function id
130 * @VP_ID: virtual port id
131 * @ignore: flag meaning this event has been marked to ignore
132 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
133 * @event_data: reply event data payload follows
135 * This object stored on ioc->fw_event_list.
137 struct fw_event_work {
138 struct list_head list;
139 u8 cancel_pending_work;
140 struct delayed_work delayed_work;
141 struct MPT2SAS_ADAPTER *ioc;
150 /* raid transport support */
151 static struct raid_template *mpt2sas_raid_template;
154 * struct _scsi_io_transfer - scsi io transfer
155 * @handle: sas device handle (assigned by firmware)
156 * @is_raid: flag set for hidden raid components
157 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
158 * @data_length: data transfer length
159 * @data_dma: dma pointer to data
162 * @cdb_length: cdb length
164 * @timeout: timeout for this command
165 * @VF_ID: virtual function id
166 * @VP_ID: virtual port id
167 * @valid_reply: flag set for reply message
168 * @sense_length: sense length
169 * @ioc_status: ioc status
170 * @scsi_state: scsi state
171 * @scsi_status: scsi staus
172 * @log_info: log information
173 * @transfer_length: data length transfer when there is a reply message
175 * Used for sending internal scsi commands to devices within this module.
176 * Refer to _scsi_send_scsi_io().
178 struct _scsi_io_transfer {
181 enum dma_data_direction dir;
184 u8 sense[SCSI_SENSE_BUFFERSIZE];
192 /* the following bits are only valid when 'valid_reply = 1' */
202 * The pci device ids are defined in mpi/mpi2_cnfg.h.
204 static struct pci_device_id scsih_pci_table[] = {
205 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
206 PCI_ANY_ID, PCI_ANY_ID },
208 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
209 PCI_ANY_ID, PCI_ANY_ID },
210 /* Liberator ~ 2108 */
211 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
212 PCI_ANY_ID, PCI_ANY_ID },
213 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
214 PCI_ANY_ID, PCI_ANY_ID },
215 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
216 PCI_ANY_ID, PCI_ANY_ID },
218 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
219 PCI_ANY_ID, PCI_ANY_ID },
220 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
221 PCI_ANY_ID, PCI_ANY_ID },
222 /* Thunderbolt ~ 2208 */
223 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
224 PCI_ANY_ID, PCI_ANY_ID },
225 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
226 PCI_ANY_ID, PCI_ANY_ID },
227 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
228 PCI_ANY_ID, PCI_ANY_ID },
229 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
230 PCI_ANY_ID, PCI_ANY_ID },
231 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
232 PCI_ANY_ID, PCI_ANY_ID },
233 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
234 PCI_ANY_ID, PCI_ANY_ID },
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
237 PCI_ANY_ID, PCI_ANY_ID },
238 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
239 PCI_ANY_ID, PCI_ANY_ID },
240 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
241 PCI_ANY_ID, PCI_ANY_ID },
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
244 PCI_ANY_ID, PCI_ANY_ID },
245 {0} /* Terminating entry */
247 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
250 * _scsih_set_debug_level - global setting of ioc->logging_level.
252 * Note: The logging levels are defined in mpt2sas_debug.h.
255 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
257 int ret = param_set_int(val, kp);
258 struct MPT2SAS_ADAPTER *ioc;
263 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
264 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
265 ioc->logging_level = logging_level;
268 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
269 &logging_level, 0644);
272 * _scsih_srch_boot_sas_address - search based on sas_address
273 * @sas_address: sas address
274 * @boot_device: boot device object from bios page 2
276 * Returns 1 when there's a match, 0 means no match.
279 _scsih_srch_boot_sas_address(u64 sas_address,
280 Mpi2BootDeviceSasWwid_t *boot_device)
282 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
286 * _scsih_srch_boot_device_name - search based on device name
287 * @device_name: device name specified in INDENTIFY fram
288 * @boot_device: boot device object from bios page 2
290 * Returns 1 when there's a match, 0 means no match.
293 _scsih_srch_boot_device_name(u64 device_name,
294 Mpi2BootDeviceDeviceName_t *boot_device)
296 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
300 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
301 * @enclosure_logical_id: enclosure logical id
302 * @slot_number: slot number
303 * @boot_device: boot device object from bios page 2
305 * Returns 1 when there's a match, 0 means no match.
308 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
309 Mpi2BootDeviceEnclosureSlot_t *boot_device)
311 return (enclosure_logical_id == le64_to_cpu(boot_device->
312 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
313 SlotNumber)) ? 1 : 0;
317 * _scsih_is_boot_device - search for matching boot device.
318 * @sas_address: sas address
319 * @device_name: device name specified in INDENTIFY fram
320 * @enclosure_logical_id: enclosure logical id
321 * @slot_number: slot number
322 * @form: specifies boot device form
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_is_boot_device(u64 sas_address, u64 device_name,
329 u64 enclosure_logical_id, u16 slot, u8 form,
330 Mpi2BiosPage2BootDevice_t *boot_device)
335 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
338 rc = _scsih_srch_boot_sas_address(
339 sas_address, &boot_device->SasWwid);
341 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
342 if (!enclosure_logical_id)
344 rc = _scsih_srch_boot_encl_slot(
345 enclosure_logical_id,
346 slot, &boot_device->EnclosureSlot);
348 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
351 rc = _scsih_srch_boot_device_name(
352 device_name, &boot_device->DeviceName);
354 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
362 * _scsih_get_sas_address - set the sas_address for given device handle
363 * @handle: device handle
364 * @sas_address: sas address
366 * Returns 0 success, non-zero when failure
369 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
372 Mpi2SasDevicePage0_t sas_device_pg0;
373 Mpi2ConfigReply_t mpi_reply;
376 if (handle <= ioc->sas_hba.num_phys) {
377 *sas_address = ioc->sas_hba.sas_address;
382 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
383 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
384 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
385 ioc->name, __FILE__, __LINE__, __func__);
389 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
391 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
392 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
393 "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
394 __FILE__, __LINE__, __func__);
398 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
403 * _scsih_determine_boot_device - determine boot device.
404 * @ioc: per adapter object
405 * @device: either sas_device or raid_device object
406 * @is_raid: [flag] 1 = raid object, 0 = sas object
408 * Determines whether this device should be first reported device to
409 * to scsi-ml or sas transport, this purpose is for persistent boot device.
410 * There are primary, alternate, and current entries in bios page 2. The order
411 * priority is primary, alternate, then current. This routine saves
412 * the corresponding device object and is_raid flag in the ioc object.
413 * The saved data to be used later in _scsih_probe_boot_devices().
416 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
417 void *device, u8 is_raid)
419 struct _sas_device *sas_device;
420 struct _raid_device *raid_device;
423 u64 enclosure_logical_id;
426 /* only process this function when driver loads */
427 if (!ioc->wait_for_port_enable_to_complete)
432 sas_address = sas_device->sas_address;
433 device_name = sas_device->device_name;
434 enclosure_logical_id = sas_device->enclosure_logical_id;
435 slot = sas_device->slot;
437 raid_device = device;
438 sas_address = raid_device->wwid;
440 enclosure_logical_id = 0;
444 if (!ioc->req_boot_device.device) {
445 if (_scsih_is_boot_device(sas_address, device_name,
446 enclosure_logical_id, slot,
447 (ioc->bios_pg2.ReqBootDeviceForm &
448 MPI2_BIOSPAGE2_FORM_MASK),
449 &ioc->bios_pg2.RequestedBootDevice)) {
450 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
451 "%s: req_boot_device(0x%016llx)\n",
453 (unsigned long long)sas_address));
454 ioc->req_boot_device.device = device;
455 ioc->req_boot_device.is_raid = is_raid;
459 if (!ioc->req_alt_boot_device.device) {
460 if (_scsih_is_boot_device(sas_address, device_name,
461 enclosure_logical_id, slot,
462 (ioc->bios_pg2.ReqAltBootDeviceForm &
463 MPI2_BIOSPAGE2_FORM_MASK),
464 &ioc->bios_pg2.RequestedAltBootDevice)) {
465 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
466 "%s: req_alt_boot_device(0x%016llx)\n",
468 (unsigned long long)sas_address));
469 ioc->req_alt_boot_device.device = device;
470 ioc->req_alt_boot_device.is_raid = is_raid;
474 if (!ioc->current_boot_device.device) {
475 if (_scsih_is_boot_device(sas_address, device_name,
476 enclosure_logical_id, slot,
477 (ioc->bios_pg2.CurrentBootDeviceForm &
478 MPI2_BIOSPAGE2_FORM_MASK),
479 &ioc->bios_pg2.CurrentBootDevice)) {
480 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
481 "%s: current_boot_device(0x%016llx)\n",
483 (unsigned long long)sas_address));
484 ioc->current_boot_device.device = device;
485 ioc->current_boot_device.is_raid = is_raid;
491 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
492 * @ioc: per adapter object
493 * @sas_address: sas address
494 * Context: Calling function should acquire ioc->sas_device_lock
496 * This searches for sas_device based on sas_address, then return sas_device
500 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
503 struct _sas_device *sas_device;
505 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
506 if (sas_device->sas_address == sas_address)
509 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
510 if (sas_device->sas_address == sas_address)
517 * _scsih_sas_device_find_by_handle - sas device search
518 * @ioc: per adapter object
519 * @handle: sas device handle (assigned by firmware)
520 * Context: Calling function should acquire ioc->sas_device_lock
522 * This searches for sas_device based on sas_address, then return sas_device
525 static struct _sas_device *
526 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
528 struct _sas_device *sas_device;
530 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
531 if (sas_device->handle == handle)
534 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
535 if (sas_device->handle == handle)
542 * _scsih_sas_device_remove - remove sas_device from list.
543 * @ioc: per adapter object
544 * @sas_device: the sas_device object
545 * Context: This function will acquire ioc->sas_device_lock.
547 * Removing object and freeing associated memory from the ioc->sas_device_list.
550 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
551 struct _sas_device *sas_device)
558 spin_lock_irqsave(&ioc->sas_device_lock, flags);
559 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
560 sas_device->sas_address)) {
561 list_del(&sas_device->list);
564 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
568 * _scsih_sas_device_add - insert sas_device to the list.
569 * @ioc: per adapter object
570 * @sas_device: the sas_device object
571 * Context: This function will acquire ioc->sas_device_lock.
573 * Adding new object to the ioc->sas_device_list.
576 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
577 struct _sas_device *sas_device)
581 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
582 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
583 sas_device->handle, (unsigned long long)sas_device->sas_address));
585 spin_lock_irqsave(&ioc->sas_device_lock, flags);
586 list_add_tail(&sas_device->list, &ioc->sas_device_list);
587 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
589 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
590 sas_device->sas_address_parent))
591 _scsih_sas_device_remove(ioc, sas_device);
595 * _scsih_sas_device_init_add - insert sas_device to the list.
596 * @ioc: per adapter object
597 * @sas_device: the sas_device object
598 * Context: This function will acquire ioc->sas_device_lock.
600 * Adding new object at driver load time to the ioc->sas_device_init_list.
603 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
604 struct _sas_device *sas_device)
608 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
609 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
610 sas_device->handle, (unsigned long long)sas_device->sas_address));
612 spin_lock_irqsave(&ioc->sas_device_lock, flags);
613 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
614 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
615 _scsih_determine_boot_device(ioc, sas_device, 0);
619 * _scsih_raid_device_find_by_id - raid device search
620 * @ioc: per adapter object
621 * @id: sas device target id
622 * @channel: sas device channel
623 * Context: Calling function should acquire ioc->raid_device_lock
625 * This searches for raid_device based on target id, then return raid_device
628 static struct _raid_device *
629 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
631 struct _raid_device *raid_device, *r;
634 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
635 if (raid_device->id == id && raid_device->channel == channel) {
646 * _scsih_raid_device_find_by_handle - raid device search
647 * @ioc: per adapter object
648 * @handle: sas device handle (assigned by firmware)
649 * Context: Calling function should acquire ioc->raid_device_lock
651 * This searches for raid_device based on handle, then return raid_device
654 static struct _raid_device *
655 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
657 struct _raid_device *raid_device, *r;
660 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
661 if (raid_device->handle != handle)
672 * _scsih_raid_device_find_by_wwid - raid device search
673 * @ioc: per adapter object
674 * @handle: sas device handle (assigned by firmware)
675 * Context: Calling function should acquire ioc->raid_device_lock
677 * This searches for raid_device based on wwid, then return raid_device
680 static struct _raid_device *
681 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
683 struct _raid_device *raid_device, *r;
686 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
687 if (raid_device->wwid != wwid)
698 * _scsih_raid_device_add - add raid_device object
699 * @ioc: per adapter object
700 * @raid_device: raid_device object
702 * This is added to the raid_device_list link list.
705 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
706 struct _raid_device *raid_device)
710 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
711 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
712 raid_device->handle, (unsigned long long)raid_device->wwid));
714 spin_lock_irqsave(&ioc->raid_device_lock, flags);
715 list_add_tail(&raid_device->list, &ioc->raid_device_list);
716 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
720 * _scsih_raid_device_remove - delete raid_device object
721 * @ioc: per adapter object
722 * @raid_device: raid_device object
724 * This is removed from the raid_device_list link list.
727 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
728 struct _raid_device *raid_device)
732 spin_lock_irqsave(&ioc->raid_device_lock, flags);
733 list_del(&raid_device->list);
734 memset(raid_device, 0, sizeof(struct _raid_device));
736 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
740 * mpt2sas_scsih_expander_find_by_handle - expander device search
741 * @ioc: per adapter object
742 * @handle: expander handle (assigned by firmware)
743 * Context: Calling function should acquire ioc->sas_device_lock
745 * This searches for expander device based on handle, then returns the
749 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
751 struct _sas_node *sas_expander, *r;
754 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
755 if (sas_expander->handle != handle)
765 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
766 * @ioc: per adapter object
767 * @sas_address: sas address
768 * Context: Calling function should acquire ioc->sas_node_lock.
770 * This searches for expander device based on sas_address, then returns the
774 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
777 struct _sas_node *sas_expander, *r;
780 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
781 if (sas_expander->sas_address != sas_address)
791 * _scsih_expander_node_add - insert expander device to the list.
792 * @ioc: per adapter object
793 * @sas_expander: the sas_device object
794 * Context: This function will acquire ioc->sas_node_lock.
796 * Adding new object to the ioc->sas_expander_list.
801 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
802 struct _sas_node *sas_expander)
806 spin_lock_irqsave(&ioc->sas_node_lock, flags);
807 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
808 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
812 * _scsih_is_end_device - determines if device is an end device
813 * @device_info: bitfield providing information about the device.
816 * Returns 1 if end device.
819 _scsih_is_end_device(u32 device_info)
821 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
822 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
823 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
824 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
831 * _scsih_scsi_lookup_get - returns scmd entry
832 * @ioc: per adapter object
833 * @smid: system request message index
835 * Returns the smid stored scmd pointer.
837 static struct scsi_cmnd *
838 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
840 return ioc->scsi_lookup[smid - 1].scmd;
844 * _scsih_scsi_lookup_get_clear - returns scmd entry
845 * @ioc: per adapter object
846 * @smid: system request message index
848 * Returns the smid stored scmd pointer.
849 * Then will derefrence the stored scmd pointer.
851 static inline struct scsi_cmnd *
852 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
855 struct scsi_cmnd *scmd;
857 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
858 scmd = ioc->scsi_lookup[smid - 1].scmd;
859 ioc->scsi_lookup[smid - 1].scmd = NULL;
860 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
866 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
867 * @ioc: per adapter object
868 * @smid: system request message index
869 * @scmd: pointer to scsi command object
870 * Context: This function will acquire ioc->scsi_lookup_lock.
872 * This will search for a scmd pointer in the scsi_lookup array,
873 * returning the revelent smid. A returned value of zero means invalid.
876 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
883 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
885 for (i = 0; i < ioc->scsiio_depth; i++) {
886 if (ioc->scsi_lookup[i].scmd == scmd) {
887 smid = ioc->scsi_lookup[i].smid;
892 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
897 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
898 * @ioc: per adapter object
901 * Context: This function will acquire ioc->scsi_lookup_lock.
903 * This will search for a matching channel:id in the scsi_lookup array,
904 * returning 1 if found.
907 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
914 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
916 for (i = 0 ; i < ioc->scsiio_depth; i++) {
917 if (ioc->scsi_lookup[i].scmd &&
918 (ioc->scsi_lookup[i].scmd->device->id == id &&
919 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
925 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
930 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
931 * @ioc: per adapter object
935 * Context: This function will acquire ioc->scsi_lookup_lock.
937 * This will search for a matching channel:id:lun in the scsi_lookup array,
938 * returning 1 if found.
941 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
942 unsigned int lun, int channel)
948 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
950 for (i = 0 ; i < ioc->scsiio_depth; i++) {
951 if (ioc->scsi_lookup[i].scmd &&
952 (ioc->scsi_lookup[i].scmd->device->id == id &&
953 ioc->scsi_lookup[i].scmd->device->channel == channel &&
954 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
960 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
965 * _scsih_get_chain_buffer_tracker - obtain chain tracker
966 * @ioc: per adapter object
967 * @smid: smid associated to an IO request
969 * Returns chain tracker(from ioc->free_chain_list)
971 static struct chain_tracker *
972 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
974 struct chain_tracker *chain_req;
977 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
978 if (list_empty(&ioc->free_chain_list)) {
979 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
980 printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
984 chain_req = list_entry(ioc->free_chain_list.next,
985 struct chain_tracker, tracker_list);
986 list_del_init(&chain_req->tracker_list);
987 list_add_tail(&chain_req->tracker_list,
988 &ioc->scsi_lookup[smid - 1].chain_list);
989 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
994 * _scsih_build_scatter_gather - main sg creation routine
995 * @ioc: per adapter object
996 * @scmd: scsi command
997 * @smid: system request message index
1000 * The main routine that builds scatter gather table from a given
1001 * scsi request sent via the .queuecommand main handler.
1003 * Returns 0 success, anything else error
1006 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1007 struct scsi_cmnd *scmd, u16 smid)
1009 Mpi2SCSIIORequest_t *mpi_request;
1010 dma_addr_t chain_dma;
1011 struct scatterlist *sg_scmd;
1012 void *sg_local, *chain;
1017 u32 sges_in_segment;
1019 u32 sgl_flags_last_element;
1020 u32 sgl_flags_end_buffer;
1021 struct chain_tracker *chain_req;
1023 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1025 /* init scatter gather flags */
1026 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1027 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1028 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1029 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1030 << MPI2_SGE_FLAGS_SHIFT;
1031 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1032 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1033 << MPI2_SGE_FLAGS_SHIFT;
1034 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1036 sg_scmd = scsi_sglist(scmd);
1037 sges_left = scsi_dma_map(scmd);
1038 if (sges_left < 0) {
1039 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1040 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1044 sg_local = &mpi_request->SGL;
1045 sges_in_segment = ioc->max_sges_in_main_message;
1046 if (sges_left <= sges_in_segment)
1047 goto fill_in_last_segment;
1049 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1050 (sges_in_segment * ioc->sge_size))/4;
1052 /* fill in main message segment when there is a chain following */
1053 while (sges_in_segment) {
1054 if (sges_in_segment == 1)
1055 ioc->base_add_sg_single(sg_local,
1056 sgl_flags_last_element | sg_dma_len(sg_scmd),
1057 sg_dma_address(sg_scmd));
1059 ioc->base_add_sg_single(sg_local, sgl_flags |
1060 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1061 sg_scmd = sg_next(sg_scmd);
1062 sg_local += ioc->sge_size;
1067 /* initializing the chain flags and pointers */
1068 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1069 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1072 chain = chain_req->chain_buffer;
1073 chain_dma = chain_req->chain_buffer_dma;
1075 sges_in_segment = (sges_left <=
1076 ioc->max_sges_in_chain_message) ? sges_left :
1077 ioc->max_sges_in_chain_message;
1078 chain_offset = (sges_left == sges_in_segment) ?
1079 0 : (sges_in_segment * ioc->sge_size)/4;
1080 chain_length = sges_in_segment * ioc->sge_size;
1082 chain_offset = chain_offset <<
1083 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1084 chain_length += ioc->sge_size;
1086 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1087 chain_length, chain_dma);
1090 goto fill_in_last_segment;
1092 /* fill in chain segments */
1093 while (sges_in_segment) {
1094 if (sges_in_segment == 1)
1095 ioc->base_add_sg_single(sg_local,
1096 sgl_flags_last_element |
1097 sg_dma_len(sg_scmd),
1098 sg_dma_address(sg_scmd));
1100 ioc->base_add_sg_single(sg_local, sgl_flags |
1101 sg_dma_len(sg_scmd),
1102 sg_dma_address(sg_scmd));
1103 sg_scmd = sg_next(sg_scmd);
1104 sg_local += ioc->sge_size;
1109 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1112 chain = chain_req->chain_buffer;
1113 chain_dma = chain_req->chain_buffer_dma;
1117 fill_in_last_segment:
1119 /* fill the last segment */
1122 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1123 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1125 ioc->base_add_sg_single(sg_local, sgl_flags |
1126 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1127 sg_scmd = sg_next(sg_scmd);
1128 sg_local += ioc->sge_size;
1136 * _scsih_adjust_queue_depth - setting device queue depth
1137 * @sdev: scsi device struct
1138 * @qdepth: requested queue depth
1144 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1146 struct Scsi_Host *shost = sdev->host;
1148 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1149 struct MPT2SAS_DEVICE *sas_device_priv_data;
1150 struct MPT2SAS_TARGET *sas_target_priv_data;
1151 struct _sas_device *sas_device;
1152 unsigned long flags;
1154 max_depth = shost->can_queue;
1156 /* limit max device queue for SATA to 32 */
1157 sas_device_priv_data = sdev->hostdata;
1158 if (!sas_device_priv_data)
1160 sas_target_priv_data = sas_device_priv_data->sas_target;
1161 if (!sas_target_priv_data)
1163 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1165 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1166 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1167 sas_device_priv_data->sas_target->sas_address);
1168 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1169 if (sas_device && sas_device->device_info &
1170 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1171 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1175 if (!sdev->tagged_supported)
1177 if (qdepth > max_depth)
1179 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1183 * _scsih_change_queue_depth - setting device queue depth
1184 * @sdev: scsi device struct
1185 * @qdepth: requested queue depth
1186 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1187 * (see include/scsi/scsi_host.h for definition)
1189 * Returns queue depth.
1192 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1194 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1195 _scsih_adjust_queue_depth(sdev, qdepth);
1196 else if (reason == SCSI_QDEPTH_QFULL)
1197 scsi_track_queue_full(sdev, qdepth);
1201 if (sdev->inquiry_len > 7)
1202 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1203 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1204 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1205 sdev->ordered_tags, sdev->scsi_level,
1206 (sdev->inquiry[7] & 2) >> 1);
1208 return sdev->queue_depth;
1212 * _scsih_change_queue_type - changing device queue tag type
1213 * @sdev: scsi device struct
1214 * @tag_type: requested tag type
1216 * Returns queue tag type.
1219 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1221 if (sdev->tagged_supported) {
1222 scsi_set_tag_type(sdev, tag_type);
1224 scsi_activate_tcq(sdev, sdev->queue_depth);
1226 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1234 * _scsih_target_alloc - target add routine
1235 * @starget: scsi target struct
1237 * Returns 0 if ok. Any other return is assumed to be an error and
1238 * the device is ignored.
1241 _scsih_target_alloc(struct scsi_target *starget)
1243 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1244 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1245 struct MPT2SAS_TARGET *sas_target_priv_data;
1246 struct _sas_device *sas_device;
1247 struct _raid_device *raid_device;
1248 unsigned long flags;
1249 struct sas_rphy *rphy;
1251 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1252 if (!sas_target_priv_data)
1255 starget->hostdata = sas_target_priv_data;
1256 sas_target_priv_data->starget = starget;
1257 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1260 if (starget->channel == RAID_CHANNEL) {
1261 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1262 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1265 sas_target_priv_data->handle = raid_device->handle;
1266 sas_target_priv_data->sas_address = raid_device->wwid;
1267 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1268 sas_target_priv_data->raid_device = raid_device;
1269 raid_device->starget = starget;
1271 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1275 /* sas/sata devices */
1276 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1277 rphy = dev_to_rphy(starget->dev.parent);
1278 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1279 rphy->identify.sas_address);
1282 sas_target_priv_data->handle = sas_device->handle;
1283 sas_target_priv_data->sas_address = sas_device->sas_address;
1284 sas_device->starget = starget;
1285 sas_device->id = starget->id;
1286 sas_device->channel = starget->channel;
1287 if (test_bit(sas_device->handle, ioc->pd_handles))
1288 sas_target_priv_data->flags |=
1289 MPT_TARGET_FLAGS_RAID_COMPONENT;
1291 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1297 * _scsih_target_destroy - target destroy routine
1298 * @starget: scsi target struct
1303 _scsih_target_destroy(struct scsi_target *starget)
1305 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1306 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1307 struct MPT2SAS_TARGET *sas_target_priv_data;
1308 struct _sas_device *sas_device;
1309 struct _raid_device *raid_device;
1310 unsigned long flags;
1311 struct sas_rphy *rphy;
1313 sas_target_priv_data = starget->hostdata;
1314 if (!sas_target_priv_data)
1317 if (starget->channel == RAID_CHANNEL) {
1318 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1319 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1322 raid_device->starget = NULL;
1323 raid_device->sdev = NULL;
1325 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1329 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1330 rphy = dev_to_rphy(starget->dev.parent);
1331 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1332 rphy->identify.sas_address);
1333 if (sas_device && (sas_device->starget == starget) &&
1334 (sas_device->id == starget->id) &&
1335 (sas_device->channel == starget->channel))
1336 sas_device->starget = NULL;
1338 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1341 kfree(sas_target_priv_data);
1342 starget->hostdata = NULL;
1346 * _scsih_slave_alloc - device add routine
1347 * @sdev: scsi device struct
1349 * Returns 0 if ok. Any other return is assumed to be an error and
1350 * the device is ignored.
1353 _scsih_slave_alloc(struct scsi_device *sdev)
1355 struct Scsi_Host *shost;
1356 struct MPT2SAS_ADAPTER *ioc;
1357 struct MPT2SAS_TARGET *sas_target_priv_data;
1358 struct MPT2SAS_DEVICE *sas_device_priv_data;
1359 struct scsi_target *starget;
1360 struct _raid_device *raid_device;
1361 unsigned long flags;
1363 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1364 if (!sas_device_priv_data)
1367 sas_device_priv_data->lun = sdev->lun;
1368 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1370 starget = scsi_target(sdev);
1371 sas_target_priv_data = starget->hostdata;
1372 sas_target_priv_data->num_luns++;
1373 sas_device_priv_data->sas_target = sas_target_priv_data;
1374 sdev->hostdata = sas_device_priv_data;
1375 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1376 sdev->no_uld_attach = 1;
1378 shost = dev_to_shost(&starget->dev);
1379 ioc = shost_priv(shost);
1380 if (starget->channel == RAID_CHANNEL) {
1381 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1382 raid_device = _scsih_raid_device_find_by_id(ioc,
1383 starget->id, starget->channel);
1385 raid_device->sdev = sdev; /* raid is single lun */
1386 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1393 * _scsih_slave_destroy - device destroy routine
1394 * @sdev: scsi device struct
1399 _scsih_slave_destroy(struct scsi_device *sdev)
1401 struct MPT2SAS_TARGET *sas_target_priv_data;
1402 struct scsi_target *starget;
1404 if (!sdev->hostdata)
1407 starget = scsi_target(sdev);
1408 sas_target_priv_data = starget->hostdata;
1409 sas_target_priv_data->num_luns--;
1410 kfree(sdev->hostdata);
1411 sdev->hostdata = NULL;
1415 * _scsih_display_sata_capabilities - sata capabilities
1416 * @ioc: per adapter object
1417 * @sas_device: the sas_device object
1418 * @sdev: scsi device struct
1421 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1422 struct _sas_device *sas_device, struct scsi_device *sdev)
1424 Mpi2ConfigReply_t mpi_reply;
1425 Mpi2SasDevicePage0_t sas_device_pg0;
1430 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1431 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1432 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1433 ioc->name, __FILE__, __LINE__, __func__);
1437 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1438 MPI2_IOCSTATUS_MASK;
1439 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1440 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1441 ioc->name, __FILE__, __LINE__, __func__);
1445 flags = le16_to_cpu(sas_device_pg0.Flags);
1446 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1448 sdev_printk(KERN_INFO, sdev,
1449 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1450 "sw_preserve(%s)\n",
1451 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1452 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1453 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1455 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1456 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1457 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1461 * _scsih_is_raid - return boolean indicating device is raid volume
1462 * @dev the device struct object
1465 _scsih_is_raid(struct device *dev)
1467 struct scsi_device *sdev = to_scsi_device(dev);
1468 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1470 if (ioc->is_warpdrive)
1472 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1476 * _scsih_get_resync - get raid volume resync percent complete
1477 * @dev the device struct object
1480 _scsih_get_resync(struct device *dev)
1482 struct scsi_device *sdev = to_scsi_device(dev);
1483 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1484 static struct _raid_device *raid_device;
1485 unsigned long flags;
1486 Mpi2RaidVolPage0_t vol_pg0;
1487 Mpi2ConfigReply_t mpi_reply;
1488 u32 volume_status_flags;
1489 u8 percent_complete = 0;
1491 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1492 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1494 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1496 if (!raid_device || ioc->is_warpdrive)
1499 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1500 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1501 sizeof(Mpi2RaidVolPage0_t))) {
1502 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1503 ioc->name, __FILE__, __LINE__, __func__);
1507 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1508 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1509 percent_complete = raid_device->percent_complete;
1511 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1515 * _scsih_get_state - get raid volume level
1516 * @dev the device struct object
1519 _scsih_get_state(struct device *dev)
1521 struct scsi_device *sdev = to_scsi_device(dev);
1522 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1523 static struct _raid_device *raid_device;
1524 unsigned long flags;
1525 Mpi2RaidVolPage0_t vol_pg0;
1526 Mpi2ConfigReply_t mpi_reply;
1528 enum raid_state state = RAID_STATE_UNKNOWN;
1530 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1531 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1533 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1538 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1539 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1540 sizeof(Mpi2RaidVolPage0_t))) {
1541 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1542 ioc->name, __FILE__, __LINE__, __func__);
1546 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1547 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1548 state = RAID_STATE_RESYNCING;
1552 switch (vol_pg0.VolumeState) {
1553 case MPI2_RAID_VOL_STATE_OPTIMAL:
1554 case MPI2_RAID_VOL_STATE_ONLINE:
1555 state = RAID_STATE_ACTIVE;
1557 case MPI2_RAID_VOL_STATE_DEGRADED:
1558 state = RAID_STATE_DEGRADED;
1560 case MPI2_RAID_VOL_STATE_FAILED:
1561 case MPI2_RAID_VOL_STATE_MISSING:
1562 state = RAID_STATE_OFFLINE;
1566 raid_set_state(mpt2sas_raid_template, dev, state);
1570 * _scsih_set_level - set raid level
1571 * @sdev: scsi device struct
1572 * @raid_device: raid_device object
1575 _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1577 enum raid_level level = RAID_LEVEL_UNKNOWN;
1579 switch (raid_device->volume_type) {
1580 case MPI2_RAID_VOL_TYPE_RAID0:
1581 level = RAID_LEVEL_0;
1583 case MPI2_RAID_VOL_TYPE_RAID10:
1584 level = RAID_LEVEL_10;
1586 case MPI2_RAID_VOL_TYPE_RAID1E:
1587 level = RAID_LEVEL_1E;
1589 case MPI2_RAID_VOL_TYPE_RAID1:
1590 level = RAID_LEVEL_1;
1594 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1598 * _scsih_get_volume_capabilities - volume capabilities
1599 * @ioc: per adapter object
1600 * @sas_device: the raid_device object
1603 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1604 struct _raid_device *raid_device)
1606 Mpi2RaidVolPage0_t *vol_pg0;
1607 Mpi2RaidPhysDiskPage0_t pd_pg0;
1608 Mpi2SasDevicePage0_t sas_device_pg0;
1609 Mpi2ConfigReply_t mpi_reply;
1613 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1614 &num_pds)) || !num_pds) {
1615 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1616 ioc->name, __FILE__, __LINE__, __func__);
1620 raid_device->num_pds = num_pds;
1621 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1622 sizeof(Mpi2RaidVol0PhysDisk_t));
1623 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1625 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1626 ioc->name, __FILE__, __LINE__, __func__);
1630 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1631 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1632 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1633 ioc->name, __FILE__, __LINE__, __func__);
1638 raid_device->volume_type = vol_pg0->VolumeType;
1640 /* figure out what the underlying devices are by
1641 * obtaining the device_info bits for the 1st device
1643 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1644 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1645 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1646 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1647 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1648 le16_to_cpu(pd_pg0.DevHandle)))) {
1649 raid_device->device_info =
1650 le32_to_cpu(sas_device_pg0.DeviceInfo);
1657 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1658 * @ioc: per adapter object
1661 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1663 Mpi2RaidVolPage1_t vol_pg1;
1664 Mpi2ConfigReply_t mpi_reply;
1665 struct _raid_device *raid_device;
1670 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1671 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1672 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1673 MPI2_IOCSTATUS_MASK;
1674 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1676 handle = le16_to_cpu(vol_pg1.DevHandle);
1677 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1679 raid_device->direct_io_enabled = 0;
1686 * _scsih_get_num_volumes - Get number of volumes in the ioc
1687 * @ioc: per adapter object
1690 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1692 Mpi2RaidVolPage1_t vol_pg1;
1693 Mpi2ConfigReply_t mpi_reply;
1699 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1700 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1701 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1702 MPI2_IOCSTATUS_MASK;
1703 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1706 handle = le16_to_cpu(vol_pg1.DevHandle);
1713 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1714 * @ioc: per adapter object
1715 * @raid_device: the raid_device object
1718 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1719 struct _raid_device *raid_device)
1721 Mpi2RaidVolPage0_t *vol_pg0;
1722 Mpi2RaidPhysDiskPage0_t pd_pg0;
1723 Mpi2ConfigReply_t mpi_reply;
1726 u64 mb = 1024 * 1024;
1727 u64 tb_2 = 2 * mb * mb;
1732 if (!ioc->is_warpdrive)
1735 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1736 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1737 "globally as drives are exposed\n", ioc->name);
1740 if (_scsih_get_num_volumes(ioc) > 1) {
1741 _scsih_disable_ddio(ioc);
1742 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1743 "globally as number of drives > 1\n", ioc->name);
1746 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1747 &num_pds)) || !num_pds) {
1748 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1749 "Failure in computing number of drives\n", ioc->name);
1753 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1754 sizeof(Mpi2RaidVol0PhysDisk_t));
1755 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1757 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1758 "Memory allocation failure for RVPG0\n", ioc->name);
1762 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1763 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1764 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1765 "Failure in retrieving RVPG0\n", ioc->name);
1771 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1772 * assumed for WARPDRIVE, disable direct I/O
1774 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1775 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1776 "for the drive with handle(0x%04x): num_mem=%d, "
1777 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1778 num_pds, MPT_MAX_WARPDRIVE_PDS);
1782 for (count = 0; count < num_pds; count++) {
1783 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1784 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1785 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1786 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1787 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1788 "disabled for the drive with handle(0x%04x) member"
1789 "handle retrieval failed for member number=%d\n",
1790 ioc->name, raid_device->handle,
1791 vol_pg0->PhysDisk[count].PhysDiskNum);
1794 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1798 * Assumption for WD: Direct I/O is not supported if the volume is
1799 * not RAID0, if the stripe size is not 64KB, if the block size is
1800 * not 512 and if the volume size is >2TB
1802 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1803 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1804 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1805 "for the drive with handle(0x%04x): type=%d, "
1806 "s_sz=%uK, blk_size=%u\n", ioc->name,
1807 raid_device->handle, raid_device->volume_type,
1808 le32_to_cpu(vol_pg0->StripeSize)/2,
1809 le16_to_cpu(vol_pg0->BlockSize));
1813 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1814 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1816 if (capacity > tb_2) {
1817 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1818 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1819 ioc->name, raid_device->handle);
1823 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1825 for (i = 0; i < 32; i++) {
1832 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1833 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1834 ioc->name, raid_device->handle,
1835 le32_to_cpu(vol_pg0->StripeSize)/2);
1838 raid_device->stripe_exponent = stripe_exp;
1839 raid_device->direct_io_enabled = 1;
1841 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1842 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1844 * WARPDRIVE: Though the following fields are not used for direct IO,
1845 * stored for future purpose:
1847 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1848 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1849 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1856 raid_device->direct_io_enabled = 0;
1857 for (count = 0; count < num_pds; count++)
1858 raid_device->pd_handle[count] = 0;
1864 * _scsih_enable_tlr - setting TLR flags
1865 * @ioc: per adapter object
1866 * @sdev: scsi device struct
1868 * Enabling Transaction Layer Retries for tape devices when
1869 * vpd page 0x90 is present
1873 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1876 if (sdev->type != TYPE_TAPE)
1879 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1882 sas_enable_tlr(sdev);
1883 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1884 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1890 * _scsih_slave_configure - device configure routine.
1891 * @sdev: scsi device struct
1893 * Returns 0 if ok. Any other return is assumed to be an error and
1894 * the device is ignored.
1897 _scsih_slave_configure(struct scsi_device *sdev)
1899 struct Scsi_Host *shost = sdev->host;
1900 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1901 struct MPT2SAS_DEVICE *sas_device_priv_data;
1902 struct MPT2SAS_TARGET *sas_target_priv_data;
1903 struct _sas_device *sas_device;
1904 struct _raid_device *raid_device;
1905 unsigned long flags;
1912 sas_device_priv_data = sdev->hostdata;
1913 sas_device_priv_data->configured_lun = 1;
1914 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1915 sas_target_priv_data = sas_device_priv_data->sas_target;
1917 /* raid volume handling */
1918 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1920 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1921 raid_device = _scsih_raid_device_find_by_handle(ioc,
1922 sas_target_priv_data->handle);
1923 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1925 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1926 ioc->name, __FILE__, __LINE__, __func__);
1930 _scsih_get_volume_capabilities(ioc, raid_device);
1933 * WARPDRIVE: Initialize the required data for Direct IO
1935 _scsih_init_warpdrive_properties(ioc, raid_device);
1937 /* RAID Queue Depth Support
1938 * IS volume = underlying qdepth of drive type, either
1939 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1940 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1942 if (raid_device->device_info &
1943 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1944 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1947 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1948 if (raid_device->device_info &
1949 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1955 switch (raid_device->volume_type) {
1956 case MPI2_RAID_VOL_TYPE_RAID0:
1959 case MPI2_RAID_VOL_TYPE_RAID1E:
1960 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1961 if (ioc->manu_pg10.OEMIdentifier &&
1962 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1963 MFG10_GF0_R10_DISPLAY) &&
1964 !(raid_device->num_pds % 2))
1969 case MPI2_RAID_VOL_TYPE_RAID1:
1970 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1973 case MPI2_RAID_VOL_TYPE_RAID10:
1974 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1977 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1979 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1984 if (!ioc->hide_ir_msg)
1985 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
1986 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
1987 r_level, raid_device->handle,
1988 (unsigned long long)raid_device->wwid,
1989 raid_device->num_pds, ds);
1990 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1991 /* raid transport support */
1992 if (!ioc->is_warpdrive)
1993 _scsih_set_level(sdev, raid_device);
1997 /* non-raid handling */
1998 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1999 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2000 sas_device_priv_data->sas_target->sas_address);
2001 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2003 if (sas_target_priv_data->flags &
2004 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2005 mpt2sas_config_get_volume_handle(ioc,
2006 sas_device->handle, &sas_device->volume_handle);
2007 mpt2sas_config_get_volume_wwid(ioc,
2008 sas_device->volume_handle,
2009 &sas_device->volume_wwid);
2011 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2012 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2016 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2017 if (sas_device->device_info &
2018 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2020 else if (sas_device->device_info &
2021 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2025 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2026 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2027 ds, sas_device->handle,
2028 (unsigned long long)sas_device->sas_address,
2030 (unsigned long long)sas_device->device_name);
2031 sdev_printk(KERN_INFO, sdev, "%s: "
2032 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2033 (unsigned long long) sas_device->enclosure_logical_id,
2037 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
2040 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2043 sas_read_port_mode_page(sdev);
2044 _scsih_enable_tlr(ioc, sdev);
2050 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2051 * @sdev: scsi device struct
2052 * @bdev: pointer to block device context
2053 * @capacity: device size (in 512 byte sectors)
2054 * @params: three element array to place output:
2055 * params[0] number of heads (max 255)
2056 * params[1] number of sectors (max 63)
2057 * params[2] number of cylinders
2062 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2063 sector_t capacity, int params[])
2073 dummy = heads * sectors;
2074 cylinders = capacity;
2075 sector_div(cylinders, dummy);
2078 * Handle extended translation size for logical drives
2081 if ((ulong)capacity >= 0x200000) {
2084 dummy = heads * sectors;
2085 cylinders = capacity;
2086 sector_div(cylinders, dummy);
2091 params[1] = sectors;
2092 params[2] = cylinders;
2098 * _scsih_response_code - translation of device response code
2099 * @ioc: per adapter object
2100 * @response_code: response code returned by the device
2105 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2109 switch (response_code) {
2110 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2111 desc = "task management request completed";
2113 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2114 desc = "invalid frame";
2116 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2117 desc = "task management request not supported";
2119 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2120 desc = "task management request failed";
2122 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2123 desc = "task management request succeeded";
2125 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2126 desc = "invalid lun";
2129 desc = "overlapped tag attempted";
2131 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2132 desc = "task queued, however not sent to target";
2138 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2139 ioc->name, response_code, desc);
2143 * _scsih_tm_done - tm completion routine
2144 * @ioc: per adapter object
2145 * @smid: system request message index
2146 * @msix_index: MSIX table index supplied by the OS
2147 * @reply: reply message frame(lower 32bit addr)
2150 * The callback handler when using scsih_issue_tm.
2152 * Return 1 meaning mf should be freed from _base_interrupt
2153 * 0 means the mf is freed from this function.
2156 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2158 MPI2DefaultReply_t *mpi_reply;
2160 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2162 if (ioc->tm_cmds.smid != smid)
2164 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2165 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2167 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2168 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2170 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2171 complete(&ioc->tm_cmds.done);
2176 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2177 * @ioc: per adapter object
2178 * @handle: device handle
2180 * During taskmangement request, we need to freeze the device queue.
2183 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2185 struct MPT2SAS_DEVICE *sas_device_priv_data;
2186 struct scsi_device *sdev;
2189 shost_for_each_device(sdev, ioc->shost) {
2192 sas_device_priv_data = sdev->hostdata;
2193 if (!sas_device_priv_data)
2195 if (sas_device_priv_data->sas_target->handle == handle) {
2196 sas_device_priv_data->sas_target->tm_busy = 1;
2198 ioc->ignore_loginfos = 1;
2204 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2205 * @ioc: per adapter object
2206 * @handle: device handle
2208 * During taskmangement request, we need to freeze the device queue.
2211 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2213 struct MPT2SAS_DEVICE *sas_device_priv_data;
2214 struct scsi_device *sdev;
2217 shost_for_each_device(sdev, ioc->shost) {
2220 sas_device_priv_data = sdev->hostdata;
2221 if (!sas_device_priv_data)
2223 if (sas_device_priv_data->sas_target->handle == handle) {
2224 sas_device_priv_data->sas_target->tm_busy = 0;
2226 ioc->ignore_loginfos = 0;
2233 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2234 * @ioc: per adapter struct
2235 * @device_handle: device handle
2236 * @channel: the channel assigned by the OS
2237 * @id: the id assigned by the OS
2239 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2240 * @smid_task: smid assigned to the task
2241 * @timeout: timeout in seconds
2242 * @serial_number: the serial_number from scmd
2243 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2246 * A generic API for sending task management requests to firmware.
2248 * The callback index is set inside `ioc->tm_cb_idx`.
2250 * Return SUCCESS or FAILED.
2253 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2254 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2255 unsigned long serial_number, enum mutex_type m_type)
2257 Mpi2SCSITaskManagementRequest_t *mpi_request;
2258 Mpi2SCSITaskManagementReply_t *mpi_reply;
2261 unsigned long timeleft;
2262 struct scsiio_tracker *scsi_lookup = NULL;
2265 if (m_type == TM_MUTEX_ON)
2266 mutex_lock(&ioc->tm_cmds.mutex);
2267 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2268 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2269 __func__, ioc->name);
2274 if (ioc->shost_recovery || ioc->remove_host ||
2275 ioc->pci_error_recovery) {
2276 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2277 __func__, ioc->name);
2282 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2283 if (ioc_state & MPI2_DOORBELL_USED) {
2284 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2285 "active!\n", ioc->name));
2286 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2288 rc = (!rc) ? SUCCESS : FAILED;
2292 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2293 mpt2sas_base_fault_info(ioc, ioc_state &
2294 MPI2_DOORBELL_DATA_MASK);
2295 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2297 rc = (!rc) ? SUCCESS : FAILED;
2301 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2303 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2304 ioc->name, __func__);
2309 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2310 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2312 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2313 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2315 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2316 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2317 ioc->tm_cmds.smid = smid;
2318 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2319 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2320 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2321 mpi_request->DevHandle = cpu_to_le16(handle);
2322 mpi_request->TaskType = type;
2323 mpi_request->TaskMID = cpu_to_le16(smid_task);
2324 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2325 mpt2sas_scsih_set_tm_flag(ioc, handle);
2326 init_completion(&ioc->tm_cmds.done);
2327 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2328 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2329 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2330 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2331 ioc->name, __func__);
2332 _debug_dump_mf(mpi_request,
2333 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2334 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2335 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2337 rc = (!rc) ? SUCCESS : FAILED;
2338 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2339 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2344 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2345 mpi_reply = ioc->tm_cmds.reply;
2346 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2347 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2348 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2349 le32_to_cpu(mpi_reply->IOCLogInfo),
2350 le32_to_cpu(mpi_reply->TerminationCount)));
2351 if (ioc->logging_level & MPT_DEBUG_TM) {
2352 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2353 if (mpi_reply->IOCStatus)
2354 _debug_dump_mf(mpi_request,
2355 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2360 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2362 if (scsi_lookup->scmd == NULL)
2367 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2368 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2374 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2375 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2376 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2381 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2389 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2390 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2391 if (m_type == TM_MUTEX_ON)
2392 mutex_unlock(&ioc->tm_cmds.mutex);
2397 if (m_type == TM_MUTEX_ON)
2398 mutex_unlock(&ioc->tm_cmds.mutex);
2403 * _scsih_tm_display_info - displays info about the device
2404 * @ioc: per adapter struct
2405 * @scmd: pointer to scsi command object
2407 * Called by task management callback handlers.
2410 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2412 struct scsi_target *starget = scmd->device->sdev_target;
2413 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2414 struct _sas_device *sas_device = NULL;
2415 unsigned long flags;
2416 char *device_str = NULL;
2420 if (ioc->hide_ir_msg)
2421 device_str = "WarpDrive";
2423 device_str = "volume";
2425 scsi_print_command(scmd);
2426 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2427 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2428 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2429 device_str, (unsigned long long)priv_target->sas_address);
2431 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2432 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2433 priv_target->sas_address);
2435 if (priv_target->flags &
2436 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2437 starget_printk(KERN_INFO, starget,
2438 "volume handle(0x%04x), "
2439 "volume wwid(0x%016llx)\n",
2440 sas_device->volume_handle,
2441 (unsigned long long)sas_device->volume_wwid);
2443 starget_printk(KERN_INFO, starget,
2444 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2446 (unsigned long long)sas_device->sas_address,
2448 starget_printk(KERN_INFO, starget,
2449 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2450 (unsigned long long)sas_device->enclosure_logical_id,
2453 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2458 * _scsih_abort - eh threads main abort routine
2459 * @scmd: pointer to scsi command object
2461 * Returns SUCCESS if command aborted else FAILED
2464 _scsih_abort(struct scsi_cmnd *scmd)
2466 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2467 struct MPT2SAS_DEVICE *sas_device_priv_data;
2472 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2473 "scmd(%p)\n", scmd);
2474 _scsih_tm_display_info(ioc, scmd);
2476 sas_device_priv_data = scmd->device->hostdata;
2477 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2478 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2479 "scmd(%p)\n", scmd);
2480 scmd->result = DID_NO_CONNECT << 16;
2481 scmd->scsi_done(scmd);
2486 /* search for the command */
2487 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2489 scmd->result = DID_RESET << 16;
2494 /* for hidden raid components and volumes this is not supported */
2495 if (sas_device_priv_data->sas_target->flags &
2496 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2497 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2498 scmd->result = DID_RESET << 16;
2503 mpt2sas_halt_firmware(ioc);
2505 handle = sas_device_priv_data->sas_target->handle;
2506 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2507 scmd->device->id, scmd->device->lun,
2508 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2509 scmd->serial_number, TM_MUTEX_ON);
2512 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2513 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2518 * _scsih_dev_reset - eh threads main device reset routine
2519 * @scmd: pointer to scsi command object
2521 * Returns SUCCESS if command aborted else FAILED
2524 _scsih_dev_reset(struct scsi_cmnd *scmd)
2526 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2527 struct MPT2SAS_DEVICE *sas_device_priv_data;
2528 struct _sas_device *sas_device;
2529 unsigned long flags;
2533 struct scsi_target *starget = scmd->device->sdev_target;
2535 starget_printk(KERN_INFO, starget, "attempting device reset! "
2536 "scmd(%p)\n", scmd);
2537 _scsih_tm_display_info(ioc, scmd);
2539 sas_device_priv_data = scmd->device->hostdata;
2540 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2541 starget_printk(KERN_INFO, starget, "device been deleted! "
2542 "scmd(%p)\n", scmd);
2543 scmd->result = DID_NO_CONNECT << 16;
2544 scmd->scsi_done(scmd);
2549 /* for hidden raid components obtain the volume_handle */
2551 if (sas_device_priv_data->sas_target->flags &
2552 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2553 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2554 sas_device = _scsih_sas_device_find_by_handle(ioc,
2555 sas_device_priv_data->sas_target->handle);
2557 handle = sas_device->volume_handle;
2558 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2560 handle = sas_device_priv_data->sas_target->handle;
2563 scmd->result = DID_RESET << 16;
2568 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2569 scmd->device->id, scmd->device->lun,
2570 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2574 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2575 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2580 * _scsih_target_reset - eh threads main target reset routine
2581 * @scmd: pointer to scsi command object
2583 * Returns SUCCESS if command aborted else FAILED
2586 _scsih_target_reset(struct scsi_cmnd *scmd)
2588 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2589 struct MPT2SAS_DEVICE *sas_device_priv_data;
2590 struct _sas_device *sas_device;
2591 unsigned long flags;
2594 struct scsi_target *starget = scmd->device->sdev_target;
2596 starget_printk(KERN_INFO, starget, "attempting target reset! "
2597 "scmd(%p)\n", scmd);
2598 _scsih_tm_display_info(ioc, scmd);
2600 sas_device_priv_data = scmd->device->hostdata;
2601 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2602 starget_printk(KERN_INFO, starget, "target been deleted! "
2603 "scmd(%p)\n", scmd);
2604 scmd->result = DID_NO_CONNECT << 16;
2605 scmd->scsi_done(scmd);
2610 /* for hidden raid components obtain the volume_handle */
2612 if (sas_device_priv_data->sas_target->flags &
2613 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2614 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2615 sas_device = _scsih_sas_device_find_by_handle(ioc,
2616 sas_device_priv_data->sas_target->handle);
2618 handle = sas_device->volume_handle;
2619 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2621 handle = sas_device_priv_data->sas_target->handle;
2624 scmd->result = DID_RESET << 16;
2629 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2630 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2631 30, 0, TM_MUTEX_ON);
2634 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2635 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2640 * _scsih_host_reset - eh threads main host reset routine
2641 * @scmd: pointer to scsi command object
2643 * Returns SUCCESS if command aborted else FAILED
2646 _scsih_host_reset(struct scsi_cmnd *scmd)
2648 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2651 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2653 scsi_print_command(scmd);
2655 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2657 r = (retval < 0) ? FAILED : SUCCESS;
2658 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2659 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2665 * _scsih_fw_event_add - insert and queue up fw_event
2666 * @ioc: per adapter object
2667 * @fw_event: object describing the event
2668 * Context: This function will acquire ioc->fw_event_lock.
2670 * This adds the firmware event object into link list, then queues it up to
2671 * be processed from user context.
2676 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2678 unsigned long flags;
2680 if (ioc->firmware_event_thread == NULL)
2683 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2684 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2685 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2686 queue_delayed_work(ioc->firmware_event_thread,
2687 &fw_event->delayed_work, 0);
2688 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2692 * _scsih_fw_event_free - delete fw_event
2693 * @ioc: per adapter object
2694 * @fw_event: object describing the event
2695 * Context: This function will acquire ioc->fw_event_lock.
2697 * This removes firmware event object from link list, frees associated memory.
2702 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2705 unsigned long flags;
2707 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2708 list_del(&fw_event->list);
2709 kfree(fw_event->event_data);
2711 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2716 * _scsih_queue_rescan - queue a topology rescan from user context
2717 * @ioc: per adapter object
2722 _scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc)
2724 struct fw_event_work *fw_event;
2726 if (ioc->wait_for_port_enable_to_complete)
2728 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2731 fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET;
2732 fw_event->ioc = ioc;
2733 _scsih_fw_event_add(ioc, fw_event);
2737 * _scsih_fw_event_cleanup_queue - cleanup event queue
2738 * @ioc: per adapter object
2740 * Walk the firmware event queue, either killing timers, or waiting
2741 * for outstanding events to complete
2746 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2748 struct fw_event_work *fw_event, *next;
2750 if (list_empty(&ioc->fw_event_list) ||
2751 !ioc->firmware_event_thread || in_interrupt())
2754 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2755 if (cancel_delayed_work(&fw_event->delayed_work)) {
2756 _scsih_fw_event_free(ioc, fw_event);
2759 fw_event->cancel_pending_work = 1;
2764 * _scsih_ublock_io_all_device - unblock every device
2765 * @ioc: per adapter object
2767 * change the device state from block to running
2770 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2772 struct MPT2SAS_DEVICE *sas_device_priv_data;
2773 struct scsi_device *sdev;
2775 shost_for_each_device(sdev, ioc->shost) {
2776 sas_device_priv_data = sdev->hostdata;
2777 if (!sas_device_priv_data)
2779 if (!sas_device_priv_data->block)
2781 sas_device_priv_data->block = 0;
2782 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2784 sas_device_priv_data->sas_target->handle));
2785 scsi_internal_device_unblock(sdev);
2789 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2790 * @ioc: per adapter object
2791 * @handle: device handle
2793 * During device pull we need to appropiately set the sdev state.
2796 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2798 struct MPT2SAS_DEVICE *sas_device_priv_data;
2799 struct scsi_device *sdev;
2801 shost_for_each_device(sdev, ioc->shost) {
2802 sas_device_priv_data = sdev->hostdata;
2803 if (!sas_device_priv_data)
2805 if (!sas_device_priv_data->block)
2807 if (sas_device_priv_data->sas_target->handle == handle) {
2808 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2809 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2810 "handle(0x%04x)\n", ioc->name, handle));
2811 sas_device_priv_data->block = 0;
2812 scsi_internal_device_unblock(sdev);
2818 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2819 * @ioc: per adapter object
2820 * @handle: device handle
2822 * During device pull we need to appropiately set the sdev state.
2825 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2827 struct MPT2SAS_DEVICE *sas_device_priv_data;
2828 struct scsi_device *sdev;
2830 shost_for_each_device(sdev, ioc->shost) {
2831 sas_device_priv_data = sdev->hostdata;
2832 if (!sas_device_priv_data)
2834 if (sas_device_priv_data->block)
2836 sas_device_priv_data->block = 1;
2837 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2839 sas_device_priv_data->sas_target->handle));
2840 scsi_internal_device_block(sdev);
2846 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2847 * @ioc: per adapter object
2848 * @handle: device handle
2850 * During device pull we need to appropiately set the sdev state.
2853 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2855 struct MPT2SAS_DEVICE *sas_device_priv_data;
2856 struct scsi_device *sdev;
2858 shost_for_each_device(sdev, ioc->shost) {
2859 sas_device_priv_data = sdev->hostdata;
2860 if (!sas_device_priv_data)
2862 if (sas_device_priv_data->block)
2864 if (sas_device_priv_data->sas_target->handle == handle) {
2865 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2866 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2867 "handle(0x%04x)\n", ioc->name, handle));
2868 sas_device_priv_data->block = 1;
2869 scsi_internal_device_block(sdev);
2875 * _scsih_block_io_to_children_attached_to_ex
2876 * @ioc: per adapter object
2877 * @sas_expander: the sas_device object
2879 * This routine set sdev state to SDEV_BLOCK for all devices
2880 * attached to this expander. This function called when expander is
2884 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2885 struct _sas_node *sas_expander)
2887 struct _sas_port *mpt2sas_port;
2888 struct _sas_device *sas_device;
2889 struct _sas_node *expander_sibling;
2890 unsigned long flags;
2895 list_for_each_entry(mpt2sas_port,
2896 &sas_expander->sas_port_list, port_list) {
2897 if (mpt2sas_port->remote_identify.device_type ==
2899 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2901 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2902 mpt2sas_port->remote_identify.sas_address);
2903 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2906 _scsih_block_io_device(ioc, sas_device->handle);
2910 list_for_each_entry(mpt2sas_port,
2911 &sas_expander->sas_port_list, port_list) {
2913 if (mpt2sas_port->remote_identify.device_type ==
2914 SAS_EDGE_EXPANDER_DEVICE ||
2915 mpt2sas_port->remote_identify.device_type ==
2916 SAS_FANOUT_EXPANDER_DEVICE) {
2918 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2920 mpt2sas_scsih_expander_find_by_sas_address(
2921 ioc, mpt2sas_port->remote_identify.sas_address);
2922 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2923 _scsih_block_io_to_children_attached_to_ex(ioc,
2930 * _scsih_block_io_to_children_attached_directly
2931 * @ioc: per adapter object
2932 * @event_data: topology change event data
2934 * This routine set sdev state to SDEV_BLOCK for all devices
2935 * direct attached during device pull.
2938 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2939 Mpi2EventDataSasTopologyChangeList_t *event_data)
2946 for (i = 0; i < event_data->NumEntries; i++) {
2947 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2950 phy_number = event_data->StartPhyNum + i;
2951 reason_code = event_data->PHY[i].PhyStatus &
2952 MPI2_EVENT_SAS_TOPO_RC_MASK;
2953 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2954 _scsih_block_io_device(ioc, handle);
2959 * _scsih_tm_tr_send - send task management request
2960 * @ioc: per adapter object
2961 * @handle: device handle
2962 * Context: interrupt time.
2964 * This code is to initiate the device removal handshake protocol
2965 * with controller firmware. This function will issue target reset
2966 * using high priority request queue. It will send a sas iounit
2967 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2969 * This is designed to send muliple task management request at the same
2970 * time to the fifo. If the fifo is full, we will append the request,
2971 * and process it in a future completion.
2974 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2976 Mpi2SCSITaskManagementRequest_t *mpi_request;
2978 struct _sas_device *sas_device;
2979 struct MPT2SAS_TARGET *sas_target_priv_data;
2980 unsigned long flags;
2981 struct _tr_list *delayed_tr;
2983 if (ioc->shost_recovery || ioc->remove_host ||
2984 ioc->pci_error_recovery) {
2985 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
2986 "progress!\n", __func__, ioc->name));
2990 /* if PD, then return */
2991 if (test_bit(handle, ioc->pd_handles))
2994 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2995 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2996 if (sas_device && sas_device->starget &&
2997 sas_device->starget->hostdata) {
2998 sas_target_priv_data = sas_device->starget->hostdata;
2999 sas_target_priv_data->deleted = 1;
3000 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3001 "setting delete flag: handle(0x%04x), "
3002 "sas_addr(0x%016llx)\n", ioc->name, handle,
3003 (unsigned long long) sas_device->sas_address));
3005 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3007 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3009 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3012 INIT_LIST_HEAD(&delayed_tr->list);
3013 delayed_tr->handle = handle;
3014 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3015 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3016 "DELAYED:tr:handle(0x%04x), (open)\n",
3017 ioc->name, handle));
3021 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3022 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3023 ioc->tm_tr_cb_idx));
3024 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3025 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3026 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3027 mpi_request->DevHandle = cpu_to_le16(handle);
3028 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3029 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3035 * _scsih_sas_control_complete - completion routine
3036 * @ioc: per adapter object
3037 * @smid: system request message index
3038 * @msix_index: MSIX table index supplied by the OS
3039 * @reply: reply message frame(lower 32bit addr)
3040 * Context: interrupt time.
3042 * This is the sas iounit control completion routine.
3043 * This code is part of the code to initiate the device removal
3044 * handshake protocol with controller firmware.
3046 * Return 1 meaning mf should be freed from _base_interrupt
3047 * 0 means the mf is freed from this function.
3050 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3051 u8 msix_index, u32 reply)
3053 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3054 Mpi2SasIoUnitControlReply_t *mpi_reply =
3055 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3057 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3058 "sc_complete:handle(0x%04x), (open) "
3059 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3060 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3061 le16_to_cpu(mpi_reply->IOCStatus),
3062 le32_to_cpu(mpi_reply->IOCLogInfo)));
3067 * _scsih_tm_tr_volume_send - send target reset request for volumes
3068 * @ioc: per adapter object
3069 * @handle: device handle
3070 * Context: interrupt time.
3072 * This is designed to send muliple task management request at the same
3073 * time to the fifo. If the fifo is full, we will append the request,
3074 * and process it in a future completion.
3077 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3079 Mpi2SCSITaskManagementRequest_t *mpi_request;
3081 struct _tr_list *delayed_tr;
3083 if (ioc->shost_recovery || ioc->remove_host ||
3084 ioc->pci_error_recovery) {
3085 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3086 "progress!\n", __func__, ioc->name));
3090 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3092 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3095 INIT_LIST_HEAD(&delayed_tr->list);
3096 delayed_tr->handle = handle;
3097 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3098 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3099 "DELAYED:tr:handle(0x%04x), (open)\n",
3100 ioc->name, handle));
3104 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3105 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3106 ioc->tm_tr_volume_cb_idx));
3107 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3108 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3109 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3110 mpi_request->DevHandle = cpu_to_le16(handle);
3111 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3112 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3116 * _scsih_tm_volume_tr_complete - target reset completion
3117 * @ioc: per adapter object
3118 * @smid: system request message index
3119 * @msix_index: MSIX table index supplied by the OS
3120 * @reply: reply message frame(lower 32bit addr)
3121 * Context: interrupt time.
3123 * Return 1 meaning mf should be freed from _base_interrupt
3124 * 0 means the mf is freed from this function.
3127 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3128 u8 msix_index, u32 reply)
3131 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3132 Mpi2SCSITaskManagementReply_t *mpi_reply =
3133 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3135 if (ioc->shost_recovery || ioc->remove_host ||
3136 ioc->pci_error_recovery) {
3137 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3138 "progress!\n", __func__, ioc->name));
3142 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3143 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3144 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3145 dewtprintk(ioc, printk("spurious interrupt: "
3146 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3147 le16_to_cpu(mpi_reply->DevHandle), smid));
3151 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3152 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3153 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3154 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3155 le32_to_cpu(mpi_reply->IOCLogInfo),
3156 le32_to_cpu(mpi_reply->TerminationCount)));
3158 return _scsih_check_for_pending_tm(ioc, smid);
3162 * _scsih_tm_tr_complete -
3163 * @ioc: per adapter object
3164 * @smid: system request message index
3165 * @msix_index: MSIX table index supplied by the OS
3166 * @reply: reply message frame(lower 32bit addr)
3167 * Context: interrupt time.
3169 * This is the target reset completion routine.
3170 * This code is part of the code to initiate the device removal
3171 * handshake protocol with controller firmware.
3172 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3174 * Return 1 meaning mf should be freed from _base_interrupt
3175 * 0 means the mf is freed from this function.
3178 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3182 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3183 Mpi2SCSITaskManagementReply_t *mpi_reply =
3184 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3185 Mpi2SasIoUnitControlRequest_t *mpi_request;
3188 if (ioc->shost_recovery || ioc->remove_host ||
3189 ioc->pci_error_recovery) {
3190 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3191 "progress!\n", __func__, ioc->name));
3195 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3196 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3197 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3198 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3199 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3200 le16_to_cpu(mpi_reply->DevHandle), smid));
3204 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3205 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3206 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3207 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3208 le32_to_cpu(mpi_reply->IOCLogInfo),
3209 le32_to_cpu(mpi_reply->TerminationCount)));
3211 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3212 if (!smid_sas_ctrl) {
3213 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3214 ioc->name, __func__);
3218 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3219 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3220 ioc->tm_sas_control_cb_idx));
3221 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3222 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3223 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3224 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3225 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3226 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3228 return _scsih_check_for_pending_tm(ioc, smid);
3232 * _scsih_check_for_pending_tm - check for pending task management
3233 * @ioc: per adapter object
3234 * @smid: system request message index
3236 * This will check delayed target reset list, and feed the
3239 * Return 1 meaning mf should be freed from _base_interrupt
3240 * 0 means the mf is freed from this function.
3243 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3245 struct _tr_list *delayed_tr;
3247 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3248 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3249 struct _tr_list, list);
3250 mpt2sas_base_free_smid(ioc, smid);
3251 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3252 list_del(&delayed_tr->list);
3257 if (!list_empty(&ioc->delayed_tr_list)) {
3258 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3259 struct _tr_list, list);
3260 mpt2sas_base_free_smid(ioc, smid);
3261 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3262 list_del(&delayed_tr->list);
3271 * _scsih_check_topo_delete_events - sanity check on topo events
3272 * @ioc: per adapter object
3273 * @event_data: the event data payload
3275 * This routine added to better handle cable breaker.
3277 * This handles the case where driver receives multiple expander
3278 * add and delete events in a single shot. When there is a delete event
3279 * the routine will void any pending add events waiting in the event queue.
3284 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3285 Mpi2EventDataSasTopologyChangeList_t *event_data)
3287 struct fw_event_work *fw_event;
3288 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3289 u16 expander_handle;
3290 struct _sas_node *sas_expander;
3291 unsigned long flags;
3295 for (i = 0 ; i < event_data->NumEntries; i++) {
3296 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3299 reason_code = event_data->PHY[i].PhyStatus &
3300 MPI2_EVENT_SAS_TOPO_RC_MASK;
3301 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3302 _scsih_tm_tr_send(ioc, handle);
3305 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3306 if (expander_handle < ioc->sas_hba.num_phys) {
3307 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3311 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3312 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3313 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3314 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3316 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3317 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3318 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3319 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3321 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3324 /* mark ignore flag for pending events */
3325 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3326 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3327 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3330 local_event_data = fw_event->event_data;
3331 if (local_event_data->ExpStatus ==
3332 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3333 local_event_data->ExpStatus ==
3334 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3335 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3337 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3338 "setting ignoring flag\n", ioc->name));
3339 fw_event->ignore = 1;
3343 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3347 * _scsih_set_volume_delete_flag - setting volume delete flag
3348 * @ioc: per adapter object
3349 * @handle: device handle
3355 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3357 struct _raid_device *raid_device;
3358 struct MPT2SAS_TARGET *sas_target_priv_data;
3359 unsigned long flags;
3361 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3362 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3363 if (raid_device && raid_device->starget &&
3364 raid_device->starget->hostdata) {
3365 sas_target_priv_data =
3366 raid_device->starget->hostdata;
3367 sas_target_priv_data->deleted = 1;
3368 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3369 "setting delete flag: handle(0x%04x), "
3370 "wwid(0x%016llx)\n", ioc->name, handle,
3371 (unsigned long long) raid_device->wwid));
3373 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3377 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3378 * @handle: input handle
3379 * @a: handle for volume a
3380 * @b: handle for volume b
3382 * IR firmware only supports two raid volumes. The purpose of this
3383 * routine is to set the volume handle in either a or b. When the given
3384 * input handle is non-zero, or when a and b have not been set before.
3387 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3389 if (!handle || handle == *a || handle == *b)
3398 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3399 * @ioc: per adapter object
3400 * @event_data: the event data payload
3401 * Context: interrupt time.
3403 * This routine will send target reset to volume, followed by target
3404 * resets to the PDs. This is called when a PD has been removed, or
3405 * volume has been deleted or removed. When the target reset is sent
3406 * to volume, the PD target resets need to be queued to start upon
3407 * completion of the volume target reset.
3412 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3413 Mpi2EventDataIrConfigChangeList_t *event_data)
3415 Mpi2EventIrConfigElement_t *element;
3417 u16 handle, volume_handle, a, b;
3418 struct _tr_list *delayed_tr;
3423 if (ioc->is_warpdrive)
3426 /* Volume Resets for Deleted or Removed */
3427 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3428 for (i = 0; i < event_data->NumElements; i++, element++) {
3429 if (element->ReasonCode ==
3430 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3431 element->ReasonCode ==
3432 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3433 volume_handle = le16_to_cpu(element->VolDevHandle);
3434 _scsih_set_volume_delete_flag(ioc, volume_handle);
3435 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3439 /* Volume Resets for UNHIDE events */
3440 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3441 for (i = 0; i < event_data->NumElements; i++, element++) {
3442 if (le32_to_cpu(event_data->Flags) &
3443 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3445 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3446 volume_handle = le16_to_cpu(element->VolDevHandle);
3447 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3452 _scsih_tm_tr_volume_send(ioc, a);
3454 _scsih_tm_tr_volume_send(ioc, b);
3456 /* PD target resets */
3457 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3458 for (i = 0; i < event_data->NumElements; i++, element++) {
3459 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3461 handle = le16_to_cpu(element->PhysDiskDevHandle);
3462 volume_handle = le16_to_cpu(element->VolDevHandle);
3463 clear_bit(handle, ioc->pd_handles);
3465 _scsih_tm_tr_send(ioc, handle);
3466 else if (volume_handle == a || volume_handle == b) {
3467 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3468 BUG_ON(!delayed_tr);
3469 INIT_LIST_HEAD(&delayed_tr->list);
3470 delayed_tr->handle = handle;
3471 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3472 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3473 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3476 _scsih_tm_tr_send(ioc, handle);
3482 * _scsih_check_volume_delete_events - set delete flag for volumes
3483 * @ioc: per adapter object
3484 * @event_data: the event data payload
3485 * Context: interrupt time.
3487 * This will handle the case when the cable connected to entire volume is
3488 * pulled. We will take care of setting the deleted flag so normal IO will
3494 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3495 Mpi2EventDataIrVolume_t *event_data)
3499 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3501 state = le32_to_cpu(event_data->NewValue);
3502 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3503 MPI2_RAID_VOL_STATE_FAILED)
3504 _scsih_set_volume_delete_flag(ioc,
3505 le16_to_cpu(event_data->VolDevHandle));
3509 * _scsih_flush_running_cmds - completing outstanding commands.
3510 * @ioc: per adapter object
3512 * The flushing out of all pending scmd commands following host reset,
3513 * where all IO is dropped to the floor.
3518 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3520 struct scsi_cmnd *scmd;
3524 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3525 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3529 mpt2sas_base_free_smid(ioc, smid);
3530 scsi_dma_unmap(scmd);
3531 if (ioc->pci_error_recovery)
3532 scmd->result = DID_NO_CONNECT << 16;
3534 scmd->result = DID_RESET << 16;
3535 scmd->scsi_done(scmd);
3537 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3542 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3543 * @scmd: pointer to scsi command object
3544 * @mpi_request: pointer to the SCSI_IO reqest message frame
3546 * Supporting protection 1 and 3.
3551 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3554 unsigned char prot_op = scsi_get_prot_op(scmd);
3555 unsigned char prot_type = scsi_get_prot_type(scmd);
3557 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3560 if (prot_op == SCSI_PROT_READ_STRIP)
3561 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3562 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3563 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3567 switch (prot_type) {
3568 case SCSI_PROT_DIF_TYPE1:
3569 case SCSI_PROT_DIF_TYPE2:
3572 * enable ref/guard checking
3573 * auto increment ref tag
3575 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3576 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3577 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3578 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3579 cpu_to_be32(scsi_get_lba(scmd));
3582 case SCSI_PROT_DIF_TYPE3:
3585 * enable guard checking
3587 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3590 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3591 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3595 * _scsih_eedp_error_handling - return sense code for EEDP errors
3596 * @scmd: pointer to scsi command object
3597 * @ioc_status: ioc status
3602 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3608 switch (ioc_status) {
3609 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3612 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3615 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3623 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3624 sk = ILLEGAL_REQUEST;
3625 host_byte = DID_ABORT;
3627 sk = ABORTED_COMMAND;
3631 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3632 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3633 SAM_STAT_CHECK_CONDITION;
3637 * _scsih_scsi_direct_io_get - returns direct io flag
3638 * @ioc: per adapter object
3639 * @smid: system request message index
3641 * Returns the smid stored scmd pointer.
3644 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3646 return ioc->scsi_lookup[smid - 1].direct_io;
3650 * _scsih_scsi_direct_io_set - sets direct io flag
3651 * @ioc: per adapter object
3652 * @smid: system request message index
3653 * @direct_io: Zero or non-zero value to set in the direct_io flag
3658 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3660 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3665 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3666 * @ioc: per adapter object
3667 * @scmd: pointer to scsi command object
3668 * @raid_device: pointer to raid device data structure
3669 * @mpi_request: pointer to the SCSI_IO reqest message frame
3670 * @smid: system request message index
3675 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3676 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3679 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3680 u32 stripe_sz, stripe_exp;
3681 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3682 u8 cdb0 = scmd->cmnd[0];
3685 * Try Direct I/O to RAID memeber disks
3687 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3688 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3689 cdb_ptr = mpi_request->CDB.CDB32;
3691 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3693 io_size = scsi_bufflen(scmd) >> 9;
3694 /* get virtual lba */
3695 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3697 tmp_ptr = (u8 *)&v_lba + 3;
3698 *tmp_ptr-- = *lba_ptr1++;
3699 *tmp_ptr-- = *lba_ptr1++;
3700 *tmp_ptr-- = *lba_ptr1++;
3701 *tmp_ptr = *lba_ptr1;
3703 if (((u64)v_lba + (u64)io_size - 1) <=
3704 (u32)raid_device->max_lba) {
3705 stripe_sz = raid_device->stripe_sz;
3706 stripe_exp = raid_device->stripe_exponent;
3707 stripe_off = v_lba & (stripe_sz - 1);
3709 /* Check whether IO falls within a stripe */
3710 if ((stripe_off + io_size) <= stripe_sz) {
3711 num_pds = raid_device->num_pds;
3712 p_lba = v_lba >> stripe_exp;
3713 stripe_unit = p_lba / num_pds;
3714 column = p_lba % num_pds;
3715 p_lba = (stripe_unit << stripe_exp) +
3717 mpi_request->DevHandle =
3718 cpu_to_le16(raid_device->
3720 tmp_ptr = (u8 *)&p_lba + 3;
3721 *lba_ptr2++ = *tmp_ptr--;
3722 *lba_ptr2++ = *tmp_ptr--;
3723 *lba_ptr2++ = *tmp_ptr--;
3724 *lba_ptr2 = *tmp_ptr;
3726 * WD: To indicate this I/O is directI/O
3728 _scsih_scsi_direct_io_set(ioc, smid, 1);
3736 * _scsih_qcmd - main scsi request entry point
3737 * @scmd: pointer to scsi command object
3738 * @done: function pointer to be invoked on completion
3740 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3742 * Returns 0 on success. If there's a failure, return either:
3743 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3744 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3747 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3749 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3750 struct MPT2SAS_DEVICE *sas_device_priv_data;
3751 struct MPT2SAS_TARGET *sas_target_priv_data;
3752 struct _raid_device *raid_device;
3753 Mpi2SCSIIORequest_t *mpi_request;
3757 scmd->scsi_done = done;
3758 sas_device_priv_data = scmd->device->hostdata;
3759 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3760 scmd->result = DID_NO_CONNECT << 16;
3761 scmd->scsi_done(scmd);
3765 if (ioc->pci_error_recovery || ioc->remove_host) {
3766 scmd->result = DID_NO_CONNECT << 16;
3767 scmd->scsi_done(scmd);
3771 sas_target_priv_data = sas_device_priv_data->sas_target;
3772 /* invalid device handle */
3773 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3774 scmd->result = DID_NO_CONNECT << 16;
3775 scmd->scsi_done(scmd);
3779 /* host recovery or link resets sent via IOCTLs */
3780 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3781 return SCSI_MLQUEUE_HOST_BUSY;
3782 /* device busy with task management */
3783 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3784 return SCSI_MLQUEUE_DEVICE_BUSY;
3785 /* device has been deleted */
3786 else if (sas_target_priv_data->deleted) {
3787 scmd->result = DID_NO_CONNECT << 16;
3788 scmd->scsi_done(scmd);
3792 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3793 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3794 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3795 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3797 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3800 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3801 if (scmd->device->tagged_supported) {
3802 if (scmd->device->ordered_tags)
3803 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3805 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3807 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3808 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3810 mpi_control |= (0x500);
3813 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3814 /* Make sure Device is not raid volume.
3815 * We do not expose raid functionality to upper layer for warpdrive.
3817 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3818 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3819 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3821 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3823 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3824 ioc->name, __func__);
3827 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3828 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3829 _scsih_setup_eedp(scmd, mpi_request);
3830 if (scmd->cmd_len == 32)
3831 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3832 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3833 if (sas_device_priv_data->sas_target->flags &
3834 MPT_TARGET_FLAGS_RAID_COMPONENT)
3835 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3837 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3838 mpi_request->DevHandle =
3839 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3840 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3841 mpi_request->Control = cpu_to_le32(mpi_control);
3842 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3843 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3844 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3845 mpi_request->SenseBufferLowAddress =
3846 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3847 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3848 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3849 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3850 mpi_request->VF_ID = 0; /* TODO */
3851 mpi_request->VP_ID = 0;
3852 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3854 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3856 if (!mpi_request->DataLength) {
3857 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3859 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3860 mpt2sas_base_free_smid(ioc, smid);
3865 raid_device = sas_target_priv_data->raid_device;
3866 if (raid_device && raid_device->direct_io_enabled)
3867 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3870 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3871 mpt2sas_base_put_smid_scsi_io(ioc, smid,
3872 le16_to_cpu(mpi_request->DevHandle));
3874 mpt2sas_base_put_smid_default(ioc, smid);
3878 return SCSI_MLQUEUE_HOST_BUSY;
3881 static DEF_SCSI_QCMD(_scsih_qcmd)
3884 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3885 * @sense_buffer: sense data returned by target
3886 * @data: normalized skey/asc/ascq
3891 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3893 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3894 /* descriptor format */
3895 data->skey = sense_buffer[1] & 0x0F;
3896 data->asc = sense_buffer[2];
3897 data->ascq = sense_buffer[3];
3900 data->skey = sense_buffer[2] & 0x0F;
3901 data->asc = sense_buffer[12];
3902 data->ascq = sense_buffer[13];
3906 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3908 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
3909 * @ioc: per adapter object
3910 * @scmd: pointer to scsi command object
3911 * @mpi_reply: reply mf payload returned from firmware
3913 * scsi_status - SCSI Status code returned from target device
3914 * scsi_state - state info associated with SCSI_IO determined by ioc
3915 * ioc_status - ioc supplied status info
3920 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3921 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3925 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3926 MPI2_IOCSTATUS_MASK;
3927 u8 scsi_state = mpi_reply->SCSIState;
3928 u8 scsi_status = mpi_reply->SCSIStatus;
3929 char *desc_ioc_state = NULL;
3930 char *desc_scsi_status = NULL;
3931 char *desc_scsi_state = ioc->tmp_string;
3932 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3933 struct _sas_device *sas_device = NULL;
3934 unsigned long flags;
3935 struct scsi_target *starget = scmd->device->sdev_target;
3936 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
3937 char *device_str = NULL;
3942 if (ioc->hide_ir_msg)
3943 device_str = "WarpDrive";
3945 device_str = "volume";
3947 if (log_info == 0x31170000)
3950 switch (ioc_status) {
3951 case MPI2_IOCSTATUS_SUCCESS:
3952 desc_ioc_state = "success";
3954 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3955 desc_ioc_state = "invalid function";
3957 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3958 desc_ioc_state = "scsi recovered error";
3960 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3961 desc_ioc_state = "scsi invalid dev handle";
3963 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3964 desc_ioc_state = "scsi device not there";
3966 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3967 desc_ioc_state = "scsi data overrun";
3969 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3970 desc_ioc_state = "scsi data underrun";
3972 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3973 desc_ioc_state = "scsi io data error";
3975 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3976 desc_ioc_state = "scsi protocol error";
3978 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3979 desc_ioc_state = "scsi task terminated";
3981 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3982 desc_ioc_state = "scsi residual mismatch";
3984 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3985 desc_ioc_state = "scsi task mgmt failed";
3987 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3988 desc_ioc_state = "scsi ioc terminated";
3990 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3991 desc_ioc_state = "scsi ext terminated";
3993 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3994 desc_ioc_state = "eedp guard error";
3996 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3997 desc_ioc_state = "eedp ref tag error";
3999 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4000 desc_ioc_state = "eedp app tag error";
4003 desc_ioc_state = "unknown";
4007 switch (scsi_status) {
4008 case MPI2_SCSI_STATUS_GOOD:
4009 desc_scsi_status = "good";
4011 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4012 desc_scsi_status = "check condition";
4014 case MPI2_SCSI_STATUS_CONDITION_MET:
4015 desc_scsi_status = "condition met";
4017 case MPI2_SCSI_STATUS_BUSY:
4018 desc_scsi_status = "busy";
4020 case MPI2_SCSI_STATUS_INTERMEDIATE:
4021 desc_scsi_status = "intermediate";
4023 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4024 desc_scsi_status = "intermediate condmet";
4026 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4027 desc_scsi_status = "reservation conflict";
4029 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4030 desc_scsi_status = "command terminated";
4032 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4033 desc_scsi_status = "task set full";
4035 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4036 desc_scsi_status = "aca active";
4038 case MPI2_SCSI_STATUS_TASK_ABORTED:
4039 desc_scsi_status = "task aborted";
4042 desc_scsi_status = "unknown";
4046 desc_scsi_state[0] = '\0';
4048 desc_scsi_state = " ";
4049 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4050 strcat(desc_scsi_state, "response info ");
4051 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4052 strcat(desc_scsi_state, "state terminated ");
4053 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4054 strcat(desc_scsi_state, "no status ");
4055 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4056 strcat(desc_scsi_state, "autosense failed ");
4057 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4058 strcat(desc_scsi_state, "autosense valid ");
4060 scsi_print_command(scmd);
4062 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4063 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4064 device_str, (unsigned long long)priv_target->sas_address);
4066 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4067 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4068 priv_target->sas_address);
4070 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4071 "phy(%d)\n", ioc->name, sas_device->sas_address,
4073 printk(MPT2SAS_WARN_FMT
4074 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4075 ioc->name, sas_device->enclosure_logical_id,
4078 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4081 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4082 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4083 desc_ioc_state, ioc_status, smid);
4084 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4085 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4086 scsi_get_resid(scmd));
4087 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4088 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4089 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4090 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4091 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4092 scsi_status, desc_scsi_state, scsi_state);
4094 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4095 struct sense_info data;
4096 _scsih_normalize_sense(scmd->sense_buffer, &data);
4097 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4098 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4099 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4102 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4103 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4104 response_bytes = (u8 *)&response_info;
4105 _scsih_response_code(ioc, response_bytes[0]);
4111 * _scsih_turn_on_fault_led - illuminate Fault LED
4112 * @ioc: per adapter object
4113 * @handle: device handle
4119 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4121 Mpi2SepReply_t mpi_reply;
4122 Mpi2SepRequest_t mpi_request;
4124 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4125 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4126 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4127 mpi_request.SlotStatus =
4128 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4129 mpi_request.DevHandle = cpu_to_le16(handle);
4130 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4131 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4132 &mpi_request)) != 0) {
4133 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4134 __FILE__, __LINE__, __func__);
4138 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4139 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4140 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4141 le16_to_cpu(mpi_reply.IOCStatus),
4142 le32_to_cpu(mpi_reply.IOCLogInfo)));
4148 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4149 * @ioc: per adapter object
4150 * @handle: device handle
4151 * Context: interrupt.
4156 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4158 struct fw_event_work *fw_event;
4160 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4163 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4164 fw_event->device_handle = handle;
4165 fw_event->ioc = ioc;
4166 _scsih_fw_event_add(ioc, fw_event);
4170 * _scsih_smart_predicted_fault - process smart errors
4171 * @ioc: per adapter object
4172 * @handle: device handle
4173 * Context: interrupt.
4178 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4180 struct scsi_target *starget;
4181 struct MPT2SAS_TARGET *sas_target_priv_data;
4182 Mpi2EventNotificationReply_t *event_reply;
4183 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4184 struct _sas_device *sas_device;
4186 unsigned long flags;
4188 /* only handle non-raid devices */
4189 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4190 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4192 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4195 starget = sas_device->starget;
4196 sas_target_priv_data = starget->hostdata;
4198 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4199 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4200 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4203 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4204 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4206 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4207 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4209 /* insert into event log */
4210 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4211 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4212 event_reply = kzalloc(sz, GFP_KERNEL);
4214 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4215 ioc->name, __FILE__, __LINE__, __func__);
4219 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4220 event_reply->Event =
4221 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4222 event_reply->MsgLength = sz/4;
4223 event_reply->EventDataLength =
4224 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4225 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4226 event_reply->EventData;
4227 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4228 event_data->ASC = 0x5D;
4229 event_data->DevHandle = cpu_to_le16(handle);
4230 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4231 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4236 * _scsih_io_done - scsi request callback
4237 * @ioc: per adapter object
4238 * @smid: system request message index
4239 * @msix_index: MSIX table index supplied by the OS
4240 * @reply: reply message frame(lower 32bit addr)
4242 * Callback handler when using _scsih_qcmd.
4244 * Return 1 meaning mf should be freed from _base_interrupt
4245 * 0 means the mf is freed from this function.
4248 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4250 Mpi2SCSIIORequest_t *mpi_request;
4251 Mpi2SCSIIOReply_t *mpi_reply;
4252 struct scsi_cmnd *scmd;
4258 struct MPT2SAS_DEVICE *sas_device_priv_data;
4259 u32 response_code = 0;
4260 unsigned long flags;
4262 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4263 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4267 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4269 if (mpi_reply == NULL) {
4270 scmd->result = DID_OK << 16;
4274 sas_device_priv_data = scmd->device->hostdata;
4275 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4276 sas_device_priv_data->sas_target->deleted) {
4277 scmd->result = DID_NO_CONNECT << 16;
4281 * WARPDRIVE: If direct_io is set then it is directIO,
4282 * the failed direct I/O should be redirected to volume
4284 if (_scsih_scsi_direct_io_get(ioc, smid)) {
4285 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4286 ioc->scsi_lookup[smid - 1].scmd = scmd;
4287 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4288 _scsih_scsi_direct_io_set(ioc, smid, 0);
4289 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4290 mpi_request->DevHandle =
4291 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4292 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4293 sas_device_priv_data->sas_target->handle);
4298 /* turning off TLR */
4299 scsi_state = mpi_reply->SCSIState;
4300 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4302 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4303 if (!sas_device_priv_data->tlr_snoop_check) {
4304 sas_device_priv_data->tlr_snoop_check++;
4305 /* Make sure Device is not raid volume.
4306 * We do not expose raid functionality to upper layer for warpdrive.
4308 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4309 sas_is_tlr_enabled(scmd->device) &&
4310 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4311 sas_disable_tlr(scmd->device);
4312 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4316 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4317 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4318 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4319 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4320 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4323 ioc_status &= MPI2_IOCSTATUS_MASK;
4324 scsi_status = mpi_reply->SCSIStatus;
4326 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4327 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4328 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4329 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4330 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4333 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4334 struct sense_info data;
4335 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4337 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4338 le32_to_cpu(mpi_reply->SenseCount));
4339 memcpy(scmd->sense_buffer, sense_data, sz);
4340 _scsih_normalize_sense(scmd->sense_buffer, &data);
4341 /* failure prediction threshold exceeded */
4342 if (data.asc == 0x5D)
4343 _scsih_smart_predicted_fault(ioc,
4344 le16_to_cpu(mpi_reply->DevHandle));
4347 switch (ioc_status) {
4348 case MPI2_IOCSTATUS_BUSY:
4349 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4350 scmd->result = SAM_STAT_BUSY;
4353 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4354 scmd->result = DID_NO_CONNECT << 16;
4357 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4358 if (sas_device_priv_data->block) {
4359 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4362 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4363 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4364 scmd->result = DID_RESET << 16;
4367 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4368 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4369 scmd->result = DID_SOFT_ERROR << 16;
4371 scmd->result = (DID_OK << 16) | scsi_status;
4374 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4375 scmd->result = (DID_OK << 16) | scsi_status;
4377 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4380 if (xfer_cnt < scmd->underflow) {
4381 if (scsi_status == SAM_STAT_BUSY)
4382 scmd->result = SAM_STAT_BUSY;
4384 scmd->result = DID_SOFT_ERROR << 16;
4385 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4386 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4387 scmd->result = DID_SOFT_ERROR << 16;
4388 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4389 scmd->result = DID_RESET << 16;
4390 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4391 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4392 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4393 scmd->result = (DRIVER_SENSE << 24) |
4394 SAM_STAT_CHECK_CONDITION;
4395 scmd->sense_buffer[0] = 0x70;
4396 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4397 scmd->sense_buffer[12] = 0x20;
4398 scmd->sense_buffer[13] = 0;
4402 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4403 scsi_set_resid(scmd, 0);
4404 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4405 case MPI2_IOCSTATUS_SUCCESS:
4406 scmd->result = (DID_OK << 16) | scsi_status;
4407 if (response_code ==
4408 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4409 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4410 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4411 scmd->result = DID_SOFT_ERROR << 16;
4412 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4413 scmd->result = DID_RESET << 16;
4416 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4417 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4418 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4419 _scsih_eedp_error_handling(scmd, ioc_status);
4421 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4422 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4423 case MPI2_IOCSTATUS_INVALID_SGL:
4424 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4425 case MPI2_IOCSTATUS_INVALID_FIELD:
4426 case MPI2_IOCSTATUS_INVALID_STATE:
4427 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4428 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4430 scmd->result = DID_SOFT_ERROR << 16;
4435 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4436 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4437 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4441 scsi_dma_unmap(scmd);
4442 scmd->scsi_done(scmd);
4447 * _scsih_sas_host_refresh - refreshing sas host object contents
4448 * @ioc: per adapter object
4451 * During port enable, fw will send topology events for every device. Its
4452 * possible that the handles may change from the previous setting, so this
4453 * code keeping handles updating if changed.
4458 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4463 Mpi2ConfigReply_t mpi_reply;
4464 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4465 u16 attached_handle;
4468 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4469 "updating handles for sas_host(0x%016llx)\n",
4470 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4472 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4473 * sizeof(Mpi2SasIOUnit0PhyData_t));
4474 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4475 if (!sas_iounit_pg0) {
4476 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4477 ioc->name, __FILE__, __LINE__, __func__);
4481 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4482 sas_iounit_pg0, sz)) != 0)
4484 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4485 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4487 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4488 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4490 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4491 PhyData[0].ControllerDevHandle);
4492 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4493 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4495 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4496 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4497 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4498 attached_handle, i, link_rate);
4501 kfree(sas_iounit_pg0);
4505 * _scsih_sas_host_add - create sas host object
4506 * @ioc: per adapter object
4508 * Creating host side data object, stored in ioc->sas_hba
4513 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4516 Mpi2ConfigReply_t mpi_reply;
4517 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4518 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4519 Mpi2SasPhyPage0_t phy_pg0;
4520 Mpi2SasDevicePage0_t sas_device_pg0;
4521 Mpi2SasEnclosurePage0_t enclosure_pg0;
4524 u16 device_missing_delay;
4526 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4527 if (!ioc->sas_hba.num_phys) {
4528 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4529 ioc->name, __FILE__, __LINE__, __func__);
4533 /* sas_iounit page 0 */
4534 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4535 sizeof(Mpi2SasIOUnit0PhyData_t));
4536 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4537 if (!sas_iounit_pg0) {
4538 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4539 ioc->name, __FILE__, __LINE__, __func__);
4542 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4543 sas_iounit_pg0, sz))) {
4544 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4545 ioc->name, __FILE__, __LINE__, __func__);
4548 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4549 MPI2_IOCSTATUS_MASK;
4550 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4551 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4552 ioc->name, __FILE__, __LINE__, __func__);
4556 /* sas_iounit page 1 */
4557 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4558 sizeof(Mpi2SasIOUnit1PhyData_t));
4559 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4560 if (!sas_iounit_pg1) {
4561 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4562 ioc->name, __FILE__, __LINE__, __func__);
4565 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4566 sas_iounit_pg1, sz))) {
4567 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4568 ioc->name, __FILE__, __LINE__, __func__);
4571 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4572 MPI2_IOCSTATUS_MASK;
4573 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4574 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4575 ioc->name, __FILE__, __LINE__, __func__);
4579 ioc->io_missing_delay =
4580 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4581 device_missing_delay =
4582 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4583 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4584 ioc->device_missing_delay = (device_missing_delay &
4585 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4587 ioc->device_missing_delay = device_missing_delay &
4588 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4590 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4591 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4592 sizeof(struct _sas_phy), GFP_KERNEL);
4593 if (!ioc->sas_hba.phy) {
4594 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4595 ioc->name, __FILE__, __LINE__, __func__);
4598 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4599 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4601 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4602 ioc->name, __FILE__, __LINE__, __func__);
4605 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4606 MPI2_IOCSTATUS_MASK;
4607 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4608 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4609 ioc->name, __FILE__, __LINE__, __func__);
4614 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4615 PhyData[0].ControllerDevHandle);
4616 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4617 ioc->sas_hba.phy[i].phy_id = i;
4618 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4619 phy_pg0, ioc->sas_hba.parent_dev);
4621 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4622 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4623 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4624 ioc->name, __FILE__, __LINE__, __func__);
4627 ioc->sas_hba.enclosure_handle =
4628 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4629 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4630 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4631 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4632 (unsigned long long) ioc->sas_hba.sas_address,
4633 ioc->sas_hba.num_phys) ;
4635 if (ioc->sas_hba.enclosure_handle) {
4636 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4638 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4639 ioc->sas_hba.enclosure_handle))) {
4640 ioc->sas_hba.enclosure_logical_id =
4641 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4646 kfree(sas_iounit_pg1);
4647 kfree(sas_iounit_pg0);
4651 * _scsih_expander_add - creating expander object
4652 * @ioc: per adapter object
4653 * @handle: expander handle
4655 * Creating expander object, stored in ioc->sas_expander_list.
4657 * Return 0 for success, else error.
4660 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4662 struct _sas_node *sas_expander;
4663 Mpi2ConfigReply_t mpi_reply;
4664 Mpi2ExpanderPage0_t expander_pg0;
4665 Mpi2ExpanderPage1_t expander_pg1;
4666 Mpi2SasEnclosurePage0_t enclosure_pg0;
4669 u64 sas_address, sas_address_parent = 0;
4671 unsigned long flags;
4672 struct _sas_port *mpt2sas_port = NULL;
4678 if (ioc->shost_recovery || ioc->pci_error_recovery)
4681 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4682 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4683 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4684 ioc->name, __FILE__, __LINE__, __func__);
4688 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4689 MPI2_IOCSTATUS_MASK;
4690 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4691 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4692 ioc->name, __FILE__, __LINE__, __func__);
4696 /* handle out of order topology events */
4697 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4698 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4700 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4701 ioc->name, __FILE__, __LINE__, __func__);
4704 if (sas_address_parent != ioc->sas_hba.sas_address) {
4705 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4706 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4707 sas_address_parent);
4708 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4709 if (!sas_expander) {
4710 rc = _scsih_expander_add(ioc, parent_handle);
4716 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4717 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4718 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4720 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4725 sas_expander = kzalloc(sizeof(struct _sas_node),
4727 if (!sas_expander) {
4728 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4729 ioc->name, __FILE__, __LINE__, __func__);
4733 sas_expander->handle = handle;
4734 sas_expander->num_phys = expander_pg0.NumPhys;
4735 sas_expander->sas_address_parent = sas_address_parent;
4736 sas_expander->sas_address = sas_address;
4738 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4739 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4740 handle, parent_handle, (unsigned long long)
4741 sas_expander->sas_address, sas_expander->num_phys);
4743 if (!sas_expander->num_phys)
4745 sas_expander->phy = kcalloc(sas_expander->num_phys,
4746 sizeof(struct _sas_phy), GFP_KERNEL);
4747 if (!sas_expander->phy) {
4748 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4749 ioc->name, __FILE__, __LINE__, __func__);
4754 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4755 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4756 sas_address_parent);
4757 if (!mpt2sas_port) {
4758 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4759 ioc->name, __FILE__, __LINE__, __func__);
4763 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4765 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4766 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4767 &expander_pg1, i, handle))) {
4768 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4769 ioc->name, __FILE__, __LINE__, __func__);
4773 sas_expander->phy[i].handle = handle;
4774 sas_expander->phy[i].phy_id = i;
4776 if ((mpt2sas_transport_add_expander_phy(ioc,
4777 &sas_expander->phy[i], expander_pg1,
4778 sas_expander->parent_dev))) {
4779 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4780 ioc->name, __FILE__, __LINE__, __func__);
4786 if (sas_expander->enclosure_handle) {
4787 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4788 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4789 sas_expander->enclosure_handle))) {
4790 sas_expander->enclosure_logical_id =
4791 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4795 _scsih_expander_node_add(ioc, sas_expander);
4801 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4802 sas_address_parent);
4803 kfree(sas_expander);
4808 * _scsih_done - scsih callback handler.
4809 * @ioc: per adapter object
4810 * @smid: system request message index
4811 * @msix_index: MSIX table index supplied by the OS
4812 * @reply: reply message frame(lower 32bit addr)
4814 * Callback handler when sending internal generated message frames.
4815 * The callback index passed is `ioc->scsih_cb_idx`
4817 * Return 1 meaning mf should be freed from _base_interrupt
4818 * 0 means the mf is freed from this function.
4821 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4823 MPI2DefaultReply_t *mpi_reply;
4825 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4826 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4828 if (ioc->scsih_cmds.smid != smid)
4830 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4832 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4833 mpi_reply->MsgLength*4);
4834 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4836 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4837 complete(&ioc->scsih_cmds.done);
4842 * mpt2sas_expander_remove - removing expander object
4843 * @ioc: per adapter object
4844 * @sas_address: expander sas_address
4849 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
4851 struct _sas_node *sas_expander;
4852 unsigned long flags;
4854 if (ioc->shost_recovery)
4857 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4858 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4860 if (!sas_expander) {
4861 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4864 list_del(&sas_expander->list);
4865 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4866 _scsih_expander_node_remove(ioc, sas_expander);
4870 * _scsih_check_access_status - check access flags
4871 * @ioc: per adapter object
4872 * @sas_address: sas address
4873 * @handle: sas device handle
4874 * @access_flags: errors returned during discovery of the device
4876 * Return 0 for success, else failure
4879 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4880 u16 handle, u8 access_status)
4885 switch (access_status) {
4886 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4887 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4890 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4891 desc = "sata capability failed";
4893 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4894 desc = "sata affiliation conflict";
4896 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4897 desc = "route not addressable";
4899 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4900 desc = "smp error not addressable";
4902 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4903 desc = "device blocked";
4905 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4906 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4907 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4908 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4909 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4910 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4911 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4912 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4913 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4914 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4915 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4916 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4917 desc = "sata initialization failed";
4927 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
4928 "handle(0x%04x)\n", ioc->name, desc,
4929 (unsigned long long)sas_address, handle);
4934 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4936 Mpi2ConfigReply_t mpi_reply;
4937 Mpi2SasDevicePage0_t sas_device_pg0;
4938 struct _sas_device *sas_device;
4940 unsigned long flags;
4942 struct scsi_target *starget;
4943 struct MPT2SAS_TARGET *sas_target_priv_data;
4946 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4947 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4950 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4951 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4954 /* check if this is end device */
4955 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4956 if (!(_scsih_is_end_device(device_info)))
4959 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4960 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4961 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4965 printk(MPT2SAS_ERR_FMT "device is not present "
4966 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
4967 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4971 if (unlikely(sas_device->handle != handle)) {
4972 starget = sas_device->starget;
4973 sas_target_priv_data = starget->hostdata;
4974 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
4975 " to (0x%04x)!!!\n", sas_device->handle, handle);
4976 sas_target_priv_data->handle = handle;
4977 sas_device->handle = handle;
4979 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4981 /* check if device is present */
4982 if (!(le16_to_cpu(sas_device_pg0.Flags) &
4983 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
4984 printk(MPT2SAS_ERR_FMT "device is not present "
4985 "handle(0x%04x), flags!!!\n", ioc->name, handle);
4989 /* check if there were any issues with discovery */
4990 if (_scsih_check_access_status(ioc, sas_address, handle,
4991 sas_device_pg0.AccessStatus))
4993 _scsih_ublock_io_device(ioc, handle);
4998 * _scsih_add_device - creating sas device object
4999 * @ioc: per adapter object
5000 * @handle: sas device handle
5001 * @phy_num: phy number end device attached to
5002 * @is_pd: is this hidden raid component
5004 * Creating end device object, stored in ioc->sas_device_list.
5006 * Returns 0 for success, non-zero for failure.
5009 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5011 Mpi2ConfigReply_t mpi_reply;
5012 Mpi2SasDevicePage0_t sas_device_pg0;
5013 Mpi2SasEnclosurePage0_t enclosure_pg0;
5014 struct _sas_device *sas_device;
5018 unsigned long flags;
5020 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5021 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5022 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5023 ioc->name, __FILE__, __LINE__, __func__);
5027 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5028 MPI2_IOCSTATUS_MASK;
5029 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5030 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5031 ioc->name, __FILE__, __LINE__, __func__);
5035 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5037 /* check if device is present */
5038 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5039 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5040 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5041 ioc->name, __FILE__, __LINE__, __func__);
5042 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5043 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5047 /* check if there were any issues with discovery */
5048 if (_scsih_check_access_status(ioc, sas_address, handle,
5049 sas_device_pg0.AccessStatus))
5052 /* check if this is end device */
5053 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5054 if (!(_scsih_is_end_device(device_info))) {
5055 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5056 ioc->name, __FILE__, __LINE__, __func__);
5061 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5062 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5064 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5069 sas_device = kzalloc(sizeof(struct _sas_device),
5072 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5073 ioc->name, __FILE__, __LINE__, __func__);
5077 sas_device->handle = handle;
5078 if (_scsih_get_sas_address(ioc, le16_to_cpu
5079 (sas_device_pg0.ParentDevHandle),
5080 &sas_device->sas_address_parent) != 0)
5081 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5082 ioc->name, __FILE__, __LINE__, __func__);
5083 sas_device->enclosure_handle =
5084 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5086 le16_to_cpu(sas_device_pg0.Slot);
5087 sas_device->device_info = device_info;
5088 sas_device->sas_address = sas_address;
5089 sas_device->phy = sas_device_pg0.PhyNum;
5091 /* get enclosure_logical_id */
5092 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5093 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5094 sas_device->enclosure_handle)))
5095 sas_device->enclosure_logical_id =
5096 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5098 /* get device name */
5099 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5101 if (ioc->wait_for_port_enable_to_complete)
5102 _scsih_sas_device_init_add(ioc, sas_device);
5104 _scsih_sas_device_add(ioc, sas_device);
5110 * _scsih_remove_device - removing sas device object
5111 * @ioc: per adapter object
5112 * @sas_device_delete: the sas_device object
5117 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5118 struct _sas_device *sas_device)
5120 struct _sas_device sas_device_backup;
5121 struct MPT2SAS_TARGET *sas_target_priv_data;
5126 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
5127 _scsih_sas_device_remove(ioc, sas_device);
5129 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5130 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5131 sas_device_backup.handle, (unsigned long long)
5132 sas_device_backup.sas_address));
5134 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5135 sas_target_priv_data = sas_device_backup.starget->hostdata;
5136 sas_target_priv_data->deleted = 1;
5139 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5141 if (!ioc->hide_drives)
5142 mpt2sas_transport_port_remove(ioc,
5143 sas_device_backup.sas_address,
5144 sas_device_backup.sas_address_parent);
5146 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5147 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5148 (unsigned long long) sas_device_backup.sas_address);
5150 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5151 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5152 sas_device_backup.handle, (unsigned long long)
5153 sas_device_backup.sas_address));
5157 * mpt2sas_device_remove - removing device object
5158 * @ioc: per adapter object
5159 * @sas_address: expander sas_address
5164 mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5166 struct _sas_device *sas_device;
5167 unsigned long flags;
5169 if (ioc->shost_recovery)
5172 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5173 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5176 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5179 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5180 _scsih_remove_device(ioc, sas_device);
5183 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5185 * _scsih_sas_topology_change_event_debug - debug for topology event
5186 * @ioc: per adapter object
5187 * @event_data: event data payload
5191 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5192 Mpi2EventDataSasTopologyChangeList_t *event_data)
5198 char *status_str = NULL;
5199 u8 link_rate, prev_link_rate;
5201 switch (event_data->ExpStatus) {
5202 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5205 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5206 status_str = "remove";
5208 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5210 status_str = "responding";
5212 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5213 status_str = "remove delay";
5216 status_str = "unknown status";
5219 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5220 ioc->name, status_str);
5221 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5222 "start_phy(%02d), count(%d)\n",
5223 le16_to_cpu(event_data->ExpanderDevHandle),
5224 le16_to_cpu(event_data->EnclosureHandle),
5225 event_data->StartPhyNum, event_data->NumEntries);
5226 for (i = 0; i < event_data->NumEntries; i++) {
5227 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5230 phy_number = event_data->StartPhyNum + i;
5231 reason_code = event_data->PHY[i].PhyStatus &
5232 MPI2_EVENT_SAS_TOPO_RC_MASK;
5233 switch (reason_code) {
5234 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5235 status_str = "target add";
5237 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5238 status_str = "target remove";
5240 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5241 status_str = "delay target remove";
5243 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5244 status_str = "link rate change";
5246 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5247 status_str = "target responding";
5250 status_str = "unknown";
5253 link_rate = event_data->PHY[i].LinkRate >> 4;
5254 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5255 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5256 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5257 handle, status_str, link_rate, prev_link_rate);
5264 * _scsih_sas_topology_change_event - handle topology changes
5265 * @ioc: per adapter object
5266 * @fw_event: The fw_event_work object
5271 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5272 struct fw_event_work *fw_event)
5275 u16 parent_handle, handle;
5277 u8 phy_number, max_phys;
5278 struct _sas_node *sas_expander;
5279 struct _sas_device *sas_device;
5281 unsigned long flags;
5282 u8 link_rate, prev_link_rate;
5283 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5285 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5286 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5287 _scsih_sas_topology_change_event_debug(ioc, event_data);
5290 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5293 if (!ioc->sas_hba.num_phys)
5294 _scsih_sas_host_add(ioc);
5296 _scsih_sas_host_refresh(ioc);
5298 if (fw_event->ignore) {
5299 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5300 "event\n", ioc->name));
5304 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5306 /* handle expander add */
5307 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5308 if (_scsih_expander_add(ioc, parent_handle) != 0)
5311 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5312 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5314 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5316 sas_address = sas_expander->sas_address;
5317 max_phys = sas_expander->num_phys;
5318 } else if (parent_handle < ioc->sas_hba.num_phys) {
5319 sas_address = ioc->sas_hba.sas_address;
5320 max_phys = ioc->sas_hba.num_phys;
5324 /* handle siblings events */
5325 for (i = 0; i < event_data->NumEntries; i++) {
5326 if (fw_event->ignore) {
5327 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5328 "expander event\n", ioc->name));
5331 if (ioc->shost_recovery || ioc->remove_host ||
5332 ioc->pci_error_recovery)
5334 phy_number = event_data->StartPhyNum + i;
5335 if (phy_number >= max_phys)
5337 reason_code = event_data->PHY[i].PhyStatus &
5338 MPI2_EVENT_SAS_TOPO_RC_MASK;
5339 if ((event_data->PHY[i].PhyStatus &
5340 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5341 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5343 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5346 link_rate = event_data->PHY[i].LinkRate >> 4;
5347 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5348 switch (reason_code) {
5349 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5351 if (link_rate == prev_link_rate)
5354 mpt2sas_transport_update_links(ioc, sas_address,
5355 handle, phy_number, link_rate);
5357 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5360 _scsih_check_device(ioc, handle);
5362 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5364 mpt2sas_transport_update_links(ioc, sas_address,
5365 handle, phy_number, link_rate);
5367 _scsih_add_device(ioc, handle, phy_number, 0);
5369 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5371 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5372 sas_device = _scsih_sas_device_find_by_handle(ioc,
5375 spin_unlock_irqrestore(&ioc->sas_device_lock,
5379 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5380 _scsih_remove_device(ioc, sas_device);
5385 /* handle expander removal */
5386 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5388 mpt2sas_expander_remove(ioc, sas_address);
5392 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5394 * _scsih_sas_device_status_change_event_debug - debug for device event
5395 * @event_data: event data payload
5401 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5402 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5404 char *reason_str = NULL;
5406 switch (event_data->ReasonCode) {
5407 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5408 reason_str = "smart data";
5410 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5411 reason_str = "unsupported device discovered";
5413 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5414 reason_str = "internal device reset";
5416 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5417 reason_str = "internal task abort";
5419 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5420 reason_str = "internal task abort set";
5422 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5423 reason_str = "internal clear task set";
5425 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5426 reason_str = "internal query task";
5428 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5429 reason_str = "sata init failure";
5431 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5432 reason_str = "internal device reset complete";
5434 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5435 reason_str = "internal task abort complete";
5437 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5438 reason_str = "internal async notification";
5440 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5441 reason_str = "expander reduced functionality";
5443 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5444 reason_str = "expander reduced functionality complete";
5447 reason_str = "unknown reason";
5450 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5451 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5452 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5453 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5454 le16_to_cpu(event_data->TaskTag));
5455 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5456 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5457 event_data->ASC, event_data->ASCQ);
5458 printk(KERN_INFO "\n");
5463 * _scsih_sas_device_status_change_event - handle device status change
5464 * @ioc: per adapter object
5465 * @fw_event: The fw_event_work object
5471 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5472 struct fw_event_work *fw_event)
5474 struct MPT2SAS_TARGET *target_priv_data;
5475 struct _sas_device *sas_device;
5477 unsigned long flags;
5478 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5479 fw_event->event_data;
5481 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5482 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5483 _scsih_sas_device_status_change_event_debug(ioc,
5487 /* In MPI Revision K (0xC), the internal device reset complete was
5488 * implemented, so avoid setting tm_busy flag for older firmware.
5490 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5493 if (event_data->ReasonCode !=
5494 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5495 event_data->ReasonCode !=
5496 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5499 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5500 sas_address = le64_to_cpu(event_data->SASAddress);
5501 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5503 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5505 if (!sas_device || !sas_device->starget)
5508 target_priv_data = sas_device->starget->hostdata;
5509 if (!target_priv_data)
5512 if (event_data->ReasonCode ==
5513 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5514 target_priv_data->tm_busy = 1;
5516 target_priv_data->tm_busy = 0;
5519 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5521 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5522 * @ioc: per adapter object
5523 * @event_data: event data payload
5529 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5530 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5532 char *reason_str = NULL;
5534 switch (event_data->ReasonCode) {
5535 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5536 reason_str = "enclosure add";
5538 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5539 reason_str = "enclosure remove";
5542 reason_str = "unknown reason";
5546 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5547 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5548 " number slots(%d)\n", ioc->name, reason_str,
5549 le16_to_cpu(event_data->EnclosureHandle),
5550 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5551 le16_to_cpu(event_data->StartSlot));
5556 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5557 * @ioc: per adapter object
5558 * @fw_event: The fw_event_work object
5564 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5565 struct fw_event_work *fw_event)
5567 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5568 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5569 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5570 fw_event->event_data);
5575 * _scsih_sas_broadcast_primative_event - handle broadcast events
5576 * @ioc: per adapter object
5577 * @fw_event: The fw_event_work object
5583 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5584 struct fw_event_work *fw_event)
5586 struct scsi_cmnd *scmd;
5587 struct scsi_device *sdev;
5590 struct MPT2SAS_DEVICE *sas_device_priv_data;
5591 u32 termination_count;
5593 Mpi2SCSITaskManagementReply_t *mpi_reply;
5594 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5596 unsigned long flags;
5599 u8 task_abort_retries;
5601 mutex_lock(&ioc->tm_cmds.mutex);
5602 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5603 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5604 event_data->PortWidth));
5606 _scsih_block_io_all_device(ioc);
5608 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5609 mpi_reply = ioc->tm_cmds.reply;
5610 broadcast_aen_retry:
5612 /* sanity checks for retrying this loop */
5613 if (max_retries++ == 5) {
5614 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5615 ioc->name, __func__));
5617 } else if (max_retries > 1)
5618 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5619 ioc->name, __func__, max_retries - 1));
5621 termination_count = 0;
5623 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5624 if (ioc->ioc_reset_in_progress_status)
5626 scmd = _scsih_scsi_lookup_get(ioc, smid);
5629 sdev = scmd->device;
5630 sas_device_priv_data = sdev->hostdata;
5631 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5633 /* skip hidden raid components */
5634 if (sas_device_priv_data->sas_target->flags &
5635 MPT_TARGET_FLAGS_RAID_COMPONENT)
5638 if (sas_device_priv_data->sas_target->flags &
5639 MPT_TARGET_FLAGS_VOLUME)
5642 handle = sas_device_priv_data->sas_target->handle;
5643 lun = sas_device_priv_data->lun;
5646 if (ioc->ioc_reset_in_progress_status)
5649 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5650 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5651 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5654 sdev_printk(KERN_WARNING, sdev,
5655 "mpt2sas_scsih_issue_tm: FAILED when sending "
5656 "QUERY_TASK: scmd(%p)\n", scmd);
5657 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5658 goto broadcast_aen_retry;
5660 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5661 & MPI2_IOCSTATUS_MASK;
5662 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5663 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5664 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5666 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5667 goto broadcast_aen_retry;
5670 /* see if IO is still owned by IOC and target */
5671 if (mpi_reply->ResponseCode ==
5672 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5673 mpi_reply->ResponseCode ==
5674 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5675 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5678 task_abort_retries = 0;
5680 if (task_abort_retries++ == 60) {
5681 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5682 "%s: ABORT_TASK: giving up\n", ioc->name,
5684 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5685 goto broadcast_aen_retry;
5688 if (ioc->ioc_reset_in_progress_status)
5691 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5692 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5693 scmd->serial_number, TM_MUTEX_OFF);
5695 sdev_printk(KERN_WARNING, sdev,
5696 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5697 "scmd(%p)\n", scmd);
5701 if (task_abort_retries > 1)
5702 sdev_printk(KERN_WARNING, sdev,
5703 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5705 task_abort_retries - 1, scmd);
5707 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5708 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5711 if (ioc->broadcast_aen_pending) {
5712 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5713 " pending AEN\n", ioc->name, __func__));
5714 ioc->broadcast_aen_pending = 0;
5715 goto broadcast_aen_retry;
5719 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5722 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5723 "%s - exit, query_count = %d termination_count = %d\n",
5724 ioc->name, __func__, query_count, termination_count));
5726 ioc->broadcast_aen_busy = 0;
5727 if (!ioc->ioc_reset_in_progress_status)
5728 _scsih_ublock_io_all_device(ioc);
5729 mutex_unlock(&ioc->tm_cmds.mutex);
5733 * _scsih_sas_discovery_event - handle discovery events
5734 * @ioc: per adapter object
5735 * @fw_event: The fw_event_work object
5741 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5742 struct fw_event_work *fw_event)
5744 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5746 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5747 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5748 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5749 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5751 if (event_data->DiscoveryStatus)
5752 printk("discovery_status(0x%08x)",
5753 le32_to_cpu(event_data->DiscoveryStatus));
5758 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5759 !ioc->sas_hba.num_phys)
5760 _scsih_sas_host_add(ioc);
5764 * _scsih_reprobe_lun - reprobing lun
5765 * @sdev: scsi device struct
5766 * @no_uld_attach: sdev->no_uld_attach flag setting
5770 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5774 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5775 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5776 sdev->no_uld_attach ? "hidding" : "exposing");
5777 rc = scsi_device_reprobe(sdev);
5781 * _scsih_reprobe_target - reprobing target
5782 * @starget: scsi target struct
5783 * @no_uld_attach: sdev->no_uld_attach flag setting
5785 * Note: no_uld_attach flag determines whether the disk device is attached
5786 * to block layer. A value of `1` means to not attach.
5789 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5791 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
5794 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5796 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5798 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5799 _scsih_reprobe_lun);
5802 * _scsih_sas_volume_add - add new volume
5803 * @ioc: per adapter object
5804 * @element: IR config element data
5810 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5811 Mpi2EventIrConfigElement_t *element)
5813 struct _raid_device *raid_device;
5814 unsigned long flags;
5816 u16 handle = le16_to_cpu(element->VolDevHandle);
5819 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5821 printk(MPT2SAS_ERR_FMT
5822 "failure at %s:%d/%s()!\n", ioc->name,
5823 __FILE__, __LINE__, __func__);
5827 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5828 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5829 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5834 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5836 printk(MPT2SAS_ERR_FMT
5837 "failure at %s:%d/%s()!\n", ioc->name,
5838 __FILE__, __LINE__, __func__);
5842 raid_device->id = ioc->sas_id++;
5843 raid_device->channel = RAID_CHANNEL;
5844 raid_device->handle = handle;
5845 raid_device->wwid = wwid;
5846 _scsih_raid_device_add(ioc, raid_device);
5847 if (!ioc->wait_for_port_enable_to_complete) {
5848 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5849 raid_device->id, 0);
5851 _scsih_raid_device_remove(ioc, raid_device);
5853 _scsih_determine_boot_device(ioc, raid_device, 1);
5857 * _scsih_sas_volume_delete - delete volume
5858 * @ioc: per adapter object
5859 * @handle: volume device handle
5865 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5867 struct _raid_device *raid_device;
5868 unsigned long flags;
5869 struct MPT2SAS_TARGET *sas_target_priv_data;
5871 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5872 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5873 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5876 if (raid_device->starget) {
5877 sas_target_priv_data = raid_device->starget->hostdata;
5878 sas_target_priv_data->deleted = 1;
5879 scsi_remove_target(&raid_device->starget->dev);
5881 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
5882 "(0x%016llx)\n", ioc->name, raid_device->handle,
5883 (unsigned long long) raid_device->wwid);
5884 _scsih_raid_device_remove(ioc, raid_device);
5888 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5889 * @ioc: per adapter object
5890 * @element: IR config element data
5896 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
5897 Mpi2EventIrConfigElement_t *element)
5899 struct _sas_device *sas_device;
5900 unsigned long flags;
5901 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5903 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5904 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5905 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5909 /* exposing raid component */
5910 sas_device->volume_handle = 0;
5911 sas_device->volume_wwid = 0;
5912 clear_bit(handle, ioc->pd_handles);
5913 _scsih_reprobe_target(sas_device->starget, 0);
5917 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5918 * @ioc: per adapter object
5919 * @element: IR config element data
5925 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
5926 Mpi2EventIrConfigElement_t *element)
5928 struct _sas_device *sas_device;
5929 unsigned long flags;
5930 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5932 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5933 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5934 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5938 /* hiding raid component */
5939 mpt2sas_config_get_volume_handle(ioc, handle,
5940 &sas_device->volume_handle);
5941 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
5942 &sas_device->volume_wwid);
5943 set_bit(handle, ioc->pd_handles);
5944 _scsih_reprobe_target(sas_device->starget, 1);
5949 * _scsih_sas_pd_delete - delete pd component
5950 * @ioc: per adapter object
5951 * @element: IR config element data
5957 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
5958 Mpi2EventIrConfigElement_t *element)
5960 struct _sas_device *sas_device;
5961 unsigned long flags;
5962 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5964 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5965 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5966 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5969 _scsih_remove_device(ioc, sas_device);
5973 * _scsih_sas_pd_add - remove pd component
5974 * @ioc: per adapter object
5975 * @element: IR config element data
5981 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
5982 Mpi2EventIrConfigElement_t *element)
5984 struct _sas_device *sas_device;
5985 unsigned long flags;
5986 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5987 Mpi2ConfigReply_t mpi_reply;
5988 Mpi2SasDevicePage0_t sas_device_pg0;
5993 set_bit(handle, ioc->pd_handles);
5995 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5996 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5997 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6001 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6002 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6003 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6004 ioc->name, __FILE__, __LINE__, __func__);
6008 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6009 MPI2_IOCSTATUS_MASK;
6010 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6011 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6012 ioc->name, __FILE__, __LINE__, __func__);
6016 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6017 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6018 mpt2sas_transport_update_links(ioc, sas_address, handle,
6019 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6021 _scsih_add_device(ioc, handle, 0, 1);
6024 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6026 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6027 * @ioc: per adapter object
6028 * @event_data: event data payload
6034 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6035 Mpi2EventDataIrConfigChangeList_t *event_data)
6037 Mpi2EventIrConfigElement_t *element;
6040 char *reason_str = NULL, *element_str = NULL;
6042 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6044 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6045 ioc->name, (le32_to_cpu(event_data->Flags) &
6046 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6047 "foreign" : "native", event_data->NumElements);
6048 for (i = 0; i < event_data->NumElements; i++, element++) {
6049 switch (element->ReasonCode) {
6050 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6053 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6054 reason_str = "remove";
6056 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6057 reason_str = "no change";
6059 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6060 reason_str = "hide";
6062 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6063 reason_str = "unhide";
6065 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6066 reason_str = "volume_created";
6068 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6069 reason_str = "volume_deleted";
6071 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6072 reason_str = "pd_created";
6074 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6075 reason_str = "pd_deleted";
6078 reason_str = "unknown reason";
6081 element_type = le16_to_cpu(element->ElementFlags) &
6082 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6083 switch (element_type) {
6084 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6085 element_str = "volume";
6087 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6088 element_str = "phys disk";
6090 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6091 element_str = "hot spare";
6094 element_str = "unknown element";
6097 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6098 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6099 reason_str, le16_to_cpu(element->VolDevHandle),
6100 le16_to_cpu(element->PhysDiskDevHandle),
6101 element->PhysDiskNum);
6107 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6108 * @ioc: per adapter object
6109 * @fw_event: The fw_event_work object
6115 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6116 struct fw_event_work *fw_event)
6118 Mpi2EventIrConfigElement_t *element;
6121 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6123 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6124 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6125 && !ioc->hide_ir_msg)
6126 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6129 foreign_config = (le32_to_cpu(event_data->Flags) &
6130 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6132 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6133 for (i = 0; i < event_data->NumElements; i++, element++) {
6135 switch (element->ReasonCode) {
6136 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6137 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6138 if (!foreign_config)
6139 _scsih_sas_volume_add(ioc, element);
6141 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6142 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6143 if (!foreign_config)
6144 _scsih_sas_volume_delete(ioc,
6145 le16_to_cpu(element->VolDevHandle));
6147 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6148 if (!ioc->is_warpdrive)
6149 _scsih_sas_pd_hide(ioc, element);
6151 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6152 if (!ioc->is_warpdrive)
6153 _scsih_sas_pd_expose(ioc, element);
6155 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6156 if (!ioc->is_warpdrive)
6157 _scsih_sas_pd_add(ioc, element);
6159 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6160 if (!ioc->is_warpdrive)
6161 _scsih_sas_pd_delete(ioc, element);
6168 * _scsih_sas_ir_volume_event - IR volume event
6169 * @ioc: per adapter object
6170 * @fw_event: The fw_event_work object
6176 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6177 struct fw_event_work *fw_event)
6180 unsigned long flags;
6181 struct _raid_device *raid_device;
6185 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6187 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6190 handle = le16_to_cpu(event_data->VolDevHandle);
6191 state = le32_to_cpu(event_data->NewValue);
6192 if (!ioc->hide_ir_msg)
6193 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6194 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6195 le32_to_cpu(event_data->PreviousValue), state));
6198 case MPI2_RAID_VOL_STATE_MISSING:
6199 case MPI2_RAID_VOL_STATE_FAILED:
6200 _scsih_sas_volume_delete(ioc, handle);
6203 case MPI2_RAID_VOL_STATE_ONLINE:
6204 case MPI2_RAID_VOL_STATE_DEGRADED:
6205 case MPI2_RAID_VOL_STATE_OPTIMAL:
6207 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6208 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6209 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6214 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6216 printk(MPT2SAS_ERR_FMT
6217 "failure at %s:%d/%s()!\n", ioc->name,
6218 __FILE__, __LINE__, __func__);
6222 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6224 printk(MPT2SAS_ERR_FMT
6225 "failure at %s:%d/%s()!\n", ioc->name,
6226 __FILE__, __LINE__, __func__);
6230 raid_device->id = ioc->sas_id++;
6231 raid_device->channel = RAID_CHANNEL;
6232 raid_device->handle = handle;
6233 raid_device->wwid = wwid;
6234 _scsih_raid_device_add(ioc, raid_device);
6235 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6236 raid_device->id, 0);
6238 _scsih_raid_device_remove(ioc, raid_device);
6241 case MPI2_RAID_VOL_STATE_INITIALIZING:
6248 * _scsih_sas_ir_physical_disk_event - PD event
6249 * @ioc: per adapter object
6250 * @fw_event: The fw_event_work object
6256 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6257 struct fw_event_work *fw_event)
6259 u16 handle, parent_handle;
6261 struct _sas_device *sas_device;
6262 unsigned long flags;
6263 Mpi2ConfigReply_t mpi_reply;
6264 Mpi2SasDevicePage0_t sas_device_pg0;
6266 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6269 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6272 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6273 state = le32_to_cpu(event_data->NewValue);
6275 if (!ioc->hide_ir_msg)
6276 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6277 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6278 le32_to_cpu(event_data->PreviousValue), state));
6281 case MPI2_RAID_PD_STATE_ONLINE:
6282 case MPI2_RAID_PD_STATE_DEGRADED:
6283 case MPI2_RAID_PD_STATE_REBUILDING:
6284 case MPI2_RAID_PD_STATE_OPTIMAL:
6285 case MPI2_RAID_PD_STATE_HOT_SPARE:
6287 if (!ioc->is_warpdrive)
6288 set_bit(handle, ioc->pd_handles);
6290 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6291 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6292 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6297 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6298 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6300 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6301 ioc->name, __FILE__, __LINE__, __func__);
6305 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6306 MPI2_IOCSTATUS_MASK;
6307 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6308 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6309 ioc->name, __FILE__, __LINE__, __func__);
6313 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6314 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6315 mpt2sas_transport_update_links(ioc, sas_address, handle,
6316 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6318 _scsih_add_device(ioc, handle, 0, 1);
6322 case MPI2_RAID_PD_STATE_OFFLINE:
6323 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6324 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6330 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6332 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6333 * @ioc: per adapter object
6334 * @event_data: event data payload
6340 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6341 Mpi2EventDataIrOperationStatus_t *event_data)
6343 char *reason_str = NULL;
6345 switch (event_data->RAIDOperation) {
6346 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6347 reason_str = "resync";
6349 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6350 reason_str = "online capacity expansion";
6352 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6353 reason_str = "consistency check";
6355 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6356 reason_str = "background init";
6358 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6359 reason_str = "make data consistent";
6366 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6367 "\thandle(0x%04x), percent complete(%d)\n",
6368 ioc->name, reason_str,
6369 le16_to_cpu(event_data->VolDevHandle),
6370 event_data->PercentComplete);
6375 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6376 * @ioc: per adapter object
6377 * @fw_event: The fw_event_work object
6383 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6384 struct fw_event_work *fw_event)
6386 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6387 static struct _raid_device *raid_device;
6388 unsigned long flags;
6391 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6392 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6393 && !ioc->hide_ir_msg)
6394 _scsih_sas_ir_operation_status_event_debug(ioc,
6398 /* code added for raid transport support */
6399 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6401 handle = le16_to_cpu(event_data->VolDevHandle);
6403 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6404 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6405 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6410 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6411 raid_device->percent_complete =
6412 event_data->PercentComplete;
6417 * _scsih_prep_device_scan - initialize parameters prior to device scan
6418 * @ioc: per adapter object
6420 * Set the deleted flag prior to device scan. If the device is found during
6421 * the scan, then we clear the deleted flag.
6424 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6426 struct MPT2SAS_DEVICE *sas_device_priv_data;
6427 struct scsi_device *sdev;
6429 shost_for_each_device(sdev, ioc->shost) {
6430 sas_device_priv_data = sdev->hostdata;
6431 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6432 sas_device_priv_data->sas_target->deleted = 1;
6437 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6438 * @ioc: per adapter object
6439 * @sas_address: sas address
6440 * @slot: enclosure slot id
6441 * @handle: device handle
6443 * After host reset, find out whether devices are still responding.
6444 * Used in _scsi_remove_unresponsive_sas_devices.
6449 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6450 u16 slot, u16 handle)
6452 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6453 struct scsi_target *starget;
6454 struct _sas_device *sas_device;
6455 unsigned long flags;
6457 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6458 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6459 if (sas_device->sas_address == sas_address &&
6460 sas_device->slot == slot) {
6461 sas_device->responding = 1;
6462 starget = sas_device->starget;
6463 if (starget && starget->hostdata) {
6464 sas_target_priv_data = starget->hostdata;
6465 sas_target_priv_data->tm_busy = 0;
6466 sas_target_priv_data->deleted = 0;
6468 sas_target_priv_data = NULL;
6470 starget_printk(KERN_INFO, starget,
6471 "handle(0x%04x), sas_addr(0x%016llx), "
6472 "enclosure logical id(0x%016llx), "
6473 "slot(%d)\n", handle,
6474 (unsigned long long)sas_device->sas_address,
6475 (unsigned long long)
6476 sas_device->enclosure_logical_id,
6478 if (sas_device->handle == handle)
6480 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6481 sas_device->handle);
6482 sas_device->handle = handle;
6483 if (sas_target_priv_data)
6484 sas_target_priv_data->handle = handle;
6489 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6493 * _scsih_search_responding_sas_devices -
6494 * @ioc: per adapter object
6496 * After host reset, find out whether devices are still responding.
6502 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6504 Mpi2SasDevicePage0_t sas_device_pg0;
6505 Mpi2ConfigReply_t mpi_reply;
6512 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
6514 if (list_empty(&ioc->sas_device_list))
6518 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6519 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6521 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6522 MPI2_IOCSTATUS_MASK;
6523 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6525 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6526 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6527 if (!(_scsih_is_end_device(device_info)))
6529 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6530 slot = le16_to_cpu(sas_device_pg0.Slot);
6531 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6537 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6538 * @ioc: per adapter object
6539 * @wwid: world wide identifier for raid volume
6540 * @handle: device handle
6542 * After host reset, find out whether devices are still responding.
6543 * Used in _scsi_remove_unresponsive_raid_devices.
6548 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6551 struct MPT2SAS_TARGET *sas_target_priv_data;
6552 struct scsi_target *starget;
6553 struct _raid_device *raid_device;
6554 unsigned long flags;
6556 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6557 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6558 if (raid_device->wwid == wwid && raid_device->starget) {
6559 starget = raid_device->starget;
6560 if (starget && starget->hostdata) {
6561 sas_target_priv_data = starget->hostdata;
6562 sas_target_priv_data->deleted = 0;
6564 sas_target_priv_data = NULL;
6565 raid_device->responding = 1;
6566 starget_printk(KERN_INFO, raid_device->starget,
6567 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6568 (unsigned long long)raid_device->wwid);
6570 * WARPDRIVE: The handles of the PDs might have changed
6571 * across the host reset so re-initialize the
6572 * required data for Direct IO
6574 _scsih_init_warpdrive_properties(ioc, raid_device);
6575 if (raid_device->handle == handle)
6577 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6578 raid_device->handle);
6579 raid_device->handle = handle;
6580 if (sas_target_priv_data)
6581 sas_target_priv_data->handle = handle;
6586 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6590 * _scsih_search_responding_raid_devices -
6591 * @ioc: per adapter object
6593 * After host reset, find out whether devices are still responding.
6599 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6601 Mpi2RaidVolPage1_t volume_pg1;
6602 Mpi2RaidVolPage0_t volume_pg0;
6603 Mpi2RaidPhysDiskPage0_t pd_pg0;
6604 Mpi2ConfigReply_t mpi_reply;
6609 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
6611 if (list_empty(&ioc->raid_device_list))
6615 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6616 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6617 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6618 MPI2_IOCSTATUS_MASK;
6619 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6621 handle = le16_to_cpu(volume_pg1.DevHandle);
6623 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6624 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6625 sizeof(Mpi2RaidVolPage0_t)))
6628 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6629 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6630 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6631 _scsih_mark_responding_raid_device(ioc,
6632 le64_to_cpu(volume_pg1.WWID), handle);
6635 /* refresh the pd_handles */
6636 if (!ioc->is_warpdrive) {
6637 phys_disk_num = 0xFF;
6638 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6639 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6640 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6642 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6643 MPI2_IOCSTATUS_MASK;
6644 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6646 phys_disk_num = pd_pg0.PhysDiskNum;
6647 handle = le16_to_cpu(pd_pg0.DevHandle);
6648 set_bit(handle, ioc->pd_handles);
6654 * _scsih_mark_responding_expander - mark a expander as responding
6655 * @ioc: per adapter object
6656 * @sas_address: sas address
6659 * After host reset, find out whether devices are still responding.
6660 * Used in _scsi_remove_unresponsive_expanders.
6665 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6668 struct _sas_node *sas_expander;
6669 unsigned long flags;
6672 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6673 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6674 if (sas_expander->sas_address != sas_address)
6676 sas_expander->responding = 1;
6677 if (sas_expander->handle == handle)
6679 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6680 " from(0x%04x) to (0x%04x)!!!\n",
6681 (unsigned long long)sas_expander->sas_address,
6682 sas_expander->handle, handle);
6683 sas_expander->handle = handle;
6684 for (i = 0 ; i < sas_expander->num_phys ; i++)
6685 sas_expander->phy[i].handle = handle;
6689 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6693 * _scsih_search_responding_expanders -
6694 * @ioc: per adapter object
6696 * After host reset, find out whether devices are still responding.
6702 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6704 Mpi2ExpanderPage0_t expander_pg0;
6705 Mpi2ConfigReply_t mpi_reply;
6710 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
6712 if (list_empty(&ioc->sas_expander_list))
6716 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6717 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6719 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6720 MPI2_IOCSTATUS_MASK;
6721 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6724 handle = le16_to_cpu(expander_pg0.DevHandle);
6725 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6726 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6727 "sas_addr(0x%016llx)\n", handle,
6728 (unsigned long long)sas_address);
6729 _scsih_mark_responding_expander(ioc, sas_address, handle);
6735 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6736 * @ioc: per adapter object
6741 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6743 struct _sas_device *sas_device, *sas_device_next;
6744 struct _sas_node *sas_expander;
6745 struct _raid_device *raid_device, *raid_device_next;
6748 list_for_each_entry_safe(sas_device, sas_device_next,
6749 &ioc->sas_device_list, list) {
6750 if (sas_device->responding) {
6751 sas_device->responding = 0;
6754 if (sas_device->starget)
6755 starget_printk(KERN_INFO, sas_device->starget,
6756 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6757 "enclosure logical id(0x%016llx), slot(%d)\n",
6759 (unsigned long long)sas_device->sas_address,
6760 (unsigned long long)
6761 sas_device->enclosure_logical_id,
6763 _scsih_remove_device(ioc, sas_device);
6766 list_for_each_entry_safe(raid_device, raid_device_next,
6767 &ioc->raid_device_list, list) {
6768 if (raid_device->responding) {
6769 raid_device->responding = 0;
6772 if (raid_device->starget) {
6773 starget_printk(KERN_INFO, raid_device->starget,
6774 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6775 raid_device->handle,
6776 (unsigned long long)raid_device->wwid);
6777 scsi_remove_target(&raid_device->starget->dev);
6779 _scsih_raid_device_remove(ioc, raid_device);
6782 retry_expander_search:
6783 sas_expander = NULL;
6784 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6785 if (sas_expander->responding) {
6786 sas_expander->responding = 0;
6789 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6790 goto retry_expander_search;
6795 * _scsih_hide_unhide_sas_devices - add/remove device to/from OS
6796 * @ioc: per adapter object
6801 _scsih_hide_unhide_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6803 struct _sas_device *sas_device, *sas_device_next;
6805 if (!ioc->is_warpdrive || ioc->mfg_pg10_hide_flag !=
6806 MFG_PAGE10_HIDE_IF_VOL_PRESENT)
6809 if (ioc->hide_drives) {
6810 if (_scsih_get_num_volumes(ioc))
6812 ioc->hide_drives = 0;
6813 list_for_each_entry_safe(sas_device, sas_device_next,
6814 &ioc->sas_device_list, list) {
6815 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
6816 sas_device->sas_address_parent)) {
6817 _scsih_sas_device_remove(ioc, sas_device);
6818 } else if (!sas_device->starget) {
6819 mpt2sas_transport_port_remove(ioc,
6820 sas_device->sas_address,
6821 sas_device->sas_address_parent);
6822 _scsih_sas_device_remove(ioc, sas_device);
6826 if (!_scsih_get_num_volumes(ioc))
6828 ioc->hide_drives = 1;
6829 list_for_each_entry_safe(sas_device, sas_device_next,
6830 &ioc->sas_device_list, list) {
6831 mpt2sas_transport_port_remove(ioc,
6832 sas_device->sas_address,
6833 sas_device->sas_address_parent);
6839 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6840 * @ioc: per adapter object
6841 * @reset_phase: phase
6843 * The handler for doing any required cleanup or initialization.
6845 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
6846 * MPT2_IOC_DONE_RESET
6851 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
6853 switch (reset_phase) {
6854 case MPT2_IOC_PRE_RESET:
6855 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
6856 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
6858 case MPT2_IOC_AFTER_RESET:
6859 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
6860 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
6861 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
6862 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
6863 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
6864 complete(&ioc->scsih_cmds.done);
6866 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
6867 ioc->tm_cmds.status |= MPT2_CMD_RESET;
6868 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
6869 complete(&ioc->tm_cmds.done);
6871 _scsih_fw_event_cleanup_queue(ioc);
6872 _scsih_flush_running_cmds(ioc);
6873 _scsih_queue_rescan(ioc);
6875 case MPT2_IOC_DONE_RESET:
6876 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
6877 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
6878 _scsih_sas_host_refresh(ioc);
6879 _scsih_prep_device_scan(ioc);
6880 _scsih_search_responding_sas_devices(ioc);
6881 _scsih_search_responding_raid_devices(ioc);
6882 _scsih_search_responding_expanders(ioc);
6888 * _firmware_event_work - delayed task for processing firmware events
6889 * @ioc: per adapter object
6890 * @work: equal to the fw_event_work object
6896 _firmware_event_work(struct work_struct *work)
6898 struct fw_event_work *fw_event = container_of(work,
6899 struct fw_event_work, delayed_work.work);
6900 unsigned long flags;
6901 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
6903 /* the queue is being flushed so ignore this event */
6904 if (ioc->remove_host || fw_event->cancel_pending_work ||
6905 ioc->pci_error_recovery) {
6906 _scsih_fw_event_free(ioc, fw_event);
6910 if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) {
6911 _scsih_fw_event_free(ioc, fw_event);
6912 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
6913 if (ioc->shost_recovery) {
6914 init_completion(&ioc->shost_recovery_done);
6915 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
6917 wait_for_completion(&ioc->shost_recovery_done);
6919 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
6921 _scsih_remove_unresponding_sas_devices(ioc);
6922 _scsih_hide_unhide_sas_devices(ioc);
6926 switch (fw_event->event) {
6927 case MPT2SAS_TURN_ON_FAULT_LED:
6928 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
6930 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
6931 _scsih_sas_topology_change_event(ioc, fw_event);
6933 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
6934 _scsih_sas_device_status_change_event(ioc,
6937 case MPI2_EVENT_SAS_DISCOVERY:
6938 _scsih_sas_discovery_event(ioc,
6941 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
6942 _scsih_sas_broadcast_primative_event(ioc,
6945 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
6946 _scsih_sas_enclosure_dev_status_change_event(ioc,
6949 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
6950 _scsih_sas_ir_config_change_event(ioc, fw_event);
6952 case MPI2_EVENT_IR_VOLUME:
6953 _scsih_sas_ir_volume_event(ioc, fw_event);
6955 case MPI2_EVENT_IR_PHYSICAL_DISK:
6956 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
6958 case MPI2_EVENT_IR_OPERATION_STATUS:
6959 _scsih_sas_ir_operation_status_event(ioc, fw_event);
6962 _scsih_fw_event_free(ioc, fw_event);
6966 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
6967 * @ioc: per adapter object
6968 * @msix_index: MSIX table index supplied by the OS
6969 * @reply: reply message frame(lower 32bit addr)
6970 * Context: interrupt.
6972 * This function merely adds a new work task into ioc->firmware_event_thread.
6973 * The tasks are worked from _firmware_event_work in user context.
6975 * Return 1 meaning mf should be freed from _base_interrupt
6976 * 0 means the mf is freed from this function.
6979 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
6982 struct fw_event_work *fw_event;
6983 Mpi2EventNotificationReply_t *mpi_reply;
6987 /* events turned off due to host reset or driver unloading */
6988 if (ioc->remove_host || ioc->pci_error_recovery)
6991 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
6992 event = le16_to_cpu(mpi_reply->Event);
6996 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
6998 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
6999 (Mpi2EventDataSasBroadcastPrimitive_t *)
7000 mpi_reply->EventData;
7002 if (baen_data->Primitive !=
7003 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7006 if (ioc->broadcast_aen_busy) {
7007 ioc->broadcast_aen_pending++;
7010 ioc->broadcast_aen_busy = 1;
7014 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7015 _scsih_check_topo_delete_events(ioc,
7016 (Mpi2EventDataSasTopologyChangeList_t *)
7017 mpi_reply->EventData);
7019 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7020 _scsih_check_ir_config_unhide_events(ioc,
7021 (Mpi2EventDataIrConfigChangeList_t *)
7022 mpi_reply->EventData);
7024 case MPI2_EVENT_IR_VOLUME:
7025 _scsih_check_volume_delete_events(ioc,
7026 (Mpi2EventDataIrVolume_t *)
7027 mpi_reply->EventData);
7029 case MPI2_EVENT_LOG_ENTRY_ADDED:
7031 Mpi2EventDataLogEntryAdded_t *log_entry;
7034 if (!ioc->is_warpdrive)
7037 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7038 mpi_reply->EventData;
7039 log_code = (u32 *)log_entry->LogData;
7041 if (le16_to_cpu(log_entry->LogEntryQualifier)
7042 != MPT2_WARPDRIVE_LOGENTRY)
7045 switch (le32_to_cpu(*log_code)) {
7046 case MPT2_WARPDRIVE_LC_SSDT:
7047 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7048 "IO Throttling has occurred in the WarpDrive "
7049 "subsystem. Check WarpDrive documentation for "
7050 "additional details.\n", ioc->name);
7052 case MPT2_WARPDRIVE_LC_SSDLW:
7053 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7054 "Program/Erase Cycles for the WarpDrive subsystem "
7055 "in degraded range. Check WarpDrive documentation "
7056 "for additional details.\n", ioc->name);
7058 case MPT2_WARPDRIVE_LC_SSDLF:
7059 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7060 "There are no Program/Erase Cycles for the "
7061 "WarpDrive subsystem. The storage device will be "
7062 "in read-only mode. Check WarpDrive documentation "
7063 "for additional details.\n", ioc->name);
7065 case MPT2_WARPDRIVE_LC_BRMF:
7066 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7067 "The Backup Rail Monitor has failed on the "
7068 "WarpDrive subsystem. Check WarpDrive "
7069 "documentation for additional details.\n",
7076 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7077 case MPI2_EVENT_IR_OPERATION_STATUS:
7078 case MPI2_EVENT_SAS_DISCOVERY:
7079 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7080 case MPI2_EVENT_IR_PHYSICAL_DISK:
7083 default: /* ignore the rest */
7087 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7089 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7090 ioc->name, __FILE__, __LINE__, __func__);
7093 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7094 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7095 if (!fw_event->event_data) {
7096 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7097 ioc->name, __FILE__, __LINE__, __func__);
7102 memcpy(fw_event->event_data, mpi_reply->EventData,
7104 fw_event->ioc = ioc;
7105 fw_event->VF_ID = mpi_reply->VF_ID;
7106 fw_event->VP_ID = mpi_reply->VP_ID;
7107 fw_event->event = event;
7108 _scsih_fw_event_add(ioc, fw_event);
7112 /* shost template */
7113 static struct scsi_host_template scsih_driver_template = {
7114 .module = THIS_MODULE,
7115 .name = "Fusion MPT SAS Host",
7116 .proc_name = MPT2SAS_DRIVER_NAME,
7117 .queuecommand = _scsih_qcmd,
7118 .target_alloc = _scsih_target_alloc,
7119 .slave_alloc = _scsih_slave_alloc,
7120 .slave_configure = _scsih_slave_configure,
7121 .target_destroy = _scsih_target_destroy,
7122 .slave_destroy = _scsih_slave_destroy,
7123 .change_queue_depth = _scsih_change_queue_depth,
7124 .change_queue_type = _scsih_change_queue_type,
7125 .eh_abort_handler = _scsih_abort,
7126 .eh_device_reset_handler = _scsih_dev_reset,
7127 .eh_target_reset_handler = _scsih_target_reset,
7128 .eh_host_reset_handler = _scsih_host_reset,
7129 .bios_param = _scsih_bios_param,
7132 .sg_tablesize = MPT2SAS_SG_DEPTH,
7133 .max_sectors = 8192,
7135 .use_clustering = ENABLE_CLUSTERING,
7136 .shost_attrs = mpt2sas_host_attrs,
7137 .sdev_attrs = mpt2sas_dev_attrs,
7141 * _scsih_expander_node_remove - removing expander device from list.
7142 * @ioc: per adapter object
7143 * @sas_expander: the sas_device object
7144 * Context: Calling function should acquire ioc->sas_node_lock.
7146 * Removing object and freeing associated memory from the
7147 * ioc->sas_expander_list.
7152 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7153 struct _sas_node *sas_expander)
7155 struct _sas_port *mpt2sas_port, *next;
7157 /* remove sibling ports attached to this expander */
7158 list_for_each_entry_safe(mpt2sas_port, next,
7159 &sas_expander->sas_port_list, port_list) {
7160 if (ioc->shost_recovery)
7162 if (mpt2sas_port->remote_identify.device_type ==
7164 mpt2sas_device_remove(ioc,
7165 mpt2sas_port->remote_identify.sas_address);
7166 else if (mpt2sas_port->remote_identify.device_type ==
7167 SAS_EDGE_EXPANDER_DEVICE ||
7168 mpt2sas_port->remote_identify.device_type ==
7169 SAS_FANOUT_EXPANDER_DEVICE)
7170 mpt2sas_expander_remove(ioc,
7171 mpt2sas_port->remote_identify.sas_address);
7174 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7175 sas_expander->sas_address_parent);
7177 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7178 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7179 sas_expander->handle, (unsigned long long)
7180 sas_expander->sas_address);
7182 kfree(sas_expander->phy);
7183 kfree(sas_expander);
7187 * _scsih_ir_shutdown - IR shutdown notification
7188 * @ioc: per adapter object
7190 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7191 * the host system is shutting down.
7196 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7198 Mpi2RaidActionRequest_t *mpi_request;
7199 Mpi2RaidActionReply_t *mpi_reply;
7202 /* is IR firmware build loaded ? */
7203 if (!ioc->ir_firmware)
7206 /* are there any volumes ? */
7207 if (list_empty(&ioc->raid_device_list))
7210 mutex_lock(&ioc->scsih_cmds.mutex);
7212 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7213 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7214 ioc->name, __func__);
7217 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7219 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7221 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7222 ioc->name, __func__);
7223 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7227 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7228 ioc->scsih_cmds.smid = smid;
7229 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7231 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7232 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7234 if (!ioc->hide_ir_msg)
7235 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7236 init_completion(&ioc->scsih_cmds.done);
7237 mpt2sas_base_put_smid_default(ioc, smid);
7238 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7240 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7241 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7242 ioc->name, __func__);
7246 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7247 mpi_reply = ioc->scsih_cmds.reply;
7249 if (!ioc->hide_ir_msg)
7250 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7251 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7252 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7253 le32_to_cpu(mpi_reply->IOCLogInfo));
7257 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7258 mutex_unlock(&ioc->scsih_cmds.mutex);
7262 * _scsih_shutdown - routine call during system shutdown
7263 * @pdev: PCI device struct
7268 _scsih_shutdown(struct pci_dev *pdev)
7270 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7271 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7272 struct workqueue_struct *wq;
7273 unsigned long flags;
7275 ioc->remove_host = 1;
7276 _scsih_fw_event_cleanup_queue(ioc);
7278 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7279 wq = ioc->firmware_event_thread;
7280 ioc->firmware_event_thread = NULL;
7281 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7283 destroy_workqueue(wq);
7285 _scsih_ir_shutdown(ioc);
7286 mpt2sas_base_detach(ioc);
7290 * _scsih_remove - detach and remove add host
7291 * @pdev: PCI device struct
7293 * Routine called when unloading the driver.
7296 static void __devexit
7297 _scsih_remove(struct pci_dev *pdev)
7299 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7300 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7301 struct _sas_port *mpt2sas_port, *next_port;
7302 struct _raid_device *raid_device, *next;
7303 struct MPT2SAS_TARGET *sas_target_priv_data;
7304 struct workqueue_struct *wq;
7305 unsigned long flags;
7307 ioc->remove_host = 1;
7308 _scsih_fw_event_cleanup_queue(ioc);
7310 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7311 wq = ioc->firmware_event_thread;
7312 ioc->firmware_event_thread = NULL;
7313 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7315 destroy_workqueue(wq);
7317 /* release all the volumes */
7318 _scsih_ir_shutdown(ioc);
7319 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7321 if (raid_device->starget) {
7322 sas_target_priv_data =
7323 raid_device->starget->hostdata;
7324 sas_target_priv_data->deleted = 1;
7325 scsi_remove_target(&raid_device->starget->dev);
7327 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7328 "(0x%016llx)\n", ioc->name, raid_device->handle,
7329 (unsigned long long) raid_device->wwid);
7330 _scsih_raid_device_remove(ioc, raid_device);
7333 /* free ports attached to the sas_host */
7334 list_for_each_entry_safe(mpt2sas_port, next_port,
7335 &ioc->sas_hba.sas_port_list, port_list) {
7336 if (mpt2sas_port->remote_identify.device_type ==
7338 mpt2sas_device_remove(ioc,
7339 mpt2sas_port->remote_identify.sas_address);
7340 else if (mpt2sas_port->remote_identify.device_type ==
7341 SAS_EDGE_EXPANDER_DEVICE ||
7342 mpt2sas_port->remote_identify.device_type ==
7343 SAS_FANOUT_EXPANDER_DEVICE)
7344 mpt2sas_expander_remove(ioc,
7345 mpt2sas_port->remote_identify.sas_address);
7348 /* free phys attached to the sas_host */
7349 if (ioc->sas_hba.num_phys) {
7350 kfree(ioc->sas_hba.phy);
7351 ioc->sas_hba.phy = NULL;
7352 ioc->sas_hba.num_phys = 0;
7355 sas_remove_host(shost);
7356 list_del(&ioc->list);
7357 scsi_remove_host(shost);
7358 scsi_host_put(shost);
7362 * _scsih_probe_boot_devices - reports 1st device
7363 * @ioc: per adapter object
7365 * If specified in bios page 2, this routine reports the 1st
7366 * device scsi-ml or sas transport for persistent boot device
7367 * purposes. Please refer to function _scsih_determine_boot_device()
7370 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7374 struct _sas_device *sas_device;
7375 struct _raid_device *raid_device;
7377 u64 sas_address_parent;
7379 unsigned long flags;
7383 if (ioc->req_boot_device.device) {
7384 device = ioc->req_boot_device.device;
7385 is_raid = ioc->req_boot_device.is_raid;
7386 } else if (ioc->req_alt_boot_device.device) {
7387 device = ioc->req_alt_boot_device.device;
7388 is_raid = ioc->req_alt_boot_device.is_raid;
7389 } else if (ioc->current_boot_device.device) {
7390 device = ioc->current_boot_device.device;
7391 is_raid = ioc->current_boot_device.is_raid;
7398 raid_device = device;
7399 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7400 raid_device->id, 0);
7402 _scsih_raid_device_remove(ioc, raid_device);
7404 sas_device = device;
7405 handle = sas_device->handle;
7406 sas_address_parent = sas_device->sas_address_parent;
7407 sas_address = sas_device->sas_address;
7408 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7409 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7410 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7412 if (ioc->hide_drives)
7414 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7415 sas_device->sas_address_parent)) {
7416 _scsih_sas_device_remove(ioc, sas_device);
7417 } else if (!sas_device->starget) {
7418 mpt2sas_transport_port_remove(ioc, sas_address,
7419 sas_address_parent);
7420 _scsih_sas_device_remove(ioc, sas_device);
7426 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7427 * @ioc: per adapter object
7429 * Called during initial loading of the driver.
7432 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7434 struct _raid_device *raid_device, *raid_next;
7437 list_for_each_entry_safe(raid_device, raid_next,
7438 &ioc->raid_device_list, list) {
7439 if (raid_device->starget)
7441 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7442 raid_device->id, 0);
7444 _scsih_raid_device_remove(ioc, raid_device);
7449 * _scsih_probe_sas - reporting sas devices to sas transport
7450 * @ioc: per adapter object
7452 * Called during initial loading of the driver.
7455 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7457 struct _sas_device *sas_device, *next;
7458 unsigned long flags;
7460 /* SAS Device List */
7461 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7463 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7464 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7465 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7467 if (ioc->hide_drives)
7470 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7471 sas_device->sas_address_parent)) {
7472 _scsih_sas_device_remove(ioc, sas_device);
7473 } else if (!sas_device->starget) {
7474 mpt2sas_transport_port_remove(ioc,
7475 sas_device->sas_address,
7476 sas_device->sas_address_parent);
7477 _scsih_sas_device_remove(ioc, sas_device);
7483 * _scsih_probe_devices - probing for devices
7484 * @ioc: per adapter object
7486 * Called during initial loading of the driver.
7489 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7491 u16 volume_mapping_flags =
7492 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7493 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7495 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7496 return; /* return when IOC doesn't support initiator mode */
7498 _scsih_probe_boot_devices(ioc);
7500 if (ioc->ir_firmware) {
7501 if ((volume_mapping_flags &
7502 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
7503 _scsih_probe_sas(ioc);
7504 _scsih_probe_raid(ioc);
7506 _scsih_probe_raid(ioc);
7507 _scsih_probe_sas(ioc);
7510 _scsih_probe_sas(ioc);
7514 * _scsih_probe - attach and add scsi host
7515 * @pdev: PCI device struct
7516 * @id: pci device id
7518 * Returns 0 success, anything else error.
7521 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7523 struct MPT2SAS_ADAPTER *ioc;
7524 struct Scsi_Host *shost;
7526 shost = scsi_host_alloc(&scsih_driver_template,
7527 sizeof(struct MPT2SAS_ADAPTER));
7531 /* init local params */
7532 ioc = shost_priv(shost);
7533 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7534 INIT_LIST_HEAD(&ioc->list);
7535 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
7537 ioc->id = mpt_ids++;
7538 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7540 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7541 ioc->is_warpdrive = 1;
7542 ioc->hide_ir_msg = 1;
7544 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
7545 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7546 ioc->tm_cb_idx = tm_cb_idx;
7547 ioc->ctl_cb_idx = ctl_cb_idx;
7548 ioc->base_cb_idx = base_cb_idx;
7549 ioc->transport_cb_idx = transport_cb_idx;
7550 ioc->scsih_cb_idx = scsih_cb_idx;
7551 ioc->config_cb_idx = config_cb_idx;
7552 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7553 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7554 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7555 ioc->logging_level = logging_level;
7556 /* misc semaphores and spin locks */
7557 mutex_init(&ioc->reset_in_progress_mutex);
7558 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7559 spin_lock_init(&ioc->scsi_lookup_lock);
7560 spin_lock_init(&ioc->sas_device_lock);
7561 spin_lock_init(&ioc->sas_node_lock);
7562 spin_lock_init(&ioc->fw_event_lock);
7563 spin_lock_init(&ioc->raid_device_lock);
7565 INIT_LIST_HEAD(&ioc->sas_device_list);
7566 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7567 INIT_LIST_HEAD(&ioc->sas_expander_list);
7568 INIT_LIST_HEAD(&ioc->fw_event_list);
7569 INIT_LIST_HEAD(&ioc->raid_device_list);
7570 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7571 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7572 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7574 /* init shost parameters */
7575 shost->max_cmd_len = 32;
7576 shost->max_lun = max_lun;
7577 shost->transportt = mpt2sas_transport_template;
7578 shost->unique_id = ioc->id;
7580 if (max_sectors != 0xFFFF) {
7581 if (max_sectors < 64) {
7582 shost->max_sectors = 64;
7583 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7584 "for max_sectors, range is 64 to 8192. Assigning "
7585 "value of 64.\n", ioc->name, max_sectors);
7586 } else if (max_sectors > 8192) {
7587 shost->max_sectors = 8192;
7588 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7589 "for max_sectors, range is 64 to 8192. Assigning "
7590 "default value of 8192.\n", ioc->name,
7593 shost->max_sectors = max_sectors & 0xFFFE;
7594 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7595 "set to %d\n", ioc->name, shost->max_sectors);
7599 if ((scsi_add_host(shost, &pdev->dev))) {
7600 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7601 ioc->name, __FILE__, __LINE__, __func__);
7602 list_del(&ioc->list);
7603 goto out_add_shost_fail;
7606 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7607 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
7608 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7611 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7612 "fw_event%d", ioc->id);
7613 ioc->firmware_event_thread = create_singlethread_workqueue(
7614 ioc->firmware_event_name);
7615 if (!ioc->firmware_event_thread) {
7616 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7617 ioc->name, __FILE__, __LINE__, __func__);
7618 goto out_thread_fail;
7621 ioc->wait_for_port_enable_to_complete = 1;
7622 if ((mpt2sas_base_attach(ioc))) {
7623 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7624 ioc->name, __FILE__, __LINE__, __func__);
7625 goto out_attach_fail;
7628 ioc->wait_for_port_enable_to_complete = 0;
7629 if (ioc->is_warpdrive) {
7630 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7631 ioc->hide_drives = 0;
7632 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
7633 ioc->hide_drives = 1;
7635 if (_scsih_get_num_volumes(ioc))
7636 ioc->hide_drives = 1;
7638 ioc->hide_drives = 0;
7641 ioc->hide_drives = 0;
7643 _scsih_probe_devices(ioc);
7647 destroy_workqueue(ioc->firmware_event_thread);
7649 list_del(&ioc->list);
7650 scsi_remove_host(shost);
7657 * _scsih_suspend - power management suspend main entry point
7658 * @pdev: PCI device struct
7659 * @state: PM state change to (usually PCI_D3)
7661 * Returns 0 success, anything else error.
7664 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7666 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7667 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7668 pci_power_t device_state;
7670 mpt2sas_base_stop_watchdog(ioc);
7671 scsi_block_requests(shost);
7672 device_state = pci_choose_state(pdev, state);
7673 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
7674 "operating state [D%d]\n", ioc->name, pdev,
7675 pci_name(pdev), device_state);
7677 mpt2sas_base_free_resources(ioc);
7678 pci_save_state(pdev);
7679 pci_disable_device(pdev);
7680 pci_set_power_state(pdev, device_state);
7685 * _scsih_resume - power management resume main entry point
7686 * @pdev: PCI device struct
7688 * Returns 0 success, anything else error.
7691 _scsih_resume(struct pci_dev *pdev)
7693 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7694 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7695 pci_power_t device_state = pdev->current_state;
7698 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
7699 "operating state [D%d]\n", ioc->name, pdev,
7700 pci_name(pdev), device_state);
7702 pci_set_power_state(pdev, PCI_D0);
7703 pci_enable_wake(pdev, PCI_D0, 0);
7704 pci_restore_state(pdev);
7706 r = mpt2sas_base_map_resources(ioc);
7710 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7711 scsi_unblock_requests(shost);
7712 mpt2sas_base_start_watchdog(ioc);
7715 #endif /* CONFIG_PM */
7718 * _scsih_pci_error_detected - Called when a PCI error is detected.
7719 * @pdev: PCI device struct
7720 * @state: PCI channel state
7722 * Description: Called when a PCI error is detected.
7725 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7727 static pci_ers_result_t
7728 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7730 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7731 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7733 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
7737 case pci_channel_io_normal:
7738 return PCI_ERS_RESULT_CAN_RECOVER;
7739 case pci_channel_io_frozen:
7740 /* Fatal error, prepare for slot reset */
7741 ioc->pci_error_recovery = 1;
7742 scsi_block_requests(ioc->shost);
7743 mpt2sas_base_stop_watchdog(ioc);
7744 mpt2sas_base_free_resources(ioc);
7745 return PCI_ERS_RESULT_NEED_RESET;
7746 case pci_channel_io_perm_failure:
7747 /* Permanent error, prepare for device removal */
7748 ioc->pci_error_recovery = 1;
7749 mpt2sas_base_stop_watchdog(ioc);
7750 _scsih_flush_running_cmds(ioc);
7751 return PCI_ERS_RESULT_DISCONNECT;
7753 return PCI_ERS_RESULT_NEED_RESET;
7757 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
7758 * @pdev: PCI device struct
7760 * Description: This routine is called by the pci error recovery
7761 * code after the PCI slot has been reset, just before we
7762 * should resume normal operations.
7764 static pci_ers_result_t
7765 _scsih_pci_slot_reset(struct pci_dev *pdev)
7767 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7768 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7771 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
7774 ioc->pci_error_recovery = 0;
7776 pci_restore_state(pdev);
7777 rc = mpt2sas_base_map_resources(ioc);
7779 return PCI_ERS_RESULT_DISCONNECT;
7782 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
7785 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
7786 (rc == 0) ? "success" : "failed");
7789 return PCI_ERS_RESULT_RECOVERED;
7791 return PCI_ERS_RESULT_DISCONNECT;
7795 * _scsih_pci_resume() - resume normal ops after PCI reset
7796 * @pdev: pointer to PCI device
7798 * Called when the error recovery driver tells us that its
7799 * OK to resume normal operation. Use completion to allow
7800 * halted scsi ops to resume.
7803 _scsih_pci_resume(struct pci_dev *pdev)
7805 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7806 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7808 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
7810 pci_cleanup_aer_uncorrect_error_status(pdev);
7811 mpt2sas_base_start_watchdog(ioc);
7812 scsi_unblock_requests(ioc->shost);
7816 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
7817 * @pdev: pointer to PCI device
7819 static pci_ers_result_t
7820 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
7822 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7823 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7825 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
7828 /* TODO - dump whatever for debugging purposes */
7830 /* Request a slot reset. */
7831 return PCI_ERS_RESULT_NEED_RESET;
7834 static struct pci_error_handlers _scsih_err_handler = {
7835 .error_detected = _scsih_pci_error_detected,
7836 .mmio_enabled = _scsih_pci_mmio_enabled,
7837 .slot_reset = _scsih_pci_slot_reset,
7838 .resume = _scsih_pci_resume,
7841 static struct pci_driver scsih_driver = {
7842 .name = MPT2SAS_DRIVER_NAME,
7843 .id_table = scsih_pci_table,
7844 .probe = _scsih_probe,
7845 .remove = __devexit_p(_scsih_remove),
7846 .shutdown = _scsih_shutdown,
7847 .err_handler = &_scsih_err_handler,
7849 .suspend = _scsih_suspend,
7850 .resume = _scsih_resume,
7854 /* raid transport support */
7855 static struct raid_function_template mpt2sas_raid_functions = {
7856 .cookie = &scsih_driver_template,
7857 .is_raid = _scsih_is_raid,
7858 .get_resync = _scsih_get_resync,
7859 .get_state = _scsih_get_state,
7863 * _scsih_init - main entry point for this driver.
7865 * Returns 0 success, anything else error.
7873 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
7874 MPT2SAS_DRIVER_VERSION);
7876 mpt2sas_transport_template =
7877 sas_attach_transport(&mpt2sas_transport_functions);
7878 if (!mpt2sas_transport_template)
7880 /* raid transport support */
7881 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
7882 if (!mpt2sas_raid_template) {
7883 sas_release_transport(mpt2sas_transport_template);
7887 mpt2sas_base_initialize_callback_handler();
7889 /* queuecommand callback hander */
7890 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
7892 /* task management callback handler */
7893 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
7895 /* base internal commands callback handler */
7896 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
7898 /* transport internal commands callback handler */
7899 transport_cb_idx = mpt2sas_base_register_callback_handler(
7900 mpt2sas_transport_done);
7902 /* scsih internal commands callback handler */
7903 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
7905 /* configuration page API internal commands callback handler */
7906 config_cb_idx = mpt2sas_base_register_callback_handler(
7907 mpt2sas_config_done);
7909 /* ctl module callback handler */
7910 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
7912 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
7913 _scsih_tm_tr_complete);
7915 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
7916 _scsih_tm_volume_tr_complete);
7918 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
7919 _scsih_sas_control_complete);
7923 error = pci_register_driver(&scsih_driver);
7925 /* raid transport support */
7926 raid_class_release(mpt2sas_raid_template);
7927 sas_release_transport(mpt2sas_transport_template);
7934 * _scsih_exit - exit point for this driver (when it is a module).
7936 * Returns 0 success, anything else error.
7941 printk(KERN_INFO "mpt2sas version %s unloading\n",
7942 MPT2SAS_DRIVER_VERSION);
7944 pci_unregister_driver(&scsih_driver);
7948 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
7949 mpt2sas_base_release_callback_handler(tm_cb_idx);
7950 mpt2sas_base_release_callback_handler(base_cb_idx);
7951 mpt2sas_base_release_callback_handler(transport_cb_idx);
7952 mpt2sas_base_release_callback_handler(scsih_cb_idx);
7953 mpt2sas_base_release_callback_handler(config_cb_idx);
7954 mpt2sas_base_release_callback_handler(ctl_cb_idx);
7956 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
7957 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
7958 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
7960 /* raid transport support */
7961 raid_class_release(mpt2sas_raid_template);
7962 sas_release_transport(mpt2sas_transport_template);
7966 module_init(_scsih_init);
7967 module_exit(_scsih_exit);