2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
69 struct _sas_node *sas_expander);
70 static void _firmware_event_work(struct work_struct *work);
72 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
74 static void _scsih_scan_start(struct Scsi_Host *shost);
75 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
77 /* global parameters */
78 LIST_HEAD(mpt2sas_ioc_list);
80 /* local parameters */
81 static u8 scsi_io_cb_idx = -1;
82 static u8 tm_cb_idx = -1;
83 static u8 ctl_cb_idx = -1;
84 static u8 base_cb_idx = -1;
85 static u8 port_enable_cb_idx = -1;
86 static u8 transport_cb_idx = -1;
87 static u8 scsih_cb_idx = -1;
88 static u8 config_cb_idx = -1;
91 static u8 tm_tr_cb_idx = -1 ;
92 static u8 tm_tr_volume_cb_idx = -1 ;
93 static u8 tm_sas_control_cb_idx = -1;
95 /* command line options */
96 static u32 logging_level;
97 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
100 static ushort max_sectors = 0xFFFF;
101 module_param(max_sectors, ushort, 0);
102 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 8192 default=8192");
104 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
105 #define MPT2SAS_MAX_LUN (16895)
106 static int max_lun = MPT2SAS_MAX_LUN;
107 module_param(max_lun, int, 0);
108 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
110 /* diag_buffer_enable is bitwise
112 * bit 1 set = SNAPSHOT
113 * bit 2 set = EXTENDED
115 * Either bit can be set, or both
117 static int diag_buffer_enable = -1;
118 module_param(diag_buffer_enable, int, 0);
119 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
120 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
123 * struct sense_info - common structure for obtaining sense keys
125 * @asc: additional sense code
126 * @ascq: additional sense code qualifier
135 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
136 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
137 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
139 * struct fw_event_work - firmware event struct
140 * @list: link list framework
141 * @work: work object (ioc->fault_reset_work_q)
142 * @cancel_pending_work: flag set during reset handling
143 * @ioc: per adapter object
144 * @device_handle: device handle
145 * @VF_ID: virtual function id
146 * @VP_ID: virtual port id
147 * @ignore: flag meaning this event has been marked to ignore
148 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
149 * @event_data: reply event data payload follows
151 * This object stored on ioc->fw_event_list.
153 struct fw_event_work {
154 struct list_head list;
155 u8 cancel_pending_work;
156 struct delayed_work delayed_work;
157 struct MPT2SAS_ADAPTER *ioc;
166 /* raid transport support */
167 static struct raid_template *mpt2sas_raid_template;
170 * struct _scsi_io_transfer - scsi io transfer
171 * @handle: sas device handle (assigned by firmware)
172 * @is_raid: flag set for hidden raid components
173 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
174 * @data_length: data transfer length
175 * @data_dma: dma pointer to data
178 * @cdb_length: cdb length
180 * @timeout: timeout for this command
181 * @VF_ID: virtual function id
182 * @VP_ID: virtual port id
183 * @valid_reply: flag set for reply message
184 * @sense_length: sense length
185 * @ioc_status: ioc status
186 * @scsi_state: scsi state
187 * @scsi_status: scsi staus
188 * @log_info: log information
189 * @transfer_length: data length transfer when there is a reply message
191 * Used for sending internal scsi commands to devices within this module.
192 * Refer to _scsi_send_scsi_io().
194 struct _scsi_io_transfer {
197 enum dma_data_direction dir;
200 u8 sense[SCSI_SENSE_BUFFERSIZE];
208 /* the following bits are only valid when 'valid_reply = 1' */
218 * The pci device ids are defined in mpi/mpi2_cnfg.h.
220 static struct pci_device_id scsih_pci_table[] = {
221 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
222 PCI_ANY_ID, PCI_ANY_ID },
224 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
225 PCI_ANY_ID, PCI_ANY_ID },
226 /* Liberator ~ 2108 */
227 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
228 PCI_ANY_ID, PCI_ANY_ID },
229 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
230 PCI_ANY_ID, PCI_ANY_ID },
231 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
232 PCI_ANY_ID, PCI_ANY_ID },
234 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
235 PCI_ANY_ID, PCI_ANY_ID },
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
237 PCI_ANY_ID, PCI_ANY_ID },
238 /* Thunderbolt ~ 2208 */
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
240 PCI_ANY_ID, PCI_ANY_ID },
241 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
242 PCI_ANY_ID, PCI_ANY_ID },
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
244 PCI_ANY_ID, PCI_ANY_ID },
245 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
246 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
250 PCI_ANY_ID, PCI_ANY_ID },
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
253 PCI_ANY_ID, PCI_ANY_ID },
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
257 PCI_ANY_ID, PCI_ANY_ID },
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
260 PCI_ANY_ID, PCI_ANY_ID },
261 {0} /* Terminating entry */
263 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
266 * _scsih_set_debug_level - global setting of ioc->logging_level.
268 * Note: The logging levels are defined in mpt2sas_debug.h.
271 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
273 int ret = param_set_int(val, kp);
274 struct MPT2SAS_ADAPTER *ioc;
279 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
280 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
281 ioc->logging_level = logging_level;
284 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
285 &logging_level, 0644);
288 * _scsih_srch_boot_sas_address - search based on sas_address
289 * @sas_address: sas address
290 * @boot_device: boot device object from bios page 2
292 * Returns 1 when there's a match, 0 means no match.
295 _scsih_srch_boot_sas_address(u64 sas_address,
296 Mpi2BootDeviceSasWwid_t *boot_device)
298 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
302 * _scsih_srch_boot_device_name - search based on device name
303 * @device_name: device name specified in INDENTIFY fram
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_srch_boot_device_name(u64 device_name,
310 Mpi2BootDeviceDeviceName_t *boot_device)
312 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
316 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
317 * @enclosure_logical_id: enclosure logical id
318 * @slot_number: slot number
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
325 Mpi2BootDeviceEnclosureSlot_t *boot_device)
327 return (enclosure_logical_id == le64_to_cpu(boot_device->
328 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
329 SlotNumber)) ? 1 : 0;
333 * _scsih_is_boot_device - search for matching boot device.
334 * @sas_address: sas address
335 * @device_name: device name specified in INDENTIFY fram
336 * @enclosure_logical_id: enclosure logical id
337 * @slot_number: slot number
338 * @form: specifies boot device form
339 * @boot_device: boot device object from bios page 2
341 * Returns 1 when there's a match, 0 means no match.
344 _scsih_is_boot_device(u64 sas_address, u64 device_name,
345 u64 enclosure_logical_id, u16 slot, u8 form,
346 Mpi2BiosPage2BootDevice_t *boot_device)
351 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
354 rc = _scsih_srch_boot_sas_address(
355 sas_address, &boot_device->SasWwid);
357 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
358 if (!enclosure_logical_id)
360 rc = _scsih_srch_boot_encl_slot(
361 enclosure_logical_id,
362 slot, &boot_device->EnclosureSlot);
364 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
367 rc = _scsih_srch_boot_device_name(
368 device_name, &boot_device->DeviceName);
370 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
378 * _scsih_get_sas_address - set the sas_address for given device handle
379 * @handle: device handle
380 * @sas_address: sas address
382 * Returns 0 success, non-zero when failure
385 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
388 Mpi2SasDevicePage0_t sas_device_pg0;
389 Mpi2ConfigReply_t mpi_reply;
392 if (handle <= ioc->sas_hba.num_phys) {
393 *sas_address = ioc->sas_hba.sas_address;
398 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
400 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
401 ioc->name, __FILE__, __LINE__, __func__);
405 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
407 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
408 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
409 "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
410 __FILE__, __LINE__, __func__);
414 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
419 * _scsih_determine_boot_device - determine boot device.
420 * @ioc: per adapter object
421 * @device: either sas_device or raid_device object
422 * @is_raid: [flag] 1 = raid object, 0 = sas object
424 * Determines whether this device should be first reported device to
425 * to scsi-ml or sas transport, this purpose is for persistent boot device.
426 * There are primary, alternate, and current entries in bios page 2. The order
427 * priority is primary, alternate, then current. This routine saves
428 * the corresponding device object and is_raid flag in the ioc object.
429 * The saved data to be used later in _scsih_probe_boot_devices().
432 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
433 void *device, u8 is_raid)
435 struct _sas_device *sas_device;
436 struct _raid_device *raid_device;
439 u64 enclosure_logical_id;
442 /* only process this function when driver loads */
443 if (!ioc->is_driver_loading)
446 /* no Bios, return immediately */
447 if (!ioc->bios_pg3.BiosVersion)
452 sas_address = sas_device->sas_address;
453 device_name = sas_device->device_name;
454 enclosure_logical_id = sas_device->enclosure_logical_id;
455 slot = sas_device->slot;
457 raid_device = device;
458 sas_address = raid_device->wwid;
460 enclosure_logical_id = 0;
464 if (!ioc->req_boot_device.device) {
465 if (_scsih_is_boot_device(sas_address, device_name,
466 enclosure_logical_id, slot,
467 (ioc->bios_pg2.ReqBootDeviceForm &
468 MPI2_BIOSPAGE2_FORM_MASK),
469 &ioc->bios_pg2.RequestedBootDevice)) {
470 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
471 "%s: req_boot_device(0x%016llx)\n",
473 (unsigned long long)sas_address));
474 ioc->req_boot_device.device = device;
475 ioc->req_boot_device.is_raid = is_raid;
479 if (!ioc->req_alt_boot_device.device) {
480 if (_scsih_is_boot_device(sas_address, device_name,
481 enclosure_logical_id, slot,
482 (ioc->bios_pg2.ReqAltBootDeviceForm &
483 MPI2_BIOSPAGE2_FORM_MASK),
484 &ioc->bios_pg2.RequestedAltBootDevice)) {
485 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
486 "%s: req_alt_boot_device(0x%016llx)\n",
488 (unsigned long long)sas_address));
489 ioc->req_alt_boot_device.device = device;
490 ioc->req_alt_boot_device.is_raid = is_raid;
494 if (!ioc->current_boot_device.device) {
495 if (_scsih_is_boot_device(sas_address, device_name,
496 enclosure_logical_id, slot,
497 (ioc->bios_pg2.CurrentBootDeviceForm &
498 MPI2_BIOSPAGE2_FORM_MASK),
499 &ioc->bios_pg2.CurrentBootDevice)) {
500 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
501 "%s: current_boot_device(0x%016llx)\n",
503 (unsigned long long)sas_address));
504 ioc->current_boot_device.device = device;
505 ioc->current_boot_device.is_raid = is_raid;
511 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
512 * @ioc: per adapter object
513 * @sas_address: sas address
514 * Context: Calling function should acquire ioc->sas_device_lock
516 * This searches for sas_device based on sas_address, then return sas_device
520 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
523 struct _sas_device *sas_device;
525 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
526 if (sas_device->sas_address == sas_address)
529 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
530 if (sas_device->sas_address == sas_address)
537 * _scsih_sas_device_find_by_handle - sas device search
538 * @ioc: per adapter object
539 * @handle: sas device handle (assigned by firmware)
540 * Context: Calling function should acquire ioc->sas_device_lock
542 * This searches for sas_device based on sas_address, then return sas_device
545 static struct _sas_device *
546 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
548 struct _sas_device *sas_device;
550 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
551 if (sas_device->handle == handle)
554 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
555 if (sas_device->handle == handle)
562 * _scsih_sas_device_remove - remove sas_device from list.
563 * @ioc: per adapter object
564 * @sas_device: the sas_device object
565 * Context: This function will acquire ioc->sas_device_lock.
567 * Removing object and freeing associated memory from the ioc->sas_device_list.
570 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
571 struct _sas_device *sas_device)
578 spin_lock_irqsave(&ioc->sas_device_lock, flags);
579 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
580 sas_device->sas_address)) {
581 list_del(&sas_device->list);
584 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
588 * _scsih_sas_device_add - insert sas_device to the list.
589 * @ioc: per adapter object
590 * @sas_device: the sas_device object
591 * Context: This function will acquire ioc->sas_device_lock.
593 * Adding new object to the ioc->sas_device_list.
596 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
597 struct _sas_device *sas_device)
601 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
602 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
603 sas_device->handle, (unsigned long long)sas_device->sas_address));
605 spin_lock_irqsave(&ioc->sas_device_lock, flags);
606 list_add_tail(&sas_device->list, &ioc->sas_device_list);
607 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
609 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
610 sas_device->sas_address_parent))
611 _scsih_sas_device_remove(ioc, sas_device);
615 * _scsih_sas_device_init_add - insert sas_device to the list.
616 * @ioc: per adapter object
617 * @sas_device: the sas_device object
618 * Context: This function will acquire ioc->sas_device_lock.
620 * Adding new object at driver load time to the ioc->sas_device_init_list.
623 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
624 struct _sas_device *sas_device)
628 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
629 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
630 sas_device->handle, (unsigned long long)sas_device->sas_address));
632 spin_lock_irqsave(&ioc->sas_device_lock, flags);
633 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
634 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
635 _scsih_determine_boot_device(ioc, sas_device, 0);
639 * _scsih_raid_device_find_by_id - raid device search
640 * @ioc: per adapter object
641 * @id: sas device target id
642 * @channel: sas device channel
643 * Context: Calling function should acquire ioc->raid_device_lock
645 * This searches for raid_device based on target id, then return raid_device
648 static struct _raid_device *
649 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
651 struct _raid_device *raid_device, *r;
654 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
655 if (raid_device->id == id && raid_device->channel == channel) {
666 * _scsih_raid_device_find_by_handle - raid device search
667 * @ioc: per adapter object
668 * @handle: sas device handle (assigned by firmware)
669 * Context: Calling function should acquire ioc->raid_device_lock
671 * This searches for raid_device based on handle, then return raid_device
674 static struct _raid_device *
675 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
677 struct _raid_device *raid_device, *r;
680 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
681 if (raid_device->handle != handle)
692 * _scsih_raid_device_find_by_wwid - raid device search
693 * @ioc: per adapter object
694 * @handle: sas device handle (assigned by firmware)
695 * Context: Calling function should acquire ioc->raid_device_lock
697 * This searches for raid_device based on wwid, then return raid_device
700 static struct _raid_device *
701 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
703 struct _raid_device *raid_device, *r;
706 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
707 if (raid_device->wwid != wwid)
718 * _scsih_raid_device_add - add raid_device object
719 * @ioc: per adapter object
720 * @raid_device: raid_device object
722 * This is added to the raid_device_list link list.
725 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
726 struct _raid_device *raid_device)
730 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
731 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
732 raid_device->handle, (unsigned long long)raid_device->wwid));
734 spin_lock_irqsave(&ioc->raid_device_lock, flags);
735 list_add_tail(&raid_device->list, &ioc->raid_device_list);
736 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
740 * _scsih_raid_device_remove - delete raid_device object
741 * @ioc: per adapter object
742 * @raid_device: raid_device object
744 * This is removed from the raid_device_list link list.
747 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
748 struct _raid_device *raid_device)
752 spin_lock_irqsave(&ioc->raid_device_lock, flags);
753 list_del(&raid_device->list);
754 memset(raid_device, 0, sizeof(struct _raid_device));
756 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
760 * mpt2sas_scsih_expander_find_by_handle - expander device search
761 * @ioc: per adapter object
762 * @handle: expander handle (assigned by firmware)
763 * Context: Calling function should acquire ioc->sas_device_lock
765 * This searches for expander device based on handle, then returns the
769 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
771 struct _sas_node *sas_expander, *r;
774 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
775 if (sas_expander->handle != handle)
785 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
786 * @ioc: per adapter object
787 * @sas_address: sas address
788 * Context: Calling function should acquire ioc->sas_node_lock.
790 * This searches for expander device based on sas_address, then returns the
794 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
797 struct _sas_node *sas_expander, *r;
800 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
801 if (sas_expander->sas_address != sas_address)
811 * _scsih_expander_node_add - insert expander device to the list.
812 * @ioc: per adapter object
813 * @sas_expander: the sas_device object
814 * Context: This function will acquire ioc->sas_node_lock.
816 * Adding new object to the ioc->sas_expander_list.
821 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
822 struct _sas_node *sas_expander)
826 spin_lock_irqsave(&ioc->sas_node_lock, flags);
827 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
828 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
832 * _scsih_is_end_device - determines if device is an end device
833 * @device_info: bitfield providing information about the device.
836 * Returns 1 if end device.
839 _scsih_is_end_device(u32 device_info)
841 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
842 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
843 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
844 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
851 * _scsih_scsi_lookup_get - returns scmd entry
852 * @ioc: per adapter object
853 * @smid: system request message index
855 * Returns the smid stored scmd pointer.
857 static struct scsi_cmnd *
858 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
860 return ioc->scsi_lookup[smid - 1].scmd;
864 * _scsih_scsi_lookup_get_clear - returns scmd entry
865 * @ioc: per adapter object
866 * @smid: system request message index
868 * Returns the smid stored scmd pointer.
869 * Then will derefrence the stored scmd pointer.
871 static inline struct scsi_cmnd *
872 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
875 struct scsi_cmnd *scmd;
877 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
878 scmd = ioc->scsi_lookup[smid - 1].scmd;
879 ioc->scsi_lookup[smid - 1].scmd = NULL;
880 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
886 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
887 * @ioc: per adapter object
888 * @smid: system request message index
889 * @scmd: pointer to scsi command object
890 * Context: This function will acquire ioc->scsi_lookup_lock.
892 * This will search for a scmd pointer in the scsi_lookup array,
893 * returning the revelent smid. A returned value of zero means invalid.
896 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
903 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
905 for (i = 0; i < ioc->scsiio_depth; i++) {
906 if (ioc->scsi_lookup[i].scmd == scmd) {
907 smid = ioc->scsi_lookup[i].smid;
912 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
917 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
918 * @ioc: per adapter object
921 * Context: This function will acquire ioc->scsi_lookup_lock.
923 * This will search for a matching channel:id in the scsi_lookup array,
924 * returning 1 if found.
927 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
934 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
936 for (i = 0 ; i < ioc->scsiio_depth; i++) {
937 if (ioc->scsi_lookup[i].scmd &&
938 (ioc->scsi_lookup[i].scmd->device->id == id &&
939 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
945 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
950 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
951 * @ioc: per adapter object
955 * Context: This function will acquire ioc->scsi_lookup_lock.
957 * This will search for a matching channel:id:lun in the scsi_lookup array,
958 * returning 1 if found.
961 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
962 unsigned int lun, int channel)
968 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
970 for (i = 0 ; i < ioc->scsiio_depth; i++) {
971 if (ioc->scsi_lookup[i].scmd &&
972 (ioc->scsi_lookup[i].scmd->device->id == id &&
973 ioc->scsi_lookup[i].scmd->device->channel == channel &&
974 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
980 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
985 * _scsih_get_chain_buffer_tracker - obtain chain tracker
986 * @ioc: per adapter object
987 * @smid: smid associated to an IO request
989 * Returns chain tracker(from ioc->free_chain_list)
991 static struct chain_tracker *
992 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
994 struct chain_tracker *chain_req;
997 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
998 if (list_empty(&ioc->free_chain_list)) {
999 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1000 printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
1004 chain_req = list_entry(ioc->free_chain_list.next,
1005 struct chain_tracker, tracker_list);
1006 list_del_init(&chain_req->tracker_list);
1007 list_add_tail(&chain_req->tracker_list,
1008 &ioc->scsi_lookup[smid - 1].chain_list);
1009 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1014 * _scsih_build_scatter_gather - main sg creation routine
1015 * @ioc: per adapter object
1016 * @scmd: scsi command
1017 * @smid: system request message index
1020 * The main routine that builds scatter gather table from a given
1021 * scsi request sent via the .queuecommand main handler.
1023 * Returns 0 success, anything else error
1026 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1027 struct scsi_cmnd *scmd, u16 smid)
1029 Mpi2SCSIIORequest_t *mpi_request;
1030 dma_addr_t chain_dma;
1031 struct scatterlist *sg_scmd;
1032 void *sg_local, *chain;
1037 u32 sges_in_segment;
1039 u32 sgl_flags_last_element;
1040 u32 sgl_flags_end_buffer;
1041 struct chain_tracker *chain_req;
1043 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1045 /* init scatter gather flags */
1046 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1047 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1048 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1049 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1050 << MPI2_SGE_FLAGS_SHIFT;
1051 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1052 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1053 << MPI2_SGE_FLAGS_SHIFT;
1054 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1056 sg_scmd = scsi_sglist(scmd);
1057 sges_left = scsi_dma_map(scmd);
1058 if (sges_left < 0) {
1059 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1060 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1064 sg_local = &mpi_request->SGL;
1065 sges_in_segment = ioc->max_sges_in_main_message;
1066 if (sges_left <= sges_in_segment)
1067 goto fill_in_last_segment;
1069 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1070 (sges_in_segment * ioc->sge_size))/4;
1072 /* fill in main message segment when there is a chain following */
1073 while (sges_in_segment) {
1074 if (sges_in_segment == 1)
1075 ioc->base_add_sg_single(sg_local,
1076 sgl_flags_last_element | sg_dma_len(sg_scmd),
1077 sg_dma_address(sg_scmd));
1079 ioc->base_add_sg_single(sg_local, sgl_flags |
1080 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1081 sg_scmd = sg_next(sg_scmd);
1082 sg_local += ioc->sge_size;
1087 /* initializing the chain flags and pointers */
1088 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1089 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1092 chain = chain_req->chain_buffer;
1093 chain_dma = chain_req->chain_buffer_dma;
1095 sges_in_segment = (sges_left <=
1096 ioc->max_sges_in_chain_message) ? sges_left :
1097 ioc->max_sges_in_chain_message;
1098 chain_offset = (sges_left == sges_in_segment) ?
1099 0 : (sges_in_segment * ioc->sge_size)/4;
1100 chain_length = sges_in_segment * ioc->sge_size;
1102 chain_offset = chain_offset <<
1103 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1104 chain_length += ioc->sge_size;
1106 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1107 chain_length, chain_dma);
1110 goto fill_in_last_segment;
1112 /* fill in chain segments */
1113 while (sges_in_segment) {
1114 if (sges_in_segment == 1)
1115 ioc->base_add_sg_single(sg_local,
1116 sgl_flags_last_element |
1117 sg_dma_len(sg_scmd),
1118 sg_dma_address(sg_scmd));
1120 ioc->base_add_sg_single(sg_local, sgl_flags |
1121 sg_dma_len(sg_scmd),
1122 sg_dma_address(sg_scmd));
1123 sg_scmd = sg_next(sg_scmd);
1124 sg_local += ioc->sge_size;
1129 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1132 chain = chain_req->chain_buffer;
1133 chain_dma = chain_req->chain_buffer_dma;
1137 fill_in_last_segment:
1139 /* fill the last segment */
1142 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1143 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1145 ioc->base_add_sg_single(sg_local, sgl_flags |
1146 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1147 sg_scmd = sg_next(sg_scmd);
1148 sg_local += ioc->sge_size;
1156 * _scsih_adjust_queue_depth - setting device queue depth
1157 * @sdev: scsi device struct
1158 * @qdepth: requested queue depth
1164 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1166 struct Scsi_Host *shost = sdev->host;
1168 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1169 struct MPT2SAS_DEVICE *sas_device_priv_data;
1170 struct MPT2SAS_TARGET *sas_target_priv_data;
1171 struct _sas_device *sas_device;
1172 unsigned long flags;
1174 max_depth = shost->can_queue;
1176 /* limit max device queue for SATA to 32 */
1177 sas_device_priv_data = sdev->hostdata;
1178 if (!sas_device_priv_data)
1180 sas_target_priv_data = sas_device_priv_data->sas_target;
1181 if (!sas_target_priv_data)
1183 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1185 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1186 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1187 sas_device_priv_data->sas_target->sas_address);
1188 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1189 if (sas_device && sas_device->device_info &
1190 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1191 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1195 if (!sdev->tagged_supported)
1197 if (qdepth > max_depth)
1199 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1203 * _scsih_change_queue_depth - setting device queue depth
1204 * @sdev: scsi device struct
1205 * @qdepth: requested queue depth
1206 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1207 * (see include/scsi/scsi_host.h for definition)
1209 * Returns queue depth.
1212 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1214 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1215 _scsih_adjust_queue_depth(sdev, qdepth);
1216 else if (reason == SCSI_QDEPTH_QFULL)
1217 scsi_track_queue_full(sdev, qdepth);
1221 if (sdev->inquiry_len > 7)
1222 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1223 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1224 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1225 sdev->ordered_tags, sdev->scsi_level,
1226 (sdev->inquiry[7] & 2) >> 1);
1228 return sdev->queue_depth;
1232 * _scsih_change_queue_type - changing device queue tag type
1233 * @sdev: scsi device struct
1234 * @tag_type: requested tag type
1236 * Returns queue tag type.
1239 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1241 if (sdev->tagged_supported) {
1242 scsi_set_tag_type(sdev, tag_type);
1244 scsi_activate_tcq(sdev, sdev->queue_depth);
1246 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1254 * _scsih_target_alloc - target add routine
1255 * @starget: scsi target struct
1257 * Returns 0 if ok. Any other return is assumed to be an error and
1258 * the device is ignored.
1261 _scsih_target_alloc(struct scsi_target *starget)
1263 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1264 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1265 struct MPT2SAS_TARGET *sas_target_priv_data;
1266 struct _sas_device *sas_device;
1267 struct _raid_device *raid_device;
1268 unsigned long flags;
1269 struct sas_rphy *rphy;
1271 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1272 if (!sas_target_priv_data)
1275 starget->hostdata = sas_target_priv_data;
1276 sas_target_priv_data->starget = starget;
1277 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1280 if (starget->channel == RAID_CHANNEL) {
1281 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1282 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1285 sas_target_priv_data->handle = raid_device->handle;
1286 sas_target_priv_data->sas_address = raid_device->wwid;
1287 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1288 sas_target_priv_data->raid_device = raid_device;
1289 raid_device->starget = starget;
1291 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1295 /* sas/sata devices */
1296 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1297 rphy = dev_to_rphy(starget->dev.parent);
1298 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1299 rphy->identify.sas_address);
1302 sas_target_priv_data->handle = sas_device->handle;
1303 sas_target_priv_data->sas_address = sas_device->sas_address;
1304 sas_device->starget = starget;
1305 sas_device->id = starget->id;
1306 sas_device->channel = starget->channel;
1307 if (test_bit(sas_device->handle, ioc->pd_handles))
1308 sas_target_priv_data->flags |=
1309 MPT_TARGET_FLAGS_RAID_COMPONENT;
1311 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1317 * _scsih_target_destroy - target destroy routine
1318 * @starget: scsi target struct
1323 _scsih_target_destroy(struct scsi_target *starget)
1325 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1326 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1327 struct MPT2SAS_TARGET *sas_target_priv_data;
1328 struct _sas_device *sas_device;
1329 struct _raid_device *raid_device;
1330 unsigned long flags;
1331 struct sas_rphy *rphy;
1333 sas_target_priv_data = starget->hostdata;
1334 if (!sas_target_priv_data)
1337 if (starget->channel == RAID_CHANNEL) {
1338 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1339 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1342 raid_device->starget = NULL;
1343 raid_device->sdev = NULL;
1345 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1349 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1350 rphy = dev_to_rphy(starget->dev.parent);
1351 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1352 rphy->identify.sas_address);
1353 if (sas_device && (sas_device->starget == starget) &&
1354 (sas_device->id == starget->id) &&
1355 (sas_device->channel == starget->channel))
1356 sas_device->starget = NULL;
1358 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1361 kfree(sas_target_priv_data);
1362 starget->hostdata = NULL;
1366 * _scsih_slave_alloc - device add routine
1367 * @sdev: scsi device struct
1369 * Returns 0 if ok. Any other return is assumed to be an error and
1370 * the device is ignored.
1373 _scsih_slave_alloc(struct scsi_device *sdev)
1375 struct Scsi_Host *shost;
1376 struct MPT2SAS_ADAPTER *ioc;
1377 struct MPT2SAS_TARGET *sas_target_priv_data;
1378 struct MPT2SAS_DEVICE *sas_device_priv_data;
1379 struct scsi_target *starget;
1380 struct _raid_device *raid_device;
1381 unsigned long flags;
1383 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1384 if (!sas_device_priv_data)
1387 sas_device_priv_data->lun = sdev->lun;
1388 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1390 starget = scsi_target(sdev);
1391 sas_target_priv_data = starget->hostdata;
1392 sas_target_priv_data->num_luns++;
1393 sas_device_priv_data->sas_target = sas_target_priv_data;
1394 sdev->hostdata = sas_device_priv_data;
1395 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1396 sdev->no_uld_attach = 1;
1398 shost = dev_to_shost(&starget->dev);
1399 ioc = shost_priv(shost);
1400 if (starget->channel == RAID_CHANNEL) {
1401 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1402 raid_device = _scsih_raid_device_find_by_id(ioc,
1403 starget->id, starget->channel);
1405 raid_device->sdev = sdev; /* raid is single lun */
1406 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1413 * _scsih_slave_destroy - device destroy routine
1414 * @sdev: scsi device struct
1419 _scsih_slave_destroy(struct scsi_device *sdev)
1421 struct MPT2SAS_TARGET *sas_target_priv_data;
1422 struct scsi_target *starget;
1424 if (!sdev->hostdata)
1427 starget = scsi_target(sdev);
1428 sas_target_priv_data = starget->hostdata;
1429 sas_target_priv_data->num_luns--;
1430 kfree(sdev->hostdata);
1431 sdev->hostdata = NULL;
1435 * _scsih_display_sata_capabilities - sata capabilities
1436 * @ioc: per adapter object
1437 * @sas_device: the sas_device object
1438 * @sdev: scsi device struct
1441 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1442 struct _sas_device *sas_device, struct scsi_device *sdev)
1444 Mpi2ConfigReply_t mpi_reply;
1445 Mpi2SasDevicePage0_t sas_device_pg0;
1450 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1451 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1452 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1453 ioc->name, __FILE__, __LINE__, __func__);
1457 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1458 MPI2_IOCSTATUS_MASK;
1459 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1461 ioc->name, __FILE__, __LINE__, __func__);
1465 flags = le16_to_cpu(sas_device_pg0.Flags);
1466 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1468 sdev_printk(KERN_INFO, sdev,
1469 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1470 "sw_preserve(%s)\n",
1471 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1472 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1473 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1475 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1476 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1477 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1481 * _scsih_is_raid - return boolean indicating device is raid volume
1482 * @dev the device struct object
1485 _scsih_is_raid(struct device *dev)
1487 struct scsi_device *sdev = to_scsi_device(dev);
1488 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1490 if (ioc->is_warpdrive)
1492 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1496 * _scsih_get_resync - get raid volume resync percent complete
1497 * @dev the device struct object
1500 _scsih_get_resync(struct device *dev)
1502 struct scsi_device *sdev = to_scsi_device(dev);
1503 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1504 static struct _raid_device *raid_device;
1505 unsigned long flags;
1506 Mpi2RaidVolPage0_t vol_pg0;
1507 Mpi2ConfigReply_t mpi_reply;
1508 u32 volume_status_flags;
1509 u8 percent_complete = 0;
1511 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1512 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1514 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1516 if (!raid_device || ioc->is_warpdrive)
1519 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1520 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1521 sizeof(Mpi2RaidVolPage0_t))) {
1522 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1523 ioc->name, __FILE__, __LINE__, __func__);
1527 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1528 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1529 percent_complete = raid_device->percent_complete;
1531 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1535 * _scsih_get_state - get raid volume level
1536 * @dev the device struct object
1539 _scsih_get_state(struct device *dev)
1541 struct scsi_device *sdev = to_scsi_device(dev);
1542 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1543 static struct _raid_device *raid_device;
1544 unsigned long flags;
1545 Mpi2RaidVolPage0_t vol_pg0;
1546 Mpi2ConfigReply_t mpi_reply;
1548 enum raid_state state = RAID_STATE_UNKNOWN;
1550 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1551 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1553 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1558 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1559 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1560 sizeof(Mpi2RaidVolPage0_t))) {
1561 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1562 ioc->name, __FILE__, __LINE__, __func__);
1566 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1567 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1568 state = RAID_STATE_RESYNCING;
1572 switch (vol_pg0.VolumeState) {
1573 case MPI2_RAID_VOL_STATE_OPTIMAL:
1574 case MPI2_RAID_VOL_STATE_ONLINE:
1575 state = RAID_STATE_ACTIVE;
1577 case MPI2_RAID_VOL_STATE_DEGRADED:
1578 state = RAID_STATE_DEGRADED;
1580 case MPI2_RAID_VOL_STATE_FAILED:
1581 case MPI2_RAID_VOL_STATE_MISSING:
1582 state = RAID_STATE_OFFLINE;
1586 raid_set_state(mpt2sas_raid_template, dev, state);
1590 * _scsih_set_level - set raid level
1591 * @sdev: scsi device struct
1592 * @raid_device: raid_device object
1595 _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1597 enum raid_level level = RAID_LEVEL_UNKNOWN;
1599 switch (raid_device->volume_type) {
1600 case MPI2_RAID_VOL_TYPE_RAID0:
1601 level = RAID_LEVEL_0;
1603 case MPI2_RAID_VOL_TYPE_RAID10:
1604 level = RAID_LEVEL_10;
1606 case MPI2_RAID_VOL_TYPE_RAID1E:
1607 level = RAID_LEVEL_1E;
1609 case MPI2_RAID_VOL_TYPE_RAID1:
1610 level = RAID_LEVEL_1;
1614 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1618 * _scsih_get_volume_capabilities - volume capabilities
1619 * @ioc: per adapter object
1620 * @sas_device: the raid_device object
1623 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1624 struct _raid_device *raid_device)
1626 Mpi2RaidVolPage0_t *vol_pg0;
1627 Mpi2RaidPhysDiskPage0_t pd_pg0;
1628 Mpi2SasDevicePage0_t sas_device_pg0;
1629 Mpi2ConfigReply_t mpi_reply;
1633 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1634 &num_pds)) || !num_pds) {
1635 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1636 ioc->name, __FILE__, __LINE__, __func__);
1640 raid_device->num_pds = num_pds;
1641 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1642 sizeof(Mpi2RaidVol0PhysDisk_t));
1643 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1645 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1646 ioc->name, __FILE__, __LINE__, __func__);
1650 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1651 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1652 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1653 ioc->name, __FILE__, __LINE__, __func__);
1658 raid_device->volume_type = vol_pg0->VolumeType;
1660 /* figure out what the underlying devices are by
1661 * obtaining the device_info bits for the 1st device
1663 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1664 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1665 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1666 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1667 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1668 le16_to_cpu(pd_pg0.DevHandle)))) {
1669 raid_device->device_info =
1670 le32_to_cpu(sas_device_pg0.DeviceInfo);
1677 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1678 * @ioc: per adapter object
1681 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1683 Mpi2RaidVolPage1_t vol_pg1;
1684 Mpi2ConfigReply_t mpi_reply;
1685 struct _raid_device *raid_device;
1690 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1691 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1692 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1693 MPI2_IOCSTATUS_MASK;
1694 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1696 handle = le16_to_cpu(vol_pg1.DevHandle);
1697 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1699 raid_device->direct_io_enabled = 0;
1706 * _scsih_get_num_volumes - Get number of volumes in the ioc
1707 * @ioc: per adapter object
1710 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1712 Mpi2RaidVolPage1_t vol_pg1;
1713 Mpi2ConfigReply_t mpi_reply;
1719 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1720 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1721 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1722 MPI2_IOCSTATUS_MASK;
1723 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1726 handle = le16_to_cpu(vol_pg1.DevHandle);
1733 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1734 * @ioc: per adapter object
1735 * @raid_device: the raid_device object
1738 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1739 struct _raid_device *raid_device)
1741 Mpi2RaidVolPage0_t *vol_pg0;
1742 Mpi2RaidPhysDiskPage0_t pd_pg0;
1743 Mpi2ConfigReply_t mpi_reply;
1746 u64 mb = 1024 * 1024;
1747 u64 tb_2 = 2 * mb * mb;
1752 if (!ioc->is_warpdrive)
1755 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1756 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1757 "globally as drives are exposed\n", ioc->name);
1760 if (_scsih_get_num_volumes(ioc) > 1) {
1761 _scsih_disable_ddio(ioc);
1762 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1763 "globally as number of drives > 1\n", ioc->name);
1766 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1767 &num_pds)) || !num_pds) {
1768 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1769 "Failure in computing number of drives\n", ioc->name);
1773 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1774 sizeof(Mpi2RaidVol0PhysDisk_t));
1775 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1777 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1778 "Memory allocation failure for RVPG0\n", ioc->name);
1782 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1783 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1784 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1785 "Failure in retrieving RVPG0\n", ioc->name);
1791 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1792 * assumed for WARPDRIVE, disable direct I/O
1794 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1795 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1796 "for the drive with handle(0x%04x): num_mem=%d, "
1797 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1798 num_pds, MPT_MAX_WARPDRIVE_PDS);
1802 for (count = 0; count < num_pds; count++) {
1803 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1804 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1805 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1806 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1807 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1808 "disabled for the drive with handle(0x%04x) member"
1809 "handle retrieval failed for member number=%d\n",
1810 ioc->name, raid_device->handle,
1811 vol_pg0->PhysDisk[count].PhysDiskNum);
1814 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1818 * Assumption for WD: Direct I/O is not supported if the volume is
1819 * not RAID0, if the stripe size is not 64KB, if the block size is
1820 * not 512 and if the volume size is >2TB
1822 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1823 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1824 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1825 "for the drive with handle(0x%04x): type=%d, "
1826 "s_sz=%uK, blk_size=%u\n", ioc->name,
1827 raid_device->handle, raid_device->volume_type,
1828 le32_to_cpu(vol_pg0->StripeSize)/2,
1829 le16_to_cpu(vol_pg0->BlockSize));
1833 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1834 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1836 if (capacity > tb_2) {
1837 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1838 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1839 ioc->name, raid_device->handle);
1843 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1845 for (i = 0; i < 32; i++) {
1852 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1853 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1854 ioc->name, raid_device->handle,
1855 le32_to_cpu(vol_pg0->StripeSize)/2);
1858 raid_device->stripe_exponent = stripe_exp;
1859 raid_device->direct_io_enabled = 1;
1861 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1862 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1864 * WARPDRIVE: Though the following fields are not used for direct IO,
1865 * stored for future purpose:
1867 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1868 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1869 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1876 raid_device->direct_io_enabled = 0;
1877 for (count = 0; count < num_pds; count++)
1878 raid_device->pd_handle[count] = 0;
1884 * _scsih_enable_tlr - setting TLR flags
1885 * @ioc: per adapter object
1886 * @sdev: scsi device struct
1888 * Enabling Transaction Layer Retries for tape devices when
1889 * vpd page 0x90 is present
1893 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1896 if (sdev->type != TYPE_TAPE)
1899 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1902 sas_enable_tlr(sdev);
1903 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1904 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1910 * _scsih_slave_configure - device configure routine.
1911 * @sdev: scsi device struct
1913 * Returns 0 if ok. Any other return is assumed to be an error and
1914 * the device is ignored.
1917 _scsih_slave_configure(struct scsi_device *sdev)
1919 struct Scsi_Host *shost = sdev->host;
1920 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1921 struct MPT2SAS_DEVICE *sas_device_priv_data;
1922 struct MPT2SAS_TARGET *sas_target_priv_data;
1923 struct _sas_device *sas_device;
1924 struct _raid_device *raid_device;
1925 unsigned long flags;
1932 sas_device_priv_data = sdev->hostdata;
1933 sas_device_priv_data->configured_lun = 1;
1934 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1935 sas_target_priv_data = sas_device_priv_data->sas_target;
1937 /* raid volume handling */
1938 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1940 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1941 raid_device = _scsih_raid_device_find_by_handle(ioc,
1942 sas_target_priv_data->handle);
1943 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1945 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1946 ioc->name, __FILE__, __LINE__, __func__);
1950 _scsih_get_volume_capabilities(ioc, raid_device);
1953 * WARPDRIVE: Initialize the required data for Direct IO
1955 _scsih_init_warpdrive_properties(ioc, raid_device);
1957 /* RAID Queue Depth Support
1958 * IS volume = underlying qdepth of drive type, either
1959 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1960 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1962 if (raid_device->device_info &
1963 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1964 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1967 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1968 if (raid_device->device_info &
1969 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1975 switch (raid_device->volume_type) {
1976 case MPI2_RAID_VOL_TYPE_RAID0:
1979 case MPI2_RAID_VOL_TYPE_RAID1E:
1980 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1981 if (ioc->manu_pg10.OEMIdentifier &&
1982 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
1983 MFG10_GF0_R10_DISPLAY) &&
1984 !(raid_device->num_pds % 2))
1989 case MPI2_RAID_VOL_TYPE_RAID1:
1990 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1993 case MPI2_RAID_VOL_TYPE_RAID10:
1994 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1997 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1999 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2004 if (!ioc->hide_ir_msg)
2005 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2006 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2007 r_level, raid_device->handle,
2008 (unsigned long long)raid_device->wwid,
2009 raid_device->num_pds, ds);
2010 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2011 /* raid transport support */
2012 if (!ioc->is_warpdrive)
2013 _scsih_set_level(sdev, raid_device);
2017 /* non-raid handling */
2018 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2019 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2020 sas_device_priv_data->sas_target->sas_address);
2021 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2023 if (sas_target_priv_data->flags &
2024 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2025 mpt2sas_config_get_volume_handle(ioc,
2026 sas_device->handle, &sas_device->volume_handle);
2027 mpt2sas_config_get_volume_wwid(ioc,
2028 sas_device->volume_handle,
2029 &sas_device->volume_wwid);
2031 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2032 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2036 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2037 if (sas_device->device_info &
2038 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2040 else if (sas_device->device_info &
2041 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2045 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2046 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2047 ds, sas_device->handle,
2048 (unsigned long long)sas_device->sas_address,
2050 (unsigned long long)sas_device->device_name);
2051 sdev_printk(KERN_INFO, sdev, "%s: "
2052 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2053 (unsigned long long) sas_device->enclosure_logical_id,
2057 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
2060 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
2063 sas_read_port_mode_page(sdev);
2064 _scsih_enable_tlr(ioc, sdev);
2070 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2071 * @sdev: scsi device struct
2072 * @bdev: pointer to block device context
2073 * @capacity: device size (in 512 byte sectors)
2074 * @params: three element array to place output:
2075 * params[0] number of heads (max 255)
2076 * params[1] number of sectors (max 63)
2077 * params[2] number of cylinders
2082 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2083 sector_t capacity, int params[])
2093 dummy = heads * sectors;
2094 cylinders = capacity;
2095 sector_div(cylinders, dummy);
2098 * Handle extended translation size for logical drives
2101 if ((ulong)capacity >= 0x200000) {
2104 dummy = heads * sectors;
2105 cylinders = capacity;
2106 sector_div(cylinders, dummy);
2111 params[1] = sectors;
2112 params[2] = cylinders;
2118 * _scsih_response_code - translation of device response code
2119 * @ioc: per adapter object
2120 * @response_code: response code returned by the device
2125 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2129 switch (response_code) {
2130 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2131 desc = "task management request completed";
2133 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2134 desc = "invalid frame";
2136 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2137 desc = "task management request not supported";
2139 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2140 desc = "task management request failed";
2142 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2143 desc = "task management request succeeded";
2145 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2146 desc = "invalid lun";
2149 desc = "overlapped tag attempted";
2151 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2152 desc = "task queued, however not sent to target";
2158 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2159 ioc->name, response_code, desc);
2163 * _scsih_tm_done - tm completion routine
2164 * @ioc: per adapter object
2165 * @smid: system request message index
2166 * @msix_index: MSIX table index supplied by the OS
2167 * @reply: reply message frame(lower 32bit addr)
2170 * The callback handler when using scsih_issue_tm.
2172 * Return 1 meaning mf should be freed from _base_interrupt
2173 * 0 means the mf is freed from this function.
2176 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2178 MPI2DefaultReply_t *mpi_reply;
2180 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2182 if (ioc->tm_cmds.smid != smid)
2184 mpt2sas_base_flush_reply_queues(ioc);
2185 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2186 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2188 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2189 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2191 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2192 complete(&ioc->tm_cmds.done);
2197 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2198 * @ioc: per adapter object
2199 * @handle: device handle
2201 * During taskmangement request, we need to freeze the device queue.
2204 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2206 struct MPT2SAS_DEVICE *sas_device_priv_data;
2207 struct scsi_device *sdev;
2210 shost_for_each_device(sdev, ioc->shost) {
2213 sas_device_priv_data = sdev->hostdata;
2214 if (!sas_device_priv_data)
2216 if (sas_device_priv_data->sas_target->handle == handle) {
2217 sas_device_priv_data->sas_target->tm_busy = 1;
2219 ioc->ignore_loginfos = 1;
2225 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2226 * @ioc: per adapter object
2227 * @handle: device handle
2229 * During taskmangement request, we need to freeze the device queue.
2232 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2234 struct MPT2SAS_DEVICE *sas_device_priv_data;
2235 struct scsi_device *sdev;
2238 shost_for_each_device(sdev, ioc->shost) {
2241 sas_device_priv_data = sdev->hostdata;
2242 if (!sas_device_priv_data)
2244 if (sas_device_priv_data->sas_target->handle == handle) {
2245 sas_device_priv_data->sas_target->tm_busy = 0;
2247 ioc->ignore_loginfos = 0;
2254 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2255 * @ioc: per adapter struct
2256 * @device_handle: device handle
2257 * @channel: the channel assigned by the OS
2258 * @id: the id assigned by the OS
2260 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2261 * @smid_task: smid assigned to the task
2262 * @timeout: timeout in seconds
2263 * @serial_number: the serial_number from scmd
2264 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2267 * A generic API for sending task management requests to firmware.
2269 * The callback index is set inside `ioc->tm_cb_idx`.
2271 * Return SUCCESS or FAILED.
2274 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2275 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2276 unsigned long serial_number, enum mutex_type m_type)
2278 Mpi2SCSITaskManagementRequest_t *mpi_request;
2279 Mpi2SCSITaskManagementReply_t *mpi_reply;
2282 unsigned long timeleft;
2283 struct scsiio_tracker *scsi_lookup = NULL;
2286 if (m_type == TM_MUTEX_ON)
2287 mutex_lock(&ioc->tm_cmds.mutex);
2288 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2289 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2290 __func__, ioc->name);
2295 if (ioc->shost_recovery || ioc->remove_host ||
2296 ioc->pci_error_recovery) {
2297 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2298 __func__, ioc->name);
2303 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2304 if (ioc_state & MPI2_DOORBELL_USED) {
2305 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2306 "active!\n", ioc->name));
2307 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2309 rc = (!rc) ? SUCCESS : FAILED;
2313 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2314 mpt2sas_base_fault_info(ioc, ioc_state &
2315 MPI2_DOORBELL_DATA_MASK);
2316 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2318 rc = (!rc) ? SUCCESS : FAILED;
2322 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2324 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2325 ioc->name, __func__);
2330 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2331 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2333 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2334 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2336 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2337 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2338 ioc->tm_cmds.smid = smid;
2339 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2340 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2341 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2342 mpi_request->DevHandle = cpu_to_le16(handle);
2343 mpi_request->TaskType = type;
2344 mpi_request->TaskMID = cpu_to_le16(smid_task);
2345 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2346 mpt2sas_scsih_set_tm_flag(ioc, handle);
2347 init_completion(&ioc->tm_cmds.done);
2348 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2349 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2350 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2351 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2352 ioc->name, __func__);
2353 _debug_dump_mf(mpi_request,
2354 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2355 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2356 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2358 rc = (!rc) ? SUCCESS : FAILED;
2359 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2360 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2365 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2366 mpi_reply = ioc->tm_cmds.reply;
2367 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2368 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2369 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2370 le32_to_cpu(mpi_reply->IOCLogInfo),
2371 le32_to_cpu(mpi_reply->TerminationCount)));
2372 if (ioc->logging_level & MPT_DEBUG_TM) {
2373 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2374 if (mpi_reply->IOCStatus)
2375 _debug_dump_mf(mpi_request,
2376 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2381 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2383 if (scsi_lookup->scmd == NULL)
2388 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2389 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2395 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2396 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2397 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2402 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2410 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2411 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2412 if (m_type == TM_MUTEX_ON)
2413 mutex_unlock(&ioc->tm_cmds.mutex);
2418 if (m_type == TM_MUTEX_ON)
2419 mutex_unlock(&ioc->tm_cmds.mutex);
2424 * _scsih_tm_display_info - displays info about the device
2425 * @ioc: per adapter struct
2426 * @scmd: pointer to scsi command object
2428 * Called by task management callback handlers.
2431 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2433 struct scsi_target *starget = scmd->device->sdev_target;
2434 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2435 struct _sas_device *sas_device = NULL;
2436 unsigned long flags;
2437 char *device_str = NULL;
2441 if (ioc->hide_ir_msg)
2442 device_str = "WarpDrive";
2444 device_str = "volume";
2446 scsi_print_command(scmd);
2447 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2448 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2449 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2450 device_str, (unsigned long long)priv_target->sas_address);
2452 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2453 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2454 priv_target->sas_address);
2456 if (priv_target->flags &
2457 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2458 starget_printk(KERN_INFO, starget,
2459 "volume handle(0x%04x), "
2460 "volume wwid(0x%016llx)\n",
2461 sas_device->volume_handle,
2462 (unsigned long long)sas_device->volume_wwid);
2464 starget_printk(KERN_INFO, starget,
2465 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2467 (unsigned long long)sas_device->sas_address,
2469 starget_printk(KERN_INFO, starget,
2470 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2471 (unsigned long long)sas_device->enclosure_logical_id,
2474 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2479 * _scsih_abort - eh threads main abort routine
2480 * @scmd: pointer to scsi command object
2482 * Returns SUCCESS if command aborted else FAILED
2485 _scsih_abort(struct scsi_cmnd *scmd)
2487 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2488 struct MPT2SAS_DEVICE *sas_device_priv_data;
2493 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2494 "scmd(%p)\n", scmd);
2495 _scsih_tm_display_info(ioc, scmd);
2497 sas_device_priv_data = scmd->device->hostdata;
2498 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2499 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2500 "scmd(%p)\n", scmd);
2501 scmd->result = DID_NO_CONNECT << 16;
2502 scmd->scsi_done(scmd);
2507 /* search for the command */
2508 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2510 scmd->result = DID_RESET << 16;
2515 /* for hidden raid components and volumes this is not supported */
2516 if (sas_device_priv_data->sas_target->flags &
2517 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2518 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2519 scmd->result = DID_RESET << 16;
2524 mpt2sas_halt_firmware(ioc);
2526 handle = sas_device_priv_data->sas_target->handle;
2527 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2528 scmd->device->id, scmd->device->lun,
2529 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2530 scmd->serial_number, TM_MUTEX_ON);
2533 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2534 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2539 * _scsih_dev_reset - eh threads main device reset routine
2540 * @scmd: pointer to scsi command object
2542 * Returns SUCCESS if command aborted else FAILED
2545 _scsih_dev_reset(struct scsi_cmnd *scmd)
2547 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2548 struct MPT2SAS_DEVICE *sas_device_priv_data;
2549 struct _sas_device *sas_device;
2550 unsigned long flags;
2554 struct scsi_target *starget = scmd->device->sdev_target;
2556 starget_printk(KERN_INFO, starget, "attempting device reset! "
2557 "scmd(%p)\n", scmd);
2558 _scsih_tm_display_info(ioc, scmd);
2560 sas_device_priv_data = scmd->device->hostdata;
2561 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2562 starget_printk(KERN_INFO, starget, "device been deleted! "
2563 "scmd(%p)\n", scmd);
2564 scmd->result = DID_NO_CONNECT << 16;
2565 scmd->scsi_done(scmd);
2570 /* for hidden raid components obtain the volume_handle */
2572 if (sas_device_priv_data->sas_target->flags &
2573 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2574 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2575 sas_device = _scsih_sas_device_find_by_handle(ioc,
2576 sas_device_priv_data->sas_target->handle);
2578 handle = sas_device->volume_handle;
2579 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2581 handle = sas_device_priv_data->sas_target->handle;
2584 scmd->result = DID_RESET << 16;
2589 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2590 scmd->device->id, scmd->device->lun,
2591 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2595 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2596 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2601 * _scsih_target_reset - eh threads main target reset routine
2602 * @scmd: pointer to scsi command object
2604 * Returns SUCCESS if command aborted else FAILED
2607 _scsih_target_reset(struct scsi_cmnd *scmd)
2609 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2610 struct MPT2SAS_DEVICE *sas_device_priv_data;
2611 struct _sas_device *sas_device;
2612 unsigned long flags;
2615 struct scsi_target *starget = scmd->device->sdev_target;
2617 starget_printk(KERN_INFO, starget, "attempting target reset! "
2618 "scmd(%p)\n", scmd);
2619 _scsih_tm_display_info(ioc, scmd);
2621 sas_device_priv_data = scmd->device->hostdata;
2622 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2623 starget_printk(KERN_INFO, starget, "target been deleted! "
2624 "scmd(%p)\n", scmd);
2625 scmd->result = DID_NO_CONNECT << 16;
2626 scmd->scsi_done(scmd);
2631 /* for hidden raid components obtain the volume_handle */
2633 if (sas_device_priv_data->sas_target->flags &
2634 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2635 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2636 sas_device = _scsih_sas_device_find_by_handle(ioc,
2637 sas_device_priv_data->sas_target->handle);
2639 handle = sas_device->volume_handle;
2640 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2642 handle = sas_device_priv_data->sas_target->handle;
2645 scmd->result = DID_RESET << 16;
2650 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2651 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2652 30, 0, TM_MUTEX_ON);
2655 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2656 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2661 * _scsih_host_reset - eh threads main host reset routine
2662 * @scmd: pointer to scsi command object
2664 * Returns SUCCESS if command aborted else FAILED
2667 _scsih_host_reset(struct scsi_cmnd *scmd)
2669 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2672 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2674 scsi_print_command(scmd);
2676 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2678 r = (retval < 0) ? FAILED : SUCCESS;
2679 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2680 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2686 * _scsih_fw_event_add - insert and queue up fw_event
2687 * @ioc: per adapter object
2688 * @fw_event: object describing the event
2689 * Context: This function will acquire ioc->fw_event_lock.
2691 * This adds the firmware event object into link list, then queues it up to
2692 * be processed from user context.
2697 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2699 unsigned long flags;
2701 if (ioc->firmware_event_thread == NULL)
2704 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2705 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2706 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2707 queue_delayed_work(ioc->firmware_event_thread,
2708 &fw_event->delayed_work, 0);
2709 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2713 * _scsih_fw_event_free - delete fw_event
2714 * @ioc: per adapter object
2715 * @fw_event: object describing the event
2716 * Context: This function will acquire ioc->fw_event_lock.
2718 * This removes firmware event object from link list, frees associated memory.
2723 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2726 unsigned long flags;
2728 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2729 list_del(&fw_event->list);
2730 kfree(fw_event->event_data);
2732 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2737 * _scsih_error_recovery_delete_devices - remove devices not responding
2738 * @ioc: per adapter object
2743 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2745 struct fw_event_work *fw_event;
2747 if (ioc->is_driver_loading)
2749 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2750 fw_event->ioc = ioc;
2751 _scsih_fw_event_add(ioc, fw_event);
2755 * mpt2sas_port_enable_complete - port enable completed (fake event)
2756 * @ioc: per adapter object
2761 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2763 struct fw_event_work *fw_event;
2765 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2768 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2769 fw_event->ioc = ioc;
2770 _scsih_fw_event_add(ioc, fw_event);
2774 * _scsih_fw_event_cleanup_queue - cleanup event queue
2775 * @ioc: per adapter object
2777 * Walk the firmware event queue, either killing timers, or waiting
2778 * for outstanding events to complete
2783 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2785 struct fw_event_work *fw_event, *next;
2787 if (list_empty(&ioc->fw_event_list) ||
2788 !ioc->firmware_event_thread || in_interrupt())
2791 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2792 if (cancel_delayed_work(&fw_event->delayed_work)) {
2793 _scsih_fw_event_free(ioc, fw_event);
2796 fw_event->cancel_pending_work = 1;
2801 * _scsih_ublock_io_all_device - unblock every device
2802 * @ioc: per adapter object
2804 * change the device state from block to running
2807 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2809 struct MPT2SAS_DEVICE *sas_device_priv_data;
2810 struct scsi_device *sdev;
2812 shost_for_each_device(sdev, ioc->shost) {
2813 sas_device_priv_data = sdev->hostdata;
2814 if (!sas_device_priv_data)
2816 if (!sas_device_priv_data->block)
2818 sas_device_priv_data->block = 0;
2819 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2821 sas_device_priv_data->sas_target->handle));
2822 scsi_internal_device_unblock(sdev);
2826 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2827 * @ioc: per adapter object
2828 * @handle: device handle
2830 * During device pull we need to appropiately set the sdev state.
2833 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2835 struct MPT2SAS_DEVICE *sas_device_priv_data;
2836 struct scsi_device *sdev;
2838 shost_for_each_device(sdev, ioc->shost) {
2839 sas_device_priv_data = sdev->hostdata;
2840 if (!sas_device_priv_data)
2842 if (!sas_device_priv_data->block)
2844 if (sas_device_priv_data->sas_target->handle == handle) {
2845 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2846 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2847 "handle(0x%04x)\n", ioc->name, handle));
2848 sas_device_priv_data->block = 0;
2849 scsi_internal_device_unblock(sdev);
2855 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2856 * @ioc: per adapter object
2857 * @handle: device handle
2859 * During device pull we need to appropiately set the sdev state.
2862 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2864 struct MPT2SAS_DEVICE *sas_device_priv_data;
2865 struct scsi_device *sdev;
2867 shost_for_each_device(sdev, ioc->shost) {
2868 sas_device_priv_data = sdev->hostdata;
2869 if (!sas_device_priv_data)
2871 if (sas_device_priv_data->block)
2873 sas_device_priv_data->block = 1;
2874 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2876 sas_device_priv_data->sas_target->handle));
2877 scsi_internal_device_block(sdev);
2883 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2884 * @ioc: per adapter object
2885 * @handle: device handle
2887 * During device pull we need to appropiately set the sdev state.
2890 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2892 struct MPT2SAS_DEVICE *sas_device_priv_data;
2893 struct scsi_device *sdev;
2895 shost_for_each_device(sdev, ioc->shost) {
2896 sas_device_priv_data = sdev->hostdata;
2897 if (!sas_device_priv_data)
2899 if (sas_device_priv_data->block)
2901 if (sas_device_priv_data->sas_target->handle == handle) {
2902 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2903 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2904 "handle(0x%04x)\n", ioc->name, handle));
2905 sas_device_priv_data->block = 1;
2906 scsi_internal_device_block(sdev);
2912 * _scsih_block_io_to_children_attached_to_ex
2913 * @ioc: per adapter object
2914 * @sas_expander: the sas_device object
2916 * This routine set sdev state to SDEV_BLOCK for all devices
2917 * attached to this expander. This function called when expander is
2921 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2922 struct _sas_node *sas_expander)
2924 struct _sas_port *mpt2sas_port;
2925 struct _sas_device *sas_device;
2926 struct _sas_node *expander_sibling;
2927 unsigned long flags;
2932 list_for_each_entry(mpt2sas_port,
2933 &sas_expander->sas_port_list, port_list) {
2934 if (mpt2sas_port->remote_identify.device_type ==
2936 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2938 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2939 mpt2sas_port->remote_identify.sas_address);
2940 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2943 _scsih_block_io_device(ioc, sas_device->handle);
2947 list_for_each_entry(mpt2sas_port,
2948 &sas_expander->sas_port_list, port_list) {
2950 if (mpt2sas_port->remote_identify.device_type ==
2951 SAS_EDGE_EXPANDER_DEVICE ||
2952 mpt2sas_port->remote_identify.device_type ==
2953 SAS_FANOUT_EXPANDER_DEVICE) {
2955 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2957 mpt2sas_scsih_expander_find_by_sas_address(
2958 ioc, mpt2sas_port->remote_identify.sas_address);
2959 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2960 _scsih_block_io_to_children_attached_to_ex(ioc,
2967 * _scsih_block_io_to_children_attached_directly
2968 * @ioc: per adapter object
2969 * @event_data: topology change event data
2971 * This routine set sdev state to SDEV_BLOCK for all devices
2972 * direct attached during device pull.
2975 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2976 Mpi2EventDataSasTopologyChangeList_t *event_data)
2983 for (i = 0; i < event_data->NumEntries; i++) {
2984 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2987 phy_number = event_data->StartPhyNum + i;
2988 reason_code = event_data->PHY[i].PhyStatus &
2989 MPI2_EVENT_SAS_TOPO_RC_MASK;
2990 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2991 _scsih_block_io_device(ioc, handle);
2996 * _scsih_tm_tr_send - send task management request
2997 * @ioc: per adapter object
2998 * @handle: device handle
2999 * Context: interrupt time.
3001 * This code is to initiate the device removal handshake protocol
3002 * with controller firmware. This function will issue target reset
3003 * using high priority request queue. It will send a sas iounit
3004 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3006 * This is designed to send muliple task management request at the same
3007 * time to the fifo. If the fifo is full, we will append the request,
3008 * and process it in a future completion.
3011 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3013 Mpi2SCSITaskManagementRequest_t *mpi_request;
3015 struct _sas_device *sas_device;
3016 struct MPT2SAS_TARGET *sas_target_priv_data;
3017 unsigned long flags;
3018 struct _tr_list *delayed_tr;
3020 if (ioc->shost_recovery || ioc->remove_host ||
3021 ioc->pci_error_recovery) {
3022 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3023 "progress!\n", __func__, ioc->name));
3027 /* if PD, then return */
3028 if (test_bit(handle, ioc->pd_handles))
3031 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3032 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3033 if (sas_device && sas_device->starget &&
3034 sas_device->starget->hostdata) {
3035 sas_target_priv_data = sas_device->starget->hostdata;
3036 sas_target_priv_data->deleted = 1;
3037 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3038 "setting delete flag: handle(0x%04x), "
3039 "sas_addr(0x%016llx)\n", ioc->name, handle,
3040 (unsigned long long) sas_device->sas_address));
3042 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3044 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3046 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3049 INIT_LIST_HEAD(&delayed_tr->list);
3050 delayed_tr->handle = handle;
3051 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3052 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3053 "DELAYED:tr:handle(0x%04x), (open)\n",
3054 ioc->name, handle));
3058 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3059 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3060 ioc->tm_tr_cb_idx));
3061 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3062 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3063 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3064 mpi_request->DevHandle = cpu_to_le16(handle);
3065 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3066 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3072 * _scsih_sas_control_complete - completion routine
3073 * @ioc: per adapter object
3074 * @smid: system request message index
3075 * @msix_index: MSIX table index supplied by the OS
3076 * @reply: reply message frame(lower 32bit addr)
3077 * Context: interrupt time.
3079 * This is the sas iounit control completion routine.
3080 * This code is part of the code to initiate the device removal
3081 * handshake protocol with controller firmware.
3083 * Return 1 meaning mf should be freed from _base_interrupt
3084 * 0 means the mf is freed from this function.
3087 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3088 u8 msix_index, u32 reply)
3090 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3091 Mpi2SasIoUnitControlReply_t *mpi_reply =
3092 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3094 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3095 "sc_complete:handle(0x%04x), (open) "
3096 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3097 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3098 le16_to_cpu(mpi_reply->IOCStatus),
3099 le32_to_cpu(mpi_reply->IOCLogInfo)));
3104 * _scsih_tm_tr_volume_send - send target reset request for volumes
3105 * @ioc: per adapter object
3106 * @handle: device handle
3107 * Context: interrupt time.
3109 * This is designed to send muliple task management request at the same
3110 * time to the fifo. If the fifo is full, we will append the request,
3111 * and process it in a future completion.
3114 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3116 Mpi2SCSITaskManagementRequest_t *mpi_request;
3118 struct _tr_list *delayed_tr;
3120 if (ioc->shost_recovery || ioc->remove_host ||
3121 ioc->pci_error_recovery) {
3122 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3123 "progress!\n", __func__, ioc->name));
3127 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3129 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3132 INIT_LIST_HEAD(&delayed_tr->list);
3133 delayed_tr->handle = handle;
3134 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3135 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3136 "DELAYED:tr:handle(0x%04x), (open)\n",
3137 ioc->name, handle));
3141 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3142 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3143 ioc->tm_tr_volume_cb_idx));
3144 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3145 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3146 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3147 mpi_request->DevHandle = cpu_to_le16(handle);
3148 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3149 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3153 * _scsih_tm_volume_tr_complete - target reset completion
3154 * @ioc: per adapter object
3155 * @smid: system request message index
3156 * @msix_index: MSIX table index supplied by the OS
3157 * @reply: reply message frame(lower 32bit addr)
3158 * Context: interrupt time.
3160 * Return 1 meaning mf should be freed from _base_interrupt
3161 * 0 means the mf is freed from this function.
3164 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3165 u8 msix_index, u32 reply)
3168 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3169 Mpi2SCSITaskManagementReply_t *mpi_reply =
3170 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3172 if (ioc->shost_recovery || ioc->remove_host ||
3173 ioc->pci_error_recovery) {
3174 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3175 "progress!\n", __func__, ioc->name));
3179 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3180 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3181 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3182 dewtprintk(ioc, printk("spurious interrupt: "
3183 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3184 le16_to_cpu(mpi_reply->DevHandle), smid));
3188 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3189 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3190 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3191 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3192 le32_to_cpu(mpi_reply->IOCLogInfo),
3193 le32_to_cpu(mpi_reply->TerminationCount)));
3195 return _scsih_check_for_pending_tm(ioc, smid);
3199 * _scsih_tm_tr_complete -
3200 * @ioc: per adapter object
3201 * @smid: system request message index
3202 * @msix_index: MSIX table index supplied by the OS
3203 * @reply: reply message frame(lower 32bit addr)
3204 * Context: interrupt time.
3206 * This is the target reset completion routine.
3207 * This code is part of the code to initiate the device removal
3208 * handshake protocol with controller firmware.
3209 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3211 * Return 1 meaning mf should be freed from _base_interrupt
3212 * 0 means the mf is freed from this function.
3215 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3219 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3220 Mpi2SCSITaskManagementReply_t *mpi_reply =
3221 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3222 Mpi2SasIoUnitControlRequest_t *mpi_request;
3225 if (ioc->shost_recovery || ioc->remove_host ||
3226 ioc->pci_error_recovery) {
3227 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3228 "progress!\n", __func__, ioc->name));
3232 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3233 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3234 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3235 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3236 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3237 le16_to_cpu(mpi_reply->DevHandle), smid));
3241 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3242 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3243 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3244 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3245 le32_to_cpu(mpi_reply->IOCLogInfo),
3246 le32_to_cpu(mpi_reply->TerminationCount)));
3248 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3249 if (!smid_sas_ctrl) {
3250 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3251 ioc->name, __func__);
3255 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3256 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3257 ioc->tm_sas_control_cb_idx));
3258 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3259 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3260 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3261 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3262 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3263 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3265 return _scsih_check_for_pending_tm(ioc, smid);
3269 * _scsih_check_for_pending_tm - check for pending task management
3270 * @ioc: per adapter object
3271 * @smid: system request message index
3273 * This will check delayed target reset list, and feed the
3276 * Return 1 meaning mf should be freed from _base_interrupt
3277 * 0 means the mf is freed from this function.
3280 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3282 struct _tr_list *delayed_tr;
3284 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3285 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3286 struct _tr_list, list);
3287 mpt2sas_base_free_smid(ioc, smid);
3288 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3289 list_del(&delayed_tr->list);
3294 if (!list_empty(&ioc->delayed_tr_list)) {
3295 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3296 struct _tr_list, list);
3297 mpt2sas_base_free_smid(ioc, smid);
3298 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3299 list_del(&delayed_tr->list);
3308 * _scsih_check_topo_delete_events - sanity check on topo events
3309 * @ioc: per adapter object
3310 * @event_data: the event data payload
3312 * This routine added to better handle cable breaker.
3314 * This handles the case where driver receives multiple expander
3315 * add and delete events in a single shot. When there is a delete event
3316 * the routine will void any pending add events waiting in the event queue.
3321 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3322 Mpi2EventDataSasTopologyChangeList_t *event_data)
3324 struct fw_event_work *fw_event;
3325 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3326 u16 expander_handle;
3327 struct _sas_node *sas_expander;
3328 unsigned long flags;
3332 for (i = 0 ; i < event_data->NumEntries; i++) {
3333 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3336 reason_code = event_data->PHY[i].PhyStatus &
3337 MPI2_EVENT_SAS_TOPO_RC_MASK;
3338 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3339 _scsih_tm_tr_send(ioc, handle);
3342 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3343 if (expander_handle < ioc->sas_hba.num_phys) {
3344 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3348 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3349 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3350 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3351 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3353 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3354 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3355 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3356 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3358 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3361 /* mark ignore flag for pending events */
3362 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3363 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3364 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3367 local_event_data = fw_event->event_data;
3368 if (local_event_data->ExpStatus ==
3369 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3370 local_event_data->ExpStatus ==
3371 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3372 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3374 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3375 "setting ignoring flag\n", ioc->name));
3376 fw_event->ignore = 1;
3380 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3384 * _scsih_set_volume_delete_flag - setting volume delete flag
3385 * @ioc: per adapter object
3386 * @handle: device handle
3392 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3394 struct _raid_device *raid_device;
3395 struct MPT2SAS_TARGET *sas_target_priv_data;
3396 unsigned long flags;
3398 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3399 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3400 if (raid_device && raid_device->starget &&
3401 raid_device->starget->hostdata) {
3402 sas_target_priv_data =
3403 raid_device->starget->hostdata;
3404 sas_target_priv_data->deleted = 1;
3405 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3406 "setting delete flag: handle(0x%04x), "
3407 "wwid(0x%016llx)\n", ioc->name, handle,
3408 (unsigned long long) raid_device->wwid));
3410 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3414 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3415 * @handle: input handle
3416 * @a: handle for volume a
3417 * @b: handle for volume b
3419 * IR firmware only supports two raid volumes. The purpose of this
3420 * routine is to set the volume handle in either a or b. When the given
3421 * input handle is non-zero, or when a and b have not been set before.
3424 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3426 if (!handle || handle == *a || handle == *b)
3435 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3436 * @ioc: per adapter object
3437 * @event_data: the event data payload
3438 * Context: interrupt time.
3440 * This routine will send target reset to volume, followed by target
3441 * resets to the PDs. This is called when a PD has been removed, or
3442 * volume has been deleted or removed. When the target reset is sent
3443 * to volume, the PD target resets need to be queued to start upon
3444 * completion of the volume target reset.
3449 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3450 Mpi2EventDataIrConfigChangeList_t *event_data)
3452 Mpi2EventIrConfigElement_t *element;
3454 u16 handle, volume_handle, a, b;
3455 struct _tr_list *delayed_tr;
3460 if (ioc->is_warpdrive)
3463 /* Volume Resets for Deleted or Removed */
3464 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3465 for (i = 0; i < event_data->NumElements; i++, element++) {
3466 if (element->ReasonCode ==
3467 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3468 element->ReasonCode ==
3469 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3470 volume_handle = le16_to_cpu(element->VolDevHandle);
3471 _scsih_set_volume_delete_flag(ioc, volume_handle);
3472 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3476 /* Volume Resets for UNHIDE events */
3477 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3478 for (i = 0; i < event_data->NumElements; i++, element++) {
3479 if (le32_to_cpu(event_data->Flags) &
3480 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3482 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3483 volume_handle = le16_to_cpu(element->VolDevHandle);
3484 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3489 _scsih_tm_tr_volume_send(ioc, a);
3491 _scsih_tm_tr_volume_send(ioc, b);
3493 /* PD target resets */
3494 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3495 for (i = 0; i < event_data->NumElements; i++, element++) {
3496 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3498 handle = le16_to_cpu(element->PhysDiskDevHandle);
3499 volume_handle = le16_to_cpu(element->VolDevHandle);
3500 clear_bit(handle, ioc->pd_handles);
3502 _scsih_tm_tr_send(ioc, handle);
3503 else if (volume_handle == a || volume_handle == b) {
3504 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3505 BUG_ON(!delayed_tr);
3506 INIT_LIST_HEAD(&delayed_tr->list);
3507 delayed_tr->handle = handle;
3508 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3510 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3513 _scsih_tm_tr_send(ioc, handle);
3519 * _scsih_check_volume_delete_events - set delete flag for volumes
3520 * @ioc: per adapter object
3521 * @event_data: the event data payload
3522 * Context: interrupt time.
3524 * This will handle the case when the cable connected to entire volume is
3525 * pulled. We will take care of setting the deleted flag so normal IO will
3531 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3532 Mpi2EventDataIrVolume_t *event_data)
3536 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3538 state = le32_to_cpu(event_data->NewValue);
3539 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3540 MPI2_RAID_VOL_STATE_FAILED)
3541 _scsih_set_volume_delete_flag(ioc,
3542 le16_to_cpu(event_data->VolDevHandle));
3546 * _scsih_flush_running_cmds - completing outstanding commands.
3547 * @ioc: per adapter object
3549 * The flushing out of all pending scmd commands following host reset,
3550 * where all IO is dropped to the floor.
3555 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3557 struct scsi_cmnd *scmd;
3561 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3562 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3566 mpt2sas_base_free_smid(ioc, smid);
3567 scsi_dma_unmap(scmd);
3568 if (ioc->pci_error_recovery)
3569 scmd->result = DID_NO_CONNECT << 16;
3571 scmd->result = DID_RESET << 16;
3572 scmd->scsi_done(scmd);
3574 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3579 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3580 * @scmd: pointer to scsi command object
3581 * @mpi_request: pointer to the SCSI_IO reqest message frame
3583 * Supporting protection 1 and 3.
3588 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3591 unsigned char prot_op = scsi_get_prot_op(scmd);
3592 unsigned char prot_type = scsi_get_prot_type(scmd);
3594 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3597 if (prot_op == SCSI_PROT_READ_STRIP)
3598 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3599 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3600 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3604 switch (prot_type) {
3605 case SCSI_PROT_DIF_TYPE1:
3606 case SCSI_PROT_DIF_TYPE2:
3609 * enable ref/guard checking
3610 * auto increment ref tag
3612 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3613 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3614 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3615 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3616 cpu_to_be32(scsi_get_lba(scmd));
3619 case SCSI_PROT_DIF_TYPE3:
3622 * enable guard checking
3624 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3627 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3628 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3632 * _scsih_eedp_error_handling - return sense code for EEDP errors
3633 * @scmd: pointer to scsi command object
3634 * @ioc_status: ioc status
3639 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3645 switch (ioc_status) {
3646 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3649 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3652 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3660 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3661 sk = ILLEGAL_REQUEST;
3662 host_byte = DID_ABORT;
3664 sk = ABORTED_COMMAND;
3668 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3669 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3670 SAM_STAT_CHECK_CONDITION;
3674 * _scsih_scsi_direct_io_get - returns direct io flag
3675 * @ioc: per adapter object
3676 * @smid: system request message index
3678 * Returns the smid stored scmd pointer.
3681 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3683 return ioc->scsi_lookup[smid - 1].direct_io;
3687 * _scsih_scsi_direct_io_set - sets direct io flag
3688 * @ioc: per adapter object
3689 * @smid: system request message index
3690 * @direct_io: Zero or non-zero value to set in the direct_io flag
3695 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3697 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3702 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3703 * @ioc: per adapter object
3704 * @scmd: pointer to scsi command object
3705 * @raid_device: pointer to raid device data structure
3706 * @mpi_request: pointer to the SCSI_IO reqest message frame
3707 * @smid: system request message index
3712 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3713 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3716 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3717 u32 stripe_sz, stripe_exp;
3718 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3719 u8 cdb0 = scmd->cmnd[0];
3722 * Try Direct I/O to RAID memeber disks
3724 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3725 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3726 cdb_ptr = mpi_request->CDB.CDB32;
3728 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3730 io_size = scsi_bufflen(scmd) >> 9;
3731 /* get virtual lba */
3732 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3734 tmp_ptr = (u8 *)&v_lba + 3;
3735 *tmp_ptr-- = *lba_ptr1++;
3736 *tmp_ptr-- = *lba_ptr1++;
3737 *tmp_ptr-- = *lba_ptr1++;
3738 *tmp_ptr = *lba_ptr1;
3740 if (((u64)v_lba + (u64)io_size - 1) <=
3741 (u32)raid_device->max_lba) {
3742 stripe_sz = raid_device->stripe_sz;
3743 stripe_exp = raid_device->stripe_exponent;
3744 stripe_off = v_lba & (stripe_sz - 1);
3746 /* Check whether IO falls within a stripe */
3747 if ((stripe_off + io_size) <= stripe_sz) {
3748 num_pds = raid_device->num_pds;
3749 p_lba = v_lba >> stripe_exp;
3750 stripe_unit = p_lba / num_pds;
3751 column = p_lba % num_pds;
3752 p_lba = (stripe_unit << stripe_exp) +
3754 mpi_request->DevHandle =
3755 cpu_to_le16(raid_device->
3757 tmp_ptr = (u8 *)&p_lba + 3;
3758 *lba_ptr2++ = *tmp_ptr--;
3759 *lba_ptr2++ = *tmp_ptr--;
3760 *lba_ptr2++ = *tmp_ptr--;
3761 *lba_ptr2 = *tmp_ptr;
3763 * WD: To indicate this I/O is directI/O
3765 _scsih_scsi_direct_io_set(ioc, smid, 1);
3773 * _scsih_qcmd - main scsi request entry point
3774 * @scmd: pointer to scsi command object
3775 * @done: function pointer to be invoked on completion
3777 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3779 * Returns 0 on success. If there's a failure, return either:
3780 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3781 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3784 _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
3786 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3787 struct MPT2SAS_DEVICE *sas_device_priv_data;
3788 struct MPT2SAS_TARGET *sas_target_priv_data;
3789 struct _raid_device *raid_device;
3790 Mpi2SCSIIORequest_t *mpi_request;
3794 scmd->scsi_done = done;
3795 sas_device_priv_data = scmd->device->hostdata;
3796 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3797 scmd->result = DID_NO_CONNECT << 16;
3798 scmd->scsi_done(scmd);
3802 if (ioc->pci_error_recovery || ioc->remove_host) {
3803 scmd->result = DID_NO_CONNECT << 16;
3804 scmd->scsi_done(scmd);
3808 sas_target_priv_data = sas_device_priv_data->sas_target;
3809 /* invalid device handle */
3810 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3811 scmd->result = DID_NO_CONNECT << 16;
3812 scmd->scsi_done(scmd);
3816 /* host recovery or link resets sent via IOCTLs */
3817 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3818 return SCSI_MLQUEUE_HOST_BUSY;
3819 /* device busy with task management */
3820 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3821 return SCSI_MLQUEUE_DEVICE_BUSY;
3822 /* device has been deleted */
3823 else if (sas_target_priv_data->deleted) {
3824 scmd->result = DID_NO_CONNECT << 16;
3825 scmd->scsi_done(scmd);
3829 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3830 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3831 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3832 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3834 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3837 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3838 if (scmd->device->tagged_supported) {
3839 if (scmd->device->ordered_tags)
3840 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3842 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3844 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3845 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3847 mpi_control |= (0x500);
3850 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3851 /* Make sure Device is not raid volume.
3852 * We do not expose raid functionality to upper layer for warpdrive.
3854 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3855 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3856 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3858 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3860 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3861 ioc->name, __func__);
3864 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3865 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3866 _scsih_setup_eedp(scmd, mpi_request);
3867 if (scmd->cmd_len == 32)
3868 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3869 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3870 if (sas_device_priv_data->sas_target->flags &
3871 MPT_TARGET_FLAGS_RAID_COMPONENT)
3872 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3874 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3875 mpi_request->DevHandle =
3876 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3877 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3878 mpi_request->Control = cpu_to_le32(mpi_control);
3879 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3880 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3881 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3882 mpi_request->SenseBufferLowAddress =
3883 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3884 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3885 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3886 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3887 mpi_request->VF_ID = 0; /* TODO */
3888 mpi_request->VP_ID = 0;
3889 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3891 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3893 if (!mpi_request->DataLength) {
3894 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3896 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3897 mpt2sas_base_free_smid(ioc, smid);
3902 raid_device = sas_target_priv_data->raid_device;
3903 if (raid_device && raid_device->direct_io_enabled)
3904 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3907 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3908 mpt2sas_base_put_smid_scsi_io(ioc, smid,
3909 le16_to_cpu(mpi_request->DevHandle));
3911 mpt2sas_base_put_smid_default(ioc, smid);
3915 return SCSI_MLQUEUE_HOST_BUSY;
3918 static DEF_SCSI_QCMD(_scsih_qcmd)
3921 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3922 * @sense_buffer: sense data returned by target
3923 * @data: normalized skey/asc/ascq
3928 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3930 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3931 /* descriptor format */
3932 data->skey = sense_buffer[1] & 0x0F;
3933 data->asc = sense_buffer[2];
3934 data->ascq = sense_buffer[3];
3937 data->skey = sense_buffer[2] & 0x0F;
3938 data->asc = sense_buffer[12];
3939 data->ascq = sense_buffer[13];
3943 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3945 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
3946 * @ioc: per adapter object
3947 * @scmd: pointer to scsi command object
3948 * @mpi_reply: reply mf payload returned from firmware
3950 * scsi_status - SCSI Status code returned from target device
3951 * scsi_state - state info associated with SCSI_IO determined by ioc
3952 * ioc_status - ioc supplied status info
3957 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3958 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3962 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3963 MPI2_IOCSTATUS_MASK;
3964 u8 scsi_state = mpi_reply->SCSIState;
3965 u8 scsi_status = mpi_reply->SCSIStatus;
3966 char *desc_ioc_state = NULL;
3967 char *desc_scsi_status = NULL;
3968 char *desc_scsi_state = ioc->tmp_string;
3969 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3970 struct _sas_device *sas_device = NULL;
3971 unsigned long flags;
3972 struct scsi_target *starget = scmd->device->sdev_target;
3973 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
3974 char *device_str = NULL;
3979 if (ioc->hide_ir_msg)
3980 device_str = "WarpDrive";
3982 device_str = "volume";
3984 if (log_info == 0x31170000)
3987 switch (ioc_status) {
3988 case MPI2_IOCSTATUS_SUCCESS:
3989 desc_ioc_state = "success";
3991 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3992 desc_ioc_state = "invalid function";
3994 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3995 desc_ioc_state = "scsi recovered error";
3997 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3998 desc_ioc_state = "scsi invalid dev handle";
4000 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4001 desc_ioc_state = "scsi device not there";
4003 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4004 desc_ioc_state = "scsi data overrun";
4006 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4007 desc_ioc_state = "scsi data underrun";
4009 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4010 desc_ioc_state = "scsi io data error";
4012 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4013 desc_ioc_state = "scsi protocol error";
4015 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4016 desc_ioc_state = "scsi task terminated";
4018 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4019 desc_ioc_state = "scsi residual mismatch";
4021 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4022 desc_ioc_state = "scsi task mgmt failed";
4024 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4025 desc_ioc_state = "scsi ioc terminated";
4027 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4028 desc_ioc_state = "scsi ext terminated";
4030 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4031 desc_ioc_state = "eedp guard error";
4033 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4034 desc_ioc_state = "eedp ref tag error";
4036 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4037 desc_ioc_state = "eedp app tag error";
4040 desc_ioc_state = "unknown";
4044 switch (scsi_status) {
4045 case MPI2_SCSI_STATUS_GOOD:
4046 desc_scsi_status = "good";
4048 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4049 desc_scsi_status = "check condition";
4051 case MPI2_SCSI_STATUS_CONDITION_MET:
4052 desc_scsi_status = "condition met";
4054 case MPI2_SCSI_STATUS_BUSY:
4055 desc_scsi_status = "busy";
4057 case MPI2_SCSI_STATUS_INTERMEDIATE:
4058 desc_scsi_status = "intermediate";
4060 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4061 desc_scsi_status = "intermediate condmet";
4063 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4064 desc_scsi_status = "reservation conflict";
4066 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4067 desc_scsi_status = "command terminated";
4069 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4070 desc_scsi_status = "task set full";
4072 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4073 desc_scsi_status = "aca active";
4075 case MPI2_SCSI_STATUS_TASK_ABORTED:
4076 desc_scsi_status = "task aborted";
4079 desc_scsi_status = "unknown";
4083 desc_scsi_state[0] = '\0';
4085 desc_scsi_state = " ";
4086 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4087 strcat(desc_scsi_state, "response info ");
4088 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4089 strcat(desc_scsi_state, "state terminated ");
4090 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4091 strcat(desc_scsi_state, "no status ");
4092 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4093 strcat(desc_scsi_state, "autosense failed ");
4094 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4095 strcat(desc_scsi_state, "autosense valid ");
4097 scsi_print_command(scmd);
4099 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4100 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4101 device_str, (unsigned long long)priv_target->sas_address);
4103 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4104 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4105 priv_target->sas_address);
4107 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4108 "phy(%d)\n", ioc->name, sas_device->sas_address,
4110 printk(MPT2SAS_WARN_FMT
4111 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4112 ioc->name, sas_device->enclosure_logical_id,
4115 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4118 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4119 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4120 desc_ioc_state, ioc_status, smid);
4121 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4122 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4123 scsi_get_resid(scmd));
4124 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4125 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4126 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4127 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4128 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4129 scsi_status, desc_scsi_state, scsi_state);
4131 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4132 struct sense_info data;
4133 _scsih_normalize_sense(scmd->sense_buffer, &data);
4134 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4135 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4136 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4139 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4140 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4141 response_bytes = (u8 *)&response_info;
4142 _scsih_response_code(ioc, response_bytes[0]);
4148 * _scsih_turn_on_fault_led - illuminate Fault LED
4149 * @ioc: per adapter object
4150 * @handle: device handle
4156 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4158 Mpi2SepReply_t mpi_reply;
4159 Mpi2SepRequest_t mpi_request;
4161 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4162 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4163 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4164 mpi_request.SlotStatus =
4165 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4166 mpi_request.DevHandle = cpu_to_le16(handle);
4167 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4168 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4169 &mpi_request)) != 0) {
4170 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4171 __FILE__, __LINE__, __func__);
4175 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4176 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4177 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4178 le16_to_cpu(mpi_reply.IOCStatus),
4179 le32_to_cpu(mpi_reply.IOCLogInfo)));
4185 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4186 * @ioc: per adapter object
4187 * @handle: device handle
4188 * Context: interrupt.
4193 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4195 struct fw_event_work *fw_event;
4197 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4200 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4201 fw_event->device_handle = handle;
4202 fw_event->ioc = ioc;
4203 _scsih_fw_event_add(ioc, fw_event);
4207 * _scsih_smart_predicted_fault - process smart errors
4208 * @ioc: per adapter object
4209 * @handle: device handle
4210 * Context: interrupt.
4215 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4217 struct scsi_target *starget;
4218 struct MPT2SAS_TARGET *sas_target_priv_data;
4219 Mpi2EventNotificationReply_t *event_reply;
4220 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4221 struct _sas_device *sas_device;
4223 unsigned long flags;
4225 /* only handle non-raid devices */
4226 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4227 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4229 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4232 starget = sas_device->starget;
4233 sas_target_priv_data = starget->hostdata;
4235 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4236 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4237 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4240 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4241 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4243 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4244 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
4246 /* insert into event log */
4247 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4248 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4249 event_reply = kzalloc(sz, GFP_KERNEL);
4251 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4252 ioc->name, __FILE__, __LINE__, __func__);
4256 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4257 event_reply->Event =
4258 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4259 event_reply->MsgLength = sz/4;
4260 event_reply->EventDataLength =
4261 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4262 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4263 event_reply->EventData;
4264 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4265 event_data->ASC = 0x5D;
4266 event_data->DevHandle = cpu_to_le16(handle);
4267 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4268 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4273 * _scsih_io_done - scsi request callback
4274 * @ioc: per adapter object
4275 * @smid: system request message index
4276 * @msix_index: MSIX table index supplied by the OS
4277 * @reply: reply message frame(lower 32bit addr)
4279 * Callback handler when using _scsih_qcmd.
4281 * Return 1 meaning mf should be freed from _base_interrupt
4282 * 0 means the mf is freed from this function.
4285 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4287 Mpi2SCSIIORequest_t *mpi_request;
4288 Mpi2SCSIIOReply_t *mpi_reply;
4289 struct scsi_cmnd *scmd;
4295 struct MPT2SAS_DEVICE *sas_device_priv_data;
4296 u32 response_code = 0;
4297 unsigned long flags;
4299 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4300 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4304 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4306 if (mpi_reply == NULL) {
4307 scmd->result = DID_OK << 16;
4311 sas_device_priv_data = scmd->device->hostdata;
4312 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4313 sas_device_priv_data->sas_target->deleted) {
4314 scmd->result = DID_NO_CONNECT << 16;
4318 * WARPDRIVE: If direct_io is set then it is directIO,
4319 * the failed direct I/O should be redirected to volume
4321 if (_scsih_scsi_direct_io_get(ioc, smid)) {
4322 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4323 ioc->scsi_lookup[smid - 1].scmd = scmd;
4324 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4325 _scsih_scsi_direct_io_set(ioc, smid, 0);
4326 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4327 mpi_request->DevHandle =
4328 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4329 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4330 sas_device_priv_data->sas_target->handle);
4335 /* turning off TLR */
4336 scsi_state = mpi_reply->SCSIState;
4337 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4339 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4340 if (!sas_device_priv_data->tlr_snoop_check) {
4341 sas_device_priv_data->tlr_snoop_check++;
4342 /* Make sure Device is not raid volume.
4343 * We do not expose raid functionality to upper layer for warpdrive.
4345 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4346 sas_is_tlr_enabled(scmd->device) &&
4347 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4348 sas_disable_tlr(scmd->device);
4349 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4353 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4354 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4355 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4356 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4357 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4360 ioc_status &= MPI2_IOCSTATUS_MASK;
4361 scsi_status = mpi_reply->SCSIStatus;
4363 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4364 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4365 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4366 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4367 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4370 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4371 struct sense_info data;
4372 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4374 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4375 le32_to_cpu(mpi_reply->SenseCount));
4376 memcpy(scmd->sense_buffer, sense_data, sz);
4377 _scsih_normalize_sense(scmd->sense_buffer, &data);
4378 /* failure prediction threshold exceeded */
4379 if (data.asc == 0x5D)
4380 _scsih_smart_predicted_fault(ioc,
4381 le16_to_cpu(mpi_reply->DevHandle));
4384 switch (ioc_status) {
4385 case MPI2_IOCSTATUS_BUSY:
4386 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4387 scmd->result = SAM_STAT_BUSY;
4390 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4391 scmd->result = DID_NO_CONNECT << 16;
4394 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4395 if (sas_device_priv_data->block) {
4396 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4399 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4400 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4401 scmd->result = DID_RESET << 16;
4404 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4405 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4406 scmd->result = DID_SOFT_ERROR << 16;
4408 scmd->result = (DID_OK << 16) | scsi_status;
4411 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4412 scmd->result = (DID_OK << 16) | scsi_status;
4414 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4417 if (xfer_cnt < scmd->underflow) {
4418 if (scsi_status == SAM_STAT_BUSY)
4419 scmd->result = SAM_STAT_BUSY;
4421 scmd->result = DID_SOFT_ERROR << 16;
4422 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4423 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4424 scmd->result = DID_SOFT_ERROR << 16;
4425 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4426 scmd->result = DID_RESET << 16;
4427 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4428 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4429 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4430 scmd->result = (DRIVER_SENSE << 24) |
4431 SAM_STAT_CHECK_CONDITION;
4432 scmd->sense_buffer[0] = 0x70;
4433 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4434 scmd->sense_buffer[12] = 0x20;
4435 scmd->sense_buffer[13] = 0;
4439 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4440 scsi_set_resid(scmd, 0);
4441 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4442 case MPI2_IOCSTATUS_SUCCESS:
4443 scmd->result = (DID_OK << 16) | scsi_status;
4444 if (response_code ==
4445 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4446 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4447 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4448 scmd->result = DID_SOFT_ERROR << 16;
4449 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4450 scmd->result = DID_RESET << 16;
4453 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4454 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4455 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4456 _scsih_eedp_error_handling(scmd, ioc_status);
4458 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4459 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4460 case MPI2_IOCSTATUS_INVALID_SGL:
4461 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4462 case MPI2_IOCSTATUS_INVALID_FIELD:
4463 case MPI2_IOCSTATUS_INVALID_STATE:
4464 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4465 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4467 scmd->result = DID_SOFT_ERROR << 16;
4472 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4473 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4474 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4478 scsi_dma_unmap(scmd);
4479 scmd->scsi_done(scmd);
4484 * _scsih_sas_host_refresh - refreshing sas host object contents
4485 * @ioc: per adapter object
4488 * During port enable, fw will send topology events for every device. Its
4489 * possible that the handles may change from the previous setting, so this
4490 * code keeping handles updating if changed.
4495 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4500 Mpi2ConfigReply_t mpi_reply;
4501 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4502 u16 attached_handle;
4505 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4506 "updating handles for sas_host(0x%016llx)\n",
4507 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4509 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4510 * sizeof(Mpi2SasIOUnit0PhyData_t));
4511 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4512 if (!sas_iounit_pg0) {
4513 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4514 ioc->name, __FILE__, __LINE__, __func__);
4518 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4519 sas_iounit_pg0, sz)) != 0)
4521 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4522 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4524 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4525 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4527 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4528 PhyData[0].ControllerDevHandle);
4529 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4530 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4532 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4533 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4534 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4535 attached_handle, i, link_rate);
4538 kfree(sas_iounit_pg0);
4542 * _scsih_sas_host_add - create sas host object
4543 * @ioc: per adapter object
4545 * Creating host side data object, stored in ioc->sas_hba
4550 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4553 Mpi2ConfigReply_t mpi_reply;
4554 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4555 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4556 Mpi2SasPhyPage0_t phy_pg0;
4557 Mpi2SasDevicePage0_t sas_device_pg0;
4558 Mpi2SasEnclosurePage0_t enclosure_pg0;
4561 u16 device_missing_delay;
4563 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4564 if (!ioc->sas_hba.num_phys) {
4565 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4566 ioc->name, __FILE__, __LINE__, __func__);
4570 /* sas_iounit page 0 */
4571 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4572 sizeof(Mpi2SasIOUnit0PhyData_t));
4573 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4574 if (!sas_iounit_pg0) {
4575 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4576 ioc->name, __FILE__, __LINE__, __func__);
4579 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4580 sas_iounit_pg0, sz))) {
4581 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4582 ioc->name, __FILE__, __LINE__, __func__);
4585 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4586 MPI2_IOCSTATUS_MASK;
4587 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4588 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4589 ioc->name, __FILE__, __LINE__, __func__);
4593 /* sas_iounit page 1 */
4594 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4595 sizeof(Mpi2SasIOUnit1PhyData_t));
4596 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4597 if (!sas_iounit_pg1) {
4598 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4599 ioc->name, __FILE__, __LINE__, __func__);
4602 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4603 sas_iounit_pg1, sz))) {
4604 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4605 ioc->name, __FILE__, __LINE__, __func__);
4608 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4609 MPI2_IOCSTATUS_MASK;
4610 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4611 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4612 ioc->name, __FILE__, __LINE__, __func__);
4616 ioc->io_missing_delay =
4617 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4618 device_missing_delay =
4619 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4620 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4621 ioc->device_missing_delay = (device_missing_delay &
4622 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4624 ioc->device_missing_delay = device_missing_delay &
4625 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4627 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4628 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4629 sizeof(struct _sas_phy), GFP_KERNEL);
4630 if (!ioc->sas_hba.phy) {
4631 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4632 ioc->name, __FILE__, __LINE__, __func__);
4635 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4636 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4638 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4639 ioc->name, __FILE__, __LINE__, __func__);
4642 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4643 MPI2_IOCSTATUS_MASK;
4644 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4645 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4646 ioc->name, __FILE__, __LINE__, __func__);
4651 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4652 PhyData[0].ControllerDevHandle);
4653 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4654 ioc->sas_hba.phy[i].phy_id = i;
4655 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4656 phy_pg0, ioc->sas_hba.parent_dev);
4658 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4659 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4660 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4661 ioc->name, __FILE__, __LINE__, __func__);
4664 ioc->sas_hba.enclosure_handle =
4665 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4666 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4667 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4668 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4669 (unsigned long long) ioc->sas_hba.sas_address,
4670 ioc->sas_hba.num_phys) ;
4672 if (ioc->sas_hba.enclosure_handle) {
4673 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4675 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4676 ioc->sas_hba.enclosure_handle))) {
4677 ioc->sas_hba.enclosure_logical_id =
4678 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4683 kfree(sas_iounit_pg1);
4684 kfree(sas_iounit_pg0);
4688 * _scsih_expander_add - creating expander object
4689 * @ioc: per adapter object
4690 * @handle: expander handle
4692 * Creating expander object, stored in ioc->sas_expander_list.
4694 * Return 0 for success, else error.
4697 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4699 struct _sas_node *sas_expander;
4700 Mpi2ConfigReply_t mpi_reply;
4701 Mpi2ExpanderPage0_t expander_pg0;
4702 Mpi2ExpanderPage1_t expander_pg1;
4703 Mpi2SasEnclosurePage0_t enclosure_pg0;
4706 u64 sas_address, sas_address_parent = 0;
4708 unsigned long flags;
4709 struct _sas_port *mpt2sas_port = NULL;
4715 if (ioc->shost_recovery || ioc->pci_error_recovery)
4718 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4719 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4720 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4721 ioc->name, __FILE__, __LINE__, __func__);
4725 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4726 MPI2_IOCSTATUS_MASK;
4727 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4728 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4729 ioc->name, __FILE__, __LINE__, __func__);
4733 /* handle out of order topology events */
4734 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4735 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4737 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4738 ioc->name, __FILE__, __LINE__, __func__);
4741 if (sas_address_parent != ioc->sas_hba.sas_address) {
4742 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4743 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4744 sas_address_parent);
4745 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4746 if (!sas_expander) {
4747 rc = _scsih_expander_add(ioc, parent_handle);
4753 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4754 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4755 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4757 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4762 sas_expander = kzalloc(sizeof(struct _sas_node),
4764 if (!sas_expander) {
4765 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4766 ioc->name, __FILE__, __LINE__, __func__);
4770 sas_expander->handle = handle;
4771 sas_expander->num_phys = expander_pg0.NumPhys;
4772 sas_expander->sas_address_parent = sas_address_parent;
4773 sas_expander->sas_address = sas_address;
4775 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4776 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4777 handle, parent_handle, (unsigned long long)
4778 sas_expander->sas_address, sas_expander->num_phys);
4780 if (!sas_expander->num_phys)
4782 sas_expander->phy = kcalloc(sas_expander->num_phys,
4783 sizeof(struct _sas_phy), GFP_KERNEL);
4784 if (!sas_expander->phy) {
4785 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4786 ioc->name, __FILE__, __LINE__, __func__);
4791 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4792 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4793 sas_address_parent);
4794 if (!mpt2sas_port) {
4795 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4796 ioc->name, __FILE__, __LINE__, __func__);
4800 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4802 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4803 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4804 &expander_pg1, i, handle))) {
4805 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4806 ioc->name, __FILE__, __LINE__, __func__);
4810 sas_expander->phy[i].handle = handle;
4811 sas_expander->phy[i].phy_id = i;
4813 if ((mpt2sas_transport_add_expander_phy(ioc,
4814 &sas_expander->phy[i], expander_pg1,
4815 sas_expander->parent_dev))) {
4816 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4817 ioc->name, __FILE__, __LINE__, __func__);
4823 if (sas_expander->enclosure_handle) {
4824 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4825 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4826 sas_expander->enclosure_handle))) {
4827 sas_expander->enclosure_logical_id =
4828 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4832 _scsih_expander_node_add(ioc, sas_expander);
4838 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4839 sas_address_parent);
4840 kfree(sas_expander);
4845 * _scsih_done - scsih callback handler.
4846 * @ioc: per adapter object
4847 * @smid: system request message index
4848 * @msix_index: MSIX table index supplied by the OS
4849 * @reply: reply message frame(lower 32bit addr)
4851 * Callback handler when sending internal generated message frames.
4852 * The callback index passed is `ioc->scsih_cb_idx`
4854 * Return 1 meaning mf should be freed from _base_interrupt
4855 * 0 means the mf is freed from this function.
4858 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4860 MPI2DefaultReply_t *mpi_reply;
4862 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4863 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4865 if (ioc->scsih_cmds.smid != smid)
4867 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4869 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4870 mpi_reply->MsgLength*4);
4871 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4873 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4874 complete(&ioc->scsih_cmds.done);
4879 * mpt2sas_expander_remove - removing expander object
4880 * @ioc: per adapter object
4881 * @sas_address: expander sas_address
4886 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
4888 struct _sas_node *sas_expander;
4889 unsigned long flags;
4891 if (ioc->shost_recovery)
4894 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4895 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4897 if (!sas_expander) {
4898 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4901 list_del(&sas_expander->list);
4902 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4903 _scsih_expander_node_remove(ioc, sas_expander);
4907 * _scsih_check_access_status - check access flags
4908 * @ioc: per adapter object
4909 * @sas_address: sas address
4910 * @handle: sas device handle
4911 * @access_flags: errors returned during discovery of the device
4913 * Return 0 for success, else failure
4916 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4917 u16 handle, u8 access_status)
4922 switch (access_status) {
4923 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4924 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4927 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4928 desc = "sata capability failed";
4930 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4931 desc = "sata affiliation conflict";
4933 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4934 desc = "route not addressable";
4936 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4937 desc = "smp error not addressable";
4939 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4940 desc = "device blocked";
4942 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4943 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4944 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4945 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4946 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4947 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4948 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4949 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4950 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4951 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4952 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4953 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4954 desc = "sata initialization failed";
4964 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
4965 "handle(0x%04x)\n", ioc->name, desc,
4966 (unsigned long long)sas_address, handle);
4971 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4973 Mpi2ConfigReply_t mpi_reply;
4974 Mpi2SasDevicePage0_t sas_device_pg0;
4975 struct _sas_device *sas_device;
4977 unsigned long flags;
4979 struct scsi_target *starget;
4980 struct MPT2SAS_TARGET *sas_target_priv_data;
4983 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4984 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4987 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4988 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4991 /* check if this is end device */
4992 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4993 if (!(_scsih_is_end_device(device_info)))
4996 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4997 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4998 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5002 printk(MPT2SAS_ERR_FMT "device is not present "
5003 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5004 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5008 if (unlikely(sas_device->handle != handle)) {
5009 starget = sas_device->starget;
5010 sas_target_priv_data = starget->hostdata;
5011 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5012 " to (0x%04x)!!!\n", sas_device->handle, handle);
5013 sas_target_priv_data->handle = handle;
5014 sas_device->handle = handle;
5016 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5018 /* check if device is present */
5019 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5020 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5021 printk(MPT2SAS_ERR_FMT "device is not present "
5022 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5026 /* check if there were any issues with discovery */
5027 if (_scsih_check_access_status(ioc, sas_address, handle,
5028 sas_device_pg0.AccessStatus))
5030 _scsih_ublock_io_device(ioc, handle);
5035 * _scsih_add_device - creating sas device object
5036 * @ioc: per adapter object
5037 * @handle: sas device handle
5038 * @phy_num: phy number end device attached to
5039 * @is_pd: is this hidden raid component
5041 * Creating end device object, stored in ioc->sas_device_list.
5043 * Returns 0 for success, non-zero for failure.
5046 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5048 Mpi2ConfigReply_t mpi_reply;
5049 Mpi2SasDevicePage0_t sas_device_pg0;
5050 Mpi2SasEnclosurePage0_t enclosure_pg0;
5051 struct _sas_device *sas_device;
5055 unsigned long flags;
5057 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5058 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5059 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5060 ioc->name, __FILE__, __LINE__, __func__);
5064 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5065 MPI2_IOCSTATUS_MASK;
5066 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5067 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5068 ioc->name, __FILE__, __LINE__, __func__);
5072 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5074 /* check if device is present */
5075 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5076 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5077 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5078 ioc->name, __FILE__, __LINE__, __func__);
5079 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5080 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5084 /* check if there were any issues with discovery */
5085 if (_scsih_check_access_status(ioc, sas_address, handle,
5086 sas_device_pg0.AccessStatus))
5089 /* check if this is end device */
5090 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5091 if (!(_scsih_is_end_device(device_info))) {
5092 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5093 ioc->name, __FILE__, __LINE__, __func__);
5098 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5099 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5101 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5106 sas_device = kzalloc(sizeof(struct _sas_device),
5109 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5110 ioc->name, __FILE__, __LINE__, __func__);
5114 sas_device->handle = handle;
5115 if (_scsih_get_sas_address(ioc, le16_to_cpu
5116 (sas_device_pg0.ParentDevHandle),
5117 &sas_device->sas_address_parent) != 0)
5118 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5119 ioc->name, __FILE__, __LINE__, __func__);
5120 sas_device->enclosure_handle =
5121 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5123 le16_to_cpu(sas_device_pg0.Slot);
5124 sas_device->device_info = device_info;
5125 sas_device->sas_address = sas_address;
5126 sas_device->phy = sas_device_pg0.PhyNum;
5128 /* get enclosure_logical_id */
5129 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5130 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5131 sas_device->enclosure_handle)))
5132 sas_device->enclosure_logical_id =
5133 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5135 /* get device name */
5136 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5138 if (ioc->wait_for_discovery_to_complete)
5139 _scsih_sas_device_init_add(ioc, sas_device);
5141 _scsih_sas_device_add(ioc, sas_device);
5147 * _scsih_remove_device - removing sas device object
5148 * @ioc: per adapter object
5149 * @sas_device_delete: the sas_device object
5154 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5155 struct _sas_device *sas_device)
5157 struct _sas_device sas_device_backup;
5158 struct MPT2SAS_TARGET *sas_target_priv_data;
5163 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
5164 _scsih_sas_device_remove(ioc, sas_device);
5166 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5167 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5168 sas_device_backup.handle, (unsigned long long)
5169 sas_device_backup.sas_address));
5171 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5172 sas_target_priv_data = sas_device_backup.starget->hostdata;
5173 sas_target_priv_data->deleted = 1;
5176 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5178 if (!ioc->hide_drives)
5179 mpt2sas_transport_port_remove(ioc,
5180 sas_device_backup.sas_address,
5181 sas_device_backup.sas_address_parent);
5183 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5184 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5185 (unsigned long long) sas_device_backup.sas_address);
5187 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5188 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5189 sas_device_backup.handle, (unsigned long long)
5190 sas_device_backup.sas_address));
5194 * mpt2sas_device_remove - removing device object
5195 * @ioc: per adapter object
5196 * @sas_address: expander sas_address
5201 mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5203 struct _sas_device *sas_device;
5204 unsigned long flags;
5206 if (ioc->shost_recovery)
5209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5210 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5213 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5216 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5217 _scsih_remove_device(ioc, sas_device);
5220 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5222 * _scsih_sas_topology_change_event_debug - debug for topology event
5223 * @ioc: per adapter object
5224 * @event_data: event data payload
5228 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5229 Mpi2EventDataSasTopologyChangeList_t *event_data)
5235 char *status_str = NULL;
5236 u8 link_rate, prev_link_rate;
5238 switch (event_data->ExpStatus) {
5239 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5242 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5243 status_str = "remove";
5245 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5247 status_str = "responding";
5249 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5250 status_str = "remove delay";
5253 status_str = "unknown status";
5256 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5257 ioc->name, status_str);
5258 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5259 "start_phy(%02d), count(%d)\n",
5260 le16_to_cpu(event_data->ExpanderDevHandle),
5261 le16_to_cpu(event_data->EnclosureHandle),
5262 event_data->StartPhyNum, event_data->NumEntries);
5263 for (i = 0; i < event_data->NumEntries; i++) {
5264 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5267 phy_number = event_data->StartPhyNum + i;
5268 reason_code = event_data->PHY[i].PhyStatus &
5269 MPI2_EVENT_SAS_TOPO_RC_MASK;
5270 switch (reason_code) {
5271 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5272 status_str = "target add";
5274 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5275 status_str = "target remove";
5277 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5278 status_str = "delay target remove";
5280 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5281 status_str = "link rate change";
5283 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5284 status_str = "target responding";
5287 status_str = "unknown";
5290 link_rate = event_data->PHY[i].LinkRate >> 4;
5291 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5292 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5293 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5294 handle, status_str, link_rate, prev_link_rate);
5301 * _scsih_sas_topology_change_event - handle topology changes
5302 * @ioc: per adapter object
5303 * @fw_event: The fw_event_work object
5308 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5309 struct fw_event_work *fw_event)
5312 u16 parent_handle, handle;
5314 u8 phy_number, max_phys;
5315 struct _sas_node *sas_expander;
5316 struct _sas_device *sas_device;
5318 unsigned long flags;
5319 u8 link_rate, prev_link_rate;
5320 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
5322 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5323 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5324 _scsih_sas_topology_change_event_debug(ioc, event_data);
5327 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
5330 if (!ioc->sas_hba.num_phys)
5331 _scsih_sas_host_add(ioc);
5333 _scsih_sas_host_refresh(ioc);
5335 if (fw_event->ignore) {
5336 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5337 "event\n", ioc->name));
5341 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5343 /* handle expander add */
5344 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5345 if (_scsih_expander_add(ioc, parent_handle) != 0)
5348 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5349 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5351 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5353 sas_address = sas_expander->sas_address;
5354 max_phys = sas_expander->num_phys;
5355 } else if (parent_handle < ioc->sas_hba.num_phys) {
5356 sas_address = ioc->sas_hba.sas_address;
5357 max_phys = ioc->sas_hba.num_phys;
5361 /* handle siblings events */
5362 for (i = 0; i < event_data->NumEntries; i++) {
5363 if (fw_event->ignore) {
5364 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5365 "expander event\n", ioc->name));
5368 if (ioc->shost_recovery || ioc->remove_host ||
5369 ioc->pci_error_recovery)
5371 phy_number = event_data->StartPhyNum + i;
5372 if (phy_number >= max_phys)
5374 reason_code = event_data->PHY[i].PhyStatus &
5375 MPI2_EVENT_SAS_TOPO_RC_MASK;
5376 if ((event_data->PHY[i].PhyStatus &
5377 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5378 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5380 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5383 link_rate = event_data->PHY[i].LinkRate >> 4;
5384 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5385 switch (reason_code) {
5386 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5388 if (link_rate == prev_link_rate)
5391 mpt2sas_transport_update_links(ioc, sas_address,
5392 handle, phy_number, link_rate);
5394 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5397 _scsih_check_device(ioc, handle);
5399 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5401 mpt2sas_transport_update_links(ioc, sas_address,
5402 handle, phy_number, link_rate);
5404 _scsih_add_device(ioc, handle, phy_number, 0);
5406 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5408 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5409 sas_device = _scsih_sas_device_find_by_handle(ioc,
5412 spin_unlock_irqrestore(&ioc->sas_device_lock,
5416 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5417 _scsih_remove_device(ioc, sas_device);
5422 /* handle expander removal */
5423 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5425 mpt2sas_expander_remove(ioc, sas_address);
5429 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5431 * _scsih_sas_device_status_change_event_debug - debug for device event
5432 * @event_data: event data payload
5438 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5439 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5441 char *reason_str = NULL;
5443 switch (event_data->ReasonCode) {
5444 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5445 reason_str = "smart data";
5447 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5448 reason_str = "unsupported device discovered";
5450 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5451 reason_str = "internal device reset";
5453 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5454 reason_str = "internal task abort";
5456 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5457 reason_str = "internal task abort set";
5459 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5460 reason_str = "internal clear task set";
5462 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5463 reason_str = "internal query task";
5465 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5466 reason_str = "sata init failure";
5468 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5469 reason_str = "internal device reset complete";
5471 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5472 reason_str = "internal task abort complete";
5474 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5475 reason_str = "internal async notification";
5477 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5478 reason_str = "expander reduced functionality";
5480 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5481 reason_str = "expander reduced functionality complete";
5484 reason_str = "unknown reason";
5487 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5488 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5489 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5490 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5491 le16_to_cpu(event_data->TaskTag));
5492 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5493 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5494 event_data->ASC, event_data->ASCQ);
5495 printk(KERN_INFO "\n");
5500 * _scsih_sas_device_status_change_event - handle device status change
5501 * @ioc: per adapter object
5502 * @fw_event: The fw_event_work object
5508 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5509 struct fw_event_work *fw_event)
5511 struct MPT2SAS_TARGET *target_priv_data;
5512 struct _sas_device *sas_device;
5514 unsigned long flags;
5515 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5516 fw_event->event_data;
5518 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5519 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5520 _scsih_sas_device_status_change_event_debug(ioc,
5524 /* In MPI Revision K (0xC), the internal device reset complete was
5525 * implemented, so avoid setting tm_busy flag for older firmware.
5527 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5530 if (event_data->ReasonCode !=
5531 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5532 event_data->ReasonCode !=
5533 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5536 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5537 sas_address = le64_to_cpu(event_data->SASAddress);
5538 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5540 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5542 if (!sas_device || !sas_device->starget)
5545 target_priv_data = sas_device->starget->hostdata;
5546 if (!target_priv_data)
5549 if (event_data->ReasonCode ==
5550 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5551 target_priv_data->tm_busy = 1;
5553 target_priv_data->tm_busy = 0;
5556 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5558 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5559 * @ioc: per adapter object
5560 * @event_data: event data payload
5566 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5567 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5569 char *reason_str = NULL;
5571 switch (event_data->ReasonCode) {
5572 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5573 reason_str = "enclosure add";
5575 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5576 reason_str = "enclosure remove";
5579 reason_str = "unknown reason";
5583 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5584 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5585 " number slots(%d)\n", ioc->name, reason_str,
5586 le16_to_cpu(event_data->EnclosureHandle),
5587 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5588 le16_to_cpu(event_data->StartSlot));
5593 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5594 * @ioc: per adapter object
5595 * @fw_event: The fw_event_work object
5601 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5602 struct fw_event_work *fw_event)
5604 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5605 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5606 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5607 fw_event->event_data);
5612 * _scsih_sas_broadcast_primative_event - handle broadcast events
5613 * @ioc: per adapter object
5614 * @fw_event: The fw_event_work object
5620 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5621 struct fw_event_work *fw_event)
5623 struct scsi_cmnd *scmd;
5624 struct scsi_device *sdev;
5627 struct MPT2SAS_DEVICE *sas_device_priv_data;
5628 u32 termination_count;
5630 Mpi2SCSITaskManagementReply_t *mpi_reply;
5631 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
5633 unsigned long flags;
5636 u8 task_abort_retries;
5638 mutex_lock(&ioc->tm_cmds.mutex);
5639 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5640 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5641 event_data->PortWidth));
5643 _scsih_block_io_all_device(ioc);
5645 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5646 mpi_reply = ioc->tm_cmds.reply;
5647 broadcast_aen_retry:
5649 /* sanity checks for retrying this loop */
5650 if (max_retries++ == 5) {
5651 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5652 ioc->name, __func__));
5654 } else if (max_retries > 1)
5655 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5656 ioc->name, __func__, max_retries - 1));
5658 termination_count = 0;
5660 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5661 if (ioc->shost_recovery)
5663 scmd = _scsih_scsi_lookup_get(ioc, smid);
5666 sdev = scmd->device;
5667 sas_device_priv_data = sdev->hostdata;
5668 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5670 /* skip hidden raid components */
5671 if (sas_device_priv_data->sas_target->flags &
5672 MPT_TARGET_FLAGS_RAID_COMPONENT)
5675 if (sas_device_priv_data->sas_target->flags &
5676 MPT_TARGET_FLAGS_VOLUME)
5679 handle = sas_device_priv_data->sas_target->handle;
5680 lun = sas_device_priv_data->lun;
5683 if (ioc->shost_recovery)
5686 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5687 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5688 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5691 sdev_printk(KERN_WARNING, sdev,
5692 "mpt2sas_scsih_issue_tm: FAILED when sending "
5693 "QUERY_TASK: scmd(%p)\n", scmd);
5694 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5695 goto broadcast_aen_retry;
5697 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5698 & MPI2_IOCSTATUS_MASK;
5699 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5700 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5701 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5703 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5704 goto broadcast_aen_retry;
5707 /* see if IO is still owned by IOC and target */
5708 if (mpi_reply->ResponseCode ==
5709 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5710 mpi_reply->ResponseCode ==
5711 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5712 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5715 task_abort_retries = 0;
5717 if (task_abort_retries++ == 60) {
5718 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5719 "%s: ABORT_TASK: giving up\n", ioc->name,
5721 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5722 goto broadcast_aen_retry;
5725 if (ioc->shost_recovery)
5728 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5729 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5730 scmd->serial_number, TM_MUTEX_OFF);
5732 sdev_printk(KERN_WARNING, sdev,
5733 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5734 "scmd(%p)\n", scmd);
5738 if (task_abort_retries > 1)
5739 sdev_printk(KERN_WARNING, sdev,
5740 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5742 task_abort_retries - 1, scmd);
5744 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5745 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5748 if (ioc->broadcast_aen_pending) {
5749 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5750 " pending AEN\n", ioc->name, __func__));
5751 ioc->broadcast_aen_pending = 0;
5752 goto broadcast_aen_retry;
5756 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5759 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5760 "%s - exit, query_count = %d termination_count = %d\n",
5761 ioc->name, __func__, query_count, termination_count));
5763 ioc->broadcast_aen_busy = 0;
5764 if (!ioc->shost_recovery)
5765 _scsih_ublock_io_all_device(ioc);
5766 mutex_unlock(&ioc->tm_cmds.mutex);
5770 * _scsih_sas_discovery_event - handle discovery events
5771 * @ioc: per adapter object
5772 * @fw_event: The fw_event_work object
5778 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5779 struct fw_event_work *fw_event)
5781 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5783 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5784 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5785 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5786 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5788 if (event_data->DiscoveryStatus)
5789 printk("discovery_status(0x%08x)",
5790 le32_to_cpu(event_data->DiscoveryStatus));
5795 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5796 !ioc->sas_hba.num_phys)
5797 _scsih_sas_host_add(ioc);
5801 * _scsih_reprobe_lun - reprobing lun
5802 * @sdev: scsi device struct
5803 * @no_uld_attach: sdev->no_uld_attach flag setting
5807 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5811 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5812 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5813 sdev->no_uld_attach ? "hidding" : "exposing");
5814 rc = scsi_device_reprobe(sdev);
5818 * _scsih_reprobe_target - reprobing target
5819 * @starget: scsi target struct
5820 * @no_uld_attach: sdev->no_uld_attach flag setting
5822 * Note: no_uld_attach flag determines whether the disk device is attached
5823 * to block layer. A value of `1` means to not attach.
5826 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5828 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
5831 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5833 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5835 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5836 _scsih_reprobe_lun);
5839 * _scsih_sas_volume_add - add new volume
5840 * @ioc: per adapter object
5841 * @element: IR config element data
5847 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5848 Mpi2EventIrConfigElement_t *element)
5850 struct _raid_device *raid_device;
5851 unsigned long flags;
5853 u16 handle = le16_to_cpu(element->VolDevHandle);
5856 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5858 printk(MPT2SAS_ERR_FMT
5859 "failure at %s:%d/%s()!\n", ioc->name,
5860 __FILE__, __LINE__, __func__);
5864 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5865 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5866 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5871 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5873 printk(MPT2SAS_ERR_FMT
5874 "failure at %s:%d/%s()!\n", ioc->name,
5875 __FILE__, __LINE__, __func__);
5879 raid_device->id = ioc->sas_id++;
5880 raid_device->channel = RAID_CHANNEL;
5881 raid_device->handle = handle;
5882 raid_device->wwid = wwid;
5883 _scsih_raid_device_add(ioc, raid_device);
5884 if (!ioc->wait_for_discovery_to_complete) {
5885 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5886 raid_device->id, 0);
5888 _scsih_raid_device_remove(ioc, raid_device);
5890 _scsih_determine_boot_device(ioc, raid_device, 1);
5894 * _scsih_sas_volume_delete - delete volume
5895 * @ioc: per adapter object
5896 * @handle: volume device handle
5902 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5904 struct _raid_device *raid_device;
5905 unsigned long flags;
5906 struct MPT2SAS_TARGET *sas_target_priv_data;
5908 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5909 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5910 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5913 if (raid_device->starget) {
5914 sas_target_priv_data = raid_device->starget->hostdata;
5915 sas_target_priv_data->deleted = 1;
5916 scsi_remove_target(&raid_device->starget->dev);
5918 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
5919 "(0x%016llx)\n", ioc->name, raid_device->handle,
5920 (unsigned long long) raid_device->wwid);
5921 _scsih_raid_device_remove(ioc, raid_device);
5925 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5926 * @ioc: per adapter object
5927 * @element: IR config element data
5933 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
5934 Mpi2EventIrConfigElement_t *element)
5936 struct _sas_device *sas_device;
5937 unsigned long flags;
5938 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5940 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5941 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5942 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5946 /* exposing raid component */
5947 sas_device->volume_handle = 0;
5948 sas_device->volume_wwid = 0;
5949 clear_bit(handle, ioc->pd_handles);
5950 _scsih_reprobe_target(sas_device->starget, 0);
5954 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5955 * @ioc: per adapter object
5956 * @element: IR config element data
5962 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
5963 Mpi2EventIrConfigElement_t *element)
5965 struct _sas_device *sas_device;
5966 unsigned long flags;
5967 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5969 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5970 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5971 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5975 /* hiding raid component */
5976 mpt2sas_config_get_volume_handle(ioc, handle,
5977 &sas_device->volume_handle);
5978 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
5979 &sas_device->volume_wwid);
5980 set_bit(handle, ioc->pd_handles);
5981 _scsih_reprobe_target(sas_device->starget, 1);
5986 * _scsih_sas_pd_delete - delete pd component
5987 * @ioc: per adapter object
5988 * @element: IR config element data
5994 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
5995 Mpi2EventIrConfigElement_t *element)
5997 struct _sas_device *sas_device;
5998 unsigned long flags;
5999 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6001 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6002 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6003 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6006 _scsih_remove_device(ioc, sas_device);
6010 * _scsih_sas_pd_add - remove pd component
6011 * @ioc: per adapter object
6012 * @element: IR config element data
6018 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6019 Mpi2EventIrConfigElement_t *element)
6021 struct _sas_device *sas_device;
6022 unsigned long flags;
6023 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6024 Mpi2ConfigReply_t mpi_reply;
6025 Mpi2SasDevicePage0_t sas_device_pg0;
6030 set_bit(handle, ioc->pd_handles);
6032 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6033 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6034 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6038 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6039 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6040 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6041 ioc->name, __FILE__, __LINE__, __func__);
6045 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6046 MPI2_IOCSTATUS_MASK;
6047 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6048 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6049 ioc->name, __FILE__, __LINE__, __func__);
6053 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6054 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6055 mpt2sas_transport_update_links(ioc, sas_address, handle,
6056 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6058 _scsih_add_device(ioc, handle, 0, 1);
6061 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6063 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6064 * @ioc: per adapter object
6065 * @event_data: event data payload
6071 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6072 Mpi2EventDataIrConfigChangeList_t *event_data)
6074 Mpi2EventIrConfigElement_t *element;
6077 char *reason_str = NULL, *element_str = NULL;
6079 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6081 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6082 ioc->name, (le32_to_cpu(event_data->Flags) &
6083 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6084 "foreign" : "native", event_data->NumElements);
6085 for (i = 0; i < event_data->NumElements; i++, element++) {
6086 switch (element->ReasonCode) {
6087 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6090 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6091 reason_str = "remove";
6093 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6094 reason_str = "no change";
6096 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6097 reason_str = "hide";
6099 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6100 reason_str = "unhide";
6102 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6103 reason_str = "volume_created";
6105 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6106 reason_str = "volume_deleted";
6108 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6109 reason_str = "pd_created";
6111 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6112 reason_str = "pd_deleted";
6115 reason_str = "unknown reason";
6118 element_type = le16_to_cpu(element->ElementFlags) &
6119 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6120 switch (element_type) {
6121 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6122 element_str = "volume";
6124 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6125 element_str = "phys disk";
6127 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6128 element_str = "hot spare";
6131 element_str = "unknown element";
6134 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6135 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6136 reason_str, le16_to_cpu(element->VolDevHandle),
6137 le16_to_cpu(element->PhysDiskDevHandle),
6138 element->PhysDiskNum);
6144 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6145 * @ioc: per adapter object
6146 * @fw_event: The fw_event_work object
6152 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6153 struct fw_event_work *fw_event)
6155 Mpi2EventIrConfigElement_t *element;
6158 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
6160 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6161 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6162 && !ioc->hide_ir_msg)
6163 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6167 if (ioc->shost_recovery)
6170 foreign_config = (le32_to_cpu(event_data->Flags) &
6171 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6173 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6174 for (i = 0; i < event_data->NumElements; i++, element++) {
6176 switch (element->ReasonCode) {
6177 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6178 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6179 if (!foreign_config)
6180 _scsih_sas_volume_add(ioc, element);
6182 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6183 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6184 if (!foreign_config)
6185 _scsih_sas_volume_delete(ioc,
6186 le16_to_cpu(element->VolDevHandle));
6188 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6189 if (!ioc->is_warpdrive)
6190 _scsih_sas_pd_hide(ioc, element);
6192 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6193 if (!ioc->is_warpdrive)
6194 _scsih_sas_pd_expose(ioc, element);
6196 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6197 if (!ioc->is_warpdrive)
6198 _scsih_sas_pd_add(ioc, element);
6200 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6201 if (!ioc->is_warpdrive)
6202 _scsih_sas_pd_delete(ioc, element);
6209 * _scsih_sas_ir_volume_event - IR volume event
6210 * @ioc: per adapter object
6211 * @fw_event: The fw_event_work object
6217 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6218 struct fw_event_work *fw_event)
6221 unsigned long flags;
6222 struct _raid_device *raid_device;
6226 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6228 if (ioc->shost_recovery)
6231 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6234 handle = le16_to_cpu(event_data->VolDevHandle);
6235 state = le32_to_cpu(event_data->NewValue);
6236 if (!ioc->hide_ir_msg)
6237 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6238 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6239 le32_to_cpu(event_data->PreviousValue), state));
6242 case MPI2_RAID_VOL_STATE_MISSING:
6243 case MPI2_RAID_VOL_STATE_FAILED:
6244 _scsih_sas_volume_delete(ioc, handle);
6247 case MPI2_RAID_VOL_STATE_ONLINE:
6248 case MPI2_RAID_VOL_STATE_DEGRADED:
6249 case MPI2_RAID_VOL_STATE_OPTIMAL:
6251 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6252 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6253 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6258 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6260 printk(MPT2SAS_ERR_FMT
6261 "failure at %s:%d/%s()!\n", ioc->name,
6262 __FILE__, __LINE__, __func__);
6266 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6268 printk(MPT2SAS_ERR_FMT
6269 "failure at %s:%d/%s()!\n", ioc->name,
6270 __FILE__, __LINE__, __func__);
6274 raid_device->id = ioc->sas_id++;
6275 raid_device->channel = RAID_CHANNEL;
6276 raid_device->handle = handle;
6277 raid_device->wwid = wwid;
6278 _scsih_raid_device_add(ioc, raid_device);
6279 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6280 raid_device->id, 0);
6282 _scsih_raid_device_remove(ioc, raid_device);
6285 case MPI2_RAID_VOL_STATE_INITIALIZING:
6292 * _scsih_sas_ir_physical_disk_event - PD event
6293 * @ioc: per adapter object
6294 * @fw_event: The fw_event_work object
6300 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6301 struct fw_event_work *fw_event)
6303 u16 handle, parent_handle;
6305 struct _sas_device *sas_device;
6306 unsigned long flags;
6307 Mpi2ConfigReply_t mpi_reply;
6308 Mpi2SasDevicePage0_t sas_device_pg0;
6310 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6313 if (ioc->shost_recovery)
6316 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6319 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6320 state = le32_to_cpu(event_data->NewValue);
6322 if (!ioc->hide_ir_msg)
6323 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6324 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6325 le32_to_cpu(event_data->PreviousValue), state));
6328 case MPI2_RAID_PD_STATE_ONLINE:
6329 case MPI2_RAID_PD_STATE_DEGRADED:
6330 case MPI2_RAID_PD_STATE_REBUILDING:
6331 case MPI2_RAID_PD_STATE_OPTIMAL:
6332 case MPI2_RAID_PD_STATE_HOT_SPARE:
6334 if (!ioc->is_warpdrive)
6335 set_bit(handle, ioc->pd_handles);
6337 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6338 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6339 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6344 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6345 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6347 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6348 ioc->name, __FILE__, __LINE__, __func__);
6352 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6353 MPI2_IOCSTATUS_MASK;
6354 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6355 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6356 ioc->name, __FILE__, __LINE__, __func__);
6360 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6361 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6362 mpt2sas_transport_update_links(ioc, sas_address, handle,
6363 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6365 _scsih_add_device(ioc, handle, 0, 1);
6369 case MPI2_RAID_PD_STATE_OFFLINE:
6370 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6371 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6377 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6379 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6380 * @ioc: per adapter object
6381 * @event_data: event data payload
6387 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6388 Mpi2EventDataIrOperationStatus_t *event_data)
6390 char *reason_str = NULL;
6392 switch (event_data->RAIDOperation) {
6393 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6394 reason_str = "resync";
6396 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6397 reason_str = "online capacity expansion";
6399 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6400 reason_str = "consistency check";
6402 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6403 reason_str = "background init";
6405 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6406 reason_str = "make data consistent";
6413 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6414 "\thandle(0x%04x), percent complete(%d)\n",
6415 ioc->name, reason_str,
6416 le16_to_cpu(event_data->VolDevHandle),
6417 event_data->PercentComplete);
6422 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6423 * @ioc: per adapter object
6424 * @fw_event: The fw_event_work object
6430 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6431 struct fw_event_work *fw_event)
6433 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6434 static struct _raid_device *raid_device;
6435 unsigned long flags;
6438 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6439 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6440 && !ioc->hide_ir_msg)
6441 _scsih_sas_ir_operation_status_event_debug(ioc,
6445 /* code added for raid transport support */
6446 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6448 handle = le16_to_cpu(event_data->VolDevHandle);
6450 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6451 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6452 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6457 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6458 raid_device->percent_complete =
6459 event_data->PercentComplete;
6464 * _scsih_prep_device_scan - initialize parameters prior to device scan
6465 * @ioc: per adapter object
6467 * Set the deleted flag prior to device scan. If the device is found during
6468 * the scan, then we clear the deleted flag.
6471 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6473 struct MPT2SAS_DEVICE *sas_device_priv_data;
6474 struct scsi_device *sdev;
6476 shost_for_each_device(sdev, ioc->shost) {
6477 sas_device_priv_data = sdev->hostdata;
6478 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6479 sas_device_priv_data->sas_target->deleted = 1;
6484 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6485 * @ioc: per adapter object
6486 * @sas_address: sas address
6487 * @slot: enclosure slot id
6488 * @handle: device handle
6490 * After host reset, find out whether devices are still responding.
6491 * Used in _scsi_remove_unresponsive_sas_devices.
6496 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6497 u16 slot, u16 handle)
6499 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6500 struct scsi_target *starget;
6501 struct _sas_device *sas_device;
6502 unsigned long flags;
6504 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6505 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6506 if (sas_device->sas_address == sas_address &&
6507 sas_device->slot == slot) {
6508 sas_device->responding = 1;
6509 starget = sas_device->starget;
6510 if (starget && starget->hostdata) {
6511 sas_target_priv_data = starget->hostdata;
6512 sas_target_priv_data->tm_busy = 0;
6513 sas_target_priv_data->deleted = 0;
6515 sas_target_priv_data = NULL;
6517 starget_printk(KERN_INFO, starget,
6518 "handle(0x%04x), sas_addr(0x%016llx), "
6519 "enclosure logical id(0x%016llx), "
6520 "slot(%d)\n", handle,
6521 (unsigned long long)sas_device->sas_address,
6522 (unsigned long long)
6523 sas_device->enclosure_logical_id,
6525 if (sas_device->handle == handle)
6527 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6528 sas_device->handle);
6529 sas_device->handle = handle;
6530 if (sas_target_priv_data)
6531 sas_target_priv_data->handle = handle;
6536 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6540 * _scsih_search_responding_sas_devices -
6541 * @ioc: per adapter object
6543 * After host reset, find out whether devices are still responding.
6549 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6551 Mpi2SasDevicePage0_t sas_device_pg0;
6552 Mpi2ConfigReply_t mpi_reply;
6559 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6561 if (list_empty(&ioc->sas_device_list))
6565 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6566 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6568 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6569 MPI2_IOCSTATUS_MASK;
6570 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6572 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6573 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6574 if (!(_scsih_is_end_device(device_info)))
6576 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6577 slot = le16_to_cpu(sas_device_pg0.Slot);
6578 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6582 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6587 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6588 * @ioc: per adapter object
6589 * @wwid: world wide identifier for raid volume
6590 * @handle: device handle
6592 * After host reset, find out whether devices are still responding.
6593 * Used in _scsi_remove_unresponsive_raid_devices.
6598 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6601 struct MPT2SAS_TARGET *sas_target_priv_data;
6602 struct scsi_target *starget;
6603 struct _raid_device *raid_device;
6604 unsigned long flags;
6606 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6607 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6608 if (raid_device->wwid == wwid && raid_device->starget) {
6609 starget = raid_device->starget;
6610 if (starget && starget->hostdata) {
6611 sas_target_priv_data = starget->hostdata;
6612 sas_target_priv_data->deleted = 0;
6614 sas_target_priv_data = NULL;
6615 raid_device->responding = 1;
6616 starget_printk(KERN_INFO, raid_device->starget,
6617 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6618 (unsigned long long)raid_device->wwid);
6620 * WARPDRIVE: The handles of the PDs might have changed
6621 * across the host reset so re-initialize the
6622 * required data for Direct IO
6624 _scsih_init_warpdrive_properties(ioc, raid_device);
6625 if (raid_device->handle == handle)
6627 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6628 raid_device->handle);
6629 raid_device->handle = handle;
6630 if (sas_target_priv_data)
6631 sas_target_priv_data->handle = handle;
6636 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6640 * _scsih_search_responding_raid_devices -
6641 * @ioc: per adapter object
6643 * After host reset, find out whether devices are still responding.
6649 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6651 Mpi2RaidVolPage1_t volume_pg1;
6652 Mpi2RaidVolPage0_t volume_pg0;
6653 Mpi2RaidPhysDiskPage0_t pd_pg0;
6654 Mpi2ConfigReply_t mpi_reply;
6659 if (!ioc->ir_firmware)
6662 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6665 if (list_empty(&ioc->raid_device_list))
6669 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6670 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6671 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6672 MPI2_IOCSTATUS_MASK;
6673 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6675 handle = le16_to_cpu(volume_pg1.DevHandle);
6677 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6678 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6679 sizeof(Mpi2RaidVolPage0_t)))
6682 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6683 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6684 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6685 _scsih_mark_responding_raid_device(ioc,
6686 le64_to_cpu(volume_pg1.WWID), handle);
6689 /* refresh the pd_handles */
6690 if (!ioc->is_warpdrive) {
6691 phys_disk_num = 0xFF;
6692 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6693 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6694 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6696 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6697 MPI2_IOCSTATUS_MASK;
6698 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6700 phys_disk_num = pd_pg0.PhysDiskNum;
6701 handle = le16_to_cpu(pd_pg0.DevHandle);
6702 set_bit(handle, ioc->pd_handles);
6706 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6707 "complete\n", ioc->name);
6711 * _scsih_mark_responding_expander - mark a expander as responding
6712 * @ioc: per adapter object
6713 * @sas_address: sas address
6716 * After host reset, find out whether devices are still responding.
6717 * Used in _scsi_remove_unresponsive_expanders.
6722 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6725 struct _sas_node *sas_expander;
6726 unsigned long flags;
6729 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6730 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6731 if (sas_expander->sas_address != sas_address)
6733 sas_expander->responding = 1;
6734 if (sas_expander->handle == handle)
6736 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6737 " from(0x%04x) to (0x%04x)!!!\n",
6738 (unsigned long long)sas_expander->sas_address,
6739 sas_expander->handle, handle);
6740 sas_expander->handle = handle;
6741 for (i = 0 ; i < sas_expander->num_phys ; i++)
6742 sas_expander->phy[i].handle = handle;
6746 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6750 * _scsih_search_responding_expanders -
6751 * @ioc: per adapter object
6753 * After host reset, find out whether devices are still responding.
6759 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6761 Mpi2ExpanderPage0_t expander_pg0;
6762 Mpi2ConfigReply_t mpi_reply;
6767 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6769 if (list_empty(&ioc->sas_expander_list))
6773 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6774 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6776 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6777 MPI2_IOCSTATUS_MASK;
6778 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6781 handle = le16_to_cpu(expander_pg0.DevHandle);
6782 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6783 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6784 "sas_addr(0x%016llx)\n", handle,
6785 (unsigned long long)sas_address);
6786 _scsih_mark_responding_expander(ioc, sas_address, handle);
6790 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6794 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6795 * @ioc: per adapter object
6800 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6802 struct _sas_device *sas_device, *sas_device_next;
6803 struct _sas_node *sas_expander;
6804 struct _raid_device *raid_device, *raid_device_next;
6806 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6809 list_for_each_entry_safe(sas_device, sas_device_next,
6810 &ioc->sas_device_list, list) {
6811 if (sas_device->responding) {
6812 sas_device->responding = 0;
6815 if (sas_device->starget)
6816 starget_printk(KERN_INFO, sas_device->starget,
6817 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6818 "enclosure logical id(0x%016llx), slot(%d)\n",
6820 (unsigned long long)sas_device->sas_address,
6821 (unsigned long long)
6822 sas_device->enclosure_logical_id,
6824 _scsih_remove_device(ioc, sas_device);
6827 if (!ioc->ir_firmware)
6828 goto retry_expander_search;
6830 list_for_each_entry_safe(raid_device, raid_device_next,
6831 &ioc->raid_device_list, list) {
6832 if (raid_device->responding) {
6833 raid_device->responding = 0;
6836 if (raid_device->starget) {
6837 starget_printk(KERN_INFO, raid_device->starget,
6838 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6839 raid_device->handle,
6840 (unsigned long long)raid_device->wwid);
6841 scsi_remove_target(&raid_device->starget->dev);
6843 _scsih_raid_device_remove(ioc, raid_device);
6846 retry_expander_search:
6847 sas_expander = NULL;
6848 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6849 if (sas_expander->responding) {
6850 sas_expander->responding = 0;
6853 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6854 goto retry_expander_search;
6856 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6858 /* unblock devices */
6859 _scsih_ublock_io_all_device(ioc);
6863 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6864 struct _sas_node *sas_expander, u16 handle)
6866 Mpi2ExpanderPage1_t expander_pg1;
6867 Mpi2ConfigReply_t mpi_reply;
6870 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6871 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6872 &expander_pg1, i, handle))) {
6873 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6874 ioc->name, __FILE__, __LINE__, __func__);
6878 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6879 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6880 expander_pg1.NegotiatedLinkRate >> 4);
6885 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6886 * @ioc: per adapter object
6891 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
6893 Mpi2ExpanderPage0_t expander_pg0;
6894 Mpi2SasDevicePage0_t sas_device_pg0;
6895 Mpi2RaidVolPage1_t volume_pg1;
6896 Mpi2RaidVolPage0_t volume_pg0;
6897 Mpi2RaidPhysDiskPage0_t pd_pg0;
6898 Mpi2EventIrConfigElement_t element;
6899 Mpi2ConfigReply_t mpi_reply;
6902 u16 handle, parent_handle;
6904 struct _sas_device *sas_device;
6905 struct _sas_node *expander_device;
6906 static struct _raid_device *raid_device;
6908 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
6910 _scsih_sas_host_refresh(ioc);
6914 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6915 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6916 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6917 MPI2_IOCSTATUS_MASK;
6918 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6920 handle = le16_to_cpu(expander_pg0.DevHandle);
6921 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
6922 ioc, le64_to_cpu(expander_pg0.SASAddress));
6923 if (expander_device)
6924 _scsih_refresh_expander_links(ioc, expander_device,
6927 _scsih_expander_add(ioc, handle);
6930 if (!ioc->ir_firmware)
6934 phys_disk_num = 0xFF;
6935 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6936 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6938 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6939 MPI2_IOCSTATUS_MASK;
6940 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6942 phys_disk_num = pd_pg0.PhysDiskNum;
6943 handle = le16_to_cpu(pd_pg0.DevHandle);
6944 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6947 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6948 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6951 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6952 if (!_scsih_get_sas_address(ioc, parent_handle,
6954 mpt2sas_transport_update_links(ioc, sas_address,
6955 handle, sas_device_pg0.PhyNum,
6956 MPI2_SAS_NEG_LINK_RATE_1_5);
6957 set_bit(handle, ioc->pd_handles);
6958 _scsih_add_device(ioc, handle, 0, 1);
6964 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6965 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6966 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6967 MPI2_IOCSTATUS_MASK;
6968 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6970 handle = le16_to_cpu(volume_pg1.DevHandle);
6971 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6972 le64_to_cpu(volume_pg1.WWID));
6975 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6976 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6977 sizeof(Mpi2RaidVolPage0_t)))
6979 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6980 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6981 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6982 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6983 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6984 element.VolDevHandle = volume_pg1.DevHandle;
6985 _scsih_sas_volume_add(ioc, &element);
6993 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6994 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6996 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6997 MPI2_IOCSTATUS_MASK;
6998 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7000 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7001 if (!(_scsih_is_end_device(
7002 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7004 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7005 le64_to_cpu(sas_device_pg0.SASAddress));
7008 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7009 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7010 mpt2sas_transport_update_links(ioc, sas_address, handle,
7011 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7012 _scsih_add_device(ioc, handle, 0, 0);
7016 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7021 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7022 * @ioc: per adapter object
7023 * @reset_phase: phase
7025 * The handler for doing any required cleanup or initialization.
7027 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7028 * MPT2_IOC_DONE_RESET
7033 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7035 switch (reset_phase) {
7036 case MPT2_IOC_PRE_RESET:
7037 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7038 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7040 case MPT2_IOC_AFTER_RESET:
7041 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7042 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7043 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7044 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7045 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7046 complete(&ioc->scsih_cmds.done);
7048 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7049 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7050 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7051 complete(&ioc->tm_cmds.done);
7053 _scsih_fw_event_cleanup_queue(ioc);
7054 _scsih_flush_running_cmds(ioc);
7056 case MPT2_IOC_DONE_RESET:
7057 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7058 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7059 _scsih_sas_host_refresh(ioc);
7060 _scsih_prep_device_scan(ioc);
7061 _scsih_search_responding_sas_devices(ioc);
7062 _scsih_search_responding_raid_devices(ioc);
7063 _scsih_search_responding_expanders(ioc);
7064 _scsih_error_recovery_delete_devices(ioc);
7070 * _firmware_event_work - delayed task for processing firmware events
7071 * @ioc: per adapter object
7072 * @work: equal to the fw_event_work object
7078 _firmware_event_work(struct work_struct *work)
7080 struct fw_event_work *fw_event = container_of(work,
7081 struct fw_event_work, delayed_work.work);
7082 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7084 /* the queue is being flushed so ignore this event */
7085 if (ioc->remove_host || fw_event->cancel_pending_work ||
7086 ioc->pci_error_recovery) {
7087 _scsih_fw_event_free(ioc, fw_event);
7091 switch (fw_event->event) {
7092 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7093 while (scsi_host_in_recovery(ioc->shost))
7095 _scsih_remove_unresponding_sas_devices(ioc);
7096 _scsih_scan_for_devices_after_reset(ioc);
7098 case MPT2SAS_PORT_ENABLE_COMPLETE:
7099 if (!ioc->is_driver_loading && ioc->shost_recovery) {
7100 _scsih_prep_device_scan(ioc);
7101 _scsih_search_responding_sas_devices(ioc);
7102 _scsih_search_responding_raid_devices(ioc);
7103 _scsih_search_responding_expanders(ioc);
7106 if (ioc->start_scan)
7107 ioc->start_scan = 0;
7109 complete(&ioc->port_enable_done);
7113 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7114 "from worker thread\n", ioc->name));
7116 case MPT2SAS_TURN_ON_FAULT_LED:
7117 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7119 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7120 _scsih_sas_topology_change_event(ioc, fw_event);
7122 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7123 _scsih_sas_device_status_change_event(ioc,
7126 case MPI2_EVENT_SAS_DISCOVERY:
7127 _scsih_sas_discovery_event(ioc,
7130 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7131 _scsih_sas_broadcast_primative_event(ioc,
7134 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7135 _scsih_sas_enclosure_dev_status_change_event(ioc,
7138 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7139 _scsih_sas_ir_config_change_event(ioc, fw_event);
7141 case MPI2_EVENT_IR_VOLUME:
7142 _scsih_sas_ir_volume_event(ioc, fw_event);
7144 case MPI2_EVENT_IR_PHYSICAL_DISK:
7145 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7147 case MPI2_EVENT_IR_OPERATION_STATUS:
7148 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7151 _scsih_fw_event_free(ioc, fw_event);
7155 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7156 * @ioc: per adapter object
7157 * @msix_index: MSIX table index supplied by the OS
7158 * @reply: reply message frame(lower 32bit addr)
7159 * Context: interrupt.
7161 * This function merely adds a new work task into ioc->firmware_event_thread.
7162 * The tasks are worked from _firmware_event_work in user context.
7164 * Return 1 meaning mf should be freed from _base_interrupt
7165 * 0 means the mf is freed from this function.
7168 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7171 struct fw_event_work *fw_event;
7172 Mpi2EventNotificationReply_t *mpi_reply;
7176 /* events turned off due to host reset or driver unloading */
7177 if (ioc->remove_host || ioc->pci_error_recovery)
7180 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7181 event = le16_to_cpu(mpi_reply->Event);
7185 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7187 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7188 (Mpi2EventDataSasBroadcastPrimitive_t *)
7189 mpi_reply->EventData;
7191 if (baen_data->Primitive !=
7192 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7195 if (ioc->broadcast_aen_busy) {
7196 ioc->broadcast_aen_pending++;
7199 ioc->broadcast_aen_busy = 1;
7203 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7204 _scsih_check_topo_delete_events(ioc,
7205 (Mpi2EventDataSasTopologyChangeList_t *)
7206 mpi_reply->EventData);
7208 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7209 _scsih_check_ir_config_unhide_events(ioc,
7210 (Mpi2EventDataIrConfigChangeList_t *)
7211 mpi_reply->EventData);
7213 case MPI2_EVENT_IR_VOLUME:
7214 _scsih_check_volume_delete_events(ioc,
7215 (Mpi2EventDataIrVolume_t *)
7216 mpi_reply->EventData);
7218 case MPI2_EVENT_LOG_ENTRY_ADDED:
7220 Mpi2EventDataLogEntryAdded_t *log_entry;
7223 if (!ioc->is_warpdrive)
7226 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7227 mpi_reply->EventData;
7228 log_code = (u32 *)log_entry->LogData;
7230 if (le16_to_cpu(log_entry->LogEntryQualifier)
7231 != MPT2_WARPDRIVE_LOGENTRY)
7234 switch (le32_to_cpu(*log_code)) {
7235 case MPT2_WARPDRIVE_LC_SSDT:
7236 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7237 "IO Throttling has occurred in the WarpDrive "
7238 "subsystem. Check WarpDrive documentation for "
7239 "additional details.\n", ioc->name);
7241 case MPT2_WARPDRIVE_LC_SSDLW:
7242 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7243 "Program/Erase Cycles for the WarpDrive subsystem "
7244 "in degraded range. Check WarpDrive documentation "
7245 "for additional details.\n", ioc->name);
7247 case MPT2_WARPDRIVE_LC_SSDLF:
7248 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7249 "There are no Program/Erase Cycles for the "
7250 "WarpDrive subsystem. The storage device will be "
7251 "in read-only mode. Check WarpDrive documentation "
7252 "for additional details.\n", ioc->name);
7254 case MPT2_WARPDRIVE_LC_BRMF:
7255 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7256 "The Backup Rail Monitor has failed on the "
7257 "WarpDrive subsystem. Check WarpDrive "
7258 "documentation for additional details.\n",
7265 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7266 case MPI2_EVENT_IR_OPERATION_STATUS:
7267 case MPI2_EVENT_SAS_DISCOVERY:
7268 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7269 case MPI2_EVENT_IR_PHYSICAL_DISK:
7272 default: /* ignore the rest */
7276 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7278 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7279 ioc->name, __FILE__, __LINE__, __func__);
7282 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7283 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
7284 if (!fw_event->event_data) {
7285 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7286 ioc->name, __FILE__, __LINE__, __func__);
7291 memcpy(fw_event->event_data, mpi_reply->EventData,
7293 fw_event->ioc = ioc;
7294 fw_event->VF_ID = mpi_reply->VF_ID;
7295 fw_event->VP_ID = mpi_reply->VP_ID;
7296 fw_event->event = event;
7297 _scsih_fw_event_add(ioc, fw_event);
7301 /* shost template */
7302 static struct scsi_host_template scsih_driver_template = {
7303 .module = THIS_MODULE,
7304 .name = "Fusion MPT SAS Host",
7305 .proc_name = MPT2SAS_DRIVER_NAME,
7306 .queuecommand = _scsih_qcmd,
7307 .target_alloc = _scsih_target_alloc,
7308 .slave_alloc = _scsih_slave_alloc,
7309 .slave_configure = _scsih_slave_configure,
7310 .target_destroy = _scsih_target_destroy,
7311 .slave_destroy = _scsih_slave_destroy,
7312 .scan_finished = _scsih_scan_finished,
7313 .scan_start = _scsih_scan_start,
7314 .change_queue_depth = _scsih_change_queue_depth,
7315 .change_queue_type = _scsih_change_queue_type,
7316 .eh_abort_handler = _scsih_abort,
7317 .eh_device_reset_handler = _scsih_dev_reset,
7318 .eh_target_reset_handler = _scsih_target_reset,
7319 .eh_host_reset_handler = _scsih_host_reset,
7320 .bios_param = _scsih_bios_param,
7323 .sg_tablesize = MPT2SAS_SG_DEPTH,
7324 .max_sectors = 8192,
7326 .use_clustering = ENABLE_CLUSTERING,
7327 .shost_attrs = mpt2sas_host_attrs,
7328 .sdev_attrs = mpt2sas_dev_attrs,
7332 * _scsih_expander_node_remove - removing expander device from list.
7333 * @ioc: per adapter object
7334 * @sas_expander: the sas_device object
7335 * Context: Calling function should acquire ioc->sas_node_lock.
7337 * Removing object and freeing associated memory from the
7338 * ioc->sas_expander_list.
7343 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7344 struct _sas_node *sas_expander)
7346 struct _sas_port *mpt2sas_port, *next;
7348 /* remove sibling ports attached to this expander */
7349 list_for_each_entry_safe(mpt2sas_port, next,
7350 &sas_expander->sas_port_list, port_list) {
7351 if (ioc->shost_recovery)
7353 if (mpt2sas_port->remote_identify.device_type ==
7355 mpt2sas_device_remove(ioc,
7356 mpt2sas_port->remote_identify.sas_address);
7357 else if (mpt2sas_port->remote_identify.device_type ==
7358 SAS_EDGE_EXPANDER_DEVICE ||
7359 mpt2sas_port->remote_identify.device_type ==
7360 SAS_FANOUT_EXPANDER_DEVICE)
7361 mpt2sas_expander_remove(ioc,
7362 mpt2sas_port->remote_identify.sas_address);
7365 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7366 sas_expander->sas_address_parent);
7368 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7369 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7370 sas_expander->handle, (unsigned long long)
7371 sas_expander->sas_address);
7373 kfree(sas_expander->phy);
7374 kfree(sas_expander);
7378 * _scsih_ir_shutdown - IR shutdown notification
7379 * @ioc: per adapter object
7381 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7382 * the host system is shutting down.
7387 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7389 Mpi2RaidActionRequest_t *mpi_request;
7390 Mpi2RaidActionReply_t *mpi_reply;
7393 /* is IR firmware build loaded ? */
7394 if (!ioc->ir_firmware)
7397 /* are there any volumes ? */
7398 if (list_empty(&ioc->raid_device_list))
7401 mutex_lock(&ioc->scsih_cmds.mutex);
7403 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7404 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7405 ioc->name, __func__);
7408 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7410 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7412 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7413 ioc->name, __func__);
7414 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7418 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7419 ioc->scsih_cmds.smid = smid;
7420 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7422 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7423 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7425 if (!ioc->hide_ir_msg)
7426 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7427 init_completion(&ioc->scsih_cmds.done);
7428 mpt2sas_base_put_smid_default(ioc, smid);
7429 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7431 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7432 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7433 ioc->name, __func__);
7437 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7438 mpi_reply = ioc->scsih_cmds.reply;
7440 if (!ioc->hide_ir_msg)
7441 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7442 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7443 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7444 le32_to_cpu(mpi_reply->IOCLogInfo));
7448 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7449 mutex_unlock(&ioc->scsih_cmds.mutex);
7453 * _scsih_shutdown - routine call during system shutdown
7454 * @pdev: PCI device struct
7459 _scsih_shutdown(struct pci_dev *pdev)
7461 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7462 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7463 struct workqueue_struct *wq;
7464 unsigned long flags;
7466 ioc->remove_host = 1;
7467 _scsih_fw_event_cleanup_queue(ioc);
7469 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7470 wq = ioc->firmware_event_thread;
7471 ioc->firmware_event_thread = NULL;
7472 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7474 destroy_workqueue(wq);
7476 _scsih_ir_shutdown(ioc);
7477 mpt2sas_base_detach(ioc);
7481 * _scsih_remove - detach and remove add host
7482 * @pdev: PCI device struct
7484 * Routine called when unloading the driver.
7487 static void __devexit
7488 _scsih_remove(struct pci_dev *pdev)
7490 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7491 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7492 struct _sas_port *mpt2sas_port, *next_port;
7493 struct _raid_device *raid_device, *next;
7494 struct MPT2SAS_TARGET *sas_target_priv_data;
7495 struct workqueue_struct *wq;
7496 unsigned long flags;
7498 ioc->remove_host = 1;
7499 _scsih_fw_event_cleanup_queue(ioc);
7501 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7502 wq = ioc->firmware_event_thread;
7503 ioc->firmware_event_thread = NULL;
7504 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7506 destroy_workqueue(wq);
7508 /* release all the volumes */
7509 _scsih_ir_shutdown(ioc);
7510 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7512 if (raid_device->starget) {
7513 sas_target_priv_data =
7514 raid_device->starget->hostdata;
7515 sas_target_priv_data->deleted = 1;
7516 scsi_remove_target(&raid_device->starget->dev);
7518 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7519 "(0x%016llx)\n", ioc->name, raid_device->handle,
7520 (unsigned long long) raid_device->wwid);
7521 _scsih_raid_device_remove(ioc, raid_device);
7524 /* free ports attached to the sas_host */
7525 list_for_each_entry_safe(mpt2sas_port, next_port,
7526 &ioc->sas_hba.sas_port_list, port_list) {
7527 if (mpt2sas_port->remote_identify.device_type ==
7529 mpt2sas_device_remove(ioc,
7530 mpt2sas_port->remote_identify.sas_address);
7531 else if (mpt2sas_port->remote_identify.device_type ==
7532 SAS_EDGE_EXPANDER_DEVICE ||
7533 mpt2sas_port->remote_identify.device_type ==
7534 SAS_FANOUT_EXPANDER_DEVICE)
7535 mpt2sas_expander_remove(ioc,
7536 mpt2sas_port->remote_identify.sas_address);
7539 /* free phys attached to the sas_host */
7540 if (ioc->sas_hba.num_phys) {
7541 kfree(ioc->sas_hba.phy);
7542 ioc->sas_hba.phy = NULL;
7543 ioc->sas_hba.num_phys = 0;
7546 sas_remove_host(shost);
7547 mpt2sas_base_detach(ioc);
7548 list_del(&ioc->list);
7549 scsi_remove_host(shost);
7550 scsi_host_put(shost);
7554 * _scsih_probe_boot_devices - reports 1st device
7555 * @ioc: per adapter object
7557 * If specified in bios page 2, this routine reports the 1st
7558 * device scsi-ml or sas transport for persistent boot device
7559 * purposes. Please refer to function _scsih_determine_boot_device()
7562 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7566 struct _sas_device *sas_device;
7567 struct _raid_device *raid_device;
7569 u64 sas_address_parent;
7571 unsigned long flags;
7574 /* no Bios, return immediately */
7575 if (!ioc->bios_pg3.BiosVersion)
7580 if (ioc->req_boot_device.device) {
7581 device = ioc->req_boot_device.device;
7582 is_raid = ioc->req_boot_device.is_raid;
7583 } else if (ioc->req_alt_boot_device.device) {
7584 device = ioc->req_alt_boot_device.device;
7585 is_raid = ioc->req_alt_boot_device.is_raid;
7586 } else if (ioc->current_boot_device.device) {
7587 device = ioc->current_boot_device.device;
7588 is_raid = ioc->current_boot_device.is_raid;
7595 raid_device = device;
7596 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7597 raid_device->id, 0);
7599 _scsih_raid_device_remove(ioc, raid_device);
7601 sas_device = device;
7602 handle = sas_device->handle;
7603 sas_address_parent = sas_device->sas_address_parent;
7604 sas_address = sas_device->sas_address;
7605 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7606 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7607 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7609 if (ioc->hide_drives)
7611 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7612 sas_device->sas_address_parent)) {
7613 _scsih_sas_device_remove(ioc, sas_device);
7614 } else if (!sas_device->starget) {
7615 mpt2sas_transport_port_remove(ioc, sas_address,
7616 sas_address_parent);
7617 _scsih_sas_device_remove(ioc, sas_device);
7623 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7624 * @ioc: per adapter object
7626 * Called during initial loading of the driver.
7629 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7631 struct _raid_device *raid_device, *raid_next;
7634 list_for_each_entry_safe(raid_device, raid_next,
7635 &ioc->raid_device_list, list) {
7636 if (raid_device->starget)
7638 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7639 raid_device->id, 0);
7641 _scsih_raid_device_remove(ioc, raid_device);
7646 * _scsih_probe_sas - reporting sas devices to sas transport
7647 * @ioc: per adapter object
7649 * Called during initial loading of the driver.
7652 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7654 struct _sas_device *sas_device, *next;
7655 unsigned long flags;
7657 /* SAS Device List */
7658 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7661 if (ioc->hide_drives)
7664 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7665 sas_device->sas_address_parent)) {
7666 list_del(&sas_device->list);
7669 } else if (!sas_device->starget) {
7670 mpt2sas_transport_port_remove(ioc,
7671 sas_device->sas_address,
7672 sas_device->sas_address_parent);
7673 list_del(&sas_device->list);
7678 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7679 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7680 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7685 * _scsih_probe_devices - probing for devices
7686 * @ioc: per adapter object
7688 * Called during initial loading of the driver.
7691 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7693 u16 volume_mapping_flags;
7695 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7696 return; /* return when IOC doesn't support initiator mode */
7698 _scsih_probe_boot_devices(ioc);
7700 if (ioc->ir_firmware) {
7701 volume_mapping_flags =
7702 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7703 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7704 if (volume_mapping_flags ==
7705 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7706 _scsih_probe_raid(ioc);
7707 _scsih_probe_sas(ioc);
7709 _scsih_probe_sas(ioc);
7710 _scsih_probe_raid(ioc);
7713 _scsih_probe_sas(ioc);
7718 * _scsih_scan_start - scsi lld callback for .scan_start
7719 * @shost: SCSI host pointer
7721 * The shost has the ability to discover targets on its own instead
7722 * of scanning the entire bus. In our implemention, we will kick off
7723 * firmware discovery.
7726 _scsih_scan_start(struct Scsi_Host *shost)
7728 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7731 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7732 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7734 ioc->start_scan = 1;
7735 rc = mpt2sas_port_enable(ioc);
7738 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7742 * _scsih_scan_finished - scsi lld callback for .scan_finished
7743 * @shost: SCSI host pointer
7744 * @time: elapsed time of the scan in jiffies
7746 * This function will be called periodically until it returns 1 with the
7747 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7748 * we wait for firmware discovery to complete, then return 1.
7751 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7753 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7755 if (time >= (300 * HZ)) {
7756 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7757 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7758 "(timeout=300s)\n", ioc->name);
7759 ioc->is_driver_loading = 0;
7763 if (ioc->start_scan)
7766 if (ioc->start_scan_failed) {
7767 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7768 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7769 ioc->is_driver_loading = 0;
7770 ioc->wait_for_discovery_to_complete = 0;
7771 ioc->remove_host = 1;
7775 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7776 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7778 if (ioc->wait_for_discovery_to_complete) {
7779 ioc->wait_for_discovery_to_complete = 0;
7780 _scsih_probe_devices(ioc);
7782 mpt2sas_base_start_watchdog(ioc);
7783 ioc->is_driver_loading = 0;
7789 * _scsih_probe - attach and add scsi host
7790 * @pdev: PCI device struct
7791 * @id: pci device id
7793 * Returns 0 success, anything else error.
7796 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7798 struct MPT2SAS_ADAPTER *ioc;
7799 struct Scsi_Host *shost;
7801 shost = scsi_host_alloc(&scsih_driver_template,
7802 sizeof(struct MPT2SAS_ADAPTER));
7806 /* init local params */
7807 ioc = shost_priv(shost);
7808 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7809 INIT_LIST_HEAD(&ioc->list);
7810 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
7812 ioc->id = mpt_ids++;
7813 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7815 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7816 ioc->is_warpdrive = 1;
7817 ioc->hide_ir_msg = 1;
7819 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
7820 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7821 ioc->tm_cb_idx = tm_cb_idx;
7822 ioc->ctl_cb_idx = ctl_cb_idx;
7823 ioc->base_cb_idx = base_cb_idx;
7824 ioc->port_enable_cb_idx = port_enable_cb_idx;
7825 ioc->transport_cb_idx = transport_cb_idx;
7826 ioc->scsih_cb_idx = scsih_cb_idx;
7827 ioc->config_cb_idx = config_cb_idx;
7828 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
7829 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
7830 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
7831 ioc->logging_level = logging_level;
7832 /* misc semaphores and spin locks */
7833 mutex_init(&ioc->reset_in_progress_mutex);
7834 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7835 spin_lock_init(&ioc->scsi_lookup_lock);
7836 spin_lock_init(&ioc->sas_device_lock);
7837 spin_lock_init(&ioc->sas_node_lock);
7838 spin_lock_init(&ioc->fw_event_lock);
7839 spin_lock_init(&ioc->raid_device_lock);
7841 INIT_LIST_HEAD(&ioc->sas_device_list);
7842 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7843 INIT_LIST_HEAD(&ioc->sas_expander_list);
7844 INIT_LIST_HEAD(&ioc->fw_event_list);
7845 INIT_LIST_HEAD(&ioc->raid_device_list);
7846 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
7847 INIT_LIST_HEAD(&ioc->delayed_tr_list);
7848 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
7850 /* init shost parameters */
7851 shost->max_cmd_len = 32;
7852 shost->max_lun = max_lun;
7853 shost->transportt = mpt2sas_transport_template;
7854 shost->unique_id = ioc->id;
7856 if (max_sectors != 0xFFFF) {
7857 if (max_sectors < 64) {
7858 shost->max_sectors = 64;
7859 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7860 "for max_sectors, range is 64 to 8192. Assigning "
7861 "value of 64.\n", ioc->name, max_sectors);
7862 } else if (max_sectors > 8192) {
7863 shost->max_sectors = 8192;
7864 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7865 "for max_sectors, range is 64 to 8192. Assigning "
7866 "default value of 8192.\n", ioc->name,
7869 shost->max_sectors = max_sectors & 0xFFFE;
7870 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7871 "set to %d\n", ioc->name, shost->max_sectors);
7875 if ((scsi_add_host(shost, &pdev->dev))) {
7876 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7877 ioc->name, __FILE__, __LINE__, __func__);
7878 list_del(&ioc->list);
7879 goto out_add_shost_fail;
7882 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
7883 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
7884 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
7887 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7888 "fw_event%d", ioc->id);
7889 ioc->firmware_event_thread = create_singlethread_workqueue(
7890 ioc->firmware_event_name);
7891 if (!ioc->firmware_event_thread) {
7892 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7893 ioc->name, __FILE__, __LINE__, __func__);
7894 goto out_thread_fail;
7897 ioc->is_driver_loading = 1;
7898 if ((mpt2sas_base_attach(ioc))) {
7899 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7900 ioc->name, __FILE__, __LINE__, __func__);
7901 goto out_attach_fail;
7904 scsi_scan_host(shost);
7905 if (ioc->is_warpdrive) {
7906 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7907 ioc->hide_drives = 0;
7908 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
7909 ioc->hide_drives = 1;
7911 if (_scsih_get_num_volumes(ioc))
7912 ioc->hide_drives = 1;
7914 ioc->hide_drives = 0;
7917 ioc->hide_drives = 0;
7919 _scsih_probe_devices(ioc);
7923 destroy_workqueue(ioc->firmware_event_thread);
7925 list_del(&ioc->list);
7926 scsi_remove_host(shost);
7927 scsi_host_put(shost);
7934 * _scsih_suspend - power management suspend main entry point
7935 * @pdev: PCI device struct
7936 * @state: PM state change to (usually PCI_D3)
7938 * Returns 0 success, anything else error.
7941 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
7943 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7944 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7945 pci_power_t device_state;
7947 mpt2sas_base_stop_watchdog(ioc);
7948 scsi_block_requests(shost);
7949 device_state = pci_choose_state(pdev, state);
7950 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
7951 "operating state [D%d]\n", ioc->name, pdev,
7952 pci_name(pdev), device_state);
7954 mpt2sas_base_free_resources(ioc);
7955 pci_save_state(pdev);
7956 pci_disable_device(pdev);
7957 pci_set_power_state(pdev, device_state);
7962 * _scsih_resume - power management resume main entry point
7963 * @pdev: PCI device struct
7965 * Returns 0 success, anything else error.
7968 _scsih_resume(struct pci_dev *pdev)
7970 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7971 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7972 pci_power_t device_state = pdev->current_state;
7975 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
7976 "operating state [D%d]\n", ioc->name, pdev,
7977 pci_name(pdev), device_state);
7979 pci_set_power_state(pdev, PCI_D0);
7980 pci_enable_wake(pdev, PCI_D0, 0);
7981 pci_restore_state(pdev);
7983 r = mpt2sas_base_map_resources(ioc);
7987 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7988 scsi_unblock_requests(shost);
7989 mpt2sas_base_start_watchdog(ioc);
7992 #endif /* CONFIG_PM */
7995 * _scsih_pci_error_detected - Called when a PCI error is detected.
7996 * @pdev: PCI device struct
7997 * @state: PCI channel state
7999 * Description: Called when a PCI error is detected.
8002 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8004 static pci_ers_result_t
8005 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8007 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8008 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8010 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8014 case pci_channel_io_normal:
8015 return PCI_ERS_RESULT_CAN_RECOVER;
8016 case pci_channel_io_frozen:
8017 /* Fatal error, prepare for slot reset */
8018 ioc->pci_error_recovery = 1;
8019 scsi_block_requests(ioc->shost);
8020 mpt2sas_base_stop_watchdog(ioc);
8021 mpt2sas_base_free_resources(ioc);
8022 return PCI_ERS_RESULT_NEED_RESET;
8023 case pci_channel_io_perm_failure:
8024 /* Permanent error, prepare for device removal */
8025 ioc->pci_error_recovery = 1;
8026 mpt2sas_base_stop_watchdog(ioc);
8027 _scsih_flush_running_cmds(ioc);
8028 return PCI_ERS_RESULT_DISCONNECT;
8030 return PCI_ERS_RESULT_NEED_RESET;
8034 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8035 * @pdev: PCI device struct
8037 * Description: This routine is called by the pci error recovery
8038 * code after the PCI slot has been reset, just before we
8039 * should resume normal operations.
8041 static pci_ers_result_t
8042 _scsih_pci_slot_reset(struct pci_dev *pdev)
8044 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8045 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8048 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8051 ioc->pci_error_recovery = 0;
8053 pci_restore_state(pdev);
8054 rc = mpt2sas_base_map_resources(ioc);
8056 return PCI_ERS_RESULT_DISCONNECT;
8059 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8062 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8063 (rc == 0) ? "success" : "failed");
8066 return PCI_ERS_RESULT_RECOVERED;
8068 return PCI_ERS_RESULT_DISCONNECT;
8072 * _scsih_pci_resume() - resume normal ops after PCI reset
8073 * @pdev: pointer to PCI device
8075 * Called when the error recovery driver tells us that its
8076 * OK to resume normal operation. Use completion to allow
8077 * halted scsi ops to resume.
8080 _scsih_pci_resume(struct pci_dev *pdev)
8082 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8083 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8085 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8087 pci_cleanup_aer_uncorrect_error_status(pdev);
8088 mpt2sas_base_start_watchdog(ioc);
8089 scsi_unblock_requests(ioc->shost);
8093 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8094 * @pdev: pointer to PCI device
8096 static pci_ers_result_t
8097 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8099 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8100 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8102 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8105 /* TODO - dump whatever for debugging purposes */
8107 /* Request a slot reset. */
8108 return PCI_ERS_RESULT_NEED_RESET;
8111 static struct pci_error_handlers _scsih_err_handler = {
8112 .error_detected = _scsih_pci_error_detected,
8113 .mmio_enabled = _scsih_pci_mmio_enabled,
8114 .slot_reset = _scsih_pci_slot_reset,
8115 .resume = _scsih_pci_resume,
8118 static struct pci_driver scsih_driver = {
8119 .name = MPT2SAS_DRIVER_NAME,
8120 .id_table = scsih_pci_table,
8121 .probe = _scsih_probe,
8122 .remove = __devexit_p(_scsih_remove),
8123 .shutdown = _scsih_shutdown,
8124 .err_handler = &_scsih_err_handler,
8126 .suspend = _scsih_suspend,
8127 .resume = _scsih_resume,
8131 /* raid transport support */
8132 static struct raid_function_template mpt2sas_raid_functions = {
8133 .cookie = &scsih_driver_template,
8134 .is_raid = _scsih_is_raid,
8135 .get_resync = _scsih_get_resync,
8136 .get_state = _scsih_get_state,
8140 * _scsih_init - main entry point for this driver.
8142 * Returns 0 success, anything else error.
8150 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8151 MPT2SAS_DRIVER_VERSION);
8153 mpt2sas_transport_template =
8154 sas_attach_transport(&mpt2sas_transport_functions);
8155 if (!mpt2sas_transport_template)
8157 /* raid transport support */
8158 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8159 if (!mpt2sas_raid_template) {
8160 sas_release_transport(mpt2sas_transport_template);
8164 mpt2sas_base_initialize_callback_handler();
8166 /* queuecommand callback hander */
8167 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8169 /* task management callback handler */
8170 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8172 /* base internal commands callback handler */
8173 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8174 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8175 mpt2sas_port_enable_done);
8177 /* transport internal commands callback handler */
8178 transport_cb_idx = mpt2sas_base_register_callback_handler(
8179 mpt2sas_transport_done);
8181 /* scsih internal commands callback handler */
8182 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8184 /* configuration page API internal commands callback handler */
8185 config_cb_idx = mpt2sas_base_register_callback_handler(
8186 mpt2sas_config_done);
8188 /* ctl module callback handler */
8189 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8191 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8192 _scsih_tm_tr_complete);
8194 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8195 _scsih_tm_volume_tr_complete);
8197 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8198 _scsih_sas_control_complete);
8202 error = pci_register_driver(&scsih_driver);
8204 /* raid transport support */
8205 raid_class_release(mpt2sas_raid_template);
8206 sas_release_transport(mpt2sas_transport_template);
8213 * _scsih_exit - exit point for this driver (when it is a module).
8215 * Returns 0 success, anything else error.
8220 printk(KERN_INFO "mpt2sas version %s unloading\n",
8221 MPT2SAS_DRIVER_VERSION);
8223 pci_unregister_driver(&scsih_driver);
8227 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8228 mpt2sas_base_release_callback_handler(tm_cb_idx);
8229 mpt2sas_base_release_callback_handler(base_cb_idx);
8230 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8231 mpt2sas_base_release_callback_handler(transport_cb_idx);
8232 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8233 mpt2sas_base_release_callback_handler(config_cb_idx);
8234 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8236 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8237 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8238 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8240 /* raid transport support */
8241 raid_class_release(mpt2sas_raid_template);
8242 sas_release_transport(mpt2sas_transport_template);
8246 module_init(_scsih_init);
8247 module_exit(_scsih_exit);