2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2014 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include <asm/unaligned.h>
60 #include "mpt2sas_base.h"
62 MODULE_AUTHOR(MPT2SAS_AUTHOR);
63 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
64 MODULE_LICENSE("GPL");
65 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
67 #define RAID_CHANNEL 1
70 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
71 struct _sas_node *sas_expander);
72 static void _firmware_event_work(struct work_struct *work);
74 static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
76 static void _scsih_scan_start(struct Scsi_Host *shost);
77 static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
79 /* global parameters */
80 LIST_HEAD(mpt2sas_ioc_list);
82 /* local parameters */
83 static u8 scsi_io_cb_idx = -1;
84 static u8 tm_cb_idx = -1;
85 static u8 ctl_cb_idx = -1;
86 static u8 base_cb_idx = -1;
87 static u8 port_enable_cb_idx = -1;
88 static u8 transport_cb_idx = -1;
89 static u8 scsih_cb_idx = -1;
90 static u8 config_cb_idx = -1;
93 static u8 tm_tr_cb_idx = -1 ;
94 static u8 tm_tr_volume_cb_idx = -1 ;
95 static u8 tm_sas_control_cb_idx = -1;
97 /* command line options */
98 static u32 logging_level;
99 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
102 static ushort max_sectors = 0xFFFF;
103 module_param(max_sectors, ushort, 0);
104 MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
106 static int missing_delay[2] = {-1, -1};
107 module_param_array(missing_delay, int, NULL, 0);
108 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
110 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
111 #define MPT2SAS_MAX_LUN (16895)
112 static int max_lun = MPT2SAS_MAX_LUN;
113 module_param(max_lun, int, 0);
114 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
116 /* diag_buffer_enable is bitwise
118 * bit 1 set = SNAPSHOT
119 * bit 2 set = EXTENDED
121 * Either bit can be set, or both
123 static int diag_buffer_enable = -1;
124 module_param(diag_buffer_enable, int, 0);
125 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
126 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
128 static int disable_discovery = -1;
129 module_param(disable_discovery, int, 0);
130 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
132 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
133 static int prot_mask = 0;
134 module_param(prot_mask, int, 0);
135 MODULE_PARM_DESC(prot_mask, " host protection capabilities mask, def=7 ");
138 * struct sense_info - common structure for obtaining sense keys
140 * @asc: additional sense code
141 * @ascq: additional sense code qualifier
150 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
151 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
152 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
154 * struct fw_event_work - firmware event struct
155 * @list: link list framework
156 * @work: work object (ioc->fault_reset_work_q)
157 * @cancel_pending_work: flag set during reset handling
158 * @ioc: per adapter object
159 * @device_handle: device handle
160 * @VF_ID: virtual function id
161 * @VP_ID: virtual port id
162 * @ignore: flag meaning this event has been marked to ignore
163 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
164 * @event_data: reply event data payload follows
166 * This object stored on ioc->fw_event_list.
168 struct fw_event_work {
169 struct list_head list;
170 u8 cancel_pending_work;
171 struct delayed_work delayed_work;
172 struct MPT2SAS_ADAPTER *ioc;
178 char event_data[0] __aligned(4);
181 /* raid transport support */
182 static struct raid_template *mpt2sas_raid_template;
185 * struct _scsi_io_transfer - scsi io transfer
186 * @handle: sas device handle (assigned by firmware)
187 * @is_raid: flag set for hidden raid components
188 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
189 * @data_length: data transfer length
190 * @data_dma: dma pointer to data
193 * @cdb_length: cdb length
195 * @timeout: timeout for this command
196 * @VF_ID: virtual function id
197 * @VP_ID: virtual port id
198 * @valid_reply: flag set for reply message
199 * @sense_length: sense length
200 * @ioc_status: ioc status
201 * @scsi_state: scsi state
202 * @scsi_status: scsi staus
203 * @log_info: log information
204 * @transfer_length: data length transfer when there is a reply message
206 * Used for sending internal scsi commands to devices within this module.
207 * Refer to _scsi_send_scsi_io().
209 struct _scsi_io_transfer {
212 enum dma_data_direction dir;
215 u8 sense[SCSI_SENSE_BUFFERSIZE];
223 /* the following bits are only valid when 'valid_reply = 1' */
233 * The pci device ids are defined in mpi/mpi2_cnfg.h.
235 static struct pci_device_id scsih_pci_table[] = {
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
237 PCI_ANY_ID, PCI_ANY_ID },
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
240 PCI_ANY_ID, PCI_ANY_ID },
241 /* Liberator ~ 2108 */
242 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
245 PCI_ANY_ID, PCI_ANY_ID },
246 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
247 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
250 PCI_ANY_ID, PCI_ANY_ID },
251 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
252 PCI_ANY_ID, PCI_ANY_ID },
253 /* Thunderbolt ~ 2208 */
254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
257 PCI_ANY_ID, PCI_ANY_ID },
258 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
259 PCI_ANY_ID, PCI_ANY_ID },
260 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
261 PCI_ANY_ID, PCI_ANY_ID },
262 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
263 PCI_ANY_ID, PCI_ANY_ID },
264 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
265 PCI_ANY_ID, PCI_ANY_ID },
267 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
268 PCI_ANY_ID, PCI_ANY_ID },
269 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
270 PCI_ANY_ID, PCI_ANY_ID },
271 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
272 PCI_ANY_ID, PCI_ANY_ID },
274 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
275 PCI_ANY_ID, PCI_ANY_ID },
276 {0} /* Terminating entry */
278 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
281 * _scsih_set_debug_level - global setting of ioc->logging_level.
283 * Note: The logging levels are defined in mpt2sas_debug.h.
286 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
288 int ret = param_set_int(val, kp);
289 struct MPT2SAS_ADAPTER *ioc;
294 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
295 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
296 ioc->logging_level = logging_level;
299 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
300 &logging_level, 0644);
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
307 * Returns 1 when there's a match, 0 means no match.
310 _scsih_srch_boot_sas_address(u64 sas_address,
311 Mpi2BootDeviceSasWwid_t *boot_device)
313 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_device_name(u64 device_name,
325 Mpi2BootDeviceDeviceName_t *boot_device)
327 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
336 * Returns 1 when there's a match, 0 means no match.
339 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
340 Mpi2BootDeviceEnclosureSlot_t *boot_device)
342 return (enclosure_logical_id == le64_to_cpu(boot_device->
343 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
344 SlotNumber)) ? 1 : 0;
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
356 * Returns 1 when there's a match, 0 means no match.
359 _scsih_is_boot_device(u64 sas_address, u64 device_name,
360 u64 enclosure_logical_id, u16 slot, u8 form,
361 Mpi2BiosPage2BootDevice_t *boot_device)
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
369 rc = _scsih_srch_boot_sas_address(
370 sas_address, &boot_device->SasWwid);
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
373 if (!enclosure_logical_id)
375 rc = _scsih_srch_boot_encl_slot(
376 enclosure_logical_id,
377 slot, &boot_device->EnclosureSlot);
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
382 rc = _scsih_srch_boot_device_name(
383 device_name, &boot_device->DeviceName);
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
397 * Returns 0 success, non-zero when failure
400 _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
403 Mpi2SasDevicePage0_t sas_device_pg0;
404 Mpi2ConfigReply_t mpi_reply;
408 if (handle <= ioc->sas_hba.num_phys) {
409 *sas_address = ioc->sas_hba.sas_address;
413 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
415 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
416 __FILE__, __LINE__, __func__);
420 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
421 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
422 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
429 /* else error case */
430 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
431 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
432 __FILE__, __LINE__, __func__);
437 * _scsih_determine_boot_device - determine boot device.
438 * @ioc: per adapter object
439 * @device: either sas_device or raid_device object
440 * @is_raid: [flag] 1 = raid object, 0 = sas object
442 * Determines whether this device should be first reported device to
443 * to scsi-ml or sas transport, this purpose is for persistent boot device.
444 * There are primary, alternate, and current entries in bios page 2. The order
445 * priority is primary, alternate, then current. This routine saves
446 * the corresponding device object and is_raid flag in the ioc object.
447 * The saved data to be used later in _scsih_probe_boot_devices().
450 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
451 void *device, u8 is_raid)
453 struct _sas_device *sas_device;
454 struct _raid_device *raid_device;
457 u64 enclosure_logical_id;
460 /* only process this function when driver loads */
461 if (!ioc->is_driver_loading)
464 /* no Bios, return immediately */
465 if (!ioc->bios_pg3.BiosVersion)
470 sas_address = sas_device->sas_address;
471 device_name = sas_device->device_name;
472 enclosure_logical_id = sas_device->enclosure_logical_id;
473 slot = sas_device->slot;
475 raid_device = device;
476 sas_address = raid_device->wwid;
478 enclosure_logical_id = 0;
482 if (!ioc->req_boot_device.device) {
483 if (_scsih_is_boot_device(sas_address, device_name,
484 enclosure_logical_id, slot,
485 (ioc->bios_pg2.ReqBootDeviceForm &
486 MPI2_BIOSPAGE2_FORM_MASK),
487 &ioc->bios_pg2.RequestedBootDevice)) {
488 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
489 "%s: req_boot_device(0x%016llx)\n",
491 (unsigned long long)sas_address));
492 ioc->req_boot_device.device = device;
493 ioc->req_boot_device.is_raid = is_raid;
497 if (!ioc->req_alt_boot_device.device) {
498 if (_scsih_is_boot_device(sas_address, device_name,
499 enclosure_logical_id, slot,
500 (ioc->bios_pg2.ReqAltBootDeviceForm &
501 MPI2_BIOSPAGE2_FORM_MASK),
502 &ioc->bios_pg2.RequestedAltBootDevice)) {
503 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
504 "%s: req_alt_boot_device(0x%016llx)\n",
506 (unsigned long long)sas_address));
507 ioc->req_alt_boot_device.device = device;
508 ioc->req_alt_boot_device.is_raid = is_raid;
512 if (!ioc->current_boot_device.device) {
513 if (_scsih_is_boot_device(sas_address, device_name,
514 enclosure_logical_id, slot,
515 (ioc->bios_pg2.CurrentBootDeviceForm &
516 MPI2_BIOSPAGE2_FORM_MASK),
517 &ioc->bios_pg2.CurrentBootDevice)) {
518 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
519 "%s: current_boot_device(0x%016llx)\n",
521 (unsigned long long)sas_address));
522 ioc->current_boot_device.device = device;
523 ioc->current_boot_device.is_raid = is_raid;
529 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
530 * @ioc: per adapter object
531 * @sas_address: sas address
532 * Context: Calling function should acquire ioc->sas_device_lock
534 * This searches for sas_device based on sas_address, then return sas_device
538 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
541 struct _sas_device *sas_device;
543 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
544 if (sas_device->sas_address == sas_address)
547 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
548 if (sas_device->sas_address == sas_address)
555 * _scsih_sas_device_find_by_handle - sas device search
556 * @ioc: per adapter object
557 * @handle: sas device handle (assigned by firmware)
558 * Context: Calling function should acquire ioc->sas_device_lock
560 * This searches for sas_device based on sas_address, then return sas_device
563 static struct _sas_device *
564 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
566 struct _sas_device *sas_device;
568 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
569 if (sas_device->handle == handle)
572 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
573 if (sas_device->handle == handle)
580 * _scsih_sas_device_remove - remove sas_device from list.
581 * @ioc: per adapter object
582 * @sas_device: the sas_device object
583 * Context: This function will acquire ioc->sas_device_lock.
585 * Removing object and freeing associated memory from the ioc->sas_device_list.
588 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
589 struct _sas_device *sas_device)
596 spin_lock_irqsave(&ioc->sas_device_lock, flags);
597 list_del(&sas_device->list);
599 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
604 * _scsih_sas_device_add - insert sas_device to the list.
605 * @ioc: per adapter object
606 * @sas_device: the sas_device object
607 * Context: This function will acquire ioc->sas_device_lock.
609 * Adding new object to the ioc->sas_device_list.
612 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
613 struct _sas_device *sas_device)
617 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
618 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
619 sas_device->handle, (unsigned long long)sas_device->sas_address));
621 spin_lock_irqsave(&ioc->sas_device_lock, flags);
622 list_add_tail(&sas_device->list, &ioc->sas_device_list);
623 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
625 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
626 sas_device->sas_address_parent)) {
627 _scsih_sas_device_remove(ioc, sas_device);
628 } else if (!sas_device->starget) {
629 /* When asyn scanning is enabled, its not possible to remove
630 * devices while scanning is turned on due to an oops in
631 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
633 if (!ioc->is_driver_loading) {
634 mpt2sas_transport_port_remove(ioc,
635 sas_device->sas_address,
636 sas_device->sas_address_parent);
637 _scsih_sas_device_remove(ioc, sas_device);
643 * _scsih_sas_device_init_add - insert sas_device to the list.
644 * @ioc: per adapter object
645 * @sas_device: the sas_device object
646 * Context: This function will acquire ioc->sas_device_lock.
648 * Adding new object at driver load time to the ioc->sas_device_init_list.
651 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
652 struct _sas_device *sas_device)
656 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
657 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
658 sas_device->handle, (unsigned long long)sas_device->sas_address));
660 spin_lock_irqsave(&ioc->sas_device_lock, flags);
661 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
662 _scsih_determine_boot_device(ioc, sas_device, 0);
663 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
667 * _scsih_raid_device_find_by_id - raid device search
668 * @ioc: per adapter object
669 * @id: sas device target id
670 * @channel: sas device channel
671 * Context: Calling function should acquire ioc->raid_device_lock
673 * This searches for raid_device based on target id, then return raid_device
676 static struct _raid_device *
677 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
679 struct _raid_device *raid_device, *r;
682 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
683 if (raid_device->id == id && raid_device->channel == channel) {
694 * _scsih_raid_device_find_by_handle - raid device search
695 * @ioc: per adapter object
696 * @handle: sas device handle (assigned by firmware)
697 * Context: Calling function should acquire ioc->raid_device_lock
699 * This searches for raid_device based on handle, then return raid_device
702 static struct _raid_device *
703 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
705 struct _raid_device *raid_device, *r;
708 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
709 if (raid_device->handle != handle)
720 * _scsih_raid_device_find_by_wwid - raid device search
721 * @ioc: per adapter object
722 * @handle: sas device handle (assigned by firmware)
723 * Context: Calling function should acquire ioc->raid_device_lock
725 * This searches for raid_device based on wwid, then return raid_device
728 static struct _raid_device *
729 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
731 struct _raid_device *raid_device, *r;
734 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
735 if (raid_device->wwid != wwid)
746 * _scsih_raid_device_add - add raid_device object
747 * @ioc: per adapter object
748 * @raid_device: raid_device object
750 * This is added to the raid_device_list link list.
753 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
754 struct _raid_device *raid_device)
758 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
759 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
760 raid_device->handle, (unsigned long long)raid_device->wwid));
762 spin_lock_irqsave(&ioc->raid_device_lock, flags);
763 list_add_tail(&raid_device->list, &ioc->raid_device_list);
764 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
768 * _scsih_raid_device_remove - delete raid_device object
769 * @ioc: per adapter object
770 * @raid_device: raid_device object
774 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
775 struct _raid_device *raid_device)
779 spin_lock_irqsave(&ioc->raid_device_lock, flags);
780 list_del(&raid_device->list);
782 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
786 * mpt2sas_scsih_expander_find_by_handle - expander device search
787 * @ioc: per adapter object
788 * @handle: expander handle (assigned by firmware)
789 * Context: Calling function should acquire ioc->sas_device_lock
791 * This searches for expander device based on handle, then returns the
795 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
797 struct _sas_node *sas_expander, *r;
800 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
801 if (sas_expander->handle != handle)
811 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
812 * @ioc: per adapter object
813 * @sas_address: sas address
814 * Context: Calling function should acquire ioc->sas_node_lock.
816 * This searches for expander device based on sas_address, then returns the
820 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
823 struct _sas_node *sas_expander, *r;
826 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
827 if (sas_expander->sas_address != sas_address)
837 * _scsih_expander_node_add - insert expander device to the list.
838 * @ioc: per adapter object
839 * @sas_expander: the sas_device object
840 * Context: This function will acquire ioc->sas_node_lock.
842 * Adding new object to the ioc->sas_expander_list.
847 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
848 struct _sas_node *sas_expander)
852 spin_lock_irqsave(&ioc->sas_node_lock, flags);
853 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
854 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
858 * _scsih_is_end_device - determines if device is an end device
859 * @device_info: bitfield providing information about the device.
862 * Returns 1 if end device.
865 _scsih_is_end_device(u32 device_info)
867 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
868 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
869 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
870 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
877 * _scsih_scsi_lookup_get - returns scmd entry
878 * @ioc: per adapter object
879 * @smid: system request message index
881 * Returns the smid stored scmd pointer.
883 static struct scsi_cmnd *
884 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
886 return ioc->scsi_lookup[smid - 1].scmd;
890 * _scsih_scsi_lookup_get_clear - returns scmd entry
891 * @ioc: per adapter object
892 * @smid: system request message index
894 * Returns the smid stored scmd pointer.
895 * Then will derefrence the stored scmd pointer.
897 static inline struct scsi_cmnd *
898 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
901 struct scsi_cmnd *scmd;
903 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
904 scmd = ioc->scsi_lookup[smid - 1].scmd;
905 ioc->scsi_lookup[smid - 1].scmd = NULL;
906 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
912 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
913 * @ioc: per adapter object
914 * @smid: system request message index
915 * @scmd: pointer to scsi command object
916 * Context: This function will acquire ioc->scsi_lookup_lock.
918 * This will search for a scmd pointer in the scsi_lookup array,
919 * returning the revelent smid. A returned value of zero means invalid.
922 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
929 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
931 for (i = 0; i < ioc->scsiio_depth; i++) {
932 if (ioc->scsi_lookup[i].scmd == scmd) {
933 smid = ioc->scsi_lookup[i].smid;
938 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
943 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
944 * @ioc: per adapter object
947 * Context: This function will acquire ioc->scsi_lookup_lock.
949 * This will search for a matching channel:id in the scsi_lookup array,
950 * returning 1 if found.
953 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
960 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
962 for (i = 0 ; i < ioc->scsiio_depth; i++) {
963 if (ioc->scsi_lookup[i].scmd &&
964 (ioc->scsi_lookup[i].scmd->device->id == id &&
965 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
971 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
976 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
977 * @ioc: per adapter object
981 * Context: This function will acquire ioc->scsi_lookup_lock.
983 * This will search for a matching channel:id:lun in the scsi_lookup array,
984 * returning 1 if found.
987 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
988 unsigned int lun, int channel)
994 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
996 for (i = 0 ; i < ioc->scsiio_depth; i++) {
997 if (ioc->scsi_lookup[i].scmd &&
998 (ioc->scsi_lookup[i].scmd->device->id == id &&
999 ioc->scsi_lookup[i].scmd->device->channel == channel &&
1000 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
1006 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1011 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1012 * @ioc: per adapter object
1013 * @smid: smid associated to an IO request
1015 * Returns chain tracker(from ioc->free_chain_list)
1017 static struct chain_tracker *
1018 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1020 struct chain_tracker *chain_req;
1021 unsigned long flags;
1023 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1024 if (list_empty(&ioc->free_chain_list)) {
1025 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1026 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1027 "available\n", ioc->name));
1030 chain_req = list_entry(ioc->free_chain_list.next,
1031 struct chain_tracker, tracker_list);
1032 list_del_init(&chain_req->tracker_list);
1033 list_add_tail(&chain_req->tracker_list,
1034 &ioc->scsi_lookup[smid - 1].chain_list);
1035 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1040 * _scsih_build_scatter_gather - main sg creation routine
1041 * @ioc: per adapter object
1042 * @scmd: scsi command
1043 * @smid: system request message index
1046 * The main routine that builds scatter gather table from a given
1047 * scsi request sent via the .queuecommand main handler.
1049 * Returns 0 success, anything else error
1052 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1053 struct scsi_cmnd *scmd, u16 smid)
1055 Mpi2SCSIIORequest_t *mpi_request;
1056 dma_addr_t chain_dma;
1057 struct scatterlist *sg_scmd;
1058 void *sg_local, *chain;
1063 u32 sges_in_segment;
1065 u32 sgl_flags_last_element;
1066 u32 sgl_flags_end_buffer;
1067 struct chain_tracker *chain_req;
1069 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1071 /* init scatter gather flags */
1072 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1073 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1074 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1075 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1076 << MPI2_SGE_FLAGS_SHIFT;
1077 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1078 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1079 << MPI2_SGE_FLAGS_SHIFT;
1080 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1082 sg_scmd = scsi_sglist(scmd);
1083 sges_left = scsi_dma_map(scmd);
1084 if (sges_left < 0) {
1085 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1086 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1090 sg_local = &mpi_request->SGL;
1091 sges_in_segment = ioc->max_sges_in_main_message;
1092 if (sges_left <= sges_in_segment)
1093 goto fill_in_last_segment;
1095 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1096 (sges_in_segment * ioc->sge_size))/4;
1098 /* fill in main message segment when there is a chain following */
1099 while (sges_in_segment) {
1100 if (sges_in_segment == 1)
1101 ioc->base_add_sg_single(sg_local,
1102 sgl_flags_last_element | sg_dma_len(sg_scmd),
1103 sg_dma_address(sg_scmd));
1105 ioc->base_add_sg_single(sg_local, sgl_flags |
1106 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1107 sg_scmd = sg_next(sg_scmd);
1108 sg_local += ioc->sge_size;
1113 /* initializing the chain flags and pointers */
1114 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1115 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1118 chain = chain_req->chain_buffer;
1119 chain_dma = chain_req->chain_buffer_dma;
1121 sges_in_segment = (sges_left <=
1122 ioc->max_sges_in_chain_message) ? sges_left :
1123 ioc->max_sges_in_chain_message;
1124 chain_offset = (sges_left == sges_in_segment) ?
1125 0 : (sges_in_segment * ioc->sge_size)/4;
1126 chain_length = sges_in_segment * ioc->sge_size;
1128 chain_offset = chain_offset <<
1129 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1130 chain_length += ioc->sge_size;
1132 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1133 chain_length, chain_dma);
1136 goto fill_in_last_segment;
1138 /* fill in chain segments */
1139 while (sges_in_segment) {
1140 if (sges_in_segment == 1)
1141 ioc->base_add_sg_single(sg_local,
1142 sgl_flags_last_element |
1143 sg_dma_len(sg_scmd),
1144 sg_dma_address(sg_scmd));
1146 ioc->base_add_sg_single(sg_local, sgl_flags |
1147 sg_dma_len(sg_scmd),
1148 sg_dma_address(sg_scmd));
1149 sg_scmd = sg_next(sg_scmd);
1150 sg_local += ioc->sge_size;
1155 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1158 chain = chain_req->chain_buffer;
1159 chain_dma = chain_req->chain_buffer_dma;
1163 fill_in_last_segment:
1165 /* fill the last segment */
1168 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1169 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1171 ioc->base_add_sg_single(sg_local, sgl_flags |
1172 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1173 sg_scmd = sg_next(sg_scmd);
1174 sg_local += ioc->sge_size;
1182 * _scsih_adjust_queue_depth - setting device queue depth
1183 * @sdev: scsi device struct
1184 * @qdepth: requested queue depth
1190 _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1192 struct Scsi_Host *shost = sdev->host;
1194 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1195 struct MPT2SAS_DEVICE *sas_device_priv_data;
1196 struct MPT2SAS_TARGET *sas_target_priv_data;
1197 struct _sas_device *sas_device;
1198 unsigned long flags;
1200 max_depth = shost->can_queue;
1202 /* limit max device queue for SATA to 32 */
1203 sas_device_priv_data = sdev->hostdata;
1204 if (!sas_device_priv_data)
1206 sas_target_priv_data = sas_device_priv_data->sas_target;
1207 if (!sas_target_priv_data)
1209 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1211 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1212 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1213 sas_device_priv_data->sas_target->sas_address);
1214 if (sas_device && sas_device->device_info &
1215 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1216 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1221 if (!sdev->tagged_supported)
1223 if (qdepth > max_depth)
1225 scsi_change_queue_depth(sdev, qdepth);
1229 * _scsih_change_queue_depth - setting device queue depth
1230 * @sdev: scsi device struct
1231 * @qdepth: requested queue depth
1233 * Returns queue depth.
1236 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1238 _scsih_adjust_queue_depth(sdev, qdepth);
1240 if (sdev->inquiry_len > 7)
1241 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1242 "simple(%d), scsi_level(%d), cmd_que(%d)\n",
1243 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1245 (sdev->inquiry[7] & 2) >> 1);
1247 return sdev->queue_depth;
1251 * _scsih_target_alloc - target add routine
1252 * @starget: scsi target struct
1254 * Returns 0 if ok. Any other return is assumed to be an error and
1255 * the device is ignored.
1258 _scsih_target_alloc(struct scsi_target *starget)
1260 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1261 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1262 struct MPT2SAS_TARGET *sas_target_priv_data;
1263 struct _sas_device *sas_device;
1264 struct _raid_device *raid_device;
1265 unsigned long flags;
1266 struct sas_rphy *rphy;
1268 sas_target_priv_data = kzalloc(sizeof(*sas_target_priv_data),
1270 if (!sas_target_priv_data)
1273 starget->hostdata = sas_target_priv_data;
1274 sas_target_priv_data->starget = starget;
1275 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1278 if (starget->channel == RAID_CHANNEL) {
1279 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1280 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1283 sas_target_priv_data->handle = raid_device->handle;
1284 sas_target_priv_data->sas_address = raid_device->wwid;
1285 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1286 if (ioc->is_warpdrive)
1287 sas_target_priv_data->raid_device = raid_device;
1288 raid_device->starget = starget;
1290 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1294 /* sas/sata devices */
1295 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1296 rphy = dev_to_rphy(starget->dev.parent);
1297 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1298 rphy->identify.sas_address);
1301 sas_target_priv_data->handle = sas_device->handle;
1302 sas_target_priv_data->sas_address = sas_device->sas_address;
1303 sas_device->starget = starget;
1304 sas_device->id = starget->id;
1305 sas_device->channel = starget->channel;
1306 if (test_bit(sas_device->handle, ioc->pd_handles))
1307 sas_target_priv_data->flags |=
1308 MPT_TARGET_FLAGS_RAID_COMPONENT;
1310 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1316 * _scsih_target_destroy - target destroy routine
1317 * @starget: scsi target struct
1322 _scsih_target_destroy(struct scsi_target *starget)
1324 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1325 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1326 struct MPT2SAS_TARGET *sas_target_priv_data;
1327 struct _sas_device *sas_device;
1328 struct _raid_device *raid_device;
1329 unsigned long flags;
1330 struct sas_rphy *rphy;
1332 sas_target_priv_data = starget->hostdata;
1333 if (!sas_target_priv_data)
1336 if (starget->channel == RAID_CHANNEL) {
1337 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1338 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1341 raid_device->starget = NULL;
1342 raid_device->sdev = NULL;
1344 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1348 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1349 rphy = dev_to_rphy(starget->dev.parent);
1350 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1351 rphy->identify.sas_address);
1352 if (sas_device && (sas_device->starget == starget) &&
1353 (sas_device->id == starget->id) &&
1354 (sas_device->channel == starget->channel))
1355 sas_device->starget = NULL;
1357 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1360 kfree(sas_target_priv_data);
1361 starget->hostdata = NULL;
1365 * _scsih_slave_alloc - device add routine
1366 * @sdev: scsi device struct
1368 * Returns 0 if ok. Any other return is assumed to be an error and
1369 * the device is ignored.
1372 _scsih_slave_alloc(struct scsi_device *sdev)
1374 struct Scsi_Host *shost;
1375 struct MPT2SAS_ADAPTER *ioc;
1376 struct MPT2SAS_TARGET *sas_target_priv_data;
1377 struct MPT2SAS_DEVICE *sas_device_priv_data;
1378 struct scsi_target *starget;
1379 struct _raid_device *raid_device;
1380 struct _sas_device *sas_device;
1381 unsigned long flags;
1383 sas_device_priv_data = kzalloc(sizeof(*sas_device_priv_data),
1385 if (!sas_device_priv_data)
1388 sas_device_priv_data->lun = sdev->lun;
1389 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1391 starget = scsi_target(sdev);
1392 sas_target_priv_data = starget->hostdata;
1393 sas_target_priv_data->num_luns++;
1394 sas_device_priv_data->sas_target = sas_target_priv_data;
1395 sdev->hostdata = sas_device_priv_data;
1396 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1397 sdev->no_uld_attach = 1;
1399 shost = dev_to_shost(&starget->dev);
1400 ioc = shost_priv(shost);
1401 if (starget->channel == RAID_CHANNEL) {
1402 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1403 raid_device = _scsih_raid_device_find_by_id(ioc,
1404 starget->id, starget->channel);
1406 raid_device->sdev = sdev; /* raid is single lun */
1407 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1410 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1411 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1412 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1413 sas_target_priv_data->sas_address);
1414 if (sas_device && (sas_device->starget == NULL)) {
1415 sdev_printk(KERN_INFO, sdev,
1416 "%s : sas_device->starget set to starget @ %d\n",
1417 __func__, __LINE__);
1418 sas_device->starget = starget;
1420 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1427 * _scsih_slave_destroy - device destroy routine
1428 * @sdev: scsi device struct
1433 _scsih_slave_destroy(struct scsi_device *sdev)
1435 struct MPT2SAS_TARGET *sas_target_priv_data;
1436 struct scsi_target *starget;
1437 struct Scsi_Host *shost;
1438 struct MPT2SAS_ADAPTER *ioc;
1439 struct _sas_device *sas_device;
1440 unsigned long flags;
1442 if (!sdev->hostdata)
1445 starget = scsi_target(sdev);
1446 sas_target_priv_data = starget->hostdata;
1447 sas_target_priv_data->num_luns--;
1449 shost = dev_to_shost(&starget->dev);
1450 ioc = shost_priv(shost);
1452 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1453 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1454 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1455 sas_target_priv_data->sas_address);
1456 if (sas_device && !sas_target_priv_data->num_luns)
1457 sas_device->starget = NULL;
1458 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1461 kfree(sdev->hostdata);
1462 sdev->hostdata = NULL;
1466 * _scsih_display_sata_capabilities - sata capabilities
1467 * @ioc: per adapter object
1468 * @handle: device handle
1469 * @sdev: scsi device struct
1472 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1473 u16 handle, struct scsi_device *sdev)
1475 Mpi2ConfigReply_t mpi_reply;
1476 Mpi2SasDevicePage0_t sas_device_pg0;
1481 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1482 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
1483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1484 ioc->name, __FILE__, __LINE__, __func__);
1488 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1489 MPI2_IOCSTATUS_MASK;
1490 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1491 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1492 ioc->name, __FILE__, __LINE__, __func__);
1496 flags = le16_to_cpu(sas_device_pg0.Flags);
1497 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
1499 sdev_printk(KERN_INFO, sdev,
1500 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1501 "sw_preserve(%s)\n",
1502 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1503 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1504 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1506 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1507 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1508 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1512 * _scsih_is_raid - return boolean indicating device is raid volume
1513 * @dev the device struct object
1516 _scsih_is_raid(struct device *dev)
1518 struct scsi_device *sdev = to_scsi_device(dev);
1519 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1521 if (ioc->is_warpdrive)
1523 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1527 * _scsih_get_resync - get raid volume resync percent complete
1528 * @dev the device struct object
1531 _scsih_get_resync(struct device *dev)
1533 struct scsi_device *sdev = to_scsi_device(dev);
1534 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1535 static struct _raid_device *raid_device;
1536 unsigned long flags;
1537 Mpi2RaidVolPage0_t vol_pg0;
1538 Mpi2ConfigReply_t mpi_reply;
1539 u32 volume_status_flags;
1540 u8 percent_complete;
1543 percent_complete = 0;
1545 if (ioc->is_warpdrive)
1548 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1549 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1552 handle = raid_device->handle;
1553 percent_complete = raid_device->percent_complete;
1555 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1560 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1561 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1562 sizeof(Mpi2RaidVolPage0_t))) {
1563 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1564 ioc->name, __FILE__, __LINE__, __func__);
1565 percent_complete = 0;
1569 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1570 if (!(volume_status_flags &
1571 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1572 percent_complete = 0;
1575 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1579 * _scsih_get_state - get raid volume level
1580 * @dev the device struct object
1583 _scsih_get_state(struct device *dev)
1585 struct scsi_device *sdev = to_scsi_device(dev);
1586 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1587 static struct _raid_device *raid_device;
1588 unsigned long flags;
1589 Mpi2RaidVolPage0_t vol_pg0;
1590 Mpi2ConfigReply_t mpi_reply;
1592 enum raid_state state = RAID_STATE_UNKNOWN;
1595 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1596 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1599 handle = raid_device->handle;
1600 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1605 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1606 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
1607 sizeof(Mpi2RaidVolPage0_t))) {
1608 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1609 ioc->name, __FILE__, __LINE__, __func__);
1613 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1614 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1615 state = RAID_STATE_RESYNCING;
1619 switch (vol_pg0.VolumeState) {
1620 case MPI2_RAID_VOL_STATE_OPTIMAL:
1621 case MPI2_RAID_VOL_STATE_ONLINE:
1622 state = RAID_STATE_ACTIVE;
1624 case MPI2_RAID_VOL_STATE_DEGRADED:
1625 state = RAID_STATE_DEGRADED;
1627 case MPI2_RAID_VOL_STATE_FAILED:
1628 case MPI2_RAID_VOL_STATE_MISSING:
1629 state = RAID_STATE_OFFLINE;
1633 raid_set_state(mpt2sas_raid_template, dev, state);
1637 * _scsih_set_level - set raid level
1638 * @sdev: scsi device struct
1639 * @volume_type: volume type
1642 _scsih_set_level(struct scsi_device *sdev, u8 volume_type)
1644 enum raid_level level = RAID_LEVEL_UNKNOWN;
1646 switch (volume_type) {
1647 case MPI2_RAID_VOL_TYPE_RAID0:
1648 level = RAID_LEVEL_0;
1650 case MPI2_RAID_VOL_TYPE_RAID10:
1651 level = RAID_LEVEL_10;
1653 case MPI2_RAID_VOL_TYPE_RAID1E:
1654 level = RAID_LEVEL_1E;
1656 case MPI2_RAID_VOL_TYPE_RAID1:
1657 level = RAID_LEVEL_1;
1661 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1665 * _scsih_get_volume_capabilities - volume capabilities
1666 * @ioc: per adapter object
1667 * @sas_device: the raid_device object
1669 * Returns 0 for success, else 1
1672 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1673 struct _raid_device *raid_device)
1675 Mpi2RaidVolPage0_t *vol_pg0;
1676 Mpi2RaidPhysDiskPage0_t pd_pg0;
1677 Mpi2SasDevicePage0_t sas_device_pg0;
1678 Mpi2ConfigReply_t mpi_reply;
1682 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1683 &num_pds)) || !num_pds) {
1684 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1685 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1690 raid_device->num_pds = num_pds;
1691 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1692 sizeof(Mpi2RaidVol0PhysDisk_t));
1693 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1695 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1696 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1701 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1702 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1703 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1704 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1710 raid_device->volume_type = vol_pg0->VolumeType;
1712 /* figure out what the underlying devices are by
1713 * obtaining the device_info bits for the 1st device
1715 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1716 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1717 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1718 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1719 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1720 le16_to_cpu(pd_pg0.DevHandle)))) {
1721 raid_device->device_info =
1722 le32_to_cpu(sas_device_pg0.DeviceInfo);
1730 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1731 * @ioc: per adapter object
1734 _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1736 Mpi2RaidVolPage1_t vol_pg1;
1737 Mpi2ConfigReply_t mpi_reply;
1738 struct _raid_device *raid_device;
1741 unsigned long flags;
1744 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1745 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1746 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1747 MPI2_IOCSTATUS_MASK;
1748 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1750 handle = le16_to_cpu(vol_pg1.DevHandle);
1751 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1752 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1754 raid_device->direct_io_enabled = 0;
1755 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1762 * _scsih_get_num_volumes - Get number of volumes in the ioc
1763 * @ioc: per adapter object
1766 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1768 Mpi2RaidVolPage1_t vol_pg1;
1769 Mpi2ConfigReply_t mpi_reply;
1775 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1776 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1777 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1778 MPI2_IOCSTATUS_MASK;
1779 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1782 handle = le16_to_cpu(vol_pg1.DevHandle);
1789 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1790 * @ioc: per adapter object
1791 * @raid_device: the raid_device object
1794 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1795 struct _raid_device *raid_device)
1797 Mpi2RaidVolPage0_t *vol_pg0;
1798 Mpi2RaidPhysDiskPage0_t pd_pg0;
1799 Mpi2ConfigReply_t mpi_reply;
1802 unsigned long stripe_sz, block_sz;
1803 u8 stripe_exp, block_exp;
1806 if (!ioc->is_warpdrive)
1809 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1810 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1811 "globally as drives are exposed\n", ioc->name);
1814 if (_scsih_get_num_volumes(ioc) > 1) {
1815 _scsih_disable_ddio(ioc);
1816 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1817 "globally as number of drives > 1\n", ioc->name);
1820 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1821 &num_pds)) || !num_pds) {
1822 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1823 "Failure in computing number of drives\n", ioc->name);
1827 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1828 sizeof(Mpi2RaidVol0PhysDisk_t));
1829 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1831 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1832 "Memory allocation failure for RVPG0\n", ioc->name);
1836 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1837 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1838 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1839 "Failure in retrieving RVPG0\n", ioc->name);
1845 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1846 * assumed for WARPDRIVE, disable direct I/O
1848 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1849 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1850 "for the drive with handle(0x%04x): num_mem=%d, "
1851 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1852 num_pds, MPT_MAX_WARPDRIVE_PDS);
1856 for (count = 0; count < num_pds; count++) {
1857 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1858 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1859 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1860 le16_to_cpu(pd_pg0.DevHandle) ==
1861 MPT2SAS_INVALID_DEVICE_HANDLE) {
1862 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1863 "disabled for the drive with handle(0x%04x) member"
1864 "handle retrieval failed for member number=%d\n",
1865 ioc->name, raid_device->handle,
1866 vol_pg0->PhysDisk[count].PhysDiskNum);
1869 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1870 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1871 if (dev_max_lba >> 32) {
1872 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1873 "disabled for the drive with handle(0x%04x) member"
1874 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1875 ioc->name, raid_device->handle,
1876 le16_to_cpu(pd_pg0.DevHandle),
1877 (unsigned long long)dev_max_lba);
1881 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1885 * Assumption for WD: Direct I/O is not supported if the volume is
1888 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
1889 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1890 "for the drive with handle(0x%04x): type=%d, "
1891 "s_sz=%uK, blk_size=%u\n", ioc->name,
1892 raid_device->handle, raid_device->volume_type,
1893 (le32_to_cpu(vol_pg0->StripeSize) *
1894 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
1895 le16_to_cpu(vol_pg0->BlockSize));
1899 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1900 stripe_exp = find_first_bit(&stripe_sz, 32);
1901 if (stripe_exp == 32) {
1902 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1903 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1904 ioc->name, raid_device->handle,
1905 (le32_to_cpu(vol_pg0->StripeSize) *
1906 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
1909 raid_device->stripe_exponent = stripe_exp;
1910 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1911 block_exp = find_first_bit(&block_sz, 16);
1912 if (block_exp == 16) {
1913 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1914 "for the drive with handle(0x%04x) invalid block sz %u\n",
1915 ioc->name, raid_device->handle,
1916 le16_to_cpu(vol_pg0->BlockSize));
1919 raid_device->block_exponent = block_exp;
1920 raid_device->direct_io_enabled = 1;
1922 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1923 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1925 * WARPDRIVE: Though the following fields are not used for direct IO,
1926 * stored for future purpose:
1928 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1929 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1930 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1937 raid_device->direct_io_enabled = 0;
1938 for (count = 0; count < num_pds; count++)
1939 raid_device->pd_handle[count] = 0;
1945 * _scsih_enable_tlr - setting TLR flags
1946 * @ioc: per adapter object
1947 * @sdev: scsi device struct
1949 * Enabling Transaction Layer Retries for tape devices when
1950 * vpd page 0x90 is present
1954 _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1957 if (sdev->type != TYPE_TAPE)
1960 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1963 sas_enable_tlr(sdev);
1964 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1965 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1971 * _scsih_slave_configure - device configure routine.
1972 * @sdev: scsi device struct
1974 * Returns 0 if ok. Any other return is assumed to be an error and
1975 * the device is ignored.
1978 _scsih_slave_configure(struct scsi_device *sdev)
1980 struct Scsi_Host *shost = sdev->host;
1981 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1982 struct MPT2SAS_DEVICE *sas_device_priv_data;
1983 struct MPT2SAS_TARGET *sas_target_priv_data;
1984 struct _sas_device *sas_device;
1985 struct _raid_device *raid_device;
1986 unsigned long flags;
1991 u16 handle, volume_handle = 0;
1992 u64 volume_wwid = 0;
1995 sas_device_priv_data = sdev->hostdata;
1996 sas_device_priv_data->configured_lun = 1;
1997 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1998 sas_target_priv_data = sas_device_priv_data->sas_target;
1999 handle = sas_target_priv_data->handle;
2001 /* raid volume handling */
2002 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
2004 spin_lock_irqsave(&ioc->raid_device_lock, flags);
2005 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
2006 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2008 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2009 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2010 __LINE__, __func__));
2014 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2015 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2016 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2017 __LINE__, __func__));
2021 * WARPDRIVE: Initialize the required data for Direct IO
2023 _scsih_init_warpdrive_properties(ioc, raid_device);
2025 /* RAID Queue Depth Support
2026 * IS volume = underlying qdepth of drive type, either
2027 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2028 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2030 if (raid_device->device_info &
2031 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2032 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2035 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2036 if (raid_device->device_info &
2037 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2043 switch (raid_device->volume_type) {
2044 case MPI2_RAID_VOL_TYPE_RAID0:
2047 case MPI2_RAID_VOL_TYPE_RAID1E:
2048 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2049 if (ioc->manu_pg10.OEMIdentifier &&
2050 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
2051 MFG10_GF0_R10_DISPLAY) &&
2052 !(raid_device->num_pds % 2))
2057 case MPI2_RAID_VOL_TYPE_RAID1:
2058 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2061 case MPI2_RAID_VOL_TYPE_RAID10:
2062 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2065 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2067 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2072 if (!ioc->hide_ir_msg)
2073 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2074 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2075 r_level, raid_device->handle,
2076 (unsigned long long)raid_device->wwid,
2077 raid_device->num_pds, ds);
2078 _scsih_change_queue_depth(sdev, qdepth);
2079 /* raid transport support */
2080 if (!ioc->is_warpdrive)
2081 _scsih_set_level(sdev, raid_device->volume_type);
2085 /* non-raid handling */
2086 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2087 if (mpt2sas_config_get_volume_handle(ioc, handle,
2089 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2090 "failure at %s:%d/%s()!\n", ioc->name,
2091 __FILE__, __LINE__, __func__));
2094 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2095 volume_handle, &volume_wwid)) {
2096 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2097 "failure at %s:%d/%s()!\n", ioc->name,
2098 __FILE__, __LINE__, __func__));
2103 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2104 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2105 sas_device_priv_data->sas_target->sas_address);
2107 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2108 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2109 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2110 __LINE__, __func__));
2113 sas_device->volume_handle = volume_handle;
2114 sas_device->volume_wwid = volume_wwid;
2115 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2116 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2120 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2121 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2123 else if (sas_device->device_info &
2124 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2127 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2128 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2129 ds, sas_device->handle,
2130 (unsigned long long)sas_device->sas_address,
2132 (unsigned long long)sas_device->device_name);
2133 sdev_printk(KERN_INFO, sdev, "%s: "
2134 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2135 (unsigned long long) sas_device->enclosure_logical_id,
2138 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2140 _scsih_display_sata_capabilities(ioc, handle, sdev);
2143 _scsih_change_queue_depth(sdev, qdepth);
2146 sas_read_port_mode_page(sdev);
2147 _scsih_enable_tlr(ioc, sdev);
2153 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2154 * @sdev: scsi device struct
2155 * @bdev: pointer to block device context
2156 * @capacity: device size (in 512 byte sectors)
2157 * @params: three element array to place output:
2158 * params[0] number of heads (max 255)
2159 * params[1] number of sectors (max 63)
2160 * params[2] number of cylinders
2165 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2166 sector_t capacity, int params[])
2176 dummy = heads * sectors;
2177 cylinders = capacity;
2178 sector_div(cylinders, dummy);
2181 * Handle extended translation size for logical drives
2184 if ((ulong)capacity >= 0x200000) {
2187 dummy = heads * sectors;
2188 cylinders = capacity;
2189 sector_div(cylinders, dummy);
2194 params[1] = sectors;
2195 params[2] = cylinders;
2201 * _scsih_response_code - translation of device response code
2202 * @ioc: per adapter object
2203 * @response_code: response code returned by the device
2208 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2212 switch (response_code) {
2213 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2214 desc = "task management request completed";
2216 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2217 desc = "invalid frame";
2219 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2220 desc = "task management request not supported";
2222 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2223 desc = "task management request failed";
2225 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2226 desc = "task management request succeeded";
2228 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2229 desc = "invalid lun";
2232 desc = "overlapped tag attempted";
2234 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2235 desc = "task queued, however not sent to target";
2241 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2242 ioc->name, response_code, desc);
2246 * _scsih_tm_done - tm completion routine
2247 * @ioc: per adapter object
2248 * @smid: system request message index
2249 * @msix_index: MSIX table index supplied by the OS
2250 * @reply: reply message frame(lower 32bit addr)
2253 * The callback handler when using scsih_issue_tm.
2255 * Return 1 meaning mf should be freed from _base_interrupt
2256 * 0 means the mf is freed from this function.
2259 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
2261 MPI2DefaultReply_t *mpi_reply;
2263 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
2265 if (ioc->tm_cmds.smid != smid)
2267 mpt2sas_base_flush_reply_queues(ioc);
2268 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2269 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2271 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2272 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2274 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2275 complete(&ioc->tm_cmds.done);
2280 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2281 * @ioc: per adapter object
2282 * @handle: device handle
2284 * During taskmangement request, we need to freeze the device queue.
2287 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2289 struct MPT2SAS_DEVICE *sas_device_priv_data;
2290 struct scsi_device *sdev;
2293 shost_for_each_device(sdev, ioc->shost) {
2296 sas_device_priv_data = sdev->hostdata;
2297 if (!sas_device_priv_data)
2299 if (sas_device_priv_data->sas_target->handle == handle) {
2300 sas_device_priv_data->sas_target->tm_busy = 1;
2302 ioc->ignore_loginfos = 1;
2308 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2309 * @ioc: per adapter object
2310 * @handle: device handle
2312 * During taskmangement request, we need to freeze the device queue.
2315 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2317 struct MPT2SAS_DEVICE *sas_device_priv_data;
2318 struct scsi_device *sdev;
2321 shost_for_each_device(sdev, ioc->shost) {
2324 sas_device_priv_data = sdev->hostdata;
2325 if (!sas_device_priv_data)
2327 if (sas_device_priv_data->sas_target->handle == handle) {
2328 sas_device_priv_data->sas_target->tm_busy = 0;
2330 ioc->ignore_loginfos = 0;
2337 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2338 * @ioc: per adapter struct
2339 * @device_handle: device handle
2340 * @channel: the channel assigned by the OS
2341 * @id: the id assigned by the OS
2343 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2344 * @smid_task: smid assigned to the task
2345 * @timeout: timeout in seconds
2346 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2349 * A generic API for sending task management requests to firmware.
2351 * The callback index is set inside `ioc->tm_cb_idx`.
2353 * Return SUCCESS or FAILED.
2356 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2357 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
2358 enum mutex_type m_type)
2360 Mpi2SCSITaskManagementRequest_t *mpi_request;
2361 Mpi2SCSITaskManagementReply_t *mpi_reply;
2364 unsigned long timeleft;
2365 struct scsiio_tracker *scsi_lookup = NULL;
2368 if (m_type == TM_MUTEX_ON)
2369 mutex_lock(&ioc->tm_cmds.mutex);
2370 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2371 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2372 __func__, ioc->name);
2377 if (ioc->shost_recovery || ioc->remove_host ||
2378 ioc->pci_error_recovery) {
2379 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2380 __func__, ioc->name);
2385 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2386 if (ioc_state & MPI2_DOORBELL_USED) {
2387 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
2388 "active!\n", ioc->name));
2389 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2391 rc = (!rc) ? SUCCESS : FAILED;
2395 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2396 mpt2sas_base_fault_info(ioc, ioc_state &
2397 MPI2_DOORBELL_DATA_MASK);
2398 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2400 rc = (!rc) ? SUCCESS : FAILED;
2404 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
2406 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2407 ioc->name, __func__);
2412 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2413 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2415 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
2416 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2418 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2419 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2420 ioc->tm_cmds.smid = smid;
2421 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2422 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
2423 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2424 mpi_request->DevHandle = cpu_to_le16(handle);
2425 mpi_request->TaskType = type;
2426 mpi_request->TaskMID = cpu_to_le16(smid_task);
2427 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2428 mpt2sas_scsih_set_tm_flag(ioc, handle);
2429 init_completion(&ioc->tm_cmds.done);
2430 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2431 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
2432 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2433 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2434 ioc->name, __func__);
2435 _debug_dump_mf(mpi_request,
2436 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2437 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
2438 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2440 rc = (!rc) ? SUCCESS : FAILED;
2441 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2442 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2447 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2448 mpi_reply = ioc->tm_cmds.reply;
2449 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2450 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2451 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2452 le32_to_cpu(mpi_reply->IOCLogInfo),
2453 le32_to_cpu(mpi_reply->TerminationCount)));
2454 if (ioc->logging_level & MPT_DEBUG_TM) {
2455 _scsih_response_code(ioc, mpi_reply->ResponseCode);
2456 if (mpi_reply->IOCStatus)
2457 _debug_dump_mf(mpi_request,
2458 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2463 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2465 if (scsi_lookup->scmd == NULL)
2470 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2471 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2477 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
2478 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2479 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2484 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2492 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2493 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2494 if (m_type == TM_MUTEX_ON)
2495 mutex_unlock(&ioc->tm_cmds.mutex);
2500 if (m_type == TM_MUTEX_ON)
2501 mutex_unlock(&ioc->tm_cmds.mutex);
2506 * _scsih_tm_display_info - displays info about the device
2507 * @ioc: per adapter struct
2508 * @scmd: pointer to scsi command object
2510 * Called by task management callback handlers.
2513 _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2515 struct scsi_target *starget = scmd->device->sdev_target;
2516 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2517 struct _sas_device *sas_device = NULL;
2518 unsigned long flags;
2519 char *device_str = NULL;
2523 if (ioc->hide_ir_msg)
2524 device_str = "WarpDrive";
2526 device_str = "volume";
2528 scsi_print_command(scmd);
2529 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2530 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2531 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2532 device_str, (unsigned long long)priv_target->sas_address);
2534 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2535 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2536 priv_target->sas_address);
2538 if (priv_target->flags &
2539 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2540 starget_printk(KERN_INFO, starget,
2541 "volume handle(0x%04x), "
2542 "volume wwid(0x%016llx)\n",
2543 sas_device->volume_handle,
2544 (unsigned long long)sas_device->volume_wwid);
2546 starget_printk(KERN_INFO, starget,
2547 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2549 (unsigned long long)sas_device->sas_address,
2551 starget_printk(KERN_INFO, starget,
2552 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2553 (unsigned long long)sas_device->enclosure_logical_id,
2556 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2561 * _scsih_abort - eh threads main abort routine
2562 * @scmd: pointer to scsi command object
2564 * Returns SUCCESS if command aborted else FAILED
2567 _scsih_abort(struct scsi_cmnd *scmd)
2569 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2570 struct MPT2SAS_DEVICE *sas_device_priv_data;
2575 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2576 "scmd(%p)\n", scmd);
2577 _scsih_tm_display_info(ioc, scmd);
2579 sas_device_priv_data = scmd->device->hostdata;
2580 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2581 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2582 "scmd(%p)\n", scmd);
2583 scmd->result = DID_NO_CONNECT << 16;
2584 scmd->scsi_done(scmd);
2589 /* search for the command */
2590 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2592 scmd->result = DID_RESET << 16;
2597 /* for hidden raid components and volumes this is not supported */
2598 if (sas_device_priv_data->sas_target->flags &
2599 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2600 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2601 scmd->result = DID_RESET << 16;
2606 mpt2sas_halt_firmware(ioc);
2608 handle = sas_device_priv_data->sas_target->handle;
2609 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2610 scmd->device->id, scmd->device->lun,
2611 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30, TM_MUTEX_ON);
2614 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2615 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2620 * _scsih_dev_reset - eh threads main device reset routine
2621 * @scmd: pointer to scsi command object
2623 * Returns SUCCESS if command aborted else FAILED
2626 _scsih_dev_reset(struct scsi_cmnd *scmd)
2628 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2629 struct MPT2SAS_DEVICE *sas_device_priv_data;
2630 struct _sas_device *sas_device;
2631 unsigned long flags;
2635 struct scsi_target *starget = scmd->device->sdev_target;
2637 starget_printk(KERN_INFO, starget, "attempting device reset! "
2638 "scmd(%p)\n", scmd);
2639 _scsih_tm_display_info(ioc, scmd);
2641 sas_device_priv_data = scmd->device->hostdata;
2642 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2643 starget_printk(KERN_INFO, starget, "device been deleted! "
2644 "scmd(%p)\n", scmd);
2645 scmd->result = DID_NO_CONNECT << 16;
2646 scmd->scsi_done(scmd);
2651 /* for hidden raid components obtain the volume_handle */
2653 if (sas_device_priv_data->sas_target->flags &
2654 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2655 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2656 sas_device = _scsih_sas_device_find_by_handle(ioc,
2657 sas_device_priv_data->sas_target->handle);
2659 handle = sas_device->volume_handle;
2660 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2662 handle = sas_device_priv_data->sas_target->handle;
2665 scmd->result = DID_RESET << 16;
2670 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2671 scmd->device->id, scmd->device->lun,
2672 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, TM_MUTEX_ON);
2675 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2676 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2681 * _scsih_target_reset - eh threads main target reset routine
2682 * @scmd: pointer to scsi command object
2684 * Returns SUCCESS if command aborted else FAILED
2687 _scsih_target_reset(struct scsi_cmnd *scmd)
2689 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2690 struct MPT2SAS_DEVICE *sas_device_priv_data;
2691 struct _sas_device *sas_device;
2692 unsigned long flags;
2695 struct scsi_target *starget = scmd->device->sdev_target;
2697 starget_printk(KERN_INFO, starget, "attempting target reset! "
2698 "scmd(%p)\n", scmd);
2699 _scsih_tm_display_info(ioc, scmd);
2701 sas_device_priv_data = scmd->device->hostdata;
2702 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2703 starget_printk(KERN_INFO, starget, "target been deleted! "
2704 "scmd(%p)\n", scmd);
2705 scmd->result = DID_NO_CONNECT << 16;
2706 scmd->scsi_done(scmd);
2711 /* for hidden raid components obtain the volume_handle */
2713 if (sas_device_priv_data->sas_target->flags &
2714 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2715 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2716 sas_device = _scsih_sas_device_find_by_handle(ioc,
2717 sas_device_priv_data->sas_target->handle);
2719 handle = sas_device->volume_handle;
2720 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2722 handle = sas_device_priv_data->sas_target->handle;
2725 scmd->result = DID_RESET << 16;
2730 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2731 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
2735 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2736 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2741 * _scsih_host_reset - eh threads main host reset routine
2742 * @scmd: pointer to scsi command object
2744 * Returns SUCCESS if command aborted else FAILED
2747 _scsih_host_reset(struct scsi_cmnd *scmd)
2749 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2752 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2754 scsi_print_command(scmd);
2756 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2758 r = (retval < 0) ? FAILED : SUCCESS;
2759 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2760 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2766 * _scsih_fw_event_add - insert and queue up fw_event
2767 * @ioc: per adapter object
2768 * @fw_event: object describing the event
2769 * Context: This function will acquire ioc->fw_event_lock.
2771 * This adds the firmware event object into link list, then queues it up to
2772 * be processed from user context.
2777 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2779 unsigned long flags;
2781 if (ioc->firmware_event_thread == NULL)
2784 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2785 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2786 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2787 queue_delayed_work(ioc->firmware_event_thread,
2788 &fw_event->delayed_work, 0);
2789 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2793 * _scsih_fw_event_free - delete fw_event
2794 * @ioc: per adapter object
2795 * @fw_event: object describing the event
2796 * Context: This function will acquire ioc->fw_event_lock.
2798 * This removes firmware event object from link list, frees associated memory.
2803 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2806 unsigned long flags;
2808 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2809 list_del(&fw_event->list);
2811 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2816 * _scsih_error_recovery_delete_devices - remove devices not responding
2817 * @ioc: per adapter object
2822 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2824 struct fw_event_work *fw_event;
2826 if (ioc->is_driver_loading)
2829 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2833 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2834 fw_event->ioc = ioc;
2835 _scsih_fw_event_add(ioc, fw_event);
2839 * mpt2sas_port_enable_complete - port enable completed (fake event)
2840 * @ioc: per adapter object
2845 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2847 struct fw_event_work *fw_event;
2849 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2852 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2853 fw_event->ioc = ioc;
2854 _scsih_fw_event_add(ioc, fw_event);
2858 * _scsih_fw_event_cleanup_queue - cleanup event queue
2859 * @ioc: per adapter object
2861 * Walk the firmware event queue, either killing timers, or waiting
2862 * for outstanding events to complete
2867 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2869 struct fw_event_work *fw_event, *next;
2871 if (list_empty(&ioc->fw_event_list) ||
2872 !ioc->firmware_event_thread || in_interrupt())
2875 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2876 if (cancel_delayed_work_sync(&fw_event->delayed_work)) {
2877 _scsih_fw_event_free(ioc, fw_event);
2884 * _scsih_ublock_io_all_device - unblock every device
2885 * @ioc: per adapter object
2887 * change the device state from block to running
2890 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
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 sas_device_priv_data->block = 0;
2902 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2904 sas_device_priv_data->sas_target->handle));
2905 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2909 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2910 * @ioc: per adapter object
2911 * @handle: device handle
2913 * During device pull we need to appropiately set the sdev state.
2916 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
2918 struct MPT2SAS_DEVICE *sas_device_priv_data;
2919 struct scsi_device *sdev;
2921 shost_for_each_device(sdev, ioc->shost) {
2922 sas_device_priv_data = sdev->hostdata;
2923 if (!sas_device_priv_data)
2925 if (!sas_device_priv_data->block)
2927 if (sas_device_priv_data->sas_target->sas_address ==
2929 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2930 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2931 "sas address(0x%016llx)\n", ioc->name,
2932 (unsigned long long)sas_address));
2933 sas_device_priv_data->block = 0;
2934 scsi_internal_device_unblock(sdev, SDEV_RUNNING);
2940 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2941 * @ioc: per adapter object
2942 * @handle: device handle
2944 * During device pull we need to appropiately set the sdev state.
2947 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2949 struct MPT2SAS_DEVICE *sas_device_priv_data;
2950 struct scsi_device *sdev;
2952 shost_for_each_device(sdev, ioc->shost) {
2953 sas_device_priv_data = sdev->hostdata;
2954 if (!sas_device_priv_data)
2956 if (sas_device_priv_data->block)
2958 sas_device_priv_data->block = 1;
2959 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2961 sas_device_priv_data->sas_target->handle));
2962 scsi_internal_device_block(sdev);
2968 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2969 * @ioc: per adapter object
2970 * @handle: device handle
2972 * During device pull we need to appropiately set the sdev state.
2975 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2977 struct MPT2SAS_DEVICE *sas_device_priv_data;
2978 struct scsi_device *sdev;
2980 shost_for_each_device(sdev, ioc->shost) {
2981 sas_device_priv_data = sdev->hostdata;
2982 if (!sas_device_priv_data)
2984 if (sas_device_priv_data->block)
2986 if (sas_device_priv_data->sas_target->handle == handle) {
2987 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2988 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2989 "handle(0x%04x)\n", ioc->name, handle));
2990 sas_device_priv_data->block = 1;
2991 scsi_internal_device_block(sdev);
2997 * _scsih_block_io_to_children_attached_to_ex
2998 * @ioc: per adapter object
2999 * @sas_expander: the sas_device object
3001 * This routine set sdev state to SDEV_BLOCK for all devices
3002 * attached to this expander. This function called when expander is
3006 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3007 struct _sas_node *sas_expander)
3009 struct _sas_port *mpt2sas_port;
3010 struct _sas_device *sas_device;
3011 struct _sas_node *expander_sibling;
3012 unsigned long flags;
3017 list_for_each_entry(mpt2sas_port,
3018 &sas_expander->sas_port_list, port_list) {
3019 if (mpt2sas_port->remote_identify.device_type ==
3021 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3023 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3024 mpt2sas_port->remote_identify.sas_address);
3026 set_bit(sas_device->handle,
3027 ioc->blocking_handles);
3028 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3032 list_for_each_entry(mpt2sas_port,
3033 &sas_expander->sas_port_list, port_list) {
3035 if (mpt2sas_port->remote_identify.device_type ==
3036 SAS_EDGE_EXPANDER_DEVICE ||
3037 mpt2sas_port->remote_identify.device_type ==
3038 SAS_FANOUT_EXPANDER_DEVICE) {
3040 mpt2sas_scsih_expander_find_by_sas_address(
3041 ioc, mpt2sas_port->remote_identify.sas_address);
3042 _scsih_block_io_to_children_attached_to_ex(ioc,
3049 * _scsih_block_io_to_children_attached_directly
3050 * @ioc: per adapter object
3051 * @event_data: topology change event data
3053 * This routine set sdev state to SDEV_BLOCK for all devices
3054 * direct attached during device pull.
3057 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3058 Mpi2EventDataSasTopologyChangeList_t *event_data)
3065 for (i = 0; i < event_data->NumEntries; i++) {
3066 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3069 phy_number = event_data->StartPhyNum + i;
3070 reason_code = event_data->PHY[i].PhyStatus &
3071 MPI2_EVENT_SAS_TOPO_RC_MASK;
3072 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3073 _scsih_block_io_device(ioc, handle);
3078 * _scsih_tm_tr_send - send task management request
3079 * @ioc: per adapter object
3080 * @handle: device handle
3081 * Context: interrupt time.
3083 * This code is to initiate the device removal handshake protocol
3084 * with controller firmware. This function will issue target reset
3085 * using high priority request queue. It will send a sas iounit
3086 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3088 * This is designed to send muliple task management request at the same
3089 * time to the fifo. If the fifo is full, we will append the request,
3090 * and process it in a future completion.
3093 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3095 Mpi2SCSITaskManagementRequest_t *mpi_request;
3097 struct _sas_device *sas_device;
3098 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3099 u64 sas_address = 0;
3100 unsigned long flags;
3101 struct _tr_list *delayed_tr;
3104 if (ioc->remove_host) {
3105 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3106 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3108 } else if (ioc->pci_error_recovery) {
3109 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3110 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3114 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3115 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3116 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3117 "operational: handle(0x%04x)\n", __func__, ioc->name,
3122 /* if PD, then return */
3123 if (test_bit(handle, ioc->pd_handles))
3126 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3127 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3128 if (sas_device && sas_device->starget &&
3129 sas_device->starget->hostdata) {
3130 sas_target_priv_data = sas_device->starget->hostdata;
3131 sas_target_priv_data->deleted = 1;
3132 sas_address = sas_device->sas_address;
3134 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3136 if (sas_target_priv_data) {
3137 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3138 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3139 (unsigned long long)sas_address));
3140 _scsih_ublock_io_device(ioc, sas_address);
3141 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3144 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3146 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3149 INIT_LIST_HEAD(&delayed_tr->list);
3150 delayed_tr->handle = handle;
3151 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3152 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3153 "DELAYED:tr:handle(0x%04x), (open)\n",
3154 ioc->name, handle));
3158 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3159 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3160 ioc->tm_tr_cb_idx));
3161 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3162 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3163 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3164 mpi_request->DevHandle = cpu_to_le16(handle);
3165 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3166 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3172 * _scsih_sas_control_complete - completion routine
3173 * @ioc: per adapter object
3174 * @smid: system request message index
3175 * @msix_index: MSIX table index supplied by the OS
3176 * @reply: reply message frame(lower 32bit addr)
3177 * Context: interrupt time.
3179 * This is the sas iounit control completion routine.
3180 * This code is part of the code to initiate the device removal
3181 * handshake protocol with controller firmware.
3183 * Return 1 meaning mf should be freed from _base_interrupt
3184 * 0 means the mf is freed from this function.
3187 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3188 u8 msix_index, u32 reply)
3190 Mpi2SasIoUnitControlReply_t *mpi_reply =
3191 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3192 if (likely(mpi_reply)) {
3193 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3194 "sc_complete:handle(0x%04x), (open) "
3195 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3196 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3197 le16_to_cpu(mpi_reply->IOCStatus),
3198 le32_to_cpu(mpi_reply->IOCLogInfo)));
3200 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3201 ioc->name, __FILE__, __LINE__, __func__);
3207 * _scsih_tm_tr_volume_send - send target reset request for volumes
3208 * @ioc: per adapter object
3209 * @handle: device handle
3210 * Context: interrupt time.
3212 * This is designed to send muliple task management request at the same
3213 * time to the fifo. If the fifo is full, we will append the request,
3214 * and process it in a future completion.
3217 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3219 Mpi2SCSITaskManagementRequest_t *mpi_request;
3221 struct _tr_list *delayed_tr;
3223 if (ioc->shost_recovery || ioc->remove_host ||
3224 ioc->pci_error_recovery) {
3225 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3226 "progress!\n", __func__, ioc->name));
3230 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3232 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3235 INIT_LIST_HEAD(&delayed_tr->list);
3236 delayed_tr->handle = handle;
3237 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3238 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3239 "DELAYED:tr:handle(0x%04x), (open)\n",
3240 ioc->name, handle));
3244 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3245 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3246 ioc->tm_tr_volume_cb_idx));
3247 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3248 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3249 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3250 mpi_request->DevHandle = cpu_to_le16(handle);
3251 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3252 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3256 * _scsih_tm_volume_tr_complete - target reset completion
3257 * @ioc: per adapter object
3258 * @smid: system request message index
3259 * @msix_index: MSIX table index supplied by the OS
3260 * @reply: reply message frame(lower 32bit addr)
3261 * Context: interrupt time.
3263 * Return 1 meaning mf should be freed from _base_interrupt
3264 * 0 means the mf is freed from this function.
3267 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3268 u8 msix_index, u32 reply)
3271 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3272 Mpi2SCSITaskManagementReply_t *mpi_reply =
3273 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3275 if (ioc->shost_recovery || ioc->remove_host ||
3276 ioc->pci_error_recovery) {
3277 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3278 "progress!\n", __func__, ioc->name));
3281 if (unlikely(!mpi_reply)) {
3282 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3283 ioc->name, __FILE__, __LINE__, __func__);
3286 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3287 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3288 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3289 dewtprintk(ioc, printk("spurious interrupt: "
3290 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3291 le16_to_cpu(mpi_reply->DevHandle), smid));
3295 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3296 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3297 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3298 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3299 le32_to_cpu(mpi_reply->IOCLogInfo),
3300 le32_to_cpu(mpi_reply->TerminationCount)));
3302 return _scsih_check_for_pending_tm(ioc, smid);
3306 * _scsih_tm_tr_complete -
3307 * @ioc: per adapter object
3308 * @smid: system request message index
3309 * @msix_index: MSIX table index supplied by the OS
3310 * @reply: reply message frame(lower 32bit addr)
3311 * Context: interrupt time.
3313 * This is the target reset completion routine.
3314 * This code is part of the code to initiate the device removal
3315 * handshake protocol with controller firmware.
3316 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3318 * Return 1 meaning mf should be freed from _base_interrupt
3319 * 0 means the mf is freed from this function.
3322 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3326 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3327 Mpi2SCSITaskManagementReply_t *mpi_reply =
3328 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3329 Mpi2SasIoUnitControlRequest_t *mpi_request;
3333 if (ioc->remove_host) {
3334 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3335 "removed\n", __func__, ioc->name));
3337 } else if (ioc->pci_error_recovery) {
3338 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3339 "error recovery\n", __func__, ioc->name));
3342 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3343 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3344 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3345 "operational\n", __func__, ioc->name));
3348 if (unlikely(!mpi_reply)) {
3349 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
3350 ioc->name, __FILE__, __LINE__, __func__);
3353 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3354 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3355 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3356 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3357 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3358 le16_to_cpu(mpi_reply->DevHandle), smid));
3362 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3363 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3364 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3365 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3366 le32_to_cpu(mpi_reply->IOCLogInfo),
3367 le32_to_cpu(mpi_reply->TerminationCount)));
3369 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3370 if (!smid_sas_ctrl) {
3371 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3372 ioc->name, __func__);
3376 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3377 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3378 ioc->tm_sas_control_cb_idx));
3379 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3380 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3381 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3382 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3383 mpi_request->DevHandle = mpi_request_tm->DevHandle;
3384 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
3386 return _scsih_check_for_pending_tm(ioc, smid);
3390 * _scsih_check_for_pending_tm - check for pending task management
3391 * @ioc: per adapter object
3392 * @smid: system request message index
3394 * This will check delayed target reset list, and feed the
3397 * Return 1 meaning mf should be freed from _base_interrupt
3398 * 0 means the mf is freed from this function.
3401 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3403 struct _tr_list *delayed_tr;
3405 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3406 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3407 struct _tr_list, list);
3408 mpt2sas_base_free_smid(ioc, smid);
3409 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3410 list_del(&delayed_tr->list);
3415 if (!list_empty(&ioc->delayed_tr_list)) {
3416 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3417 struct _tr_list, list);
3418 mpt2sas_base_free_smid(ioc, smid);
3419 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3420 list_del(&delayed_tr->list);
3429 * _scsih_check_topo_delete_events - sanity check on topo events
3430 * @ioc: per adapter object
3431 * @event_data: the event data payload
3433 * This routine added to better handle cable breaker.
3435 * This handles the case where driver receives multiple expander
3436 * add and delete events in a single shot. When there is a delete event
3437 * the routine will void any pending add events waiting in the event queue.
3442 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3443 Mpi2EventDataSasTopologyChangeList_t *event_data)
3445 struct fw_event_work *fw_event;
3446 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3447 u16 expander_handle;
3448 struct _sas_node *sas_expander;
3449 unsigned long flags;
3453 for (i = 0 ; i < event_data->NumEntries; i++) {
3454 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3457 reason_code = event_data->PHY[i].PhyStatus &
3458 MPI2_EVENT_SAS_TOPO_RC_MASK;
3459 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3460 _scsih_tm_tr_send(ioc, handle);
3463 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3464 if (expander_handle < ioc->sas_hba.num_phys) {
3465 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3468 if (event_data->ExpStatus ==
3469 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3470 /* put expander attached devices into blocking state */
3471 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3472 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3474 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3475 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3477 handle = find_first_bit(ioc->blocking_handles,
3478 ioc->facts.MaxDevHandle);
3479 if (handle < ioc->facts.MaxDevHandle)
3480 _scsih_block_io_device(ioc, handle);
3481 } while (test_and_clear_bit(handle, ioc->blocking_handles));
3482 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3483 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3485 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3488 /* mark ignore flag for pending events */
3489 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3490 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3491 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3494 local_event_data = (Mpi2EventDataSasTopologyChangeList_t *)
3495 fw_event->event_data;
3496 if (local_event_data->ExpStatus ==
3497 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3498 local_event_data->ExpStatus ==
3499 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3500 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3502 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3503 "setting ignoring flag\n", ioc->name));
3504 fw_event->ignore = 1;
3508 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3512 * _scsih_set_volume_delete_flag - setting volume delete flag
3513 * @ioc: per adapter object
3514 * @handle: device handle
3520 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3522 struct _raid_device *raid_device;
3523 struct MPT2SAS_TARGET *sas_target_priv_data;
3524 unsigned long flags;
3526 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3527 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3528 if (raid_device && raid_device->starget &&
3529 raid_device->starget->hostdata) {
3530 sas_target_priv_data =
3531 raid_device->starget->hostdata;
3532 sas_target_priv_data->deleted = 1;
3533 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3534 "setting delete flag: handle(0x%04x), "
3535 "wwid(0x%016llx)\n", ioc->name, handle,
3536 (unsigned long long) raid_device->wwid));
3538 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3542 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3543 * @handle: input handle
3544 * @a: handle for volume a
3545 * @b: handle for volume b
3547 * IR firmware only supports two raid volumes. The purpose of this
3548 * routine is to set the volume handle in either a or b. When the given
3549 * input handle is non-zero, or when a and b have not been set before.
3552 _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3554 if (!handle || handle == *a || handle == *b)
3563 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3564 * @ioc: per adapter object
3565 * @event_data: the event data payload
3566 * Context: interrupt time.
3568 * This routine will send target reset to volume, followed by target
3569 * resets to the PDs. This is called when a PD has been removed, or
3570 * volume has been deleted or removed. When the target reset is sent
3571 * to volume, the PD target resets need to be queued to start upon
3572 * completion of the volume target reset.
3577 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3578 Mpi2EventDataIrConfigChangeList_t *event_data)
3580 Mpi2EventIrConfigElement_t *element;
3582 u16 handle, volume_handle, a, b;
3583 struct _tr_list *delayed_tr;
3588 if (ioc->is_warpdrive)
3591 /* Volume Resets for Deleted or Removed */
3592 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3593 for (i = 0; i < event_data->NumElements; i++, element++) {
3594 if (element->ReasonCode ==
3595 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3596 element->ReasonCode ==
3597 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3598 volume_handle = le16_to_cpu(element->VolDevHandle);
3599 _scsih_set_volume_delete_flag(ioc, volume_handle);
3600 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3604 /* Volume Resets for UNHIDE events */
3605 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3606 for (i = 0; i < event_data->NumElements; i++, element++) {
3607 if (le32_to_cpu(event_data->Flags) &
3608 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3610 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3611 volume_handle = le16_to_cpu(element->VolDevHandle);
3612 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3617 _scsih_tm_tr_volume_send(ioc, a);
3619 _scsih_tm_tr_volume_send(ioc, b);
3621 /* PD target resets */
3622 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3623 for (i = 0; i < event_data->NumElements; i++, element++) {
3624 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3626 handle = le16_to_cpu(element->PhysDiskDevHandle);
3627 volume_handle = le16_to_cpu(element->VolDevHandle);
3628 clear_bit(handle, ioc->pd_handles);
3630 _scsih_tm_tr_send(ioc, handle);
3631 else if (volume_handle == a || volume_handle == b) {
3632 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3633 BUG_ON(!delayed_tr);
3634 INIT_LIST_HEAD(&delayed_tr->list);
3635 delayed_tr->handle = handle;
3636 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3637 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3638 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3641 _scsih_tm_tr_send(ioc, handle);
3647 * _scsih_check_volume_delete_events - set delete flag for volumes
3648 * @ioc: per adapter object
3649 * @event_data: the event data payload
3650 * Context: interrupt time.
3652 * This will handle the case when the cable connected to entire volume is
3653 * pulled. We will take care of setting the deleted flag so normal IO will
3659 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3660 Mpi2EventDataIrVolume_t *event_data)
3664 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3666 state = le32_to_cpu(event_data->NewValue);
3667 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3668 MPI2_RAID_VOL_STATE_FAILED)
3669 _scsih_set_volume_delete_flag(ioc,
3670 le16_to_cpu(event_data->VolDevHandle));
3674 * _scsih_flush_running_cmds - completing outstanding commands.
3675 * @ioc: per adapter object
3677 * The flushing out of all pending scmd commands following host reset,
3678 * where all IO is dropped to the floor.
3683 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3685 struct scsi_cmnd *scmd;
3689 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
3690 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
3694 mpt2sas_base_free_smid(ioc, smid);
3695 scsi_dma_unmap(scmd);
3696 if (ioc->pci_error_recovery)
3697 scmd->result = DID_NO_CONNECT << 16;
3699 scmd->result = DID_RESET << 16;
3700 scmd->scsi_done(scmd);
3702 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3707 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3708 * @scmd: pointer to scsi command object
3709 * @mpi_request: pointer to the SCSI_IO reqest message frame
3711 * Supporting protection 1 and 3.
3716 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3719 unsigned char prot_op = scsi_get_prot_op(scmd);
3720 unsigned char prot_type = scsi_get_prot_type(scmd);
3722 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
3725 if (prot_op == SCSI_PROT_READ_STRIP)
3726 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3727 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3728 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3732 switch (prot_type) {
3733 case SCSI_PROT_DIF_TYPE1:
3734 case SCSI_PROT_DIF_TYPE2:
3737 * enable ref/guard checking
3738 * auto increment ref tag
3740 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
3741 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3742 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3743 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3744 cpu_to_be32(scsi_get_lba(scmd));
3747 case SCSI_PROT_DIF_TYPE3:
3750 * enable guard checking
3752 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3755 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3756 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
3760 * _scsih_eedp_error_handling - return sense code for EEDP errors
3761 * @scmd: pointer to scsi command object
3762 * @ioc_status: ioc status
3767 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3771 switch (ioc_status) {
3772 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3775 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3778 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3786 scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, ascq);
3787 scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
3788 SAM_STAT_CHECK_CONDITION;
3792 * _scsih_scsi_direct_io_get - returns direct io flag
3793 * @ioc: per adapter object
3794 * @smid: system request message index
3796 * Returns the smid stored scmd pointer.
3799 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3801 return ioc->scsi_lookup[smid - 1].direct_io;
3805 * _scsih_scsi_direct_io_set - sets direct io flag
3806 * @ioc: per adapter object
3807 * @smid: system request message index
3808 * @direct_io: Zero or non-zero value to set in the direct_io flag
3813 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3815 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3820 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3821 * @ioc: per adapter object
3822 * @scmd: pointer to scsi command object
3823 * @raid_device: pointer to raid device data structure
3824 * @mpi_request: pointer to the SCSI_IO reqest message frame
3825 * @smid: system request message index
3830 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3831 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3834 sector_t v_lba, p_lba, stripe_off, column, io_size;
3835 u32 stripe_sz, stripe_exp;
3836 u8 num_pds, cmd = scmd->cmnd[0];
3838 if (cmd != READ_10 && cmd != WRITE_10 &&
3839 cmd != READ_16 && cmd != WRITE_16)
3842 if (cmd == READ_10 || cmd == WRITE_10)
3843 v_lba = get_unaligned_be32(&mpi_request->CDB.CDB32[2]);
3845 v_lba = get_unaligned_be64(&mpi_request->CDB.CDB32[2]);
3847 io_size = scsi_bufflen(scmd) >> raid_device->block_exponent;
3849 if (v_lba + io_size - 1 > raid_device->max_lba)
3852 stripe_sz = raid_device->stripe_sz;
3853 stripe_exp = raid_device->stripe_exponent;
3854 stripe_off = v_lba & (stripe_sz - 1);
3856 /* Return unless IO falls within a stripe */
3857 if (stripe_off + io_size > stripe_sz)
3860 num_pds = raid_device->num_pds;
3861 p_lba = v_lba >> stripe_exp;
3862 column = sector_div(p_lba, num_pds);
3863 p_lba = (p_lba << stripe_exp) + stripe_off;
3865 mpi_request->DevHandle = cpu_to_le16(raid_device->pd_handle[column]);
3867 if (cmd == READ_10 || cmd == WRITE_10)
3868 put_unaligned_be32(lower_32_bits(p_lba),
3869 &mpi_request->CDB.CDB32[2]);
3871 put_unaligned_be64(p_lba, &mpi_request->CDB.CDB32[2]);
3873 _scsih_scsi_direct_io_set(ioc, smid, 1);
3877 * _scsih_qcmd - main scsi request entry point
3878 * @scmd: pointer to scsi command object
3879 * @done: function pointer to be invoked on completion
3881 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3883 * Returns 0 on success. If there's a failure, return either:
3884 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3885 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3888 _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3890 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
3891 struct MPT2SAS_DEVICE *sas_device_priv_data;
3892 struct MPT2SAS_TARGET *sas_target_priv_data;
3893 struct _raid_device *raid_device;
3894 Mpi2SCSIIORequest_t *mpi_request;
3898 sas_device_priv_data = scmd->device->hostdata;
3899 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
3900 scmd->result = DID_NO_CONNECT << 16;
3901 scmd->scsi_done(scmd);
3905 if (ioc->pci_error_recovery || ioc->remove_host) {
3906 scmd->result = DID_NO_CONNECT << 16;
3907 scmd->scsi_done(scmd);
3911 sas_target_priv_data = sas_device_priv_data->sas_target;
3912 /* invalid device handle */
3913 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
3914 scmd->result = DID_NO_CONNECT << 16;
3915 scmd->scsi_done(scmd);
3919 /* host recovery or link resets sent via IOCTLs */
3920 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
3921 return SCSI_MLQUEUE_HOST_BUSY;
3922 /* device busy with task management */
3923 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3924 return SCSI_MLQUEUE_DEVICE_BUSY;
3925 /* device has been deleted */
3926 else if (sas_target_priv_data->deleted) {
3927 scmd->result = DID_NO_CONNECT << 16;
3928 scmd->scsi_done(scmd);
3932 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3933 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3934 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3935 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3937 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3940 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3942 /* Make sure Device is not raid volume.
3943 * We do not expose raid functionality to upper layer for warpdrive.
3945 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
3946 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
3947 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3949 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
3951 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3952 ioc->name, __func__);
3955 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3956 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
3957 _scsih_setup_eedp(scmd, mpi_request);
3958 if (scmd->cmd_len == 32)
3959 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
3960 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3961 if (sas_device_priv_data->sas_target->flags &
3962 MPT_TARGET_FLAGS_RAID_COMPONENT)
3963 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3965 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3966 mpi_request->DevHandle =
3967 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3968 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3969 mpi_request->Control = cpu_to_le32(mpi_control);
3970 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3971 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3972 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3973 mpi_request->SenseBufferLowAddress =
3974 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
3975 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3976 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3977 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
3978 mpi_request->VF_ID = 0; /* TODO */
3979 mpi_request->VP_ID = 0;
3980 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3982 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3984 if (!mpi_request->DataLength) {
3985 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3987 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3988 mpt2sas_base_free_smid(ioc, smid);
3993 raid_device = sas_target_priv_data->raid_device;
3994 if (raid_device && raid_device->direct_io_enabled)
3995 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3998 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3999 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4000 le16_to_cpu(mpi_request->DevHandle));
4002 mpt2sas_base_put_smid_default(ioc, smid);
4006 return SCSI_MLQUEUE_HOST_BUSY;
4010 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4011 * @sense_buffer: sense data returned by target
4012 * @data: normalized skey/asc/ascq
4017 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4019 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4020 /* descriptor format */
4021 data->skey = sense_buffer[1] & 0x0F;
4022 data->asc = sense_buffer[2];
4023 data->ascq = sense_buffer[3];
4026 data->skey = sense_buffer[2] & 0x0F;
4027 data->asc = sense_buffer[12];
4028 data->ascq = sense_buffer[13];
4032 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4034 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4035 * @ioc: per adapter object
4036 * @scmd: pointer to scsi command object
4037 * @mpi_reply: reply mf payload returned from firmware
4039 * scsi_status - SCSI Status code returned from target device
4040 * scsi_state - state info associated with SCSI_IO determined by ioc
4041 * ioc_status - ioc supplied status info
4046 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4047 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4051 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4052 MPI2_IOCSTATUS_MASK;
4053 u8 scsi_state = mpi_reply->SCSIState;
4054 u8 scsi_status = mpi_reply->SCSIStatus;
4055 char *desc_ioc_state = NULL;
4056 char *desc_scsi_status = NULL;
4057 char *desc_scsi_state = ioc->tmp_string;
4058 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4059 struct _sas_device *sas_device = NULL;
4060 unsigned long flags;
4061 struct scsi_target *starget = scmd->device->sdev_target;
4062 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
4063 char *device_str = NULL;
4068 if (ioc->hide_ir_msg)
4069 device_str = "WarpDrive";
4071 device_str = "volume";
4073 if (log_info == 0x31170000)
4076 switch (ioc_status) {
4077 case MPI2_IOCSTATUS_SUCCESS:
4078 desc_ioc_state = "success";
4080 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4081 desc_ioc_state = "invalid function";
4083 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4084 desc_ioc_state = "scsi recovered error";
4086 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4087 desc_ioc_state = "scsi invalid dev handle";
4089 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4090 desc_ioc_state = "scsi device not there";
4092 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4093 desc_ioc_state = "scsi data overrun";
4095 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4096 desc_ioc_state = "scsi data underrun";
4098 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4099 desc_ioc_state = "scsi io data error";
4101 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4102 desc_ioc_state = "scsi protocol error";
4104 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4105 desc_ioc_state = "scsi task terminated";
4107 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4108 desc_ioc_state = "scsi residual mismatch";
4110 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4111 desc_ioc_state = "scsi task mgmt failed";
4113 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4114 desc_ioc_state = "scsi ioc terminated";
4116 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4117 desc_ioc_state = "scsi ext terminated";
4119 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4120 desc_ioc_state = "eedp guard error";
4122 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4123 desc_ioc_state = "eedp ref tag error";
4125 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4126 desc_ioc_state = "eedp app tag error";
4129 desc_ioc_state = "unknown";
4133 switch (scsi_status) {
4134 case MPI2_SCSI_STATUS_GOOD:
4135 desc_scsi_status = "good";
4137 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4138 desc_scsi_status = "check condition";
4140 case MPI2_SCSI_STATUS_CONDITION_MET:
4141 desc_scsi_status = "condition met";
4143 case MPI2_SCSI_STATUS_BUSY:
4144 desc_scsi_status = "busy";
4146 case MPI2_SCSI_STATUS_INTERMEDIATE:
4147 desc_scsi_status = "intermediate";
4149 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4150 desc_scsi_status = "intermediate condmet";
4152 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4153 desc_scsi_status = "reservation conflict";
4155 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4156 desc_scsi_status = "command terminated";
4158 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4159 desc_scsi_status = "task set full";
4161 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4162 desc_scsi_status = "aca active";
4164 case MPI2_SCSI_STATUS_TASK_ABORTED:
4165 desc_scsi_status = "task aborted";
4168 desc_scsi_status = "unknown";
4172 desc_scsi_state[0] = '\0';
4174 desc_scsi_state = " ";
4175 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4176 strcat(desc_scsi_state, "response info ");
4177 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4178 strcat(desc_scsi_state, "state terminated ");
4179 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4180 strcat(desc_scsi_state, "no status ");
4181 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4182 strcat(desc_scsi_state, "autosense failed ");
4183 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4184 strcat(desc_scsi_state, "autosense valid ");
4186 scsi_print_command(scmd);
4188 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
4189 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4190 device_str, (unsigned long long)priv_target->sas_address);
4192 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4193 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4194 priv_target->sas_address);
4196 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4197 "phy(%d)\n", ioc->name, sas_device->sas_address,
4199 printk(MPT2SAS_WARN_FMT
4200 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4201 ioc->name, sas_device->enclosure_logical_id,
4204 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4207 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4208 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4209 desc_ioc_state, ioc_status, smid);
4210 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4211 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4212 scsi_get_resid(scmd));
4213 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4214 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4215 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4216 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4217 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4218 scsi_status, desc_scsi_state, scsi_state);
4220 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4221 struct sense_info data;
4222 _scsih_normalize_sense(scmd->sense_buffer, &data);
4223 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
4224 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4225 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
4228 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4229 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4230 response_bytes = (u8 *)&response_info;
4231 _scsih_response_code(ioc, response_bytes[0]);
4237 * _scsih_turn_on_pfa_led - illuminate PFA LED
4238 * @ioc: per adapter object
4239 * @handle: device handle
4245 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4247 Mpi2SepReply_t mpi_reply;
4248 Mpi2SepRequest_t mpi_request;
4249 struct _sas_device *sas_device;
4251 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4255 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4256 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4257 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4258 mpi_request.SlotStatus =
4259 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4260 mpi_request.DevHandle = cpu_to_le16(handle);
4261 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4262 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4263 &mpi_request)) != 0) {
4264 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4265 __FILE__, __LINE__, __func__);
4268 sas_device->pfa_led_on = 1;
4271 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4272 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
4273 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4274 ioc->name, le16_to_cpu(mpi_reply.IOCStatus),
4275 le32_to_cpu(mpi_reply.IOCLogInfo)));
4281 * _scsih_turn_off_pfa_led - turn off PFA LED
4282 * @ioc: per adapter object
4283 * @sas_device: sas device whose PFA LED has to turned off
4289 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER *ioc,
4290 struct _sas_device *sas_device)
4292 Mpi2SepReply_t mpi_reply;
4293 Mpi2SepRequest_t mpi_request;
4295 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4296 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4297 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4298 mpi_request.SlotStatus = 0;
4299 mpi_request.Slot = cpu_to_le16(sas_device->slot);
4300 mpi_request.DevHandle = 0;
4301 mpi_request.EnclosureHandle = cpu_to_le16(sas_device->enclosure_handle);
4302 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS;
4303 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4304 &mpi_request)) != 0) {
4305 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4306 __FILE__, __LINE__, __func__);
4310 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4311 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4312 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4313 le16_to_cpu(mpi_reply.IOCStatus),
4314 le32_to_cpu(mpi_reply.IOCLogInfo)));
4320 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4321 * @ioc: per adapter object
4322 * @handle: device handle
4323 * Context: interrupt.
4328 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4330 struct fw_event_work *fw_event;
4332 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4335 fw_event->event = MPT2SAS_TURN_ON_PFA_LED;
4336 fw_event->device_handle = handle;
4337 fw_event->ioc = ioc;
4338 _scsih_fw_event_add(ioc, fw_event);
4342 * _scsih_smart_predicted_fault - process smart errors
4343 * @ioc: per adapter object
4344 * @handle: device handle
4345 * Context: interrupt.
4350 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4352 struct scsi_target *starget;
4353 struct MPT2SAS_TARGET *sas_target_priv_data;
4354 Mpi2EventNotificationReply_t *event_reply;
4355 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4356 struct _sas_device *sas_device;
4358 unsigned long flags;
4360 /* only handle non-raid devices */
4361 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4362 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4364 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4367 starget = sas_device->starget;
4368 sas_target_priv_data = starget->hostdata;
4370 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4371 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4372 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4375 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4376 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4378 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4379 _scsih_send_event_to_turn_on_pfa_led(ioc, handle);
4381 /* insert into event log */
4382 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4383 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4384 event_reply = kzalloc(sz, GFP_ATOMIC);
4386 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4387 ioc->name, __FILE__, __LINE__, __func__);
4391 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4392 event_reply->Event =
4393 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4394 event_reply->MsgLength = sz/4;
4395 event_reply->EventDataLength =
4396 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4397 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4398 event_reply->EventData;
4399 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4400 event_data->ASC = 0x5D;
4401 event_data->DevHandle = cpu_to_le16(handle);
4402 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4403 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4408 * _scsih_io_done - scsi request callback
4409 * @ioc: per adapter object
4410 * @smid: system request message index
4411 * @msix_index: MSIX table index supplied by the OS
4412 * @reply: reply message frame(lower 32bit addr)
4414 * Callback handler when using _scsih_qcmd.
4416 * Return 1 meaning mf should be freed from _base_interrupt
4417 * 0 means the mf is freed from this function.
4420 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4422 Mpi2SCSIIORequest_t *mpi_request;
4423 Mpi2SCSIIOReply_t *mpi_reply;
4424 struct scsi_cmnd *scmd;
4430 struct MPT2SAS_DEVICE *sas_device_priv_data;
4431 u32 response_code = 0;
4432 unsigned long flags;
4434 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4435 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
4439 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4441 if (mpi_reply == NULL) {
4442 scmd->result = DID_OK << 16;
4446 sas_device_priv_data = scmd->device->hostdata;
4447 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4448 sas_device_priv_data->sas_target->deleted) {
4449 scmd->result = DID_NO_CONNECT << 16;
4452 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4454 * WARPDRIVE: If direct_io is set then it is directIO,
4455 * the failed direct I/O should be redirected to volume
4457 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4458 ((ioc_status & MPI2_IOCSTATUS_MASK)
4459 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
4460 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4461 ioc->scsi_lookup[smid - 1].scmd = scmd;
4462 _scsih_scsi_direct_io_set(ioc, smid, 0);
4463 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4464 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4465 mpi_request->DevHandle =
4466 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4467 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4468 sas_device_priv_data->sas_target->handle);
4473 /* turning off TLR */
4474 scsi_state = mpi_reply->SCSIState;
4475 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4477 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
4478 if (!sas_device_priv_data->tlr_snoop_check) {
4479 sas_device_priv_data->tlr_snoop_check++;
4480 /* Make sure Device is not raid volume.
4481 * We do not expose raid functionality to upper layer for warpdrive.
4483 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
4484 sas_is_tlr_enabled(scmd->device) &&
4485 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4486 sas_disable_tlr(scmd->device);
4487 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4491 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4492 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4493 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4494 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4497 ioc_status &= MPI2_IOCSTATUS_MASK;
4498 scsi_status = mpi_reply->SCSIStatus;
4500 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4501 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4502 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4503 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4504 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4507 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4508 struct sense_info data;
4509 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4511 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
4512 le32_to_cpu(mpi_reply->SenseCount));
4513 memcpy(scmd->sense_buffer, sense_data, sz);
4514 _scsih_normalize_sense(scmd->sense_buffer, &data);
4515 /* failure prediction threshold exceeded */
4516 if (data.asc == 0x5D)
4517 _scsih_smart_predicted_fault(ioc,
4518 le16_to_cpu(mpi_reply->DevHandle));
4521 switch (ioc_status) {
4522 case MPI2_IOCSTATUS_BUSY:
4523 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4524 scmd->result = SAM_STAT_BUSY;
4527 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4528 scmd->result = DID_NO_CONNECT << 16;
4531 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4532 if (sas_device_priv_data->block) {
4533 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4536 scmd->result = DID_SOFT_ERROR << 16;
4538 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4539 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4540 scmd->result = DID_RESET << 16;
4543 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4544 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4545 scmd->result = DID_SOFT_ERROR << 16;
4547 scmd->result = (DID_OK << 16) | scsi_status;
4550 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4551 scmd->result = (DID_OK << 16) | scsi_status;
4553 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4556 if (xfer_cnt < scmd->underflow) {
4557 if (scsi_status == SAM_STAT_BUSY)
4558 scmd->result = SAM_STAT_BUSY;
4560 scmd->result = DID_SOFT_ERROR << 16;
4561 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4562 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4563 scmd->result = DID_SOFT_ERROR << 16;
4564 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4565 scmd->result = DID_RESET << 16;
4566 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4567 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4568 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4569 scmd->result = (DRIVER_SENSE << 24) |
4570 SAM_STAT_CHECK_CONDITION;
4571 scmd->sense_buffer[0] = 0x70;
4572 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4573 scmd->sense_buffer[12] = 0x20;
4574 scmd->sense_buffer[13] = 0;
4578 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4579 scsi_set_resid(scmd, 0);
4580 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4581 case MPI2_IOCSTATUS_SUCCESS:
4582 scmd->result = (DID_OK << 16) | scsi_status;
4583 if (response_code ==
4584 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4585 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4586 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
4587 scmd->result = DID_SOFT_ERROR << 16;
4588 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4589 scmd->result = DID_RESET << 16;
4592 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4593 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4594 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4595 _scsih_eedp_error_handling(scmd, ioc_status);
4597 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4598 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4599 case MPI2_IOCSTATUS_INVALID_SGL:
4600 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4601 case MPI2_IOCSTATUS_INVALID_FIELD:
4602 case MPI2_IOCSTATUS_INVALID_STATE:
4603 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4604 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4606 scmd->result = DID_SOFT_ERROR << 16;
4611 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4612 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4613 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4617 scsi_dma_unmap(scmd);
4618 scmd->scsi_done(scmd);
4623 * _scsih_sas_host_refresh - refreshing sas host object contents
4624 * @ioc: per adapter object
4627 * During port enable, fw will send topology events for every device. Its
4628 * possible that the handles may change from the previous setting, so this
4629 * code keeping handles updating if changed.
4634 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
4639 Mpi2ConfigReply_t mpi_reply;
4640 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4641 u16 attached_handle;
4644 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4645 "updating handles for sas_host(0x%016llx)\n",
4646 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4648 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4649 * sizeof(Mpi2SasIOUnit0PhyData_t));
4650 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4651 if (!sas_iounit_pg0) {
4652 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4653 ioc->name, __FILE__, __LINE__, __func__);
4657 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4658 sas_iounit_pg0, sz)) != 0)
4660 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4661 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4663 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4664 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
4666 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4667 PhyData[0].ControllerDevHandle);
4668 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4669 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4671 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4672 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
4673 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
4674 attached_handle, i, link_rate);
4677 kfree(sas_iounit_pg0);
4681 * _scsih_sas_host_add - create sas host object
4682 * @ioc: per adapter object
4684 * Creating host side data object, stored in ioc->sas_hba
4689 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4692 Mpi2ConfigReply_t mpi_reply;
4693 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4694 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4695 Mpi2SasPhyPage0_t phy_pg0;
4696 Mpi2SasDevicePage0_t sas_device_pg0;
4697 Mpi2SasEnclosurePage0_t enclosure_pg0;
4700 u16 device_missing_delay;
4702 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4703 if (!ioc->sas_hba.num_phys) {
4704 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4705 ioc->name, __FILE__, __LINE__, __func__);
4709 /* sas_iounit page 0 */
4710 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4711 sizeof(Mpi2SasIOUnit0PhyData_t));
4712 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4713 if (!sas_iounit_pg0) {
4714 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4715 ioc->name, __FILE__, __LINE__, __func__);
4718 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4719 sas_iounit_pg0, sz))) {
4720 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4721 ioc->name, __FILE__, __LINE__, __func__);
4724 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4725 MPI2_IOCSTATUS_MASK;
4726 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4727 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4728 ioc->name, __FILE__, __LINE__, __func__);
4732 /* sas_iounit page 1 */
4733 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4734 sizeof(Mpi2SasIOUnit1PhyData_t));
4735 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4736 if (!sas_iounit_pg1) {
4737 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4738 ioc->name, __FILE__, __LINE__, __func__);
4741 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4742 sas_iounit_pg1, sz))) {
4743 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4744 ioc->name, __FILE__, __LINE__, __func__);
4747 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4748 MPI2_IOCSTATUS_MASK;
4749 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4750 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4751 ioc->name, __FILE__, __LINE__, __func__);
4755 ioc->io_missing_delay =
4756 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4757 device_missing_delay =
4758 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4759 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4760 ioc->device_missing_delay = (device_missing_delay &
4761 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4763 ioc->device_missing_delay = device_missing_delay &
4764 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4766 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4767 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4768 sizeof(struct _sas_phy), GFP_KERNEL);
4769 if (!ioc->sas_hba.phy) {
4770 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4771 ioc->name, __FILE__, __LINE__, __func__);
4774 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4775 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4777 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4778 ioc->name, __FILE__, __LINE__, __func__);
4781 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4782 MPI2_IOCSTATUS_MASK;
4783 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4784 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4785 ioc->name, __FILE__, __LINE__, __func__);
4790 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4791 PhyData[0].ControllerDevHandle);
4792 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4793 ioc->sas_hba.phy[i].phy_id = i;
4794 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4795 phy_pg0, ioc->sas_hba.parent_dev);
4797 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4798 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
4799 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4800 ioc->name, __FILE__, __LINE__, __func__);
4803 ioc->sas_hba.enclosure_handle =
4804 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4805 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4806 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4807 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4808 (unsigned long long) ioc->sas_hba.sas_address,
4809 ioc->sas_hba.num_phys) ;
4811 if (ioc->sas_hba.enclosure_handle) {
4812 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4814 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4815 ioc->sas_hba.enclosure_handle))) {
4816 ioc->sas_hba.enclosure_logical_id =
4817 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4822 kfree(sas_iounit_pg1);
4823 kfree(sas_iounit_pg0);
4827 * _scsih_expander_add - creating expander object
4828 * @ioc: per adapter object
4829 * @handle: expander handle
4831 * Creating expander object, stored in ioc->sas_expander_list.
4833 * Return 0 for success, else error.
4836 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4838 struct _sas_node *sas_expander;
4839 Mpi2ConfigReply_t mpi_reply;
4840 Mpi2ExpanderPage0_t expander_pg0;
4841 Mpi2ExpanderPage1_t expander_pg1;
4842 Mpi2SasEnclosurePage0_t enclosure_pg0;
4845 u64 sas_address, sas_address_parent = 0;
4847 unsigned long flags;
4848 struct _sas_port *mpt2sas_port = NULL;
4854 if (ioc->shost_recovery || ioc->pci_error_recovery)
4857 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4858 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4859 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4860 ioc->name, __FILE__, __LINE__, __func__);
4864 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4865 MPI2_IOCSTATUS_MASK;
4866 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4867 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4868 ioc->name, __FILE__, __LINE__, __func__);
4872 /* handle out of order topology events */
4873 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
4874 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4876 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4877 ioc->name, __FILE__, __LINE__, __func__);
4880 if (sas_address_parent != ioc->sas_hba.sas_address) {
4881 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4882 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4883 sas_address_parent);
4884 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4885 if (!sas_expander) {
4886 rc = _scsih_expander_add(ioc, parent_handle);
4892 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4893 sas_address = le64_to_cpu(expander_pg0.SASAddress);
4894 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4896 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4901 sas_expander = kzalloc(sizeof(struct _sas_node),
4903 if (!sas_expander) {
4904 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4905 ioc->name, __FILE__, __LINE__, __func__);
4909 sas_expander->handle = handle;
4910 sas_expander->num_phys = expander_pg0.NumPhys;
4911 sas_expander->sas_address_parent = sas_address_parent;
4912 sas_expander->sas_address = sas_address;
4914 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4915 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
4916 handle, parent_handle, (unsigned long long)
4917 sas_expander->sas_address, sas_expander->num_phys);
4919 if (!sas_expander->num_phys)
4921 sas_expander->phy = kcalloc(sas_expander->num_phys,
4922 sizeof(struct _sas_phy), GFP_KERNEL);
4923 if (!sas_expander->phy) {
4924 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4925 ioc->name, __FILE__, __LINE__, __func__);
4930 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4931 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
4932 sas_address_parent);
4933 if (!mpt2sas_port) {
4934 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4935 ioc->name, __FILE__, __LINE__, __func__);
4939 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4941 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4942 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4943 &expander_pg1, i, handle))) {
4944 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4945 ioc->name, __FILE__, __LINE__, __func__);
4949 sas_expander->phy[i].handle = handle;
4950 sas_expander->phy[i].phy_id = i;
4952 if ((mpt2sas_transport_add_expander_phy(ioc,
4953 &sas_expander->phy[i], expander_pg1,
4954 sas_expander->parent_dev))) {
4955 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4956 ioc->name, __FILE__, __LINE__, __func__);
4962 if (sas_expander->enclosure_handle) {
4963 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4964 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4965 sas_expander->enclosure_handle))) {
4966 sas_expander->enclosure_logical_id =
4967 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4971 _scsih_expander_node_add(ioc, sas_expander);
4977 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
4978 sas_address_parent);
4979 kfree(sas_expander);
4984 * _scsih_done - scsih callback handler.
4985 * @ioc: per adapter object
4986 * @smid: system request message index
4987 * @msix_index: MSIX table index supplied by the OS
4988 * @reply: reply message frame(lower 32bit addr)
4990 * Callback handler when sending internal generated message frames.
4991 * The callback index passed is `ioc->scsih_cb_idx`
4993 * Return 1 meaning mf should be freed from _base_interrupt
4994 * 0 means the mf is freed from this function.
4997 _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4999 MPI2DefaultReply_t *mpi_reply;
5001 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5002 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5004 if (ioc->scsih_cmds.smid != smid)
5006 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5008 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5009 mpi_reply->MsgLength*4);
5010 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5012 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5013 complete(&ioc->scsih_cmds.done);
5018 * mpt2sas_expander_remove - removing expander object
5019 * @ioc: per adapter object
5020 * @sas_address: expander sas_address
5025 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5027 struct _sas_node *sas_expander;
5028 unsigned long flags;
5030 if (ioc->shost_recovery)
5033 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5034 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5037 list_del(&sas_expander->list);
5038 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5040 _scsih_expander_node_remove(ioc, sas_expander);
5044 * _scsih_check_access_status - check access flags
5045 * @ioc: per adapter object
5046 * @sas_address: sas address
5047 * @handle: sas device handle
5048 * @access_flags: errors returned during discovery of the device
5050 * Return 0 for success, else failure
5053 _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5054 u16 handle, u8 access_status)
5059 switch (access_status) {
5060 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5061 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5064 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5065 desc = "sata capability failed";
5067 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5068 desc = "sata affiliation conflict";
5070 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5071 desc = "route not addressable";
5073 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5074 desc = "smp error not addressable";
5076 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5077 desc = "device blocked";
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5080 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5081 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5082 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5083 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5084 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5085 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5086 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5087 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5090 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5091 desc = "sata initialization failed";
5101 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5102 "handle(0x%04x)\n", ioc->name, desc,
5103 (unsigned long long)sas_address, handle);
5108 _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5110 Mpi2ConfigReply_t mpi_reply;
5111 Mpi2SasDevicePage0_t sas_device_pg0;
5112 struct _sas_device *sas_device;
5114 unsigned long flags;
5116 struct scsi_target *starget;
5117 struct MPT2SAS_TARGET *sas_target_priv_data;
5121 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5122 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5125 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5126 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5129 /* check if this is end device */
5130 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5131 if (!(_scsih_is_end_device(device_info)))
5134 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5135 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5136 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5140 printk(MPT2SAS_ERR_FMT "device is not present "
5141 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5142 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5146 if (unlikely(sas_device->handle != handle)) {
5147 starget = sas_device->starget;
5148 sas_target_priv_data = starget->hostdata;
5149 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5150 " to (0x%04x)!!!\n", sas_device->handle, handle);
5151 sas_target_priv_data->handle = handle;
5152 sas_device->handle = handle;
5155 /* check if device is present */
5156 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5157 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5158 printk(MPT2SAS_ERR_FMT "device is not present "
5159 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5160 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5164 /* check if there were any issues with discovery */
5165 if (_scsih_check_access_status(ioc, sas_address, handle,
5166 sas_device_pg0.AccessStatus)) {
5167 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5171 _scsih_ublock_io_device(ioc, sas_address);
5176 * _scsih_add_device - creating sas device object
5177 * @ioc: per adapter object
5178 * @handle: sas device handle
5179 * @phy_num: phy number end device attached to
5180 * @is_pd: is this hidden raid component
5182 * Creating end device object, stored in ioc->sas_device_list.
5184 * Returns 0 for success, non-zero for failure.
5187 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5189 Mpi2ConfigReply_t mpi_reply;
5190 Mpi2SasDevicePage0_t sas_device_pg0;
5191 Mpi2SasEnclosurePage0_t enclosure_pg0;
5192 struct _sas_device *sas_device;
5196 unsigned long flags;
5198 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5199 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5200 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5201 ioc->name, __FILE__, __LINE__, __func__);
5205 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5206 MPI2_IOCSTATUS_MASK;
5207 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5208 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5209 ioc->name, __FILE__, __LINE__, __func__);
5213 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5215 /* check if device is present */
5216 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5217 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5218 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5219 ioc->name, __FILE__, __LINE__, __func__);
5220 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5221 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5225 /* check if there were any issues with discovery */
5226 if (_scsih_check_access_status(ioc, sas_address, handle,
5227 sas_device_pg0.AccessStatus))
5230 /* check if this is end device */
5231 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5232 if (!(_scsih_is_end_device(device_info))) {
5233 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5234 ioc->name, __FILE__, __LINE__, __func__);
5239 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5240 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5242 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5247 sas_device = kzalloc(sizeof(struct _sas_device),
5250 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5251 ioc->name, __FILE__, __LINE__, __func__);
5255 sas_device->handle = handle;
5256 if (_scsih_get_sas_address(ioc, le16_to_cpu
5257 (sas_device_pg0.ParentDevHandle),
5258 &sas_device->sas_address_parent) != 0)
5259 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5260 ioc->name, __FILE__, __LINE__, __func__);
5261 sas_device->enclosure_handle =
5262 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5264 le16_to_cpu(sas_device_pg0.Slot);
5265 sas_device->device_info = device_info;
5266 sas_device->sas_address = sas_address;
5267 sas_device->phy = sas_device_pg0.PhyNum;
5269 /* get enclosure_logical_id */
5270 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5271 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5272 sas_device->enclosure_handle)))
5273 sas_device->enclosure_logical_id =
5274 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
5276 /* get device name */
5277 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5279 if (ioc->wait_for_discovery_to_complete)
5280 _scsih_sas_device_init_add(ioc, sas_device);
5282 _scsih_sas_device_add(ioc, sas_device);
5288 * _scsih_remove_device - removing sas device object
5289 * @ioc: per adapter object
5290 * @sas_device_delete: the sas_device object
5295 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5296 struct _sas_device *sas_device)
5298 struct MPT2SAS_TARGET *sas_target_priv_data;
5300 if ((ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
5301 (sas_device->pfa_led_on)) {
5302 _scsih_turn_off_pfa_led(ioc, sas_device);
5303 sas_device->pfa_led_on = 0;
5306 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5307 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5308 sas_device->handle, (unsigned long long)
5309 sas_device->sas_address));
5311 if (sas_device->starget && sas_device->starget->hostdata) {
5312 sas_target_priv_data = sas_device->starget->hostdata;
5313 sas_target_priv_data->deleted = 1;
5314 _scsih_ublock_io_device(ioc, sas_device->sas_address);
5315 sas_target_priv_data->handle =
5316 MPT2SAS_INVALID_DEVICE_HANDLE;
5319 if (!ioc->hide_drives)
5320 mpt2sas_transport_port_remove(ioc,
5321 sas_device->sas_address,
5322 sas_device->sas_address_parent);
5324 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5325 "(0x%016llx)\n", ioc->name, sas_device->handle,
5326 (unsigned long long) sas_device->sas_address);
5328 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5329 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5330 sas_device->handle, (unsigned long long)
5331 sas_device->sas_address));
5335 * _scsih_device_remove_by_handle - removing device object by handle
5336 * @ioc: per adapter object
5337 * @handle: device handle
5342 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5344 struct _sas_device *sas_device;
5345 unsigned long flags;
5347 if (ioc->shost_recovery)
5350 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5351 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5353 list_del(&sas_device->list);
5354 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5356 _scsih_remove_device(ioc, sas_device);
5360 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5361 * @ioc: per adapter object
5362 * @sas_address: device sas_address
5367 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5370 struct _sas_device *sas_device;
5371 unsigned long flags;
5373 if (ioc->shost_recovery)
5376 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5377 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5380 list_del(&sas_device->list);
5381 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5383 _scsih_remove_device(ioc, sas_device);
5385 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5387 * _scsih_sas_topology_change_event_debug - debug for topology event
5388 * @ioc: per adapter object
5389 * @event_data: event data payload
5393 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5394 Mpi2EventDataSasTopologyChangeList_t *event_data)
5400 char *status_str = NULL;
5401 u8 link_rate, prev_link_rate;
5403 switch (event_data->ExpStatus) {
5404 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5407 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5408 status_str = "remove";
5410 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
5412 status_str = "responding";
5414 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5415 status_str = "remove delay";
5418 status_str = "unknown status";
5421 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
5422 ioc->name, status_str);
5423 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
5424 "start_phy(%02d), count(%d)\n",
5425 le16_to_cpu(event_data->ExpanderDevHandle),
5426 le16_to_cpu(event_data->EnclosureHandle),
5427 event_data->StartPhyNum, event_data->NumEntries);
5428 for (i = 0; i < event_data->NumEntries; i++) {
5429 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5432 phy_number = event_data->StartPhyNum + i;
5433 reason_code = event_data->PHY[i].PhyStatus &
5434 MPI2_EVENT_SAS_TOPO_RC_MASK;
5435 switch (reason_code) {
5436 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5437 status_str = "target add";
5439 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5440 status_str = "target remove";
5442 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
5443 status_str = "delay target remove";
5445 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5446 status_str = "link rate change";
5448 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
5449 status_str = "target responding";
5452 status_str = "unknown";
5455 link_rate = event_data->PHY[i].LinkRate >> 4;
5456 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5457 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
5458 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5459 handle, status_str, link_rate, prev_link_rate);
5466 * _scsih_sas_topology_change_event - handle topology changes
5467 * @ioc: per adapter object
5468 * @fw_event: The fw_event_work object
5473 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5474 struct fw_event_work *fw_event)
5477 u16 parent_handle, handle;
5479 u8 phy_number, max_phys;
5480 struct _sas_node *sas_expander;
5482 unsigned long flags;
5483 u8 link_rate, prev_link_rate;
5484 Mpi2EventDataSasTopologyChangeList_t *event_data =
5485 (Mpi2EventDataSasTopologyChangeList_t *)
5486 fw_event->event_data;
5488 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5489 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5490 _scsih_sas_topology_change_event_debug(ioc, event_data);
5493 if (ioc->remove_host || ioc->pci_error_recovery)
5496 if (!ioc->sas_hba.num_phys)
5497 _scsih_sas_host_add(ioc);
5499 _scsih_sas_host_refresh(ioc);
5501 if (fw_event->ignore) {
5502 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
5503 "event\n", ioc->name));
5507 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5509 /* handle expander add */
5510 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5511 if (_scsih_expander_add(ioc, parent_handle) != 0)
5514 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5515 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5518 sas_address = sas_expander->sas_address;
5519 max_phys = sas_expander->num_phys;
5520 } else if (parent_handle < ioc->sas_hba.num_phys) {
5521 sas_address = ioc->sas_hba.sas_address;
5522 max_phys = ioc->sas_hba.num_phys;
5524 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5527 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5529 /* handle siblings events */
5530 for (i = 0; i < event_data->NumEntries; i++) {
5531 if (fw_event->ignore) {
5532 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
5533 "expander event\n", ioc->name));
5536 if (ioc->shost_recovery || ioc->remove_host ||
5537 ioc->pci_error_recovery)
5539 phy_number = event_data->StartPhyNum + i;
5540 if (phy_number >= max_phys)
5542 reason_code = event_data->PHY[i].PhyStatus &
5543 MPI2_EVENT_SAS_TOPO_RC_MASK;
5544 if ((event_data->PHY[i].PhyStatus &
5545 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5546 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
5548 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5551 link_rate = event_data->PHY[i].LinkRate >> 4;
5552 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
5553 switch (reason_code) {
5554 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5556 if (ioc->shost_recovery)
5559 if (link_rate == prev_link_rate)
5562 mpt2sas_transport_update_links(ioc, sas_address,
5563 handle, phy_number, link_rate);
5565 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5568 _scsih_check_device(ioc, handle);
5570 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5572 if (ioc->shost_recovery)
5575 mpt2sas_transport_update_links(ioc, sas_address,
5576 handle, phy_number, link_rate);
5578 _scsih_add_device(ioc, handle, phy_number, 0);
5580 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
5582 _scsih_device_remove_by_handle(ioc, handle);
5587 /* handle expander removal */
5588 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5590 mpt2sas_expander_remove(ioc, sas_address);
5594 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5596 * _scsih_sas_device_status_change_event_debug - debug for device event
5597 * @event_data: event data payload
5603 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5604 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5606 char *reason_str = NULL;
5608 switch (event_data->ReasonCode) {
5609 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5610 reason_str = "smart data";
5612 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5613 reason_str = "unsupported device discovered";
5615 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5616 reason_str = "internal device reset";
5618 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5619 reason_str = "internal task abort";
5621 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5622 reason_str = "internal task abort set";
5624 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5625 reason_str = "internal clear task set";
5627 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5628 reason_str = "internal query task";
5630 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5631 reason_str = "sata init failure";
5633 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5634 reason_str = "internal device reset complete";
5636 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5637 reason_str = "internal task abort complete";
5639 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5640 reason_str = "internal async notification";
5642 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5643 reason_str = "expander reduced functionality";
5645 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5646 reason_str = "expander reduced functionality complete";
5649 reason_str = "unknown reason";
5652 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
5653 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5654 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5655 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5656 le16_to_cpu(event_data->TaskTag));
5657 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
5658 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
5659 event_data->ASC, event_data->ASCQ);
5660 printk(KERN_INFO "\n");
5665 * _scsih_sas_device_status_change_event - handle device status change
5666 * @ioc: per adapter object
5667 * @fw_event: The fw_event_work object
5673 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5674 struct fw_event_work *fw_event)
5676 struct MPT2SAS_TARGET *target_priv_data;
5677 struct _sas_device *sas_device;
5679 unsigned long flags;
5680 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5681 (Mpi2EventDataSasDeviceStatusChange_t *)
5682 fw_event->event_data;
5684 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5685 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5686 _scsih_sas_device_status_change_event_debug(ioc,
5690 /* In MPI Revision K (0xC), the internal device reset complete was
5691 * implemented, so avoid setting tm_busy flag for older firmware.
5693 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5696 if (event_data->ReasonCode !=
5697 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5698 event_data->ReasonCode !=
5699 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
5702 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5703 sas_address = le64_to_cpu(event_data->SASAddress);
5704 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5707 if (!sas_device || !sas_device->starget) {
5708 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5712 target_priv_data = sas_device->starget->hostdata;
5713 if (!target_priv_data) {
5714 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5718 if (event_data->ReasonCode ==
5719 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5720 target_priv_data->tm_busy = 1;
5722 target_priv_data->tm_busy = 0;
5723 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5726 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5728 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5729 * @ioc: per adapter object
5730 * @event_data: event data payload
5736 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5737 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5739 char *reason_str = NULL;
5741 switch (event_data->ReasonCode) {
5742 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5743 reason_str = "enclosure add";
5745 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5746 reason_str = "enclosure remove";
5749 reason_str = "unknown reason";
5753 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
5754 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5755 " number slots(%d)\n", ioc->name, reason_str,
5756 le16_to_cpu(event_data->EnclosureHandle),
5757 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5758 le16_to_cpu(event_data->StartSlot));
5763 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5764 * @ioc: per adapter object
5765 * @fw_event: The fw_event_work object
5771 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5772 struct fw_event_work *fw_event)
5774 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5775 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5776 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
5777 (Mpi2EventDataSasEnclDevStatusChange_t *)
5778 fw_event->event_data);
5783 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5784 * @ioc: per adapter object
5785 * @fw_event: The fw_event_work object
5791 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
5792 struct fw_event_work *fw_event)
5794 struct scsi_cmnd *scmd;
5795 struct scsi_device *sdev;
5798 struct MPT2SAS_DEVICE *sas_device_priv_data;
5799 u32 termination_count;
5801 Mpi2SCSITaskManagementReply_t *mpi_reply;
5802 Mpi2EventDataSasBroadcastPrimitive_t *event_data =
5803 (Mpi2EventDataSasBroadcastPrimitive_t *)
5804 fw_event->event_data;
5806 unsigned long flags;
5809 u8 task_abort_retries;
5811 mutex_lock(&ioc->tm_cmds.mutex);
5813 "%s: enter: phy number(%d), width(%d)\n",
5814 ioc->name, __func__, event_data->PhyNum,
5815 event_data->PortWidth);
5817 _scsih_block_io_all_device(ioc);
5819 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5820 mpi_reply = ioc->tm_cmds.reply;
5821 broadcast_aen_retry:
5823 /* sanity checks for retrying this loop */
5824 if (max_retries++ == 5) {
5825 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5826 ioc->name, __func__));
5828 } else if (max_retries > 1)
5829 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5830 ioc->name, __func__, max_retries - 1));
5832 termination_count = 0;
5834 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5835 if (ioc->shost_recovery)
5837 scmd = _scsih_scsi_lookup_get(ioc, smid);
5840 sdev = scmd->device;
5841 sas_device_priv_data = sdev->hostdata;
5842 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5844 /* skip hidden raid components */
5845 if (sas_device_priv_data->sas_target->flags &
5846 MPT_TARGET_FLAGS_RAID_COMPONENT)
5849 if (sas_device_priv_data->sas_target->flags &
5850 MPT_TARGET_FLAGS_VOLUME)
5853 handle = sas_device_priv_data->sas_target->handle;
5854 lun = sas_device_priv_data->lun;
5857 if (ioc->shost_recovery)
5860 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5861 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5862 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30,
5865 sdev_printk(KERN_WARNING, sdev,
5866 "mpt2sas_scsih_issue_tm: FAILED when sending "
5867 "QUERY_TASK: scmd(%p)\n", scmd);
5868 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5869 goto broadcast_aen_retry;
5871 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5872 & MPI2_IOCSTATUS_MASK;
5873 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5874 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5875 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5877 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5878 goto broadcast_aen_retry;
5881 /* see if IO is still owned by IOC and target */
5882 if (mpi_reply->ResponseCode ==
5883 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5884 mpi_reply->ResponseCode ==
5885 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
5886 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5889 task_abort_retries = 0;
5891 if (task_abort_retries++ == 60) {
5892 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5893 "%s: ABORT_TASK: giving up\n", ioc->name,
5895 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5896 goto broadcast_aen_retry;
5899 if (ioc->shost_recovery)
5902 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5903 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
5906 sdev_printk(KERN_WARNING, sdev,
5907 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5908 "scmd(%p)\n", scmd);
5912 if (task_abort_retries > 1)
5913 sdev_printk(KERN_WARNING, sdev,
5914 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5916 task_abort_retries - 1, scmd);
5918 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
5919 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5922 if (ioc->broadcast_aen_pending) {
5923 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5924 " pending AEN\n", ioc->name, __func__));
5925 ioc->broadcast_aen_pending = 0;
5926 goto broadcast_aen_retry;
5930 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5933 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5934 "%s - exit, query_count = %d termination_count = %d\n",
5935 ioc->name, __func__, query_count, termination_count));
5937 ioc->broadcast_aen_busy = 0;
5938 if (!ioc->shost_recovery)
5939 _scsih_ublock_io_all_device(ioc);
5940 mutex_unlock(&ioc->tm_cmds.mutex);
5944 * _scsih_sas_discovery_event - handle discovery events
5945 * @ioc: per adapter object
5946 * @fw_event: The fw_event_work object
5952 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5953 struct fw_event_work *fw_event)
5955 Mpi2EventDataSasDiscovery_t *event_data =
5956 (Mpi2EventDataSasDiscovery_t *)
5957 fw_event->event_data;
5959 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5960 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
5961 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
5962 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5964 if (event_data->DiscoveryStatus)
5965 printk("discovery_status(0x%08x)",
5966 le32_to_cpu(event_data->DiscoveryStatus));
5971 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5972 !ioc->sas_hba.num_phys) {
5973 if (disable_discovery > 0 && ioc->shost_recovery) {
5974 /* Wait for the reset to complete */
5975 while (ioc->shost_recovery)
5978 _scsih_sas_host_add(ioc);
5983 * _scsih_reprobe_lun - reprobing lun
5984 * @sdev: scsi device struct
5985 * @no_uld_attach: sdev->no_uld_attach flag setting
5989 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5993 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5994 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5995 sdev->no_uld_attach ? "hidding" : "exposing");
5996 rc = scsi_device_reprobe(sdev);
6000 * _scsih_sas_volume_add - add new volume
6001 * @ioc: per adapter object
6002 * @element: IR config element data
6008 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
6009 Mpi2EventIrConfigElement_t *element)
6011 struct _raid_device *raid_device;
6012 unsigned long flags;
6014 u16 handle = le16_to_cpu(element->VolDevHandle);
6017 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6019 printk(MPT2SAS_ERR_FMT
6020 "failure at %s:%d/%s()!\n", ioc->name,
6021 __FILE__, __LINE__, __func__);
6025 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6026 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6027 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6032 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6034 printk(MPT2SAS_ERR_FMT
6035 "failure at %s:%d/%s()!\n", ioc->name,
6036 __FILE__, __LINE__, __func__);
6040 raid_device->id = ioc->sas_id++;
6041 raid_device->channel = RAID_CHANNEL;
6042 raid_device->handle = handle;
6043 raid_device->wwid = wwid;
6044 _scsih_raid_device_add(ioc, raid_device);
6045 if (!ioc->wait_for_discovery_to_complete) {
6046 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6047 raid_device->id, 0);
6049 _scsih_raid_device_remove(ioc, raid_device);
6051 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6052 _scsih_determine_boot_device(ioc, raid_device, 1);
6053 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6058 * _scsih_sas_volume_delete - delete volume
6059 * @ioc: per adapter object
6060 * @handle: volume device handle
6066 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
6068 struct _raid_device *raid_device;
6069 unsigned long flags;
6070 struct MPT2SAS_TARGET *sas_target_priv_data;
6071 struct scsi_target *starget = NULL;
6073 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6074 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6076 if (raid_device->starget) {
6077 starget = raid_device->starget;
6078 sas_target_priv_data = starget->hostdata;
6079 sas_target_priv_data->deleted = 1;
6081 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6082 "(0x%016llx)\n", ioc->name, raid_device->handle,
6083 (unsigned long long) raid_device->wwid);
6084 list_del(&raid_device->list);
6087 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6089 scsi_remove_target(&starget->dev);
6093 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6094 * @ioc: per adapter object
6095 * @element: IR config element data
6101 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6102 Mpi2EventIrConfigElement_t *element)
6104 struct _sas_device *sas_device;
6105 struct scsi_target *starget = NULL;
6106 struct MPT2SAS_TARGET *sas_target_priv_data;
6107 unsigned long flags;
6108 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6110 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6111 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6113 sas_device->volume_handle = 0;
6114 sas_device->volume_wwid = 0;
6115 clear_bit(handle, ioc->pd_handles);
6116 if (sas_device->starget && sas_device->starget->hostdata) {
6117 starget = sas_device->starget;
6118 sas_target_priv_data = starget->hostdata;
6119 sas_target_priv_data->flags &=
6120 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6123 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6127 /* exposing raid component */
6129 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
6133 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6134 * @ioc: per adapter object
6135 * @element: IR config element data
6141 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6142 Mpi2EventIrConfigElement_t *element)
6144 struct _sas_device *sas_device;
6145 struct scsi_target *starget = NULL;
6146 struct MPT2SAS_TARGET *sas_target_priv_data;
6147 unsigned long flags;
6148 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6149 u16 volume_handle = 0;
6150 u64 volume_wwid = 0;
6152 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6154 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6157 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6158 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6160 set_bit(handle, ioc->pd_handles);
6161 if (sas_device->starget && sas_device->starget->hostdata) {
6162 starget = sas_device->starget;
6163 sas_target_priv_data = starget->hostdata;
6164 sas_target_priv_data->flags |=
6165 MPT_TARGET_FLAGS_RAID_COMPONENT;
6166 sas_device->volume_handle = volume_handle;
6167 sas_device->volume_wwid = volume_wwid;
6170 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6174 /* hiding raid component */
6176 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
6180 * _scsih_sas_pd_delete - delete pd component
6181 * @ioc: per adapter object
6182 * @element: IR config element data
6188 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6189 Mpi2EventIrConfigElement_t *element)
6191 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6193 _scsih_device_remove_by_handle(ioc, handle);
6197 * _scsih_sas_pd_add - remove pd component
6198 * @ioc: per adapter object
6199 * @element: IR config element data
6205 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6206 Mpi2EventIrConfigElement_t *element)
6208 struct _sas_device *sas_device;
6209 unsigned long flags;
6210 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6211 Mpi2ConfigReply_t mpi_reply;
6212 Mpi2SasDevicePage0_t sas_device_pg0;
6217 set_bit(handle, ioc->pd_handles);
6219 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6220 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6221 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6225 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6226 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6227 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6228 ioc->name, __FILE__, __LINE__, __func__);
6232 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6233 MPI2_IOCSTATUS_MASK;
6234 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6235 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6236 ioc->name, __FILE__, __LINE__, __func__);
6240 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6241 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6242 mpt2sas_transport_update_links(ioc, sas_address, handle,
6243 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6245 _scsih_add_device(ioc, handle, 0, 1);
6248 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6250 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6251 * @ioc: per adapter object
6252 * @event_data: event data payload
6258 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6259 Mpi2EventDataIrConfigChangeList_t *event_data)
6261 Mpi2EventIrConfigElement_t *element;
6264 char *reason_str = NULL, *element_str = NULL;
6266 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6268 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
6269 ioc->name, (le32_to_cpu(event_data->Flags) &
6270 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6271 "foreign" : "native", event_data->NumElements);
6272 for (i = 0; i < event_data->NumElements; i++, element++) {
6273 switch (element->ReasonCode) {
6274 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6277 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6278 reason_str = "remove";
6280 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6281 reason_str = "no change";
6283 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6284 reason_str = "hide";
6286 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6287 reason_str = "unhide";
6289 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6290 reason_str = "volume_created";
6292 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6293 reason_str = "volume_deleted";
6295 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6296 reason_str = "pd_created";
6298 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6299 reason_str = "pd_deleted";
6302 reason_str = "unknown reason";
6305 element_type = le16_to_cpu(element->ElementFlags) &
6306 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6307 switch (element_type) {
6308 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6309 element_str = "volume";
6311 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6312 element_str = "phys disk";
6314 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6315 element_str = "hot spare";
6318 element_str = "unknown element";
6321 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
6322 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6323 reason_str, le16_to_cpu(element->VolDevHandle),
6324 le16_to_cpu(element->PhysDiskDevHandle),
6325 element->PhysDiskNum);
6331 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6332 * @ioc: per adapter object
6333 * @fw_event: The fw_event_work object
6339 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6340 struct fw_event_work *fw_event)
6342 Mpi2EventIrConfigElement_t *element;
6345 Mpi2EventDataIrConfigChangeList_t *event_data =
6346 (Mpi2EventDataIrConfigChangeList_t *)
6347 fw_event->event_data;
6349 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6350 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6351 && !ioc->hide_ir_msg)
6352 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6356 if (ioc->shost_recovery)
6359 foreign_config = (le32_to_cpu(event_data->Flags) &
6360 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6362 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6363 for (i = 0; i < event_data->NumElements; i++, element++) {
6365 switch (element->ReasonCode) {
6366 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6367 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6368 if (!foreign_config)
6369 _scsih_sas_volume_add(ioc, element);
6371 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6372 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6373 if (!foreign_config)
6374 _scsih_sas_volume_delete(ioc,
6375 le16_to_cpu(element->VolDevHandle));
6377 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6378 if (!ioc->is_warpdrive)
6379 _scsih_sas_pd_hide(ioc, element);
6381 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6382 if (!ioc->is_warpdrive)
6383 _scsih_sas_pd_expose(ioc, element);
6385 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6386 if (!ioc->is_warpdrive)
6387 _scsih_sas_pd_add(ioc, element);
6389 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6390 if (!ioc->is_warpdrive)
6391 _scsih_sas_pd_delete(ioc, element);
6398 * _scsih_sas_ir_volume_event - IR volume event
6399 * @ioc: per adapter object
6400 * @fw_event: The fw_event_work object
6406 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6407 struct fw_event_work *fw_event)
6410 unsigned long flags;
6411 struct _raid_device *raid_device;
6415 Mpi2EventDataIrVolume_t *event_data =
6416 (Mpi2EventDataIrVolume_t *)
6417 fw_event->event_data;
6419 if (ioc->shost_recovery)
6422 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6425 handle = le16_to_cpu(event_data->VolDevHandle);
6426 state = le32_to_cpu(event_data->NewValue);
6427 if (!ioc->hide_ir_msg)
6428 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6429 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6430 le32_to_cpu(event_data->PreviousValue), state));
6433 case MPI2_RAID_VOL_STATE_MISSING:
6434 case MPI2_RAID_VOL_STATE_FAILED:
6435 _scsih_sas_volume_delete(ioc, handle);
6438 case MPI2_RAID_VOL_STATE_ONLINE:
6439 case MPI2_RAID_VOL_STATE_DEGRADED:
6440 case MPI2_RAID_VOL_STATE_OPTIMAL:
6442 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6443 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6444 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6449 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6451 printk(MPT2SAS_ERR_FMT
6452 "failure at %s:%d/%s()!\n", ioc->name,
6453 __FILE__, __LINE__, __func__);
6457 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6459 printk(MPT2SAS_ERR_FMT
6460 "failure at %s:%d/%s()!\n", ioc->name,
6461 __FILE__, __LINE__, __func__);
6465 raid_device->id = ioc->sas_id++;
6466 raid_device->channel = RAID_CHANNEL;
6467 raid_device->handle = handle;
6468 raid_device->wwid = wwid;
6469 _scsih_raid_device_add(ioc, raid_device);
6470 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6471 raid_device->id, 0);
6473 _scsih_raid_device_remove(ioc, raid_device);
6476 case MPI2_RAID_VOL_STATE_INITIALIZING:
6483 * _scsih_sas_ir_physical_disk_event - PD event
6484 * @ioc: per adapter object
6485 * @fw_event: The fw_event_work object
6491 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6492 struct fw_event_work *fw_event)
6494 u16 handle, parent_handle;
6496 struct _sas_device *sas_device;
6497 unsigned long flags;
6498 Mpi2ConfigReply_t mpi_reply;
6499 Mpi2SasDevicePage0_t sas_device_pg0;
6501 Mpi2EventDataIrPhysicalDisk_t *event_data =
6502 (Mpi2EventDataIrPhysicalDisk_t *)
6503 fw_event->event_data;
6506 if (ioc->shost_recovery)
6509 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6512 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6513 state = le32_to_cpu(event_data->NewValue);
6515 if (!ioc->hide_ir_msg)
6516 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6517 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6518 le32_to_cpu(event_data->PreviousValue), state));
6521 case MPI2_RAID_PD_STATE_ONLINE:
6522 case MPI2_RAID_PD_STATE_DEGRADED:
6523 case MPI2_RAID_PD_STATE_REBUILDING:
6524 case MPI2_RAID_PD_STATE_OPTIMAL:
6525 case MPI2_RAID_PD_STATE_HOT_SPARE:
6527 if (!ioc->is_warpdrive)
6528 set_bit(handle, ioc->pd_handles);
6530 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6531 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6532 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6537 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6538 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6540 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6541 ioc->name, __FILE__, __LINE__, __func__);
6545 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6546 MPI2_IOCSTATUS_MASK;
6547 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6548 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6549 ioc->name, __FILE__, __LINE__, __func__);
6553 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6554 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6555 mpt2sas_transport_update_links(ioc, sas_address, handle,
6556 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
6558 _scsih_add_device(ioc, handle, 0, 1);
6562 case MPI2_RAID_PD_STATE_OFFLINE:
6563 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6564 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
6570 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6572 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6573 * @ioc: per adapter object
6574 * @event_data: event data payload
6580 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6581 Mpi2EventDataIrOperationStatus_t *event_data)
6583 char *reason_str = NULL;
6585 switch (event_data->RAIDOperation) {
6586 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6587 reason_str = "resync";
6589 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6590 reason_str = "online capacity expansion";
6592 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6593 reason_str = "consistency check";
6595 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6596 reason_str = "background init";
6598 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6599 reason_str = "make data consistent";
6606 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6607 "\thandle(0x%04x), percent complete(%d)\n",
6608 ioc->name, reason_str,
6609 le16_to_cpu(event_data->VolDevHandle),
6610 event_data->PercentComplete);
6615 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6616 * @ioc: per adapter object
6617 * @fw_event: The fw_event_work object
6623 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6624 struct fw_event_work *fw_event)
6626 Mpi2EventDataIrOperationStatus_t *event_data =
6627 (Mpi2EventDataIrOperationStatus_t *)
6628 fw_event->event_data;
6629 static struct _raid_device *raid_device;
6630 unsigned long flags;
6633 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6634 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6635 && !ioc->hide_ir_msg)
6636 _scsih_sas_ir_operation_status_event_debug(ioc,
6640 /* code added for raid transport support */
6641 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6643 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6644 handle = le16_to_cpu(event_data->VolDevHandle);
6645 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6647 raid_device->percent_complete =
6648 event_data->PercentComplete;
6649 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6654 * _scsih_prep_device_scan - initialize parameters prior to device scan
6655 * @ioc: per adapter object
6657 * Set the deleted flag prior to device scan. If the device is found during
6658 * the scan, then we clear the deleted flag.
6661 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6663 struct MPT2SAS_DEVICE *sas_device_priv_data;
6664 struct scsi_device *sdev;
6666 shost_for_each_device(sdev, ioc->shost) {
6667 sas_device_priv_data = sdev->hostdata;
6668 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6669 sas_device_priv_data->sas_target->deleted = 1;
6674 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6675 * @ioc: per adapter object
6676 * @sas_address: sas address
6677 * @slot: enclosure slot id
6678 * @handle: device handle
6680 * After host reset, find out whether devices are still responding.
6681 * Used in _scsi_remove_unresponsive_sas_devices.
6686 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6687 u16 slot, u16 handle)
6689 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
6690 struct scsi_target *starget;
6691 struct _sas_device *sas_device;
6692 unsigned long flags;
6694 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6695 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6696 if (sas_device->sas_address == sas_address &&
6697 sas_device->slot == slot) {
6698 sas_device->responding = 1;
6699 starget = sas_device->starget;
6700 if (starget && starget->hostdata) {
6701 sas_target_priv_data = starget->hostdata;
6702 sas_target_priv_data->tm_busy = 0;
6703 sas_target_priv_data->deleted = 0;
6705 sas_target_priv_data = NULL;
6707 starget_printk(KERN_INFO, starget,
6708 "handle(0x%04x), sas_addr(0x%016llx), "
6709 "enclosure logical id(0x%016llx), "
6710 "slot(%d)\n", handle,
6711 (unsigned long long)sas_device->sas_address,
6712 (unsigned long long)
6713 sas_device->enclosure_logical_id,
6715 if (sas_device->handle == handle)
6717 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6718 sas_device->handle);
6719 sas_device->handle = handle;
6720 if (sas_target_priv_data)
6721 sas_target_priv_data->handle = handle;
6726 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6730 * _scsih_search_responding_sas_devices -
6731 * @ioc: per adapter object
6733 * After host reset, find out whether devices are still responding.
6739 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6741 Mpi2SasDevicePage0_t sas_device_pg0;
6742 Mpi2ConfigReply_t mpi_reply;
6749 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6751 if (list_empty(&ioc->sas_device_list))
6755 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6756 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6758 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6759 MPI2_IOCSTATUS_MASK;
6760 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6762 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6763 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6764 if (!(_scsih_is_end_device(device_info)))
6766 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6767 slot = le16_to_cpu(sas_device_pg0.Slot);
6768 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6772 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6777 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6778 * @ioc: per adapter object
6779 * @wwid: world wide identifier for raid volume
6780 * @handle: device handle
6782 * After host reset, find out whether devices are still responding.
6783 * Used in _scsi_remove_unresponsive_raid_devices.
6788 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6791 struct MPT2SAS_TARGET *sas_target_priv_data;
6792 struct scsi_target *starget;
6793 struct _raid_device *raid_device;
6794 unsigned long flags;
6796 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6797 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6798 if (raid_device->wwid == wwid && raid_device->starget) {
6799 starget = raid_device->starget;
6800 if (starget && starget->hostdata) {
6801 sas_target_priv_data = starget->hostdata;
6802 sas_target_priv_data->deleted = 0;
6804 sas_target_priv_data = NULL;
6805 raid_device->responding = 1;
6806 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6807 starget_printk(KERN_INFO, raid_device->starget,
6808 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6809 (unsigned long long)raid_device->wwid);
6811 * WARPDRIVE: The handles of the PDs might have changed
6812 * across the host reset so re-initialize the
6813 * required data for Direct IO
6815 _scsih_init_warpdrive_properties(ioc, raid_device);
6816 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6817 if (raid_device->handle == handle) {
6818 spin_unlock_irqrestore(&ioc->raid_device_lock,
6822 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6823 raid_device->handle);
6824 raid_device->handle = handle;
6825 if (sas_target_priv_data)
6826 sas_target_priv_data->handle = handle;
6827 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6832 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6836 * _scsih_search_responding_raid_devices -
6837 * @ioc: per adapter object
6839 * After host reset, find out whether devices are still responding.
6845 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6847 Mpi2RaidVolPage1_t volume_pg1;
6848 Mpi2RaidVolPage0_t volume_pg0;
6849 Mpi2RaidPhysDiskPage0_t pd_pg0;
6850 Mpi2ConfigReply_t mpi_reply;
6855 if (!ioc->ir_firmware)
6858 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6861 if (list_empty(&ioc->raid_device_list))
6865 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6866 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6867 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6868 MPI2_IOCSTATUS_MASK;
6869 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6871 handle = le16_to_cpu(volume_pg1.DevHandle);
6873 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6874 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6875 sizeof(Mpi2RaidVolPage0_t)))
6878 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6879 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6880 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6881 _scsih_mark_responding_raid_device(ioc,
6882 le64_to_cpu(volume_pg1.WWID), handle);
6885 /* refresh the pd_handles */
6886 if (!ioc->is_warpdrive) {
6887 phys_disk_num = 0xFF;
6888 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6889 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6890 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6892 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6893 MPI2_IOCSTATUS_MASK;
6894 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6896 phys_disk_num = pd_pg0.PhysDiskNum;
6897 handle = le16_to_cpu(pd_pg0.DevHandle);
6898 set_bit(handle, ioc->pd_handles);
6902 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6903 "complete\n", ioc->name);
6907 * _scsih_mark_responding_expander - mark a expander as responding
6908 * @ioc: per adapter object
6909 * @sas_address: sas address
6912 * After host reset, find out whether devices are still responding.
6913 * Used in _scsi_remove_unresponsive_expanders.
6918 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6921 struct _sas_node *sas_expander;
6922 unsigned long flags;
6925 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6926 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
6927 if (sas_expander->sas_address != sas_address)
6929 sas_expander->responding = 1;
6930 if (sas_expander->handle == handle)
6932 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6933 " from(0x%04x) to (0x%04x)!!!\n",
6934 (unsigned long long)sas_expander->sas_address,
6935 sas_expander->handle, handle);
6936 sas_expander->handle = handle;
6937 for (i = 0 ; i < sas_expander->num_phys ; i++)
6938 sas_expander->phy[i].handle = handle;
6942 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6946 * _scsih_search_responding_expanders -
6947 * @ioc: per adapter object
6949 * After host reset, find out whether devices are still responding.
6955 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6957 Mpi2ExpanderPage0_t expander_pg0;
6958 Mpi2ConfigReply_t mpi_reply;
6963 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6965 if (list_empty(&ioc->sas_expander_list))
6969 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6970 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6972 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6973 MPI2_IOCSTATUS_MASK;
6974 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
6977 handle = le16_to_cpu(expander_pg0.DevHandle);
6978 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6979 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6980 "sas_addr(0x%016llx)\n", handle,
6981 (unsigned long long)sas_address);
6982 _scsih_mark_responding_expander(ioc, sas_address, handle);
6986 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6990 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6991 * @ioc: per adapter object
6996 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6998 struct _sas_device *sas_device, *sas_device_next;
6999 struct _sas_node *sas_expander, *sas_expander_next;
7000 struct _raid_device *raid_device, *raid_device_next;
7001 struct list_head tmp_list;
7002 unsigned long flags;
7004 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
7007 /* removing unresponding end devices */
7008 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
7010 list_for_each_entry_safe(sas_device, sas_device_next,
7011 &ioc->sas_device_list, list) {
7012 if (!sas_device->responding)
7013 mpt2sas_device_remove_by_sas_address(ioc,
7014 sas_device->sas_address);
7016 sas_device->responding = 0;
7019 /* removing unresponding volumes */
7020 if (ioc->ir_firmware) {
7021 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
7022 "volumes\n", ioc->name);
7023 list_for_each_entry_safe(raid_device, raid_device_next,
7024 &ioc->raid_device_list, list) {
7025 if (!raid_device->responding)
7026 _scsih_sas_volume_delete(ioc,
7027 raid_device->handle);
7029 raid_device->responding = 0;
7032 /* removing unresponding expanders */
7033 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7035 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7036 INIT_LIST_HEAD(&tmp_list);
7037 list_for_each_entry_safe(sas_expander, sas_expander_next,
7038 &ioc->sas_expander_list, list) {
7039 if (!sas_expander->responding)
7040 list_move_tail(&sas_expander->list, &tmp_list);
7042 sas_expander->responding = 0;
7044 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7045 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7047 list_del(&sas_expander->list);
7048 _scsih_expander_node_remove(ioc, sas_expander);
7050 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7052 /* unblock devices */
7053 _scsih_ublock_io_all_device(ioc);
7057 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7058 struct _sas_node *sas_expander, u16 handle)
7060 Mpi2ExpanderPage1_t expander_pg1;
7061 Mpi2ConfigReply_t mpi_reply;
7064 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7065 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7066 &expander_pg1, i, handle))) {
7067 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7068 ioc->name, __FILE__, __LINE__, __func__);
7072 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7073 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7074 expander_pg1.NegotiatedLinkRate >> 4);
7079 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7080 * @ioc: per adapter object
7085 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
7087 Mpi2ExpanderPage0_t expander_pg0;
7088 Mpi2SasDevicePage0_t sas_device_pg0;
7089 Mpi2RaidVolPage1_t volume_pg1;
7090 Mpi2RaidVolPage0_t volume_pg0;
7091 Mpi2RaidPhysDiskPage0_t pd_pg0;
7092 Mpi2EventIrConfigElement_t element;
7093 Mpi2ConfigReply_t mpi_reply;
7096 u16 handle, parent_handle;
7098 struct _sas_device *sas_device;
7099 struct _sas_node *expander_device;
7100 static struct _raid_device *raid_device;
7102 unsigned long flags;
7104 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
7106 _scsih_sas_host_refresh(ioc);
7108 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders start\n",
7112 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7113 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7114 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7115 MPI2_IOCSTATUS_MASK;
7116 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7117 printk(MPT2SAS_INFO_FMT "\tbreak from expander scan: "
7118 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7119 ioc->name, ioc_status,
7120 le32_to_cpu(mpi_reply.IOCLogInfo));
7123 handle = le16_to_cpu(expander_pg0.DevHandle);
7124 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7125 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7126 ioc, le64_to_cpu(expander_pg0.SASAddress));
7127 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7128 if (expander_device)
7129 _scsih_refresh_expander_links(ioc, expander_device,
7132 printk(MPT2SAS_INFO_FMT "\tBEFORE adding expander: "
7133 "handle (0x%04x), sas_addr(0x%016llx)\n",
7134 ioc->name, handle, (unsigned long long)
7135 le64_to_cpu(expander_pg0.SASAddress));
7136 _scsih_expander_add(ioc, handle);
7137 printk(MPT2SAS_INFO_FMT "\tAFTER adding expander: "
7138 "handle (0x%04x), sas_addr(0x%016llx)\n",
7139 ioc->name, handle, (unsigned long long)
7140 le64_to_cpu(expander_pg0.SASAddress));
7144 printk(MPT2SAS_INFO_FMT "\tscan devices: expanders complete\n",
7147 if (!ioc->ir_firmware)
7150 printk(MPT2SAS_INFO_FMT "\tscan devices phys disk start\n", ioc->name);
7152 phys_disk_num = 0xFF;
7153 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7154 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7156 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7157 MPI2_IOCSTATUS_MASK;
7158 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7159 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan:"
7160 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7161 ioc->name, ioc_status,
7162 le32_to_cpu(mpi_reply.IOCLogInfo));
7165 phys_disk_num = pd_pg0.PhysDiskNum;
7166 handle = le16_to_cpu(pd_pg0.DevHandle);
7167 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7168 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7169 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7172 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7173 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7176 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7177 MPI2_IOCSTATUS_MASK;
7178 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7179 printk(MPT2SAS_INFO_FMT "\tbreak from phys disk scan "
7180 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7181 ioc->name, ioc_status,
7182 le32_to_cpu(mpi_reply.IOCLogInfo));
7185 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7186 if (!_scsih_get_sas_address(ioc, parent_handle,
7188 printk(MPT2SAS_INFO_FMT "\tBEFORE adding phys disk: "
7189 " handle (0x%04x), sas_addr(0x%016llx)\n",
7190 ioc->name, handle, (unsigned long long)
7191 le64_to_cpu(sas_device_pg0.SASAddress));
7192 mpt2sas_transport_update_links(ioc, sas_address,
7193 handle, sas_device_pg0.PhyNum,
7194 MPI2_SAS_NEG_LINK_RATE_1_5);
7195 set_bit(handle, ioc->pd_handles);
7197 /* This will retry adding the end device.
7198 * _scsih_add_device() will decide on retries and
7199 * return "1" when it should be retried
7201 while (_scsih_add_device(ioc, handle, retry_count++,
7205 printk(MPT2SAS_INFO_FMT "\tAFTER adding phys disk: "
7206 " handle (0x%04x), sas_addr(0x%016llx)\n",
7207 ioc->name, handle, (unsigned long long)
7208 le64_to_cpu(sas_device_pg0.SASAddress));
7212 printk(MPT2SAS_INFO_FMT "\tscan devices: phys disk complete\n",
7215 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes start\n", ioc->name);
7218 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7219 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7221 MPI2_IOCSTATUS_MASK;
7222 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7223 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7224 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7225 ioc->name, ioc_status,
7226 le32_to_cpu(mpi_reply.IOCLogInfo));
7229 handle = le16_to_cpu(volume_pg1.DevHandle);
7230 spin_lock_irqsave(&ioc->raid_device_lock, flags);
7231 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7232 le64_to_cpu(volume_pg1.WWID));
7233 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
7236 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7237 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7238 sizeof(Mpi2RaidVolPage0_t)))
7240 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7241 MPI2_IOCSTATUS_MASK;
7242 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7243 printk(MPT2SAS_INFO_FMT "\tbreak from volume scan: "
7244 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7245 ioc->name, ioc_status,
7246 le32_to_cpu(mpi_reply.IOCLogInfo));
7249 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7250 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7251 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7252 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7253 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7254 element.VolDevHandle = volume_pg1.DevHandle;
7255 printk(MPT2SAS_INFO_FMT "\tBEFORE adding volume: "
7256 " handle (0x%04x)\n", ioc->name,
7257 volume_pg1.DevHandle);
7258 _scsih_sas_volume_add(ioc, &element);
7259 printk(MPT2SAS_INFO_FMT "\tAFTER adding volume: "
7260 " handle (0x%04x)\n", ioc->name,
7261 volume_pg1.DevHandle);
7265 printk(MPT2SAS_INFO_FMT "\tscan devices: volumes complete\n",
7270 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices start\n",
7274 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7275 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7277 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7278 MPI2_IOCSTATUS_MASK;
7279 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
7280 printk(MPT2SAS_INFO_FMT "\tbreak from end device scan:"
7281 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7282 ioc->name, ioc_status,
7283 le32_to_cpu(mpi_reply.IOCLogInfo));
7286 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7287 if (!(_scsih_is_end_device(
7288 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7290 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7291 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7292 le64_to_cpu(sas_device_pg0.SASAddress));
7293 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7296 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7297 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7298 printk(MPT2SAS_INFO_FMT "\tBEFORE adding end device: "
7299 "handle (0x%04x), sas_addr(0x%016llx)\n",
7300 ioc->name, handle, (unsigned long long)
7301 le64_to_cpu(sas_device_pg0.SASAddress));
7302 mpt2sas_transport_update_links(ioc, sas_address, handle,
7303 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7305 /* This will retry adding the end device.
7306 * _scsih_add_device() will decide on retries and
7307 * return "1" when it should be retried
7309 while (_scsih_add_device(ioc, handle, retry_count++,
7313 printk(MPT2SAS_INFO_FMT "\tAFTER adding end device: "
7314 "handle (0x%04x), sas_addr(0x%016llx)\n",
7315 ioc->name, handle, (unsigned long long)
7316 le64_to_cpu(sas_device_pg0.SASAddress));
7320 printk(MPT2SAS_INFO_FMT "\tscan devices: end devices complete\n",
7323 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
7328 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7329 * @ioc: per adapter object
7330 * @reset_phase: phase
7332 * The handler for doing any required cleanup or initialization.
7334 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7335 * MPT2_IOC_DONE_RESET
7340 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7342 switch (reset_phase) {
7343 case MPT2_IOC_PRE_RESET:
7344 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7345 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
7347 case MPT2_IOC_AFTER_RESET:
7348 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7349 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
7350 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7351 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7352 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7353 complete(&ioc->scsih_cmds.done);
7355 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7356 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7357 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7358 complete(&ioc->tm_cmds.done);
7360 _scsih_fw_event_cleanup_queue(ioc);
7361 _scsih_flush_running_cmds(ioc);
7363 case MPT2_IOC_DONE_RESET:
7364 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
7365 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
7366 _scsih_sas_host_refresh(ioc);
7367 _scsih_prep_device_scan(ioc);
7368 _scsih_search_responding_sas_devices(ioc);
7369 _scsih_search_responding_raid_devices(ioc);
7370 _scsih_search_responding_expanders(ioc);
7371 if ((!ioc->is_driver_loading) && !(disable_discovery > 0 &&
7372 !ioc->sas_hba.num_phys)) {
7373 _scsih_prep_device_scan(ioc);
7374 _scsih_search_responding_sas_devices(ioc);
7375 _scsih_search_responding_raid_devices(ioc);
7376 _scsih_search_responding_expanders(ioc);
7377 _scsih_error_recovery_delete_devices(ioc);
7384 * _firmware_event_work - delayed task for processing firmware events
7385 * @ioc: per adapter object
7386 * @work: equal to the fw_event_work object
7392 _firmware_event_work(struct work_struct *work)
7394 struct fw_event_work *fw_event = container_of(work,
7395 struct fw_event_work, delayed_work.work);
7396 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7398 /* the queue is being flushed so ignore this event */
7399 if (ioc->remove_host ||
7400 ioc->pci_error_recovery) {
7401 _scsih_fw_event_free(ioc, fw_event);
7405 switch (fw_event->event) {
7406 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7407 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
7409 _scsih_remove_unresponding_sas_devices(ioc);
7410 _scsih_scan_for_devices_after_reset(ioc);
7412 case MPT2SAS_PORT_ENABLE_COMPLETE:
7413 ioc->start_scan = 0;
7415 if (missing_delay[0] != -1 && missing_delay[1] != -1)
7416 mpt2sas_base_update_missing_delay(ioc, missing_delay[0],
7419 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7420 "from worker thread\n", ioc->name));
7422 case MPT2SAS_TURN_ON_PFA_LED:
7423 _scsih_turn_on_pfa_led(ioc, fw_event->device_handle);
7425 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7426 _scsih_sas_topology_change_event(ioc, fw_event);
7428 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7429 _scsih_sas_device_status_change_event(ioc,
7432 case MPI2_EVENT_SAS_DISCOVERY:
7433 _scsih_sas_discovery_event(ioc,
7436 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7437 _scsih_sas_broadcast_primitive_event(ioc,
7440 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7441 _scsih_sas_enclosure_dev_status_change_event(ioc,
7444 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7445 _scsih_sas_ir_config_change_event(ioc, fw_event);
7447 case MPI2_EVENT_IR_VOLUME:
7448 _scsih_sas_ir_volume_event(ioc, fw_event);
7450 case MPI2_EVENT_IR_PHYSICAL_DISK:
7451 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
7453 case MPI2_EVENT_IR_OPERATION_STATUS:
7454 _scsih_sas_ir_operation_status_event(ioc, fw_event);
7457 _scsih_fw_event_free(ioc, fw_event);
7461 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7462 * @ioc: per adapter object
7463 * @msix_index: MSIX table index supplied by the OS
7464 * @reply: reply message frame(lower 32bit addr)
7465 * Context: interrupt.
7467 * This function merely adds a new work task into ioc->firmware_event_thread.
7468 * The tasks are worked from _firmware_event_work in user context.
7473 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7476 struct fw_event_work *fw_event;
7477 Mpi2EventNotificationReply_t *mpi_reply;
7481 /* events turned off due to host reset or driver unloading */
7482 if (ioc->remove_host || ioc->pci_error_recovery)
7485 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
7487 if (unlikely(!mpi_reply)) {
7488 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
7489 ioc->name, __FILE__, __LINE__, __func__);
7493 event = le16_to_cpu(mpi_reply->Event);
7497 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7499 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7500 (Mpi2EventDataSasBroadcastPrimitive_t *)
7501 mpi_reply->EventData;
7503 if (baen_data->Primitive !=
7504 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
7507 if (ioc->broadcast_aen_busy) {
7508 ioc->broadcast_aen_pending++;
7511 ioc->broadcast_aen_busy = 1;
7515 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7516 _scsih_check_topo_delete_events(ioc,
7517 (Mpi2EventDataSasTopologyChangeList_t *)
7518 mpi_reply->EventData);
7520 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7521 _scsih_check_ir_config_unhide_events(ioc,
7522 (Mpi2EventDataIrConfigChangeList_t *)
7523 mpi_reply->EventData);
7525 case MPI2_EVENT_IR_VOLUME:
7526 _scsih_check_volume_delete_events(ioc,
7527 (Mpi2EventDataIrVolume_t *)
7528 mpi_reply->EventData);
7530 case MPI2_EVENT_LOG_ENTRY_ADDED:
7532 Mpi2EventDataLogEntryAdded_t *log_entry;
7535 if (!ioc->is_warpdrive)
7538 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7539 mpi_reply->EventData;
7540 log_code = (__le32 *)log_entry->LogData;
7542 if (le16_to_cpu(log_entry->LogEntryQualifier)
7543 != MPT2_WARPDRIVE_LOGENTRY)
7546 switch (le32_to_cpu(*log_code)) {
7547 case MPT2_WARPDRIVE_LC_SSDT:
7548 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7549 "IO Throttling has occurred in the WarpDrive "
7550 "subsystem. Check WarpDrive documentation for "
7551 "additional details.\n", ioc->name);
7553 case MPT2_WARPDRIVE_LC_SSDLW:
7554 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7555 "Program/Erase Cycles for the WarpDrive subsystem "
7556 "in degraded range. Check WarpDrive documentation "
7557 "for additional details.\n", ioc->name);
7559 case MPT2_WARPDRIVE_LC_SSDLF:
7560 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7561 "There are no Program/Erase Cycles for the "
7562 "WarpDrive subsystem. The storage device will be "
7563 "in read-only mode. Check WarpDrive documentation "
7564 "for additional details.\n", ioc->name);
7566 case MPT2_WARPDRIVE_LC_BRMF:
7567 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7568 "The Backup Rail Monitor has failed on the "
7569 "WarpDrive subsystem. Check WarpDrive "
7570 "documentation for additional details.\n",
7577 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7578 case MPI2_EVENT_IR_OPERATION_STATUS:
7579 case MPI2_EVENT_SAS_DISCOVERY:
7580 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7581 case MPI2_EVENT_IR_PHYSICAL_DISK:
7584 default: /* ignore the rest */
7588 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7589 fw_event = kzalloc(sizeof(*fw_event) + sz, GFP_ATOMIC);
7591 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7592 ioc->name, __FILE__, __LINE__, __func__);
7596 memcpy(fw_event->event_data, mpi_reply->EventData, sz);
7597 fw_event->ioc = ioc;
7598 fw_event->VF_ID = mpi_reply->VF_ID;
7599 fw_event->VP_ID = mpi_reply->VP_ID;
7600 fw_event->event = event;
7601 _scsih_fw_event_add(ioc, fw_event);
7605 /* shost template */
7606 static struct scsi_host_template scsih_driver_template = {
7607 .module = THIS_MODULE,
7608 .name = "Fusion MPT SAS Host",
7609 .proc_name = MPT2SAS_DRIVER_NAME,
7610 .queuecommand = _scsih_qcmd,
7611 .target_alloc = _scsih_target_alloc,
7612 .slave_alloc = _scsih_slave_alloc,
7613 .slave_configure = _scsih_slave_configure,
7614 .target_destroy = _scsih_target_destroy,
7615 .slave_destroy = _scsih_slave_destroy,
7616 .scan_finished = _scsih_scan_finished,
7617 .scan_start = _scsih_scan_start,
7618 .change_queue_depth = _scsih_change_queue_depth,
7619 .change_queue_type = scsi_change_queue_type,
7620 .eh_abort_handler = _scsih_abort,
7621 .eh_device_reset_handler = _scsih_dev_reset,
7622 .eh_target_reset_handler = _scsih_target_reset,
7623 .eh_host_reset_handler = _scsih_host_reset,
7624 .bios_param = _scsih_bios_param,
7627 .sg_tablesize = MPT2SAS_SG_DEPTH,
7628 .max_sectors = 32767,
7630 .use_clustering = ENABLE_CLUSTERING,
7631 .shost_attrs = mpt2sas_host_attrs,
7632 .sdev_attrs = mpt2sas_dev_attrs,
7633 .track_queue_depth = 1,
7637 * _scsih_expander_node_remove - removing expander device from list.
7638 * @ioc: per adapter object
7639 * @sas_expander: the sas_device object
7640 * Context: Calling function should acquire ioc->sas_node_lock.
7642 * Removing object and freeing associated memory from the
7643 * ioc->sas_expander_list.
7648 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7649 struct _sas_node *sas_expander)
7651 struct _sas_port *mpt2sas_port, *next;
7653 /* remove sibling ports attached to this expander */
7654 list_for_each_entry_safe(mpt2sas_port, next,
7655 &sas_expander->sas_port_list, port_list) {
7656 if (ioc->shost_recovery)
7658 if (mpt2sas_port->remote_identify.device_type ==
7660 mpt2sas_device_remove_by_sas_address(ioc,
7661 mpt2sas_port->remote_identify.sas_address);
7662 else if (mpt2sas_port->remote_identify.device_type ==
7663 SAS_EDGE_EXPANDER_DEVICE ||
7664 mpt2sas_port->remote_identify.device_type ==
7665 SAS_FANOUT_EXPANDER_DEVICE)
7666 mpt2sas_expander_remove(ioc,
7667 mpt2sas_port->remote_identify.sas_address);
7670 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
7671 sas_expander->sas_address_parent);
7673 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7674 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7675 sas_expander->handle, (unsigned long long)
7676 sas_expander->sas_address);
7678 kfree(sas_expander->phy);
7679 kfree(sas_expander);
7683 * _scsih_ir_shutdown - IR shutdown notification
7684 * @ioc: per adapter object
7686 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7687 * the host system is shutting down.
7692 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7694 Mpi2RaidActionRequest_t *mpi_request;
7695 Mpi2RaidActionReply_t *mpi_reply;
7698 /* is IR firmware build loaded ? */
7699 if (!ioc->ir_firmware)
7702 mutex_lock(&ioc->scsih_cmds.mutex);
7704 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7705 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7706 ioc->name, __func__);
7709 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7711 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7713 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7714 ioc->name, __func__);
7715 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7719 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7720 ioc->scsih_cmds.smid = smid;
7721 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7723 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7724 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7726 if (!ioc->hide_ir_msg)
7727 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
7728 init_completion(&ioc->scsih_cmds.done);
7729 mpt2sas_base_put_smid_default(ioc, smid);
7730 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7732 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7733 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7734 ioc->name, __func__);
7738 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7739 mpi_reply = ioc->scsih_cmds.reply;
7741 if (!ioc->hide_ir_msg)
7742 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7743 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7744 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7745 le32_to_cpu(mpi_reply->IOCLogInfo));
7749 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7750 mutex_unlock(&ioc->scsih_cmds.mutex);
7754 * _scsih_shutdown - routine call during system shutdown
7755 * @pdev: PCI device struct
7760 _scsih_shutdown(struct pci_dev *pdev)
7762 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7763 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7764 struct workqueue_struct *wq;
7765 unsigned long flags;
7767 ioc->remove_host = 1;
7768 _scsih_fw_event_cleanup_queue(ioc);
7770 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7771 wq = ioc->firmware_event_thread;
7772 ioc->firmware_event_thread = NULL;
7773 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7775 destroy_workqueue(wq);
7777 _scsih_ir_shutdown(ioc);
7778 mpt2sas_base_detach(ioc);
7782 * _scsih_remove - detach and remove add host
7783 * @pdev: PCI device struct
7785 * Routine called when unloading the driver.
7789 _scsih_remove(struct pci_dev *pdev)
7791 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7792 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7793 struct _sas_port *mpt2sas_port, *next_port;
7794 struct _raid_device *raid_device, *next;
7795 struct MPT2SAS_TARGET *sas_target_priv_data;
7796 struct workqueue_struct *wq;
7797 unsigned long flags;
7799 ioc->remove_host = 1;
7800 _scsih_fw_event_cleanup_queue(ioc);
7802 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7803 wq = ioc->firmware_event_thread;
7804 ioc->firmware_event_thread = NULL;
7805 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7807 destroy_workqueue(wq);
7809 /* release all the volumes */
7810 _scsih_ir_shutdown(ioc);
7811 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7813 if (raid_device->starget) {
7814 sas_target_priv_data =
7815 raid_device->starget->hostdata;
7816 sas_target_priv_data->deleted = 1;
7817 scsi_remove_target(&raid_device->starget->dev);
7819 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7820 "(0x%016llx)\n", ioc->name, raid_device->handle,
7821 (unsigned long long) raid_device->wwid);
7822 _scsih_raid_device_remove(ioc, raid_device);
7825 /* free ports attached to the sas_host */
7826 list_for_each_entry_safe(mpt2sas_port, next_port,
7827 &ioc->sas_hba.sas_port_list, port_list) {
7828 if (mpt2sas_port->remote_identify.device_type ==
7830 mpt2sas_device_remove_by_sas_address(ioc,
7831 mpt2sas_port->remote_identify.sas_address);
7832 else if (mpt2sas_port->remote_identify.device_type ==
7833 SAS_EDGE_EXPANDER_DEVICE ||
7834 mpt2sas_port->remote_identify.device_type ==
7835 SAS_FANOUT_EXPANDER_DEVICE)
7836 mpt2sas_expander_remove(ioc,
7837 mpt2sas_port->remote_identify.sas_address);
7840 /* free phys attached to the sas_host */
7841 if (ioc->sas_hba.num_phys) {
7842 kfree(ioc->sas_hba.phy);
7843 ioc->sas_hba.phy = NULL;
7844 ioc->sas_hba.num_phys = 0;
7847 sas_remove_host(shost);
7848 scsi_remove_host(shost);
7849 mpt2sas_base_detach(ioc);
7850 list_del(&ioc->list);
7851 scsi_host_put(shost);
7855 * _scsih_probe_boot_devices - reports 1st device
7856 * @ioc: per adapter object
7858 * If specified in bios page 2, this routine reports the 1st
7859 * device scsi-ml or sas transport for persistent boot device
7860 * purposes. Please refer to function _scsih_determine_boot_device()
7863 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7867 struct _sas_device *sas_device;
7868 struct _raid_device *raid_device;
7870 u64 sas_address_parent;
7872 unsigned long flags;
7875 /* no Bios, return immediately */
7876 if (!ioc->bios_pg3.BiosVersion)
7881 if (ioc->req_boot_device.device) {
7882 device = ioc->req_boot_device.device;
7883 is_raid = ioc->req_boot_device.is_raid;
7884 } else if (ioc->req_alt_boot_device.device) {
7885 device = ioc->req_alt_boot_device.device;
7886 is_raid = ioc->req_alt_boot_device.is_raid;
7887 } else if (ioc->current_boot_device.device) {
7888 device = ioc->current_boot_device.device;
7889 is_raid = ioc->current_boot_device.is_raid;
7896 raid_device = device;
7897 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7898 raid_device->id, 0);
7900 _scsih_raid_device_remove(ioc, raid_device);
7902 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7903 sas_device = device;
7904 handle = sas_device->handle;
7905 sas_address_parent = sas_device->sas_address_parent;
7906 sas_address = sas_device->sas_address;
7907 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7908 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7910 if (ioc->hide_drives)
7912 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7913 sas_device->sas_address_parent)) {
7914 _scsih_sas_device_remove(ioc, sas_device);
7915 } else if (!sas_device->starget) {
7916 if (!ioc->is_driver_loading) {
7917 mpt2sas_transport_port_remove(ioc,
7919 sas_address_parent);
7920 _scsih_sas_device_remove(ioc, sas_device);
7927 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7928 * @ioc: per adapter object
7930 * Called during initial loading of the driver.
7933 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7935 struct _raid_device *raid_device, *raid_next;
7938 list_for_each_entry_safe(raid_device, raid_next,
7939 &ioc->raid_device_list, list) {
7940 if (raid_device->starget)
7942 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7943 raid_device->id, 0);
7945 _scsih_raid_device_remove(ioc, raid_device);
7950 * _scsih_probe_sas - reporting sas devices to sas transport
7951 * @ioc: per adapter object
7953 * Called during initial loading of the driver.
7956 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7958 struct _sas_device *sas_device, *next;
7959 unsigned long flags;
7961 /* SAS Device List */
7962 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7965 if (ioc->hide_drives)
7968 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7969 sas_device->sas_address_parent)) {
7970 list_del(&sas_device->list);
7973 } else if (!sas_device->starget) {
7974 if (!ioc->is_driver_loading) {
7975 mpt2sas_transport_port_remove(ioc,
7976 sas_device->sas_address,
7977 sas_device->sas_address_parent);
7978 list_del(&sas_device->list);
7983 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7984 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7985 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7990 * _scsih_probe_devices - probing for devices
7991 * @ioc: per adapter object
7993 * Called during initial loading of the driver.
7996 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7998 u16 volume_mapping_flags;
8000 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
8001 return; /* return when IOC doesn't support initiator mode */
8003 _scsih_probe_boot_devices(ioc);
8005 if (ioc->ir_firmware) {
8006 volume_mapping_flags =
8007 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
8008 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
8009 if (volume_mapping_flags ==
8010 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
8011 _scsih_probe_raid(ioc);
8012 _scsih_probe_sas(ioc);
8014 _scsih_probe_sas(ioc);
8015 _scsih_probe_raid(ioc);
8018 _scsih_probe_sas(ioc);
8023 * _scsih_scan_start - scsi lld callback for .scan_start
8024 * @shost: SCSI host pointer
8026 * The shost has the ability to discover targets on its own instead
8027 * of scanning the entire bus. In our implemention, we will kick off
8028 * firmware discovery.
8031 _scsih_scan_start(struct Scsi_Host *shost)
8033 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8036 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
8037 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
8039 if (disable_discovery > 0)
8042 ioc->start_scan = 1;
8043 rc = mpt2sas_port_enable(ioc);
8046 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
8050 * _scsih_scan_finished - scsi lld callback for .scan_finished
8051 * @shost: SCSI host pointer
8052 * @time: elapsed time of the scan in jiffies
8054 * This function will be called periodically until it returns 1 with the
8055 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8056 * we wait for firmware discovery to complete, then return 1.
8059 _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
8061 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8063 if (disable_discovery > 0) {
8064 ioc->is_driver_loading = 0;
8065 ioc->wait_for_discovery_to_complete = 0;
8069 if (time >= (300 * HZ)) {
8070 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8071 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
8072 "(timeout=300s)\n", ioc->name);
8073 ioc->is_driver_loading = 0;
8077 if (ioc->start_scan)
8080 if (ioc->start_scan_failed) {
8081 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
8082 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
8083 ioc->is_driver_loading = 0;
8084 ioc->wait_for_discovery_to_complete = 0;
8085 ioc->remove_host = 1;
8089 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
8090 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
8092 if (ioc->wait_for_discovery_to_complete) {
8093 ioc->wait_for_discovery_to_complete = 0;
8094 _scsih_probe_devices(ioc);
8096 mpt2sas_base_start_watchdog(ioc);
8097 ioc->is_driver_loading = 0;
8103 * _scsih_probe - attach and add scsi host
8104 * @pdev: PCI device struct
8105 * @id: pci device id
8107 * Returns 0 success, anything else error.
8110 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
8112 struct MPT2SAS_ADAPTER *ioc;
8113 struct Scsi_Host *shost;
8116 shost = scsi_host_alloc(&scsih_driver_template,
8117 sizeof(struct MPT2SAS_ADAPTER));
8121 /* init local params */
8122 ioc = shost_priv(shost);
8123 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
8124 INIT_LIST_HEAD(&ioc->list);
8125 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
8127 ioc->id = mpt_ids++;
8128 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
8130 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
8131 ioc->is_warpdrive = 1;
8132 ioc->hide_ir_msg = 1;
8134 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
8135 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
8136 ioc->tm_cb_idx = tm_cb_idx;
8137 ioc->ctl_cb_idx = ctl_cb_idx;
8138 ioc->base_cb_idx = base_cb_idx;
8139 ioc->port_enable_cb_idx = port_enable_cb_idx;
8140 ioc->transport_cb_idx = transport_cb_idx;
8141 ioc->scsih_cb_idx = scsih_cb_idx;
8142 ioc->config_cb_idx = config_cb_idx;
8143 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
8144 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
8145 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
8146 ioc->logging_level = logging_level;
8147 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
8148 /* misc semaphores and spin locks */
8149 mutex_init(&ioc->reset_in_progress_mutex);
8150 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8151 spin_lock_init(&ioc->scsi_lookup_lock);
8152 spin_lock_init(&ioc->sas_device_lock);
8153 spin_lock_init(&ioc->sas_node_lock);
8154 spin_lock_init(&ioc->fw_event_lock);
8155 spin_lock_init(&ioc->raid_device_lock);
8157 INIT_LIST_HEAD(&ioc->sas_device_list);
8158 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8159 INIT_LIST_HEAD(&ioc->sas_expander_list);
8160 INIT_LIST_HEAD(&ioc->fw_event_list);
8161 INIT_LIST_HEAD(&ioc->raid_device_list);
8162 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
8163 INIT_LIST_HEAD(&ioc->delayed_tr_list);
8164 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
8165 INIT_LIST_HEAD(&ioc->reply_queue_list);
8167 /* init shost parameters */
8168 shost->max_cmd_len = 32;
8169 shost->max_lun = max_lun;
8170 shost->transportt = mpt2sas_transport_template;
8171 shost->unique_id = ioc->id;
8173 if (max_sectors != 0xFFFF) {
8174 if (max_sectors < 64) {
8175 shost->max_sectors = 64;
8176 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8177 "for max_sectors, range is 64 to 32767. Assigning "
8178 "value of 64.\n", ioc->name, max_sectors);
8179 } else if (max_sectors > 32767) {
8180 shost->max_sectors = 32767;
8181 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8182 "for max_sectors, range is 64 to 8192. Assigning "
8183 "default value of 32767.\n", ioc->name,
8186 shost->max_sectors = max_sectors & 0xFFFE;
8187 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8188 "set to %d\n", ioc->name, shost->max_sectors);
8192 /* register EEDP capabilities with SCSI layer */
8194 scsi_host_set_prot(shost, prot_mask);
8196 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
8197 | SHOST_DIF_TYPE2_PROTECTION
8198 | SHOST_DIF_TYPE3_PROTECTION);
8200 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
8203 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8204 "fw_event%d", ioc->id);
8205 ioc->firmware_event_thread = create_singlethread_workqueue(
8206 ioc->firmware_event_name);
8207 if (!ioc->firmware_event_thread) {
8208 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8209 ioc->name, __FILE__, __LINE__, __func__);
8211 goto out_thread_fail;
8214 ioc->is_driver_loading = 1;
8215 if ((mpt2sas_base_attach(ioc))) {
8216 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8217 ioc->name, __FILE__, __LINE__, __func__);
8219 goto out_attach_fail;
8222 if (ioc->is_warpdrive) {
8223 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8224 ioc->hide_drives = 0;
8225 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8226 ioc->hide_drives = 1;
8228 if (_scsih_get_num_volumes(ioc))
8229 ioc->hide_drives = 1;
8231 ioc->hide_drives = 0;
8234 ioc->hide_drives = 0;
8236 rv = scsi_add_host(shost, &pdev->dev);
8238 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8239 ioc->name, __FILE__, __LINE__, __func__);
8240 goto out_add_shost_fail;
8243 scsi_scan_host(shost);
8248 mpt2sas_base_detach(ioc);
8250 destroy_workqueue(ioc->firmware_event_thread);
8252 list_del(&ioc->list);
8253 scsi_host_put(shost);
8259 * _scsih_suspend - power management suspend main entry point
8260 * @pdev: PCI device struct
8261 * @state: PM state change to (usually PCI_D3)
8263 * Returns 0 success, anything else error.
8266 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
8268 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8269 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8270 pci_power_t device_state;
8272 mpt2sas_base_stop_watchdog(ioc);
8273 scsi_block_requests(shost);
8274 _scsih_ir_shutdown(ioc);
8275 device_state = pci_choose_state(pdev, state);
8276 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8277 "operating state [D%d]\n", ioc->name, pdev,
8278 pci_name(pdev), device_state);
8280 mpt2sas_base_free_resources(ioc);
8281 pci_save_state(pdev);
8282 pci_set_power_state(pdev, device_state);
8287 * _scsih_resume - power management resume main entry point
8288 * @pdev: PCI device struct
8290 * Returns 0 success, anything else error.
8293 _scsih_resume(struct pci_dev *pdev)
8295 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8296 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8297 pci_power_t device_state = pdev->current_state;
8300 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8301 "operating state [D%d]\n", ioc->name, pdev,
8302 pci_name(pdev), device_state);
8304 pci_set_power_state(pdev, PCI_D0);
8305 pci_enable_wake(pdev, PCI_D0, 0);
8306 pci_restore_state(pdev);
8308 r = mpt2sas_base_map_resources(ioc);
8312 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8313 scsi_unblock_requests(shost);
8314 mpt2sas_base_start_watchdog(ioc);
8317 #endif /* CONFIG_PM */
8320 * _scsih_pci_error_detected - Called when a PCI error is detected.
8321 * @pdev: PCI device struct
8322 * @state: PCI channel state
8324 * Description: Called when a PCI error is detected.
8327 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8329 static pci_ers_result_t
8330 _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8332 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8333 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8335 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8339 case pci_channel_io_normal:
8340 return PCI_ERS_RESULT_CAN_RECOVER;
8341 case pci_channel_io_frozen:
8342 /* Fatal error, prepare for slot reset */
8343 ioc->pci_error_recovery = 1;
8344 scsi_block_requests(ioc->shost);
8345 mpt2sas_base_stop_watchdog(ioc);
8346 mpt2sas_base_free_resources(ioc);
8347 return PCI_ERS_RESULT_NEED_RESET;
8348 case pci_channel_io_perm_failure:
8349 /* Permanent error, prepare for device removal */
8350 ioc->pci_error_recovery = 1;
8351 mpt2sas_base_stop_watchdog(ioc);
8352 _scsih_flush_running_cmds(ioc);
8353 return PCI_ERS_RESULT_DISCONNECT;
8355 return PCI_ERS_RESULT_NEED_RESET;
8359 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8360 * @pdev: PCI device struct
8362 * Description: This routine is called by the pci error recovery
8363 * code after the PCI slot has been reset, just before we
8364 * should resume normal operations.
8366 static pci_ers_result_t
8367 _scsih_pci_slot_reset(struct pci_dev *pdev)
8369 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8370 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8373 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8376 ioc->pci_error_recovery = 0;
8378 pci_restore_state(pdev);
8379 rc = mpt2sas_base_map_resources(ioc);
8381 return PCI_ERS_RESULT_DISCONNECT;
8384 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8387 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8388 (rc == 0) ? "success" : "failed");
8391 return PCI_ERS_RESULT_RECOVERED;
8393 return PCI_ERS_RESULT_DISCONNECT;
8397 * _scsih_pci_resume() - resume normal ops after PCI reset
8398 * @pdev: pointer to PCI device
8400 * Called when the error recovery driver tells us that its
8401 * OK to resume normal operation. Use completion to allow
8402 * halted scsi ops to resume.
8405 _scsih_pci_resume(struct pci_dev *pdev)
8407 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8408 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8410 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8412 pci_cleanup_aer_uncorrect_error_status(pdev);
8413 mpt2sas_base_start_watchdog(ioc);
8414 scsi_unblock_requests(ioc->shost);
8418 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8419 * @pdev: pointer to PCI device
8421 static pci_ers_result_t
8422 _scsih_pci_mmio_enabled(struct pci_dev *pdev)
8424 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8425 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8427 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8430 /* TODO - dump whatever for debugging purposes */
8432 /* Request a slot reset. */
8433 return PCI_ERS_RESULT_NEED_RESET;
8436 static const struct pci_error_handlers _scsih_err_handler = {
8437 .error_detected = _scsih_pci_error_detected,
8438 .mmio_enabled = _scsih_pci_mmio_enabled,
8439 .slot_reset = _scsih_pci_slot_reset,
8440 .resume = _scsih_pci_resume,
8443 static struct pci_driver scsih_driver = {
8444 .name = MPT2SAS_DRIVER_NAME,
8445 .id_table = scsih_pci_table,
8446 .probe = _scsih_probe,
8447 .remove = _scsih_remove,
8448 .shutdown = _scsih_shutdown,
8449 .err_handler = &_scsih_err_handler,
8451 .suspend = _scsih_suspend,
8452 .resume = _scsih_resume,
8456 /* raid transport support */
8457 static struct raid_function_template mpt2sas_raid_functions = {
8458 .cookie = &scsih_driver_template,
8459 .is_raid = _scsih_is_raid,
8460 .get_resync = _scsih_get_resync,
8461 .get_state = _scsih_get_state,
8465 * _scsih_init - main entry point for this driver.
8467 * Returns 0 success, anything else error.
8475 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8476 MPT2SAS_DRIVER_VERSION);
8478 mpt2sas_transport_template =
8479 sas_attach_transport(&mpt2sas_transport_functions);
8480 if (!mpt2sas_transport_template)
8482 /* raid transport support */
8483 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8484 if (!mpt2sas_raid_template) {
8485 sas_release_transport(mpt2sas_transport_template);
8489 mpt2sas_base_initialize_callback_handler();
8491 /* queuecommand callback hander */
8492 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
8494 /* task management callback handler */
8495 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
8497 /* base internal commands callback handler */
8498 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8499 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8500 mpt2sas_port_enable_done);
8502 /* transport internal commands callback handler */
8503 transport_cb_idx = mpt2sas_base_register_callback_handler(
8504 mpt2sas_transport_done);
8506 /* scsih internal commands callback handler */
8507 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8509 /* configuration page API internal commands callback handler */
8510 config_cb_idx = mpt2sas_base_register_callback_handler(
8511 mpt2sas_config_done);
8513 /* ctl module callback handler */
8514 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8516 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8517 _scsih_tm_tr_complete);
8519 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8520 _scsih_tm_volume_tr_complete);
8522 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8523 _scsih_sas_control_complete);
8527 error = pci_register_driver(&scsih_driver);
8529 /* raid transport support */
8530 raid_class_release(mpt2sas_raid_template);
8531 sas_release_transport(mpt2sas_transport_template);
8538 * _scsih_exit - exit point for this driver (when it is a module).
8540 * Returns 0 success, anything else error.
8545 printk(KERN_INFO "mpt2sas version %s unloading\n",
8546 MPT2SAS_DRIVER_VERSION);
8548 pci_unregister_driver(&scsih_driver);
8552 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8553 mpt2sas_base_release_callback_handler(tm_cb_idx);
8554 mpt2sas_base_release_callback_handler(base_cb_idx);
8555 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
8556 mpt2sas_base_release_callback_handler(transport_cb_idx);
8557 mpt2sas_base_release_callback_handler(scsih_cb_idx);
8558 mpt2sas_base_release_callback_handler(config_cb_idx);
8559 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8561 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
8562 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
8563 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8565 /* raid transport support */
8566 raid_class_release(mpt2sas_raid_template);
8567 sas_release_transport(mpt2sas_transport_template);
8571 module_init(_scsih_init);
8572 module_exit(_scsih_exit);