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);
83 /* local parameters */
84 static u8 scsi_io_cb_idx = -1;
85 static u8 tm_cb_idx = -1;
86 static u8 ctl_cb_idx = -1;
87 static u8 base_cb_idx = -1;
88 static u8 port_enable_cb_idx = -1;
89 static u8 transport_cb_idx = -1;
90 static u8 scsih_cb_idx = -1;
91 static u8 config_cb_idx = -1;
94 static u8 tm_tr_cb_idx = -1 ;
95 static u8 tm_tr_volume_cb_idx = -1 ;
96 static u8 tm_sas_control_cb_idx = -1;
98 /* command line options */
99 static u32 logging_level;
100 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
103 static ushort max_sectors = 0xFFFF;
104 module_param(max_sectors, ushort, 0);
105 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
107 static int missing_delay[2] = {-1, -1};
108 module_param_array(missing_delay, int, NULL, 0);
109 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
111 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
112 #define MPT2SAS_MAX_LUN (16895)
113 static int max_lun = MPT2SAS_MAX_LUN;
114 module_param(max_lun, int, 0);
115 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
117 /* diag_buffer_enable is bitwise
119 * bit 1 set = SNAPSHOT
120 * bit 2 set = EXTENDED
122 * Either bit can be set, or both
124 static int diag_buffer_enable = -1;
125 module_param(diag_buffer_enable, int, 0);
126 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
127 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
129 static int disable_discovery = -1;
130 module_param(disable_discovery, int, 0);
131 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
133 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
134 static int prot_mask = 0;
135 module_param(prot_mask, int, 0);
136 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
139 * struct sense_info - common structure for obtaining sense keys
141 * @asc: additional sense code
142 * @ascq: additional sense code qualifier
151 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
152 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
153 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
155 * struct fw_event_work - firmware event struct
156 * @list: link list framework
157 * @work: work object (ioc->fault_reset_work_q)
158 * @cancel_pending_work: flag set during reset handling
159 * @ioc: per adapter object
160 * @device_handle: device handle
161 * @VF_ID: virtual function id
162 * @VP_ID: virtual port id
163 * @ignore: flag meaning this event has been marked to ignore
164 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
165 * @event_data: reply event data payload follows
167 * This object stored on ioc->fw_event_list.
169 struct fw_event_work {
170 struct list_head list;
171 u8 cancel_pending_work;
172 struct delayed_work delayed_work;
173 struct MPT2SAS_ADAPTER *ioc;
179 struct kref refcount;
180 char event_data[0] __aligned(4);
183 static void fw_event_work_free(struct kref *r)
185 kfree(container_of(r, struct fw_event_work, refcount));
188 static void fw_event_work_get(struct fw_event_work *fw_work)
190 kref_get(&fw_work->refcount);
193 static void fw_event_work_put(struct fw_event_work *fw_work)
195 kref_put(&fw_work->refcount, fw_event_work_free);
198 static struct fw_event_work *alloc_fw_event_work(int len)
200 struct fw_event_work *fw_event;
202 fw_event = kzalloc(sizeof(*fw_event) + len, GFP_ATOMIC);
206 kref_init(&fw_event->refcount);
210 /* raid transport support */
211 static struct raid_template *mpt2sas_raid_template;
214 * struct _scsi_io_transfer - scsi io transfer
215 * @handle: sas device handle (assigned by firmware)
216 * @is_raid: flag set for hidden raid components
217 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
218 * @data_length: data transfer length
219 * @data_dma: dma pointer to data
222 * @cdb_length: cdb length
224 * @timeout: timeout for this command
225 * @VF_ID: virtual function id
226 * @VP_ID: virtual port id
227 * @valid_reply: flag set for reply message
228 * @sense_length: sense length
229 * @ioc_status: ioc status
230 * @scsi_state: scsi state
231 * @scsi_status: scsi staus
232 * @log_info: log information
233 * @transfer_length: data length transfer when there is a reply message
235 * Used for sending internal scsi commands to devices within this module.
236 * Refer to _scsi_send_scsi_io().
238 struct _scsi_io_transfer {
241 enum dma_data_direction dir;
244 u8 sense[SCSI_SENSE_BUFFERSIZE];
252 /* the following bits are only valid when 'valid_reply = 1' */
262 * The pci device ids are defined in mpi/mpi2_cnfg.h.
264 static struct pci_device_id scsih_pci_table[] = {
265 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
266 PCI_ANY_ID, PCI_ANY_ID },
268 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
269 PCI_ANY_ID, PCI_ANY_ID },
270 /* Liberator ~ 2108 */
271 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
272 PCI_ANY_ID, PCI_ANY_ID },
273 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
274 PCI_ANY_ID, PCI_ANY_ID },
275 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
276 PCI_ANY_ID, PCI_ANY_ID },
278 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
279 PCI_ANY_ID, PCI_ANY_ID },
280 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
281 PCI_ANY_ID, PCI_ANY_ID },
282 /* Thunderbolt ~ 2208 */
283 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
284 PCI_ANY_ID, PCI_ANY_ID },
285 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
286 PCI_ANY_ID, PCI_ANY_ID },
287 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
288 PCI_ANY_ID, PCI_ANY_ID },
289 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
290 PCI_ANY_ID, PCI_ANY_ID },
291 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
292 PCI_ANY_ID, PCI_ANY_ID },
293 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
294 PCI_ANY_ID, PCI_ANY_ID },
296 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
297 PCI_ANY_ID, PCI_ANY_ID },
298 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
299 PCI_ANY_ID, PCI_ANY_ID },
300 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
301 PCI_ANY_ID, PCI_ANY_ID },
303 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
304 PCI_ANY_ID, PCI_ANY_ID },
305 {0} /* Terminating entry */
307 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
310 * _scsih_set_debug_level - global setting of ioc->logging_level.
312 * Note: The logging levels are defined in mpt2sas_debug.h.
315 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
317 int ret = param_set_int(val, kp);
318 struct MPT2SAS_ADAPTER *ioc;
323 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
324 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
325 ioc->logging_level = logging_level;
328 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
329 &logging_level, 0644);
332 * _scsih_srch_boot_sas_address - search based on sas_address
333 * @sas_address: sas address
334 * @boot_device: boot device object from bios page 2
336 * Returns 1 when there's a match, 0 means no match.
339 _scsih_srch_boot_sas_address(u64 sas_address,
340 Mpi2BootDeviceSasWwid_t *boot_device)
342 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
346 * _scsih_srch_boot_device_name - search based on device name
347 * @device_name: device name specified in INDENTIFY fram
348 * @boot_device: boot device object from bios page 2
350 * Returns 1 when there's a match, 0 means no match.
353 _scsih_srch_boot_device_name(u64 device_name,
354 Mpi2BootDeviceDeviceName_t *boot_device)
356 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
360 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
361 * @enclosure_logical_id: enclosure logical id
362 * @slot_number: slot number
363 * @boot_device: boot device object from bios page 2
365 * Returns 1 when there's a match, 0 means no match.
368 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
369 Mpi2BootDeviceEnclosureSlot_t *boot_device)
371 return (enclosure_logical_id == le64_to_cpu(boot_device->
372 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
373 SlotNumber)) ? 1 : 0;
377 * _scsih_is_boot_device - search for matching boot device.
378 * @sas_address: sas address
379 * @device_name: device name specified in INDENTIFY fram
380 * @enclosure_logical_id: enclosure logical id
381 * @slot_number: slot number
382 * @form: specifies boot device form
383 * @boot_device: boot device object from bios page 2
385 * Returns 1 when there's a match, 0 means no match.
388 _scsih_is_boot_device(u64 sas_address, u64 device_name,
389 u64 enclosure_logical_id, u16 slot, u8 form,
390 Mpi2BiosPage2BootDevice_t *boot_device)
395 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
398 rc = _scsih_srch_boot_sas_address(
399 sas_address, &boot_device->SasWwid);
401 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
402 if (!enclosure_logical_id)
404 rc = _scsih_srch_boot_encl_slot(
405 enclosure_logical_id,
406 slot, &boot_device->EnclosureSlot);
408 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
411 rc = _scsih_srch_boot_device_name(
412 device_name, &boot_device->DeviceName);
414 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
422 * _scsih_get_sas_address - set the sas_address for given device handle
423 * @handle: device handle
424 * @sas_address: sas address
426 * Returns 0 success, non-zero when failure
429 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
432 Mpi2SasDevicePage0_t sas_device_pg0;
433 Mpi2ConfigReply_t mpi_reply;
437 if (handle <= ioc->sas_hba.num_phys) {
438 *sas_address = ioc->sas_hba.sas_address;
442 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
443 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
444 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
445 __FILE__, __LINE__, __func__);
449 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
450 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
451 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
455 /* we hit this becuase the given parent handle doesn't exist */
456 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
458 /* else error case */
459 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
460 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
461 __FILE__, __LINE__, __func__);
466 * _scsih_determine_boot_device - determine boot device.
467 * @ioc: per adapter object
468 * @device: either sas_device or raid_device object
469 * @is_raid: [flag] 1 = raid object, 0 = sas object
471 * Determines whether this device should be first reported device to
472 * to scsi-ml or sas transport, this purpose is for persistent boot device.
473 * There are primary, alternate, and current entries in bios page 2. The order
474 * priority is primary, alternate, then current. This routine saves
475 * the corresponding device object and is_raid flag in the ioc object.
476 * The saved data to be used later in _scsih_probe_boot_devices().
479 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
480 void *device, u8 is_raid)
482 struct _sas_device *sas_device;
483 struct _raid_device *raid_device;
486 u64 enclosure_logical_id;
489 /* only process this function when driver loads */
490 if (!ioc->is_driver_loading)
493 /* no Bios, return immediately */
494 if (!ioc->bios_pg3.BiosVersion)
499 sas_address = sas_device->sas_address;
500 device_name = sas_device->device_name;
501 enclosure_logical_id = sas_device->enclosure_logical_id;
502 slot = sas_device->slot;
504 raid_device = device;
505 sas_address = raid_device->wwid;
507 enclosure_logical_id = 0;
511 if (!ioc->req_boot_device.device) {
512 if (_scsih_is_boot_device(sas_address, device_name,
513 enclosure_logical_id, slot,
514 (ioc->bios_pg2.ReqBootDeviceForm &
515 MPI2_BIOSPAGE2_FORM_MASK),
516 &ioc->bios_pg2.RequestedBootDevice)) {
517 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
518 "%s: req_boot_device(0x%016llx)\n",
520 (unsigned long long)sas_address));
521 ioc->req_boot_device.device = device;
522 ioc->req_boot_device.is_raid = is_raid;
526 if (!ioc->req_alt_boot_device.device) {
527 if (_scsih_is_boot_device(sas_address, device_name,
528 enclosure_logical_id, slot,
529 (ioc->bios_pg2.ReqAltBootDeviceForm &
530 MPI2_BIOSPAGE2_FORM_MASK),
531 &ioc->bios_pg2.RequestedAltBootDevice)) {
532 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
533 "%s: req_alt_boot_device(0x%016llx)\n",
535 (unsigned long long)sas_address));
536 ioc->req_alt_boot_device.device = device;
537 ioc->req_alt_boot_device.is_raid = is_raid;
541 if (!ioc->current_boot_device.device) {
542 if (_scsih_is_boot_device(sas_address, device_name,
543 enclosure_logical_id, slot,
544 (ioc->bios_pg2.CurrentBootDeviceForm &
545 MPI2_BIOSPAGE2_FORM_MASK),
546 &ioc->bios_pg2.CurrentBootDevice)) {
547 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
548 "%s: current_boot_device(0x%016llx)\n",
550 (unsigned long long)sas_address));
551 ioc->current_boot_device.device = device;
552 ioc->current_boot_device.is_raid = is_raid;
557 static struct _sas_device *
558 __mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc,
559 struct MPT2SAS_TARGET *tgt_priv)
561 struct _sas_device *ret;
563 assert_spin_locked(&ioc->sas_device_lock);
565 ret = tgt_priv->sdev;
572 static struct _sas_device *
573 mpt2sas_get_sdev_from_target(struct MPT2SAS_ADAPTER *ioc,
574 struct MPT2SAS_TARGET *tgt_priv)
576 struct _sas_device *ret;
579 spin_lock_irqsave(&ioc->sas_device_lock, flags);
580 ret = __mpt2sas_get_sdev_from_target(ioc, tgt_priv);
581 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
588 __mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc,
591 struct _sas_device *sas_device;
593 assert_spin_locked(&ioc->sas_device_lock);
595 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
596 if (sas_device->sas_address == sas_address)
599 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
600 if (sas_device->sas_address == sas_address)
606 sas_device_get(sas_device);
611 * mpt2sas_get_sdev_by_addr - sas device search
612 * @ioc: per adapter object
613 * @sas_address: sas address
614 * Context: Calling function should acquire ioc->sas_device_lock
616 * This searches for sas_device based on sas_address, then return sas_device
620 mpt2sas_get_sdev_by_addr(struct MPT2SAS_ADAPTER *ioc,
623 struct _sas_device *sas_device;
626 spin_lock_irqsave(&ioc->sas_device_lock, flags);
627 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
629 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
634 static struct _sas_device *
635 __mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
637 struct _sas_device *sas_device;
639 assert_spin_locked(&ioc->sas_device_lock);
641 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
642 if (sas_device->handle == handle)
645 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
646 if (sas_device->handle == handle)
652 sas_device_get(sas_device);
657 * mpt2sas_get_sdev_by_handle - sas device search
658 * @ioc: per adapter object
659 * @handle: sas device handle (assigned by firmware)
660 * Context: Calling function should acquire ioc->sas_device_lock
662 * This searches for sas_device based on sas_address, then return sas_device
665 static struct _sas_device *
666 mpt2sas_get_sdev_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
668 struct _sas_device *sas_device;
671 spin_lock_irqsave(&ioc->sas_device_lock, flags);
672 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
673 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
679 * _scsih_sas_device_remove - remove sas_device from list.
680 * @ioc: per adapter object
681 * @sas_device: the sas_device object
682 * Context: This function will acquire ioc->sas_device_lock.
684 * If sas_device is on the list, remove it and decrement its reference count.
687 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
688 struct _sas_device *sas_device)
696 * The lock serializes access to the list, but we still need to verify
697 * that nobody removed the entry while we were waiting on the lock.
699 spin_lock_irqsave(&ioc->sas_device_lock, flags);
700 if (!list_empty(&sas_device->list)) {
701 list_del_init(&sas_device->list);
702 sas_device_put(sas_device);
704 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
709 * _scsih_sas_device_add - insert sas_device to the list.
710 * @ioc: per adapter object
711 * @sas_device: the sas_device object
712 * Context: This function will acquire ioc->sas_device_lock.
714 * Adding new object to the ioc->sas_device_list.
717 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
718 struct _sas_device *sas_device)
722 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
723 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
724 sas_device->handle, (unsigned long long)sas_device->sas_address));
726 spin_lock_irqsave(&ioc->sas_device_lock, flags);
727 sas_device_get(sas_device);
728 list_add_tail(&sas_device->list, &ioc->sas_device_list);
729 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
731 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
732 sas_device->sas_address_parent)) {
733 _scsih_sas_device_remove(ioc, sas_device);
734 } else if (!sas_device->starget) {
735 /* When asyn scanning is enabled, its not possible to remove
736 * devices while scanning is turned on due to an oops in
737 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
739 if (!ioc->is_driver_loading) {
740 mpt2sas_transport_port_remove(ioc,
741 sas_device->sas_address,
742 sas_device->sas_address_parent);
743 _scsih_sas_device_remove(ioc, sas_device);
749 * _scsih_sas_device_init_add - insert sas_device to the list.
750 * @ioc: per adapter object
751 * @sas_device: the sas_device object
752 * Context: This function will acquire ioc->sas_device_lock.
754 * Adding new object at driver load time to the ioc->sas_device_init_list.
757 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
758 struct _sas_device *sas_device)
762 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
763 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
764 sas_device->handle, (unsigned long long)sas_device->sas_address));
766 spin_lock_irqsave(&ioc->sas_device_lock, flags);
767 sas_device_get(sas_device);
768 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
769 _scsih_determine_boot_device(ioc, sas_device, 0);
770 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
774 * _scsih_raid_device_find_by_id - raid device search
775 * @ioc: per adapter object
776 * @id: sas device target id
777 * @channel: sas device channel
778 * Context: Calling function should acquire ioc->raid_device_lock
780 * This searches for raid_device based on target id, then return raid_device
783 static struct _raid_device *
784 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
786 struct _raid_device *raid_device, *r;
789 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
790 if (raid_device->id == id && raid_device->channel == channel) {
801 * _scsih_raid_device_find_by_handle - raid device search
802 * @ioc: per adapter object
803 * @handle: sas device handle (assigned by firmware)
804 * Context: Calling function should acquire ioc->raid_device_lock
806 * This searches for raid_device based on handle, then return raid_device
809 static struct _raid_device *
810 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
812 struct _raid_device *raid_device, *r;
815 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
816 if (raid_device->handle != handle)
827 * _scsih_raid_device_find_by_wwid - raid device search
828 * @ioc: per adapter object
829 * @handle: sas device handle (assigned by firmware)
830 * Context: Calling function should acquire ioc->raid_device_lock
832 * This searches for raid_device based on wwid, then return raid_device
835 static struct _raid_device *
836 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
838 struct _raid_device *raid_device, *r;
841 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
842 if (raid_device->wwid != wwid)
853 * _scsih_raid_device_add - add raid_device object
854 * @ioc: per adapter object
855 * @raid_device: raid_device object
857 * This is added to the raid_device_list link list.
860 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
861 struct _raid_device *raid_device)
865 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
866 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
867 raid_device->handle, (unsigned long long)raid_device->wwid));
869 spin_lock_irqsave(&ioc->raid_device_lock, flags);
870 list_add_tail(&raid_device->list, &ioc->raid_device_list);
871 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
875 * _scsih_raid_device_remove - delete raid_device object
876 * @ioc: per adapter object
877 * @raid_device: raid_device object
881 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
882 struct _raid_device *raid_device)
886 spin_lock_irqsave(&ioc->raid_device_lock, flags);
887 list_del(&raid_device->list);
889 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
893 * mpt2sas_scsih_expander_find_by_handle - expander device search
894 * @ioc: per adapter object
895 * @handle: expander handle (assigned by firmware)
896 * Context: Calling function should acquire ioc->sas_device_lock
898 * This searches for expander device based on handle, then returns the
902 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
904 struct _sas_node *sas_expander, *r;
907 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
908 if (sas_expander->handle != handle)
918 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
919 * @ioc: per adapter object
920 * @sas_address: sas address
921 * Context: Calling function should acquire ioc->sas_node_lock.
923 * This searches for expander device based on sas_address, then returns the
927 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
930 struct _sas_node *sas_expander, *r;
933 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
934 if (sas_expander->sas_address != sas_address)
944 * _scsih_expander_node_add - insert expander device to the list.
945 * @ioc: per adapter object
946 * @sas_expander: the sas_device object
947 * Context: This function will acquire ioc->sas_node_lock.
949 * Adding new object to the ioc->sas_expander_list.
954 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
955 struct _sas_node *sas_expander)
959 spin_lock_irqsave(&ioc->sas_node_lock, flags);
960 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
961 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
965 * _scsih_is_end_device - determines if device is an end device
966 * @device_info: bitfield providing information about the device.
969 * Returns 1 if end device.
972 _scsih_is_end_device(u32 device_info)
974 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
975 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
976 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
977 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
984 * _scsih_scsi_lookup_get - returns scmd entry
985 * @ioc: per adapter object
986 * @smid: system request message index
988 * Returns the smid stored scmd pointer.
990 static struct scsi_cmnd *
991 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
993 return ioc->scsi_lookup[smid - 1].scmd;
997 * _scsih_scsi_lookup_get_clear - returns scmd entry
998 * @ioc: per adapter object
999 * @smid: system request message index
1001 * Returns the smid stored scmd pointer.
1002 * Then will derefrence the stored scmd pointer.
1004 static inline struct scsi_cmnd *
1005 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1007 unsigned long flags;
1008 struct scsi_cmnd *scmd;
1010 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1011 scmd = ioc->scsi_lookup[smid - 1].scmd;
1012 ioc->scsi_lookup[smid - 1].scmd = NULL;
1013 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1019 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
1020 * @ioc: per adapter object
1021 * @smid: system request message index
1022 * @scmd: pointer to scsi command object
1023 * Context: This function will acquire ioc->scsi_lookup_lock.
1025 * This will search for a scmd pointer in the scsi_lookup array,
1026 * returning the revelent smid. A returned value of zero means invalid.
1029 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
1033 unsigned long flags;
1036 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1038 for (i = 0; i < ioc->scsiio_depth; i++) {
1039 if (ioc->scsi_lookup[i].scmd == scmd) {
1040 smid = ioc->scsi_lookup[i].smid;
1045 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1050 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
1051 * @ioc: per adapter object
1054 * Context: This function will acquire ioc->scsi_lookup_lock.
1056 * This will search for a matching channel:id in the scsi_lookup array,
1057 * returning 1 if found.
1060 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
1064 unsigned long flags;
1067 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1069 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1070 if (ioc->scsi_lookup[i].scmd &&
1071 (ioc->scsi_lookup[i].scmd->device->id == id &&
1072 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
1078 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1083 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
1084 * @ioc: per adapter object
1088 * Context: This function will acquire ioc->scsi_lookup_lock.
1090 * This will search for a matching channel:id:lun in the scsi_lookup array,
1091 * returning 1 if found.
1094 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
1095 unsigned int lun, int channel)
1098 unsigned long flags;
1101 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1103 for (i = 0 ; i < ioc->scsiio_depth; i++) {
1104 if (ioc->scsi_lookup[i].scmd &&
1105 (ioc->scsi_lookup[i].scmd->device->id == id &&
1106 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1107 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1113 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1118 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1119 * @ioc: per adapter object
1120 * @smid: smid associated to an IO request
1122 * Returns chain tracker(from ioc->free_chain_list)
1124 static struct chain_tracker *
1125 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1127 struct chain_tracker *chain_req;
1128 unsigned long flags;
1130 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1131 if (list_empty(&ioc->free_chain_list)) {
1132 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1133 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1134 "available\n", ioc->name));
1137 chain_req = list_entry(ioc->free_chain_list.next,
1138 struct chain_tracker, tracker_list);
1139 list_del_init(&chain_req->tracker_list);
1140 list_add_tail(&chain_req->tracker_list,
1141 &ioc->scsi_lookup[smid - 1].chain_list);
1142 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1147 * _scsih_build_scatter_gather - main sg creation routine
1148 * @ioc: per adapter object
1149 * @scmd: scsi command
1150 * @smid: system request message index
1153 * The main routine that builds scatter gather table from a given
1154 * scsi request sent via the .queuecommand main handler.
1156 * Returns 0 success, anything else error
1159 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1160 struct scsi_cmnd *scmd, u16 smid)
1162 Mpi2SCSIIORequest_t *mpi_request;
1163 dma_addr_t chain_dma;
1164 struct scatterlist *sg_scmd;
1165 void *sg_local, *chain;
1170 u32 sges_in_segment;
1172 u32 sgl_flags_last_element;
1173 u32 sgl_flags_end_buffer;
1174 struct chain_tracker *chain_req;
1176 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1178 /* init scatter gather flags */
1179 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1180 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1181 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1182 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1183 << MPI2_SGE_FLAGS_SHIFT;
1184 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1185 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1186 << MPI2_SGE_FLAGS_SHIFT;
1187 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1189 sg_scmd = scsi_sglist(scmd);
1190 sges_left = scsi_dma_map(scmd);
1191 if (sges_left < 0) {
1192 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1193 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1197 sg_local = &mpi_request->SGL;
1198 sges_in_segment = ioc->max_sges_in_main_message;
1199 if (sges_left <= sges_in_segment)
1200 goto fill_in_last_segment;
1202 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1203 (sges_in_segment * ioc->sge_size))/4;
1205 /* fill in main message segment when there is a chain following */
1206 while (sges_in_segment) {
1207 if (sges_in_segment == 1)
1208 ioc->base_add_sg_single(sg_local,
1209 sgl_flags_last_element | sg_dma_len(sg_scmd),
1210 sg_dma_address(sg_scmd));
1212 ioc->base_add_sg_single(sg_local, sgl_flags |
1213 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1214 sg_scmd = sg_next(sg_scmd);
1215 sg_local += ioc->sge_size;
1220 /* initializing the chain flags and pointers */
1221 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1222 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1225 chain = chain_req->chain_buffer;
1226 chain_dma = chain_req->chain_buffer_dma;
1228 sges_in_segment = (sges_left <=
1229 ioc->max_sges_in_chain_message) ? sges_left :
1230 ioc->max_sges_in_chain_message;
1231 chain_offset = (sges_left == sges_in_segment) ?
1232 0 : (sges_in_segment * ioc->sge_size)/4;
1233 chain_length = sges_in_segment * ioc->sge_size;
1235 chain_offset = chain_offset <<
1236 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1237 chain_length += ioc->sge_size;
1239 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1240 chain_length, chain_dma);
1243 goto fill_in_last_segment;
1245 /* fill in chain segments */
1246 while (sges_in_segment) {
1247 if (sges_in_segment == 1)
1248 ioc->base_add_sg_single(sg_local,
1249 sgl_flags_last_element |
1250 sg_dma_len(sg_scmd),
1251 sg_dma_address(sg_scmd));
1253 ioc->base_add_sg_single(sg_local, sgl_flags |
1254 sg_dma_len(sg_scmd),
1255 sg_dma_address(sg_scmd));
1256 sg_scmd = sg_next(sg_scmd);
1257 sg_local += ioc->sge_size;
1262 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1265 chain = chain_req->chain_buffer;
1266 chain_dma = chain_req->chain_buffer_dma;
1270 fill_in_last_segment:
1272 /* fill the last segment */
1275 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1276 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1278 ioc->base_add_sg_single(sg_local, sgl_flags |
1279 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1280 sg_scmd = sg_next(sg_scmd);
1281 sg_local += ioc->sge_size;
1289 * _scsih_change_queue_depth - setting device queue depth
1290 * @sdev: scsi device struct
1291 * @qdepth: requested queue depth
1293 * Returns queue depth.
1296 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1298 struct Scsi_Host *shost = sdev->host;
1300 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1301 struct MPT2SAS_DEVICE *sas_device_priv_data;
1302 struct MPT2SAS_TARGET *sas_target_priv_data;
1303 struct _sas_device *sas_device;
1304 unsigned long flags;
1306 max_depth = shost->can_queue;
1308 /* limit max device queue for SATA to 32 */
1309 sas_device_priv_data = sdev->hostdata;
1310 if (!sas_device_priv_data)
1312 sas_target_priv_data = sas_device_priv_data->sas_target;
1313 if (!sas_target_priv_data)
1315 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1318 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1319 sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data);
1321 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1322 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1324 sas_device_put(sas_device);
1326 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1329 if (!sdev->tagged_supported)
1331 if (qdepth > max_depth)
1333 return scsi_change_queue_depth(sdev, qdepth);
1337 * _scsih_target_alloc - target add routine
1338 * @starget: scsi target struct
1340 * Returns 0 if ok. Any other return is assumed to be an error and
1341 * the device is ignored.
1344 _scsih_target_alloc(struct scsi_target *starget)
1346 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1347 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1348 struct MPT2SAS_TARGET *sas_target_priv_data;
1349 struct _sas_device *sas_device;
1350 struct _raid_device *raid_device;
1351 unsigned long flags;
1352 struct sas_rphy *rphy;
1354 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1356 if (!sas_target_priv_data)
1359 starget->hostdata = sas_target_priv_data;
1360 sas_target_priv_data->starget = starget;
1361 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1364 if (starget->channel == RAID_CHANNEL) {
1365 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1366 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1369 sas_target_priv_data->handle = raid_device->handle;
1370 sas_target_priv_data->sas_address = raid_device->wwid;
1371 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1372 if (ioc->is_warpdrive)
1373 sas_target_priv_data->raid_device = raid_device;
1374 raid_device->starget = starget;
1376 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1380 /* sas/sata devices */
1381 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1382 rphy = dev_to_rphy(starget->dev.parent);
1383 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
1384 rphy->identify.sas_address);
1387 sas_target_priv_data->handle = sas_device->handle;
1388 sas_target_priv_data->sas_address = sas_device->sas_address;
1389 sas_target_priv_data->sdev = sas_device;
1390 sas_device->starget = starget;
1391 sas_device->id = starget->id;
1392 sas_device->channel = starget->channel;
1393 if (test_bit(sas_device->handle, ioc->pd_handles))
1394 sas_target_priv_data->flags |=
1395 MPT_TARGET_FLAGS_RAID_COMPONENT;
1398 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1404 * _scsih_target_destroy - target destroy routine
1405 * @starget: scsi target struct
1410 _scsih_target_destroy(struct scsi_target *starget)
1412 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1413 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1414 struct MPT2SAS_TARGET *sas_target_priv_data;
1415 struct _sas_device *sas_device;
1416 struct _raid_device *raid_device;
1417 unsigned long flags;
1418 struct sas_rphy *rphy;
1420 sas_target_priv_data = starget->hostdata;
1421 if (!sas_target_priv_data)
1424 if (starget->channel == RAID_CHANNEL) {
1425 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1426 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1429 raid_device->starget = NULL;
1430 raid_device->sdev = NULL;
1432 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1436 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1437 rphy = dev_to_rphy(starget->dev.parent);
1438 sas_device = __mpt2sas_get_sdev_from_target(ioc, sas_target_priv_data);
1439 if (sas_device && (sas_device->starget == starget) &&
1440 (sas_device->id == starget->id) &&
1441 (sas_device->channel == starget->channel))
1442 sas_device->starget = NULL;
1446 * Corresponding get() is in _scsih_target_alloc()
1448 sas_target_priv_data->sdev = NULL;
1449 sas_device_put(sas_device);
1451 sas_device_put(sas_device);
1453 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1456 kfree(sas_target_priv_data);
1457 starget->hostdata = NULL;
1461 * _scsih_slave_alloc - device add routine
1462 * @sdev: scsi device struct
1464 * Returns 0 if ok. Any other return is assumed to be an error and
1465 * the device is ignored.
1468 _scsih_slave_alloc(struct scsi_device *sdev)
1470 struct Scsi_Host *shost;
1471 struct MPT2SAS_ADAPTER *ioc;
1472 struct MPT2SAS_TARGET *sas_target_priv_data;
1473 struct MPT2SAS_DEVICE *sas_device_priv_data;
1474 struct scsi_target *starget;
1475 struct _raid_device *raid_device;
1476 struct _sas_device *sas_device;
1477 unsigned long flags;
1479 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1481 if (!sas_device_priv_data)
1484 sas_device_priv_data->lun = sdev->lun;
1485 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1487 starget = scsi_target(sdev);
1488 sas_target_priv_data = starget->hostdata;
1489 sas_target_priv_data->num_luns++;
1490 sas_device_priv_data->sas_target = sas_target_priv_data;
1491 sdev->hostdata = sas_device_priv_data;
1492 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1493 sdev->no_uld_attach = 1;
1495 shost = dev_to_shost(&starget->dev);
1496 ioc = shost_priv(shost);
1497 if (starget->channel == RAID_CHANNEL) {
1498 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1499 raid_device = _scsih_raid_device_find_by_id(ioc,
1500 starget->id, starget->channel);
1502 raid_device->sdev = sdev; /* raid is single lun */
1503 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1506 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1507 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1508 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
1509 sas_target_priv_data->sas_address);
1510 if (sas_device && (sas_device->starget == NULL)) {
1511 sdev_printk(KERN_INFO, sdev,
1512 "%s : sas_device->starget set to starget @ %d\n",
1513 __func__, __LINE__);
1514 sas_device->starget = starget;
1518 sas_device_put(sas_device);
1520 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1527 * _scsih_slave_destroy - device destroy routine
1528 * @sdev: scsi device struct
1533 _scsih_slave_destroy(struct scsi_device *sdev)
1535 struct MPT2SAS_TARGET *sas_target_priv_data;
1536 struct scsi_target *starget;
1537 struct Scsi_Host *shost;
1538 struct MPT2SAS_ADAPTER *ioc;
1539 struct _sas_device *sas_device;
1540 unsigned long flags;
1542 if (!sdev->hostdata)
1545 starget = scsi_target(sdev);
1546 sas_target_priv_data = starget->hostdata;
1547 sas_target_priv_data->num_luns--;
1549 shost = dev_to_shost(&starget->dev);
1550 ioc = shost_priv(shost);
1552 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1553 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1554 sas_device = __mpt2sas_get_sdev_from_target(ioc,
1555 sas_target_priv_data);
1556 if (sas_device && !sas_target_priv_data->num_luns)
1557 sas_device->starget = NULL;
1560 sas_device_put(sas_device);
1561 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1564 kfree(sdev->hostdata);
1565 sdev->hostdata = NULL;
1569 * _scsih_display_sata_capabilities - sata capabilities
1570 * @ioc: per adapter object
1571 * @handle: device handle
1572 * @sdev: scsi device struct
1575 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1576 u16 handle, struct scsi_device *sdev)
1578 Mpi2ConfigReply_t mpi_reply;
1579 Mpi2SasDevicePage0_t sas_device_pg0;
1584 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1585 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1586 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1587 ioc->name, __FILE__, __LINE__, __func__);
1591 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1592 MPI2_IOCSTATUS_MASK;
1593 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1594 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1595 ioc->name, __FILE__, __LINE__, __func__);
1599 flags = le16_to_cpu(sas_device_pg0.Flags);
1600 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1602 sdev_printk(KERN_INFO, sdev,
1603 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1604 "sw_preserve(%s)\n",
1605 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1606 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1607 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1609 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1610 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1611 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1615 * _scsih_is_raid - return boolean indicating device is raid volume
1616 * @dev the device struct object
1619 _scsih_is_raid(struct device *dev)
1621 struct scsi_device *sdev = to_scsi_device(dev);
1622 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1624 if (ioc->is_warpdrive)
1626 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1630 * _scsih_get_resync - get raid volume resync percent complete
1631 * @dev the device struct object
1634 _scsih_get_resync(struct device *dev)
1636 struct scsi_device *sdev = to_scsi_device(dev);
1637 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1638 static struct _raid_device *raid_device;
1639 unsigned long flags;
1640 Mpi2RaidVolPage0_t vol_pg0;
1641 Mpi2ConfigReply_t mpi_reply;
1642 u32 volume_status_flags;
1643 u8 percent_complete;
1646 percent_complete = 0;
1648 if (ioc->is_warpdrive)
1651 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1652 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1655 handle = raid_device->handle;
1656 percent_complete = raid_device->percent_complete;
1658 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1663 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1664 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1665 sizeof(Mpi2RaidVolPage0_t))) {
1666 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1667 ioc->name, __FILE__, __LINE__, __func__);
1668 percent_complete = 0;
1672 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1673 if (!(volume_status_flags &
1674 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1675 percent_complete = 0;
1678 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1682 * _scsih_get_state - get raid volume level
1683 * @dev the device struct object
1686 _scsih_get_state(struct device *dev)
1688 struct scsi_device *sdev = to_scsi_device(dev);
1689 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1690 static struct _raid_device *raid_device;
1691 unsigned long flags;
1692 Mpi2RaidVolPage0_t vol_pg0;
1693 Mpi2ConfigReply_t mpi_reply;
1695 enum raid_state state = RAID_STATE_UNKNOWN;
1698 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1699 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1702 handle = raid_device->handle;
1703 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1708 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1709 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1710 sizeof(Mpi2RaidVolPage0_t))) {
1711 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1712 ioc->name, __FILE__, __LINE__, __func__);
1716 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1717 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1718 state = RAID_STATE_RESYNCING;
1722 switch (vol_pg0.VolumeState) {
1723 case MPI2_RAID_VOL_STATE_OPTIMAL:
1724 case MPI2_RAID_VOL_STATE_ONLINE:
1725 state = RAID_STATE_ACTIVE;
1727 case MPI2_RAID_VOL_STATE_DEGRADED:
1728 state = RAID_STATE_DEGRADED;
1730 case MPI2_RAID_VOL_STATE_FAILED:
1731 case MPI2_RAID_VOL_STATE_MISSING:
1732 state = RAID_STATE_OFFLINE;
1736 raid_set_state(mpt2sas_raid_template, dev, state);
1740 * _scsih_set_level - set raid level
1741 * @sdev: scsi device struct
1742 * @volume_type: volume type
1745 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1747 enum raid_level level = RAID_LEVEL_UNKNOWN;
1749 switch (volume_type) {
1750 case MPI2_RAID_VOL_TYPE_RAID0:
1751 level = RAID_LEVEL_0;
1753 case MPI2_RAID_VOL_TYPE_RAID10:
1754 level = RAID_LEVEL_10;
1756 case MPI2_RAID_VOL_TYPE_RAID1E:
1757 level = RAID_LEVEL_1E;
1759 case MPI2_RAID_VOL_TYPE_RAID1:
1760 level = RAID_LEVEL_1;
1764 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1768 * _scsih_get_volume_capabilities - volume capabilities
1769 * @ioc: per adapter object
1770 * @sas_device: the raid_device object
1772 * Returns 0 for success, else 1
1775 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1776 struct _raid_device *raid_device)
1778 Mpi2RaidVolPage0_t *vol_pg0;
1779 Mpi2RaidPhysDiskPage0_t pd_pg0;
1780 Mpi2SasDevicePage0_t sas_device_pg0;
1781 Mpi2ConfigReply_t mpi_reply;
1785 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1786 &num_pds)) || !num_pds) {
1787 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1788 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1793 raid_device->num_pds = num_pds;
1794 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1795 sizeof(Mpi2RaidVol0PhysDisk_t));
1796 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1798 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1799 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1804 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1805 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1806 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1807 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1813 raid_device->volume_type = vol_pg0->VolumeType;
1815 /* figure out what the underlying devices are by
1816 * obtaining the device_info bits for the 1st device
1818 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1819 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1820 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1821 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1822 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1823 le16_to_cpu(pd_pg0.DevHandle)))) {
1824 raid_device->device_info =
1825 le32_to_cpu(sas_device_pg0.DeviceInfo);
1833 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1834 * @ioc: per adapter object
1837 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1839 Mpi2RaidVolPage1_t vol_pg1;
1840 Mpi2ConfigReply_t mpi_reply;
1841 struct _raid_device *raid_device;
1844 unsigned long flags;
1847 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1848 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1849 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1850 MPI2_IOCSTATUS_MASK;
1851 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1853 handle = le16_to_cpu(vol_pg1.DevHandle);
1854 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1855 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1857 raid_device->direct_io_enabled = 0;
1858 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1865 * _scsih_get_num_volumes - Get number of volumes in the ioc
1866 * @ioc: per adapter object
1869 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1871 Mpi2RaidVolPage1_t vol_pg1;
1872 Mpi2ConfigReply_t mpi_reply;
1878 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1879 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1880 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1881 MPI2_IOCSTATUS_MASK;
1882 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1885 handle = le16_to_cpu(vol_pg1.DevHandle);
1892 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1893 * @ioc: per adapter object
1894 * @raid_device: the raid_device object
1897 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1898 struct _raid_device *raid_device)
1900 Mpi2RaidVolPage0_t *vol_pg0;
1901 Mpi2RaidPhysDiskPage0_t pd_pg0;
1902 Mpi2ConfigReply_t mpi_reply;
1905 unsigned long stripe_sz, block_sz;
1906 u8 stripe_exp, block_exp;
1909 if (!ioc->is_warpdrive)
1912 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1913 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1914 "globally as drives are exposed\n", ioc->name);
1917 if (_scsih_get_num_volumes(ioc) > 1) {
1918 _scsih_disable_ddio(ioc);
1919 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1920 "globally as number of drives > 1\n", ioc->name);
1923 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1924 &num_pds)) || !num_pds) {
1925 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1926 "Failure in computing number of drives\n", ioc->name);
1930 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1931 sizeof(Mpi2RaidVol0PhysDisk_t));
1932 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1934 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1935 "Memory allocation failure for RVPG0\n", ioc->name);
1939 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1940 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1941 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1942 "Failure in retrieving RVPG0\n", ioc->name);
1948 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1949 * assumed for WARPDRIVE, disable direct I/O
1951 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1952 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1953 "for the drive with handle(0x%04x): num_mem=%d, "
1954 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1955 num_pds, MPT_MAX_WARPDRIVE_PDS);
1959 for (count = 0; count < num_pds; count++) {
1960 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1961 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1962 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1963 le16_to_cpu(pd_pg0.DevHandle) ==
1964 MPT2SAS_INVALID_DEVICE_HANDLE) {
1965 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1966 "disabled for the drive with handle(0x%04x) member"
1967 "handle retrieval failed for member number=%d\n",
1968 ioc->name, raid_device->handle,
1969 vol_pg0->PhysDisk[count].PhysDiskNum);
1972 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1973 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1974 if (dev_max_lba >> 32) {
1975 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1976 "disabled for the drive with handle(0x%04x) member"
1977 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1978 ioc->name, raid_device->handle,
1979 le16_to_cpu(pd_pg0.DevHandle),
1980 (unsigned long long)dev_max_lba);
1984 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1988 * Assumption for WD: Direct I/O is not supported if the volume is
1991 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
1992 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1993 "for the drive with handle(0x%04x): type=%d, "
1994 "s_sz=%uK, blk_size=%u\n", ioc->name,
1995 raid_device->handle, raid_device->volume_type,
1996 (le32_to_cpu(vol_pg0->StripeSize) *
1997 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
1998 le16_to_cpu(vol_pg0->BlockSize));
2002 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
2003 stripe_exp = find_first_bit(&stripe_sz, 32);
2004 if (stripe_exp == 32) {
2005 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
2006 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
2007 ioc->name, raid_device->handle,
2008 (le32_to_cpu(vol_pg0->StripeSize) *
2009 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
2012 raid_device->stripe_exponent = stripe_exp;
2013 block_sz = le16_to_cpu(vol_pg0->BlockSize);
2014 block_exp = find_first_bit(&block_sz, 16);
2015 if (block_exp == 16) {
2016 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
2017 "for the drive with handle(0x%04x) invalid block sz %u\n",
2018 ioc->name, raid_device->handle,
2019 le16_to_cpu(vol_pg0->BlockSize));
2022 raid_device->block_exponent = block_exp;
2023 raid_device->direct_io_enabled = 1;
2025 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
2026 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
2028 * WARPDRIVE: Though the following fields are not used for direct IO,
2029 * stored for future purpose:
2031 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
2032 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
2033 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
2040 raid_device->direct_io_enabled = 0;
2041 for (count = 0; count < num_pds; count++)
2042 raid_device->pd_handle[count] = 0;
2048 * _scsih_enable_tlr - setting TLR flags
2049 * @ioc: per adapter object
2050 * @sdev: scsi device struct
2052 * Enabling Transaction Layer Retries for tape devices when
2053 * vpd page 0x90 is present
2057 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
2060 if (sdev->type != TYPE_TAPE)
2063 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
2066 sas_enable_tlr(sdev);
2067 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
2068 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
2074 * _scsih_slave_configure - device configure routine.
2075 * @sdev: scsi device struct
2077 * Returns 0 if ok. Any other return is assumed to be an error and
2078 * the device is ignored.
2081 _scsih_slave_configure(struct scsi_device *sdev)
2083 struct Scsi_Host *shost = sdev->host;
2084 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
2085 struct MPT2SAS_DEVICE *sas_device_priv_data;
2086 struct MPT2SAS_TARGET *sas_target_priv_data;
2087 struct _sas_device *sas_device;
2088 struct _raid_device *raid_device;
2089 unsigned long flags;
2094 u16 handle, volume_handle = 0;
2095 u64 volume_wwid = 0;
2098 sas_device_priv_data = sdev->hostdata;
2099 sas_device_priv_data->configured_lun = 1;
2100 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
2101 sas_target_priv_data = sas_device_priv_data->sas_target;
2102 handle = sas_target_priv_data->handle;
2104 /* raid volume handling */
2105 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2107 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2108 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
2109 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2111 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2112 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2113 __LINE__, __func__));
2117 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2118 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2119 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2120 __LINE__, __func__));
2124 * WARPDRIVE: Initialize the required data for Direct IO
2126 _scsih_init_warpdrive_properties(ioc, raid_device);
2128 /* RAID Queue Depth Support
2129 * IS volume = underlying qdepth of drive type, either
2130 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2131 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2133 if (raid_device->device_info &
2134 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2135 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2138 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2139 if (raid_device->device_info &
2140 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2146 switch (raid_device->volume_type) {
2147 case MPI2_RAID_VOL_TYPE_RAID0:
2150 case MPI2_RAID_VOL_TYPE_RAID1E:
2151 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2152 if (ioc->manu_pg10.OEMIdentifier &&
2153 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2154 MFG10_GF0_R10_DISPLAY) &&
2155 !(raid_device->num_pds % 2))
2160 case MPI2_RAID_VOL_TYPE_RAID1:
2161 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2164 case MPI2_RAID_VOL_TYPE_RAID10:
2165 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2168 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2170 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2175 if (!ioc->hide_ir_msg)
2176 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2177 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2178 r_level, raid_device->handle,
2179 (unsigned long long)raid_device->wwid,
2180 raid_device->num_pds, ds);
2181 _scsih_change_queue_depth(sdev, qdepth);
2182 /* raid transport support */
2183 if (!ioc->is_warpdrive)
2184 _scsih_set_level(sdev, raid_device->volume_type);
2188 /* non-raid handling */
2189 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2190 if (mpt2sas_config_get_volume_handle(ioc, handle,
2192 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2193 "failure at %s:%d/%s()!\n", ioc->name,
2194 __FILE__, __LINE__, __func__));
2197 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2198 volume_handle, &volume_wwid)) {
2199 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2200 "failure at %s:%d/%s()!\n", ioc->name,
2201 __FILE__, __LINE__, __func__));
2206 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2207 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
2208 sas_device_priv_data->sas_target->sas_address);
2210 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2211 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2212 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2213 __LINE__, __func__));
2216 sas_device->volume_handle = volume_handle;
2217 sas_device->volume_wwid = volume_wwid;
2218 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2219 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2223 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2224 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2226 else if (sas_device->device_info &
2227 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2230 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2231 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2232 ds, sas_device->handle,
2233 (unsigned long long)sas_device->sas_address,
2235 (unsigned long long)sas_device->device_name);
2236 sdev_printk(KERN_INFO, sdev, "%s: "
2237 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2238 (unsigned long long) sas_device->enclosure_logical_id,
2241 sas_device_put(sas_device);
2242 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2244 _scsih_display_sata_capabilities(ioc, handle, sdev);
2246 _scsih_change_queue_depth(sdev, qdepth);
2249 sas_read_port_mode_page(sdev);
2250 _scsih_enable_tlr(ioc, sdev);
2257 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2258 * @sdev: scsi device struct
2259 * @bdev: pointer to block device context
2260 * @capacity: device size (in 512 byte sectors)
2261 * @params: three element array to place output:
2262 * params[0] number of heads (max 255)
2263 * params[1] number of sectors (max 63)
2264 * params[2] number of cylinders
2269 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2270 sector_t capacity, int params[])
2280 dummy = heads * sectors;
2281 cylinders = capacity;
2282 sector_div(cylinders, dummy);
2285 * Handle extended translation size for logical drives
2288 if ((ulong)capacity >= 0x200000) {
2291 dummy = heads * sectors;
2292 cylinders = capacity;
2293 sector_div(cylinders, dummy);
2298 params[1] = sectors;
2299 params[2] = cylinders;
2305 * _scsih_response_code - translation of device response code
2306 * @ioc: per adapter object
2307 * @response_code: response code returned by the device
2312 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2316 switch (response_code) {
2317 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2318 desc = "task management request completed";
2320 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2321 desc = "invalid frame";
2323 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2324 desc = "task management request not supported";
2326 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2327 desc = "task management request failed";
2329 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2330 desc = "task management request succeeded";
2332 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2333 desc = "invalid lun";
2336 desc = "overlapped tag attempted";
2338 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2339 desc = "task queued, however not sent to target";
2345 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2346 ioc->name, response_code, desc);
2350 * _scsih_tm_done - tm completion routine
2351 * @ioc: per adapter object
2352 * @smid: system request message index
2353 * @msix_index: MSIX table index supplied by the OS
2354 * @reply: reply message frame(lower 32bit addr)
2357 * The callback handler when using scsih_issue_tm.
2359 * Return 1 meaning mf should be freed from _base_interrupt
2360 * 0 means the mf is freed from this function.
2363 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2365 MPI2DefaultReply_t *mpi_reply;
2367 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2369 if (ioc->tm_cmds.smid != smid)
2371 mpt2sas_base_flush_reply_queues(ioc);
2372 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2373 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2375 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2376 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2378 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2379 complete(&ioc->tm_cmds.done);
2384 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2385 * @ioc: per adapter object
2386 * @handle: device handle
2388 * During taskmangement request, we need to freeze the device queue.
2391 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2393 struct MPT2SAS_DEVICE *sas_device_priv_data;
2394 struct scsi_device *sdev;
2397 shost_for_each_device(sdev, ioc->shost) {
2400 sas_device_priv_data = sdev->hostdata;
2401 if (!sas_device_priv_data)
2403 if (sas_device_priv_data->sas_target->handle == handle) {
2404 sas_device_priv_data->sas_target->tm_busy = 1;
2406 ioc->ignore_loginfos = 1;
2412 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2413 * @ioc: per adapter object
2414 * @handle: device handle
2416 * During taskmangement request, we need to freeze the device queue.
2419 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2421 struct MPT2SAS_DEVICE *sas_device_priv_data;
2422 struct scsi_device *sdev;
2425 shost_for_each_device(sdev, ioc->shost) {
2428 sas_device_priv_data = sdev->hostdata;
2429 if (!sas_device_priv_data)
2431 if (sas_device_priv_data->sas_target->handle == handle) {
2432 sas_device_priv_data->sas_target->tm_busy = 0;
2434 ioc->ignore_loginfos = 0;
2441 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2442 * @ioc: per adapter struct
2443 * @device_handle: device handle
2444 * @channel: the channel assigned by the OS
2445 * @id: the id assigned by the OS
2447 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2448 * @smid_task: smid assigned to the task
2449 * @timeout: timeout in seconds
2450 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2453 * A generic API for sending task management requests to firmware.
2455 * The callback index is set inside `ioc->tm_cb_idx`.
2457 * Return SUCCESS or FAILED.
2460 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2461 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2462 enum mutex_type m_type)
2464 Mpi2SCSITaskManagementRequest_t *mpi_request;
2465 Mpi2SCSITaskManagementReply_t *mpi_reply;
2468 unsigned long timeleft;
2469 struct scsiio_tracker *scsi_lookup = NULL;
2472 if (m_type == TM_MUTEX_ON)
2473 mutex_lock(&ioc->tm_cmds.mutex);
2474 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2475 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2476 __func__, ioc->name);
2481 if (ioc->shost_recovery || ioc->remove_host ||
2482 ioc->pci_error_recovery) {
2483 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2484 __func__, ioc->name);
2489 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2490 if (ioc_state & MPI2_DOORBELL_USED) {
2491 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2492 "active!\n", ioc->name));
2493 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2495 rc = (!rc) ? SUCCESS : FAILED;
2499 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2500 mpt2sas_base_fault_info(ioc, ioc_state &
2501 MPI2_DOORBELL_DATA_MASK);
2502 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2504 rc = (!rc) ? SUCCESS : FAILED;
2508 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2510 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2511 ioc->name, __func__);
2516 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2517 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2519 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2520 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2522 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2523 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2524 ioc->tm_cmds.smid = smid;
2525 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2526 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2527 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2528 mpi_request->DevHandle = cpu_to_le16(handle);
2529 mpi_request->TaskType = type;
2530 mpi_request->TaskMID = cpu_to_le16(smid_task);
2531 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2532 mpt2sas_scsih_set_tm_flag(ioc, handle);
2533 init_completion(&ioc->tm_cmds.done);
2534 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2535 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2536 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2537 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2538 ioc->name, __func__);
2539 _debug_dump_mf(mpi_request,
2540 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2541 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2542 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2544 rc = (!rc) ? SUCCESS : FAILED;
2545 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2546 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2551 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2552 mpi_reply = ioc->tm_cmds.reply;
2553 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2554 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2555 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2556 le32_to_cpu(mpi_reply->IOCLogInfo),
2557 le32_to_cpu(mpi_reply->TerminationCount)));
2558 if (ioc->logging_level & MPT_DEBUG_TM) {
2559 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2560 if (mpi_reply->IOCStatus)
2561 _debug_dump_mf(mpi_request,
2562 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2567 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2569 if (scsi_lookup->scmd == NULL)
2574 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2575 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2581 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2582 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2583 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2588 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2596 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2597 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2598 if (m_type == TM_MUTEX_ON)
2599 mutex_unlock(&ioc->tm_cmds.mutex);
2604 if (m_type == TM_MUTEX_ON)
2605 mutex_unlock(&ioc->tm_cmds.mutex);
2610 * _scsih_tm_display_info - displays info about the device
2611 * @ioc: per adapter struct
2612 * @scmd: pointer to scsi command object
2614 * Called by task management callback handlers.
2617 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2619 struct scsi_target *starget = scmd->device->sdev_target;
2620 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2621 struct _sas_device *sas_device = NULL;
2622 unsigned long flags;
2623 char *device_str = NULL;
2627 if (ioc->hide_ir_msg)
2628 device_str = "WarpDrive";
2630 device_str = "volume";
2632 scsi_print_command(scmd);
2633 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2634 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2635 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2636 device_str, (unsigned long long)priv_target->sas_address);
2638 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2639 sas_device = __mpt2sas_get_sdev_from_target(ioc, priv_target);
2641 if (priv_target->flags &
2642 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2643 starget_printk(KERN_INFO, starget,
2644 "volume handle(0x%04x), "
2645 "volume wwid(0x%016llx)\n",
2646 sas_device->volume_handle,
2647 (unsigned long long)sas_device->volume_wwid);
2649 starget_printk(KERN_INFO, starget,
2650 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2652 (unsigned long long)sas_device->sas_address,
2654 starget_printk(KERN_INFO, starget,
2655 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2656 (unsigned long long)sas_device->enclosure_logical_id,
2659 sas_device_put(sas_device);
2661 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2666 * _scsih_abort - eh threads main abort routine
2667 * @scmd: pointer to scsi command object
2669 * Returns SUCCESS if command aborted else FAILED
2672 _scsih_abort(struct scsi_cmnd *scmd)
2674 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2675 struct MPT2SAS_DEVICE *sas_device_priv_data;
2680 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2681 "scmd(%p)\n", scmd);
2682 _scsih_tm_display_info(ioc, scmd);
2684 sas_device_priv_data = scmd->device->hostdata;
2685 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2686 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2687 "scmd(%p)\n", scmd);
2688 scmd->result = DID_NO_CONNECT << 16;
2689 scmd->scsi_done(scmd);
2694 /* search for the command */
2695 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2697 scmd->result = DID_RESET << 16;
2702 /* for hidden raid components and volumes this is not supported */
2703 if (sas_device_priv_data->sas_target->flags &
2704 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2705 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2706 scmd->result = DID_RESET << 16;
2711 mpt2sas_halt_firmware(ioc);
2713 handle = sas_device_priv_data->sas_target->handle;
2714 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2715 scmd->device->id, scmd->device->lun,
2716 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2719 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2720 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2725 * _scsih_dev_reset - eh threads main device reset routine
2726 * @scmd: pointer to scsi command object
2728 * Returns SUCCESS if command aborted else FAILED
2731 _scsih_dev_reset(struct scsi_cmnd *scmd)
2733 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2734 struct MPT2SAS_DEVICE *sas_device_priv_data;
2735 struct _sas_device *sas_device = NULL;
2739 struct scsi_target *starget = scmd->device->sdev_target;
2740 struct MPT2SAS_TARGET *target_priv_data = starget->hostdata;
2742 starget_printk(KERN_INFO, starget, "attempting device reset! "
2743 "scmd(%p)\n", scmd);
2744 _scsih_tm_display_info(ioc, scmd);
2746 sas_device_priv_data = scmd->device->hostdata;
2747 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2748 starget_printk(KERN_INFO, starget, "device been deleted! "
2749 "scmd(%p)\n", scmd);
2750 scmd->result = DID_NO_CONNECT << 16;
2751 scmd->scsi_done(scmd);
2756 /* for hidden raid components obtain the volume_handle */
2758 if (sas_device_priv_data->sas_target->flags &
2759 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2760 sas_device = mpt2sas_get_sdev_from_target(ioc,
2763 handle = sas_device->volume_handle;
2765 handle = sas_device_priv_data->sas_target->handle;
2768 scmd->result = DID_RESET << 16;
2773 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2774 scmd->device->id, scmd->device->lun,
2775 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2778 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2779 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2782 sas_device_put(sas_device);
2788 * _scsih_target_reset - eh threads main target reset routine
2789 * @scmd: pointer to scsi command object
2791 * Returns SUCCESS if command aborted else FAILED
2794 _scsih_target_reset(struct scsi_cmnd *scmd)
2796 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2797 struct MPT2SAS_DEVICE *sas_device_priv_data;
2798 struct _sas_device *sas_device = NULL;
2801 struct scsi_target *starget = scmd->device->sdev_target;
2802 struct MPT2SAS_TARGET *target_priv_data = starget->hostdata;
2804 starget_printk(KERN_INFO, starget, "attempting target reset! "
2805 "scmd(%p)\n", scmd);
2806 _scsih_tm_display_info(ioc, scmd);
2808 sas_device_priv_data = scmd->device->hostdata;
2809 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2810 starget_printk(KERN_INFO, starget, "target been deleted! "
2811 "scmd(%p)\n", scmd);
2812 scmd->result = DID_NO_CONNECT << 16;
2813 scmd->scsi_done(scmd);
2818 /* for hidden raid components obtain the volume_handle */
2820 if (sas_device_priv_data->sas_target->flags &
2821 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2822 sas_device = mpt2sas_get_sdev_from_target(ioc,
2825 handle = sas_device->volume_handle;
2827 handle = sas_device_priv_data->sas_target->handle;
2830 scmd->result = DID_RESET << 16;
2835 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2836 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2840 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2841 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2844 sas_device_put(sas_device);
2850 * _scsih_host_reset - eh threads main host reset routine
2851 * @scmd: pointer to scsi command object
2853 * Returns SUCCESS if command aborted else FAILED
2856 _scsih_host_reset(struct scsi_cmnd *scmd)
2858 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2861 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2863 scsi_print_command(scmd);
2865 if (ioc->is_driver_loading) {
2866 printk(MPT2SAS_INFO_FMT "Blocking the host reset\n",
2872 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2874 r = (retval < 0) ? FAILED : SUCCESS;
2877 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2878 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2884 * _scsih_fw_event_add - insert and queue up fw_event
2885 * @ioc: per adapter object
2886 * @fw_event: object describing the event
2887 * Context: This function will acquire ioc->fw_event_lock.
2889 * This adds the firmware event object into link list, then queues it up to
2890 * be processed from user context.
2895 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2897 unsigned long flags;
2899 if (ioc->firmware_event_thread == NULL)
2902 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2903 fw_event_work_get(fw_event);
2904 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2905 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2906 fw_event_work_get(fw_event);
2907 queue_delayed_work(ioc->firmware_event_thread,
2908 &fw_event->delayed_work, 0);
2909 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2913 * _scsih_fw_event_del_from_list - delete fw_event from the list
2914 * @ioc: per adapter object
2915 * @fw_event: object describing the event
2916 * Context: This function will acquire ioc->fw_event_lock.
2918 * If the fw_event is on the fw_event_list, remove it and do a put.
2923 _scsih_fw_event_del_from_list(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2926 unsigned long flags;
2928 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2929 if (!list_empty(&fw_event->list)) {
2930 list_del_init(&fw_event->list);
2931 fw_event_work_put(fw_event);
2933 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2937 * _scsih_error_recovery_delete_devices - remove devices not responding
2938 * @ioc: per adapter object
2943 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2945 struct fw_event_work *fw_event;
2947 if (ioc->is_driver_loading)
2950 fw_event = alloc_fw_event_work(0);
2954 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2955 fw_event->ioc = ioc;
2956 _scsih_fw_event_add(ioc, fw_event);
2957 fw_event_work_put(fw_event);
2961 * mpt2sas_port_enable_complete - port enable completed (fake event)
2962 * @ioc: per adapter object
2967 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2969 struct fw_event_work *fw_event;
2971 fw_event = alloc_fw_event_work(0);
2974 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2975 fw_event->ioc = ioc;
2976 _scsih_fw_event_add(ioc, fw_event);
2977 fw_event_work_put(fw_event);
2980 static struct fw_event_work *dequeue_next_fw_event(struct MPT2SAS_ADAPTER *ioc)
2982 unsigned long flags;
2983 struct fw_event_work *fw_event = NULL;
2985 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2986 if (!list_empty(&ioc->fw_event_list)) {
2987 fw_event = list_first_entry(&ioc->fw_event_list,
2988 struct fw_event_work, list);
2989 list_del_init(&fw_event->list);
2991 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2997 * _scsih_fw_event_cleanup_queue - cleanup event queue
2998 * @ioc: per adapter object
3000 * Walk the firmware event queue, either killing timers, or waiting
3001 * for outstanding events to complete
3006 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
3008 struct fw_event_work *fw_event;
3010 if (list_empty(&ioc->fw_event_list) ||
3011 !ioc->firmware_event_thread || in_interrupt())
3014 while ((fw_event = dequeue_next_fw_event(ioc))) {
3016 * Wait on the fw_event to complete. If this returns 1, then
3017 * the event was never executed, and we need a put for the
3018 * reference the delayed_work had on the fw_event.
3020 * If it did execute, we wait for it to finish, and the put will
3021 * happen from _firmware_event_work()
3023 if (cancel_delayed_work_sync(&fw_event->delayed_work))
3024 fw_event_work_put(fw_event);
3026 fw_event_work_put(fw_event);
3031 * _scsih_ublock_io_all_device - unblock every device
3032 * @ioc: per adapter object
3034 * change the device state from block to running
3037 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
3039 struct MPT2SAS_DEVICE *sas_device_priv_data;
3040 struct scsi_device *sdev;
3042 shost_for_each_device(sdev, ioc->shost) {
3043 sas_device_priv_data = sdev->hostdata;
3044 if (!sas_device_priv_data)
3046 if (!sas_device_priv_data->block)
3048 sas_device_priv_data->block = 0;
3049 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
3051 sas_device_priv_data->sas_target->handle));
3052 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
3056 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
3057 * @ioc: per adapter object
3058 * @handle: device handle
3060 * During device pull we need to appropiately set the sdev state.
3063 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
3065 struct MPT2SAS_DEVICE *sas_device_priv_data;
3066 struct scsi_device *sdev;
3068 shost_for_each_device(sdev, ioc->shost) {
3069 sas_device_priv_data = sdev->hostdata;
3070 if (!sas_device_priv_data)
3072 if (!sas_device_priv_data->block)
3074 if (sas_device_priv_data->sas_target->sas_address ==
3076 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3077 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
3078 "sas address(0x%016llx)\n", ioc->name,
3079 (unsigned long long)sas_address));
3080 sas_device_priv_data->block = 0;
3081 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
3087 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3088 * @ioc: per adapter object
3089 * @handle: device handle
3091 * During device pull we need to appropiately set the sdev state.
3094 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
3096 struct MPT2SAS_DEVICE *sas_device_priv_data;
3097 struct scsi_device *sdev;
3099 shost_for_each_device(sdev, ioc->shost) {
3100 sas_device_priv_data = sdev->hostdata;
3101 if (!sas_device_priv_data)
3103 if (sas_device_priv_data->block)
3105 sas_device_priv_data->block = 1;
3106 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
3108 sas_device_priv_data->sas_target->handle));
3109 scsi_internal_device_block(sdev);
3115 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3116 * @ioc: per adapter object
3117 * @handle: device handle
3119 * During device pull we need to appropiately set the sdev state.
3122 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3124 struct MPT2SAS_DEVICE *sas_device_priv_data;
3125 struct scsi_device *sdev;
3127 shost_for_each_device(sdev, ioc->shost) {
3128 sas_device_priv_data = sdev->hostdata;
3129 if (!sas_device_priv_data)
3131 if (sas_device_priv_data->block)
3133 if (sas_device_priv_data->sas_target->handle == handle) {
3134 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
3135 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
3136 "handle(0x%04x)\n", ioc->name, handle));
3137 sas_device_priv_data->block = 1;
3138 scsi_internal_device_block(sdev);
3144 * _scsih_block_io_to_children_attached_to_ex
3145 * @ioc: per adapter object
3146 * @sas_expander: the sas_device object
3148 * This routine set sdev state to SDEV_BLOCK for all devices
3149 * attached to this expander. This function called when expander is
3153 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3154 struct _sas_node *sas_expander)
3156 struct _sas_port *mpt2sas_port;
3157 struct _sas_device *sas_device;
3158 struct _sas_node *expander_sibling;
3159 unsigned long flags;
3164 list_for_each_entry(mpt2sas_port,
3165 &sas_expander->sas_port_list, port_list) {
3166 if (mpt2sas_port->remote_identify.device_type == SAS_END_DEVICE) {
3167 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3168 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
3169 mpt2sas_port->remote_identify.sas_address);
3171 set_bit(sas_device->handle,
3172 ioc->blocking_handles);
3173 sas_device_put(sas_device);
3175 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3179 list_for_each_entry(mpt2sas_port,
3180 &sas_expander->sas_port_list, port_list) {
3182 if (mpt2sas_port->remote_identify.device_type ==
3183 SAS_EDGE_EXPANDER_DEVICE ||
3184 mpt2sas_port->remote_identify.device_type ==
3185 SAS_FANOUT_EXPANDER_DEVICE) {
3187 mpt2sas_scsih_expander_find_by_sas_address(
3188 ioc, mpt2sas_port->remote_identify.sas_address);
3189 _scsih_block_io_to_children_attached_to_ex(ioc,
3196 * _scsih_block_io_to_children_attached_directly
3197 * @ioc: per adapter object
3198 * @event_data: topology change event data
3200 * This routine set sdev state to SDEV_BLOCK for all devices
3201 * direct attached during device pull.
3204 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3205 Mpi2EventDataSasTopologyChangeList_t *event_data)
3212 for (i = 0; i < event_data->NumEntries; i++) {
3213 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3216 phy_number = event_data->StartPhyNum + i;
3217 reason_code = event_data->PHY[i].PhyStatus &
3218 MPI2_EVENT_SAS_TOPO_RC_MASK;
3219 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3220 _scsih_block_io_device(ioc, handle);
3225 * _scsih_tm_tr_send - send task management request
3226 * @ioc: per adapter object
3227 * @handle: device handle
3228 * Context: interrupt time.
3230 * This code is to initiate the device removal handshake protocol
3231 * with controller firmware. This function will issue target reset
3232 * using high priority request queue. It will send a sas iounit
3233 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3235 * This is designed to send muliple task management request at the same
3236 * time to the fifo. If the fifo is full, we will append the request,
3237 * and process it in a future completion.
3240 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3242 Mpi2SCSITaskManagementRequest_t *mpi_request;
3244 struct _sas_device *sas_device = NULL;
3245 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3246 u64 sas_address = 0;
3247 unsigned long flags;
3248 struct _tr_list *delayed_tr;
3251 if (ioc->remove_host) {
3252 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3253 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3255 } else if (ioc->pci_error_recovery) {
3256 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3257 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3261 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3262 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3263 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3264 "operational: handle(0x%04x)\n", __func__, ioc->name,
3269 /* if PD, then return */
3270 if (test_bit(handle, ioc->pd_handles))
3273 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3274 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
3275 if (sas_device && sas_device->starget &&
3276 sas_device->starget->hostdata) {
3277 sas_target_priv_data = sas_device->starget->hostdata;
3278 sas_target_priv_data->deleted = 1;
3279 sas_address = sas_device->sas_address;
3281 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3283 if (sas_target_priv_data) {
3284 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3285 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3286 (unsigned long long)sas_address));
3287 _scsih_ublock_io_device(ioc, sas_address);
3288 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3291 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3293 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3296 INIT_LIST_HEAD(&delayed_tr->list);
3297 delayed_tr->handle = handle;
3298 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3299 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3300 "DELAYED:tr:handle(0x%04x), (open)\n",
3301 ioc->name, handle));
3305 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3306 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3307 ioc->tm_tr_cb_idx));
3308 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3309 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3310 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3311 mpi_request->DevHandle = cpu_to_le16(handle);
3312 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3313 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3316 sas_device_put(sas_device);
3322 * _scsih_sas_control_complete - completion routine
3323 * @ioc: per adapter object
3324 * @smid: system request message index
3325 * @msix_index: MSIX table index supplied by the OS
3326 * @reply: reply message frame(lower 32bit addr)
3327 * Context: interrupt time.
3329 * This is the sas iounit control completion routine.
3330 * This code is part of the code to initiate the device removal
3331 * handshake protocol with controller firmware.
3333 * Return 1 meaning mf should be freed from _base_interrupt
3334 * 0 means the mf is freed from this function.
3337 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3338 u8 msix_index, u32 reply)
3340 Mpi2SasIoUnitControlReply_t *mpi_reply =
3341 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3342 if (likely(mpi_reply)) {
3343 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3344 "sc_complete:handle(0x%04x), (open) "
3345 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3346 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3347 le16_to_cpu(mpi_reply->IOCStatus),
3348 le32_to_cpu(mpi_reply->IOCLogInfo)));
3350 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3351 ioc->name, __FILE__, __LINE__, __func__);
3357 * _scsih_tm_tr_volume_send - send target reset request for volumes
3358 * @ioc: per adapter object
3359 * @handle: device handle
3360 * Context: interrupt time.
3362 * This is designed to send muliple task management request at the same
3363 * time to the fifo. If the fifo is full, we will append the request,
3364 * and process it in a future completion.
3367 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3369 Mpi2SCSITaskManagementRequest_t *mpi_request;
3371 struct _tr_list *delayed_tr;
3373 if (ioc->shost_recovery || ioc->remove_host ||
3374 ioc->pci_error_recovery) {
3375 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3376 "progress!\n", __func__, ioc->name));
3380 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3382 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3385 INIT_LIST_HEAD(&delayed_tr->list);
3386 delayed_tr->handle = handle;
3387 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3388 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3389 "DELAYED:tr:handle(0x%04x), (open)\n",
3390 ioc->name, handle));
3394 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3395 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3396 ioc->tm_tr_volume_cb_idx));
3397 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3398 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3399 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3400 mpi_request->DevHandle = cpu_to_le16(handle);
3401 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3402 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3406 * _scsih_tm_volume_tr_complete - target reset completion
3407 * @ioc: per adapter object
3408 * @smid: system request message index
3409 * @msix_index: MSIX table index supplied by the OS
3410 * @reply: reply message frame(lower 32bit addr)
3411 * Context: interrupt time.
3413 * Return 1 meaning mf should be freed from _base_interrupt
3414 * 0 means the mf is freed from this function.
3417 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3418 u8 msix_index, u32 reply)
3421 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3422 Mpi2SCSITaskManagementReply_t *mpi_reply =
3423 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3425 if (ioc->shost_recovery || ioc->remove_host ||
3426 ioc->pci_error_recovery) {
3427 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3428 "progress!\n", __func__, ioc->name));
3431 if (unlikely(!mpi_reply)) {
3432 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3433 ioc->name, __FILE__, __LINE__, __func__);
3436 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3437 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3438 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3439 dewtprintk(ioc, printk("spurious interrupt: "
3440 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3441 le16_to_cpu(mpi_reply->DevHandle), smid));
3445 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3446 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3447 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3448 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3449 le32_to_cpu(mpi_reply->IOCLogInfo),
3450 le32_to_cpu(mpi_reply->TerminationCount)));
3452 return _scsih_check_for_pending_tm(ioc, smid);
3456 * _scsih_tm_tr_complete -
3457 * @ioc: per adapter object
3458 * @smid: system request message index
3459 * @msix_index: MSIX table index supplied by the OS
3460 * @reply: reply message frame(lower 32bit addr)
3461 * Context: interrupt time.
3463 * This is the target reset completion routine.
3464 * This code is part of the code to initiate the device removal
3465 * handshake protocol with controller firmware.
3466 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3468 * Return 1 meaning mf should be freed from _base_interrupt
3469 * 0 means the mf is freed from this function.
3472 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3476 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3477 Mpi2SCSITaskManagementReply_t *mpi_reply =
3478 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3479 Mpi2SasIoUnitControlRequest_t *mpi_request;
3483 if (ioc->remove_host) {
3484 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3485 "removed\n", __func__, ioc->name));
3487 } else if (ioc->pci_error_recovery) {
3488 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3489 "error recovery\n", __func__, ioc->name));
3492 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3493 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3494 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3495 "operational\n", __func__, ioc->name));
3498 if (unlikely(!mpi_reply)) {
3499 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3500 ioc->name, __FILE__, __LINE__, __func__);
3503 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3504 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3505 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3506 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3507 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3508 le16_to_cpu(mpi_reply->DevHandle), smid));
3512 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3513 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3514 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3515 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3516 le32_to_cpu(mpi_reply->IOCLogInfo),
3517 le32_to_cpu(mpi_reply->TerminationCount)));
3519 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3520 if (!smid_sas_ctrl) {
3521 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3522 ioc->name, __func__);
3526 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3527 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3528 ioc->tm_sas_control_cb_idx));
3529 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3530 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3531 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3532 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3533 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3534 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3536 return _scsih_check_for_pending_tm(ioc, smid);
3540 * _scsih_check_for_pending_tm - check for pending task management
3541 * @ioc: per adapter object
3542 * @smid: system request message index
3544 * This will check delayed target reset list, and feed the
3547 * Return 1 meaning mf should be freed from _base_interrupt
3548 * 0 means the mf is freed from this function.
3551 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3553 struct _tr_list *delayed_tr;
3555 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3556 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3557 struct _tr_list, list);
3558 mpt2sas_base_free_smid(ioc, smid);
3559 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3560 list_del(&delayed_tr->list);
3565 if (!list_empty(&ioc->delayed_tr_list)) {
3566 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3567 struct _tr_list, list);
3568 mpt2sas_base_free_smid(ioc, smid);
3569 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3570 list_del(&delayed_tr->list);
3579 * _scsih_check_topo_delete_events - sanity check on topo events
3580 * @ioc: per adapter object
3581 * @event_data: the event data payload
3583 * This routine added to better handle cable breaker.
3585 * This handles the case where driver receives multiple expander
3586 * add and delete events in a single shot. When there is a delete event
3587 * the routine will void any pending add events waiting in the event queue.
3592 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3593 Mpi2EventDataSasTopologyChangeList_t *event_data)
3595 struct fw_event_work *fw_event;
3596 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3597 u16 expander_handle;
3598 struct _sas_node *sas_expander;
3599 unsigned long flags;
3603 for (i = 0 ; i < event_data->NumEntries; i++) {
3604 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3607 reason_code = event_data->PHY[i].PhyStatus &
3608 MPI2_EVENT_SAS_TOPO_RC_MASK;
3609 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3610 _scsih_tm_tr_send(ioc, handle);
3613 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3614 if (expander_handle < ioc->sas_hba.num_phys) {
3615 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3618 if (event_data->ExpStatus ==
3619 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3620 /* put expander attached devices into blocking state */
3621 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3622 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3624 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3625 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3627 handle = find_first_bit(ioc->blocking_handles,
3628 ioc->facts.MaxDevHandle);
3629 if (handle < ioc->facts.MaxDevHandle)
3630 _scsih_block_io_device(ioc, handle);
3631 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3632 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3633 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3635 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3638 /* mark ignore flag for pending events */
3639 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3640 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3641 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3644 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3645 fw_event->event_data;
3646 if (local_event_data->ExpStatus ==
3647 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3648 local_event_data->ExpStatus ==
3649 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3650 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3652 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3653 "setting ignoring flag\n", ioc->name));
3654 fw_event->ignore = 1;
3658 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3662 * _scsih_set_volume_delete_flag - setting volume delete flag
3663 * @ioc: per adapter object
3664 * @handle: device handle
3670 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3672 struct _raid_device *raid_device;
3673 struct MPT2SAS_TARGET *sas_target_priv_data;
3674 unsigned long flags;
3676 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3677 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3678 if (raid_device && raid_device->starget &&
3679 raid_device->starget->hostdata) {
3680 sas_target_priv_data =
3681 raid_device->starget->hostdata;
3682 sas_target_priv_data->deleted = 1;
3683 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3684 "setting delete flag: handle(0x%04x), "
3685 "wwid(0x%016llx)\n", ioc->name, handle,
3686 (unsigned long long) raid_device->wwid));
3688 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3692 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3693 * @handle: input handle
3694 * @a: handle for volume a
3695 * @b: handle for volume b
3697 * IR firmware only supports two raid volumes. The purpose of this
3698 * routine is to set the volume handle in either a or b. When the given
3699 * input handle is non-zero, or when a and b have not been set before.
3702 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3704 if (!handle || handle == *a || handle == *b)
3713 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3714 * @ioc: per adapter object
3715 * @event_data: the event data payload
3716 * Context: interrupt time.
3718 * This routine will send target reset to volume, followed by target
3719 * resets to the PDs. This is called when a PD has been removed, or
3720 * volume has been deleted or removed. When the target reset is sent
3721 * to volume, the PD target resets need to be queued to start upon
3722 * completion of the volume target reset.
3727 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3728 Mpi2EventDataIrConfigChangeList_t *event_data)
3730 Mpi2EventIrConfigElement_t *element;
3732 u16 handle, volume_handle, a, b;
3733 struct _tr_list *delayed_tr;
3738 if (ioc->is_warpdrive)
3741 /* Volume Resets for Deleted or Removed */
3742 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3743 for (i = 0; i < event_data->NumElements; i++, element++) {
3744 if (element->ReasonCode ==
3745 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3746 element->ReasonCode ==
3747 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3748 volume_handle = le16_to_cpu(element->VolDevHandle);
3749 _scsih_set_volume_delete_flag(ioc, volume_handle);
3750 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3754 /* Volume Resets for UNHIDE events */
3755 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3756 for (i = 0; i < event_data->NumElements; i++, element++) {
3757 if (le32_to_cpu(event_data->Flags) &
3758 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3760 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3761 volume_handle = le16_to_cpu(element->VolDevHandle);
3762 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3767 _scsih_tm_tr_volume_send(ioc, a);
3769 _scsih_tm_tr_volume_send(ioc, b);
3771 /* PD target resets */
3772 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3773 for (i = 0; i < event_data->NumElements; i++, element++) {
3774 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3776 handle = le16_to_cpu(element->PhysDiskDevHandle);
3777 volume_handle = le16_to_cpu(element->VolDevHandle);
3778 clear_bit(handle, ioc->pd_handles);
3780 _scsih_tm_tr_send(ioc, handle);
3781 else if (volume_handle == a || volume_handle == b) {
3782 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3783 BUG_ON(!delayed_tr);
3784 INIT_LIST_HEAD(&delayed_tr->list);
3785 delayed_tr->handle = handle;
3786 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3787 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3788 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3791 _scsih_tm_tr_send(ioc, handle);
3797 * _scsih_check_volume_delete_events - set delete flag for volumes
3798 * @ioc: per adapter object
3799 * @event_data: the event data payload
3800 * Context: interrupt time.
3802 * This will handle the case when the cable connected to entire volume is
3803 * pulled. We will take care of setting the deleted flag so normal IO will
3809 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3810 Mpi2EventDataIrVolume_t *event_data)
3814 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3816 state = le32_to_cpu(event_data->NewValue);
3817 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3818 MPI2_RAID_VOL_STATE_FAILED)
3819 _scsih_set_volume_delete_flag(ioc,
3820 le16_to_cpu(event_data->VolDevHandle));
3824 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3825 * @ioc: per adapter object
3826 * @event_data: the temp threshold event data
3827 * Context: interrupt time.
3832 _scsih_temp_threshold_events(struct MPT2SAS_ADAPTER *ioc,
3833 Mpi2EventDataTemperature_t *event_data)
3835 if (ioc->temp_sensors_count >= event_data->SensorNum) {
3836 printk(MPT2SAS_ERR_FMT "Temperature Threshold flags %s%s%s%s"
3837 " exceeded for Sensor: %d !!!\n", ioc->name,
3838 ((le16_to_cpu(event_data->Status) & 0x1) == 1) ? "0 " : " ",
3839 ((le16_to_cpu(event_data->Status) & 0x2) == 2) ? "1 " : " ",
3840 ((le16_to_cpu(event_data->Status) & 0x4) == 4) ? "2 " : " ",
3841 ((le16_to_cpu(event_data->Status) & 0x8) == 8) ? "3 " : " ",
3842 event_data->SensorNum);
3843 printk(MPT2SAS_ERR_FMT "Current Temp In Celsius: %d\n",
3844 ioc->name, event_data->CurrentTemperature);
3849 * _scsih_flush_running_cmds - completing outstanding commands.
3850 * @ioc: per adapter object
3852 * The flushing out of all pending scmd commands following host reset,
3853 * where all IO is dropped to the floor.
3858 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3860 struct scsi_cmnd *scmd;
3864 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3865 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3869 mpt2sas_base_free_smid(ioc, smid);
3870 scsi_dma_unmap(scmd);
3871 if (ioc->pci_error_recovery)
3872 scmd->result = DID_NO_CONNECT << 16;
3874 scmd->result = DID_RESET << 16;
3875 scmd->scsi_done(scmd);
3877 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3882 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3883 * @scmd: pointer to scsi command object
3884 * @mpi_request: pointer to the SCSI_IO reqest message frame
3886 * Supporting protection 1 and 3.
3891 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3894 unsigned char prot_op = scsi_get_prot_op(scmd);
3895 unsigned char prot_type = scsi_get_prot_type(scmd);
3897 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3900 if (prot_op == SCSI_PROT_READ_STRIP)
3901 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3902 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3903 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3907 switch (prot_type) {
3908 case SCSI_PROT_DIF_TYPE1:
3909 case SCSI_PROT_DIF_TYPE2:
3912 * enable ref/guard checking
3913 * auto increment ref tag
3915 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3916 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3917 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3918 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3919 cpu_to_be32(scsi_get_lba(scmd));
3922 case SCSI_PROT_DIF_TYPE3:
3925 * enable guard checking
3927 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3930 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3931 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3935 * _scsih_eedp_error_handling - return sense code for EEDP errors
3936 * @scmd: pointer to scsi command object
3937 * @ioc_status: ioc status
3942 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3946 switch (ioc_status) {
3947 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3950 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3953 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3961 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3962 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3963 SAM_STAT_CHECK_CONDITION;
3967 * _scsih_scsi_direct_io_get - returns direct io flag
3968 * @ioc: per adapter object
3969 * @smid: system request message index
3971 * Returns the smid stored scmd pointer.
3974 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3976 return ioc->scsi_lookup[smid - 1].direct_io;
3980 * _scsih_scsi_direct_io_set - sets direct io flag
3981 * @ioc: per adapter object
3982 * @smid: system request message index
3983 * @direct_io: Zero or non-zero value to set in the direct_io flag
3988 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3990 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3995 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3996 * @ioc: per adapter object
3997 * @scmd: pointer to scsi command object
3998 * @raid_device: pointer to raid device data structure
3999 * @mpi_request: pointer to the SCSI_IO reqest message frame
4000 * @smid: system request message index
4005 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4006 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
4009 sector_t v_lba, p_lba, stripe_off, column, io_size;
4010 u32 stripe_sz, stripe_exp;
4011 u8 num_pds, cmd = scmd->cmnd[0];
4013 if (cmd != READ_10 && cmd != WRITE_10 &&
4014 cmd != READ_16 && cmd != WRITE_16)
4017 if (cmd == READ_10 || cmd == WRITE_10)
4018 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
4020 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
4022 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
4024 if (v_lba + io_size - 1 > raid_device->max_lba)
4027 stripe_sz = raid_device->stripe_sz;
4028 stripe_exp = raid_device->stripe_exponent;
4029 stripe_off = v_lba & (stripe_sz - 1);
4031 /* Return unless IO falls within a stripe */
4032 if (stripe_off + io_size > stripe_sz)
4035 num_pds = raid_device->num_pds;
4036 p_lba = v_lba >> stripe_exp;
4037 column = sector_div(p_lba, num_pds);
4038 p_lba = (p_lba << stripe_exp) + stripe_off;
4040 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
4042 if (cmd == READ_10 || cmd == WRITE_10)
4043 put_unaligned_be32(lower_32_bits(p_lba),
4044 &mpi_request->CDB.CDB32[2]);
4046 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
4048 _scsih_scsi_direct_io_set(ioc, smid, 1);
4052 * _scsih_qcmd - main scsi request entry point
4053 * @scmd: pointer to scsi command object
4054 * @done: function pointer to be invoked on completion
4056 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4058 * Returns 0 on success. If there's a failure, return either:
4059 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4060 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4063 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4065 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
4066 struct MPT2SAS_DEVICE *sas_device_priv_data;
4067 struct MPT2SAS_TARGET *sas_target_priv_data;
4068 struct _raid_device *raid_device;
4069 Mpi2SCSIIORequest_t *mpi_request;
4073 sas_device_priv_data = scmd->device->hostdata;
4074 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4075 scmd->result = DID_NO_CONNECT << 16;
4076 scmd->scsi_done(scmd);
4080 if (ioc->pci_error_recovery || ioc->remove_host) {
4081 scmd->result = DID_NO_CONNECT << 16;
4082 scmd->scsi_done(scmd);
4086 sas_target_priv_data = sas_device_priv_data->sas_target;
4087 /* invalid device handle */
4088 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
4089 scmd->result = DID_NO_CONNECT << 16;
4090 scmd->scsi_done(scmd);
4094 /* host recovery or link resets sent via IOCTLs */
4095 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
4096 return SCSI_MLQUEUE_HOST_BUSY;
4097 /* device busy with task management */
4098 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
4099 return SCSI_MLQUEUE_DEVICE_BUSY;
4100 /* device has been deleted */
4101 else if (sas_target_priv_data->deleted) {
4102 scmd->result = DID_NO_CONNECT << 16;
4103 scmd->scsi_done(scmd);
4107 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
4108 mpi_control = MPI2_SCSIIO_CONTROL_READ;
4109 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
4110 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
4112 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
4115 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
4117 /* Make sure Device is not raid volume.
4118 * We do not expose raid functionality to upper layer for warpdrive.
4120 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4121 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
4122 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
4124 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
4126 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4127 ioc->name, __func__);
4130 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4131 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
4132 _scsih_setup_eedp(scmd, mpi_request);
4133 if (scmd->cmd_len == 32)
4134 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
4135 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4136 if (sas_device_priv_data->sas_target->flags &
4137 MPT_TARGET_FLAGS_RAID_COMPONENT)
4138 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4140 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4141 mpi_request->DevHandle =
4142 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4143 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4144 mpi_request->Control = cpu_to_le32(mpi_control);
4145 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4146 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4147 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4148 mpi_request->SenseBufferLowAddress =
4149 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
4150 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4151 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4152 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
4153 mpi_request->VF_ID = 0; /* TODO */
4154 mpi_request->VP_ID = 0;
4155 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4157 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4159 if (!mpi_request->DataLength) {
4160 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4162 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4163 mpt2sas_base_free_smid(ioc, smid);
4168 raid_device = sas_target_priv_data->raid_device;
4169 if (raid_device && raid_device->direct_io_enabled)
4170 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4173 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4174 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4175 le16_to_cpu(mpi_request->DevHandle));
4177 mpt2sas_base_put_smid_default(ioc, smid);
4181 return SCSI_MLQUEUE_HOST_BUSY;
4185 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4186 * @sense_buffer: sense data returned by target
4187 * @data: normalized skey/asc/ascq
4192 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4194 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4195 /* descriptor format */
4196 data->skey = sense_buffer[1] & 0x0F;
4197 data->asc = sense_buffer[2];
4198 data->ascq = sense_buffer[3];
4201 data->skey = sense_buffer[2] & 0x0F;
4202 data->asc = sense_buffer[12];
4203 data->ascq = sense_buffer[13];
4207 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4209 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4210 * @ioc: per adapter object
4211 * @scmd: pointer to scsi command object
4212 * @mpi_reply: reply mf payload returned from firmware
4214 * scsi_status - SCSI Status code returned from target device
4215 * scsi_state - state info associated with SCSI_IO determined by ioc
4216 * ioc_status - ioc supplied status info
4221 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4222 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4226 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4227 MPI2_IOCSTATUS_MASK;
4228 u8 scsi_state = mpi_reply->SCSIState;
4229 u8 scsi_status = mpi_reply->SCSIStatus;
4230 char *desc_ioc_state = NULL;
4231 char *desc_scsi_status = NULL;
4232 char *desc_scsi_state = ioc->tmp_string;
4233 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4234 struct _sas_device *sas_device = NULL;
4235 struct scsi_target *starget = scmd->device->sdev_target;
4236 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4237 char *device_str = NULL;
4242 if (ioc->hide_ir_msg)
4243 device_str = "WarpDrive";
4245 device_str = "volume";
4247 if (log_info == 0x31170000)
4250 switch (ioc_status) {
4251 case MPI2_IOCSTATUS_SUCCESS:
4252 desc_ioc_state = "success";
4254 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4255 desc_ioc_state = "invalid function";
4257 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4258 desc_ioc_state = "scsi recovered error";
4260 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4261 desc_ioc_state = "scsi invalid dev handle";
4263 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4264 desc_ioc_state = "scsi device not there";
4266 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4267 desc_ioc_state = "scsi data overrun";
4269 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4270 desc_ioc_state = "scsi data underrun";
4272 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4273 desc_ioc_state = "scsi io data error";
4275 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4276 desc_ioc_state = "scsi protocol error";
4278 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4279 desc_ioc_state = "scsi task terminated";
4281 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4282 desc_ioc_state = "scsi residual mismatch";
4284 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4285 desc_ioc_state = "scsi task mgmt failed";
4287 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4288 desc_ioc_state = "scsi ioc terminated";
4290 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4291 desc_ioc_state = "scsi ext terminated";
4293 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4294 desc_ioc_state = "eedp guard error";
4296 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4297 desc_ioc_state = "eedp ref tag error";
4299 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4300 desc_ioc_state = "eedp app tag error";
4303 desc_ioc_state = "unknown";
4307 switch (scsi_status) {
4308 case MPI2_SCSI_STATUS_GOOD:
4309 desc_scsi_status = "good";
4311 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4312 desc_scsi_status = "check condition";
4314 case MPI2_SCSI_STATUS_CONDITION_MET:
4315 desc_scsi_status = "condition met";
4317 case MPI2_SCSI_STATUS_BUSY:
4318 desc_scsi_status = "busy";
4320 case MPI2_SCSI_STATUS_INTERMEDIATE:
4321 desc_scsi_status = "intermediate";
4323 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4324 desc_scsi_status = "intermediate condmet";
4326 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4327 desc_scsi_status = "reservation conflict";
4329 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4330 desc_scsi_status = "command terminated";
4332 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4333 desc_scsi_status = "task set full";
4335 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4336 desc_scsi_status = "aca active";
4338 case MPI2_SCSI_STATUS_TASK_ABORTED:
4339 desc_scsi_status = "task aborted";
4342 desc_scsi_status = "unknown";
4346 desc_scsi_state[0] = '\0';
4348 desc_scsi_state = " ";
4349 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4350 strcat(desc_scsi_state, "response info ");
4351 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4352 strcat(desc_scsi_state, "state terminated ");
4353 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4354 strcat(desc_scsi_state, "no status ");
4355 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4356 strcat(desc_scsi_state, "autosense failed ");
4357 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4358 strcat(desc_scsi_state, "autosense valid ");
4360 scsi_print_command(scmd);
4362 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4363 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4364 device_str, (unsigned long long)priv_target->sas_address);
4366 sas_device = mpt2sas_get_sdev_from_target(ioc, priv_target);
4368 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4369 "phy(%d)\n", ioc->name, sas_device->sas_address,
4371 printk(MPT2SAS_WARN_FMT
4372 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4373 ioc->name, sas_device->enclosure_logical_id,
4376 sas_device_put(sas_device);
4380 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4381 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4382 desc_ioc_state, ioc_status, smid);
4383 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4384 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4385 scsi_get_resid(scmd));
4386 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4387 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4388 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4389 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4390 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4391 scsi_status, desc_scsi_state, scsi_state);
4393 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4394 struct sense_info data;
4395 _scsih_normalize_sense(scmd->sense_buffer, &data);
4396 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4397 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4398 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4401 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4402 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4403 response_bytes = (u8 *)&response_info;
4404 _scsih_response_code(ioc, response_bytes[0]);
4410 * _scsih_turn_on_pfa_led - illuminate PFA LED
4411 * @ioc: per adapter object
4412 * @handle: device handle
4418 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4420 Mpi2SepReply_t mpi_reply;
4421 Mpi2SepRequest_t mpi_request;
4422 struct _sas_device *sas_device;
4424 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
4428 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4429 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4430 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4431 mpi_request.SlotStatus =
4432 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4433 mpi_request.DevHandle = cpu_to_le16(handle);
4434 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4435 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4436 &mpi_request)) != 0) {
4437 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4438 __FILE__, __LINE__, __func__);
4441 sas_device->pfa_led_on = 1;
4444 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4445 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4446 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4447 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4448 le32_to_cpu(mpi_reply.IOCLogInfo)));
4452 sas_device_put(sas_device);
4456 * _scsih_turn_off_pfa_led - turn off PFA LED
4457 * @ioc: per adapter object
4458 * @sas_device: sas device whose PFA LED has to turned off
4464 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4465 struct _sas_device *sas_device)
4467 Mpi2SepReply_t mpi_reply;
4468 Mpi2SepRequest_t mpi_request;
4470 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4471 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4472 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4473 mpi_request.SlotStatus = 0;
4474 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4475 mpi_request.DevHandle = 0;
4476 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4477 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4478 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4479 &mpi_request)) != 0) {
4480 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4481 __FILE__, __LINE__, __func__);
4485 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4486 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4487 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4488 le16_to_cpu(mpi_reply.IOCStatus),
4489 le32_to_cpu(mpi_reply.IOCLogInfo)));
4495 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4496 * @ioc: per adapter object
4497 * @handle: device handle
4498 * Context: interrupt.
4503 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4505 struct fw_event_work *fw_event;
4507 fw_event = alloc_fw_event_work(0);
4510 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
4511 fw_event->device_handle = handle;
4512 fw_event->ioc = ioc;
4513 _scsih_fw_event_add(ioc, fw_event);
4514 fw_event_work_put(fw_event);
4518 * _scsih_smart_predicted_fault - process smart errors
4519 * @ioc: per adapter object
4520 * @handle: device handle
4521 * Context: interrupt.
4526 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4528 struct scsi_target *starget;
4529 struct MPT2SAS_TARGET *sas_target_priv_data;
4530 Mpi2EventNotificationReply_t *event_reply;
4531 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4532 struct _sas_device *sas_device;
4534 unsigned long flags;
4536 /* only handle non-raid devices */
4537 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4538 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
4542 starget = sas_device->starget;
4543 sas_target_priv_data = starget->hostdata;
4545 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4546 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)))
4549 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4550 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4552 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4553 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4555 /* insert into event log */
4556 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4557 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4558 event_reply = kzalloc(sz, GFP_ATOMIC);
4560 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4561 ioc->name, __FILE__, __LINE__, __func__);
4565 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4566 event_reply->Event =
4567 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4568 event_reply->MsgLength = sz/4;
4569 event_reply->EventDataLength =
4570 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4571 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4572 event_reply->EventData;
4573 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4574 event_data->ASC = 0x5D;
4575 event_data->DevHandle = cpu_to_le16(handle);
4576 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4577 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4581 sas_device_put(sas_device);
4585 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4590 * _scsih_io_done - scsi request callback
4591 * @ioc: per adapter object
4592 * @smid: system request message index
4593 * @msix_index: MSIX table index supplied by the OS
4594 * @reply: reply message frame(lower 32bit addr)
4596 * Callback handler when using _scsih_qcmd.
4598 * Return 1 meaning mf should be freed from _base_interrupt
4599 * 0 means the mf is freed from this function.
4602 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4604 Mpi2SCSIIORequest_t *mpi_request;
4605 Mpi2SCSIIOReply_t *mpi_reply;
4606 struct scsi_cmnd *scmd;
4612 struct MPT2SAS_DEVICE *sas_device_priv_data;
4613 u32 response_code = 0;
4614 unsigned long flags;
4616 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4617 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4621 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4623 if (mpi_reply == NULL) {
4624 scmd->result = DID_OK << 16;
4628 sas_device_priv_data = scmd->device->hostdata;
4629 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4630 sas_device_priv_data->sas_target->deleted) {
4631 scmd->result = DID_NO_CONNECT << 16;
4634 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4636 * WARPDRIVE: If direct_io is set then it is directIO,
4637 * the failed direct I/O should be redirected to volume
4639 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4640 ((ioc_status & MPI2_IOCSTATUS_MASK)
4641 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4642 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4643 ioc->scsi_lookup[smid - 1].scmd = scmd;
4644 _scsih_scsi_direct_io_set(ioc, smid, 0);
4645 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4646 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4647 mpi_request->DevHandle =
4648 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4649 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4650 sas_device_priv_data->sas_target->handle);
4655 /* turning off TLR */
4656 scsi_state = mpi_reply->SCSIState;
4657 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4659 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4660 if (!sas_device_priv_data->tlr_snoop_check) {
4661 sas_device_priv_data->tlr_snoop_check++;
4662 /* Make sure Device is not raid volume.
4663 * We do not expose raid functionality to upper layer for warpdrive.
4665 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4666 sas_is_tlr_enabled(scmd->device) &&
4667 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4668 sas_disable_tlr(scmd->device);
4669 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4673 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4674 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4675 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4676 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4679 ioc_status &= MPI2_IOCSTATUS_MASK;
4680 scsi_status = mpi_reply->SCSIStatus;
4682 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4683 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4684 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4685 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4686 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4689 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4690 struct sense_info data;
4691 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4693 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4694 le32_to_cpu(mpi_reply->SenseCount));
4695 memcpy(scmd->sense_buffer, sense_data, sz);
4696 _scsih_normalize_sense(scmd->sense_buffer, &data);
4697 /* failure prediction threshold exceeded */
4698 if (data.asc == 0x5D)
4699 _scsih_smart_predicted_fault(ioc,
4700 le16_to_cpu(mpi_reply->DevHandle));
4703 switch (ioc_status) {
4704 case MPI2_IOCSTATUS_BUSY:
4705 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4706 scmd->result = SAM_STAT_BUSY;
4709 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4710 scmd->result = DID_NO_CONNECT << 16;
4713 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4714 if (sas_device_priv_data->block) {
4715 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4718 if (log_info == 0x32010081) {
4719 scmd->result = DID_RESET << 16;
4722 scmd->result = DID_SOFT_ERROR << 16;
4724 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4725 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4726 scmd->result = DID_RESET << 16;
4729 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4730 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4731 scmd->result = DID_SOFT_ERROR << 16;
4733 scmd->result = (DID_OK << 16) | scsi_status;
4736 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4737 scmd->result = (DID_OK << 16) | scsi_status;
4739 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4742 if (xfer_cnt < scmd->underflow) {
4743 if (scsi_status == SAM_STAT_BUSY)
4744 scmd->result = SAM_STAT_BUSY;
4746 scmd->result = DID_SOFT_ERROR << 16;
4747 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4748 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4749 scmd->result = DID_SOFT_ERROR << 16;
4750 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4751 scmd->result = DID_RESET << 16;
4752 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4753 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4754 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4755 scmd->result = (DRIVER_SENSE << 24) |
4756 SAM_STAT_CHECK_CONDITION;
4757 scmd->sense_buffer[0] = 0x70;
4758 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4759 scmd->sense_buffer[12] = 0x20;
4760 scmd->sense_buffer[13] = 0;
4764 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4765 scsi_set_resid(scmd, 0);
4766 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4767 case MPI2_IOCSTATUS_SUCCESS:
4768 scmd->result = (DID_OK << 16) | scsi_status;
4769 if (response_code ==
4770 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4771 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4772 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4773 scmd->result = DID_SOFT_ERROR << 16;
4774 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4775 scmd->result = DID_RESET << 16;
4778 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4779 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4780 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4781 _scsih_eedp_error_handling(scmd, ioc_status);
4783 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4784 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4785 case MPI2_IOCSTATUS_INVALID_SGL:
4786 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4787 case MPI2_IOCSTATUS_INVALID_FIELD:
4788 case MPI2_IOCSTATUS_INVALID_STATE:
4789 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4790 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4792 scmd->result = DID_SOFT_ERROR << 16;
4797 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4798 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4799 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4803 scsi_dma_unmap(scmd);
4804 scmd->scsi_done(scmd);
4809 * _scsih_sas_host_refresh - refreshing sas host object contents
4810 * @ioc: per adapter object
4813 * During port enable, fw will send topology events for every device. Its
4814 * possible that the handles may change from the previous setting, so this
4815 * code keeping handles updating if changed.
4820 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4825 Mpi2ConfigReply_t mpi_reply;
4826 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4827 u16 attached_handle;
4830 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4831 "updating handles for sas_host(0x%016llx)\n",
4832 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4834 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4835 * sizeof(Mpi2SasIOUnit0PhyData_t));
4836 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4837 if (!sas_iounit_pg0) {
4838 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4839 ioc->name, __FILE__, __LINE__, __func__);
4843 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4844 sas_iounit_pg0, sz)) != 0)
4846 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4847 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4849 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4850 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4852 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4853 PhyData[0].ControllerDevHandle);
4854 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4855 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4857 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4858 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4859 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4860 attached_handle, i, link_rate);
4863 kfree(sas_iounit_pg0);
4867 * _scsih_sas_host_add - create sas host object
4868 * @ioc: per adapter object
4870 * Creating host side data object, stored in ioc->sas_hba
4875 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4878 Mpi2ConfigReply_t mpi_reply;
4879 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4880 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4881 Mpi2SasPhyPage0_t phy_pg0;
4882 Mpi2SasDevicePage0_t sas_device_pg0;
4883 Mpi2SasEnclosurePage0_t enclosure_pg0;
4886 u16 device_missing_delay;
4888 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4889 if (!ioc->sas_hba.num_phys) {
4890 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4891 ioc->name, __FILE__, __LINE__, __func__);
4895 /* sas_iounit page 0 */
4896 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4897 sizeof(Mpi2SasIOUnit0PhyData_t));
4898 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4899 if (!sas_iounit_pg0) {
4900 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4901 ioc->name, __FILE__, __LINE__, __func__);
4904 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4905 sas_iounit_pg0, sz))) {
4906 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4907 ioc->name, __FILE__, __LINE__, __func__);
4910 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4911 MPI2_IOCSTATUS_MASK;
4912 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4913 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4914 ioc->name, __FILE__, __LINE__, __func__);
4918 /* sas_iounit page 1 */
4919 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4920 sizeof(Mpi2SasIOUnit1PhyData_t));
4921 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4922 if (!sas_iounit_pg1) {
4923 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4924 ioc->name, __FILE__, __LINE__, __func__);
4927 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4928 sas_iounit_pg1, sz))) {
4929 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4930 ioc->name, __FILE__, __LINE__, __func__);
4933 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4934 MPI2_IOCSTATUS_MASK;
4935 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4936 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4937 ioc->name, __FILE__, __LINE__, __func__);
4941 ioc->io_missing_delay =
4942 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4943 device_missing_delay =
4944 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4945 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4946 ioc->device_missing_delay = (device_missing_delay &
4947 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4949 ioc->device_missing_delay = device_missing_delay &
4950 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4952 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4953 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4954 sizeof(struct _sas_phy), GFP_KERNEL);
4955 if (!ioc->sas_hba.phy) {
4956 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4957 ioc->name, __FILE__, __LINE__, __func__);
4960 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4961 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4963 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4964 ioc->name, __FILE__, __LINE__, __func__);
4967 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4968 MPI2_IOCSTATUS_MASK;
4969 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4970 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4971 ioc->name, __FILE__, __LINE__, __func__);
4976 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4977 PhyData[0].ControllerDevHandle);
4978 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4979 ioc->sas_hba.phy[i].phy_id = i;
4980 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4981 phy_pg0, ioc->sas_hba.parent_dev);
4983 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4984 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4985 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4986 ioc->name, __FILE__, __LINE__, __func__);
4989 ioc->sas_hba.enclosure_handle =
4990 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4991 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4992 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4993 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4994 (unsigned long long) ioc->sas_hba.sas_address,
4995 ioc->sas_hba.num_phys) ;
4997 if (ioc->sas_hba.enclosure_handle) {
4998 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5000 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5001 ioc->sas_hba.enclosure_handle))) {
5002 ioc->sas_hba.enclosure_logical_id =
5003 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5008 kfree(sas_iounit_pg1);
5009 kfree(sas_iounit_pg0);
5013 * _scsih_expander_add - creating expander object
5014 * @ioc: per adapter object
5015 * @handle: expander handle
5017 * Creating expander object, stored in ioc->sas_expander_list.
5019 * Return 0 for success, else error.
5022 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5024 struct _sas_node *sas_expander;
5025 Mpi2ConfigReply_t mpi_reply;
5026 Mpi2ExpanderPage0_t expander_pg0;
5027 Mpi2ExpanderPage1_t expander_pg1;
5028 Mpi2SasEnclosurePage0_t enclosure_pg0;
5031 u64 sas_address, sas_address_parent = 0;
5033 unsigned long flags;
5034 struct _sas_port *mpt2sas_port = NULL;
5040 if (ioc->shost_recovery || ioc->pci_error_recovery)
5043 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5044 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
5045 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5046 ioc->name, __FILE__, __LINE__, __func__);
5050 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5051 MPI2_IOCSTATUS_MASK;
5052 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5053 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5054 ioc->name, __FILE__, __LINE__, __func__);
5058 /* handle out of order topology events */
5059 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
5060 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
5062 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5063 ioc->name, __FILE__, __LINE__, __func__);
5066 if (sas_address_parent != ioc->sas_hba.sas_address) {
5067 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5068 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5069 sas_address_parent);
5070 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5071 if (!sas_expander) {
5072 rc = _scsih_expander_add(ioc, parent_handle);
5078 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5079 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5080 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5082 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5087 sas_expander = kzalloc(sizeof(struct _sas_node),
5089 if (!sas_expander) {
5090 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5091 ioc->name, __FILE__, __LINE__, __func__);
5095 sas_expander->handle = handle;
5096 sas_expander->num_phys = expander_pg0.NumPhys;
5097 sas_expander->sas_address_parent = sas_address_parent;
5098 sas_expander->sas_address = sas_address;
5100 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
5101 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
5102 handle, parent_handle, (unsigned long long)
5103 sas_expander->sas_address, sas_expander->num_phys);
5105 if (!sas_expander->num_phys)
5107 sas_expander->phy = kcalloc(sas_expander->num_phys,
5108 sizeof(struct _sas_phy), GFP_KERNEL);
5109 if (!sas_expander->phy) {
5110 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5111 ioc->name, __FILE__, __LINE__, __func__);
5116 INIT_LIST_HEAD(&sas_expander->sas_port_list);
5117 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
5118 sas_address_parent);
5119 if (!mpt2sas_port) {
5120 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5121 ioc->name, __FILE__, __LINE__, __func__);
5125 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
5127 for (i = 0 ; i < sas_expander->num_phys ; i++) {
5128 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
5129 &expander_pg1, i, handle))) {
5130 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5131 ioc->name, __FILE__, __LINE__, __func__);
5135 sas_expander->phy[i].handle = handle;
5136 sas_expander->phy[i].phy_id = i;
5138 if ((mpt2sas_transport_add_expander_phy(ioc,
5139 &sas_expander->phy[i], expander_pg1,
5140 sas_expander->parent_dev))) {
5141 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5142 ioc->name, __FILE__, __LINE__, __func__);
5148 if (sas_expander->enclosure_handle) {
5149 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
5150 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5151 sas_expander->enclosure_handle))) {
5152 sas_expander->enclosure_logical_id =
5153 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5157 _scsih_expander_node_add(ioc, sas_expander);
5163 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5164 sas_address_parent);
5165 kfree(sas_expander);
5170 * _scsih_done - scsih callback handler.
5171 * @ioc: per adapter object
5172 * @smid: system request message index
5173 * @msix_index: MSIX table index supplied by the OS
5174 * @reply: reply message frame(lower 32bit addr)
5176 * Callback handler when sending internal generated message frames.
5177 * The callback index passed is `ioc->scsih_cb_idx`
5179 * Return 1 meaning mf should be freed from _base_interrupt
5180 * 0 means the mf is freed from this function.
5183 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5185 MPI2DefaultReply_t *mpi_reply;
5187 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5188 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5190 if (ioc->scsih_cmds.smid != smid)
5192 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5194 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5195 mpi_reply->MsgLength*4);
5196 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5198 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5199 complete(&ioc->scsih_cmds.done);
5204 * mpt2sas_expander_remove - removing expander object
5205 * @ioc: per adapter object
5206 * @sas_address: expander sas_address
5211 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5213 struct _sas_node *sas_expander;
5214 unsigned long flags;
5216 if (ioc->shost_recovery)
5219 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5220 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5223 list_del(&sas_expander->list);
5224 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5226 _scsih_expander_node_remove(ioc, sas_expander);
5230 * _scsih_check_access_status - check access flags
5231 * @ioc: per adapter object
5232 * @sas_address: sas address
5233 * @handle: sas device handle
5234 * @access_flags: errors returned during discovery of the device
5236 * Return 0 for success, else failure
5239 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5240 u16 handle, u8 access_status)
5245 switch (access_status) {
5246 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5247 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5250 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5251 desc = "sata capability failed";
5253 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5254 desc = "sata affiliation conflict";
5256 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5257 desc = "route not addressable";
5259 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5260 desc = "smp error not addressable";
5262 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5263 desc = "device blocked";
5265 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5266 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5267 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5268 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5269 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5270 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5271 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5272 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5273 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5274 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5275 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5276 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5277 desc = "sata initialization failed";
5287 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5288 "handle(0x%04x)\n", ioc->name, desc,
5289 (unsigned long long)sas_address, handle);
5294 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5296 Mpi2ConfigReply_t mpi_reply;
5297 Mpi2SasDevicePage0_t sas_device_pg0;
5298 struct _sas_device *sas_device;
5300 unsigned long flags;
5302 struct scsi_target *starget;
5303 struct MPT2SAS_TARGET *sas_target_priv_data;
5307 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5308 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5311 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5312 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5315 /* check if this is end device */
5316 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5317 if (!(_scsih_is_end_device(device_info)))
5320 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5321 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5322 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
5326 printk(MPT2SAS_ERR_FMT "device is not present "
5327 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5331 if (unlikely(sas_device->handle != handle)) {
5332 starget = sas_device->starget;
5333 sas_target_priv_data = starget->hostdata;
5334 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5335 " to (0x%04x)!!!\n", sas_device->handle, handle);
5336 sas_target_priv_data->handle = handle;
5337 sas_device->handle = handle;
5340 /* check if device is present */
5341 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5342 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5343 printk(MPT2SAS_ERR_FMT "device is not present "
5344 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5348 /* check if there were any issues with discovery */
5349 if (_scsih_check_access_status(ioc, sas_address, handle,
5350 sas_device_pg0.AccessStatus))
5353 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5354 _scsih_ublock_io_device(ioc, sas_address);
5356 sas_device_put(sas_device);
5360 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5362 sas_device_put(sas_device);
5366 * _scsih_add_device - creating sas device object
5367 * @ioc: per adapter object
5368 * @handle: sas device handle
5369 * @phy_num: phy number end device attached to
5370 * @is_pd: is this hidden raid component
5372 * Creating end device object, stored in ioc->sas_device_list.
5374 * Returns 0 for success, non-zero for failure.
5377 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5379 Mpi2ConfigReply_t mpi_reply;
5380 Mpi2SasDevicePage0_t sas_device_pg0;
5381 Mpi2SasEnclosurePage0_t enclosure_pg0;
5382 struct _sas_device *sas_device;
5387 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5388 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5389 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5390 ioc->name, __FILE__, __LINE__, __func__);
5394 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5395 MPI2_IOCSTATUS_MASK;
5396 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5397 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5398 ioc->name, __FILE__, __LINE__, __func__);
5402 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5404 /* check if device is present */
5405 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5406 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5407 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5408 ioc->name, __FILE__, __LINE__, __func__);
5409 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5410 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5414 /* check if there were any issues with discovery */
5415 if (_scsih_check_access_status(ioc, sas_address, handle,
5416 sas_device_pg0.AccessStatus))
5419 /* check if this is end device */
5420 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5421 if (!(_scsih_is_end_device(device_info))) {
5422 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5423 ioc->name, __FILE__, __LINE__, __func__);
5427 sas_device = mpt2sas_get_sdev_by_addr(ioc,
5431 sas_device_put(sas_device);
5435 sas_device = kzalloc(sizeof(struct _sas_device),
5438 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5439 ioc->name, __FILE__, __LINE__, __func__);
5443 kref_init(&sas_device->refcount);
5444 sas_device->handle = handle;
5445 if (_scsih_get_sas_address(ioc, le16_to_cpu
5446 (sas_device_pg0.ParentDevHandle),
5447 &sas_device->sas_address_parent) != 0)
5448 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5449 ioc->name, __FILE__, __LINE__, __func__);
5450 sas_device->enclosure_handle =
5451 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5453 le16_to_cpu(sas_device_pg0.Slot);
5454 sas_device->device_info = device_info;
5455 sas_device->sas_address = sas_address;
5456 sas_device->phy = sas_device_pg0.PhyNum;
5458 /* get enclosure_logical_id */
5459 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5460 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5461 sas_device->enclosure_handle)))
5462 sas_device->enclosure_logical_id =
5463 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5465 /* get device name */
5466 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5468 if (ioc->wait_for_discovery_to_complete)
5469 _scsih_sas_device_init_add(ioc, sas_device);
5471 _scsih_sas_device_add(ioc, sas_device);
5473 sas_device_put(sas_device);
5478 * _scsih_remove_device - removing sas device object
5479 * @ioc: per adapter object
5480 * @sas_device_delete: the sas_device object
5485 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5486 struct _sas_device *sas_device)
5488 struct MPT2SAS_TARGET *sas_target_priv_data;
5490 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5491 (sas_device->pfa_led_on)) {
5492 _scsih_turn_off_pfa_led(ioc, sas_device);
5493 sas_device->pfa_led_on = 0;
5496 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5497 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5498 sas_device->handle, (unsigned long long)
5499 sas_device->sas_address));
5501 if (sas_device->starget && sas_device->starget->hostdata) {
5502 sas_target_priv_data = sas_device->starget->hostdata;
5503 sas_target_priv_data->deleted = 1;
5504 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5505 sas_target_priv_data->handle =
5506 MPT2SAS_INVALID_DEVICE_HANDLE;
5509 if (!ioc->hide_drives)
5510 mpt2sas_transport_port_remove(ioc,
5511 sas_device->sas_address,
5512 sas_device->sas_address_parent);
5514 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5515 "(0x%016llx)\n", ioc->name, sas_device->handle,
5516 (unsigned long long) sas_device->sas_address);
5518 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5519 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5520 sas_device->handle, (unsigned long long)
5521 sas_device->sas_address));
5524 * _scsih_device_remove_by_handle - removing device object by handle
5525 * @ioc: per adapter object
5526 * @handle: device handle
5531 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5533 struct _sas_device *sas_device;
5534 unsigned long flags;
5536 if (ioc->shost_recovery)
5539 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5540 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
5542 list_del_init(&sas_device->list);
5543 sas_device_put(sas_device);
5545 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5548 _scsih_remove_device(ioc, sas_device);
5549 sas_device_put(sas_device);
5554 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5555 * @ioc: per adapter object
5556 * @sas_address: device sas_address
5561 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5564 struct _sas_device *sas_device;
5565 unsigned long flags;
5567 if (ioc->shost_recovery)
5570 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5571 sas_device = __mpt2sas_get_sdev_by_addr(ioc, sas_address);
5573 list_del_init(&sas_device->list);
5574 sas_device_put(sas_device);
5576 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5579 _scsih_remove_device(ioc, sas_device);
5580 sas_device_put(sas_device);
5583 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5585 * _scsih_sas_topology_change_event_debug - debug for topology event
5586 * @ioc: per adapter object
5587 * @event_data: event data payload
5591 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5592 Mpi2EventDataSasTopologyChangeList_t *event_data)
5598 char *status_str = NULL;
5599 u8 link_rate, prev_link_rate;
5601 switch (event_data->ExpStatus) {
5602 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5605 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5606 status_str = "remove";
5608 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5610 status_str = "responding";
5612 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5613 status_str = "remove delay";
5616 status_str = "unknown status";
5619 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5620 ioc->name, status_str);
5621 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5622 "start_phy(%02d), count(%d)\n",
5623 le16_to_cpu(event_data->ExpanderDevHandle),
5624 le16_to_cpu(event_data->EnclosureHandle),
5625 event_data->StartPhyNum, event_data->NumEntries);
5626 for (i = 0; i < event_data->NumEntries; i++) {
5627 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5630 phy_number = event_data->StartPhyNum + i;
5631 reason_code = event_data->PHY[i].PhyStatus &
5632 MPI2_EVENT_SAS_TOPO_RC_MASK;
5633 switch (reason_code) {
5634 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5635 status_str = "target add";
5637 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5638 status_str = "target remove";
5640 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5641 status_str = "delay target remove";
5643 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5644 status_str = "link rate change";
5646 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5647 status_str = "target responding";
5650 status_str = "unknown";
5653 link_rate = event_data->PHY[i].LinkRate >> 4;
5654 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5655 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5656 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5657 handle, status_str, link_rate, prev_link_rate);
5664 * _scsih_sas_topology_change_event - handle topology changes
5665 * @ioc: per adapter object
5666 * @fw_event: The fw_event_work object
5671 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5672 struct fw_event_work *fw_event)
5675 u16 parent_handle, handle;
5677 u8 phy_number, max_phys;
5678 struct _sas_node *sas_expander;
5680 unsigned long flags;
5681 u8 link_rate, prev_link_rate;
5682 Mpi2EventDataSasTopologyChangeList_t *event_data =
5683 (Mpi2EventDataSasTopologyChangeList_t *)
5684 fw_event->event_data;
5686 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5687 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5688 _scsih_sas_topology_change_event_debug(ioc, event_data);
5691 if (ioc->remove_host || ioc->pci_error_recovery)
5694 if (!ioc->sas_hba.num_phys)
5695 _scsih_sas_host_add(ioc);
5697 _scsih_sas_host_refresh(ioc);
5699 if (fw_event->ignore) {
5700 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5701 "event\n", ioc->name));
5705 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5707 /* handle expander add */
5708 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5709 if (_scsih_expander_add(ioc, parent_handle) != 0)
5712 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5713 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5716 sas_address = sas_expander->sas_address;
5717 max_phys = sas_expander->num_phys;
5718 } else if (parent_handle < ioc->sas_hba.num_phys) {
5719 sas_address = ioc->sas_hba.sas_address;
5720 max_phys = ioc->sas_hba.num_phys;
5722 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5725 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5727 /* handle siblings events */
5728 for (i = 0; i < event_data->NumEntries; i++) {
5729 if (fw_event->ignore) {
5730 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5731 "expander event\n", ioc->name));
5734 if (ioc->shost_recovery || ioc->remove_host ||
5735 ioc->pci_error_recovery)
5737 phy_number = event_data->StartPhyNum + i;
5738 if (phy_number >= max_phys)
5740 reason_code = event_data->PHY[i].PhyStatus &
5741 MPI2_EVENT_SAS_TOPO_RC_MASK;
5742 if ((event_data->PHY[i].PhyStatus &
5743 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5744 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5746 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5749 link_rate = event_data->PHY[i].LinkRate >> 4;
5750 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5751 switch (reason_code) {
5752 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5754 if (ioc->shost_recovery)
5757 if (link_rate == prev_link_rate)
5760 mpt2sas_transport_update_links(ioc, sas_address,
5761 handle, phy_number, link_rate);
5763 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5766 _scsih_check_device(ioc, handle);
5768 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5770 if (ioc->shost_recovery)
5773 mpt2sas_transport_update_links(ioc, sas_address,
5774 handle, phy_number, link_rate);
5776 _scsih_add_device(ioc, handle, phy_number, 0);
5778 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5780 _scsih_device_remove_by_handle(ioc, handle);
5785 /* handle expander removal */
5786 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5788 mpt2sas_expander_remove(ioc, sas_address);
5792 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5794 * _scsih_sas_device_status_change_event_debug - debug for device event
5795 * @event_data: event data payload
5801 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5802 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5804 char *reason_str = NULL;
5806 switch (event_data->ReasonCode) {
5807 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5808 reason_str = "smart data";
5810 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5811 reason_str = "unsupported device discovered";
5813 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5814 reason_str = "internal device reset";
5816 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5817 reason_str = "internal task abort";
5819 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5820 reason_str = "internal task abort set";
5822 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5823 reason_str = "internal clear task set";
5825 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5826 reason_str = "internal query task";
5828 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5829 reason_str = "sata init failure";
5831 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5832 reason_str = "internal device reset complete";
5834 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5835 reason_str = "internal task abort complete";
5837 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5838 reason_str = "internal async notification";
5840 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5841 reason_str = "expander reduced functionality";
5843 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5844 reason_str = "expander reduced functionality complete";
5847 reason_str = "unknown reason";
5850 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5851 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5852 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5853 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5854 le16_to_cpu(event_data->TaskTag));
5855 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5856 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5857 event_data->ASC, event_data->ASCQ);
5858 printk(KERN_INFO "\n");
5863 * _scsih_sas_device_status_change_event - handle device status change
5864 * @ioc: per adapter object
5865 * @fw_event: The fw_event_work object
5871 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5872 struct fw_event_work *fw_event)
5874 struct MPT2SAS_TARGET *target_priv_data;
5875 struct _sas_device *sas_device;
5877 unsigned long flags;
5878 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5879 (Mpi2EventDataSasDeviceStatusChange_t *)
5880 fw_event->event_data;
5882 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5883 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5884 _scsih_sas_device_status_change_event_debug(ioc,
5888 /* In MPI Revision K (0xC), the internal device reset complete was
5889 * implemented, so avoid setting tm_busy flag for older firmware.
5891 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5894 if (event_data->ReasonCode !=
5895 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5896 event_data->ReasonCode !=
5897 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5900 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5901 sas_address = le64_to_cpu(event_data->SASAddress);
5902 sas_device = __mpt2sas_get_sdev_by_addr(ioc,
5905 if (!sas_device || !sas_device->starget)
5908 target_priv_data = sas_device->starget->hostdata;
5909 if (!target_priv_data)
5912 if (event_data->ReasonCode ==
5913 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5914 target_priv_data->tm_busy = 1;
5916 target_priv_data->tm_busy = 0;
5920 sas_device_put(sas_device);
5922 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5926 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5928 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5929 * @ioc: per adapter object
5930 * @event_data: event data payload
5936 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5937 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5939 char *reason_str = NULL;
5941 switch (event_data->ReasonCode) {
5942 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5943 reason_str = "enclosure add";
5945 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5946 reason_str = "enclosure remove";
5949 reason_str = "unknown reason";
5953 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5954 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5955 " number slots(%d)\n", ioc->name, reason_str,
5956 le16_to_cpu(event_data->EnclosureHandle),
5957 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5958 le16_to_cpu(event_data->StartSlot));
5963 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5964 * @ioc: per adapter object
5965 * @fw_event: The fw_event_work object
5971 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5972 struct fw_event_work *fw_event)
5974 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5975 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5976 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5977 (Mpi2EventDataSasEnclDevStatusChange_t *)
5978 fw_event->event_data);
5983 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5984 * @ioc: per adapter object
5985 * @fw_event: The fw_event_work object
5991 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5992 struct fw_event_work *fw_event)
5994 struct scsi_cmnd *scmd;
5995 struct scsi_device *sdev;
5998 struct MPT2SAS_DEVICE *sas_device_priv_data;
5999 u32 termination_count;
6001 Mpi2SCSITaskManagementReply_t *mpi_reply;
6002 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
6003 (Mpi2EventDataSasBroadcastPrimitive_t *)
6004 fw_event->event_data;
6006 unsigned long flags;
6009 u8 task_abort_retries;
6011 mutex_lock(&ioc->tm_cmds.mutex);
6013 "%s: enter: phy number(%d), width(%d)\n",
6014 ioc->name, __func__, event_data->PhyNum,
6015 event_data->PortWidth);
6017 _scsih_block_io_all_device(ioc);
6019 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6020 mpi_reply = ioc->tm_cmds.reply;
6021 broadcast_aen_retry:
6023 /* sanity checks for retrying this loop */
6024 if (max_retries++ == 5) {
6025 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
6026 ioc->name, __func__));
6028 } else if (max_retries > 1)
6029 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
6030 ioc->name, __func__, max_retries - 1));
6032 termination_count = 0;
6034 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
6035 if (ioc->shost_recovery)
6037 scmd = _scsih_scsi_lookup_get(ioc, smid);
6040 sdev = scmd->device;
6041 sas_device_priv_data = sdev->hostdata;
6042 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
6044 /* skip hidden raid components */
6045 if (sas_device_priv_data->sas_target->flags &
6046 MPT_TARGET_FLAGS_RAID_COMPONENT)
6049 if (sas_device_priv_data->sas_target->flags &
6050 MPT_TARGET_FLAGS_VOLUME)
6053 handle = sas_device_priv_data->sas_target->handle;
6054 lun = sas_device_priv_data->lun;
6057 if (ioc->shost_recovery)
6060 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6061 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
6062 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
6065 sdev_printk(KERN_WARNING, sdev,
6066 "mpt2sas_scsih_issue_tm: FAILED when sending "
6067 "QUERY_TASK: scmd(%p)\n", scmd);
6068 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6069 goto broadcast_aen_retry;
6071 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
6072 & MPI2_IOCSTATUS_MASK;
6073 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6074 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
6075 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
6077 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6078 goto broadcast_aen_retry;
6081 /* see if IO is still owned by IOC and target */
6082 if (mpi_reply->ResponseCode ==
6083 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
6084 mpi_reply->ResponseCode ==
6085 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
6086 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6089 task_abort_retries = 0;
6091 if (task_abort_retries++ == 60) {
6092 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
6093 "%s: ABORT_TASK: giving up\n", ioc->name,
6095 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6096 goto broadcast_aen_retry;
6099 if (ioc->shost_recovery)
6102 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
6103 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
6106 sdev_printk(KERN_WARNING, sdev,
6107 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
6108 "scmd(%p)\n", scmd);
6112 if (task_abort_retries > 1)
6113 sdev_printk(KERN_WARNING, sdev,
6114 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
6116 task_abort_retries - 1, scmd);
6118 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
6119 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
6122 if (ioc->broadcast_aen_pending) {
6123 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
6124 " pending AEN\n", ioc->name, __func__));
6125 ioc->broadcast_aen_pending = 0;
6126 goto broadcast_aen_retry;
6130 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
6133 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
6134 "%s - exit, query_count = %d termination_count = %d\n",
6135 ioc->name, __func__, query_count, termination_count));
6137 ioc->broadcast_aen_busy = 0;
6138 if (!ioc->shost_recovery)
6139 _scsih_ublock_io_all_device(ioc);
6140 mutex_unlock(&ioc->tm_cmds.mutex);
6144 * _scsih_sas_discovery_event - handle discovery events
6145 * @ioc: per adapter object
6146 * @fw_event: The fw_event_work object
6152 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
6153 struct fw_event_work *fw_event)
6155 Mpi2EventDataSasDiscovery_t *event_data =
6156 (Mpi2EventDataSasDiscovery_t *)
6157 fw_event->event_data;
6159 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6160 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
6161 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
6162 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
6164 if (event_data->DiscoveryStatus)
6165 printk("discovery_status(0x%08x)",
6166 le32_to_cpu(event_data->DiscoveryStatus));
6171 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
6172 !ioc->sas_hba.num_phys) {
6173 if (disable_discovery > 0 && ioc->shost_recovery) {
6174 /* Wait for the reset to complete */
6175 while (ioc->shost_recovery)
6178 _scsih_sas_host_add(ioc);
6183 * _scsih_reprobe_lun - reprobing lun
6184 * @sdev: scsi device struct
6185 * @no_uld_attach: sdev->no_uld_attach flag setting
6189 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
6193 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
6194 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
6195 sdev->no_uld_attach ? "hidding" : "exposing");
6196 rc = scsi_device_reprobe(sdev);
6200 * _scsih_sas_volume_add - add new volume
6201 * @ioc: per adapter object
6202 * @element: IR config element data
6208 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6209 Mpi2EventIrConfigElement_t *element)
6211 struct _raid_device *raid_device;
6212 unsigned long flags;
6214 u16 handle = le16_to_cpu(element->VolDevHandle);
6217 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6219 printk(MPT2SAS_ERR_FMT
6220 "failure at %s:%d/%s()!\n", ioc->name,
6221 __FILE__, __LINE__, __func__);
6225 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6226 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6227 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6232 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6234 printk(MPT2SAS_ERR_FMT
6235 "failure at %s:%d/%s()!\n", ioc->name,
6236 __FILE__, __LINE__, __func__);
6240 raid_device->id = ioc->sas_id++;
6241 raid_device->channel = RAID_CHANNEL;
6242 raid_device->handle = handle;
6243 raid_device->wwid = wwid;
6244 _scsih_raid_device_add(ioc, raid_device);
6245 if (!ioc->wait_for_discovery_to_complete) {
6246 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6247 raid_device->id, 0);
6249 _scsih_raid_device_remove(ioc, raid_device);
6251 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6252 _scsih_determine_boot_device(ioc, raid_device, 1);
6253 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6258 * _scsih_sas_volume_delete - delete volume
6259 * @ioc: per adapter object
6260 * @handle: volume device handle
6266 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6268 struct _raid_device *raid_device;
6269 unsigned long flags;
6270 struct MPT2SAS_TARGET *sas_target_priv_data;
6271 struct scsi_target *starget = NULL;
6273 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6274 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6276 if (raid_device->starget) {
6277 starget = raid_device->starget;
6278 sas_target_priv_data = starget->hostdata;
6279 sas_target_priv_data->deleted = 1;
6281 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6282 "(0x%016llx)\n", ioc->name, raid_device->handle,
6283 (unsigned long long) raid_device->wwid);
6284 list_del(&raid_device->list);
6287 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6289 scsi_remove_target(&starget->dev);
6293 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6294 * @ioc: per adapter object
6295 * @element: IR config element data
6301 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6302 Mpi2EventIrConfigElement_t *element)
6304 struct _sas_device *sas_device;
6305 struct scsi_target *starget = NULL;
6306 struct MPT2SAS_TARGET *sas_target_priv_data;
6307 unsigned long flags;
6308 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6310 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6311 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
6313 sas_device->volume_handle = 0;
6314 sas_device->volume_wwid = 0;
6315 clear_bit(handle, ioc->pd_handles);
6316 if (sas_device->starget && sas_device->starget->hostdata) {
6317 starget = sas_device->starget;
6318 sas_target_priv_data = starget->hostdata;
6319 sas_target_priv_data->flags &=
6320 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6323 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6327 /* exposing raid component */
6329 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6331 sas_device_put(sas_device);
6335 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6336 * @ioc: per adapter object
6337 * @element: IR config element data
6343 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6344 Mpi2EventIrConfigElement_t *element)
6346 struct _sas_device *sas_device;
6347 struct scsi_target *starget = NULL;
6348 struct MPT2SAS_TARGET *sas_target_priv_data;
6349 unsigned long flags;
6350 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6351 u16 volume_handle = 0;
6352 u64 volume_wwid = 0;
6354 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6356 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6359 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6360 sas_device = __mpt2sas_get_sdev_by_handle(ioc, handle);
6362 set_bit(handle, ioc->pd_handles);
6363 if (sas_device->starget && sas_device->starget->hostdata) {
6364 starget = sas_device->starget;
6365 sas_target_priv_data = starget->hostdata;
6366 sas_target_priv_data->flags |=
6367 MPT_TARGET_FLAGS_RAID_COMPONENT;
6368 sas_device->volume_handle = volume_handle;
6369 sas_device->volume_wwid = volume_wwid;
6372 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6376 /* hiding raid component */
6378 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6380 sas_device_put(sas_device);
6384 * _scsih_sas_pd_delete - delete pd component
6385 * @ioc: per adapter object
6386 * @element: IR config element data
6392 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6393 Mpi2EventIrConfigElement_t *element)
6395 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6397 _scsih_device_remove_by_handle(ioc, handle);
6401 * _scsih_sas_pd_add - remove pd component
6402 * @ioc: per adapter object
6403 * @element: IR config element data
6409 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6410 Mpi2EventIrConfigElement_t *element)
6412 struct _sas_device *sas_device;
6413 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6414 Mpi2ConfigReply_t mpi_reply;
6415 Mpi2SasDevicePage0_t sas_device_pg0;
6420 set_bit(handle, ioc->pd_handles);
6422 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
6424 sas_device_put(sas_device);
6428 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6429 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6430 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6431 ioc->name, __FILE__, __LINE__, __func__);
6435 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6436 MPI2_IOCSTATUS_MASK;
6437 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6438 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6439 ioc->name, __FILE__, __LINE__, __func__);
6443 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6444 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6445 mpt2sas_transport_update_links(ioc, sas_address, handle,
6446 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6448 _scsih_add_device(ioc, handle, 0, 1);
6451 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6453 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6454 * @ioc: per adapter object
6455 * @event_data: event data payload
6461 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6462 Mpi2EventDataIrConfigChangeList_t *event_data)
6464 Mpi2EventIrConfigElement_t *element;
6467 char *reason_str = NULL, *element_str = NULL;
6469 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6471 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6472 ioc->name, (le32_to_cpu(event_data->Flags) &
6473 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6474 "foreign" : "native", event_data->NumElements);
6475 for (i = 0; i < event_data->NumElements; i++, element++) {
6476 switch (element->ReasonCode) {
6477 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6480 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6481 reason_str = "remove";
6483 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6484 reason_str = "no change";
6486 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6487 reason_str = "hide";
6489 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6490 reason_str = "unhide";
6492 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6493 reason_str = "volume_created";
6495 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6496 reason_str = "volume_deleted";
6498 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6499 reason_str = "pd_created";
6501 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6502 reason_str = "pd_deleted";
6505 reason_str = "unknown reason";
6508 element_type = le16_to_cpu(element->ElementFlags) &
6509 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6510 switch (element_type) {
6511 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6512 element_str = "volume";
6514 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6515 element_str = "phys disk";
6517 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6518 element_str = "hot spare";
6521 element_str = "unknown element";
6524 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6525 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6526 reason_str, le16_to_cpu(element->VolDevHandle),
6527 le16_to_cpu(element->PhysDiskDevHandle),
6528 element->PhysDiskNum);
6534 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6535 * @ioc: per adapter object
6536 * @fw_event: The fw_event_work object
6542 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6543 struct fw_event_work *fw_event)
6545 Mpi2EventIrConfigElement_t *element;
6548 Mpi2EventDataIrConfigChangeList_t *event_data =
6549 (Mpi2EventDataIrConfigChangeList_t *)
6550 fw_event->event_data;
6552 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6553 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6554 && !ioc->hide_ir_msg)
6555 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6559 if (ioc->shost_recovery)
6562 foreign_config = (le32_to_cpu(event_data->Flags) &
6563 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6565 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6566 for (i = 0; i < event_data->NumElements; i++, element++) {
6568 switch (element->ReasonCode) {
6569 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6570 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6571 if (!foreign_config)
6572 _scsih_sas_volume_add(ioc, element);
6574 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6575 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6576 if (!foreign_config)
6577 _scsih_sas_volume_delete(ioc,
6578 le16_to_cpu(element->VolDevHandle));
6580 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6581 if (!ioc->is_warpdrive)
6582 _scsih_sas_pd_hide(ioc, element);
6584 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6585 if (!ioc->is_warpdrive)
6586 _scsih_sas_pd_expose(ioc, element);
6588 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6589 if (!ioc->is_warpdrive)
6590 _scsih_sas_pd_add(ioc, element);
6592 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6593 if (!ioc->is_warpdrive)
6594 _scsih_sas_pd_delete(ioc, element);
6601 * _scsih_sas_ir_volume_event - IR volume event
6602 * @ioc: per adapter object
6603 * @fw_event: The fw_event_work object
6609 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6610 struct fw_event_work *fw_event)
6613 unsigned long flags;
6614 struct _raid_device *raid_device;
6618 Mpi2EventDataIrVolume_t *event_data =
6619 (Mpi2EventDataIrVolume_t *)
6620 fw_event->event_data;
6622 if (ioc->shost_recovery)
6625 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6628 handle = le16_to_cpu(event_data->VolDevHandle);
6629 state = le32_to_cpu(event_data->NewValue);
6630 if (!ioc->hide_ir_msg)
6631 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6632 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6633 le32_to_cpu(event_data->PreviousValue), state));
6636 case MPI2_RAID_VOL_STATE_MISSING:
6637 case MPI2_RAID_VOL_STATE_FAILED:
6638 _scsih_sas_volume_delete(ioc, handle);
6641 case MPI2_RAID_VOL_STATE_ONLINE:
6642 case MPI2_RAID_VOL_STATE_DEGRADED:
6643 case MPI2_RAID_VOL_STATE_OPTIMAL:
6645 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6646 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6647 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6652 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6654 printk(MPT2SAS_ERR_FMT
6655 "failure at %s:%d/%s()!\n", ioc->name,
6656 __FILE__, __LINE__, __func__);
6660 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6662 printk(MPT2SAS_ERR_FMT
6663 "failure at %s:%d/%s()!\n", ioc->name,
6664 __FILE__, __LINE__, __func__);
6668 raid_device->id = ioc->sas_id++;
6669 raid_device->channel = RAID_CHANNEL;
6670 raid_device->handle = handle;
6671 raid_device->wwid = wwid;
6672 _scsih_raid_device_add(ioc, raid_device);
6673 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6674 raid_device->id, 0);
6676 _scsih_raid_device_remove(ioc, raid_device);
6679 case MPI2_RAID_VOL_STATE_INITIALIZING:
6686 * _scsih_sas_ir_physical_disk_event - PD event
6687 * @ioc: per adapter object
6688 * @fw_event: The fw_event_work object
6694 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6695 struct fw_event_work *fw_event)
6697 u16 handle, parent_handle;
6699 struct _sas_device *sas_device;
6700 Mpi2ConfigReply_t mpi_reply;
6701 Mpi2SasDevicePage0_t sas_device_pg0;
6703 Mpi2EventDataIrPhysicalDisk_t *event_data =
6704 (Mpi2EventDataIrPhysicalDisk_t *)
6705 fw_event->event_data;
6708 if (ioc->shost_recovery)
6711 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6714 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6715 state = le32_to_cpu(event_data->NewValue);
6717 if (!ioc->hide_ir_msg)
6718 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6719 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6720 le32_to_cpu(event_data->PreviousValue), state));
6723 case MPI2_RAID_PD_STATE_ONLINE:
6724 case MPI2_RAID_PD_STATE_DEGRADED:
6725 case MPI2_RAID_PD_STATE_REBUILDING:
6726 case MPI2_RAID_PD_STATE_OPTIMAL:
6727 case MPI2_RAID_PD_STATE_HOT_SPARE:
6729 if (!ioc->is_warpdrive)
6730 set_bit(handle, ioc->pd_handles);
6732 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
6734 sas_device_put(sas_device);
6738 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6739 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6741 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6742 ioc->name, __FILE__, __LINE__, __func__);
6746 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6747 MPI2_IOCSTATUS_MASK;
6748 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6749 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6750 ioc->name, __FILE__, __LINE__, __func__);
6754 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6755 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6756 mpt2sas_transport_update_links(ioc, sas_address, handle,
6757 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6759 _scsih_add_device(ioc, handle, 0, 1);
6763 case MPI2_RAID_PD_STATE_OFFLINE:
6764 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6765 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6771 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6773 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6774 * @ioc: per adapter object
6775 * @event_data: event data payload
6781 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6782 Mpi2EventDataIrOperationStatus_t *event_data)
6784 char *reason_str = NULL;
6786 switch (event_data->RAIDOperation) {
6787 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6788 reason_str = "resync";
6790 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6791 reason_str = "online capacity expansion";
6793 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6794 reason_str = "consistency check";
6796 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6797 reason_str = "background init";
6799 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6800 reason_str = "make data consistent";
6807 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6808 "\thandle(0x%04x), percent complete(%d)\n",
6809 ioc->name, reason_str,
6810 le16_to_cpu(event_data->VolDevHandle),
6811 event_data->PercentComplete);
6816 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6817 * @ioc: per adapter object
6818 * @fw_event: The fw_event_work object
6824 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6825 struct fw_event_work *fw_event)
6827 Mpi2EventDataIrOperationStatus_t *event_data =
6828 (Mpi2EventDataIrOperationStatus_t *)
6829 fw_event->event_data;
6830 static struct _raid_device *raid_device;
6831 unsigned long flags;
6834 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6835 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6836 && !ioc->hide_ir_msg)
6837 _scsih_sas_ir_operation_status_event_debug(ioc,
6841 /* code added for raid transport support */
6842 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6844 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6845 handle = le16_to_cpu(event_data->VolDevHandle);
6846 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6848 raid_device->percent_complete =
6849 event_data->PercentComplete;
6850 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6855 * _scsih_prep_device_scan - initialize parameters prior to device scan
6856 * @ioc: per adapter object
6858 * Set the deleted flag prior to device scan. If the device is found during
6859 * the scan, then we clear the deleted flag.
6862 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6864 struct MPT2SAS_DEVICE *sas_device_priv_data;
6865 struct scsi_device *sdev;
6867 shost_for_each_device(sdev, ioc->shost) {
6868 sas_device_priv_data = sdev->hostdata;
6869 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6870 sas_device_priv_data->sas_target->deleted = 1;
6875 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6876 * @ioc: per adapter object
6877 * @sas_address: sas address
6878 * @slot: enclosure slot id
6879 * @handle: device handle
6881 * After host reset, find out whether devices are still responding.
6882 * Used in _scsi_remove_unresponsive_sas_devices.
6887 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6888 u16 slot, u16 handle)
6890 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6891 struct scsi_target *starget;
6892 struct _sas_device *sas_device;
6893 unsigned long flags;
6895 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6896 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6897 if (sas_device->sas_address == sas_address &&
6898 sas_device->slot == slot) {
6899 sas_device->responding = 1;
6900 starget = sas_device->starget;
6901 if (starget && starget->hostdata) {
6902 sas_target_priv_data = starget->hostdata;
6903 sas_target_priv_data->tm_busy = 0;
6904 sas_target_priv_data->deleted = 0;
6906 sas_target_priv_data = NULL;
6908 starget_printk(KERN_INFO, starget,
6909 "handle(0x%04x), sas_addr(0x%016llx), "
6910 "enclosure logical id(0x%016llx), "
6911 "slot(%d)\n", handle,
6912 (unsigned long long)sas_device->sas_address,
6913 (unsigned long long)
6914 sas_device->enclosure_logical_id,
6916 if (sas_device->handle == handle)
6918 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6919 sas_device->handle);
6920 sas_device->handle = handle;
6921 if (sas_target_priv_data)
6922 sas_target_priv_data->handle = handle;
6927 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6931 * _scsih_search_responding_sas_devices -
6932 * @ioc: per adapter object
6934 * After host reset, find out whether devices are still responding.
6940 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6942 Mpi2SasDevicePage0_t sas_device_pg0;
6943 Mpi2ConfigReply_t mpi_reply;
6950 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6952 if (list_empty(&ioc->sas_device_list))
6956 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6957 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6959 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6960 MPI2_IOCSTATUS_MASK;
6961 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6963 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6964 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6965 if (!(_scsih_is_end_device(device_info)))
6967 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6968 slot = le16_to_cpu(sas_device_pg0.Slot);
6969 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6973 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6978 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6979 * @ioc: per adapter object
6980 * @wwid: world wide identifier for raid volume
6981 * @handle: device handle
6983 * After host reset, find out whether devices are still responding.
6984 * Used in _scsi_remove_unresponsive_raid_devices.
6989 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6992 struct MPT2SAS_TARGET *sas_target_priv_data;
6993 struct scsi_target *starget;
6994 struct _raid_device *raid_device;
6995 unsigned long flags;
6997 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6998 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6999 if (raid_device->wwid == wwid && raid_device->starget) {
7000 starget = raid_device->starget;
7001 if (starget && starget->hostdata) {
7002 sas_target_priv_data = starget->hostdata;
7003 sas_target_priv_data->deleted = 0;
7005 sas_target_priv_data = NULL;
7006 raid_device->responding = 1;
7007 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7008 starget_printk(KERN_INFO, raid_device->starget,
7009 "handle(0x%04x), wwid(0x%016llx)\n", handle,
7010 (unsigned long long)raid_device->wwid);
7012 * WARPDRIVE: The handles of the PDs might have changed
7013 * across the host reset so re-initialize the
7014 * required data for Direct IO
7016 _scsih_init_warpdrive_properties(ioc, raid_device);
7017 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7018 if (raid_device->handle == handle) {
7019 spin_unlock_irqrestore(&ioc->raid_device_lock,
7023 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
7024 raid_device->handle);
7025 raid_device->handle = handle;
7026 if (sas_target_priv_data)
7027 sas_target_priv_data->handle = handle;
7028 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7033 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7037 * _scsih_search_responding_raid_devices -
7038 * @ioc: per adapter object
7040 * After host reset, find out whether devices are still responding.
7046 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
7048 Mpi2RaidVolPage1_t volume_pg1;
7049 Mpi2RaidVolPage0_t volume_pg0;
7050 Mpi2RaidPhysDiskPage0_t pd_pg0;
7051 Mpi2ConfigReply_t mpi_reply;
7056 if (!ioc->ir_firmware)
7059 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
7062 if (list_empty(&ioc->raid_device_list))
7066 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7067 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7068 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7069 MPI2_IOCSTATUS_MASK;
7070 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7072 handle = le16_to_cpu(volume_pg1.DevHandle);
7074 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7075 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7076 sizeof(Mpi2RaidVolPage0_t)))
7079 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7080 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7081 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
7082 _scsih_mark_responding_raid_device(ioc,
7083 le64_to_cpu(volume_pg1.WWID), handle);
7086 /* refresh the pd_handles */
7087 if (!ioc->is_warpdrive) {
7088 phys_disk_num = 0xFF;
7089 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
7090 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7091 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7093 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7094 MPI2_IOCSTATUS_MASK;
7095 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7097 phys_disk_num = pd_pg0.PhysDiskNum;
7098 handle = le16_to_cpu(pd_pg0.DevHandle);
7099 set_bit(handle, ioc->pd_handles);
7103 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
7104 "complete\n", ioc->name);
7108 * _scsih_mark_responding_expander - mark a expander as responding
7109 * @ioc: per adapter object
7110 * @sas_address: sas address
7113 * After host reset, find out whether devices are still responding.
7114 * Used in _scsi_remove_unresponsive_expanders.
7119 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
7122 struct _sas_node *sas_expander;
7123 unsigned long flags;
7126 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7127 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
7128 if (sas_expander->sas_address != sas_address)
7130 sas_expander->responding = 1;
7131 if (sas_expander->handle == handle)
7133 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
7134 " from(0x%04x) to (0x%04x)!!!\n",
7135 (unsigned long long)sas_expander->sas_address,
7136 sas_expander->handle, handle);
7137 sas_expander->handle = handle;
7138 for (i = 0 ; i < sas_expander->num_phys ; i++)
7139 sas_expander->phy[i].handle = handle;
7143 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7147 * _scsih_search_responding_expanders -
7148 * @ioc: per adapter object
7150 * After host reset, find out whether devices are still responding.
7156 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
7158 Mpi2ExpanderPage0_t expander_pg0;
7159 Mpi2ConfigReply_t mpi_reply;
7164 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
7166 if (list_empty(&ioc->sas_expander_list))
7170 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7171 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7173 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7174 MPI2_IOCSTATUS_MASK;
7175 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
7178 handle = le16_to_cpu(expander_pg0.DevHandle);
7179 sas_address = le64_to_cpu(expander_pg0.SASAddress);
7180 printk(KERN_INFO "\texpander present: handle(0x%04x), "
7181 "sas_addr(0x%016llx)\n", handle,
7182 (unsigned long long)sas_address);
7183 _scsih_mark_responding_expander(ioc, sas_address, handle);
7187 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
7191 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7192 * @ioc: per adapter object
7197 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
7199 struct _sas_device *sas_device, *sas_device_next;
7200 struct _sas_node *sas_expander, *sas_expander_next;
7201 struct _raid_device *raid_device, *raid_device_next;
7202 struct list_head tmp_list;
7203 unsigned long flags;
7206 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7209 /* removing unresponding end devices */
7210 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7214 * Iterate, pulling off devices marked as non-responding. We become the
7215 * owner for the reference the list had on any object we prune.
7217 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7218 list_for_each_entry_safe(sas_device, sas_device_next,
7219 &ioc->sas_device_list, list) {
7220 if (!sas_device->responding)
7221 list_move_tail(&sas_device->list, &head);
7223 sas_device->responding = 0;
7225 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7228 * Now, uninitialize and remove the unresponding devices we pruned.
7230 list_for_each_entry_safe(sas_device, sas_device_next, &head, list) {
7231 _scsih_remove_device(ioc, sas_device);
7232 list_del_init(&sas_device->list);
7233 sas_device_put(sas_device);
7236 /* removing unresponding volumes */
7237 if (ioc->ir_firmware) {
7238 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7239 "volumes\n", ioc->name);
7240 list_for_each_entry_safe(raid_device, raid_device_next,
7241 &ioc->raid_device_list, list) {
7242 if (!raid_device->responding)
7243 _scsih_sas_volume_delete(ioc,
7244 raid_device->handle);
7246 raid_device->responding = 0;
7249 /* removing unresponding expanders */
7250 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7252 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7253 INIT_LIST_HEAD(&tmp_list);
7254 list_for_each_entry_safe(sas_expander, sas_expander_next,
7255 &ioc->sas_expander_list, list) {
7256 if (!sas_expander->responding)
7257 list_move_tail(&sas_expander->list, &tmp_list);
7259 sas_expander->responding = 0;
7261 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7262 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7264 list_del(&sas_expander->list);
7265 _scsih_expander_node_remove(ioc, sas_expander);
7267 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7269 /* unblock devices */
7270 _scsih_ublock_io_all_device(ioc);
7274 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7275 struct _sas_node *sas_expander, u16 handle)
7277 Mpi2ExpanderPage1_t expander_pg1;
7278 Mpi2ConfigReply_t mpi_reply;
7281 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7282 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7283 &expander_pg1, i, handle))) {
7284 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7285 ioc->name, __FILE__, __LINE__, __func__);
7289 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7290 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7291 expander_pg1.NegotiatedLinkRate >> 4);
7296 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7297 * @ioc: per adapter object
7302 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7304 Mpi2ExpanderPage0_t expander_pg0;
7305 Mpi2SasDevicePage0_t sas_device_pg0;
7306 Mpi2RaidVolPage1_t volume_pg1;
7307 Mpi2RaidVolPage0_t volume_pg0;
7308 Mpi2RaidPhysDiskPage0_t pd_pg0;
7309 Mpi2EventIrConfigElement_t element;
7310 Mpi2ConfigReply_t mpi_reply;
7313 u16 handle, parent_handle;
7315 struct _sas_device *sas_device;
7316 struct _sas_node *expander_device;
7317 static struct _raid_device *raid_device;
7319 unsigned long flags;
7321 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7323 _scsih_sas_host_refresh(ioc);
7325 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7329 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7330 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7331 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7332 MPI2_IOCSTATUS_MASK;
7333 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7334 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7335 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7336 ioc->name, ioc_status,
7337 le32_to_cpu(mpi_reply.IOCLogInfo));
7340 handle = le16_to_cpu(expander_pg0.DevHandle);
7341 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7342 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7343 ioc, le64_to_cpu(expander_pg0.SASAddress));
7344 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7345 if (expander_device)
7346 _scsih_refresh_expander_links(ioc, expander_device,
7349 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7350 "handle (0x%04x), sas_addr(0x%016llx)\n",
7351 ioc->name, handle, (unsigned long long)
7352 le64_to_cpu(expander_pg0.SASAddress));
7353 _scsih_expander_add(ioc, handle);
7354 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7355 "handle (0x%04x), sas_addr(0x%016llx)\n",
7356 ioc->name, handle, (unsigned long long)
7357 le64_to_cpu(expander_pg0.SASAddress));
7361 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7364 if (!ioc->ir_firmware)
7367 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7369 phys_disk_num = 0xFF;
7370 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7371 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7373 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7374 MPI2_IOCSTATUS_MASK;
7375 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7376 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7377 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7378 ioc->name, ioc_status,
7379 le32_to_cpu(mpi_reply.IOCLogInfo));
7382 phys_disk_num = pd_pg0.PhysDiskNum;
7383 handle = le16_to_cpu(pd_pg0.DevHandle);
7384 sas_device = mpt2sas_get_sdev_by_handle(ioc, handle);
7386 sas_device_put(sas_device);
7389 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7390 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7393 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7394 MPI2_IOCSTATUS_MASK;
7395 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7396 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7397 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7398 ioc->name, ioc_status,
7399 le32_to_cpu(mpi_reply.IOCLogInfo));
7402 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7403 if (!_scsih_get_sas_address(ioc, parent_handle,
7405 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7406 " handle (0x%04x), sas_addr(0x%016llx)\n",
7407 ioc->name, handle, (unsigned long long)
7408 le64_to_cpu(sas_device_pg0.SASAddress));
7409 mpt2sas_transport_update_links(ioc, sas_address,
7410 handle, sas_device_pg0.PhyNum,
7411 MPI2_SAS_NEG_LINK_RATE_1_5);
7412 set_bit(handle, ioc->pd_handles);
7414 /* This will retry adding the end device.
7415 * _scsih_add_device() will decide on retries and
7416 * return "1" when it should be retried
7418 while (_scsih_add_device(ioc, handle, retry_count++,
7422 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7423 " handle (0x%04x), sas_addr(0x%016llx)\n",
7424 ioc->name, handle, (unsigned long long)
7425 le64_to_cpu(sas_device_pg0.SASAddress));
7429 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7432 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7435 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7436 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7437 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7438 MPI2_IOCSTATUS_MASK;
7439 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7440 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7441 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7442 ioc->name, ioc_status,
7443 le32_to_cpu(mpi_reply.IOCLogInfo));
7446 handle = le16_to_cpu(volume_pg1.DevHandle);
7447 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7448 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7449 le64_to_cpu(volume_pg1.WWID));
7450 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7453 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7454 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7455 sizeof(Mpi2RaidVolPage0_t)))
7457 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7458 MPI2_IOCSTATUS_MASK;
7459 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7460 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7461 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7462 ioc->name, ioc_status,
7463 le32_to_cpu(mpi_reply.IOCLogInfo));
7466 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7467 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7468 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7469 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7470 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7471 element.VolDevHandle = volume_pg1.DevHandle;
7472 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7473 " handle (0x%04x)\n", ioc->name,
7474 volume_pg1.DevHandle);
7475 _scsih_sas_volume_add(ioc, &element);
7476 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7477 " handle (0x%04x)\n", ioc->name,
7478 volume_pg1.DevHandle);
7482 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7487 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7491 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7492 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7494 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7495 MPI2_IOCSTATUS_MASK;
7496 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7497 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7498 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7499 ioc->name, ioc_status,
7500 le32_to_cpu(mpi_reply.IOCLogInfo));
7503 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7504 if (!(_scsih_is_end_device(
7505 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7507 sas_device = mpt2sas_get_sdev_by_addr(ioc,
7508 le64_to_cpu(sas_device_pg0.SASAddress));
7510 sas_device_put(sas_device);
7513 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7514 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7515 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7516 "handle (0x%04x), sas_addr(0x%016llx)\n",
7517 ioc->name, handle, (unsigned long long)
7518 le64_to_cpu(sas_device_pg0.SASAddress));
7519 mpt2sas_transport_update_links(ioc, sas_address, handle,
7520 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7522 /* This will retry adding the end device.
7523 * _scsih_add_device() will decide on retries and
7524 * return "1" when it should be retried
7526 while (_scsih_add_device(ioc, handle, retry_count++,
7530 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7531 "handle (0x%04x), sas_addr(0x%016llx)\n",
7532 ioc->name, handle, (unsigned long long)
7533 le64_to_cpu(sas_device_pg0.SASAddress));
7537 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7540 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7545 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7546 * @ioc: per adapter object
7547 * @reset_phase: phase
7549 * The handler for doing any required cleanup or initialization.
7551 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7552 * MPT2_IOC_DONE_RESET
7557 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7559 switch (reset_phase) {
7560 case MPT2_IOC_PRE_RESET:
7561 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7562 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7564 case MPT2_IOC_AFTER_RESET:
7565 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7566 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7567 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7568 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7569 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7570 complete(&ioc->scsih_cmds.done);
7572 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7573 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7574 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7575 complete(&ioc->tm_cmds.done);
7577 _scsih_fw_event_cleanup_queue(ioc);
7578 _scsih_flush_running_cmds(ioc);
7580 case MPT2_IOC_DONE_RESET:
7581 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7582 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7583 _scsih_sas_host_refresh(ioc);
7584 _scsih_prep_device_scan(ioc);
7585 _scsih_search_responding_sas_devices(ioc);
7586 _scsih_search_responding_raid_devices(ioc);
7587 _scsih_search_responding_expanders(ioc);
7588 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7589 !ioc->sas_hba.num_phys)) {
7590 _scsih_prep_device_scan(ioc);
7591 _scsih_search_responding_sas_devices(ioc);
7592 _scsih_search_responding_raid_devices(ioc);
7593 _scsih_search_responding_expanders(ioc);
7594 _scsih_error_recovery_delete_devices(ioc);
7601 * _firmware_event_work - delayed task for processing firmware events
7602 * @ioc: per adapter object
7603 * @work: equal to the fw_event_work object
7609 _firmware_event_work(struct work_struct *work)
7611 struct fw_event_work *fw_event = container_of(work,
7612 struct fw_event_work, delayed_work.work);
7613 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7615 _scsih_fw_event_del_from_list(ioc, fw_event);
7617 /* the queue is being flushed so ignore this event */
7618 if (ioc->remove_host || ioc->pci_error_recovery) {
7619 fw_event_work_put(fw_event);
7623 switch (fw_event->event) {
7624 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7625 while (scsi_host_in_recovery(ioc->shost) ||
7626 ioc->shost_recovery) {
7628 * If we're unloading, bail. Otherwise, this can become
7631 if (ioc->remove_host)
7636 _scsih_remove_unresponding_sas_devices(ioc);
7637 _scsih_scan_for_devices_after_reset(ioc);
7639 case MPT2SAS_PORT_ENABLE_COMPLETE:
7640 ioc->start_scan = 0;
7642 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7643 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7646 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7647 "from worker thread\n", ioc->name));
7649 case MPT2SAS_TURN_ON_PFA_LED:
7650 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7652 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7653 _scsih_sas_topology_change_event(ioc, fw_event);
7655 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7656 _scsih_sas_device_status_change_event(ioc,
7659 case MPI2_EVENT_SAS_DISCOVERY:
7660 _scsih_sas_discovery_event(ioc,
7663 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7664 _scsih_sas_broadcast_primitive_event(ioc,
7667 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7668 _scsih_sas_enclosure_dev_status_change_event(ioc,
7671 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7672 _scsih_sas_ir_config_change_event(ioc, fw_event);
7674 case MPI2_EVENT_IR_VOLUME:
7675 _scsih_sas_ir_volume_event(ioc, fw_event);
7677 case MPI2_EVENT_IR_PHYSICAL_DISK:
7678 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7680 case MPI2_EVENT_IR_OPERATION_STATUS:
7681 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7685 fw_event_work_put(fw_event);
7689 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7690 * @ioc: per adapter object
7691 * @msix_index: MSIX table index supplied by the OS
7692 * @reply: reply message frame(lower 32bit addr)
7693 * Context: interrupt.
7695 * This function merely adds a new work task into ioc->firmware_event_thread.
7696 * The tasks are worked from _firmware_event_work in user context.
7701 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7704 struct fw_event_work *fw_event;
7705 Mpi2EventNotificationReply_t *mpi_reply;
7709 /* events turned off due to host reset or driver unloading */
7710 if (ioc->remove_host || ioc->pci_error_recovery)
7713 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7715 if (unlikely(!mpi_reply)) {
7716 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7717 ioc->name, __FILE__, __LINE__, __func__);
7721 event = le16_to_cpu(mpi_reply->Event);
7725 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7727 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7728 (Mpi2EventDataSasBroadcastPrimitive_t *)
7729 mpi_reply->EventData;
7731 if (baen_data->Primitive !=
7732 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7735 if (ioc->broadcast_aen_busy) {
7736 ioc->broadcast_aen_pending++;
7739 ioc->broadcast_aen_busy = 1;
7743 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7744 _scsih_check_topo_delete_events(ioc,
7745 (Mpi2EventDataSasTopologyChangeList_t *)
7746 mpi_reply->EventData);
7748 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7749 _scsih_check_ir_config_unhide_events(ioc,
7750 (Mpi2EventDataIrConfigChangeList_t *)
7751 mpi_reply->EventData);
7753 case MPI2_EVENT_IR_VOLUME:
7754 _scsih_check_volume_delete_events(ioc,
7755 (Mpi2EventDataIrVolume_t *)
7756 mpi_reply->EventData);
7758 case MPI2_EVENT_LOG_ENTRY_ADDED:
7760 Mpi2EventDataLogEntryAdded_t *log_entry;
7763 if (!ioc->is_warpdrive)
7766 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7767 mpi_reply->EventData;
7768 log_code = (__le32 *)log_entry->LogData;
7770 if (le16_to_cpu(log_entry->LogEntryQualifier)
7771 != MPT2_WARPDRIVE_LOGENTRY)
7774 switch (le32_to_cpu(*log_code)) {
7775 case MPT2_WARPDRIVE_LC_SSDT:
7776 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7777 "IO Throttling has occurred in the WarpDrive "
7778 "subsystem. Check WarpDrive documentation for "
7779 "additional details.\n", ioc->name);
7781 case MPT2_WARPDRIVE_LC_SSDLW:
7782 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7783 "Program/Erase Cycles for the WarpDrive subsystem "
7784 "in degraded range. Check WarpDrive documentation "
7785 "for additional details.\n", ioc->name);
7787 case MPT2_WARPDRIVE_LC_SSDLF:
7788 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7789 "There are no Program/Erase Cycles for the "
7790 "WarpDrive subsystem. The storage device will be "
7791 "in read-only mode. Check WarpDrive documentation "
7792 "for additional details.\n", ioc->name);
7794 case MPT2_WARPDRIVE_LC_BRMF:
7795 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7796 "The Backup Rail Monitor has failed on the "
7797 "WarpDrive subsystem. Check WarpDrive "
7798 "documentation for additional details.\n",
7805 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7806 case MPI2_EVENT_IR_OPERATION_STATUS:
7807 case MPI2_EVENT_SAS_DISCOVERY:
7808 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7809 case MPI2_EVENT_IR_PHYSICAL_DISK:
7812 case MPI2_EVENT_TEMP_THRESHOLD:
7813 _scsih_temp_threshold_events(ioc,
7814 (Mpi2EventDataTemperature_t *)
7815 mpi_reply->EventData);
7818 default: /* ignore the rest */
7822 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7823 fw_event = alloc_fw_event_work(sz);
7825 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7826 ioc->name, __FILE__, __LINE__, __func__);
7830 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7831 fw_event->ioc = ioc;
7832 fw_event->VF_ID = mpi_reply->VF_ID;
7833 fw_event->VP_ID = mpi_reply->VP_ID;
7834 fw_event->event = event;
7835 _scsih_fw_event_add(ioc, fw_event);
7836 fw_event_work_put(fw_event);
7840 /* shost template */
7841 static struct scsi_host_template scsih_driver_template = {
7842 .module = THIS_MODULE,
7843 .name = "Fusion MPT SAS Host",
7844 .proc_name = MPT2SAS_DRIVER_NAME,
7845 .queuecommand = _scsih_qcmd,
7846 .target_alloc = _scsih_target_alloc,
7847 .slave_alloc = _scsih_slave_alloc,
7848 .slave_configure = _scsih_slave_configure,
7849 .target_destroy = _scsih_target_destroy,
7850 .slave_destroy = _scsih_slave_destroy,
7851 .scan_finished = _scsih_scan_finished,
7852 .scan_start = _scsih_scan_start,
7853 .change_queue_depth = _scsih_change_queue_depth,
7854 .eh_abort_handler = _scsih_abort,
7855 .eh_device_reset_handler = _scsih_dev_reset,
7856 .eh_target_reset_handler = _scsih_target_reset,
7857 .eh_host_reset_handler = _scsih_host_reset,
7858 .bios_param = _scsih_bios_param,
7861 .sg_tablesize = MPT2SAS_SG_DEPTH,
7862 .max_sectors = 32767,
7864 .use_clustering = ENABLE_CLUSTERING,
7865 .shost_attrs = mpt2sas_host_attrs,
7866 .sdev_attrs = mpt2sas_dev_attrs,
7867 .track_queue_depth = 1,
7871 * _scsih_expander_node_remove - removing expander device from list.
7872 * @ioc: per adapter object
7873 * @sas_expander: the sas_device object
7874 * Context: Calling function should acquire ioc->sas_node_lock.
7876 * Removing object and freeing associated memory from the
7877 * ioc->sas_expander_list.
7882 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7883 struct _sas_node *sas_expander)
7885 struct _sas_port *mpt2sas_port, *next;
7887 /* remove sibling ports attached to this expander */
7888 list_for_each_entry_safe(mpt2sas_port, next,
7889 &sas_expander->sas_port_list, port_list) {
7890 if (ioc->shost_recovery)
7892 if (mpt2sas_port->remote_identify.device_type ==
7894 mpt2sas_device_remove_by_sas_address(ioc,
7895 mpt2sas_port->remote_identify.sas_address);
7896 else if (mpt2sas_port->remote_identify.device_type ==
7897 SAS_EDGE_EXPANDER_DEVICE ||
7898 mpt2sas_port->remote_identify.device_type ==
7899 SAS_FANOUT_EXPANDER_DEVICE)
7900 mpt2sas_expander_remove(ioc,
7901 mpt2sas_port->remote_identify.sas_address);
7904 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7905 sas_expander->sas_address_parent);
7907 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7908 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7909 sas_expander->handle, (unsigned long long)
7910 sas_expander->sas_address);
7912 kfree(sas_expander->phy);
7913 kfree(sas_expander);
7917 * _scsih_ir_shutdown - IR shutdown notification
7918 * @ioc: per adapter object
7920 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7921 * the host system is shutting down.
7926 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7928 Mpi2RaidActionRequest_t *mpi_request;
7929 Mpi2RaidActionReply_t *mpi_reply;
7932 /* is IR firmware build loaded ? */
7933 if (!ioc->ir_firmware)
7936 mutex_lock(&ioc->scsih_cmds.mutex);
7938 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7939 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7940 ioc->name, __func__);
7943 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7945 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7947 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7948 ioc->name, __func__);
7949 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7953 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7954 ioc->scsih_cmds.smid = smid;
7955 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7957 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7958 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7960 if (!ioc->hide_ir_msg)
7961 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7962 init_completion(&ioc->scsih_cmds.done);
7963 mpt2sas_base_put_smid_default(ioc, smid);
7964 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7966 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7967 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7968 ioc->name, __func__);
7972 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7973 mpi_reply = ioc->scsih_cmds.reply;
7975 if (!ioc->hide_ir_msg)
7976 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7977 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7978 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7979 le32_to_cpu(mpi_reply->IOCLogInfo));
7983 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7984 mutex_unlock(&ioc->scsih_cmds.mutex);
7988 * _scsih_shutdown - routine call during system shutdown
7989 * @pdev: PCI device struct
7994 _scsih_shutdown(struct pci_dev *pdev)
7996 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7997 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7998 struct workqueue_struct *wq;
7999 unsigned long flags;
8001 ioc->remove_host = 1;
8002 _scsih_fw_event_cleanup_queue(ioc);
8004 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8005 wq = ioc->firmware_event_thread;
8006 ioc->firmware_event_thread = NULL;
8007 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8009 destroy_workqueue(wq);
8011 _scsih_ir_shutdown(ioc);
8012 mpt2sas_base_detach(ioc);
8016 * _scsih_remove - detach and remove add host
8017 * @pdev: PCI device struct
8019 * Routine called when unloading the driver.
8023 _scsih_remove(struct pci_dev *pdev)
8025 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8026 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8027 struct _sas_port *mpt2sas_port, *next_port;
8028 struct _raid_device *raid_device, *next;
8029 struct MPT2SAS_TARGET *sas_target_priv_data;
8030 struct workqueue_struct *wq;
8031 unsigned long flags;
8033 ioc->remove_host = 1;
8034 _scsih_fw_event_cleanup_queue(ioc);
8036 spin_lock_irqsave(&ioc->fw_event_lock, flags);
8037 wq = ioc->firmware_event_thread;
8038 ioc->firmware_event_thread = NULL;
8039 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
8041 destroy_workqueue(wq);
8043 /* release all the volumes */
8044 _scsih_ir_shutdown(ioc);
8045 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
8047 if (raid_device->starget) {
8048 sas_target_priv_data =
8049 raid_device->starget->hostdata;
8050 sas_target_priv_data->deleted = 1;
8051 scsi_remove_target(&raid_device->starget->dev);
8053 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
8054 "(0x%016llx)\n", ioc->name, raid_device->handle,
8055 (unsigned long long) raid_device->wwid);
8056 _scsih_raid_device_remove(ioc, raid_device);
8059 /* free ports attached to the sas_host */
8060 list_for_each_entry_safe(mpt2sas_port, next_port,
8061 &ioc->sas_hba.sas_port_list, port_list) {
8062 if (mpt2sas_port->remote_identify.device_type ==
8064 mpt2sas_device_remove_by_sas_address(ioc,
8065 mpt2sas_port->remote_identify.sas_address);
8066 else if (mpt2sas_port->remote_identify.device_type ==
8067 SAS_EDGE_EXPANDER_DEVICE ||
8068 mpt2sas_port->remote_identify.device_type ==
8069 SAS_FANOUT_EXPANDER_DEVICE)
8070 mpt2sas_expander_remove(ioc,
8071 mpt2sas_port->remote_identify.sas_address);
8074 /* free phys attached to the sas_host */
8075 if (ioc->sas_hba.num_phys) {
8076 kfree(ioc->sas_hba.phy);
8077 ioc->sas_hba.phy = NULL;
8078 ioc->sas_hba.num_phys = 0;
8081 sas_remove_host(shost);
8082 scsi_remove_host(shost);
8083 mpt2sas_base_detach(ioc);
8084 list_del(&ioc->list);
8085 scsi_host_put(shost);
8089 * _scsih_probe_boot_devices - reports 1st device
8090 * @ioc: per adapter object
8092 * If specified in bios page 2, this routine reports the 1st
8093 * device scsi-ml or sas transport for persistent boot device
8094 * purposes. Please refer to function _scsih_determine_boot_device()
8097 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
8101 struct _sas_device *sas_device;
8102 struct _raid_device *raid_device;
8104 u64 sas_address_parent;
8106 unsigned long flags;
8109 /* no Bios, return immediately */
8110 if (!ioc->bios_pg3.BiosVersion)
8115 if (ioc->req_boot_device.device) {
8116 device = ioc->req_boot_device.device;
8117 is_raid = ioc->req_boot_device.is_raid;
8118 } else if (ioc->req_alt_boot_device.device) {
8119 device = ioc->req_alt_boot_device.device;
8120 is_raid = ioc->req_alt_boot_device.is_raid;
8121 } else if (ioc->current_boot_device.device) {
8122 device = ioc->current_boot_device.device;
8123 is_raid = ioc->current_boot_device.is_raid;
8130 raid_device = device;
8131 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8132 raid_device->id, 0);
8134 _scsih_raid_device_remove(ioc, raid_device);
8136 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8137 sas_device = device;
8138 handle = sas_device->handle;
8139 sas_address_parent = sas_device->sas_address_parent;
8140 sas_address = sas_device->sas_address;
8141 list_move_tail(&sas_device->list, &ioc->sas_device_list);
8142 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8144 if (ioc->hide_drives)
8146 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
8147 sas_device->sas_address_parent)) {
8148 _scsih_sas_device_remove(ioc, sas_device);
8149 } else if (!sas_device->starget) {
8150 if (!ioc->is_driver_loading) {
8151 mpt2sas_transport_port_remove(ioc,
8153 sas_address_parent);
8154 _scsih_sas_device_remove(ioc, sas_device);
8161 * _scsih_probe_raid - reporting raid volumes to scsi-ml
8162 * @ioc: per adapter object
8164 * Called during initial loading of the driver.
8167 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
8169 struct _raid_device *raid_device, *raid_next;
8172 list_for_each_entry_safe(raid_device, raid_next,
8173 &ioc->raid_device_list, list) {
8174 if (raid_device->starget)
8176 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
8177 raid_device->id, 0);
8179 _scsih_raid_device_remove(ioc, raid_device);
8183 static struct _sas_device *get_next_sas_device(struct MPT2SAS_ADAPTER *ioc)
8185 struct _sas_device *sas_device = NULL;
8186 unsigned long flags;
8188 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8189 if (!list_empty(&ioc->sas_device_init_list)) {
8190 sas_device = list_first_entry(&ioc->sas_device_init_list,
8191 struct _sas_device, list);
8192 sas_device_get(sas_device);
8194 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8199 static void sas_device_make_active(struct MPT2SAS_ADAPTER *ioc,
8200 struct _sas_device *sas_device)
8202 unsigned long flags;
8204 spin_lock_irqsave(&ioc->sas_device_lock, flags);
8207 * Since we dropped the lock during the call to port_add(), we need to
8208 * be careful here that somebody else didn't move or delete this item
8209 * while we were busy with other things.
8211 * If it was on the list, we need a put() for the reference the list
8212 * had. Either way, we need a get() for the destination list.
8214 if (!list_empty(&sas_device->list)) {
8215 list_del_init(&sas_device->list);
8216 sas_device_put(sas_device);
8219 sas_device_get(sas_device);
8220 list_add_tail(&sas_device->list, &ioc->sas_device_list);
8222 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
8226 * _scsih_probe_sas - reporting sas devices to sas transport
8227 * @ioc: per adapter object
8229 * Called during initial loading of the driver.
8232 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
8234 struct _sas_device *sas_device;
8236 if (ioc->hide_drives)
8239 while ((sas_device = get_next_sas_device(ioc))) {
8240 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
8241 sas_device->sas_address_parent)) {
8242 _scsih_sas_device_remove(ioc, sas_device);
8243 sas_device_put(sas_device);
8245 } else if (!sas_device->starget) {
8246 if (!ioc->is_driver_loading) {
8247 mpt2sas_transport_port_remove(ioc,
8248 sas_device->sas_address,
8249 sas_device->sas_address_parent);
8250 _scsih_sas_device_remove(ioc, sas_device);
8251 sas_device_put(sas_device);
8256 sas_device_make_active(ioc, sas_device);
8257 sas_device_put(sas_device);
8262 * _scsih_probe_devices - probing for devices
8263 * @ioc: per adapter object
8265 * Called during initial loading of the driver.
8268 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
8270 u16 volume_mapping_flags;
8272 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8273 return; /* return when IOC doesn't support initiator mode */
8275 _scsih_probe_boot_devices(ioc);
8277 if (ioc->ir_firmware) {
8278 volume_mapping_flags =
8279 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8280 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8281 if (volume_mapping_flags ==
8282 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8283 _scsih_probe_raid(ioc);
8284 _scsih_probe_sas(ioc);
8286 _scsih_probe_sas(ioc);
8287 _scsih_probe_raid(ioc);
8290 _scsih_probe_sas(ioc);
8295 * _scsih_scan_start - scsi lld callback for .scan_start
8296 * @shost: SCSI host pointer
8298 * The shost has the ability to discover targets on its own instead
8299 * of scanning the entire bus. In our implemention, we will kick off
8300 * firmware discovery.
8303 _scsih_scan_start(struct Scsi_Host *shost)
8305 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8308 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8309 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8311 if (disable_discovery > 0)
8314 ioc->start_scan = 1;
8315 rc = mpt2sas_port_enable(ioc);
8318 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8322 * _scsih_scan_finished - scsi lld callback for .scan_finished
8323 * @shost: SCSI host pointer
8324 * @time: elapsed time of the scan in jiffies
8326 * This function will be called periodically until it returns 1 with the
8327 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8328 * we wait for firmware discovery to complete, then return 1.
8331 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8333 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8335 if (disable_discovery > 0) {
8336 ioc->is_driver_loading = 0;
8337 ioc->wait_for_discovery_to_complete = 0;
8341 if (time >= (300 * HZ)) {
8342 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8343 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8344 "(timeout=300s)\n", ioc->name);
8345 ioc->is_driver_loading = 0;
8349 if (ioc->start_scan)
8352 if (ioc->start_scan_failed) {
8353 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8354 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8355 ioc->is_driver_loading = 0;
8356 ioc->wait_for_discovery_to_complete = 0;
8357 ioc->remove_host = 1;
8361 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8362 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8364 if (ioc->wait_for_discovery_to_complete) {
8365 ioc->wait_for_discovery_to_complete = 0;
8366 _scsih_probe_devices(ioc);
8368 mpt2sas_base_start_watchdog(ioc);
8369 ioc->is_driver_loading = 0;
8375 * _scsih_probe - attach and add scsi host
8376 * @pdev: PCI device struct
8377 * @id: pci device id
8379 * Returns 0 success, anything else error.
8382 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8384 struct MPT2SAS_ADAPTER *ioc;
8385 struct Scsi_Host *shost;
8388 shost = scsi_host_alloc(&scsih_driver_template,
8389 sizeof(struct MPT2SAS_ADAPTER));
8393 /* init local params */
8394 ioc = shost_priv(shost);
8395 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8396 INIT_LIST_HEAD(&ioc->list);
8397 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8399 ioc->id = mpt_ids++;
8400 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8402 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8403 ioc->is_warpdrive = 1;
8404 ioc->hide_ir_msg = 1;
8406 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8407 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8408 ioc->tm_cb_idx = tm_cb_idx;
8409 ioc->ctl_cb_idx = ctl_cb_idx;
8410 ioc->base_cb_idx = base_cb_idx;
8411 ioc->port_enable_cb_idx = port_enable_cb_idx;
8412 ioc->transport_cb_idx = transport_cb_idx;
8413 ioc->scsih_cb_idx = scsih_cb_idx;
8414 ioc->config_cb_idx = config_cb_idx;
8415 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8416 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8417 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8418 ioc->logging_level = logging_level;
8419 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8420 /* misc semaphores and spin locks */
8421 mutex_init(&ioc->reset_in_progress_mutex);
8422 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8423 spin_lock_init(&ioc->scsi_lookup_lock);
8424 spin_lock_init(&ioc->sas_device_lock);
8425 spin_lock_init(&ioc->sas_node_lock);
8426 spin_lock_init(&ioc->fw_event_lock);
8427 spin_lock_init(&ioc->raid_device_lock);
8429 INIT_LIST_HEAD(&ioc->sas_device_list);
8430 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8431 INIT_LIST_HEAD(&ioc->sas_expander_list);
8432 INIT_LIST_HEAD(&ioc->fw_event_list);
8433 INIT_LIST_HEAD(&ioc->raid_device_list);
8434 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8435 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8436 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8437 INIT_LIST_HEAD(&ioc->reply_queue_list);
8439 /* init shost parameters */
8440 shost->max_cmd_len = 32;
8441 shost->max_lun = max_lun;
8442 shost->transportt = mpt2sas_transport_template;
8443 shost->unique_id = ioc->id;
8445 if (max_sectors != 0xFFFF) {
8446 if (max_sectors < 64) {
8447 shost->max_sectors = 64;
8448 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8449 "for max_sectors, range is 64 to 32767. Assigning "
8450 "value of 64.\n", ioc->name, max_sectors);
8451 } else if (max_sectors > 32767) {
8452 shost->max_sectors = 32767;
8453 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8454 "for max_sectors, range is 64 to 8192. Assigning "
8455 "default value of 32767.\n", ioc->name,
8458 shost->max_sectors = max_sectors & 0xFFFE;
8459 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8460 "set to %d\n", ioc->name, shost->max_sectors);
8464 /* register EEDP capabilities with SCSI layer */
8466 scsi_host_set_prot(shost, prot_mask);
8468 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8469 | SHOST_DIF_TYPE2_PROTECTION
8470 | SHOST_DIF_TYPE3_PROTECTION);
8472 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8475 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8476 "fw_event%d", ioc->id);
8477 ioc->firmware_event_thread = create_singlethread_workqueue(
8478 ioc->firmware_event_name);
8479 if (!ioc->firmware_event_thread) {
8480 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8481 ioc->name, __FILE__, __LINE__, __func__);
8483 goto out_thread_fail;
8486 ioc->is_driver_loading = 1;
8487 if ((mpt2sas_base_attach(ioc))) {
8488 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8489 ioc->name, __FILE__, __LINE__, __func__);
8491 goto out_attach_fail;
8494 if (ioc->is_warpdrive) {
8495 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8496 ioc->hide_drives = 0;
8497 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8498 ioc->hide_drives = 1;
8500 if (_scsih_get_num_volumes(ioc))
8501 ioc->hide_drives = 1;
8503 ioc->hide_drives = 0;
8506 ioc->hide_drives = 0;
8508 rv = scsi_add_host(shost, &pdev->dev);
8510 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8511 ioc->name, __FILE__, __LINE__, __func__);
8512 goto out_add_shost_fail;
8515 scsi_scan_host(shost);
8520 mpt2sas_base_detach(ioc);
8522 destroy_workqueue(ioc->firmware_event_thread);
8524 list_del(&ioc->list);
8525 scsi_host_put(shost);
8531 * _scsih_suspend - power management suspend main entry point
8532 * @pdev: PCI device struct
8533 * @state: PM state change to (usually PCI_D3)
8535 * Returns 0 success, anything else error.
8538 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8540 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8541 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8542 pci_power_t device_state;
8544 mpt2sas_base_stop_watchdog(ioc);
8545 scsi_block_requests(shost);
8546 _scsih_ir_shutdown(ioc);
8547 device_state = pci_choose_state(pdev, state);
8548 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8549 "operating state [D%d]\n", ioc->name, pdev,
8550 pci_name(pdev), device_state);
8552 mpt2sas_base_free_resources(ioc);
8553 pci_save_state(pdev);
8554 pci_set_power_state(pdev, device_state);
8559 * _scsih_resume - power management resume main entry point
8560 * @pdev: PCI device struct
8562 * Returns 0 success, anything else error.
8565 _scsih_resume(struct pci_dev *pdev)
8567 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8568 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8569 pci_power_t device_state = pdev->current_state;
8572 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8573 "operating state [D%d]\n", ioc->name, pdev,
8574 pci_name(pdev), device_state);
8576 pci_set_power_state(pdev, PCI_D0);
8577 pci_enable_wake(pdev, PCI_D0, 0);
8578 pci_restore_state(pdev);
8580 r = mpt2sas_base_map_resources(ioc);
8584 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8585 scsi_unblock_requests(shost);
8586 mpt2sas_base_start_watchdog(ioc);
8589 #endif /* CONFIG_PM */
8592 * _scsih_pci_error_detected - Called when a PCI error is detected.
8593 * @pdev: PCI device struct
8594 * @state: PCI channel state
8596 * Description: Called when a PCI error is detected.
8599 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8601 static pci_ers_result_t
8602 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8604 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8605 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8607 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8611 case pci_channel_io_normal:
8612 return PCI_ERS_RESULT_CAN_RECOVER;
8613 case pci_channel_io_frozen:
8614 /* Fatal error, prepare for slot reset */
8615 ioc->pci_error_recovery = 1;
8616 scsi_block_requests(ioc->shost);
8617 mpt2sas_base_stop_watchdog(ioc);
8618 mpt2sas_base_free_resources(ioc);
8619 return PCI_ERS_RESULT_NEED_RESET;
8620 case pci_channel_io_perm_failure:
8621 /* Permanent error, prepare for device removal */
8622 ioc->pci_error_recovery = 1;
8623 mpt2sas_base_stop_watchdog(ioc);
8624 _scsih_flush_running_cmds(ioc);
8625 return PCI_ERS_RESULT_DISCONNECT;
8627 return PCI_ERS_RESULT_NEED_RESET;
8631 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8632 * @pdev: PCI device struct
8634 * Description: This routine is called by the pci error recovery
8635 * code after the PCI slot has been reset, just before we
8636 * should resume normal operations.
8638 static pci_ers_result_t
8639 _scsih_pci_slot_reset(struct pci_dev *pdev)
8641 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8642 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8645 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8648 ioc->pci_error_recovery = 0;
8650 pci_restore_state(pdev);
8651 rc = mpt2sas_base_map_resources(ioc);
8653 return PCI_ERS_RESULT_DISCONNECT;
8656 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8659 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8660 (rc == 0) ? "success" : "failed");
8663 return PCI_ERS_RESULT_RECOVERED;
8665 return PCI_ERS_RESULT_DISCONNECT;
8669 * _scsih_pci_resume() - resume normal ops after PCI reset
8670 * @pdev: pointer to PCI device
8672 * Called when the error recovery driver tells us that its
8673 * OK to resume normal operation. Use completion to allow
8674 * halted scsi ops to resume.
8677 _scsih_pci_resume(struct pci_dev *pdev)
8679 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8680 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8682 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8684 pci_cleanup_aer_uncorrect_error_status(pdev);
8685 mpt2sas_base_start_watchdog(ioc);
8686 scsi_unblock_requests(ioc->shost);
8690 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8691 * @pdev: pointer to PCI device
8693 static pci_ers_result_t
8694 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8696 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8697 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8699 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8702 /* TODO - dump whatever for debugging purposes */
8704 /* Request a slot reset. */
8705 return PCI_ERS_RESULT_NEED_RESET;
8708 static const struct pci_error_handlers _scsih_err_handler = {
8709 .error_detected = _scsih_pci_error_detected,
8710 .mmio_enabled = _scsih_pci_mmio_enabled,
8711 .slot_reset = _scsih_pci_slot_reset,
8712 .resume = _scsih_pci_resume,
8715 static struct pci_driver scsih_driver = {
8716 .name = MPT2SAS_DRIVER_NAME,
8717 .id_table = scsih_pci_table,
8718 .probe = _scsih_probe,
8719 .remove = _scsih_remove,
8720 .shutdown = _scsih_shutdown,
8721 .err_handler = &_scsih_err_handler,
8723 .suspend = _scsih_suspend,
8724 .resume = _scsih_resume,
8728 /* raid transport support */
8729 static struct raid_function_template mpt2sas_raid_functions = {
8730 .cookie = &scsih_driver_template,
8731 .is_raid = _scsih_is_raid,
8732 .get_resync = _scsih_get_resync,
8733 .get_state = _scsih_get_state,
8737 * _scsih_init - main entry point for this driver.
8739 * Returns 0 success, anything else error.
8747 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8748 MPT2SAS_DRIVER_VERSION);
8750 mpt2sas_transport_template =
8751 sas_attach_transport(&mpt2sas_transport_functions);
8752 if (!mpt2sas_transport_template)
8754 /* raid transport support */
8755 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8756 if (!mpt2sas_raid_template) {
8757 sas_release_transport(mpt2sas_transport_template);
8761 mpt2sas_base_initialize_callback_handler();
8763 /* queuecommand callback hander */
8764 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8766 /* task management callback handler */
8767 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8769 /* base internal commands callback handler */
8770 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8771 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8772 mpt2sas_port_enable_done);
8774 /* transport internal commands callback handler */
8775 transport_cb_idx = mpt2sas_base_register_callback_handler(
8776 mpt2sas_transport_done);
8778 /* scsih internal commands callback handler */
8779 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8781 /* configuration page API internal commands callback handler */
8782 config_cb_idx = mpt2sas_base_register_callback_handler(
8783 mpt2sas_config_done);
8785 /* ctl module callback handler */
8786 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8788 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8789 _scsih_tm_tr_complete);
8791 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8792 _scsih_tm_volume_tr_complete);
8794 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8795 _scsih_sas_control_complete);
8799 error = pci_register_driver(&scsih_driver);
8801 /* raid transport support */
8802 raid_class_release(mpt2sas_raid_template);
8803 sas_release_transport(mpt2sas_transport_template);
8810 * _scsih_exit - exit point for this driver (when it is a module).
8812 * Returns 0 success, anything else error.
8817 printk(KERN_INFO "mpt2sas version %s unloading\n",
8818 MPT2SAS_DRIVER_VERSION);
8820 pci_unregister_driver(&scsih_driver);
8824 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8825 mpt2sas_base_release_callback_handler(tm_cb_idx);
8826 mpt2sas_base_release_callback_handler(base_cb_idx);
8827 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8828 mpt2sas_base_release_callback_handler(transport_cb_idx);
8829 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8830 mpt2sas_base_release_callback_handler(config_cb_idx);
8831 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8833 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8834 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8835 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8837 /* raid transport support */
8838 raid_class_release(mpt2sas_raid_template);
8839 sas_release_transport(mpt2sas_transport_template);
8843 module_init(_scsih_init);
8844 module_exit(_scsih_exit);