2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2014 LSI Corporation
6 * Copyright (C) 20013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <linux/slab.h>
59 #include <asm/unaligned.h>
61 #include "mpt2sas_base.h"
63 MODULE_AUTHOR(MPT2SAS_AUTHOR);
64 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
65 MODULE_LICENSE("GPL");
66 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
68 #define RAID_CHANNEL 1
71 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
72 struct _sas_node *sas_expander);
73 static void _firmware_event_work(struct work_struct *work);
75 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
77 static void _scsih_scan_start(struct Scsi_Host *shost);
78 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
80 /* global parameters */
81 LIST_HEAD(mpt2sas_ioc_list);
82 /* global ioc lock for list operations */
83 DEFINE_SPINLOCK(gioc_lock);
84 /* local parameters */
85 static u8 scsi_io_cb_idx = -1;
86 static u8 tm_cb_idx = -1;
87 static u8 ctl_cb_idx = -1;
88 static u8 base_cb_idx = -1;
89 static u8 port_enable_cb_idx = -1;
90 static u8 transport_cb_idx = -1;
91 static u8 scsih_cb_idx = -1;
92 static u8 config_cb_idx = -1;
95 static u8 tm_tr_cb_idx = -1 ;
96 static u8 tm_tr_volume_cb_idx = -1 ;
97 static u8 tm_sas_control_cb_idx = -1;
99 /* command line options */
100 static u32 logging_level;
101 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
104 static ushort max_sectors = 0xFFFF;
105 module_param(max_sectors, ushort, 0);
106 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
108 static int missing_delay[2] = {-1, -1};
109 module_param_array(missing_delay, int, NULL, 0);
110 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
112 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
113 #define MPT2SAS_MAX_LUN (16895)
114 static int max_lun = MPT2SAS_MAX_LUN;
115 module_param(max_lun, int, 0);
116 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
118 /* diag_buffer_enable is bitwise
120 * bit 1 set = SNAPSHOT
121 * bit 2 set = EXTENDED
123 * Either bit can be set, or both
125 static int diag_buffer_enable = -1;
126 module_param(diag_buffer_enable, int, 0);
127 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
128 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
130 static int disable_discovery = -1;
131 module_param(disable_discovery, int, 0);
132 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
134 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
135 static int prot_mask = 0;
136 module_param(prot_mask, int, 0);
137 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
140 * struct sense_info - common structure for obtaining sense keys
142 * @asc: additional sense code
143 * @ascq: additional sense code qualifier
152 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
153 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
154 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
156 * struct fw_event_work - firmware event struct
157 * @list: link list framework
158 * @work: work object (ioc->fault_reset_work_q)
159 * @cancel_pending_work: flag set during reset handling
160 * @ioc: per adapter object
161 * @device_handle: device handle
162 * @VF_ID: virtual function id
163 * @VP_ID: virtual port id
164 * @ignore: flag meaning this event has been marked to ignore
165 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
166 * @event_data: reply event data payload follows
168 * This object stored on ioc->fw_event_list.
170 struct fw_event_work {
171 struct list_head list;
172 u8 cancel_pending_work;
173 struct delayed_work delayed_work;
174 struct MPT2SAS_ADAPTER *ioc;
180 char event_data[0] __aligned(4);
183 /* raid transport support */
184 static struct raid_template *mpt2sas_raid_template;
187 * struct _scsi_io_transfer - scsi io transfer
188 * @handle: sas device handle (assigned by firmware)
189 * @is_raid: flag set for hidden raid components
190 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
191 * @data_length: data transfer length
192 * @data_dma: dma pointer to data
195 * @cdb_length: cdb length
197 * @timeout: timeout for this command
198 * @VF_ID: virtual function id
199 * @VP_ID: virtual port id
200 * @valid_reply: flag set for reply message
201 * @sense_length: sense length
202 * @ioc_status: ioc status
203 * @scsi_state: scsi state
204 * @scsi_status: scsi staus
205 * @log_info: log information
206 * @transfer_length: data length transfer when there is a reply message
208 * Used for sending internal scsi commands to devices within this module.
209 * Refer to _scsi_send_scsi_io().
211 struct _scsi_io_transfer {
214 enum dma_data_direction dir;
217 u8 sense[SCSI_SENSE_BUFFERSIZE];
225 /* the following bits are only valid when 'valid_reply = 1' */
235 * The pci device ids are defined in mpi/mpi2_cnfg.h.
237 static struct pci_device_id scsih_pci_table[] = {
238 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
239 PCI_ANY_ID, PCI_ANY_ID },
241 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
242 PCI_ANY_ID, PCI_ANY_ID },
243 /* Liberator ~ 2108 */
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
245 PCI_ANY_ID, PCI_ANY_ID },
246 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
247 PCI_ANY_ID, PCI_ANY_ID },
248 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
249 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
252 PCI_ANY_ID, PCI_ANY_ID },
253 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
254 PCI_ANY_ID, PCI_ANY_ID },
255 /* Thunderbolt ~ 2208 */
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
265 PCI_ANY_ID, PCI_ANY_ID },
266 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
267 PCI_ANY_ID, PCI_ANY_ID },
269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
270 PCI_ANY_ID, PCI_ANY_ID },
271 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
272 PCI_ANY_ID, PCI_ANY_ID },
273 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
274 PCI_ANY_ID, PCI_ANY_ID },
276 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
277 PCI_ANY_ID, PCI_ANY_ID },
278 {0} /* Terminating entry */
280 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
283 * _scsih_set_debug_level - global setting of ioc->logging_level.
285 * Note: The logging levels are defined in mpt2sas_debug.h.
288 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
290 int ret = param_set_int(val, kp);
291 struct MPT2SAS_ADAPTER *ioc;
296 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
297 spin_lock(&gioc_lock);
298 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
299 ioc->logging_level = logging_level;
300 spin_unlock(&gioc_lock);
303 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
304 &logging_level, 0644);
307 * _scsih_srch_boot_sas_address - search based on sas_address
308 * @sas_address: sas address
309 * @boot_device: boot device object from bios page 2
311 * Returns 1 when there's a match, 0 means no match.
314 _scsih_srch_boot_sas_address(u64 sas_address,
315 Mpi2BootDeviceSasWwid_t *boot_device)
317 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
321 * _scsih_srch_boot_device_name - search based on device name
322 * @device_name: device name specified in INDENTIFY fram
323 * @boot_device: boot device object from bios page 2
325 * Returns 1 when there's a match, 0 means no match.
328 _scsih_srch_boot_device_name(u64 device_name,
329 Mpi2BootDeviceDeviceName_t *boot_device)
331 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
335 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
336 * @enclosure_logical_id: enclosure logical id
337 * @slot_number: slot number
338 * @boot_device: boot device object from bios page 2
340 * Returns 1 when there's a match, 0 means no match.
343 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
344 Mpi2BootDeviceEnclosureSlot_t *boot_device)
346 return (enclosure_logical_id == le64_to_cpu(boot_device->
347 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
348 SlotNumber)) ? 1 : 0;
352 * _scsih_is_boot_device - search for matching boot device.
353 * @sas_address: sas address
354 * @device_name: device name specified in INDENTIFY fram
355 * @enclosure_logical_id: enclosure logical id
356 * @slot_number: slot number
357 * @form: specifies boot device form
358 * @boot_device: boot device object from bios page 2
360 * Returns 1 when there's a match, 0 means no match.
363 _scsih_is_boot_device(u64 sas_address, u64 device_name,
364 u64 enclosure_logical_id, u16 slot, u8 form,
365 Mpi2BiosPage2BootDevice_t *boot_device)
370 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
373 rc = _scsih_srch_boot_sas_address(
374 sas_address, &boot_device->SasWwid);
376 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
377 if (!enclosure_logical_id)
379 rc = _scsih_srch_boot_encl_slot(
380 enclosure_logical_id,
381 slot, &boot_device->EnclosureSlot);
383 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
386 rc = _scsih_srch_boot_device_name(
387 device_name, &boot_device->DeviceName);
389 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
397 * _scsih_get_sas_address - set the sas_address for given device handle
398 * @handle: device handle
399 * @sas_address: sas address
401 * Returns 0 success, non-zero when failure
404 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
407 Mpi2SasDevicePage0_t sas_device_pg0;
408 Mpi2ConfigReply_t mpi_reply;
412 if (handle <= ioc->sas_hba.num_phys) {
413 *sas_address = ioc->sas_hba.sas_address;
417 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
418 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
419 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
420 __FILE__, __LINE__, __func__);
424 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
425 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
426 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
430 /* we hit this becuase the given parent handle doesn't exist */
431 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
433 /* else error case */
434 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
435 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
436 __FILE__, __LINE__, __func__);
441 * _scsih_determine_boot_device - determine boot device.
442 * @ioc: per adapter object
443 * @device: either sas_device or raid_device object
444 * @is_raid: [flag] 1 = raid object, 0 = sas object
446 * Determines whether this device should be first reported device to
447 * to scsi-ml or sas transport, this purpose is for persistent boot device.
448 * There are primary, alternate, and current entries in bios page 2. The order
449 * priority is primary, alternate, then current. This routine saves
450 * the corresponding device object and is_raid flag in the ioc object.
451 * The saved data to be used later in _scsih_probe_boot_devices().
454 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
455 void *device, u8 is_raid)
457 struct _sas_device *sas_device;
458 struct _raid_device *raid_device;
461 u64 enclosure_logical_id;
464 /* only process this function when driver loads */
465 if (!ioc->is_driver_loading)
468 /* no Bios, return immediately */
469 if (!ioc->bios_pg3.BiosVersion)
474 sas_address = sas_device->sas_address;
475 device_name = sas_device->device_name;
476 enclosure_logical_id = sas_device->enclosure_logical_id;
477 slot = sas_device->slot;
479 raid_device = device;
480 sas_address = raid_device->wwid;
482 enclosure_logical_id = 0;
486 if (!ioc->req_boot_device.device) {
487 if (_scsih_is_boot_device(sas_address, device_name,
488 enclosure_logical_id, slot,
489 (ioc->bios_pg2.ReqBootDeviceForm &
490 MPI2_BIOSPAGE2_FORM_MASK),
491 &ioc->bios_pg2.RequestedBootDevice)) {
492 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
493 "%s: req_boot_device(0x%016llx)\n",
495 (unsigned long long)sas_address));
496 ioc->req_boot_device.device = device;
497 ioc->req_boot_device.is_raid = is_raid;
501 if (!ioc->req_alt_boot_device.device) {
502 if (_scsih_is_boot_device(sas_address, device_name,
503 enclosure_logical_id, slot,
504 (ioc->bios_pg2.ReqAltBootDeviceForm &
505 MPI2_BIOSPAGE2_FORM_MASK),
506 &ioc->bios_pg2.RequestedAltBootDevice)) {
507 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
508 "%s: req_alt_boot_device(0x%016llx)\n",
510 (unsigned long long)sas_address));
511 ioc->req_alt_boot_device.device = device;
512 ioc->req_alt_boot_device.is_raid = is_raid;
516 if (!ioc->current_boot_device.device) {
517 if (_scsih_is_boot_device(sas_address, device_name,
518 enclosure_logical_id, slot,
519 (ioc->bios_pg2.CurrentBootDeviceForm &
520 MPI2_BIOSPAGE2_FORM_MASK),
521 &ioc->bios_pg2.CurrentBootDevice)) {
522 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
523 "%s: current_boot_device(0x%016llx)\n",
525 (unsigned long long)sas_address));
526 ioc->current_boot_device.device = device;
527 ioc->current_boot_device.is_raid = is_raid;
532 static struct _sas_device *
533 __mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc,
534 struct MPT2SAS_TARGET *tgt_priv)
536 struct _sas_device *ret;
538 assert_spin_locked(&ioc->sas_device_lock);
540 ret = tgt_priv->sdev;
547 static struct _sas_device *
548 mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc,
549 struct MPT2SAS_TARGET *tgt_priv)
551 struct _sas_device *ret;
554 spin_lock_irqsave(&ioc->sas_device_lock, flags);
555 ret = __mpt2sas_get_sdev_from_target(ioc, tgt_priv);
556 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
563 __mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc,
566 struct _sas_device *sas_device;
568 assert_spin_locked(&ioc->sas_device_lock);
570 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
571 if (sas_device->sas_address == sas_address)
574 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
575 if (sas_device->sas_address == sas_address)
581 sas_device_get(sas_device);
586 * mpt2sas_get_sdev_by_addr - sas device search
587 * @ioc: per adapter object
588 * @sas_address: sas address
589 * Context: Calling function should acquire ioc->sas_device_lock
591 * This searches for sas_device based on sas_address, then return sas_device
595 mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc,
598 struct _sas_device *sas_device;
601 spin_lock_irqsave(&ioc->sas_device_lock, flags);
602 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
604 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
609 static struct _sas_device *
610 __mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
612 struct _sas_device *sas_device;
614 assert_spin_locked(&ioc->sas_device_lock);
616 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
617 if (sas_device->handle == handle)
620 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
621 if (sas_device->handle == handle)
627 sas_device_get(sas_device);
632 * mpt2sas_get_sdev_by_handle - sas device search
633 * @ioc: per adapter object
634 * @handle: sas device handle (assigned by firmware)
635 * Context: Calling function should acquire ioc->sas_device_lock
637 * This searches for sas_device based on sas_address, then return sas_device
640 static struct _sas_device *
641 mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
643 struct _sas_device *sas_device;
646 spin_lock_irqsave(&ioc->sas_device_lock, flags);
647 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
648 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
654 * _scsih_sas_device_remove - remove sas_device from list.
655 * @ioc: per adapter object
656 * @sas_device: the sas_device object
657 * Context: This function will acquire ioc->sas_device_lock.
659 * If sas_device is on the list, remove it and decrement its reference count.
662 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
663 struct _sas_device *sas_device)
671 * The lock serializes access to the list, but we still need to verify
672 * that nobody removed the entry while we were waiting on the lock.
674 spin_lock_irqsave(&ioc->sas_device_lock, flags);
675 if (!list_empty(&sas_device->list)) {
676 list_del_init(&sas_device->list);
677 sas_device_put(sas_device);
679 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
684 * _scsih_sas_device_add - insert sas_device to the list.
685 * @ioc: per adapter object
686 * @sas_device: the sas_device object
687 * Context: This function will acquire ioc->sas_device_lock.
689 * Adding new object to the ioc->sas_device_list.
692 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
693 struct _sas_device *sas_device)
697 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
698 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
699 sas_device->handle, (unsigned long long)sas_device->sas_address));
701 spin_lock_irqsave(&ioc->sas_device_lock, flags);
702 sas_device_get(sas_device);
703 list_add_tail(&sas_device->list, &ioc->sas_device_list);
704 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
706 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
707 sas_device->sas_address_parent)) {
708 _scsih_sas_device_remove(ioc, sas_device);
709 } else if (!sas_device->starget) {
710 /* When asyn scanning is enabled, its not possible to remove
711 * devices while scanning is turned on due to an oops in
712 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
714 if (!ioc->is_driver_loading) {
715 mpt2sas_transport_port_remove(ioc,
716 sas_device->sas_address,
717 sas_device->sas_address_parent);
718 _scsih_sas_device_remove(ioc, sas_device);
724 * _scsih_sas_device_init_add - insert sas_device to the list.
725 * @ioc: per adapter object
726 * @sas_device: the sas_device object
727 * Context: This function will acquire ioc->sas_device_lock.
729 * Adding new object at driver load time to the ioc->sas_device_init_list.
732 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
733 struct _sas_device *sas_device)
737 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
738 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
739 sas_device->handle, (unsigned long long)sas_device->sas_address));
741 spin_lock_irqsave(&ioc->sas_device_lock, flags);
742 sas_device_get(sas_device);
743 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
744 _scsih_determine_boot_device(ioc, sas_device, 0);
745 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
749 * _scsih_raid_device_find_by_id - raid device search
750 * @ioc: per adapter object
751 * @id: sas device target id
752 * @channel: sas device channel
753 * Context: Calling function should acquire ioc->raid_device_lock
755 * This searches for raid_device based on target id, then return raid_device
758 static struct _raid_device *
759 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
761 struct _raid_device *raid_device, *r;
764 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
765 if (raid_device->id == id && raid_device->channel == channel) {
776 * _scsih_raid_device_find_by_handle - raid device search
777 * @ioc: per adapter object
778 * @handle: sas device handle (assigned by firmware)
779 * Context: Calling function should acquire ioc->raid_device_lock
781 * This searches for raid_device based on handle, then return raid_device
784 static struct _raid_device *
785 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
787 struct _raid_device *raid_device, *r;
790 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
791 if (raid_device->handle != handle)
802 * _scsih_raid_device_find_by_wwid - raid device search
803 * @ioc: per adapter object
804 * @handle: sas device handle (assigned by firmware)
805 * Context: Calling function should acquire ioc->raid_device_lock
807 * This searches for raid_device based on wwid, then return raid_device
810 static struct _raid_device *
811 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
813 struct _raid_device *raid_device, *r;
816 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
817 if (raid_device->wwid != wwid)
828 * _scsih_raid_device_add - add raid_device object
829 * @ioc: per adapter object
830 * @raid_device: raid_device object
832 * This is added to the raid_device_list link list.
835 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
836 struct _raid_device *raid_device)
840 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
841 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
842 raid_device->handle, (unsigned long long)raid_device->wwid));
844 spin_lock_irqsave(&ioc->raid_device_lock, flags);
845 list_add_tail(&raid_device->list, &ioc->raid_device_list);
846 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
850 * _scsih_raid_device_remove - delete raid_device object
851 * @ioc: per adapter object
852 * @raid_device: raid_device object
856 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
857 struct _raid_device *raid_device)
861 spin_lock_irqsave(&ioc->raid_device_lock, flags);
862 list_del(&raid_device->list);
864 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
868 * mpt2sas_scsih_expander_find_by_handle - expander device search
869 * @ioc: per adapter object
870 * @handle: expander handle (assigned by firmware)
871 * Context: Calling function should acquire ioc->sas_device_lock
873 * This searches for expander device based on handle, then returns the
877 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
879 struct _sas_node *sas_expander, *r;
882 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
883 if (sas_expander->handle != handle)
893 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
894 * @ioc: per adapter object
895 * @sas_address: sas address
896 * Context: Calling function should acquire ioc->sas_node_lock.
898 * This searches for expander device based on sas_address, then returns the
902 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
905 struct _sas_node *sas_expander, *r;
908 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
909 if (sas_expander->sas_address != sas_address)
919 * _scsih_expander_node_add - insert expander device to the list.
920 * @ioc: per adapter object
921 * @sas_expander: the sas_device object
922 * Context: This function will acquire ioc->sas_node_lock.
924 * Adding new object to the ioc->sas_expander_list.
929 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
930 struct _sas_node *sas_expander)
934 spin_lock_irqsave(&ioc->sas_node_lock, flags);
935 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
936 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
940 * _scsih_is_end_device - determines if device is an end device
941 * @device_info: bitfield providing information about the device.
944 * Returns 1 if end device.
947 _scsih_is_end_device(u32 device_info)
949 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
950 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
951 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
952 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
959 * _scsih_scsi_lookup_get - returns scmd entry
960 * @ioc: per adapter object
961 * @smid: system request message index
963 * Returns the smid stored scmd pointer.
965 static struct scsi_cmnd *
966 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
968 return ioc->scsi_lookup[smid - 1].scmd;
972 * _scsih_scsi_lookup_get_clear - returns scmd entry
973 * @ioc: per adapter object
974 * @smid: system request message index
976 * Returns the smid stored scmd pointer.
977 * Then will derefrence the stored scmd pointer.
979 static inline struct scsi_cmnd *
980 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
983 struct scsi_cmnd *scmd;
985 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
986 scmd = ioc->scsi_lookup[smid - 1].scmd;
987 ioc->scsi_lookup[smid - 1].scmd = NULL;
988 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
994 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
995 * @ioc: per adapter object
996 * @smid: system request message index
997 * @scmd: pointer to scsi command object
998 * Context: This function will acquire ioc->scsi_lookup_lock.
1000 * This will search for a scmd pointer in the scsi_lookup array,
1001 * returning the revelent smid. A returned value of zero means invalid.
1004 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
1008 unsigned long flags;
1011 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1013 for (i = 0; i < ioc->scsiio_depth; i++) {
1014 if (ioc->scsi_lookup[i].scmd == scmd) {
1015 smid = ioc->scsi_lookup[i].smid;
1020 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1025 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1026 * @ioc: per adapter object
1029 * Context: This function will acquire ioc->scsi_lookup_lock.
1031 * This will search for a matching channel:id in the scsi_lookup array,
1032 * returning 1 if found.
1035 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
1039 unsigned long flags;
1042 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1044 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1045 if (ioc->scsi_lookup[i].scmd &&
1046 (ioc->scsi_lookup[i].scmd->device->id == id &&
1047 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1053 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1058 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1059 * @ioc: per adapter object
1063 * Context: This function will acquire ioc->scsi_lookup_lock.
1065 * This will search for a matching channel:id:lun in the scsi_lookup array,
1066 * returning 1 if found.
1069 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
1070 unsigned int lun, int channel)
1073 unsigned long flags;
1076 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1078 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1079 if (ioc->scsi_lookup[i].scmd &&
1080 (ioc->scsi_lookup[i].scmd->device->id == id &&
1081 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1082 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1088 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1093 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1094 * @ioc: per adapter object
1095 * @smid: smid associated to an IO request
1097 * Returns chain tracker(from ioc->free_chain_list)
1099 static struct chain_tracker *
1100 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1102 struct chain_tracker *chain_req;
1103 unsigned long flags;
1105 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1106 if (list_empty(&ioc->free_chain_list)) {
1107 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1108 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1109 "available\n", ioc->name));
1112 chain_req = list_entry(ioc->free_chain_list.next,
1113 struct chain_tracker, tracker_list);
1114 list_del_init(&chain_req->tracker_list);
1115 list_add_tail(&chain_req->tracker_list,
1116 &ioc->scsi_lookup[smid - 1].chain_list);
1117 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1122 * _scsih_build_scatter_gather - main sg creation routine
1123 * @ioc: per adapter object
1124 * @scmd: scsi command
1125 * @smid: system request message index
1128 * The main routine that builds scatter gather table from a given
1129 * scsi request sent via the .queuecommand main handler.
1131 * Returns 0 success, anything else error
1134 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1135 struct scsi_cmnd *scmd, u16 smid)
1137 Mpi2SCSIIORequest_t *mpi_request;
1138 dma_addr_t chain_dma;
1139 struct scatterlist *sg_scmd;
1140 void *sg_local, *chain;
1145 u32 sges_in_segment;
1147 u32 sgl_flags_last_element;
1148 u32 sgl_flags_end_buffer;
1149 struct chain_tracker *chain_req;
1151 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1153 /* init scatter gather flags */
1154 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1155 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1156 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1157 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1158 << MPI2_SGE_FLAGS_SHIFT;
1159 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1160 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1161 << MPI2_SGE_FLAGS_SHIFT;
1162 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1164 sg_scmd = scsi_sglist(scmd);
1165 sges_left = scsi_dma_map(scmd);
1166 if (sges_left < 0) {
1167 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1168 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1172 sg_local = &mpi_request->SGL;
1173 sges_in_segment = ioc->max_sges_in_main_message;
1174 if (sges_left <= sges_in_segment)
1175 goto fill_in_last_segment;
1177 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1178 (sges_in_segment * ioc->sge_size))/4;
1180 /* fill in main message segment when there is a chain following */
1181 while (sges_in_segment) {
1182 if (sges_in_segment == 1)
1183 ioc->base_add_sg_single(sg_local,
1184 sgl_flags_last_element | sg_dma_len(sg_scmd),
1185 sg_dma_address(sg_scmd));
1187 ioc->base_add_sg_single(sg_local, sgl_flags |
1188 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1189 sg_scmd = sg_next(sg_scmd);
1190 sg_local += ioc->sge_size;
1195 /* initializing the chain flags and pointers */
1196 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1197 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1200 chain = chain_req->chain_buffer;
1201 chain_dma = chain_req->chain_buffer_dma;
1203 sges_in_segment = (sges_left <=
1204 ioc->max_sges_in_chain_message) ? sges_left :
1205 ioc->max_sges_in_chain_message;
1206 chain_offset = (sges_left == sges_in_segment) ?
1207 0 : (sges_in_segment * ioc->sge_size)/4;
1208 chain_length = sges_in_segment * ioc->sge_size;
1210 chain_offset = chain_offset <<
1211 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1212 chain_length += ioc->sge_size;
1214 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1215 chain_length, chain_dma);
1218 goto fill_in_last_segment;
1220 /* fill in chain segments */
1221 while (sges_in_segment) {
1222 if (sges_in_segment == 1)
1223 ioc->base_add_sg_single(sg_local,
1224 sgl_flags_last_element |
1225 sg_dma_len(sg_scmd),
1226 sg_dma_address(sg_scmd));
1228 ioc->base_add_sg_single(sg_local, sgl_flags |
1229 sg_dma_len(sg_scmd),
1230 sg_dma_address(sg_scmd));
1231 sg_scmd = sg_next(sg_scmd);
1232 sg_local += ioc->sge_size;
1237 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1240 chain = chain_req->chain_buffer;
1241 chain_dma = chain_req->chain_buffer_dma;
1245 fill_in_last_segment:
1247 /* fill the last segment */
1250 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1251 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1253 ioc->base_add_sg_single(sg_local, sgl_flags |
1254 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1255 sg_scmd = sg_next(sg_scmd);
1256 sg_local += ioc->sge_size;
1264 * _scsih_change_queue_depth - setting device queue depth
1265 * @sdev: scsi device struct
1266 * @qdepth: requested queue depth
1268 * Returns queue depth.
1271 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1273 struct Scsi_Host *shost = sdev->host;
1275 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1276 struct MPT2SAS_DEVICE *sas_device_priv_data;
1277 struct MPT2SAS_TARGET *sas_target_priv_data;
1278 struct _sas_device *sas_device;
1279 unsigned long flags;
1281 max_depth = shost->can_queue;
1283 /* limit max device queue for SATA to 32 */
1284 sas_device_priv_data = sdev->hostdata;
1285 if (!sas_device_priv_data)
1287 sas_target_priv_data = sas_device_priv_data->sas_target;
1288 if (!sas_target_priv_data)
1290 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1293 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1294 sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data);
1296 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1297 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1299 sas_device_put(sas_device);
1301 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1304 if (!sdev->tagged_supported)
1306 if (qdepth > max_depth)
1308 return scsi_change_queue_depth(sdev, qdepth);
1312 * _scsih_target_alloc - target add routine
1313 * @starget: scsi target struct
1315 * Returns 0 if ok. Any other return is assumed to be an error and
1316 * the device is ignored.
1319 _scsih_target_alloc(struct scsi_target *starget)
1321 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1322 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1323 struct MPT2SAS_TARGET *sas_target_priv_data;
1324 struct _sas_device *sas_device;
1325 struct _raid_device *raid_device;
1326 unsigned long flags;
1327 struct sas_rphy *rphy;
1329 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1331 if (!sas_target_priv_data)
1334 starget->hostdata = sas_target_priv_data;
1335 sas_target_priv_data->starget = starget;
1336 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1339 if (starget->channel == RAID_CHANNEL) {
1340 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1341 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1344 sas_target_priv_data->handle = raid_device->handle;
1345 sas_target_priv_data->sas_address = raid_device->wwid;
1346 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1347 if (ioc->is_warpdrive)
1348 sas_target_priv_data->raid_device = raid_device;
1349 raid_device->starget = starget;
1351 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1355 /* sas/sata devices */
1356 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1357 rphy = dev_to_rphy(starget->dev.parent);
1358 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
1359 rphy->identify.sas_address);
1362 sas_target_priv_data->handle = sas_device->handle;
1363 sas_target_priv_data->sas_address = sas_device->sas_address;
1364 sas_target_priv_data->sdev = sas_device;
1365 sas_device->starget = starget;
1366 sas_device->id = starget->id;
1367 sas_device->channel = starget->channel;
1368 if (test_bit(sas_device->handle, ioc->pd_handles))
1369 sas_target_priv_data->flags |=
1370 MPT_TARGET_FLAGS_RAID_COMPONENT;
1373 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1379 * _scsih_target_destroy - target destroy routine
1380 * @starget: scsi target struct
1385 _scsih_target_destroy(struct scsi_target *starget)
1387 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1388 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1389 struct MPT2SAS_TARGET *sas_target_priv_data;
1390 struct _sas_device *sas_device;
1391 struct _raid_device *raid_device;
1392 unsigned long flags;
1393 struct sas_rphy *rphy;
1395 sas_target_priv_data = starget->hostdata;
1396 if (!sas_target_priv_data)
1399 if (starget->channel == RAID_CHANNEL) {
1400 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1401 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1404 raid_device->starget = NULL;
1405 raid_device->sdev = NULL;
1407 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1411 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1412 rphy = dev_to_rphy(starget->dev.parent);
1413 sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data);
1414 if (sas_device && (sas_device->starget == starget) &&
1415 (sas_device->id == starget->id) &&
1416 (sas_device->channel == starget->channel))
1417 sas_device->starget = NULL;
1421 * Corresponding get() is in _scsih_target_alloc()
1423 sas_target_priv_data->sdev = NULL;
1424 sas_device_put(sas_device);
1426 sas_device_put(sas_device);
1428 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1431 kfree(sas_target_priv_data);
1432 starget->hostdata = NULL;
1436 * _scsih_slave_alloc - device add routine
1437 * @sdev: scsi device struct
1439 * Returns 0 if ok. Any other return is assumed to be an error and
1440 * the device is ignored.
1443 _scsih_slave_alloc(struct scsi_device *sdev)
1445 struct Scsi_Host *shost;
1446 struct MPT2SAS_ADAPTER *ioc;
1447 struct MPT2SAS_TARGET *sas_target_priv_data;
1448 struct MPT2SAS_DEVICE *sas_device_priv_data;
1449 struct scsi_target *starget;
1450 struct _raid_device *raid_device;
1451 struct _sas_device *sas_device;
1452 unsigned long flags;
1454 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1456 if (!sas_device_priv_data)
1459 sas_device_priv_data->lun = sdev->lun;
1460 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1462 starget = scsi_target(sdev);
1463 sas_target_priv_data = starget->hostdata;
1464 sas_target_priv_data->num_luns++;
1465 sas_device_priv_data->sas_target = sas_target_priv_data;
1466 sdev->hostdata = sas_device_priv_data;
1467 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1468 sdev->no_uld_attach = 1;
1470 shost = dev_to_shost(&starget->dev);
1471 ioc = shost_priv(shost);
1472 if (starget->channel == RAID_CHANNEL) {
1473 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1474 raid_device = _scsih_raid_device_find_by_id(ioc,
1475 starget->id, starget->channel);
1477 raid_device->sdev = sdev; /* raid is single lun */
1478 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1481 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1482 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1483 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
1484 sas_target_priv_data->sas_address);
1485 if (sas_device && (sas_device->starget == NULL)) {
1486 sdev_printk(KERN_INFO, sdev,
1487 "%s : sas_device->starget set to starget @ %d\n",
1488 __func__, __LINE__);
1489 sas_device->starget = starget;
1493 sas_device_put(sas_device);
1495 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1502 * _scsih_slave_destroy - device destroy routine
1503 * @sdev: scsi device struct
1508 _scsih_slave_destroy(struct scsi_device *sdev)
1510 struct MPT2SAS_TARGET *sas_target_priv_data;
1511 struct scsi_target *starget;
1512 struct Scsi_Host *shost;
1513 struct MPT2SAS_ADAPTER *ioc;
1514 struct _sas_device *sas_device;
1515 unsigned long flags;
1517 if (!sdev->hostdata)
1520 starget = scsi_target(sdev);
1521 sas_target_priv_data = starget->hostdata;
1522 sas_target_priv_data->num_luns--;
1524 shost = dev_to_shost(&starget->dev);
1525 ioc = shost_priv(shost);
1527 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1528 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1529 sas_device = __mpt2sas_get_sdev_from_target(ioc,
1530 sas_target_priv_data);
1531 if (sas_device && !sas_target_priv_data->num_luns)
1532 sas_device->starget = NULL;
1535 sas_device_put(sas_device);
1536 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1539 kfree(sdev->hostdata);
1540 sdev->hostdata = NULL;
1544 * _scsih_display_sata_capabilities - sata capabilities
1545 * @ioc: per adapter object
1546 * @handle: device handle
1547 * @sdev: scsi device struct
1550 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1551 u16 handle, struct scsi_device *sdev)
1553 Mpi2ConfigReply_t mpi_reply;
1554 Mpi2SasDevicePage0_t sas_device_pg0;
1559 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1560 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1561 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1562 ioc->name, __FILE__, __LINE__, __func__);
1566 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1567 MPI2_IOCSTATUS_MASK;
1568 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1569 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1570 ioc->name, __FILE__, __LINE__, __func__);
1574 flags = le16_to_cpu(sas_device_pg0.Flags);
1575 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1577 sdev_printk(KERN_INFO, sdev,
1578 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1579 "sw_preserve(%s)\n",
1580 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1581 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1582 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1584 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1585 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1586 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1590 * _scsih_is_raid - return boolean indicating device is raid volume
1591 * @dev the device struct object
1594 _scsih_is_raid(struct device *dev)
1596 struct scsi_device *sdev = to_scsi_device(dev);
1597 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1599 if (ioc->is_warpdrive)
1601 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1605 * _scsih_get_resync - get raid volume resync percent complete
1606 * @dev the device struct object
1609 _scsih_get_resync(struct device *dev)
1611 struct scsi_device *sdev = to_scsi_device(dev);
1612 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1613 static struct _raid_device *raid_device;
1614 unsigned long flags;
1615 Mpi2RaidVolPage0_t vol_pg0;
1616 Mpi2ConfigReply_t mpi_reply;
1617 u32 volume_status_flags;
1618 u8 percent_complete;
1621 percent_complete = 0;
1623 if (ioc->is_warpdrive)
1626 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1627 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1630 handle = raid_device->handle;
1631 percent_complete = raid_device->percent_complete;
1633 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1638 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1639 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1640 sizeof(Mpi2RaidVolPage0_t))) {
1641 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1642 ioc->name, __FILE__, __LINE__, __func__);
1643 percent_complete = 0;
1647 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1648 if (!(volume_status_flags &
1649 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1650 percent_complete = 0;
1653 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1657 * _scsih_get_state - get raid volume level
1658 * @dev the device struct object
1661 _scsih_get_state(struct device *dev)
1663 struct scsi_device *sdev = to_scsi_device(dev);
1664 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1665 static struct _raid_device *raid_device;
1666 unsigned long flags;
1667 Mpi2RaidVolPage0_t vol_pg0;
1668 Mpi2ConfigReply_t mpi_reply;
1670 enum raid_state state = RAID_STATE_UNKNOWN;
1673 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1674 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1677 handle = raid_device->handle;
1678 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1683 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1684 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1685 sizeof(Mpi2RaidVolPage0_t))) {
1686 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1687 ioc->name, __FILE__, __LINE__, __func__);
1691 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1692 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1693 state = RAID_STATE_RESYNCING;
1697 switch (vol_pg0.VolumeState) {
1698 case MPI2_RAID_VOL_STATE_OPTIMAL:
1699 case MPI2_RAID_VOL_STATE_ONLINE:
1700 state = RAID_STATE_ACTIVE;
1702 case MPI2_RAID_VOL_STATE_DEGRADED:
1703 state = RAID_STATE_DEGRADED;
1705 case MPI2_RAID_VOL_STATE_FAILED:
1706 case MPI2_RAID_VOL_STATE_MISSING:
1707 state = RAID_STATE_OFFLINE;
1711 raid_set_state(mpt2sas_raid_template, dev, state);
1715 * _scsih_set_level - set raid level
1716 * @sdev: scsi device struct
1717 * @volume_type: volume type
1720 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1722 enum raid_level level = RAID_LEVEL_UNKNOWN;
1724 switch (volume_type) {
1725 case MPI2_RAID_VOL_TYPE_RAID0:
1726 level = RAID_LEVEL_0;
1728 case MPI2_RAID_VOL_TYPE_RAID10:
1729 level = RAID_LEVEL_10;
1731 case MPI2_RAID_VOL_TYPE_RAID1E:
1732 level = RAID_LEVEL_1E;
1734 case MPI2_RAID_VOL_TYPE_RAID1:
1735 level = RAID_LEVEL_1;
1739 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1743 * _scsih_get_volume_capabilities - volume capabilities
1744 * @ioc: per adapter object
1745 * @sas_device: the raid_device object
1747 * Returns 0 for success, else 1
1750 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1751 struct _raid_device *raid_device)
1753 Mpi2RaidVolPage0_t *vol_pg0;
1754 Mpi2RaidPhysDiskPage0_t pd_pg0;
1755 Mpi2SasDevicePage0_t sas_device_pg0;
1756 Mpi2ConfigReply_t mpi_reply;
1760 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1761 &num_pds)) || !num_pds) {
1762 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1763 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1768 raid_device->num_pds = num_pds;
1769 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1770 sizeof(Mpi2RaidVol0PhysDisk_t));
1771 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1773 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1774 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1779 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1780 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1781 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1782 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1788 raid_device->volume_type = vol_pg0->VolumeType;
1790 /* figure out what the underlying devices are by
1791 * obtaining the device_info bits for the 1st device
1793 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1794 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1795 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1796 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1797 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1798 le16_to_cpu(pd_pg0.DevHandle)))) {
1799 raid_device->device_info =
1800 le32_to_cpu(sas_device_pg0.DeviceInfo);
1808 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1809 * @ioc: per adapter object
1812 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1814 Mpi2RaidVolPage1_t vol_pg1;
1815 Mpi2ConfigReply_t mpi_reply;
1816 struct _raid_device *raid_device;
1819 unsigned long flags;
1822 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1823 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1824 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1825 MPI2_IOCSTATUS_MASK;
1826 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1828 handle = le16_to_cpu(vol_pg1.DevHandle);
1829 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1830 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1832 raid_device->direct_io_enabled = 0;
1833 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1840 * _scsih_get_num_volumes - Get number of volumes in the ioc
1841 * @ioc: per adapter object
1844 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1846 Mpi2RaidVolPage1_t vol_pg1;
1847 Mpi2ConfigReply_t mpi_reply;
1853 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1854 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1855 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1856 MPI2_IOCSTATUS_MASK;
1857 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1860 handle = le16_to_cpu(vol_pg1.DevHandle);
1867 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1868 * @ioc: per adapter object
1869 * @raid_device: the raid_device object
1872 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1873 struct _raid_device *raid_device)
1875 Mpi2RaidVolPage0_t *vol_pg0;
1876 Mpi2RaidPhysDiskPage0_t pd_pg0;
1877 Mpi2ConfigReply_t mpi_reply;
1880 unsigned long stripe_sz, block_sz;
1881 u8 stripe_exp, block_exp;
1884 if (!ioc->is_warpdrive)
1887 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1888 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1889 "globally as drives are exposed\n", ioc->name);
1892 if (_scsih_get_num_volumes(ioc) > 1) {
1893 _scsih_disable_ddio(ioc);
1894 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1895 "globally as number of drives > 1\n", ioc->name);
1898 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1899 &num_pds)) || !num_pds) {
1900 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1901 "Failure in computing number of drives\n", ioc->name);
1905 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1906 sizeof(Mpi2RaidVol0PhysDisk_t));
1907 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1909 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1910 "Memory allocation failure for RVPG0\n", ioc->name);
1914 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1915 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1916 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1917 "Failure in retrieving RVPG0\n", ioc->name);
1923 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1924 * assumed for WARPDRIVE, disable direct I/O
1926 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1927 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1928 "for the drive with handle(0x%04x): num_mem=%d, "
1929 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1930 num_pds, MPT_MAX_WARPDRIVE_PDS);
1934 for (count = 0; count < num_pds; count++) {
1935 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1936 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1937 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1938 le16_to_cpu(pd_pg0.DevHandle) ==
1939 MPT2SAS_INVALID_DEVICE_HANDLE) {
1940 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1941 "disabled for the drive with handle(0x%04x) member"
1942 "handle retrieval failed for member number=%d\n",
1943 ioc->name, raid_device->handle,
1944 vol_pg0->PhysDisk[count].PhysDiskNum);
1947 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1948 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1949 if (dev_max_lba >> 32) {
1950 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1951 "disabled for the drive with handle(0x%04x) member"
1952 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1953 ioc->name, raid_device->handle,
1954 le16_to_cpu(pd_pg0.DevHandle),
1955 (unsigned long long)dev_max_lba);
1959 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1963 * Assumption for WD: Direct I/O is not supported if the volume is
1966 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
1967 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1968 "for the drive with handle(0x%04x): type=%d, "
1969 "s_sz=%uK, blk_size=%u\n", ioc->name,
1970 raid_device->handle, raid_device->volume_type,
1971 (le32_to_cpu(vol_pg0->StripeSize) *
1972 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
1973 le16_to_cpu(vol_pg0->BlockSize));
1977 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1978 stripe_exp = find_first_bit(&stripe_sz, 32);
1979 if (stripe_exp == 32) {
1980 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1981 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1982 ioc->name, raid_device->handle,
1983 (le32_to_cpu(vol_pg0->StripeSize) *
1984 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
1987 raid_device->stripe_exponent = stripe_exp;
1988 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1989 block_exp = find_first_bit(&block_sz, 16);
1990 if (block_exp == 16) {
1991 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1992 "for the drive with handle(0x%04x) invalid block sz %u\n",
1993 ioc->name, raid_device->handle,
1994 le16_to_cpu(vol_pg0->BlockSize));
1997 raid_device->block_exponent = block_exp;
1998 raid_device->direct_io_enabled = 1;
2000 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
2001 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
2003 * WARPDRIVE: Though the following fields are not used for direct IO,
2004 * stored for future purpose:
2006 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
2007 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
2008 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
2015 raid_device->direct_io_enabled = 0;
2016 for (count = 0; count < num_pds; count++)
2017 raid_device->pd_handle[count] = 0;
2023 * _scsih_enable_tlr - setting TLR flags
2024 * @ioc: per adapter object
2025 * @sdev: scsi device struct
2027 * Enabling Transaction Layer Retries for tape devices when
2028 * vpd page 0x90 is present
2032 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
2035 if (sdev->type != TYPE_TAPE)
2038 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2041 sas_enable_tlr(sdev);
2042 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2043 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2049 * _scsih_slave_configure - device configure routine.
2050 * @sdev: scsi device struct
2052 * Returns 0 if ok. Any other return is assumed to be an error and
2053 * the device is ignored.
2056 _scsih_slave_configure(struct scsi_device *sdev)
2058 struct Scsi_Host *shost = sdev->host;
2059 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2060 struct MPT2SAS_DEVICE *sas_device_priv_data;
2061 struct MPT2SAS_TARGET *sas_target_priv_data;
2062 struct _sas_device *sas_device;
2063 struct _raid_device *raid_device;
2064 unsigned long flags;
2069 u16 handle, volume_handle = 0;
2070 u64 volume_wwid = 0;
2073 sas_device_priv_data = sdev->hostdata;
2074 sas_device_priv_data->configured_lun = 1;
2075 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2076 sas_target_priv_data = sas_device_priv_data->sas_target;
2077 handle = sas_target_priv_data->handle;
2079 /* raid volume handling */
2080 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2082 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2083 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
2084 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2086 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2087 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2088 __LINE__, __func__));
2092 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2093 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2094 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2095 __LINE__, __func__));
2099 * WARPDRIVE: Initialize the required data for Direct IO
2101 _scsih_init_warpdrive_properties(ioc, raid_device);
2103 /* RAID Queue Depth Support
2104 * IS volume = underlying qdepth of drive type, either
2105 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2106 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2108 if (raid_device->device_info &
2109 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2110 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2113 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2114 if (raid_device->device_info &
2115 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2121 switch (raid_device->volume_type) {
2122 case MPI2_RAID_VOL_TYPE_RAID0:
2125 case MPI2_RAID_VOL_TYPE_RAID1E:
2126 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2127 if (ioc->manu_pg10.OEMIdentifier &&
2128 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2129 MFG10_GF0_R10_DISPLAY) &&
2130 !(raid_device->num_pds % 2))
2135 case MPI2_RAID_VOL_TYPE_RAID1:
2136 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2139 case MPI2_RAID_VOL_TYPE_RAID10:
2140 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2143 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2145 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2150 if (!ioc->hide_ir_msg)
2151 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2152 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2153 r_level, raid_device->handle,
2154 (unsigned long long)raid_device->wwid,
2155 raid_device->num_pds, ds);
2156 _scsih_change_queue_depth(sdev, qdepth);
2157 /* raid transport support */
2158 if (!ioc->is_warpdrive)
2159 _scsih_set_level(sdev, raid_device->volume_type);
2163 /* non-raid handling */
2164 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2165 if (mpt2sas_config_get_volume_handle(ioc, handle,
2167 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2168 "failure at %s:%d/%s()!\n", ioc->name,
2169 __FILE__, __LINE__, __func__));
2172 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2173 volume_handle, &volume_wwid)) {
2174 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2175 "failure at %s:%d/%s()!\n", ioc->name,
2176 __FILE__, __LINE__, __func__));
2181 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2182 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
2183 sas_device_priv_data->sas_target->sas_address);
2185 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2186 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2187 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2188 __LINE__, __func__));
2191 sas_device->volume_handle = volume_handle;
2192 sas_device->volume_wwid = volume_wwid;
2193 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2194 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2198 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2199 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2201 else if (sas_device->device_info &
2202 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2205 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2206 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2207 ds, sas_device->handle,
2208 (unsigned long long)sas_device->sas_address,
2210 (unsigned long long)sas_device->device_name);
2211 sdev_printk(KERN_INFO, sdev, "%s: "
2212 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2213 (unsigned long long) sas_device->enclosure_logical_id,
2216 sas_device_put(sas_device);
2217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2219 _scsih_display_sata_capabilities(ioc, handle, sdev);
2221 _scsih_change_queue_depth(sdev, qdepth);
2224 sas_read_port_mode_page(sdev);
2225 _scsih_enable_tlr(ioc, sdev);
2232 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2233 * @sdev: scsi device struct
2234 * @bdev: pointer to block device context
2235 * @capacity: device size (in 512 byte sectors)
2236 * @params: three element array to place output:
2237 * params[0] number of heads (max 255)
2238 * params[1] number of sectors (max 63)
2239 * params[2] number of cylinders
2244 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2245 sector_t capacity, int params[])
2255 dummy = heads * sectors;
2256 cylinders = capacity;
2257 sector_div(cylinders, dummy);
2260 * Handle extended translation size for logical drives
2263 if ((ulong)capacity >= 0x200000) {
2266 dummy = heads * sectors;
2267 cylinders = capacity;
2268 sector_div(cylinders, dummy);
2273 params[1] = sectors;
2274 params[2] = cylinders;
2280 * _scsih_response_code - translation of device response code
2281 * @ioc: per adapter object
2282 * @response_code: response code returned by the device
2287 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2291 switch (response_code) {
2292 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2293 desc = "task management request completed";
2295 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2296 desc = "invalid frame";
2298 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2299 desc = "task management request not supported";
2301 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2302 desc = "task management request failed";
2304 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2305 desc = "task management request succeeded";
2307 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2308 desc = "invalid lun";
2311 desc = "overlapped tag attempted";
2313 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2314 desc = "task queued, however not sent to target";
2320 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2321 ioc->name, response_code, desc);
2325 * _scsih_tm_done - tm completion routine
2326 * @ioc: per adapter object
2327 * @smid: system request message index
2328 * @msix_index: MSIX table index supplied by the OS
2329 * @reply: reply message frame(lower 32bit addr)
2332 * The callback handler when using scsih_issue_tm.
2334 * Return 1 meaning mf should be freed from _base_interrupt
2335 * 0 means the mf is freed from this function.
2338 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2340 MPI2DefaultReply_t *mpi_reply;
2342 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2344 if (ioc->tm_cmds.smid != smid)
2346 mpt2sas_base_flush_reply_queues(ioc);
2347 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2348 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2350 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2351 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2353 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2354 complete(&ioc->tm_cmds.done);
2359 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2360 * @ioc: per adapter object
2361 * @handle: device handle
2363 * During taskmangement request, we need to freeze the device queue.
2366 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2368 struct MPT2SAS_DEVICE *sas_device_priv_data;
2369 struct scsi_device *sdev;
2372 shost_for_each_device(sdev, ioc->shost) {
2375 sas_device_priv_data = sdev->hostdata;
2376 if (!sas_device_priv_data)
2378 if (sas_device_priv_data->sas_target->handle == handle) {
2379 sas_device_priv_data->sas_target->tm_busy = 1;
2381 ioc->ignore_loginfos = 1;
2387 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2388 * @ioc: per adapter object
2389 * @handle: device handle
2391 * During taskmangement request, we need to freeze the device queue.
2394 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2396 struct MPT2SAS_DEVICE *sas_device_priv_data;
2397 struct scsi_device *sdev;
2400 shost_for_each_device(sdev, ioc->shost) {
2403 sas_device_priv_data = sdev->hostdata;
2404 if (!sas_device_priv_data)
2406 if (sas_device_priv_data->sas_target->handle == handle) {
2407 sas_device_priv_data->sas_target->tm_busy = 0;
2409 ioc->ignore_loginfos = 0;
2416 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2417 * @ioc: per adapter struct
2418 * @device_handle: device handle
2419 * @channel: the channel assigned by the OS
2420 * @id: the id assigned by the OS
2422 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2423 * @smid_task: smid assigned to the task
2424 * @timeout: timeout in seconds
2425 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2428 * A generic API for sending task management requests to firmware.
2430 * The callback index is set inside `ioc->tm_cb_idx`.
2432 * Return SUCCESS or FAILED.
2435 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2436 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2437 enum mutex_type m_type)
2439 Mpi2SCSITaskManagementRequest_t *mpi_request;
2440 Mpi2SCSITaskManagementReply_t *mpi_reply;
2443 unsigned long timeleft;
2444 struct scsiio_tracker *scsi_lookup = NULL;
2447 if (m_type == TM_MUTEX_ON)
2448 mutex_lock(&ioc->tm_cmds.mutex);
2449 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2450 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2451 __func__, ioc->name);
2456 if (ioc->shost_recovery || ioc->remove_host ||
2457 ioc->pci_error_recovery) {
2458 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2459 __func__, ioc->name);
2464 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2465 if (ioc_state & MPI2_DOORBELL_USED) {
2466 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2467 "active!\n", ioc->name));
2468 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2470 rc = (!rc) ? SUCCESS : FAILED;
2474 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2475 mpt2sas_base_fault_info(ioc, ioc_state &
2476 MPI2_DOORBELL_DATA_MASK);
2477 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2479 rc = (!rc) ? SUCCESS : FAILED;
2483 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2485 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2486 ioc->name, __func__);
2491 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2492 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2494 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2495 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2497 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2498 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2499 ioc->tm_cmds.smid = smid;
2500 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2501 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2502 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2503 mpi_request->DevHandle = cpu_to_le16(handle);
2504 mpi_request->TaskType = type;
2505 mpi_request->TaskMID = cpu_to_le16(smid_task);
2506 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2507 mpt2sas_scsih_set_tm_flag(ioc, handle);
2508 init_completion(&ioc->tm_cmds.done);
2509 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2510 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2511 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2512 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2513 ioc->name, __func__);
2514 _debug_dump_mf(mpi_request,
2515 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2516 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2517 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2519 rc = (!rc) ? SUCCESS : FAILED;
2520 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2521 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2526 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2527 mpi_reply = ioc->tm_cmds.reply;
2528 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2529 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2530 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2531 le32_to_cpu(mpi_reply->IOCLogInfo),
2532 le32_to_cpu(mpi_reply->TerminationCount)));
2533 if (ioc->logging_level & MPT_DEBUG_TM) {
2534 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2535 if (mpi_reply->IOCStatus)
2536 _debug_dump_mf(mpi_request,
2537 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2542 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2544 if (scsi_lookup->scmd == NULL)
2549 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2550 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2556 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2557 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2558 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2563 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2571 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2572 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2573 if (m_type == TM_MUTEX_ON)
2574 mutex_unlock(&ioc->tm_cmds.mutex);
2579 if (m_type == TM_MUTEX_ON)
2580 mutex_unlock(&ioc->tm_cmds.mutex);
2585 * _scsih_tm_display_info - displays info about the device
2586 * @ioc: per adapter struct
2587 * @scmd: pointer to scsi command object
2589 * Called by task management callback handlers.
2592 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2594 struct scsi_target *starget = scmd->device->sdev_target;
2595 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2596 struct _sas_device *sas_device = NULL;
2597 unsigned long flags;
2598 char *device_str = NULL;
2602 if (ioc->hide_ir_msg)
2603 device_str = "WarpDrive";
2605 device_str = "volume";
2607 scsi_print_command(scmd);
2608 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2609 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2610 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2611 device_str, (unsigned long long)priv_target->sas_address);
2613 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2614 sas_device = __mpt2sas_get_sdev_from_target(ioc, priv_target);
2616 if (priv_target->flags &
2617 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2618 starget_printk(KERN_INFO, starget,
2619 "volume handle(0x%04x), "
2620 "volume wwid(0x%016llx)\n",
2621 sas_device->volume_handle,
2622 (unsigned long long)sas_device->volume_wwid);
2624 starget_printk(KERN_INFO, starget,
2625 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2627 (unsigned long long)sas_device->sas_address,
2629 starget_printk(KERN_INFO, starget,
2630 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2631 (unsigned long long)sas_device->enclosure_logical_id,
2634 sas_device_put(sas_device);
2636 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2641 * _scsih_abort - eh threads main abort routine
2642 * @scmd: pointer to scsi command object
2644 * Returns SUCCESS if command aborted else FAILED
2647 _scsih_abort(struct scsi_cmnd *scmd)
2649 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2650 struct MPT2SAS_DEVICE *sas_device_priv_data;
2655 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2656 "scmd(%p)\n", scmd);
2657 _scsih_tm_display_info(ioc, scmd);
2659 sas_device_priv_data = scmd->device->hostdata;
2660 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2661 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2662 "scmd(%p)\n", scmd);
2663 scmd->result = DID_NO_CONNECT << 16;
2664 scmd->scsi_done(scmd);
2669 /* search for the command */
2670 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2672 scmd->result = DID_RESET << 16;
2677 /* for hidden raid components and volumes this is not supported */
2678 if (sas_device_priv_data->sas_target->flags &
2679 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2680 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2681 scmd->result = DID_RESET << 16;
2686 mpt2sas_halt_firmware(ioc);
2688 handle = sas_device_priv_data->sas_target->handle;
2689 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2690 scmd->device->id, scmd->device->lun,
2691 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2694 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2695 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2700 * _scsih_dev_reset - eh threads main device reset routine
2701 * @scmd: pointer to scsi command object
2703 * Returns SUCCESS if command aborted else FAILED
2706 _scsih_dev_reset(struct scsi_cmnd *scmd)
2708 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2709 struct MPT2SAS_DEVICE *sas_device_priv_data;
2710 struct _sas_device *sas_device = NULL;
2714 struct scsi_target *starget = scmd->device->sdev_target;
2715 struct MPT2SAS_TARGET *target_priv_data = starget->hostdata;
2717 starget_printk(KERN_INFO, starget, "attempting device reset! "
2718 "scmd(%p)\n", scmd);
2719 _scsih_tm_display_info(ioc, scmd);
2721 sas_device_priv_data = scmd->device->hostdata;
2722 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2723 starget_printk(KERN_INFO, starget, "device been deleted! "
2724 "scmd(%p)\n", scmd);
2725 scmd->result = DID_NO_CONNECT << 16;
2726 scmd->scsi_done(scmd);
2731 /* for hidden raid components obtain the volume_handle */
2733 if (sas_device_priv_data->sas_target->flags &
2734 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2735 sas_device = mpt2sas_get_sdev_from_target(ioc,
2738 handle = sas_device->volume_handle;
2740 handle = sas_device_priv_data->sas_target->handle;
2743 scmd->result = DID_RESET << 16;
2748 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2749 scmd->device->id, scmd->device->lun,
2750 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2753 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2754 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2757 sas_device_put(sas_device);
2763 * _scsih_target_reset - eh threads main target reset routine
2764 * @scmd: pointer to scsi command object
2766 * Returns SUCCESS if command aborted else FAILED
2769 _scsih_target_reset(struct scsi_cmnd *scmd)
2771 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2772 struct MPT2SAS_DEVICE *sas_device_priv_data;
2773 struct _sas_device *sas_device = NULL;
2776 struct scsi_target *starget = scmd->device->sdev_target;
2777 struct MPT2SAS_TARGET *target_priv_data = starget->hostdata;
2779 starget_printk(KERN_INFO, starget, "attempting target reset! "
2780 "scmd(%p)\n", scmd);
2781 _scsih_tm_display_info(ioc, scmd);
2783 sas_device_priv_data = scmd->device->hostdata;
2784 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2785 starget_printk(KERN_INFO, starget, "target been deleted! "
2786 "scmd(%p)\n", scmd);
2787 scmd->result = DID_NO_CONNECT << 16;
2788 scmd->scsi_done(scmd);
2793 /* for hidden raid components obtain the volume_handle */
2795 if (sas_device_priv_data->sas_target->flags &
2796 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2797 sas_device = mpt2sas_get_sdev_from_target(ioc,
2800 handle = sas_device->volume_handle;
2802 handle = sas_device_priv_data->sas_target->handle;
2805 scmd->result = DID_RESET << 16;
2810 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2811 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2815 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2816 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2819 sas_device_put(sas_device);
2825 * _scsih_host_reset - eh threads main host reset routine
2826 * @scmd: pointer to scsi command object
2828 * Returns SUCCESS if command aborted else FAILED
2831 _scsih_host_reset(struct scsi_cmnd *scmd)
2833 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2836 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2838 scsi_print_command(scmd);
2840 if (ioc->is_driver_loading) {
2841 printk(MPT2SAS_INFO_FMT "Blocking the host reset\n",
2847 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2849 r = (retval < 0) ? FAILED : SUCCESS;
2852 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2853 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2859 * _scsih_fw_event_add - insert and queue up fw_event
2860 * @ioc: per adapter object
2861 * @fw_event: object describing the event
2862 * Context: This function will acquire ioc->fw_event_lock.
2864 * This adds the firmware event object into link list, then queues it up to
2865 * be processed from user context.
2870 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2872 unsigned long flags;
2874 if (ioc->firmware_event_thread == NULL)
2877 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2878 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2879 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2880 queue_delayed_work(ioc->firmware_event_thread,
2881 &fw_event->delayed_work, 0);
2882 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2886 * _scsih_fw_event_free - delete fw_event
2887 * @ioc: per adapter object
2888 * @fw_event: object describing the event
2889 * Context: This function will acquire ioc->fw_event_lock.
2891 * This removes firmware event object from link list, frees associated memory.
2896 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2899 unsigned long flags;
2901 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2902 list_del(&fw_event->list);
2904 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2909 * _scsih_error_recovery_delete_devices - remove devices not responding
2910 * @ioc: per adapter object
2915 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2917 struct fw_event_work *fw_event;
2919 if (ioc->is_driver_loading)
2922 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2926 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2927 fw_event->ioc = ioc;
2928 _scsih_fw_event_add(ioc, fw_event);
2932 * mpt2sas_port_enable_complete - port enable completed (fake event)
2933 * @ioc: per adapter object
2938 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2940 struct fw_event_work *fw_event;
2942 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2945 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2946 fw_event->ioc = ioc;
2947 _scsih_fw_event_add(ioc, fw_event);
2951 * _scsih_fw_event_cleanup_queue - cleanup event queue
2952 * @ioc: per adapter object
2954 * Walk the firmware event queue, either killing timers, or waiting
2955 * for outstanding events to complete
2960 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2962 struct fw_event_work *fw_event, *next;
2964 if (list_empty(&ioc->fw_event_list) ||
2965 !ioc->firmware_event_thread || in_interrupt())
2968 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2969 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2970 _scsih_fw_event_free(ioc, fw_event);
2977 * _scsih_ublock_io_all_device - unblock every device
2978 * @ioc: per adapter object
2980 * change the device state from block to running
2983 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2985 struct MPT2SAS_DEVICE *sas_device_priv_data;
2986 struct scsi_device *sdev;
2988 shost_for_each_device(sdev, ioc->shost) {
2989 sas_device_priv_data = sdev->hostdata;
2990 if (!sas_device_priv_data)
2992 if (!sas_device_priv_data->block)
2994 sas_device_priv_data->block = 0;
2995 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2997 sas_device_priv_data->sas_target->handle));
2998 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
3002 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
3003 * @ioc: per adapter object
3004 * @handle: device handle
3006 * During device pull we need to appropiately set the sdev state.
3009 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
3011 struct MPT2SAS_DEVICE *sas_device_priv_data;
3012 struct scsi_device *sdev;
3014 shost_for_each_device(sdev, ioc->shost) {
3015 sas_device_priv_data = sdev->hostdata;
3016 if (!sas_device_priv_data)
3018 if (!sas_device_priv_data->block)
3020 if (sas_device_priv_data->sas_target->sas_address ==
3022 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3023 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
3024 "sas address(0x%016llx)\n", ioc->name,
3025 (unsigned long long)sas_address));
3026 sas_device_priv_data->block = 0;
3027 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
3033 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3034 * @ioc: per adapter object
3035 * @handle: device handle
3037 * During device pull we need to appropiately set the sdev state.
3040 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
3042 struct MPT2SAS_DEVICE *sas_device_priv_data;
3043 struct scsi_device *sdev;
3045 shost_for_each_device(sdev, ioc->shost) {
3046 sas_device_priv_data = sdev->hostdata;
3047 if (!sas_device_priv_data)
3049 if (sas_device_priv_data->block)
3051 sas_device_priv_data->block = 1;
3052 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
3054 sas_device_priv_data->sas_target->handle));
3055 scsi_internal_device_block(sdev);
3061 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3062 * @ioc: per adapter object
3063 * @handle: device handle
3065 * During device pull we need to appropiately set the sdev state.
3068 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3070 struct MPT2SAS_DEVICE *sas_device_priv_data;
3071 struct scsi_device *sdev;
3073 shost_for_each_device(sdev, ioc->shost) {
3074 sas_device_priv_data = sdev->hostdata;
3075 if (!sas_device_priv_data)
3077 if (sas_device_priv_data->block)
3079 if (sas_device_priv_data->sas_target->handle == handle) {
3080 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3081 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
3082 "handle(0x%04x)\n", ioc->name, handle));
3083 sas_device_priv_data->block = 1;
3084 scsi_internal_device_block(sdev);
3090 * _scsih_block_io_to_children_attached_to_ex
3091 * @ioc: per adapter object
3092 * @sas_expander: the sas_device object
3094 * This routine set sdev state to SDEV_BLOCK for all devices
3095 * attached to this expander. This function called when expander is
3099 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3100 struct _sas_node *sas_expander)
3102 struct _sas_port *mpt2sas_port;
3103 struct _sas_device *sas_device;
3104 struct _sas_node *expander_sibling;
3105 unsigned long flags;
3110 list_for_each_entry(mpt2sas_port,
3111 &sas_expander->sas_port_list, port_list) {
3112 if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) {
3113 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3114 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
3115 mpt2sas_port->remote_identify.sas_address);
3117 set_bit(sas_device->handle,
3118 ioc->blocking_handles);
3119 sas_device_put(sas_device);
3121 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3125 list_for_each_entry(mpt2sas_port,
3126 &sas_expander->sas_port_list, port_list) {
3128 if (mpt2sas_port->remote_identify.device_type ==
3129 SAS_EDGE_EXPANDER_DEVICE ||
3130 mpt2sas_port->remote_identify.device_type ==
3131 SAS_FANOUT_EXPANDER_DEVICE) {
3133 mpt2sas_scsih_expander_find_by_sas_address(
3134 ioc, mpt2sas_port->remote_identify.sas_address);
3135 _scsih_block_io_to_children_attached_to_ex(ioc,
3142 * _scsih_block_io_to_children_attached_directly
3143 * @ioc: per adapter object
3144 * @event_data: topology change event data
3146 * This routine set sdev state to SDEV_BLOCK for all devices
3147 * direct attached during device pull.
3150 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3151 Mpi2EventDataSasTopologyChangeList_t *event_data)
3158 for (i = 0; i < event_data->NumEntries; i++) {
3159 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3162 phy_number = event_data->StartPhyNum + i;
3163 reason_code = event_data->PHY[i].PhyStatus &
3164 MPI2_EVENT_SAS_TOPO_RC_MASK;
3165 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3166 _scsih_block_io_device(ioc, handle);
3171 * _scsih_tm_tr_send - send task management request
3172 * @ioc: per adapter object
3173 * @handle: device handle
3174 * Context: interrupt time.
3176 * This code is to initiate the device removal handshake protocol
3177 * with controller firmware. This function will issue target reset
3178 * using high priority request queue. It will send a sas iounit
3179 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3181 * This is designed to send muliple task management request at the same
3182 * time to the fifo. If the fifo is full, we will append the request,
3183 * and process it in a future completion.
3186 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3188 Mpi2SCSITaskManagementRequest_t *mpi_request;
3190 struct _sas_device *sas_device = NULL;
3191 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3192 u64 sas_address = 0;
3193 unsigned long flags;
3194 struct _tr_list *delayed_tr;
3197 if (ioc->remove_host) {
3198 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3199 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3201 } else if (ioc->pci_error_recovery) {
3202 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3203 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3207 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3208 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3209 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3210 "operational: handle(0x%04x)\n", __func__, ioc->name,
3215 /* if PD, then return */
3216 if (test_bit(handle, ioc->pd_handles))
3219 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3220 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
3221 if (sas_device && sas_device->starget &&
3222 sas_device->starget->hostdata) {
3223 sas_target_priv_data = sas_device->starget->hostdata;
3224 sas_target_priv_data->deleted = 1;
3225 sas_address = sas_device->sas_address;
3227 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3229 if (sas_target_priv_data) {
3230 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3231 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3232 (unsigned long long)sas_address));
3233 _scsih_ublock_io_device(ioc, sas_address);
3234 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3237 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3239 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3242 INIT_LIST_HEAD(&delayed_tr->list);
3243 delayed_tr->handle = handle;
3244 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3245 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3246 "DELAYED:tr:handle(0x%04x), (open)\n",
3247 ioc->name, handle));
3251 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3252 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3253 ioc->tm_tr_cb_idx));
3254 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3255 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3256 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3257 mpi_request->DevHandle = cpu_to_le16(handle);
3258 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3259 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3262 sas_device_put(sas_device);
3268 * _scsih_sas_control_complete - completion routine
3269 * @ioc: per adapter object
3270 * @smid: system request message index
3271 * @msix_index: MSIX table index supplied by the OS
3272 * @reply: reply message frame(lower 32bit addr)
3273 * Context: interrupt time.
3275 * This is the sas iounit control completion routine.
3276 * This code is part of the code to initiate the device removal
3277 * handshake protocol with controller firmware.
3279 * Return 1 meaning mf should be freed from _base_interrupt
3280 * 0 means the mf is freed from this function.
3283 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3284 u8 msix_index, u32 reply)
3286 Mpi2SasIoUnitControlReply_t *mpi_reply =
3287 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3288 if (likely(mpi_reply)) {
3289 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3290 "sc_complete:handle(0x%04x), (open) "
3291 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3292 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3293 le16_to_cpu(mpi_reply->IOCStatus),
3294 le32_to_cpu(mpi_reply->IOCLogInfo)));
3296 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3297 ioc->name, __FILE__, __LINE__, __func__);
3303 * _scsih_tm_tr_volume_send - send target reset request for volumes
3304 * @ioc: per adapter object
3305 * @handle: device handle
3306 * Context: interrupt time.
3308 * This is designed to send muliple task management request at the same
3309 * time to the fifo. If the fifo is full, we will append the request,
3310 * and process it in a future completion.
3313 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3315 Mpi2SCSITaskManagementRequest_t *mpi_request;
3317 struct _tr_list *delayed_tr;
3319 if (ioc->shost_recovery || ioc->remove_host ||
3320 ioc->pci_error_recovery) {
3321 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3322 "progress!\n", __func__, ioc->name));
3326 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3328 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3331 INIT_LIST_HEAD(&delayed_tr->list);
3332 delayed_tr->handle = handle;
3333 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3334 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3335 "DELAYED:tr:handle(0x%04x), (open)\n",
3336 ioc->name, handle));
3340 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3341 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3342 ioc->tm_tr_volume_cb_idx));
3343 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3344 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3345 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3346 mpi_request->DevHandle = cpu_to_le16(handle);
3347 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3348 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3352 * _scsih_tm_volume_tr_complete - target reset completion
3353 * @ioc: per adapter object
3354 * @smid: system request message index
3355 * @msix_index: MSIX table index supplied by the OS
3356 * @reply: reply message frame(lower 32bit addr)
3357 * Context: interrupt time.
3359 * Return 1 meaning mf should be freed from _base_interrupt
3360 * 0 means the mf is freed from this function.
3363 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3364 u8 msix_index, u32 reply)
3367 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3368 Mpi2SCSITaskManagementReply_t *mpi_reply =
3369 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3371 if (ioc->shost_recovery || ioc->remove_host ||
3372 ioc->pci_error_recovery) {
3373 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3374 "progress!\n", __func__, ioc->name));
3377 if (unlikely(!mpi_reply)) {
3378 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3379 ioc->name, __FILE__, __LINE__, __func__);
3382 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3383 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3384 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3385 dewtprintk(ioc, printk("spurious interrupt: "
3386 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3387 le16_to_cpu(mpi_reply->DevHandle), smid));
3391 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3392 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3393 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3394 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3395 le32_to_cpu(mpi_reply->IOCLogInfo),
3396 le32_to_cpu(mpi_reply->TerminationCount)));
3398 return _scsih_check_for_pending_tm(ioc, smid);
3402 * _scsih_tm_tr_complete -
3403 * @ioc: per adapter object
3404 * @smid: system request message index
3405 * @msix_index: MSIX table index supplied by the OS
3406 * @reply: reply message frame(lower 32bit addr)
3407 * Context: interrupt time.
3409 * This is the target reset completion routine.
3410 * This code is part of the code to initiate the device removal
3411 * handshake protocol with controller firmware.
3412 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3414 * Return 1 meaning mf should be freed from _base_interrupt
3415 * 0 means the mf is freed from this function.
3418 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3422 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3423 Mpi2SCSITaskManagementReply_t *mpi_reply =
3424 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3425 Mpi2SasIoUnitControlRequest_t *mpi_request;
3429 if (ioc->remove_host) {
3430 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3431 "removed\n", __func__, ioc->name));
3433 } else if (ioc->pci_error_recovery) {
3434 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3435 "error recovery\n", __func__, ioc->name));
3438 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3439 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3440 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3441 "operational\n", __func__, ioc->name));
3444 if (unlikely(!mpi_reply)) {
3445 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3446 ioc->name, __FILE__, __LINE__, __func__);
3449 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3450 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3451 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3452 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3453 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3454 le16_to_cpu(mpi_reply->DevHandle), smid));
3458 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3459 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3460 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3461 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3462 le32_to_cpu(mpi_reply->IOCLogInfo),
3463 le32_to_cpu(mpi_reply->TerminationCount)));
3465 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3466 if (!smid_sas_ctrl) {
3467 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3468 ioc->name, __func__);
3472 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3473 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3474 ioc->tm_sas_control_cb_idx));
3475 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3476 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3477 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3478 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3479 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3480 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3482 return _scsih_check_for_pending_tm(ioc, smid);
3486 * _scsih_check_for_pending_tm - check for pending task management
3487 * @ioc: per adapter object
3488 * @smid: system request message index
3490 * This will check delayed target reset list, and feed the
3493 * Return 1 meaning mf should be freed from _base_interrupt
3494 * 0 means the mf is freed from this function.
3497 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3499 struct _tr_list *delayed_tr;
3501 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3502 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3503 struct _tr_list, list);
3504 mpt2sas_base_free_smid(ioc, smid);
3505 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3506 list_del(&delayed_tr->list);
3511 if (!list_empty(&ioc->delayed_tr_list)) {
3512 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3513 struct _tr_list, list);
3514 mpt2sas_base_free_smid(ioc, smid);
3515 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3516 list_del(&delayed_tr->list);
3525 * _scsih_check_topo_delete_events - sanity check on topo events
3526 * @ioc: per adapter object
3527 * @event_data: the event data payload
3529 * This routine added to better handle cable breaker.
3531 * This handles the case where driver receives multiple expander
3532 * add and delete events in a single shot. When there is a delete event
3533 * the routine will void any pending add events waiting in the event queue.
3538 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3539 Mpi2EventDataSasTopologyChangeList_t *event_data)
3541 struct fw_event_work *fw_event;
3542 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3543 u16 expander_handle;
3544 struct _sas_node *sas_expander;
3545 unsigned long flags;
3549 for (i = 0 ; i < event_data->NumEntries; i++) {
3550 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3553 reason_code = event_data->PHY[i].PhyStatus &
3554 MPI2_EVENT_SAS_TOPO_RC_MASK;
3555 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3556 _scsih_tm_tr_send(ioc, handle);
3559 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3560 if (expander_handle < ioc->sas_hba.num_phys) {
3561 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3564 if (event_data->ExpStatus ==
3565 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3566 /* put expander attached devices into blocking state */
3567 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3568 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3570 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3571 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3573 handle = find_first_bit(ioc->blocking_handles,
3574 ioc->facts.MaxDevHandle);
3575 if (handle < ioc->facts.MaxDevHandle)
3576 _scsih_block_io_device(ioc, handle);
3577 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3578 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3579 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3581 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3584 /* mark ignore flag for pending events */
3585 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3586 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3587 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3590 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3591 fw_event->event_data;
3592 if (local_event_data->ExpStatus ==
3593 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3594 local_event_data->ExpStatus ==
3595 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3596 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3598 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3599 "setting ignoring flag\n", ioc->name));
3600 fw_event->ignore = 1;
3604 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3608 * _scsih_set_volume_delete_flag - setting volume delete flag
3609 * @ioc: per adapter object
3610 * @handle: device handle
3616 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3618 struct _raid_device *raid_device;
3619 struct MPT2SAS_TARGET *sas_target_priv_data;
3620 unsigned long flags;
3622 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3623 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3624 if (raid_device && raid_device->starget &&
3625 raid_device->starget->hostdata) {
3626 sas_target_priv_data =
3627 raid_device->starget->hostdata;
3628 sas_target_priv_data->deleted = 1;
3629 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3630 "setting delete flag: handle(0x%04x), "
3631 "wwid(0x%016llx)\n", ioc->name, handle,
3632 (unsigned long long) raid_device->wwid));
3634 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3638 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3639 * @handle: input handle
3640 * @a: handle for volume a
3641 * @b: handle for volume b
3643 * IR firmware only supports two raid volumes. The purpose of this
3644 * routine is to set the volume handle in either a or b. When the given
3645 * input handle is non-zero, or when a and b have not been set before.
3648 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3650 if (!handle || handle == *a || handle == *b)
3659 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3660 * @ioc: per adapter object
3661 * @event_data: the event data payload
3662 * Context: interrupt time.
3664 * This routine will send target reset to volume, followed by target
3665 * resets to the PDs. This is called when a PD has been removed, or
3666 * volume has been deleted or removed. When the target reset is sent
3667 * to volume, the PD target resets need to be queued to start upon
3668 * completion of the volume target reset.
3673 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3674 Mpi2EventDataIrConfigChangeList_t *event_data)
3676 Mpi2EventIrConfigElement_t *element;
3678 u16 handle, volume_handle, a, b;
3679 struct _tr_list *delayed_tr;
3684 if (ioc->is_warpdrive)
3687 /* Volume Resets for Deleted or Removed */
3688 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3689 for (i = 0; i < event_data->NumElements; i++, element++) {
3690 if (element->ReasonCode ==
3691 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3692 element->ReasonCode ==
3693 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3694 volume_handle = le16_to_cpu(element->VolDevHandle);
3695 _scsih_set_volume_delete_flag(ioc, volume_handle);
3696 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3700 /* Volume Resets for UNHIDE events */
3701 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3702 for (i = 0; i < event_data->NumElements; i++, element++) {
3703 if (le32_to_cpu(event_data->Flags) &
3704 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3706 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3707 volume_handle = le16_to_cpu(element->VolDevHandle);
3708 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3713 _scsih_tm_tr_volume_send(ioc, a);
3715 _scsih_tm_tr_volume_send(ioc, b);
3717 /* PD target resets */
3718 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3719 for (i = 0; i < event_data->NumElements; i++, element++) {
3720 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3722 handle = le16_to_cpu(element->PhysDiskDevHandle);
3723 volume_handle = le16_to_cpu(element->VolDevHandle);
3724 clear_bit(handle, ioc->pd_handles);
3726 _scsih_tm_tr_send(ioc, handle);
3727 else if (volume_handle == a || volume_handle == b) {
3728 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3729 BUG_ON(!delayed_tr);
3730 INIT_LIST_HEAD(&delayed_tr->list);
3731 delayed_tr->handle = handle;
3732 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3733 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3734 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3737 _scsih_tm_tr_send(ioc, handle);
3743 * _scsih_check_volume_delete_events - set delete flag for volumes
3744 * @ioc: per adapter object
3745 * @event_data: the event data payload
3746 * Context: interrupt time.
3748 * This will handle the case when the cable connected to entire volume is
3749 * pulled. We will take care of setting the deleted flag so normal IO will
3755 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3756 Mpi2EventDataIrVolume_t *event_data)
3760 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3762 state = le32_to_cpu(event_data->NewValue);
3763 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3764 MPI2_RAID_VOL_STATE_FAILED)
3765 _scsih_set_volume_delete_flag(ioc,
3766 le16_to_cpu(event_data->VolDevHandle));
3770 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3771 * @ioc: per adapter object
3772 * @event_data: the temp threshold event data
3773 * Context: interrupt time.
3778 _scsih_temp_threshold_events(struct MPT2SAS_ADAPTER *ioc,
3779 Mpi2EventDataTemperature_t *event_data)
3781 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3782 printk(MPT2SAS_ERR_FMT "Temperature Threshold flags %s%s%s%s"
3783 " exceeded for Sensor: %d !!!\n", ioc->name,
3784 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3785 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3786 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3787 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3788 event_data->SensorNum);
3789 printk(MPT2SAS_ERR_FMT "Current Temp In Celsius: %d\n",
3790 ioc->name, event_data->CurrentTemperature);
3795 * _scsih_flush_running_cmds - completing outstanding commands.
3796 * @ioc: per adapter object
3798 * The flushing out of all pending scmd commands following host reset,
3799 * where all IO is dropped to the floor.
3804 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3806 struct scsi_cmnd *scmd;
3810 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3811 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3815 mpt2sas_base_free_smid(ioc, smid);
3816 scsi_dma_unmap(scmd);
3817 if (ioc->pci_error_recovery)
3818 scmd->result = DID_NO_CONNECT << 16;
3820 scmd->result = DID_RESET << 16;
3821 scmd->scsi_done(scmd);
3823 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3828 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3829 * @scmd: pointer to scsi command object
3830 * @mpi_request: pointer to the SCSI_IO reqest message frame
3832 * Supporting protection 1 and 3.
3837 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3840 unsigned char prot_op = scsi_get_prot_op(scmd);
3841 unsigned char prot_type = scsi_get_prot_type(scmd);
3843 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3846 if (prot_op == SCSI_PROT_READ_STRIP)
3847 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3848 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3849 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3853 switch (prot_type) {
3854 case SCSI_PROT_DIF_TYPE1:
3855 case SCSI_PROT_DIF_TYPE2:
3858 * enable ref/guard checking
3859 * auto increment ref tag
3861 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3862 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3863 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3864 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3865 cpu_to_be32(scsi_get_lba(scmd));
3868 case SCSI_PROT_DIF_TYPE3:
3871 * enable guard checking
3873 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3876 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3877 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3881 * _scsih_eedp_error_handling - return sense code for EEDP errors
3882 * @scmd: pointer to scsi command object
3883 * @ioc_status: ioc status
3888 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3892 switch (ioc_status) {
3893 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3896 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3899 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3907 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3908 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3909 SAM_STAT_CHECK_CONDITION;
3913 * _scsih_scsi_direct_io_get - returns direct io flag
3914 * @ioc: per adapter object
3915 * @smid: system request message index
3917 * Returns the smid stored scmd pointer.
3920 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3922 return ioc->scsi_lookup[smid - 1].direct_io;
3926 * _scsih_scsi_direct_io_set - sets direct io flag
3927 * @ioc: per adapter object
3928 * @smid: system request message index
3929 * @direct_io: Zero or non-zero value to set in the direct_io flag
3934 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3936 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3941 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3942 * @ioc: per adapter object
3943 * @scmd: pointer to scsi command object
3944 * @raid_device: pointer to raid device data structure
3945 * @mpi_request: pointer to the SCSI_IO reqest message frame
3946 * @smid: system request message index
3951 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3952 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3955 sector_t v_lba, p_lba, stripe_off, column, io_size;
3956 u32 stripe_sz, stripe_exp;
3957 u8 num_pds, cmd = scmd->cmnd[0];
3959 if (cmd != READ_10 && cmd != WRITE_10 &&
3960 cmd != READ_16 && cmd != WRITE_16)
3963 if (cmd == READ_10 || cmd == WRITE_10)
3964 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3966 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
3968 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
3970 if (v_lba + io_size - 1 > raid_device->max_lba)
3973 stripe_sz = raid_device->stripe_sz;
3974 stripe_exp = raid_device->stripe_exponent;
3975 stripe_off = v_lba & (stripe_sz - 1);
3977 /* Return unless IO falls within a stripe */
3978 if (stripe_off + io_size > stripe_sz)
3981 num_pds = raid_device->num_pds;
3982 p_lba = v_lba >> stripe_exp;
3983 column = sector_div(p_lba, num_pds);
3984 p_lba = (p_lba << stripe_exp) + stripe_off;
3986 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3988 if (cmd == READ_10 || cmd == WRITE_10)
3989 put_unaligned_be32(lower_32_bits(p_lba),
3990 &mpi_request->CDB.CDB32[2]);
3992 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3994 _scsih_scsi_direct_io_set(ioc, smid, 1);
3998 * _scsih_qcmd - main scsi request entry point
3999 * @scmd: pointer to scsi command object
4000 * @done: function pointer to be invoked on completion
4002 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4004 * Returns 0 on success. If there's a failure, return either:
4005 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4006 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4009 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4011 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
4012 struct MPT2SAS_DEVICE *sas_device_priv_data;
4013 struct MPT2SAS_TARGET *sas_target_priv_data;
4014 struct _raid_device *raid_device;
4015 Mpi2SCSIIORequest_t *mpi_request;
4019 sas_device_priv_data = scmd->device->hostdata;
4020 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4021 scmd->result = DID_NO_CONNECT << 16;
4022 scmd->scsi_done(scmd);
4026 if (ioc->pci_error_recovery || ioc->remove_host) {
4027 scmd->result = DID_NO_CONNECT << 16;
4028 scmd->scsi_done(scmd);
4032 sas_target_priv_data = sas_device_priv_data->sas_target;
4033 /* invalid device handle */
4034 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
4035 scmd->result = DID_NO_CONNECT << 16;
4036 scmd->scsi_done(scmd);
4040 /* host recovery or link resets sent via IOCTLs */
4041 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4042 return SCSI_MLQUEUE_HOST_BUSY;
4043 /* device busy with task management */
4044 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
4045 return SCSI_MLQUEUE_DEVICE_BUSY;
4046 /* device has been deleted */
4047 else if (sas_target_priv_data->deleted) {
4048 scmd->result = DID_NO_CONNECT << 16;
4049 scmd->scsi_done(scmd);
4053 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4054 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4055 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4056 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4058 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4061 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4063 /* Make sure Device is not raid volume.
4064 * We do not expose raid functionality to upper layer for warpdrive.
4066 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4067 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4068 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4070 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4072 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4073 ioc->name, __func__);
4076 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4077 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4078 _scsih_setup_eedp(scmd, mpi_request);
4079 if (scmd->cmd_len == 32)
4080 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4081 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4082 if (sas_device_priv_data->sas_target->flags &
4083 MPT_TARGET_FLAGS_RAID_COMPONENT)
4084 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4086 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4087 mpi_request->DevHandle =
4088 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4089 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4090 mpi_request->Control = cpu_to_le32(mpi_control);
4091 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4092 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4093 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4094 mpi_request->SenseBufferLowAddress =
4095 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
4096 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4097 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4098 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
4099 mpi_request->VF_ID = 0; /* TODO */
4100 mpi_request->VP_ID = 0;
4101 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4103 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4105 if (!mpi_request->DataLength) {
4106 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4108 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4109 mpt2sas_base_free_smid(ioc, smid);
4114 raid_device = sas_target_priv_data->raid_device;
4115 if (raid_device && raid_device->direct_io_enabled)
4116 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4119 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4120 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4121 le16_to_cpu(mpi_request->DevHandle));
4123 mpt2sas_base_put_smid_default(ioc, smid);
4127 return SCSI_MLQUEUE_HOST_BUSY;
4131 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4132 * @sense_buffer: sense data returned by target
4133 * @data: normalized skey/asc/ascq
4138 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4140 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4141 /* descriptor format */
4142 data->skey = sense_buffer[1] & 0x0F;
4143 data->asc = sense_buffer[2];
4144 data->ascq = sense_buffer[3];
4147 data->skey = sense_buffer[2] & 0x0F;
4148 data->asc = sense_buffer[12];
4149 data->ascq = sense_buffer[13];
4153 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4155 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4156 * @ioc: per adapter object
4157 * @scmd: pointer to scsi command object
4158 * @mpi_reply: reply mf payload returned from firmware
4160 * scsi_status - SCSI Status code returned from target device
4161 * scsi_state - state info associated with SCSI_IO determined by ioc
4162 * ioc_status - ioc supplied status info
4167 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4168 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4172 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4173 MPI2_IOCSTATUS_MASK;
4174 u8 scsi_state = mpi_reply->SCSIState;
4175 u8 scsi_status = mpi_reply->SCSIStatus;
4176 char *desc_ioc_state = NULL;
4177 char *desc_scsi_status = NULL;
4178 char *desc_scsi_state = ioc->tmp_string;
4179 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4180 struct _sas_device *sas_device = NULL;
4181 struct scsi_target *starget = scmd->device->sdev_target;
4182 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4183 char *device_str = NULL;
4188 if (ioc->hide_ir_msg)
4189 device_str = "WarpDrive";
4191 device_str = "volume";
4193 if (log_info == 0x31170000)
4196 switch (ioc_status) {
4197 case MPI2_IOCSTATUS_SUCCESS:
4198 desc_ioc_state = "success";
4200 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4201 desc_ioc_state = "invalid function";
4203 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4204 desc_ioc_state = "scsi recovered error";
4206 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4207 desc_ioc_state = "scsi invalid dev handle";
4209 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4210 desc_ioc_state = "scsi device not there";
4212 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4213 desc_ioc_state = "scsi data overrun";
4215 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4216 desc_ioc_state = "scsi data underrun";
4218 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4219 desc_ioc_state = "scsi io data error";
4221 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4222 desc_ioc_state = "scsi protocol error";
4224 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4225 desc_ioc_state = "scsi task terminated";
4227 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4228 desc_ioc_state = "scsi residual mismatch";
4230 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4231 desc_ioc_state = "scsi task mgmt failed";
4233 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4234 desc_ioc_state = "scsi ioc terminated";
4236 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4237 desc_ioc_state = "scsi ext terminated";
4239 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4240 desc_ioc_state = "eedp guard error";
4242 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4243 desc_ioc_state = "eedp ref tag error";
4245 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4246 desc_ioc_state = "eedp app tag error";
4249 desc_ioc_state = "unknown";
4253 switch (scsi_status) {
4254 case MPI2_SCSI_STATUS_GOOD:
4255 desc_scsi_status = "good";
4257 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4258 desc_scsi_status = "check condition";
4260 case MPI2_SCSI_STATUS_CONDITION_MET:
4261 desc_scsi_status = "condition met";
4263 case MPI2_SCSI_STATUS_BUSY:
4264 desc_scsi_status = "busy";
4266 case MPI2_SCSI_STATUS_INTERMEDIATE:
4267 desc_scsi_status = "intermediate";
4269 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4270 desc_scsi_status = "intermediate condmet";
4272 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4273 desc_scsi_status = "reservation conflict";
4275 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4276 desc_scsi_status = "command terminated";
4278 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4279 desc_scsi_status = "task set full";
4281 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4282 desc_scsi_status = "aca active";
4284 case MPI2_SCSI_STATUS_TASK_ABORTED:
4285 desc_scsi_status = "task aborted";
4288 desc_scsi_status = "unknown";
4292 desc_scsi_state[0] = '\0';
4294 desc_scsi_state = " ";
4295 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4296 strcat(desc_scsi_state, "response info ");
4297 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4298 strcat(desc_scsi_state, "state terminated ");
4299 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4300 strcat(desc_scsi_state, "no status ");
4301 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4302 strcat(desc_scsi_state, "autosense failed ");
4303 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4304 strcat(desc_scsi_state, "autosense valid ");
4306 scsi_print_command(scmd);
4308 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4309 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4310 device_str, (unsigned long long)priv_target->sas_address);
4312 sas_device = mpt2sas_get_sdev_from_target(ioc, priv_target);
4314 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4315 "phy(%d)\n", ioc->name, sas_device->sas_address,
4317 printk(MPT2SAS_WARN_FMT
4318 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4319 ioc->name, sas_device->enclosure_logical_id,
4322 sas_device_put(sas_device);
4326 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4327 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4328 desc_ioc_state, ioc_status, smid);
4329 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4330 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4331 scsi_get_resid(scmd));
4332 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4333 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4334 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4335 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4336 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4337 scsi_status, desc_scsi_state, scsi_state);
4339 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4340 struct sense_info data;
4341 _scsih_normalize_sense(scmd->sense_buffer, &data);
4342 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4343 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4344 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4347 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4348 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4349 response_bytes = (u8 *)&response_info;
4350 _scsih_response_code(ioc, response_bytes[0]);
4356 * _scsih_turn_on_pfa_led - illuminate PFA LED
4357 * @ioc: per adapter object
4358 * @handle: device handle
4364 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4366 Mpi2SepReply_t mpi_reply;
4367 Mpi2SepRequest_t mpi_request;
4368 struct _sas_device *sas_device;
4370 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
4374 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4375 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4376 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4377 mpi_request.SlotStatus =
4378 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4379 mpi_request.DevHandle = cpu_to_le16(handle);
4380 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4381 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4382 &mpi_request)) != 0) {
4383 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4384 __FILE__, __LINE__, __func__);
4387 sas_device->pfa_led_on = 1;
4390 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4391 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4392 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4393 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4394 le32_to_cpu(mpi_reply.IOCLogInfo)));
4398 sas_device_put(sas_device);
4402 * _scsih_turn_off_pfa_led - turn off PFA LED
4403 * @ioc: per adapter object
4404 * @sas_device: sas device whose PFA LED has to turned off
4410 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4411 struct _sas_device *sas_device)
4413 Mpi2SepReply_t mpi_reply;
4414 Mpi2SepRequest_t mpi_request;
4416 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4417 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4418 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4419 mpi_request.SlotStatus = 0;
4420 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4421 mpi_request.DevHandle = 0;
4422 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4423 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4424 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4425 &mpi_request)) != 0) {
4426 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4427 __FILE__, __LINE__, __func__);
4431 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4432 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4433 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4434 le16_to_cpu(mpi_reply.IOCStatus),
4435 le32_to_cpu(mpi_reply.IOCLogInfo)));
4441 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4442 * @ioc: per adapter object
4443 * @handle: device handle
4444 * Context: interrupt.
4449 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4451 struct fw_event_work *fw_event;
4453 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4456 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
4457 fw_event->device_handle = handle;
4458 fw_event->ioc = ioc;
4459 _scsih_fw_event_add(ioc, fw_event);
4463 * _scsih_smart_predicted_fault - process smart errors
4464 * @ioc: per adapter object
4465 * @handle: device handle
4466 * Context: interrupt.
4471 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4473 struct scsi_target *starget;
4474 struct MPT2SAS_TARGET *sas_target_priv_data;
4475 Mpi2EventNotificationReply_t *event_reply;
4476 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4477 struct _sas_device *sas_device;
4479 unsigned long flags;
4481 /* only handle non-raid devices */
4482 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4483 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
4487 starget = sas_device->starget;
4488 sas_target_priv_data = starget->hostdata;
4490 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4491 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4494 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4495 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4497 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4498 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4500 /* insert into event log */
4501 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4502 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4503 event_reply = kzalloc(sz, GFP_ATOMIC);
4505 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4506 ioc->name, __FILE__, __LINE__, __func__);
4510 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4511 event_reply->Event =
4512 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4513 event_reply->MsgLength = sz/4;
4514 event_reply->EventDataLength =
4515 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4516 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4517 event_reply->EventData;
4518 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4519 event_data->ASC = 0x5D;
4520 event_data->DevHandle = cpu_to_le16(handle);
4521 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4522 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4526 sas_device_put(sas_device);
4530 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4535 * _scsih_io_done - scsi request callback
4536 * @ioc: per adapter object
4537 * @smid: system request message index
4538 * @msix_index: MSIX table index supplied by the OS
4539 * @reply: reply message frame(lower 32bit addr)
4541 * Callback handler when using _scsih_qcmd.
4543 * Return 1 meaning mf should be freed from _base_interrupt
4544 * 0 means the mf is freed from this function.
4547 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4549 Mpi2SCSIIORequest_t *mpi_request;
4550 Mpi2SCSIIOReply_t *mpi_reply;
4551 struct scsi_cmnd *scmd;
4557 struct MPT2SAS_DEVICE *sas_device_priv_data;
4558 u32 response_code = 0;
4559 unsigned long flags;
4561 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4562 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4566 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4568 if (mpi_reply == NULL) {
4569 scmd->result = DID_OK << 16;
4573 sas_device_priv_data = scmd->device->hostdata;
4574 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4575 sas_device_priv_data->sas_target->deleted) {
4576 scmd->result = DID_NO_CONNECT << 16;
4579 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4581 * WARPDRIVE: If direct_io is set then it is directIO,
4582 * the failed direct I/O should be redirected to volume
4584 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4585 ((ioc_status & MPI2_IOCSTATUS_MASK)
4586 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4587 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4588 ioc->scsi_lookup[smid - 1].scmd = scmd;
4589 _scsih_scsi_direct_io_set(ioc, smid, 0);
4590 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4591 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4592 mpi_request->DevHandle =
4593 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4594 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4595 sas_device_priv_data->sas_target->handle);
4600 /* turning off TLR */
4601 scsi_state = mpi_reply->SCSIState;
4602 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4604 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4605 if (!sas_device_priv_data->tlr_snoop_check) {
4606 sas_device_priv_data->tlr_snoop_check++;
4607 /* Make sure Device is not raid volume.
4608 * We do not expose raid functionality to upper layer for warpdrive.
4610 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4611 sas_is_tlr_enabled(scmd->device) &&
4612 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4613 sas_disable_tlr(scmd->device);
4614 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4618 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4619 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4620 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4621 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4624 ioc_status &= MPI2_IOCSTATUS_MASK;
4625 scsi_status = mpi_reply->SCSIStatus;
4627 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4628 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4629 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4630 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4631 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4634 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4635 struct sense_info data;
4636 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4638 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4639 le32_to_cpu(mpi_reply->SenseCount));
4640 memcpy(scmd->sense_buffer, sense_data, sz);
4641 _scsih_normalize_sense(scmd->sense_buffer, &data);
4642 /* failure prediction threshold exceeded */
4643 if (data.asc == 0x5D)
4644 _scsih_smart_predicted_fault(ioc,
4645 le16_to_cpu(mpi_reply->DevHandle));
4648 switch (ioc_status) {
4649 case MPI2_IOCSTATUS_BUSY:
4650 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4651 scmd->result = SAM_STAT_BUSY;
4654 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4655 scmd->result = DID_NO_CONNECT << 16;
4658 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4659 if (sas_device_priv_data->block) {
4660 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4663 if (log_info == 0x32010081) {
4664 scmd->result = DID_RESET << 16;
4667 scmd->result = DID_SOFT_ERROR << 16;
4669 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4670 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4671 scmd->result = DID_RESET << 16;
4674 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4675 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4676 scmd->result = DID_SOFT_ERROR << 16;
4678 scmd->result = (DID_OK << 16) | scsi_status;
4681 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4682 scmd->result = (DID_OK << 16) | scsi_status;
4684 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4687 if (xfer_cnt < scmd->underflow) {
4688 if (scsi_status == SAM_STAT_BUSY)
4689 scmd->result = SAM_STAT_BUSY;
4691 scmd->result = DID_SOFT_ERROR << 16;
4692 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4693 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4694 scmd->result = DID_SOFT_ERROR << 16;
4695 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4696 scmd->result = DID_RESET << 16;
4697 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4698 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4699 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4700 scmd->result = (DRIVER_SENSE << 24) |
4701 SAM_STAT_CHECK_CONDITION;
4702 scmd->sense_buffer[0] = 0x70;
4703 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4704 scmd->sense_buffer[12] = 0x20;
4705 scmd->sense_buffer[13] = 0;
4709 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4710 scsi_set_resid(scmd, 0);
4711 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4712 case MPI2_IOCSTATUS_SUCCESS:
4713 scmd->result = (DID_OK << 16) | scsi_status;
4714 if (response_code ==
4715 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4716 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4717 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4718 scmd->result = DID_SOFT_ERROR << 16;
4719 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4720 scmd->result = DID_RESET << 16;
4723 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4724 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4725 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4726 _scsih_eedp_error_handling(scmd, ioc_status);
4728 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4729 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4730 case MPI2_IOCSTATUS_INVALID_SGL:
4731 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4732 case MPI2_IOCSTATUS_INVALID_FIELD:
4733 case MPI2_IOCSTATUS_INVALID_STATE:
4734 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4735 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4737 scmd->result = DID_SOFT_ERROR << 16;
4742 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4743 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4744 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4748 scsi_dma_unmap(scmd);
4749 scmd->scsi_done(scmd);
4754 * _scsih_sas_host_refresh - refreshing sas host object contents
4755 * @ioc: per adapter object
4758 * During port enable, fw will send topology events for every device. Its
4759 * possible that the handles may change from the previous setting, so this
4760 * code keeping handles updating if changed.
4765 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4770 Mpi2ConfigReply_t mpi_reply;
4771 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4772 u16 attached_handle;
4775 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4776 "updating handles for sas_host(0x%016llx)\n",
4777 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4779 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4780 * sizeof(Mpi2SasIOUnit0PhyData_t));
4781 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4782 if (!sas_iounit_pg0) {
4783 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4784 ioc->name, __FILE__, __LINE__, __func__);
4788 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4789 sas_iounit_pg0, sz)) != 0)
4791 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4792 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4794 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4795 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4797 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4798 PhyData[0].ControllerDevHandle);
4799 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4800 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4802 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4803 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4804 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4805 attached_handle, i, link_rate);
4808 kfree(sas_iounit_pg0);
4812 * _scsih_sas_host_add - create sas host object
4813 * @ioc: per adapter object
4815 * Creating host side data object, stored in ioc->sas_hba
4820 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4823 Mpi2ConfigReply_t mpi_reply;
4824 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4825 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4826 Mpi2SasPhyPage0_t phy_pg0;
4827 Mpi2SasDevicePage0_t sas_device_pg0;
4828 Mpi2SasEnclosurePage0_t enclosure_pg0;
4831 u16 device_missing_delay;
4833 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4834 if (!ioc->sas_hba.num_phys) {
4835 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4836 ioc->name, __FILE__, __LINE__, __func__);
4840 /* sas_iounit page 0 */
4841 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4842 sizeof(Mpi2SasIOUnit0PhyData_t));
4843 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4844 if (!sas_iounit_pg0) {
4845 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4846 ioc->name, __FILE__, __LINE__, __func__);
4849 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4850 sas_iounit_pg0, sz))) {
4851 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4852 ioc->name, __FILE__, __LINE__, __func__);
4855 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4856 MPI2_IOCSTATUS_MASK;
4857 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4858 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4859 ioc->name, __FILE__, __LINE__, __func__);
4863 /* sas_iounit page 1 */
4864 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4865 sizeof(Mpi2SasIOUnit1PhyData_t));
4866 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4867 if (!sas_iounit_pg1) {
4868 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4869 ioc->name, __FILE__, __LINE__, __func__);
4872 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4873 sas_iounit_pg1, sz))) {
4874 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4875 ioc->name, __FILE__, __LINE__, __func__);
4878 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4879 MPI2_IOCSTATUS_MASK;
4880 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4881 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4882 ioc->name, __FILE__, __LINE__, __func__);
4886 ioc->io_missing_delay =
4887 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4888 device_missing_delay =
4889 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4890 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4891 ioc->device_missing_delay = (device_missing_delay &
4892 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4894 ioc->device_missing_delay = device_missing_delay &
4895 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4897 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4898 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4899 sizeof(struct _sas_phy), GFP_KERNEL);
4900 if (!ioc->sas_hba.phy) {
4901 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4902 ioc->name, __FILE__, __LINE__, __func__);
4905 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4906 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4908 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4909 ioc->name, __FILE__, __LINE__, __func__);
4912 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4913 MPI2_IOCSTATUS_MASK;
4914 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4915 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4916 ioc->name, __FILE__, __LINE__, __func__);
4921 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4922 PhyData[0].ControllerDevHandle);
4923 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4924 ioc->sas_hba.phy[i].phy_id = i;
4925 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4926 phy_pg0, ioc->sas_hba.parent_dev);
4928 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4929 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4930 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4931 ioc->name, __FILE__, __LINE__, __func__);
4934 ioc->sas_hba.enclosure_handle =
4935 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4936 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4937 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4938 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4939 (unsigned long long) ioc->sas_hba.sas_address,
4940 ioc->sas_hba.num_phys) ;
4942 if (ioc->sas_hba.enclosure_handle) {
4943 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4945 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4946 ioc->sas_hba.enclosure_handle))) {
4947 ioc->sas_hba.enclosure_logical_id =
4948 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4953 kfree(sas_iounit_pg1);
4954 kfree(sas_iounit_pg0);
4958 * _scsih_expander_add - creating expander object
4959 * @ioc: per adapter object
4960 * @handle: expander handle
4962 * Creating expander object, stored in ioc->sas_expander_list.
4964 * Return 0 for success, else error.
4967 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4969 struct _sas_node *sas_expander;
4970 Mpi2ConfigReply_t mpi_reply;
4971 Mpi2ExpanderPage0_t expander_pg0;
4972 Mpi2ExpanderPage1_t expander_pg1;
4973 Mpi2SasEnclosurePage0_t enclosure_pg0;
4976 u64 sas_address, sas_address_parent = 0;
4978 unsigned long flags;
4979 struct _sas_port *mpt2sas_port = NULL;
4985 if (ioc->shost_recovery || ioc->pci_error_recovery)
4988 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4989 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4990 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4991 ioc->name, __FILE__, __LINE__, __func__);
4995 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4996 MPI2_IOCSTATUS_MASK;
4997 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4998 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4999 ioc->name, __FILE__, __LINE__, __func__);
5003 /* handle out of order topology events */
5004 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5005 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5007 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5008 ioc->name, __FILE__, __LINE__, __func__);
5011 if (sas_address_parent != ioc->sas_hba.sas_address) {
5012 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5013 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5014 sas_address_parent);
5015 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5016 if (!sas_expander) {
5017 rc = _scsih_expander_add(ioc, parent_handle);
5023 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5024 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5025 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5027 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5032 sas_expander = kzalloc(sizeof(struct _sas_node),
5034 if (!sas_expander) {
5035 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5036 ioc->name, __FILE__, __LINE__, __func__);
5040 sas_expander->handle = handle;
5041 sas_expander->num_phys = expander_pg0.NumPhys;
5042 sas_expander->sas_address_parent = sas_address_parent;
5043 sas_expander->sas_address = sas_address;
5045 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
5046 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5047 handle, parent_handle, (unsigned long long)
5048 sas_expander->sas_address, sas_expander->num_phys);
5050 if (!sas_expander->num_phys)
5052 sas_expander->phy = kcalloc(sas_expander->num_phys,
5053 sizeof(struct _sas_phy), GFP_KERNEL);
5054 if (!sas_expander->phy) {
5055 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5056 ioc->name, __FILE__, __LINE__, __func__);
5061 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5062 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
5063 sas_address_parent);
5064 if (!mpt2sas_port) {
5065 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5066 ioc->name, __FILE__, __LINE__, __func__);
5070 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
5072 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5073 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
5074 &expander_pg1, i, handle))) {
5075 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5076 ioc->name, __FILE__, __LINE__, __func__);
5080 sas_expander->phy[i].handle = handle;
5081 sas_expander->phy[i].phy_id = i;
5083 if ((mpt2sas_transport_add_expander_phy(ioc,
5084 &sas_expander->phy[i], expander_pg1,
5085 sas_expander->parent_dev))) {
5086 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5087 ioc->name, __FILE__, __LINE__, __func__);
5093 if (sas_expander->enclosure_handle) {
5094 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5095 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5096 sas_expander->enclosure_handle))) {
5097 sas_expander->enclosure_logical_id =
5098 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5102 _scsih_expander_node_add(ioc, sas_expander);
5108 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5109 sas_address_parent);
5110 kfree(sas_expander);
5115 * _scsih_done - scsih callback handler.
5116 * @ioc: per adapter object
5117 * @smid: system request message index
5118 * @msix_index: MSIX table index supplied by the OS
5119 * @reply: reply message frame(lower 32bit addr)
5121 * Callback handler when sending internal generated message frames.
5122 * The callback index passed is `ioc->scsih_cb_idx`
5124 * Return 1 meaning mf should be freed from _base_interrupt
5125 * 0 means the mf is freed from this function.
5128 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5130 MPI2DefaultReply_t *mpi_reply;
5132 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5133 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5135 if (ioc->scsih_cmds.smid != smid)
5137 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5139 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5140 mpi_reply->MsgLength*4);
5141 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5143 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5144 complete(&ioc->scsih_cmds.done);
5149 * mpt2sas_expander_remove - removing expander object
5150 * @ioc: per adapter object
5151 * @sas_address: expander sas_address
5156 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5158 struct _sas_node *sas_expander;
5159 unsigned long flags;
5161 if (ioc->shost_recovery)
5164 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5165 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5168 list_del(&sas_expander->list);
5169 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5171 _scsih_expander_node_remove(ioc, sas_expander);
5175 * _scsih_check_access_status - check access flags
5176 * @ioc: per adapter object
5177 * @sas_address: sas address
5178 * @handle: sas device handle
5179 * @access_flags: errors returned during discovery of the device
5181 * Return 0 for success, else failure
5184 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5185 u16 handle, u8 access_status)
5190 switch (access_status) {
5191 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5192 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5195 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5196 desc = "sata capability failed";
5198 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5199 desc = "sata affiliation conflict";
5201 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5202 desc = "route not addressable";
5204 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5205 desc = "smp error not addressable";
5207 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5208 desc = "device blocked";
5210 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5211 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5212 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5213 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5214 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5215 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5216 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5217 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5218 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5219 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5220 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5221 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5222 desc = "sata initialization failed";
5232 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5233 "handle(0x%04x)\n", ioc->name, desc,
5234 (unsigned long long)sas_address, handle);
5239 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5241 Mpi2ConfigReply_t mpi_reply;
5242 Mpi2SasDevicePage0_t sas_device_pg0;
5243 struct _sas_device *sas_device;
5245 unsigned long flags;
5247 struct scsi_target *starget;
5248 struct MPT2SAS_TARGET *sas_target_priv_data;
5252 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5253 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5256 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5257 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5260 /* check if this is end device */
5261 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5262 if (!(_scsih_is_end_device(device_info)))
5265 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5266 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5267 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
5271 printk(MPT2SAS_ERR_FMT "device is not present "
5272 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5276 if (unlikely(sas_device->handle != handle)) {
5277 starget = sas_device->starget;
5278 sas_target_priv_data = starget->hostdata;
5279 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5280 " to (0x%04x)!!!\n", sas_device->handle, handle);
5281 sas_target_priv_data->handle = handle;
5282 sas_device->handle = handle;
5285 /* check if device is present */
5286 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5287 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5288 printk(MPT2SAS_ERR_FMT "device is not present "
5289 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5293 /* check if there were any issues with discovery */
5294 if (_scsih_check_access_status(ioc, sas_address, handle,
5295 sas_device_pg0.AccessStatus))
5298 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5299 _scsih_ublock_io_device(ioc, sas_address);
5301 sas_device_put(sas_device);
5305 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5307 sas_device_put(sas_device);
5311 * _scsih_add_device - creating sas device object
5312 * @ioc: per adapter object
5313 * @handle: sas device handle
5314 * @phy_num: phy number end device attached to
5315 * @is_pd: is this hidden raid component
5317 * Creating end device object, stored in ioc->sas_device_list.
5319 * Returns 0 for success, non-zero for failure.
5322 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5324 Mpi2ConfigReply_t mpi_reply;
5325 Mpi2SasDevicePage0_t sas_device_pg0;
5326 Mpi2SasEnclosurePage0_t enclosure_pg0;
5327 struct _sas_device *sas_device;
5332 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5333 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5334 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5335 ioc->name, __FILE__, __LINE__, __func__);
5339 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5340 MPI2_IOCSTATUS_MASK;
5341 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5342 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5343 ioc->name, __FILE__, __LINE__, __func__);
5347 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5349 /* check if device is present */
5350 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5351 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5352 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5353 ioc->name, __FILE__, __LINE__, __func__);
5354 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5355 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5359 /* check if there were any issues with discovery */
5360 if (_scsih_check_access_status(ioc, sas_address, handle,
5361 sas_device_pg0.AccessStatus))
5364 /* check if this is end device */
5365 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5366 if (!(_scsih_is_end_device(device_info))) {
5367 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5368 ioc->name, __FILE__, __LINE__, __func__);
5372 sas_device = mpt2sas_get_sdev_by_addr(ioc,
5376 sas_device_put(sas_device);
5380 sas_device = kzalloc(sizeof(struct _sas_device),
5383 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5384 ioc->name, __FILE__, __LINE__, __func__);
5388 kref_init(&sas_device->refcount);
5389 sas_device->handle = handle;
5390 if (_scsih_get_sas_address(ioc, le16_to_cpu
5391 (sas_device_pg0.ParentDevHandle),
5392 &sas_device->sas_address_parent) != 0)
5393 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5394 ioc->name, __FILE__, __LINE__, __func__);
5395 sas_device->enclosure_handle =
5396 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5398 le16_to_cpu(sas_device_pg0.Slot);
5399 sas_device->device_info = device_info;
5400 sas_device->sas_address = sas_address;
5401 sas_device->phy = sas_device_pg0.PhyNum;
5403 /* get enclosure_logical_id */
5404 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5405 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5406 sas_device->enclosure_handle)))
5407 sas_device->enclosure_logical_id =
5408 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5410 /* get device name */
5411 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5413 if (ioc->wait_for_discovery_to_complete)
5414 _scsih_sas_device_init_add(ioc, sas_device);
5416 _scsih_sas_device_add(ioc, sas_device);
5418 sas_device_put(sas_device);
5423 * _scsih_remove_device - removing sas device object
5424 * @ioc: per adapter object
5425 * @sas_device_delete: the sas_device object
5430 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5431 struct _sas_device *sas_device)
5433 struct MPT2SAS_TARGET *sas_target_priv_data;
5435 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5436 (sas_device->pfa_led_on)) {
5437 _scsih_turn_off_pfa_led(ioc, sas_device);
5438 sas_device->pfa_led_on = 0;
5441 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5442 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5443 sas_device->handle, (unsigned long long)
5444 sas_device->sas_address));
5446 if (sas_device->starget && sas_device->starget->hostdata) {
5447 sas_target_priv_data = sas_device->starget->hostdata;
5448 sas_target_priv_data->deleted = 1;
5449 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5450 sas_target_priv_data->handle =
5451 MPT2SAS_INVALID_DEVICE_HANDLE;
5454 if (!ioc->hide_drives)
5455 mpt2sas_transport_port_remove(ioc,
5456 sas_device->sas_address,
5457 sas_device->sas_address_parent);
5459 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5460 "(0x%016llx)\n", ioc->name, sas_device->handle,
5461 (unsigned long long) sas_device->sas_address);
5463 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5464 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5465 sas_device->handle, (unsigned long long)
5466 sas_device->sas_address));
5469 * _scsih_device_remove_by_handle - removing device object by handle
5470 * @ioc: per adapter object
5471 * @handle: device handle
5476 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5478 struct _sas_device *sas_device;
5479 unsigned long flags;
5481 if (ioc->shost_recovery)
5484 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5485 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
5487 list_del_init(&sas_device->list);
5488 sas_device_put(sas_device);
5490 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5493 _scsih_remove_device(ioc, sas_device);
5494 sas_device_put(sas_device);
5499 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5500 * @ioc: per adapter object
5501 * @sas_address: device sas_address
5506 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5509 struct _sas_device *sas_device;
5510 unsigned long flags;
5512 if (ioc->shost_recovery)
5515 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5516 sas_device = __mpt2sas_get_sdev_by_addr(ioc, sas_address);
5518 list_del_init(&sas_device->list);
5519 sas_device_put(sas_device);
5521 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5524 _scsih_remove_device(ioc, sas_device);
5525 sas_device_put(sas_device);
5528 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5530 * _scsih_sas_topology_change_event_debug - debug for topology event
5531 * @ioc: per adapter object
5532 * @event_data: event data payload
5536 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5537 Mpi2EventDataSasTopologyChangeList_t *event_data)
5543 char *status_str = NULL;
5544 u8 link_rate, prev_link_rate;
5546 switch (event_data->ExpStatus) {
5547 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5550 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5551 status_str = "remove";
5553 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5555 status_str = "responding";
5557 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5558 status_str = "remove delay";
5561 status_str = "unknown status";
5564 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5565 ioc->name, status_str);
5566 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5567 "start_phy(%02d), count(%d)\n",
5568 le16_to_cpu(event_data->ExpanderDevHandle),
5569 le16_to_cpu(event_data->EnclosureHandle),
5570 event_data->StartPhyNum, event_data->NumEntries);
5571 for (i = 0; i < event_data->NumEntries; i++) {
5572 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5575 phy_number = event_data->StartPhyNum + i;
5576 reason_code = event_data->PHY[i].PhyStatus &
5577 MPI2_EVENT_SAS_TOPO_RC_MASK;
5578 switch (reason_code) {
5579 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5580 status_str = "target add";
5582 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5583 status_str = "target remove";
5585 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5586 status_str = "delay target remove";
5588 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5589 status_str = "link rate change";
5591 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5592 status_str = "target responding";
5595 status_str = "unknown";
5598 link_rate = event_data->PHY[i].LinkRate >> 4;
5599 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5600 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5601 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5602 handle, status_str, link_rate, prev_link_rate);
5609 * _scsih_sas_topology_change_event - handle topology changes
5610 * @ioc: per adapter object
5611 * @fw_event: The fw_event_work object
5616 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5617 struct fw_event_work *fw_event)
5620 u16 parent_handle, handle;
5622 u8 phy_number, max_phys;
5623 struct _sas_node *sas_expander;
5625 unsigned long flags;
5626 u8 link_rate, prev_link_rate;
5627 Mpi2EventDataSasTopologyChangeList_t *event_data =
5628 (Mpi2EventDataSasTopologyChangeList_t *)
5629 fw_event->event_data;
5631 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5632 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5633 _scsih_sas_topology_change_event_debug(ioc, event_data);
5636 if (ioc->remove_host || ioc->pci_error_recovery)
5639 if (!ioc->sas_hba.num_phys)
5640 _scsih_sas_host_add(ioc);
5642 _scsih_sas_host_refresh(ioc);
5644 if (fw_event->ignore) {
5645 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5646 "event\n", ioc->name));
5650 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5652 /* handle expander add */
5653 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5654 if (_scsih_expander_add(ioc, parent_handle) != 0)
5657 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5658 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5661 sas_address = sas_expander->sas_address;
5662 max_phys = sas_expander->num_phys;
5663 } else if (parent_handle < ioc->sas_hba.num_phys) {
5664 sas_address = ioc->sas_hba.sas_address;
5665 max_phys = ioc->sas_hba.num_phys;
5667 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5670 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5672 /* handle siblings events */
5673 for (i = 0; i < event_data->NumEntries; i++) {
5674 if (fw_event->ignore) {
5675 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5676 "expander event\n", ioc->name));
5679 if (ioc->shost_recovery || ioc->remove_host ||
5680 ioc->pci_error_recovery)
5682 phy_number = event_data->StartPhyNum + i;
5683 if (phy_number >= max_phys)
5685 reason_code = event_data->PHY[i].PhyStatus &
5686 MPI2_EVENT_SAS_TOPO_RC_MASK;
5687 if ((event_data->PHY[i].PhyStatus &
5688 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5689 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5691 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5694 link_rate = event_data->PHY[i].LinkRate >> 4;
5695 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5696 switch (reason_code) {
5697 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5699 if (ioc->shost_recovery)
5702 if (link_rate == prev_link_rate)
5705 mpt2sas_transport_update_links(ioc, sas_address,
5706 handle, phy_number, link_rate);
5708 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5711 _scsih_check_device(ioc, handle);
5713 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5715 if (ioc->shost_recovery)
5718 mpt2sas_transport_update_links(ioc, sas_address,
5719 handle, phy_number, link_rate);
5721 _scsih_add_device(ioc, handle, phy_number, 0);
5723 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5725 _scsih_device_remove_by_handle(ioc, handle);
5730 /* handle expander removal */
5731 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5733 mpt2sas_expander_remove(ioc, sas_address);
5737 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5739 * _scsih_sas_device_status_change_event_debug - debug for device event
5740 * @event_data: event data payload
5746 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5747 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5749 char *reason_str = NULL;
5751 switch (event_data->ReasonCode) {
5752 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5753 reason_str = "smart data";
5755 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5756 reason_str = "unsupported device discovered";
5758 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5759 reason_str = "internal device reset";
5761 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5762 reason_str = "internal task abort";
5764 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5765 reason_str = "internal task abort set";
5767 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5768 reason_str = "internal clear task set";
5770 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5771 reason_str = "internal query task";
5773 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5774 reason_str = "sata init failure";
5776 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5777 reason_str = "internal device reset complete";
5779 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5780 reason_str = "internal task abort complete";
5782 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5783 reason_str = "internal async notification";
5785 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5786 reason_str = "expander reduced functionality";
5788 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5789 reason_str = "expander reduced functionality complete";
5792 reason_str = "unknown reason";
5795 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5796 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5797 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5798 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5799 le16_to_cpu(event_data->TaskTag));
5800 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5801 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5802 event_data->ASC, event_data->ASCQ);
5803 printk(KERN_INFO "\n");
5808 * _scsih_sas_device_status_change_event - handle device status change
5809 * @ioc: per adapter object
5810 * @fw_event: The fw_event_work object
5816 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5817 struct fw_event_work *fw_event)
5819 struct MPT2SAS_TARGET *target_priv_data;
5820 struct _sas_device *sas_device;
5822 unsigned long flags;
5823 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5824 (Mpi2EventDataSasDeviceStatusChange_t *)
5825 fw_event->event_data;
5827 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5828 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5829 _scsih_sas_device_status_change_event_debug(ioc,
5833 /* In MPI Revision K (0xC), the internal device reset complete was
5834 * implemented, so avoid setting tm_busy flag for older firmware.
5836 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5839 if (event_data->ReasonCode !=
5840 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5841 event_data->ReasonCode !=
5842 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5845 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5846 sas_address = le64_to_cpu(event_data->SASAddress);
5847 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
5850 if (!sas_device || !sas_device->starget)
5853 target_priv_data = sas_device->starget->hostdata;
5854 if (!target_priv_data)
5857 if (event_data->ReasonCode ==
5858 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5859 target_priv_data->tm_busy = 1;
5861 target_priv_data->tm_busy = 0;
5865 sas_device_put(sas_device);
5867 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5871 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5873 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5874 * @ioc: per adapter object
5875 * @event_data: event data payload
5881 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5882 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5884 char *reason_str = NULL;
5886 switch (event_data->ReasonCode) {
5887 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5888 reason_str = "enclosure add";
5890 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5891 reason_str = "enclosure remove";
5894 reason_str = "unknown reason";
5898 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5899 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5900 " number slots(%d)\n", ioc->name, reason_str,
5901 le16_to_cpu(event_data->EnclosureHandle),
5902 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5903 le16_to_cpu(event_data->StartSlot));
5908 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5909 * @ioc: per adapter object
5910 * @fw_event: The fw_event_work object
5916 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5917 struct fw_event_work *fw_event)
5919 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5920 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5921 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5922 (Mpi2EventDataSasEnclDevStatusChange_t *)
5923 fw_event->event_data);
5928 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5929 * @ioc: per adapter object
5930 * @fw_event: The fw_event_work object
5936 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5937 struct fw_event_work *fw_event)
5939 struct scsi_cmnd *scmd;
5940 struct scsi_device *sdev;
5943 struct MPT2SAS_DEVICE *sas_device_priv_data;
5944 u32 termination_count;
5946 Mpi2SCSITaskManagementReply_t *mpi_reply;
5947 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5948 (Mpi2EventDataSasBroadcastPrimitive_t *)
5949 fw_event->event_data;
5951 unsigned long flags;
5954 u8 task_abort_retries;
5956 mutex_lock(&ioc->tm_cmds.mutex);
5958 "%s: enter: phy number(%d), width(%d)\n",
5959 ioc->name, __func__, event_data->PhyNum,
5960 event_data->PortWidth);
5962 _scsih_block_io_all_device(ioc);
5964 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5965 mpi_reply = ioc->tm_cmds.reply;
5966 broadcast_aen_retry:
5968 /* sanity checks for retrying this loop */
5969 if (max_retries++ == 5) {
5970 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5971 ioc->name, __func__));
5973 } else if (max_retries > 1)
5974 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5975 ioc->name, __func__, max_retries - 1));
5977 termination_count = 0;
5979 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5980 if (ioc->shost_recovery)
5982 scmd = _scsih_scsi_lookup_get(ioc, smid);
5985 sdev = scmd->device;
5986 sas_device_priv_data = sdev->hostdata;
5987 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5989 /* skip hidden raid components */
5990 if (sas_device_priv_data->sas_target->flags &
5991 MPT_TARGET_FLAGS_RAID_COMPONENT)
5994 if (sas_device_priv_data->sas_target->flags &
5995 MPT_TARGET_FLAGS_VOLUME)
5998 handle = sas_device_priv_data->sas_target->handle;
5999 lun = sas_device_priv_data->lun;
6002 if (ioc->shost_recovery)
6005 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6006 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6007 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
6010 sdev_printk(KERN_WARNING, sdev,
6011 "mpt2sas_scsih_issue_tm: FAILED when sending "
6012 "QUERY_TASK: scmd(%p)\n", scmd);
6013 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6014 goto broadcast_aen_retry;
6016 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6017 & MPI2_IOCSTATUS_MASK;
6018 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6019 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
6020 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
6022 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6023 goto broadcast_aen_retry;
6026 /* see if IO is still owned by IOC and target */
6027 if (mpi_reply->ResponseCode ==
6028 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6029 mpi_reply->ResponseCode ==
6030 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6031 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6034 task_abort_retries = 0;
6036 if (task_abort_retries++ == 60) {
6037 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
6038 "%s: ABORT_TASK: giving up\n", ioc->name,
6040 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6041 goto broadcast_aen_retry;
6044 if (ioc->shost_recovery)
6047 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6048 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
6051 sdev_printk(KERN_WARNING, sdev,
6052 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6053 "scmd(%p)\n", scmd);
6057 if (task_abort_retries > 1)
6058 sdev_printk(KERN_WARNING, sdev,
6059 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6061 task_abort_retries - 1, scmd);
6063 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6064 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6067 if (ioc->broadcast_aen_pending) {
6068 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
6069 " pending AEN\n", ioc->name, __func__));
6070 ioc->broadcast_aen_pending = 0;
6071 goto broadcast_aen_retry;
6075 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6078 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
6079 "%s - exit, query_count = %d termination_count = %d\n",
6080 ioc->name, __func__, query_count, termination_count));
6082 ioc->broadcast_aen_busy = 0;
6083 if (!ioc->shost_recovery)
6084 _scsih_ublock_io_all_device(ioc);
6085 mutex_unlock(&ioc->tm_cmds.mutex);
6089 * _scsih_sas_discovery_event - handle discovery events
6090 * @ioc: per adapter object
6091 * @fw_event: The fw_event_work object
6097 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
6098 struct fw_event_work *fw_event)
6100 Mpi2EventDataSasDiscovery_t *event_data =
6101 (Mpi2EventDataSasDiscovery_t *)
6102 fw_event->event_data;
6104 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6105 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6106 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
6107 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6109 if (event_data->DiscoveryStatus)
6110 printk("discovery_status(0x%08x)",
6111 le32_to_cpu(event_data->DiscoveryStatus));
6116 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6117 !ioc->sas_hba.num_phys) {
6118 if (disable_discovery > 0 && ioc->shost_recovery) {
6119 /* Wait for the reset to complete */
6120 while (ioc->shost_recovery)
6123 _scsih_sas_host_add(ioc);
6128 * _scsih_reprobe_lun - reprobing lun
6129 * @sdev: scsi device struct
6130 * @no_uld_attach: sdev->no_uld_attach flag setting
6134 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6138 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6139 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6140 sdev->no_uld_attach ? "hidding" : "exposing");
6141 rc = scsi_device_reprobe(sdev);
6145 * _scsih_sas_volume_add - add new volume
6146 * @ioc: per adapter object
6147 * @element: IR config element data
6153 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6154 Mpi2EventIrConfigElement_t *element)
6156 struct _raid_device *raid_device;
6157 unsigned long flags;
6159 u16 handle = le16_to_cpu(element->VolDevHandle);
6162 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6164 printk(MPT2SAS_ERR_FMT
6165 "failure at %s:%d/%s()!\n", ioc->name,
6166 __FILE__, __LINE__, __func__);
6170 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6171 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6172 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6177 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6179 printk(MPT2SAS_ERR_FMT
6180 "failure at %s:%d/%s()!\n", ioc->name,
6181 __FILE__, __LINE__, __func__);
6185 raid_device->id = ioc->sas_id++;
6186 raid_device->channel = RAID_CHANNEL;
6187 raid_device->handle = handle;
6188 raid_device->wwid = wwid;
6189 _scsih_raid_device_add(ioc, raid_device);
6190 if (!ioc->wait_for_discovery_to_complete) {
6191 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6192 raid_device->id, 0);
6194 _scsih_raid_device_remove(ioc, raid_device);
6196 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6197 _scsih_determine_boot_device(ioc, raid_device, 1);
6198 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6203 * _scsih_sas_volume_delete - delete volume
6204 * @ioc: per adapter object
6205 * @handle: volume device handle
6211 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6213 struct _raid_device *raid_device;
6214 unsigned long flags;
6215 struct MPT2SAS_TARGET *sas_target_priv_data;
6216 struct scsi_target *starget = NULL;
6218 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6219 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6221 if (raid_device->starget) {
6222 starget = raid_device->starget;
6223 sas_target_priv_data = starget->hostdata;
6224 sas_target_priv_data->deleted = 1;
6226 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6227 "(0x%016llx)\n", ioc->name, raid_device->handle,
6228 (unsigned long long) raid_device->wwid);
6229 list_del(&raid_device->list);
6232 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6234 scsi_remove_target(&starget->dev);
6238 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6239 * @ioc: per adapter object
6240 * @element: IR config element data
6246 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6247 Mpi2EventIrConfigElement_t *element)
6249 struct _sas_device *sas_device;
6250 struct scsi_target *starget = NULL;
6251 struct MPT2SAS_TARGET *sas_target_priv_data;
6252 unsigned long flags;
6253 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6255 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6256 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
6258 sas_device->volume_handle = 0;
6259 sas_device->volume_wwid = 0;
6260 clear_bit(handle, ioc->pd_handles);
6261 if (sas_device->starget && sas_device->starget->hostdata) {
6262 starget = sas_device->starget;
6263 sas_target_priv_data = starget->hostdata;
6264 sas_target_priv_data->flags &=
6265 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6268 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6272 /* exposing raid component */
6274 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6276 sas_device_put(sas_device);
6280 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6281 * @ioc: per adapter object
6282 * @element: IR config element data
6288 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6289 Mpi2EventIrConfigElement_t *element)
6291 struct _sas_device *sas_device;
6292 struct scsi_target *starget = NULL;
6293 struct MPT2SAS_TARGET *sas_target_priv_data;
6294 unsigned long flags;
6295 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6296 u16 volume_handle = 0;
6297 u64 volume_wwid = 0;
6299 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6301 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6304 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6305 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
6307 set_bit(handle, ioc->pd_handles);
6308 if (sas_device->starget && sas_device->starget->hostdata) {
6309 starget = sas_device->starget;
6310 sas_target_priv_data = starget->hostdata;
6311 sas_target_priv_data->flags |=
6312 MPT_TARGET_FLAGS_RAID_COMPONENT;
6313 sas_device->volume_handle = volume_handle;
6314 sas_device->volume_wwid = volume_wwid;
6317 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6321 /* hiding raid component */
6323 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6325 sas_device_put(sas_device);
6329 * _scsih_sas_pd_delete - delete pd component
6330 * @ioc: per adapter object
6331 * @element: IR config element data
6337 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6338 Mpi2EventIrConfigElement_t *element)
6340 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6342 _scsih_device_remove_by_handle(ioc, handle);
6346 * _scsih_sas_pd_add - remove pd component
6347 * @ioc: per adapter object
6348 * @element: IR config element data
6354 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6355 Mpi2EventIrConfigElement_t *element)
6357 struct _sas_device *sas_device;
6358 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6359 Mpi2ConfigReply_t mpi_reply;
6360 Mpi2SasDevicePage0_t sas_device_pg0;
6365 set_bit(handle, ioc->pd_handles);
6367 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
6369 sas_device_put(sas_device);
6373 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6374 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6375 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6376 ioc->name, __FILE__, __LINE__, __func__);
6380 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6381 MPI2_IOCSTATUS_MASK;
6382 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6383 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6384 ioc->name, __FILE__, __LINE__, __func__);
6388 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6389 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6390 mpt2sas_transport_update_links(ioc, sas_address, handle,
6391 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6393 _scsih_add_device(ioc, handle, 0, 1);
6396 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6398 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6399 * @ioc: per adapter object
6400 * @event_data: event data payload
6406 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6407 Mpi2EventDataIrConfigChangeList_t *event_data)
6409 Mpi2EventIrConfigElement_t *element;
6412 char *reason_str = NULL, *element_str = NULL;
6414 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6416 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6417 ioc->name, (le32_to_cpu(event_data->Flags) &
6418 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6419 "foreign" : "native", event_data->NumElements);
6420 for (i = 0; i < event_data->NumElements; i++, element++) {
6421 switch (element->ReasonCode) {
6422 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6425 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6426 reason_str = "remove";
6428 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6429 reason_str = "no change";
6431 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6432 reason_str = "hide";
6434 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6435 reason_str = "unhide";
6437 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6438 reason_str = "volume_created";
6440 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6441 reason_str = "volume_deleted";
6443 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6444 reason_str = "pd_created";
6446 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6447 reason_str = "pd_deleted";
6450 reason_str = "unknown reason";
6453 element_type = le16_to_cpu(element->ElementFlags) &
6454 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6455 switch (element_type) {
6456 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6457 element_str = "volume";
6459 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6460 element_str = "phys disk";
6462 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6463 element_str = "hot spare";
6466 element_str = "unknown element";
6469 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6470 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6471 reason_str, le16_to_cpu(element->VolDevHandle),
6472 le16_to_cpu(element->PhysDiskDevHandle),
6473 element->PhysDiskNum);
6479 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6480 * @ioc: per adapter object
6481 * @fw_event: The fw_event_work object
6487 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6488 struct fw_event_work *fw_event)
6490 Mpi2EventIrConfigElement_t *element;
6493 Mpi2EventDataIrConfigChangeList_t *event_data =
6494 (Mpi2EventDataIrConfigChangeList_t *)
6495 fw_event->event_data;
6497 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6498 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6499 && !ioc->hide_ir_msg)
6500 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6504 if (ioc->shost_recovery)
6507 foreign_config = (le32_to_cpu(event_data->Flags) &
6508 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6510 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6511 for (i = 0; i < event_data->NumElements; i++, element++) {
6513 switch (element->ReasonCode) {
6514 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6515 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6516 if (!foreign_config)
6517 _scsih_sas_volume_add(ioc, element);
6519 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6520 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6521 if (!foreign_config)
6522 _scsih_sas_volume_delete(ioc,
6523 le16_to_cpu(element->VolDevHandle));
6525 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6526 if (!ioc->is_warpdrive)
6527 _scsih_sas_pd_hide(ioc, element);
6529 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6530 if (!ioc->is_warpdrive)
6531 _scsih_sas_pd_expose(ioc, element);
6533 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6534 if (!ioc->is_warpdrive)
6535 _scsih_sas_pd_add(ioc, element);
6537 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6538 if (!ioc->is_warpdrive)
6539 _scsih_sas_pd_delete(ioc, element);
6546 * _scsih_sas_ir_volume_event - IR volume event
6547 * @ioc: per adapter object
6548 * @fw_event: The fw_event_work object
6554 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6555 struct fw_event_work *fw_event)
6558 unsigned long flags;
6559 struct _raid_device *raid_device;
6563 Mpi2EventDataIrVolume_t *event_data =
6564 (Mpi2EventDataIrVolume_t *)
6565 fw_event->event_data;
6567 if (ioc->shost_recovery)
6570 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6573 handle = le16_to_cpu(event_data->VolDevHandle);
6574 state = le32_to_cpu(event_data->NewValue);
6575 if (!ioc->hide_ir_msg)
6576 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6577 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6578 le32_to_cpu(event_data->PreviousValue), state));
6581 case MPI2_RAID_VOL_STATE_MISSING:
6582 case MPI2_RAID_VOL_STATE_FAILED:
6583 _scsih_sas_volume_delete(ioc, handle);
6586 case MPI2_RAID_VOL_STATE_ONLINE:
6587 case MPI2_RAID_VOL_STATE_DEGRADED:
6588 case MPI2_RAID_VOL_STATE_OPTIMAL:
6590 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6591 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6592 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6597 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6599 printk(MPT2SAS_ERR_FMT
6600 "failure at %s:%d/%s()!\n", ioc->name,
6601 __FILE__, __LINE__, __func__);
6605 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6607 printk(MPT2SAS_ERR_FMT
6608 "failure at %s:%d/%s()!\n", ioc->name,
6609 __FILE__, __LINE__, __func__);
6613 raid_device->id = ioc->sas_id++;
6614 raid_device->channel = RAID_CHANNEL;
6615 raid_device->handle = handle;
6616 raid_device->wwid = wwid;
6617 _scsih_raid_device_add(ioc, raid_device);
6618 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6619 raid_device->id, 0);
6621 _scsih_raid_device_remove(ioc, raid_device);
6624 case MPI2_RAID_VOL_STATE_INITIALIZING:
6631 * _scsih_sas_ir_physical_disk_event - PD event
6632 * @ioc: per adapter object
6633 * @fw_event: The fw_event_work object
6639 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6640 struct fw_event_work *fw_event)
6642 u16 handle, parent_handle;
6644 struct _sas_device *sas_device;
6645 Mpi2ConfigReply_t mpi_reply;
6646 Mpi2SasDevicePage0_t sas_device_pg0;
6648 Mpi2EventDataIrPhysicalDisk_t *event_data =
6649 (Mpi2EventDataIrPhysicalDisk_t *)
6650 fw_event->event_data;
6653 if (ioc->shost_recovery)
6656 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6659 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6660 state = le32_to_cpu(event_data->NewValue);
6662 if (!ioc->hide_ir_msg)
6663 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6664 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6665 le32_to_cpu(event_data->PreviousValue), state));
6668 case MPI2_RAID_PD_STATE_ONLINE:
6669 case MPI2_RAID_PD_STATE_DEGRADED:
6670 case MPI2_RAID_PD_STATE_REBUILDING:
6671 case MPI2_RAID_PD_STATE_OPTIMAL:
6672 case MPI2_RAID_PD_STATE_HOT_SPARE:
6674 if (!ioc->is_warpdrive)
6675 set_bit(handle, ioc->pd_handles);
6677 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
6679 sas_device_put(sas_device);
6683 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6684 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6686 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6687 ioc->name, __FILE__, __LINE__, __func__);
6691 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6692 MPI2_IOCSTATUS_MASK;
6693 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6694 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6695 ioc->name, __FILE__, __LINE__, __func__);
6699 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6700 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6701 mpt2sas_transport_update_links(ioc, sas_address, handle,
6702 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6704 _scsih_add_device(ioc, handle, 0, 1);
6708 case MPI2_RAID_PD_STATE_OFFLINE:
6709 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6710 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6716 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6718 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6719 * @ioc: per adapter object
6720 * @event_data: event data payload
6726 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6727 Mpi2EventDataIrOperationStatus_t *event_data)
6729 char *reason_str = NULL;
6731 switch (event_data->RAIDOperation) {
6732 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6733 reason_str = "resync";
6735 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6736 reason_str = "online capacity expansion";
6738 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6739 reason_str = "consistency check";
6741 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6742 reason_str = "background init";
6744 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6745 reason_str = "make data consistent";
6752 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6753 "\thandle(0x%04x), percent complete(%d)\n",
6754 ioc->name, reason_str,
6755 le16_to_cpu(event_data->VolDevHandle),
6756 event_data->PercentComplete);
6761 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6762 * @ioc: per adapter object
6763 * @fw_event: The fw_event_work object
6769 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6770 struct fw_event_work *fw_event)
6772 Mpi2EventDataIrOperationStatus_t *event_data =
6773 (Mpi2EventDataIrOperationStatus_t *)
6774 fw_event->event_data;
6775 static struct _raid_device *raid_device;
6776 unsigned long flags;
6779 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6780 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6781 && !ioc->hide_ir_msg)
6782 _scsih_sas_ir_operation_status_event_debug(ioc,
6786 /* code added for raid transport support */
6787 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6789 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6790 handle = le16_to_cpu(event_data->VolDevHandle);
6791 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6793 raid_device->percent_complete =
6794 event_data->PercentComplete;
6795 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6800 * _scsih_prep_device_scan - initialize parameters prior to device scan
6801 * @ioc: per adapter object
6803 * Set the deleted flag prior to device scan. If the device is found during
6804 * the scan, then we clear the deleted flag.
6807 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6809 struct MPT2SAS_DEVICE *sas_device_priv_data;
6810 struct scsi_device *sdev;
6812 shost_for_each_device(sdev, ioc->shost) {
6813 sas_device_priv_data = sdev->hostdata;
6814 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6815 sas_device_priv_data->sas_target->deleted = 1;
6820 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6821 * @ioc: per adapter object
6822 * @sas_address: sas address
6823 * @slot: enclosure slot id
6824 * @handle: device handle
6826 * After host reset, find out whether devices are still responding.
6827 * Used in _scsi_remove_unresponsive_sas_devices.
6832 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6833 u16 slot, u16 handle)
6835 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6836 struct scsi_target *starget;
6837 struct _sas_device *sas_device;
6838 unsigned long flags;
6840 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6841 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6842 if (sas_device->sas_address == sas_address &&
6843 sas_device->slot == slot) {
6844 sas_device->responding = 1;
6845 starget = sas_device->starget;
6846 if (starget && starget->hostdata) {
6847 sas_target_priv_data = starget->hostdata;
6848 sas_target_priv_data->tm_busy = 0;
6849 sas_target_priv_data->deleted = 0;
6851 sas_target_priv_data = NULL;
6853 starget_printk(KERN_INFO, starget,
6854 "handle(0x%04x), sas_addr(0x%016llx), "
6855 "enclosure logical id(0x%016llx), "
6856 "slot(%d)\n", handle,
6857 (unsigned long long)sas_device->sas_address,
6858 (unsigned long long)
6859 sas_device->enclosure_logical_id,
6861 if (sas_device->handle == handle)
6863 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6864 sas_device->handle);
6865 sas_device->handle = handle;
6866 if (sas_target_priv_data)
6867 sas_target_priv_data->handle = handle;
6872 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6876 * _scsih_search_responding_sas_devices -
6877 * @ioc: per adapter object
6879 * After host reset, find out whether devices are still responding.
6885 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6887 Mpi2SasDevicePage0_t sas_device_pg0;
6888 Mpi2ConfigReply_t mpi_reply;
6895 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6897 if (list_empty(&ioc->sas_device_list))
6901 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6902 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6904 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6905 MPI2_IOCSTATUS_MASK;
6906 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6908 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6909 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6910 if (!(_scsih_is_end_device(device_info)))
6912 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6913 slot = le16_to_cpu(sas_device_pg0.Slot);
6914 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6918 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6923 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6924 * @ioc: per adapter object
6925 * @wwid: world wide identifier for raid volume
6926 * @handle: device handle
6928 * After host reset, find out whether devices are still responding.
6929 * Used in _scsi_remove_unresponsive_raid_devices.
6934 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6937 struct MPT2SAS_TARGET *sas_target_priv_data;
6938 struct scsi_target *starget;
6939 struct _raid_device *raid_device;
6940 unsigned long flags;
6942 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6943 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6944 if (raid_device->wwid == wwid && raid_device->starget) {
6945 starget = raid_device->starget;
6946 if (starget && starget->hostdata) {
6947 sas_target_priv_data = starget->hostdata;
6948 sas_target_priv_data->deleted = 0;
6950 sas_target_priv_data = NULL;
6951 raid_device->responding = 1;
6952 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6953 starget_printk(KERN_INFO, raid_device->starget,
6954 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6955 (unsigned long long)raid_device->wwid);
6957 * WARPDRIVE: The handles of the PDs might have changed
6958 * across the host reset so re-initialize the
6959 * required data for Direct IO
6961 _scsih_init_warpdrive_properties(ioc, raid_device);
6962 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6963 if (raid_device->handle == handle) {
6964 spin_unlock_irqrestore(&ioc->raid_device_lock,
6968 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6969 raid_device->handle);
6970 raid_device->handle = handle;
6971 if (sas_target_priv_data)
6972 sas_target_priv_data->handle = handle;
6973 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6978 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6982 * _scsih_search_responding_raid_devices -
6983 * @ioc: per adapter object
6985 * After host reset, find out whether devices are still responding.
6991 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6993 Mpi2RaidVolPage1_t volume_pg1;
6994 Mpi2RaidVolPage0_t volume_pg0;
6995 Mpi2RaidPhysDiskPage0_t pd_pg0;
6996 Mpi2ConfigReply_t mpi_reply;
7001 if (!ioc->ir_firmware)
7004 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
7007 if (list_empty(&ioc->raid_device_list))
7011 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7012 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7013 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7014 MPI2_IOCSTATUS_MASK;
7015 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7017 handle = le16_to_cpu(volume_pg1.DevHandle);
7019 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7020 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7021 sizeof(Mpi2RaidVolPage0_t)))
7024 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7025 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7026 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7027 _scsih_mark_responding_raid_device(ioc,
7028 le64_to_cpu(volume_pg1.WWID), handle);
7031 /* refresh the pd_handles */
7032 if (!ioc->is_warpdrive) {
7033 phys_disk_num = 0xFF;
7034 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7035 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7036 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7038 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7039 MPI2_IOCSTATUS_MASK;
7040 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7042 phys_disk_num = pd_pg0.PhysDiskNum;
7043 handle = le16_to_cpu(pd_pg0.DevHandle);
7044 set_bit(handle, ioc->pd_handles);
7048 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
7049 "complete\n", ioc->name);
7053 * _scsih_mark_responding_expander - mark a expander as responding
7054 * @ioc: per adapter object
7055 * @sas_address: sas address
7058 * After host reset, find out whether devices are still responding.
7059 * Used in _scsi_remove_unresponsive_expanders.
7064 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
7067 struct _sas_node *sas_expander;
7068 unsigned long flags;
7071 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7072 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7073 if (sas_expander->sas_address != sas_address)
7075 sas_expander->responding = 1;
7076 if (sas_expander->handle == handle)
7078 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
7079 " from(0x%04x) to (0x%04x)!!!\n",
7080 (unsigned long long)sas_expander->sas_address,
7081 sas_expander->handle, handle);
7082 sas_expander->handle = handle;
7083 for (i = 0 ; i < sas_expander->num_phys ; i++)
7084 sas_expander->phy[i].handle = handle;
7088 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7092 * _scsih_search_responding_expanders -
7093 * @ioc: per adapter object
7095 * After host reset, find out whether devices are still responding.
7101 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
7103 Mpi2ExpanderPage0_t expander_pg0;
7104 Mpi2ConfigReply_t mpi_reply;
7109 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
7111 if (list_empty(&ioc->sas_expander_list))
7115 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7116 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7118 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7119 MPI2_IOCSTATUS_MASK;
7120 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7123 handle = le16_to_cpu(expander_pg0.DevHandle);
7124 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7125 printk(KERN_INFO "\texpander present: handle(0x%04x), "
7126 "sas_addr(0x%016llx)\n", handle,
7127 (unsigned long long)sas_address);
7128 _scsih_mark_responding_expander(ioc, sas_address, handle);
7132 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
7136 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7137 * @ioc: per adapter object
7142 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
7144 struct _sas_device *sas_device, *sas_device_next;
7145 struct _sas_node *sas_expander, *sas_expander_next;
7146 struct _raid_device *raid_device, *raid_device_next;
7147 struct list_head tmp_list;
7148 unsigned long flags;
7151 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7154 /* removing unresponding end devices */
7155 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7159 * Iterate, pulling off devices marked as non-responding. We become the
7160 * owner for the reference the list had on any object we prune.
7162 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7163 list_for_each_entry_safe(sas_device, sas_device_next,
7164 &ioc->sas_device_list, list) {
7165 if (!sas_device->responding)
7166 list_move_tail(&sas_device->list, &head);
7168 sas_device->responding = 0;
7170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7173 * Now, uninitialize and remove the unresponding devices we pruned.
7175 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7176 _scsih_remove_device(ioc, sas_device);
7177 list_del_init(&sas_device->list);
7178 sas_device_put(sas_device);
7181 /* removing unresponding volumes */
7182 if (ioc->ir_firmware) {
7183 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7184 "volumes\n", ioc->name);
7185 list_for_each_entry_safe(raid_device, raid_device_next,
7186 &ioc->raid_device_list, list) {
7187 if (!raid_device->responding)
7188 _scsih_sas_volume_delete(ioc,
7189 raid_device->handle);
7191 raid_device->responding = 0;
7194 /* removing unresponding expanders */
7195 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7197 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7198 INIT_LIST_HEAD(&tmp_list);
7199 list_for_each_entry_safe(sas_expander, sas_expander_next,
7200 &ioc->sas_expander_list, list) {
7201 if (!sas_expander->responding)
7202 list_move_tail(&sas_expander->list, &tmp_list);
7204 sas_expander->responding = 0;
7206 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7207 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7209 list_del(&sas_expander->list);
7210 _scsih_expander_node_remove(ioc, sas_expander);
7212 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7214 /* unblock devices */
7215 _scsih_ublock_io_all_device(ioc);
7219 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7220 struct _sas_node *sas_expander, u16 handle)
7222 Mpi2ExpanderPage1_t expander_pg1;
7223 Mpi2ConfigReply_t mpi_reply;
7226 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7227 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7228 &expander_pg1, i, handle))) {
7229 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7230 ioc->name, __FILE__, __LINE__, __func__);
7234 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7235 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7236 expander_pg1.NegotiatedLinkRate >> 4);
7241 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7242 * @ioc: per adapter object
7247 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7249 Mpi2ExpanderPage0_t expander_pg0;
7250 Mpi2SasDevicePage0_t sas_device_pg0;
7251 Mpi2RaidVolPage1_t volume_pg1;
7252 Mpi2RaidVolPage0_t volume_pg0;
7253 Mpi2RaidPhysDiskPage0_t pd_pg0;
7254 Mpi2EventIrConfigElement_t element;
7255 Mpi2ConfigReply_t mpi_reply;
7258 u16 handle, parent_handle;
7260 struct _sas_device *sas_device;
7261 struct _sas_node *expander_device;
7262 static struct _raid_device *raid_device;
7264 unsigned long flags;
7266 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7268 _scsih_sas_host_refresh(ioc);
7270 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7274 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7275 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7276 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7277 MPI2_IOCSTATUS_MASK;
7278 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7279 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7280 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7281 ioc->name, ioc_status,
7282 le32_to_cpu(mpi_reply.IOCLogInfo));
7285 handle = le16_to_cpu(expander_pg0.DevHandle);
7286 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7287 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7288 ioc, le64_to_cpu(expander_pg0.SASAddress));
7289 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7290 if (expander_device)
7291 _scsih_refresh_expander_links(ioc, expander_device,
7294 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7295 "handle (0x%04x), sas_addr(0x%016llx)\n",
7296 ioc->name, handle, (unsigned long long)
7297 le64_to_cpu(expander_pg0.SASAddress));
7298 _scsih_expander_add(ioc, handle);
7299 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7300 "handle (0x%04x), sas_addr(0x%016llx)\n",
7301 ioc->name, handle, (unsigned long long)
7302 le64_to_cpu(expander_pg0.SASAddress));
7306 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7309 if (!ioc->ir_firmware)
7312 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7314 phys_disk_num = 0xFF;
7315 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7316 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7318 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7319 MPI2_IOCSTATUS_MASK;
7320 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7321 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7322 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7323 ioc->name, ioc_status,
7324 le32_to_cpu(mpi_reply.IOCLogInfo));
7327 phys_disk_num = pd_pg0.PhysDiskNum;
7328 handle = le16_to_cpu(pd_pg0.DevHandle);
7329 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
7331 sas_device_put(sas_device);
7334 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7335 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7338 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7339 MPI2_IOCSTATUS_MASK;
7340 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7341 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7342 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7343 ioc->name, ioc_status,
7344 le32_to_cpu(mpi_reply.IOCLogInfo));
7347 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7348 if (!_scsih_get_sas_address(ioc, parent_handle,
7350 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7351 " handle (0x%04x), sas_addr(0x%016llx)\n",
7352 ioc->name, handle, (unsigned long long)
7353 le64_to_cpu(sas_device_pg0.SASAddress));
7354 mpt2sas_transport_update_links(ioc, sas_address,
7355 handle, sas_device_pg0.PhyNum,
7356 MPI2_SAS_NEG_LINK_RATE_1_5);
7357 set_bit(handle, ioc->pd_handles);
7359 /* This will retry adding the end device.
7360 * _scsih_add_device() will decide on retries and
7361 * return "1" when it should be retried
7363 while (_scsih_add_device(ioc, handle, retry_count++,
7367 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7368 " handle (0x%04x), sas_addr(0x%016llx)\n",
7369 ioc->name, handle, (unsigned long long)
7370 le64_to_cpu(sas_device_pg0.SASAddress));
7374 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7377 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7380 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7381 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7382 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7383 MPI2_IOCSTATUS_MASK;
7384 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7385 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7386 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7387 ioc->name, ioc_status,
7388 le32_to_cpu(mpi_reply.IOCLogInfo));
7391 handle = le16_to_cpu(volume_pg1.DevHandle);
7392 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7393 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7394 le64_to_cpu(volume_pg1.WWID));
7395 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7398 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7399 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7400 sizeof(Mpi2RaidVolPage0_t)))
7402 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7403 MPI2_IOCSTATUS_MASK;
7404 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7405 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7406 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7407 ioc->name, ioc_status,
7408 le32_to_cpu(mpi_reply.IOCLogInfo));
7411 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7412 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7413 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7414 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7415 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7416 element.VolDevHandle = volume_pg1.DevHandle;
7417 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7418 " handle (0x%04x)\n", ioc->name,
7419 volume_pg1.DevHandle);
7420 _scsih_sas_volume_add(ioc, &element);
7421 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7422 " handle (0x%04x)\n", ioc->name,
7423 volume_pg1.DevHandle);
7427 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7432 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7436 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7437 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7439 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7440 MPI2_IOCSTATUS_MASK;
7441 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7442 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7443 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7444 ioc->name, ioc_status,
7445 le32_to_cpu(mpi_reply.IOCLogInfo));
7448 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7449 if (!(_scsih_is_end_device(
7450 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7452 sas_device = mpt2sas_get_sdev_by_addr(ioc,
7453 le64_to_cpu(sas_device_pg0.SASAddress));
7455 sas_device_put(sas_device);
7458 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7459 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7460 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7461 "handle (0x%04x), sas_addr(0x%016llx)\n",
7462 ioc->name, handle, (unsigned long long)
7463 le64_to_cpu(sas_device_pg0.SASAddress));
7464 mpt2sas_transport_update_links(ioc, sas_address, handle,
7465 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7467 /* This will retry adding the end device.
7468 * _scsih_add_device() will decide on retries and
7469 * return "1" when it should be retried
7471 while (_scsih_add_device(ioc, handle, retry_count++,
7475 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7476 "handle (0x%04x), sas_addr(0x%016llx)\n",
7477 ioc->name, handle, (unsigned long long)
7478 le64_to_cpu(sas_device_pg0.SASAddress));
7482 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7485 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7490 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7491 * @ioc: per adapter object
7492 * @reset_phase: phase
7494 * The handler for doing any required cleanup or initialization.
7496 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7497 * MPT2_IOC_DONE_RESET
7502 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7504 switch (reset_phase) {
7505 case MPT2_IOC_PRE_RESET:
7506 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7507 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7509 case MPT2_IOC_AFTER_RESET:
7510 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7511 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7512 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7513 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7514 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7515 complete(&ioc->scsih_cmds.done);
7517 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7518 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7519 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7520 complete(&ioc->tm_cmds.done);
7522 _scsih_fw_event_cleanup_queue(ioc);
7523 _scsih_flush_running_cmds(ioc);
7525 case MPT2_IOC_DONE_RESET:
7526 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7527 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7528 _scsih_sas_host_refresh(ioc);
7529 _scsih_prep_device_scan(ioc);
7530 _scsih_search_responding_sas_devices(ioc);
7531 _scsih_search_responding_raid_devices(ioc);
7532 _scsih_search_responding_expanders(ioc);
7533 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7534 !ioc->sas_hba.num_phys)) {
7535 _scsih_prep_device_scan(ioc);
7536 _scsih_search_responding_sas_devices(ioc);
7537 _scsih_search_responding_raid_devices(ioc);
7538 _scsih_search_responding_expanders(ioc);
7539 _scsih_error_recovery_delete_devices(ioc);
7546 * _firmware_event_work - delayed task for processing firmware events
7547 * @ioc: per adapter object
7548 * @work: equal to the fw_event_work object
7554 _firmware_event_work(struct work_struct *work)
7556 struct fw_event_work *fw_event = container_of(work,
7557 struct fw_event_work, delayed_work.work);
7558 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7560 /* the queue is being flushed so ignore this event */
7561 if (ioc->remove_host ||
7562 ioc->pci_error_recovery) {
7563 _scsih_fw_event_free(ioc, fw_event);
7567 switch (fw_event->event) {
7568 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7569 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7571 _scsih_remove_unresponding_sas_devices(ioc);
7572 _scsih_scan_for_devices_after_reset(ioc);
7574 case MPT2SAS_PORT_ENABLE_COMPLETE:
7575 ioc->start_scan = 0;
7577 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7578 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7581 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7582 "from worker thread\n", ioc->name));
7584 case MPT2SAS_TURN_ON_PFA_LED:
7585 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7587 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7588 _scsih_sas_topology_change_event(ioc, fw_event);
7590 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7591 _scsih_sas_device_status_change_event(ioc,
7594 case MPI2_EVENT_SAS_DISCOVERY:
7595 _scsih_sas_discovery_event(ioc,
7598 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7599 _scsih_sas_broadcast_primitive_event(ioc,
7602 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7603 _scsih_sas_enclosure_dev_status_change_event(ioc,
7606 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7607 _scsih_sas_ir_config_change_event(ioc, fw_event);
7609 case MPI2_EVENT_IR_VOLUME:
7610 _scsih_sas_ir_volume_event(ioc, fw_event);
7612 case MPI2_EVENT_IR_PHYSICAL_DISK:
7613 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7615 case MPI2_EVENT_IR_OPERATION_STATUS:
7616 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7619 _scsih_fw_event_free(ioc, fw_event);
7623 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7624 * @ioc: per adapter object
7625 * @msix_index: MSIX table index supplied by the OS
7626 * @reply: reply message frame(lower 32bit addr)
7627 * Context: interrupt.
7629 * This function merely adds a new work task into ioc->firmware_event_thread.
7630 * The tasks are worked from _firmware_event_work in user context.
7635 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7638 struct fw_event_work *fw_event;
7639 Mpi2EventNotificationReply_t *mpi_reply;
7643 /* events turned off due to host reset or driver unloading */
7644 if (ioc->remove_host || ioc->pci_error_recovery)
7647 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7649 if (unlikely(!mpi_reply)) {
7650 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7651 ioc->name, __FILE__, __LINE__, __func__);
7655 event = le16_to_cpu(mpi_reply->Event);
7659 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7661 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7662 (Mpi2EventDataSasBroadcastPrimitive_t *)
7663 mpi_reply->EventData;
7665 if (baen_data->Primitive !=
7666 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7669 if (ioc->broadcast_aen_busy) {
7670 ioc->broadcast_aen_pending++;
7673 ioc->broadcast_aen_busy = 1;
7677 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7678 _scsih_check_topo_delete_events(ioc,
7679 (Mpi2EventDataSasTopologyChangeList_t *)
7680 mpi_reply->EventData);
7682 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7683 _scsih_check_ir_config_unhide_events(ioc,
7684 (Mpi2EventDataIrConfigChangeList_t *)
7685 mpi_reply->EventData);
7687 case MPI2_EVENT_IR_VOLUME:
7688 _scsih_check_volume_delete_events(ioc,
7689 (Mpi2EventDataIrVolume_t *)
7690 mpi_reply->EventData);
7692 case MPI2_EVENT_LOG_ENTRY_ADDED:
7694 Mpi2EventDataLogEntryAdded_t *log_entry;
7697 if (!ioc->is_warpdrive)
7700 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7701 mpi_reply->EventData;
7702 log_code = (__le32 *)log_entry->LogData;
7704 if (le16_to_cpu(log_entry->LogEntryQualifier)
7705 != MPT2_WARPDRIVE_LOGENTRY)
7708 switch (le32_to_cpu(*log_code)) {
7709 case MPT2_WARPDRIVE_LC_SSDT:
7710 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7711 "IO Throttling has occurred in the WarpDrive "
7712 "subsystem. Check WarpDrive documentation for "
7713 "additional details.\n", ioc->name);
7715 case MPT2_WARPDRIVE_LC_SSDLW:
7716 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7717 "Program/Erase Cycles for the WarpDrive subsystem "
7718 "in degraded range. Check WarpDrive documentation "
7719 "for additional details.\n", ioc->name);
7721 case MPT2_WARPDRIVE_LC_SSDLF:
7722 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7723 "There are no Program/Erase Cycles for the "
7724 "WarpDrive subsystem. The storage device will be "
7725 "in read-only mode. Check WarpDrive documentation "
7726 "for additional details.\n", ioc->name);
7728 case MPT2_WARPDRIVE_LC_BRMF:
7729 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7730 "The Backup Rail Monitor has failed on the "
7731 "WarpDrive subsystem. Check WarpDrive "
7732 "documentation for additional details.\n",
7739 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7740 case MPI2_EVENT_IR_OPERATION_STATUS:
7741 case MPI2_EVENT_SAS_DISCOVERY:
7742 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7743 case MPI2_EVENT_IR_PHYSICAL_DISK:
7746 case MPI2_EVENT_TEMP_THRESHOLD:
7747 _scsih_temp_threshold_events(ioc,
7748 (Mpi2EventDataTemperature_t *)
7749 mpi_reply->EventData);
7752 default: /* ignore the rest */
7756 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7757 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7759 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7760 ioc->name, __FILE__, __LINE__, __func__);
7764 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7765 fw_event->ioc = ioc;
7766 fw_event->VF_ID = mpi_reply->VF_ID;
7767 fw_event->VP_ID = mpi_reply->VP_ID;
7768 fw_event->event = event;
7769 _scsih_fw_event_add(ioc, fw_event);
7773 /* shost template */
7774 static struct scsi_host_template scsih_driver_template = {
7775 .module = THIS_MODULE,
7776 .name = "Fusion MPT SAS Host",
7777 .proc_name = MPT2SAS_DRIVER_NAME,
7778 .queuecommand = _scsih_qcmd,
7779 .target_alloc = _scsih_target_alloc,
7780 .slave_alloc = _scsih_slave_alloc,
7781 .slave_configure = _scsih_slave_configure,
7782 .target_destroy = _scsih_target_destroy,
7783 .slave_destroy = _scsih_slave_destroy,
7784 .scan_finished = _scsih_scan_finished,
7785 .scan_start = _scsih_scan_start,
7786 .change_queue_depth = _scsih_change_queue_depth,
7787 .eh_abort_handler = _scsih_abort,
7788 .eh_device_reset_handler = _scsih_dev_reset,
7789 .eh_target_reset_handler = _scsih_target_reset,
7790 .eh_host_reset_handler = _scsih_host_reset,
7791 .bios_param = _scsih_bios_param,
7794 .sg_tablesize = MPT2SAS_SG_DEPTH,
7795 .max_sectors = 32767,
7797 .use_clustering = ENABLE_CLUSTERING,
7798 .shost_attrs = mpt2sas_host_attrs,
7799 .sdev_attrs = mpt2sas_dev_attrs,
7800 .track_queue_depth = 1,
7804 * _scsih_expander_node_remove - removing expander device from list.
7805 * @ioc: per adapter object
7806 * @sas_expander: the sas_device object
7807 * Context: Calling function should acquire ioc->sas_node_lock.
7809 * Removing object and freeing associated memory from the
7810 * ioc->sas_expander_list.
7815 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7816 struct _sas_node *sas_expander)
7818 struct _sas_port *mpt2sas_port, *next;
7820 /* remove sibling ports attached to this expander */
7821 list_for_each_entry_safe(mpt2sas_port, next,
7822 &sas_expander->sas_port_list, port_list) {
7823 if (ioc->shost_recovery)
7825 if (mpt2sas_port->remote_identify.device_type ==
7827 mpt2sas_device_remove_by_sas_address(ioc,
7828 mpt2sas_port->remote_identify.sas_address);
7829 else if (mpt2sas_port->remote_identify.device_type ==
7830 SAS_EDGE_EXPANDER_DEVICE ||
7831 mpt2sas_port->remote_identify.device_type ==
7832 SAS_FANOUT_EXPANDER_DEVICE)
7833 mpt2sas_expander_remove(ioc,
7834 mpt2sas_port->remote_identify.sas_address);
7837 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7838 sas_expander->sas_address_parent);
7840 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7841 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7842 sas_expander->handle, (unsigned long long)
7843 sas_expander->sas_address);
7845 kfree(sas_expander->phy);
7846 kfree(sas_expander);
7850 * _scsih_ir_shutdown - IR shutdown notification
7851 * @ioc: per adapter object
7853 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7854 * the host system is shutting down.
7859 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7861 Mpi2RaidActionRequest_t *mpi_request;
7862 Mpi2RaidActionReply_t *mpi_reply;
7865 /* is IR firmware build loaded ? */
7866 if (!ioc->ir_firmware)
7869 mutex_lock(&ioc->scsih_cmds.mutex);
7871 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7872 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7873 ioc->name, __func__);
7876 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7878 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7880 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7881 ioc->name, __func__);
7882 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7886 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7887 ioc->scsih_cmds.smid = smid;
7888 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7890 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7891 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7893 if (!ioc->hide_ir_msg)
7894 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7895 init_completion(&ioc->scsih_cmds.done);
7896 mpt2sas_base_put_smid_default(ioc, smid);
7897 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7899 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7900 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7901 ioc->name, __func__);
7905 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7906 mpi_reply = ioc->scsih_cmds.reply;
7908 if (!ioc->hide_ir_msg)
7909 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7910 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7911 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7912 le32_to_cpu(mpi_reply->IOCLogInfo));
7916 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7917 mutex_unlock(&ioc->scsih_cmds.mutex);
7921 * _scsih_shutdown - routine call during system shutdown
7922 * @pdev: PCI device struct
7927 _scsih_shutdown(struct pci_dev *pdev)
7929 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7930 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7931 struct workqueue_struct *wq;
7932 unsigned long flags;
7934 ioc->remove_host = 1;
7935 _scsih_fw_event_cleanup_queue(ioc);
7937 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7938 wq = ioc->firmware_event_thread;
7939 ioc->firmware_event_thread = NULL;
7940 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7942 destroy_workqueue(wq);
7944 _scsih_ir_shutdown(ioc);
7945 mpt2sas_base_detach(ioc);
7949 * _scsih_remove - detach and remove add host
7950 * @pdev: PCI device struct
7952 * Routine called when unloading the driver.
7956 _scsih_remove(struct pci_dev *pdev)
7958 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7959 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7960 struct _sas_port *mpt2sas_port, *next_port;
7961 struct _raid_device *raid_device, *next;
7962 struct MPT2SAS_TARGET *sas_target_priv_data;
7963 struct workqueue_struct *wq;
7964 unsigned long flags;
7966 ioc->remove_host = 1;
7967 _scsih_fw_event_cleanup_queue(ioc);
7969 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7970 wq = ioc->firmware_event_thread;
7971 ioc->firmware_event_thread = NULL;
7972 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7974 destroy_workqueue(wq);
7976 /* release all the volumes */
7977 _scsih_ir_shutdown(ioc);
7978 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7980 if (raid_device->starget) {
7981 sas_target_priv_data =
7982 raid_device->starget->hostdata;
7983 sas_target_priv_data->deleted = 1;
7984 scsi_remove_target(&raid_device->starget->dev);
7986 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7987 "(0x%016llx)\n", ioc->name, raid_device->handle,
7988 (unsigned long long) raid_device->wwid);
7989 _scsih_raid_device_remove(ioc, raid_device);
7992 /* free ports attached to the sas_host */
7993 list_for_each_entry_safe(mpt2sas_port, next_port,
7994 &ioc->sas_hba.sas_port_list, port_list) {
7995 if (mpt2sas_port->remote_identify.device_type ==
7997 mpt2sas_device_remove_by_sas_address(ioc,
7998 mpt2sas_port->remote_identify.sas_address);
7999 else if (mpt2sas_port->remote_identify.device_type ==
8000 SAS_EDGE_EXPANDER_DEVICE ||
8001 mpt2sas_port->remote_identify.device_type ==
8002 SAS_FANOUT_EXPANDER_DEVICE)
8003 mpt2sas_expander_remove(ioc,
8004 mpt2sas_port->remote_identify.sas_address);
8007 /* free phys attached to the sas_host */
8008 if (ioc->sas_hba.num_phys) {
8009 kfree(ioc->sas_hba.phy);
8010 ioc->sas_hba.phy = NULL;
8011 ioc->sas_hba.num_phys = 0;
8014 sas_remove_host(shost);
8015 scsi_remove_host(shost);
8016 mpt2sas_base_detach(ioc);
8017 spin_lock(&gioc_lock);
8018 list_del(&ioc->list);
8019 spin_unlock(&gioc_lock);
8020 scsi_host_put(shost);
8024 * _scsih_probe_boot_devices - reports 1st device
8025 * @ioc: per adapter object
8027 * If specified in bios page 2, this routine reports the 1st
8028 * device scsi-ml or sas transport for persistent boot device
8029 * purposes. Please refer to function _scsih_determine_boot_device()
8032 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
8036 struct _sas_device *sas_device;
8037 struct _raid_device *raid_device;
8039 u64 sas_address_parent;
8041 unsigned long flags;
8044 /* no Bios, return immediately */
8045 if (!ioc->bios_pg3.BiosVersion)
8050 if (ioc->req_boot_device.device) {
8051 device = ioc->req_boot_device.device;
8052 is_raid = ioc->req_boot_device.is_raid;
8053 } else if (ioc->req_alt_boot_device.device) {
8054 device = ioc->req_alt_boot_device.device;
8055 is_raid = ioc->req_alt_boot_device.is_raid;
8056 } else if (ioc->current_boot_device.device) {
8057 device = ioc->current_boot_device.device;
8058 is_raid = ioc->current_boot_device.is_raid;
8065 raid_device = device;
8066 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8067 raid_device->id, 0);
8069 _scsih_raid_device_remove(ioc, raid_device);
8071 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8072 sas_device = device;
8073 handle = sas_device->handle;
8074 sas_address_parent = sas_device->sas_address_parent;
8075 sas_address = sas_device->sas_address;
8076 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8077 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8079 if (ioc->hide_drives)
8081 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
8082 sas_device->sas_address_parent)) {
8083 _scsih_sas_device_remove(ioc, sas_device);
8084 } else if (!sas_device->starget) {
8085 if (!ioc->is_driver_loading) {
8086 mpt2sas_transport_port_remove(ioc,
8088 sas_address_parent);
8089 _scsih_sas_device_remove(ioc, sas_device);
8096 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8097 * @ioc: per adapter object
8099 * Called during initial loading of the driver.
8102 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
8104 struct _raid_device *raid_device, *raid_next;
8107 list_for_each_entry_safe(raid_device, raid_next,
8108 &ioc->raid_device_list, list) {
8109 if (raid_device->starget)
8111 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8112 raid_device->id, 0);
8114 _scsih_raid_device_remove(ioc, raid_device);
8118 static struct _sas_device *get_next_sas_device(struct MPT2SAS_ADAPTER *ioc)
8120 struct _sas_device *sas_device = NULL;
8121 unsigned long flags;
8123 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8124 if (!list_empty(&ioc->sas_device_init_list)) {
8125 sas_device = list_first_entry(&ioc->sas_device_init_list,
8126 struct _sas_device, list);
8127 sas_device_get(sas_device);
8129 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8134 static void sas_device_make_active(struct MPT2SAS_ADAPTER *ioc,
8135 struct _sas_device *sas_device)
8137 unsigned long flags;
8139 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8142 * Since we dropped the lock during the call to port_add(), we need to
8143 * be careful here that somebody else didn't move or delete this item
8144 * while we were busy with other things.
8146 * If it was on the list, we need a put() for the reference the list
8147 * had. Either way, we need a get() for the destination list.
8149 if (!list_empty(&sas_device->list)) {
8150 list_del_init(&sas_device->list);
8151 sas_device_put(sas_device);
8154 sas_device_get(sas_device);
8155 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8157 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8161 * _scsih_probe_sas - reporting sas devices to sas transport
8162 * @ioc: per adapter object
8164 * Called during initial loading of the driver.
8167 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
8169 struct _sas_device *sas_device;
8171 if (ioc->hide_drives)
8174 while ((sas_device = get_next_sas_device(ioc))) {
8175 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
8176 sas_device->sas_address_parent)) {
8177 _scsih_sas_device_remove(ioc, sas_device);
8178 sas_device_put(sas_device);
8180 } else if (!sas_device->starget) {
8181 if (!ioc->is_driver_loading) {
8182 mpt2sas_transport_port_remove(ioc,
8183 sas_device->sas_address,
8184 sas_device->sas_address_parent);
8185 _scsih_sas_device_remove(ioc, sas_device);
8186 sas_device_put(sas_device);
8191 sas_device_make_active(ioc, sas_device);
8192 sas_device_put(sas_device);
8197 * _scsih_probe_devices - probing for devices
8198 * @ioc: per adapter object
8200 * Called during initial loading of the driver.
8203 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8205 u16 volume_mapping_flags;
8207 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8208 return; /* return when IOC doesn't support initiator mode */
8210 _scsih_probe_boot_devices(ioc);
8212 if (ioc->ir_firmware) {
8213 volume_mapping_flags =
8214 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8215 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8216 if (volume_mapping_flags ==
8217 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8218 _scsih_probe_raid(ioc);
8219 _scsih_probe_sas(ioc);
8221 _scsih_probe_sas(ioc);
8222 _scsih_probe_raid(ioc);
8225 _scsih_probe_sas(ioc);
8230 * _scsih_scan_start - scsi lld callback for .scan_start
8231 * @shost: SCSI host pointer
8233 * The shost has the ability to discover targets on its own instead
8234 * of scanning the entire bus. In our implemention, we will kick off
8235 * firmware discovery.
8238 _scsih_scan_start(struct Scsi_Host *shost)
8240 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8243 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8244 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8246 if (disable_discovery > 0)
8249 ioc->start_scan = 1;
8250 rc = mpt2sas_port_enable(ioc);
8253 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8257 * _scsih_scan_finished - scsi lld callback for .scan_finished
8258 * @shost: SCSI host pointer
8259 * @time: elapsed time of the scan in jiffies
8261 * This function will be called periodically until it returns 1 with the
8262 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8263 * we wait for firmware discovery to complete, then return 1.
8266 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8268 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8270 if (disable_discovery > 0) {
8271 ioc->is_driver_loading = 0;
8272 ioc->wait_for_discovery_to_complete = 0;
8276 if (time >= (300 * HZ)) {
8277 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8278 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8279 "(timeout=300s)\n", ioc->name);
8280 ioc->is_driver_loading = 0;
8284 if (ioc->start_scan)
8287 if (ioc->start_scan_failed) {
8288 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8289 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8290 ioc->is_driver_loading = 0;
8291 ioc->wait_for_discovery_to_complete = 0;
8292 ioc->remove_host = 1;
8296 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8297 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8299 if (ioc->wait_for_discovery_to_complete) {
8300 ioc->wait_for_discovery_to_complete = 0;
8301 _scsih_probe_devices(ioc);
8303 mpt2sas_base_start_watchdog(ioc);
8304 ioc->is_driver_loading = 0;
8310 * _scsih_probe - attach and add scsi host
8311 * @pdev: PCI device struct
8312 * @id: pci device id
8314 * Returns 0 success, anything else error.
8317 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8319 struct MPT2SAS_ADAPTER *ioc;
8320 struct Scsi_Host *shost;
8323 shost = scsi_host_alloc(&scsih_driver_template,
8324 sizeof(struct MPT2SAS_ADAPTER));
8328 /* init local params */
8329 ioc = shost_priv(shost);
8330 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8331 INIT_LIST_HEAD(&ioc->list);
8332 spin_lock(&gioc_lock);
8333 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8334 spin_unlock(&gioc_lock);
8336 ioc->id = mpt_ids++;
8337 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8339 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8340 ioc->is_warpdrive = 1;
8341 ioc->hide_ir_msg = 1;
8343 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8344 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8345 ioc->tm_cb_idx = tm_cb_idx;
8346 ioc->ctl_cb_idx = ctl_cb_idx;
8347 ioc->base_cb_idx = base_cb_idx;
8348 ioc->port_enable_cb_idx = port_enable_cb_idx;
8349 ioc->transport_cb_idx = transport_cb_idx;
8350 ioc->scsih_cb_idx = scsih_cb_idx;
8351 ioc->config_cb_idx = config_cb_idx;
8352 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8353 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8354 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8355 ioc->logging_level = logging_level;
8356 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8357 /* misc semaphores and spin locks */
8358 mutex_init(&ioc->reset_in_progress_mutex);
8359 /* initializing pci_access_mutex lock */
8360 mutex_init(&ioc->pci_access_mutex);
8361 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8362 spin_lock_init(&ioc->scsi_lookup_lock);
8363 spin_lock_init(&ioc->sas_device_lock);
8364 spin_lock_init(&ioc->sas_node_lock);
8365 spin_lock_init(&ioc->fw_event_lock);
8366 spin_lock_init(&ioc->raid_device_lock);
8368 INIT_LIST_HEAD(&ioc->sas_device_list);
8369 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8370 INIT_LIST_HEAD(&ioc->sas_expander_list);
8371 INIT_LIST_HEAD(&ioc->fw_event_list);
8372 INIT_LIST_HEAD(&ioc->raid_device_list);
8373 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8374 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8375 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8376 INIT_LIST_HEAD(&ioc->reply_queue_list);
8378 /* init shost parameters */
8379 shost->max_cmd_len = 32;
8380 shost->max_lun = max_lun;
8381 shost->transportt = mpt2sas_transport_template;
8382 shost->unique_id = ioc->id;
8384 if (max_sectors != 0xFFFF) {
8385 if (max_sectors < 64) {
8386 shost->max_sectors = 64;
8387 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8388 "for max_sectors, range is 64 to 32767. Assigning "
8389 "value of 64.\n", ioc->name, max_sectors);
8390 } else if (max_sectors > 32767) {
8391 shost->max_sectors = 32767;
8392 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8393 "for max_sectors, range is 64 to 8192. Assigning "
8394 "default value of 32767.\n", ioc->name,
8397 shost->max_sectors = max_sectors & 0xFFFE;
8398 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8399 "set to %d\n", ioc->name, shost->max_sectors);
8403 /* register EEDP capabilities with SCSI layer */
8405 scsi_host_set_prot(shost, prot_mask);
8407 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8408 | SHOST_DIF_TYPE2_PROTECTION
8409 | SHOST_DIF_TYPE3_PROTECTION);
8411 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8414 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8415 "fw_event%d", ioc->id);
8416 ioc->firmware_event_thread = create_singlethread_workqueue(
8417 ioc->firmware_event_name);
8418 if (!ioc->firmware_event_thread) {
8419 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8420 ioc->name, __FILE__, __LINE__, __func__);
8422 goto out_thread_fail;
8425 ioc->is_driver_loading = 1;
8426 if ((mpt2sas_base_attach(ioc))) {
8427 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8428 ioc->name, __FILE__, __LINE__, __func__);
8430 goto out_attach_fail;
8433 if (ioc->is_warpdrive) {
8434 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8435 ioc->hide_drives = 0;
8436 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8437 ioc->hide_drives = 1;
8439 if (_scsih_get_num_volumes(ioc))
8440 ioc->hide_drives = 1;
8442 ioc->hide_drives = 0;
8445 ioc->hide_drives = 0;
8447 rv = scsi_add_host(shost, &pdev->dev);
8449 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8450 ioc->name, __FILE__, __LINE__, __func__);
8451 goto out_add_shost_fail;
8454 scsi_scan_host(shost);
8459 mpt2sas_base_detach(ioc);
8461 destroy_workqueue(ioc->firmware_event_thread);
8463 spin_lock(&gioc_lock);
8464 list_del(&ioc->list);
8465 spin_unlock(&gioc_lock);
8466 scsi_host_put(shost);
8472 * _scsih_suspend - power management suspend main entry point
8473 * @pdev: PCI device struct
8474 * @state: PM state change to (usually PCI_D3)
8476 * Returns 0 success, anything else error.
8479 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8481 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8482 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8483 pci_power_t device_state;
8485 mpt2sas_base_stop_watchdog(ioc);
8486 scsi_block_requests(shost);
8487 _scsih_ir_shutdown(ioc);
8488 device_state = pci_choose_state(pdev, state);
8489 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8490 "operating state [D%d]\n", ioc->name, pdev,
8491 pci_name(pdev), device_state);
8493 mpt2sas_base_free_resources(ioc);
8494 pci_save_state(pdev);
8495 pci_set_power_state(pdev, device_state);
8500 * _scsih_resume - power management resume main entry point
8501 * @pdev: PCI device struct
8503 * Returns 0 success, anything else error.
8506 _scsih_resume(struct pci_dev *pdev)
8508 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8509 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8510 pci_power_t device_state = pdev->current_state;
8513 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8514 "operating state [D%d]\n", ioc->name, pdev,
8515 pci_name(pdev), device_state);
8517 pci_set_power_state(pdev, PCI_D0);
8518 pci_enable_wake(pdev, PCI_D0, 0);
8519 pci_restore_state(pdev);
8521 r = mpt2sas_base_map_resources(ioc);
8525 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8526 scsi_unblock_requests(shost);
8527 mpt2sas_base_start_watchdog(ioc);
8530 #endif /* CONFIG_PM */
8533 * _scsih_pci_error_detected - Called when a PCI error is detected.
8534 * @pdev: PCI device struct
8535 * @state: PCI channel state
8537 * Description: Called when a PCI error is detected.
8540 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8542 static pci_ers_result_t
8543 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8545 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8546 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8548 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8552 case pci_channel_io_normal:
8553 return PCI_ERS_RESULT_CAN_RECOVER;
8554 case pci_channel_io_frozen:
8555 /* Fatal error, prepare for slot reset */
8556 ioc->pci_error_recovery = 1;
8557 scsi_block_requests(ioc->shost);
8558 mpt2sas_base_stop_watchdog(ioc);
8559 mpt2sas_base_free_resources(ioc);
8560 return PCI_ERS_RESULT_NEED_RESET;
8561 case pci_channel_io_perm_failure:
8562 /* Permanent error, prepare for device removal */
8563 ioc->pci_error_recovery = 1;
8564 mpt2sas_base_stop_watchdog(ioc);
8565 _scsih_flush_running_cmds(ioc);
8566 return PCI_ERS_RESULT_DISCONNECT;
8568 return PCI_ERS_RESULT_NEED_RESET;
8572 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8573 * @pdev: PCI device struct
8575 * Description: This routine is called by the pci error recovery
8576 * code after the PCI slot has been reset, just before we
8577 * should resume normal operations.
8579 static pci_ers_result_t
8580 _scsih_pci_slot_reset(struct pci_dev *pdev)
8582 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8583 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8586 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8589 ioc->pci_error_recovery = 0;
8591 pci_restore_state(pdev);
8592 rc = mpt2sas_base_map_resources(ioc);
8594 return PCI_ERS_RESULT_DISCONNECT;
8597 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8600 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8601 (rc == 0) ? "success" : "failed");
8604 return PCI_ERS_RESULT_RECOVERED;
8606 return PCI_ERS_RESULT_DISCONNECT;
8610 * _scsih_pci_resume() - resume normal ops after PCI reset
8611 * @pdev: pointer to PCI device
8613 * Called when the error recovery driver tells us that its
8614 * OK to resume normal operation. Use completion to allow
8615 * halted scsi ops to resume.
8618 _scsih_pci_resume(struct pci_dev *pdev)
8620 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8621 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8623 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8625 pci_cleanup_aer_uncorrect_error_status(pdev);
8626 mpt2sas_base_start_watchdog(ioc);
8627 scsi_unblock_requests(ioc->shost);
8631 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8632 * @pdev: pointer to PCI device
8634 static pci_ers_result_t
8635 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8637 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8638 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8640 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8643 /* TODO - dump whatever for debugging purposes */
8645 /* Request a slot reset. */
8646 return PCI_ERS_RESULT_NEED_RESET;
8649 static const struct pci_error_handlers _scsih_err_handler = {
8650 .error_detected = _scsih_pci_error_detected,
8651 .mmio_enabled = _scsih_pci_mmio_enabled,
8652 .slot_reset = _scsih_pci_slot_reset,
8653 .resume = _scsih_pci_resume,
8656 static struct pci_driver scsih_driver = {
8657 .name = MPT2SAS_DRIVER_NAME,
8658 .id_table = scsih_pci_table,
8659 .probe = _scsih_probe,
8660 .remove = _scsih_remove,
8661 .shutdown = _scsih_shutdown,
8662 .err_handler = &_scsih_err_handler,
8664 .suspend = _scsih_suspend,
8665 .resume = _scsih_resume,
8669 /* raid transport support */
8670 static struct raid_function_template mpt2sas_raid_functions = {
8671 .cookie = &scsih_driver_template,
8672 .is_raid = _scsih_is_raid,
8673 .get_resync = _scsih_get_resync,
8674 .get_state = _scsih_get_state,
8678 * _scsih_init - main entry point for this driver.
8680 * Returns 0 success, anything else error.
8688 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8689 MPT2SAS_DRIVER_VERSION);
8691 mpt2sas_transport_template =
8692 sas_attach_transport(&mpt2sas_transport_functions);
8693 if (!mpt2sas_transport_template)
8695 /* raid transport support */
8696 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8697 if (!mpt2sas_raid_template) {
8698 sas_release_transport(mpt2sas_transport_template);
8702 mpt2sas_base_initialize_callback_handler();
8704 /* queuecommand callback hander */
8705 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8707 /* task management callback handler */
8708 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8710 /* base internal commands callback handler */
8711 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8712 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8713 mpt2sas_port_enable_done);
8715 /* transport internal commands callback handler */
8716 transport_cb_idx = mpt2sas_base_register_callback_handler(
8717 mpt2sas_transport_done);
8719 /* scsih internal commands callback handler */
8720 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8722 /* configuration page API internal commands callback handler */
8723 config_cb_idx = mpt2sas_base_register_callback_handler(
8724 mpt2sas_config_done);
8726 /* ctl module callback handler */
8727 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8729 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8730 _scsih_tm_tr_complete);
8732 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8733 _scsih_tm_volume_tr_complete);
8735 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8736 _scsih_sas_control_complete);
8740 error = pci_register_driver(&scsih_driver);
8742 /* raid transport support */
8743 raid_class_release(mpt2sas_raid_template);
8744 sas_release_transport(mpt2sas_transport_template);
8751 * _scsih_exit - exit point for this driver (when it is a module).
8753 * Returns 0 success, anything else error.
8758 printk(KERN_INFO "mpt2sas version %s unloading\n",
8759 MPT2SAS_DRIVER_VERSION);
8761 pci_unregister_driver(&scsih_driver);
8765 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8766 mpt2sas_base_release_callback_handler(tm_cb_idx);
8767 mpt2sas_base_release_callback_handler(base_cb_idx);
8768 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8769 mpt2sas_base_release_callback_handler(transport_cb_idx);
8770 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8771 mpt2sas_base_release_callback_handler(config_cb_idx);
8772 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8774 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8775 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8776 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8778 /* raid transport support */
8779 raid_class_release(mpt2sas_raid_template);
8780 sas_release_transport(mpt2sas_transport_template);
8784 module_init(_scsih_init);
8785 module_exit(_scsih_exit);