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-2013 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
69 struct _sas_node
*sas_expander
);
70 static void _firmware_event_work(struct work_struct
*work
);
72 static u8
_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
);
74 static void _scsih_scan_start(struct Scsi_Host
*shost
);
75 static int _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
);
77 /* global parameters */
78 LIST_HEAD(mpt2sas_ioc_list
);
80 /* local parameters */
81 static u8 scsi_io_cb_idx
= -1;
82 static u8 tm_cb_idx
= -1;
83 static u8 ctl_cb_idx
= -1;
84 static u8 base_cb_idx
= -1;
85 static u8 port_enable_cb_idx
= -1;
86 static u8 transport_cb_idx
= -1;
87 static u8 scsih_cb_idx
= -1;
88 static u8 config_cb_idx
= -1;
91 static u8 tm_tr_cb_idx
= -1 ;
92 static u8 tm_tr_volume_cb_idx
= -1 ;
93 static u8 tm_sas_control_cb_idx
= -1;
95 /* command line options */
96 static u32 logging_level
;
97 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
100 static ushort max_sectors
= 0xFFFF;
101 module_param(max_sectors
, ushort
, 0);
102 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
104 static int missing_delay
[2] = {-1, -1};
105 module_param_array(missing_delay
, int, NULL
, 0);
106 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
108 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
109 #define MPT2SAS_MAX_LUN (16895)
110 static int max_lun
= MPT2SAS_MAX_LUN
;
111 module_param(max_lun
, int, 0);
112 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
114 /* diag_buffer_enable is bitwise
116 * bit 1 set = SNAPSHOT
117 * bit 2 set = EXTENDED
119 * Either bit can be set, or both
121 static int diag_buffer_enable
= -1;
122 module_param(diag_buffer_enable
, int, 0);
123 MODULE_PARM_DESC(diag_buffer_enable
, " post diag buffers "
124 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
126 static int disable_discovery
= -1;
127 module_param(disable_discovery
, int, 0);
128 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
130 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
131 static int prot_mask
= 0;
132 module_param(prot_mask
, int, 0);
133 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
136 * struct sense_info - common structure for obtaining sense keys
138 * @asc: additional sense code
139 * @ascq: additional sense code qualifier
148 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
149 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
150 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
152 * struct fw_event_work - firmware event struct
153 * @list: link list framework
154 * @work: work object (ioc->fault_reset_work_q)
155 * @cancel_pending_work: flag set during reset handling
156 * @ioc: per adapter object
157 * @device_handle: device handle
158 * @VF_ID: virtual function id
159 * @VP_ID: virtual port id
160 * @ignore: flag meaning this event has been marked to ignore
161 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
162 * @event_data: reply event data payload follows
164 * This object stored on ioc->fw_event_list.
166 struct fw_event_work
{
167 struct list_head list
;
168 u8 cancel_pending_work
;
169 struct delayed_work delayed_work
;
170 struct MPT2SAS_ADAPTER
*ioc
;
179 /* raid transport support */
180 static struct raid_template
*mpt2sas_raid_template
;
183 * struct _scsi_io_transfer - scsi io transfer
184 * @handle: sas device handle (assigned by firmware)
185 * @is_raid: flag set for hidden raid components
186 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
187 * @data_length: data transfer length
188 * @data_dma: dma pointer to data
191 * @cdb_length: cdb length
193 * @timeout: timeout for this command
194 * @VF_ID: virtual function id
195 * @VP_ID: virtual port id
196 * @valid_reply: flag set for reply message
197 * @sense_length: sense length
198 * @ioc_status: ioc status
199 * @scsi_state: scsi state
200 * @scsi_status: scsi staus
201 * @log_info: log information
202 * @transfer_length: data length transfer when there is a reply message
204 * Used for sending internal scsi commands to devices within this module.
205 * Refer to _scsi_send_scsi_io().
207 struct _scsi_io_transfer
{
210 enum dma_data_direction dir
;
213 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
221 /* the following bits are only valid when 'valid_reply = 1' */
231 * The pci device ids are defined in mpi/mpi2_cnfg.h.
233 static struct pci_device_id scsih_pci_table
[] = {
234 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
235 PCI_ANY_ID
, PCI_ANY_ID
},
237 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
238 PCI_ANY_ID
, PCI_ANY_ID
},
239 /* Liberator ~ 2108 */
240 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
241 PCI_ANY_ID
, PCI_ANY_ID
},
242 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
243 PCI_ANY_ID
, PCI_ANY_ID
},
244 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
245 PCI_ANY_ID
, PCI_ANY_ID
},
247 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
248 PCI_ANY_ID
, PCI_ANY_ID
},
249 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
250 PCI_ANY_ID
, PCI_ANY_ID
},
251 /* Thunderbolt ~ 2208 */
252 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
253 PCI_ANY_ID
, PCI_ANY_ID
},
254 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
255 PCI_ANY_ID
, PCI_ANY_ID
},
256 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
257 PCI_ANY_ID
, PCI_ANY_ID
},
258 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
259 PCI_ANY_ID
, PCI_ANY_ID
},
260 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
261 PCI_ANY_ID
, PCI_ANY_ID
},
262 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
263 PCI_ANY_ID
, PCI_ANY_ID
},
265 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
266 PCI_ANY_ID
, PCI_ANY_ID
},
267 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
268 PCI_ANY_ID
, PCI_ANY_ID
},
269 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
270 PCI_ANY_ID
, PCI_ANY_ID
},
272 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
273 PCI_ANY_ID
, PCI_ANY_ID
},
274 {0} /* Terminating entry */
276 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
279 * _scsih_set_debug_level - global setting of ioc->logging_level.
281 * Note: The logging levels are defined in mpt2sas_debug.h.
284 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
286 int ret
= param_set_int(val
, kp
);
287 struct MPT2SAS_ADAPTER
*ioc
;
292 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
293 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
294 ioc
->logging_level
= logging_level
;
297 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
298 &logging_level
, 0644);
301 * _scsih_srch_boot_sas_address - search based on sas_address
302 * @sas_address: sas address
303 * @boot_device: boot device object from bios page 2
305 * Returns 1 when there's a match, 0 means no match.
308 _scsih_srch_boot_sas_address(u64 sas_address
,
309 Mpi2BootDeviceSasWwid_t
*boot_device
)
311 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
315 * _scsih_srch_boot_device_name - search based on device name
316 * @device_name: device name specified in INDENTIFY fram
317 * @boot_device: boot device object from bios page 2
319 * Returns 1 when there's a match, 0 means no match.
322 _scsih_srch_boot_device_name(u64 device_name
,
323 Mpi2BootDeviceDeviceName_t
*boot_device
)
325 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
329 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
330 * @enclosure_logical_id: enclosure logical id
331 * @slot_number: slot number
332 * @boot_device: boot device object from bios page 2
334 * Returns 1 when there's a match, 0 means no match.
337 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
338 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
340 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
341 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
342 SlotNumber
)) ? 1 : 0;
346 * _scsih_is_boot_device - search for matching boot device.
347 * @sas_address: sas address
348 * @device_name: device name specified in INDENTIFY fram
349 * @enclosure_logical_id: enclosure logical id
350 * @slot_number: slot number
351 * @form: specifies boot device form
352 * @boot_device: boot device object from bios page 2
354 * Returns 1 when there's a match, 0 means no match.
357 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
358 u64 enclosure_logical_id
, u16 slot
, u8 form
,
359 Mpi2BiosPage2BootDevice_t
*boot_device
)
364 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
367 rc
= _scsih_srch_boot_sas_address(
368 sas_address
, &boot_device
->SasWwid
);
370 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
371 if (!enclosure_logical_id
)
373 rc
= _scsih_srch_boot_encl_slot(
374 enclosure_logical_id
,
375 slot
, &boot_device
->EnclosureSlot
);
377 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
380 rc
= _scsih_srch_boot_device_name(
381 device_name
, &boot_device
->DeviceName
);
383 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
391 * _scsih_get_sas_address - set the sas_address for given device handle
392 * @handle: device handle
393 * @sas_address: sas address
395 * Returns 0 success, non-zero when failure
398 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
401 Mpi2SasDevicePage0_t sas_device_pg0
;
402 Mpi2ConfigReply_t mpi_reply
;
406 if (handle
<= ioc
->sas_hba
.num_phys
) {
407 *sas_address
= ioc
->sas_hba
.sas_address
;
411 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
412 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
413 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
414 __FILE__
, __LINE__
, __func__
);
418 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
419 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
420 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
424 /* we hit this becuase the given parent handle doesn't exist */
425 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
427 /* else error case */
428 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x), "
429 "failure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
430 __FILE__
, __LINE__
, __func__
);
435 * _scsih_determine_boot_device - determine boot device.
436 * @ioc: per adapter object
437 * @device: either sas_device or raid_device object
438 * @is_raid: [flag] 1 = raid object, 0 = sas object
440 * Determines whether this device should be first reported device to
441 * to scsi-ml or sas transport, this purpose is for persistent boot device.
442 * There are primary, alternate, and current entries in bios page 2. The order
443 * priority is primary, alternate, then current. This routine saves
444 * the corresponding device object and is_raid flag in the ioc object.
445 * The saved data to be used later in _scsih_probe_boot_devices().
448 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
449 void *device
, u8 is_raid
)
451 struct _sas_device
*sas_device
;
452 struct _raid_device
*raid_device
;
455 u64 enclosure_logical_id
;
458 /* only process this function when driver loads */
459 if (!ioc
->is_driver_loading
)
462 /* no Bios, return immediately */
463 if (!ioc
->bios_pg3
.BiosVersion
)
468 sas_address
= sas_device
->sas_address
;
469 device_name
= sas_device
->device_name
;
470 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
471 slot
= sas_device
->slot
;
473 raid_device
= device
;
474 sas_address
= raid_device
->wwid
;
476 enclosure_logical_id
= 0;
480 if (!ioc
->req_boot_device
.device
) {
481 if (_scsih_is_boot_device(sas_address
, device_name
,
482 enclosure_logical_id
, slot
,
483 (ioc
->bios_pg2
.ReqBootDeviceForm
&
484 MPI2_BIOSPAGE2_FORM_MASK
),
485 &ioc
->bios_pg2
.RequestedBootDevice
)) {
486 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
487 "%s: req_boot_device(0x%016llx)\n",
489 (unsigned long long)sas_address
));
490 ioc
->req_boot_device
.device
= device
;
491 ioc
->req_boot_device
.is_raid
= is_raid
;
495 if (!ioc
->req_alt_boot_device
.device
) {
496 if (_scsih_is_boot_device(sas_address
, device_name
,
497 enclosure_logical_id
, slot
,
498 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
499 MPI2_BIOSPAGE2_FORM_MASK
),
500 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
501 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
502 "%s: req_alt_boot_device(0x%016llx)\n",
504 (unsigned long long)sas_address
));
505 ioc
->req_alt_boot_device
.device
= device
;
506 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
510 if (!ioc
->current_boot_device
.device
) {
511 if (_scsih_is_boot_device(sas_address
, device_name
,
512 enclosure_logical_id
, slot
,
513 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
514 MPI2_BIOSPAGE2_FORM_MASK
),
515 &ioc
->bios_pg2
.CurrentBootDevice
)) {
516 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
517 "%s: current_boot_device(0x%016llx)\n",
519 (unsigned long long)sas_address
));
520 ioc
->current_boot_device
.device
= device
;
521 ioc
->current_boot_device
.is_raid
= is_raid
;
527 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
528 * @ioc: per adapter object
529 * @sas_address: sas address
530 * Context: Calling function should acquire ioc->sas_device_lock
532 * This searches for sas_device based on sas_address, then return sas_device
536 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
539 struct _sas_device
*sas_device
;
541 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
542 if (sas_device
->sas_address
== sas_address
)
545 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
546 if (sas_device
->sas_address
== sas_address
)
553 * _scsih_sas_device_find_by_handle - sas device search
554 * @ioc: per adapter object
555 * @handle: sas device handle (assigned by firmware)
556 * Context: Calling function should acquire ioc->sas_device_lock
558 * This searches for sas_device based on sas_address, then return sas_device
561 static struct _sas_device
*
562 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
564 struct _sas_device
*sas_device
;
566 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
567 if (sas_device
->handle
== handle
)
570 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
571 if (sas_device
->handle
== handle
)
578 * _scsih_sas_device_remove - remove sas_device from list.
579 * @ioc: per adapter object
580 * @sas_device: the sas_device object
581 * Context: This function will acquire ioc->sas_device_lock.
583 * Removing object and freeing associated memory from the ioc->sas_device_list.
586 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
587 struct _sas_device
*sas_device
)
594 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
595 list_del(&sas_device
->list
);
597 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
602 * _scsih_sas_device_add - insert sas_device to the list.
603 * @ioc: per adapter object
604 * @sas_device: the sas_device object
605 * Context: This function will acquire ioc->sas_device_lock.
607 * Adding new object to the ioc->sas_device_list.
610 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
611 struct _sas_device
*sas_device
)
615 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
616 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
617 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
619 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
620 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
621 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
623 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
624 sas_device
->sas_address_parent
)) {
625 _scsih_sas_device_remove(ioc
, sas_device
);
626 } else if (!sas_device
->starget
) {
627 /* When asyn scanning is enabled, its not possible to remove
628 * devices while scanning is turned on due to an oops in
629 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
631 if (!ioc
->is_driver_loading
) {
632 mpt2sas_transport_port_remove(ioc
,
633 sas_device
->sas_address
,
634 sas_device
->sas_address_parent
);
635 _scsih_sas_device_remove(ioc
, sas_device
);
641 * _scsih_sas_device_init_add - insert sas_device to the list.
642 * @ioc: per adapter object
643 * @sas_device: the sas_device object
644 * Context: This function will acquire ioc->sas_device_lock.
646 * Adding new object at driver load time to the ioc->sas_device_init_list.
649 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
650 struct _sas_device
*sas_device
)
654 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
655 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
656 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
658 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
659 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
660 _scsih_determine_boot_device(ioc
, sas_device
, 0);
661 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
665 * _scsih_raid_device_find_by_id - raid device search
666 * @ioc: per adapter object
667 * @id: sas device target id
668 * @channel: sas device channel
669 * Context: Calling function should acquire ioc->raid_device_lock
671 * This searches for raid_device based on target id, then return raid_device
674 static struct _raid_device
*
675 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
677 struct _raid_device
*raid_device
, *r
;
680 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
681 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
692 * _scsih_raid_device_find_by_handle - raid device search
693 * @ioc: per adapter object
694 * @handle: sas device handle (assigned by firmware)
695 * Context: Calling function should acquire ioc->raid_device_lock
697 * This searches for raid_device based on handle, then return raid_device
700 static struct _raid_device
*
701 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
703 struct _raid_device
*raid_device
, *r
;
706 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
707 if (raid_device
->handle
!= handle
)
718 * _scsih_raid_device_find_by_wwid - raid device search
719 * @ioc: per adapter object
720 * @handle: sas device handle (assigned by firmware)
721 * Context: Calling function should acquire ioc->raid_device_lock
723 * This searches for raid_device based on wwid, then return raid_device
726 static struct _raid_device
*
727 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
729 struct _raid_device
*raid_device
, *r
;
732 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
733 if (raid_device
->wwid
!= wwid
)
744 * _scsih_raid_device_add - add raid_device object
745 * @ioc: per adapter object
746 * @raid_device: raid_device object
748 * This is added to the raid_device_list link list.
751 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
752 struct _raid_device
*raid_device
)
756 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
757 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
758 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
760 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
761 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
762 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
766 * _scsih_raid_device_remove - delete raid_device object
767 * @ioc: per adapter object
768 * @raid_device: raid_device object
772 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
773 struct _raid_device
*raid_device
)
777 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
778 list_del(&raid_device
->list
);
780 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
784 * mpt2sas_scsih_expander_find_by_handle - expander device search
785 * @ioc: per adapter object
786 * @handle: expander handle (assigned by firmware)
787 * Context: Calling function should acquire ioc->sas_device_lock
789 * This searches for expander device based on handle, then returns the
793 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
795 struct _sas_node
*sas_expander
, *r
;
798 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
799 if (sas_expander
->handle
!= handle
)
809 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
810 * @ioc: per adapter object
811 * @sas_address: sas address
812 * Context: Calling function should acquire ioc->sas_node_lock.
814 * This searches for expander device based on sas_address, then returns the
818 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
821 struct _sas_node
*sas_expander
, *r
;
824 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
825 if (sas_expander
->sas_address
!= sas_address
)
835 * _scsih_expander_node_add - insert expander device to the list.
836 * @ioc: per adapter object
837 * @sas_expander: the sas_device object
838 * Context: This function will acquire ioc->sas_node_lock.
840 * Adding new object to the ioc->sas_expander_list.
845 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
846 struct _sas_node
*sas_expander
)
850 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
851 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
852 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
856 * _scsih_is_end_device - determines if device is an end device
857 * @device_info: bitfield providing information about the device.
860 * Returns 1 if end device.
863 _scsih_is_end_device(u32 device_info
)
865 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
866 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
867 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
868 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
875 * _scsih_scsi_lookup_get - returns scmd entry
876 * @ioc: per adapter object
877 * @smid: system request message index
879 * Returns the smid stored scmd pointer.
881 static struct scsi_cmnd
*
882 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
884 return ioc
->scsi_lookup
[smid
- 1].scmd
;
888 * _scsih_scsi_lookup_get_clear - returns scmd entry
889 * @ioc: per adapter object
890 * @smid: system request message index
892 * Returns the smid stored scmd pointer.
893 * Then will derefrence the stored scmd pointer.
895 static inline struct scsi_cmnd
*
896 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
899 struct scsi_cmnd
*scmd
;
901 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
902 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
903 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
904 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
910 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
911 * @ioc: per adapter object
912 * @smid: system request message index
913 * @scmd: pointer to scsi command object
914 * Context: This function will acquire ioc->scsi_lookup_lock.
916 * This will search for a scmd pointer in the scsi_lookup array,
917 * returning the revelent smid. A returned value of zero means invalid.
920 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
927 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
929 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
930 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
931 smid
= ioc
->scsi_lookup
[i
].smid
;
936 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
941 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
942 * @ioc: per adapter object
945 * Context: This function will acquire ioc->scsi_lookup_lock.
947 * This will search for a matching channel:id in the scsi_lookup array,
948 * returning 1 if found.
951 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
958 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
960 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
961 if (ioc
->scsi_lookup
[i
].scmd
&&
962 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
963 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
969 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
974 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
975 * @ioc: per adapter object
979 * Context: This function will acquire ioc->scsi_lookup_lock.
981 * This will search for a matching channel:id:lun in the scsi_lookup array,
982 * returning 1 if found.
985 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
986 unsigned int lun
, int channel
)
992 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
994 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
995 if (ioc
->scsi_lookup
[i
].scmd
&&
996 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
997 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
998 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1004 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1009 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1010 * @ioc: per adapter object
1011 * @smid: smid associated to an IO request
1013 * Returns chain tracker(from ioc->free_chain_list)
1015 static struct chain_tracker
*
1016 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1018 struct chain_tracker
*chain_req
;
1019 unsigned long flags
;
1021 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1022 if (list_empty(&ioc
->free_chain_list
)) {
1023 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1024 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
"chain buffers not "
1025 "available\n", ioc
->name
));
1028 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1029 struct chain_tracker
, tracker_list
);
1030 list_del_init(&chain_req
->tracker_list
);
1031 list_add_tail(&chain_req
->tracker_list
,
1032 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1033 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1038 * _scsih_build_scatter_gather - main sg creation routine
1039 * @ioc: per adapter object
1040 * @scmd: scsi command
1041 * @smid: system request message index
1044 * The main routine that builds scatter gather table from a given
1045 * scsi request sent via the .queuecommand main handler.
1047 * Returns 0 success, anything else error
1050 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
1051 struct scsi_cmnd
*scmd
, u16 smid
)
1053 Mpi2SCSIIORequest_t
*mpi_request
;
1054 dma_addr_t chain_dma
;
1055 struct scatterlist
*sg_scmd
;
1056 void *sg_local
, *chain
;
1061 u32 sges_in_segment
;
1063 u32 sgl_flags_last_element
;
1064 u32 sgl_flags_end_buffer
;
1065 struct chain_tracker
*chain_req
;
1067 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1069 /* init scatter gather flags */
1070 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1071 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1072 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1073 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1074 << MPI2_SGE_FLAGS_SHIFT
;
1075 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1076 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1077 << MPI2_SGE_FLAGS_SHIFT
;
1078 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1080 sg_scmd
= scsi_sglist(scmd
);
1081 sges_left
= scsi_dma_map(scmd
);
1082 if (sges_left
< 0) {
1083 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1084 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1088 sg_local
= &mpi_request
->SGL
;
1089 sges_in_segment
= ioc
->max_sges_in_main_message
;
1090 if (sges_left
<= sges_in_segment
)
1091 goto fill_in_last_segment
;
1093 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1094 (sges_in_segment
* ioc
->sge_size
))/4;
1096 /* fill in main message segment when there is a chain following */
1097 while (sges_in_segment
) {
1098 if (sges_in_segment
== 1)
1099 ioc
->base_add_sg_single(sg_local
,
1100 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1101 sg_dma_address(sg_scmd
));
1103 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1104 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1105 sg_scmd
= sg_next(sg_scmd
);
1106 sg_local
+= ioc
->sge_size
;
1111 /* initializing the chain flags and pointers */
1112 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1113 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1116 chain
= chain_req
->chain_buffer
;
1117 chain_dma
= chain_req
->chain_buffer_dma
;
1119 sges_in_segment
= (sges_left
<=
1120 ioc
->max_sges_in_chain_message
) ? sges_left
:
1121 ioc
->max_sges_in_chain_message
;
1122 chain_offset
= (sges_left
== sges_in_segment
) ?
1123 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1124 chain_length
= sges_in_segment
* ioc
->sge_size
;
1126 chain_offset
= chain_offset
<<
1127 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1128 chain_length
+= ioc
->sge_size
;
1130 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1131 chain_length
, chain_dma
);
1134 goto fill_in_last_segment
;
1136 /* fill in chain segments */
1137 while (sges_in_segment
) {
1138 if (sges_in_segment
== 1)
1139 ioc
->base_add_sg_single(sg_local
,
1140 sgl_flags_last_element
|
1141 sg_dma_len(sg_scmd
),
1142 sg_dma_address(sg_scmd
));
1144 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1145 sg_dma_len(sg_scmd
),
1146 sg_dma_address(sg_scmd
));
1147 sg_scmd
= sg_next(sg_scmd
);
1148 sg_local
+= ioc
->sge_size
;
1153 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1156 chain
= chain_req
->chain_buffer
;
1157 chain_dma
= chain_req
->chain_buffer_dma
;
1161 fill_in_last_segment
:
1163 /* fill the last segment */
1166 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1167 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1169 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1170 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1171 sg_scmd
= sg_next(sg_scmd
);
1172 sg_local
+= ioc
->sge_size
;
1180 * _scsih_adjust_queue_depth - setting device queue depth
1181 * @sdev: scsi device struct
1182 * @qdepth: requested queue depth
1188 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1190 struct Scsi_Host
*shost
= sdev
->host
;
1192 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1193 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1194 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1195 struct _sas_device
*sas_device
;
1196 unsigned long flags
;
1198 max_depth
= shost
->can_queue
;
1200 /* limit max device queue for SATA to 32 */
1201 sas_device_priv_data
= sdev
->hostdata
;
1202 if (!sas_device_priv_data
)
1204 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1205 if (!sas_target_priv_data
)
1207 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1209 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1210 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1211 sas_device_priv_data
->sas_target
->sas_address
);
1212 if (sas_device
&& sas_device
->device_info
&
1213 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1214 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1215 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1219 if (!sdev
->tagged_supported
)
1221 if (qdepth
> max_depth
)
1223 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1227 * _scsih_change_queue_depth - setting device queue depth
1228 * @sdev: scsi device struct
1229 * @qdepth: requested queue depth
1230 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1231 * (see include/scsi/scsi_host.h for definition)
1233 * Returns queue depth.
1236 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1238 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1239 _scsih_adjust_queue_depth(sdev
, qdepth
);
1240 else if (reason
== SCSI_QDEPTH_QFULL
)
1241 scsi_track_queue_full(sdev
, qdepth
);
1245 if (sdev
->inquiry_len
> 7)
1246 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1247 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1248 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1249 sdev
->ordered_tags
, sdev
->scsi_level
,
1250 (sdev
->inquiry
[7] & 2) >> 1);
1252 return sdev
->queue_depth
;
1256 * _scsih_change_queue_type - changing device queue tag type
1257 * @sdev: scsi device struct
1258 * @tag_type: requested tag type
1260 * Returns queue tag type.
1263 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1265 if (sdev
->tagged_supported
) {
1266 scsi_set_tag_type(sdev
, tag_type
);
1268 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1270 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1278 * _scsih_target_alloc - target add routine
1279 * @starget: scsi target struct
1281 * Returns 0 if ok. Any other return is assumed to be an error and
1282 * the device is ignored.
1285 _scsih_target_alloc(struct scsi_target
*starget
)
1287 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1288 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1289 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1290 struct _sas_device
*sas_device
;
1291 struct _raid_device
*raid_device
;
1292 unsigned long flags
;
1293 struct sas_rphy
*rphy
;
1295 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1296 if (!sas_target_priv_data
)
1299 starget
->hostdata
= sas_target_priv_data
;
1300 sas_target_priv_data
->starget
= starget
;
1301 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1304 if (starget
->channel
== RAID_CHANNEL
) {
1305 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1306 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1309 sas_target_priv_data
->handle
= raid_device
->handle
;
1310 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1311 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1312 if (ioc
->is_warpdrive
)
1313 sas_target_priv_data
->raid_device
= raid_device
;
1314 raid_device
->starget
= starget
;
1316 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1320 /* sas/sata devices */
1321 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1322 rphy
= dev_to_rphy(starget
->dev
.parent
);
1323 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1324 rphy
->identify
.sas_address
);
1327 sas_target_priv_data
->handle
= sas_device
->handle
;
1328 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1329 sas_device
->starget
= starget
;
1330 sas_device
->id
= starget
->id
;
1331 sas_device
->channel
= starget
->channel
;
1332 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1333 sas_target_priv_data
->flags
|=
1334 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1336 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1342 * _scsih_target_destroy - target destroy routine
1343 * @starget: scsi target struct
1348 _scsih_target_destroy(struct scsi_target
*starget
)
1350 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1351 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1352 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1353 struct _sas_device
*sas_device
;
1354 struct _raid_device
*raid_device
;
1355 unsigned long flags
;
1356 struct sas_rphy
*rphy
;
1358 sas_target_priv_data
= starget
->hostdata
;
1359 if (!sas_target_priv_data
)
1362 if (starget
->channel
== RAID_CHANNEL
) {
1363 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1364 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1367 raid_device
->starget
= NULL
;
1368 raid_device
->sdev
= NULL
;
1370 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1374 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1375 rphy
= dev_to_rphy(starget
->dev
.parent
);
1376 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1377 rphy
->identify
.sas_address
);
1378 if (sas_device
&& (sas_device
->starget
== starget
) &&
1379 (sas_device
->id
== starget
->id
) &&
1380 (sas_device
->channel
== starget
->channel
))
1381 sas_device
->starget
= NULL
;
1383 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1386 kfree(sas_target_priv_data
);
1387 starget
->hostdata
= NULL
;
1391 * _scsih_slave_alloc - device add routine
1392 * @sdev: scsi device struct
1394 * Returns 0 if ok. Any other return is assumed to be an error and
1395 * the device is ignored.
1398 _scsih_slave_alloc(struct scsi_device
*sdev
)
1400 struct Scsi_Host
*shost
;
1401 struct MPT2SAS_ADAPTER
*ioc
;
1402 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1403 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1404 struct scsi_target
*starget
;
1405 struct _raid_device
*raid_device
;
1406 struct _sas_device
*sas_device
;
1407 unsigned long flags
;
1409 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1410 if (!sas_device_priv_data
)
1413 sas_device_priv_data
->lun
= sdev
->lun
;
1414 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1416 starget
= scsi_target(sdev
);
1417 sas_target_priv_data
= starget
->hostdata
;
1418 sas_target_priv_data
->num_luns
++;
1419 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1420 sdev
->hostdata
= sas_device_priv_data
;
1421 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1422 sdev
->no_uld_attach
= 1;
1424 shost
= dev_to_shost(&starget
->dev
);
1425 ioc
= shost_priv(shost
);
1426 if (starget
->channel
== RAID_CHANNEL
) {
1427 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1428 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1429 starget
->id
, starget
->channel
);
1431 raid_device
->sdev
= sdev
; /* raid is single lun */
1432 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1435 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1436 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1437 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1438 sas_target_priv_data
->sas_address
);
1439 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1440 sdev_printk(KERN_INFO
, sdev
,
1441 "%s : sas_device->starget set to starget @ %d\n",
1442 __func__
, __LINE__
);
1443 sas_device
->starget
= starget
;
1445 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1452 * _scsih_slave_destroy - device destroy routine
1453 * @sdev: scsi device struct
1458 _scsih_slave_destroy(struct scsi_device
*sdev
)
1460 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1461 struct scsi_target
*starget
;
1462 struct Scsi_Host
*shost
;
1463 struct MPT2SAS_ADAPTER
*ioc
;
1464 struct _sas_device
*sas_device
;
1465 unsigned long flags
;
1467 if (!sdev
->hostdata
)
1470 starget
= scsi_target(sdev
);
1471 sas_target_priv_data
= starget
->hostdata
;
1472 sas_target_priv_data
->num_luns
--;
1474 shost
= dev_to_shost(&starget
->dev
);
1475 ioc
= shost_priv(shost
);
1477 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1478 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1479 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1480 sas_target_priv_data
->sas_address
);
1481 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1482 sas_device
->starget
= NULL
;
1483 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1486 kfree(sdev
->hostdata
);
1487 sdev
->hostdata
= NULL
;
1491 * _scsih_display_sata_capabilities - sata capabilities
1492 * @ioc: per adapter object
1493 * @handle: device handle
1494 * @sdev: scsi device struct
1497 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1498 u16 handle
, struct scsi_device
*sdev
)
1500 Mpi2ConfigReply_t mpi_reply
;
1501 Mpi2SasDevicePage0_t sas_device_pg0
;
1506 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1507 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1508 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1509 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1513 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1514 MPI2_IOCSTATUS_MASK
;
1515 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1516 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1517 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1521 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1522 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1524 sdev_printk(KERN_INFO
, sdev
,
1525 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1526 "sw_preserve(%s)\n",
1527 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1528 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1529 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1531 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1532 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1533 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1537 * _scsih_is_raid - return boolean indicating device is raid volume
1538 * @dev the device struct object
1541 _scsih_is_raid(struct device
*dev
)
1543 struct scsi_device
*sdev
= to_scsi_device(dev
);
1544 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1546 if (ioc
->is_warpdrive
)
1548 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1552 * _scsih_get_resync - get raid volume resync percent complete
1553 * @dev the device struct object
1556 _scsih_get_resync(struct device
*dev
)
1558 struct scsi_device
*sdev
= to_scsi_device(dev
);
1559 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1560 static struct _raid_device
*raid_device
;
1561 unsigned long flags
;
1562 Mpi2RaidVolPage0_t vol_pg0
;
1563 Mpi2ConfigReply_t mpi_reply
;
1564 u32 volume_status_flags
;
1565 u8 percent_complete
;
1568 percent_complete
= 0;
1570 if (ioc
->is_warpdrive
)
1573 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1574 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1577 handle
= raid_device
->handle
;
1578 percent_complete
= raid_device
->percent_complete
;
1580 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1585 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1586 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1587 sizeof(Mpi2RaidVolPage0_t
))) {
1588 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1589 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1590 percent_complete
= 0;
1594 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1595 if (!(volume_status_flags
&
1596 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1597 percent_complete
= 0;
1600 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1604 * _scsih_get_state - get raid volume level
1605 * @dev the device struct object
1608 _scsih_get_state(struct device
*dev
)
1610 struct scsi_device
*sdev
= to_scsi_device(dev
);
1611 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1612 static struct _raid_device
*raid_device
;
1613 unsigned long flags
;
1614 Mpi2RaidVolPage0_t vol_pg0
;
1615 Mpi2ConfigReply_t mpi_reply
;
1617 enum raid_state state
= RAID_STATE_UNKNOWN
;
1620 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1621 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1624 handle
= raid_device
->handle
;
1625 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1630 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1631 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1632 sizeof(Mpi2RaidVolPage0_t
))) {
1633 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1634 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1638 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1639 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1640 state
= RAID_STATE_RESYNCING
;
1644 switch (vol_pg0
.VolumeState
) {
1645 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1646 case MPI2_RAID_VOL_STATE_ONLINE
:
1647 state
= RAID_STATE_ACTIVE
;
1649 case MPI2_RAID_VOL_STATE_DEGRADED
:
1650 state
= RAID_STATE_DEGRADED
;
1652 case MPI2_RAID_VOL_STATE_FAILED
:
1653 case MPI2_RAID_VOL_STATE_MISSING
:
1654 state
= RAID_STATE_OFFLINE
;
1658 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1662 * _scsih_set_level - set raid level
1663 * @sdev: scsi device struct
1664 * @volume_type: volume type
1667 _scsih_set_level(struct scsi_device
*sdev
, u8 volume_type
)
1669 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1671 switch (volume_type
) {
1672 case MPI2_RAID_VOL_TYPE_RAID0
:
1673 level
= RAID_LEVEL_0
;
1675 case MPI2_RAID_VOL_TYPE_RAID10
:
1676 level
= RAID_LEVEL_10
;
1678 case MPI2_RAID_VOL_TYPE_RAID1E
:
1679 level
= RAID_LEVEL_1E
;
1681 case MPI2_RAID_VOL_TYPE_RAID1
:
1682 level
= RAID_LEVEL_1
;
1686 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1690 * _scsih_get_volume_capabilities - volume capabilities
1691 * @ioc: per adapter object
1692 * @sas_device: the raid_device object
1694 * Returns 0 for success, else 1
1697 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1698 struct _raid_device
*raid_device
)
1700 Mpi2RaidVolPage0_t
*vol_pg0
;
1701 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1702 Mpi2SasDevicePage0_t sas_device_pg0
;
1703 Mpi2ConfigReply_t mpi_reply
;
1707 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1708 &num_pds
)) || !num_pds
) {
1709 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1710 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1715 raid_device
->num_pds
= num_pds
;
1716 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1717 sizeof(Mpi2RaidVol0PhysDisk_t
));
1718 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1720 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1721 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1726 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1727 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1728 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1729 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1735 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1737 /* figure out what the underlying devices are by
1738 * obtaining the device_info bits for the 1st device
1740 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1741 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1742 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1743 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1744 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1745 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1746 raid_device
->device_info
=
1747 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1755 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1756 * @ioc: per adapter object
1759 _scsih_disable_ddio(struct MPT2SAS_ADAPTER
*ioc
)
1761 Mpi2RaidVolPage1_t vol_pg1
;
1762 Mpi2ConfigReply_t mpi_reply
;
1763 struct _raid_device
*raid_device
;
1766 unsigned long flags
;
1769 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1770 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1771 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1772 MPI2_IOCSTATUS_MASK
;
1773 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1775 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1776 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1777 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1779 raid_device
->direct_io_enabled
= 0;
1780 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1787 * _scsih_get_num_volumes - Get number of volumes in the ioc
1788 * @ioc: per adapter object
1791 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER
*ioc
)
1793 Mpi2RaidVolPage1_t vol_pg1
;
1794 Mpi2ConfigReply_t mpi_reply
;
1800 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1801 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1802 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1803 MPI2_IOCSTATUS_MASK
;
1804 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1807 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1814 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1815 * @ioc: per adapter object
1816 * @raid_device: the raid_device object
1819 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER
*ioc
,
1820 struct _raid_device
*raid_device
)
1822 Mpi2RaidVolPage0_t
*vol_pg0
;
1823 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1824 Mpi2ConfigReply_t mpi_reply
;
1827 unsigned long stripe_sz
, block_sz
;
1828 u8 stripe_exp
, block_exp
;
1831 if (!ioc
->is_warpdrive
)
1834 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
) {
1835 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1836 "globally as drives are exposed\n", ioc
->name
);
1839 if (_scsih_get_num_volumes(ioc
) > 1) {
1840 _scsih_disable_ddio(ioc
);
1841 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1842 "globally as number of drives > 1\n", ioc
->name
);
1845 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1846 &num_pds
)) || !num_pds
) {
1847 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1848 "Failure in computing number of drives\n", ioc
->name
);
1852 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1853 sizeof(Mpi2RaidVol0PhysDisk_t
));
1854 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1856 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1857 "Memory allocation failure for RVPG0\n", ioc
->name
);
1861 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1862 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1863 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1864 "Failure in retrieving RVPG0\n", ioc
->name
);
1870 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1871 * assumed for WARPDRIVE, disable direct I/O
1873 if (num_pds
> MPT_MAX_WARPDRIVE_PDS
) {
1874 printk(MPT2SAS_WARN_FMT
"WarpDrive : Direct IO is disabled "
1875 "for the drive with handle(0x%04x): num_mem=%d, "
1876 "max_mem_allowed=%d\n", ioc
->name
, raid_device
->handle
,
1877 num_pds
, MPT_MAX_WARPDRIVE_PDS
);
1881 for (count
= 0; count
< num_pds
; count
++) {
1882 if (mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1883 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1884 vol_pg0
->PhysDisk
[count
].PhysDiskNum
) ||
1885 le16_to_cpu(pd_pg0
.DevHandle
) ==
1886 MPT2SAS_INVALID_DEVICE_HANDLE
) {
1887 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1888 "disabled for the drive with handle(0x%04x) member"
1889 "handle retrieval failed for member number=%d\n",
1890 ioc
->name
, raid_device
->handle
,
1891 vol_pg0
->PhysDisk
[count
].PhysDiskNum
);
1894 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1895 dev_max_lba
= le64_to_cpu(pd_pg0
.DeviceMaxLBA
);
1896 if (dev_max_lba
>> 32) {
1897 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1898 "disabled for the drive with handle(0x%04x) member"
1899 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1900 ioc
->name
, raid_device
->handle
,
1901 le16_to_cpu(pd_pg0
.DevHandle
),
1902 (unsigned long long)dev_max_lba
);
1906 raid_device
->pd_handle
[count
] = le16_to_cpu(pd_pg0
.DevHandle
);
1910 * Assumption for WD: Direct I/O is not supported if the volume is
1913 if (raid_device
->volume_type
!= MPI2_RAID_VOL_TYPE_RAID0
) {
1914 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1915 "for the drive with handle(0x%04x): type=%d, "
1916 "s_sz=%uK, blk_size=%u\n", ioc
->name
,
1917 raid_device
->handle
, raid_device
->volume_type
,
1918 (le32_to_cpu(vol_pg0
->StripeSize
) *
1919 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024,
1920 le16_to_cpu(vol_pg0
->BlockSize
));
1924 stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1925 stripe_exp
= find_first_bit(&stripe_sz
, 32);
1926 if (stripe_exp
== 32) {
1927 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1928 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1929 ioc
->name
, raid_device
->handle
,
1930 (le32_to_cpu(vol_pg0
->StripeSize
) *
1931 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024);
1934 raid_device
->stripe_exponent
= stripe_exp
;
1935 block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1936 block_exp
= find_first_bit(&block_sz
, 16);
1937 if (block_exp
== 16) {
1938 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1939 "for the drive with handle(0x%04x) invalid block sz %u\n",
1940 ioc
->name
, raid_device
->handle
,
1941 le16_to_cpu(vol_pg0
->BlockSize
));
1944 raid_device
->block_exponent
= block_exp
;
1945 raid_device
->direct_io_enabled
= 1;
1947 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is Enabled for the drive"
1948 " with handle(0x%04x)\n", ioc
->name
, raid_device
->handle
);
1950 * WARPDRIVE: Though the following fields are not used for direct IO,
1951 * stored for future purpose:
1953 raid_device
->max_lba
= le64_to_cpu(vol_pg0
->MaxLBA
);
1954 raid_device
->stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1955 raid_device
->block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1962 raid_device
->direct_io_enabled
= 0;
1963 for (count
= 0; count
< num_pds
; count
++)
1964 raid_device
->pd_handle
[count
] = 0;
1970 * _scsih_enable_tlr - setting TLR flags
1971 * @ioc: per adapter object
1972 * @sdev: scsi device struct
1974 * Enabling Transaction Layer Retries for tape devices when
1975 * vpd page 0x90 is present
1979 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1982 if (sdev
->type
!= TYPE_TAPE
)
1985 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1988 sas_enable_tlr(sdev
);
1989 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1990 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1996 * _scsih_slave_configure - device configure routine.
1997 * @sdev: scsi device struct
1999 * Returns 0 if ok. Any other return is assumed to be an error and
2000 * the device is ignored.
2003 _scsih_slave_configure(struct scsi_device
*sdev
)
2005 struct Scsi_Host
*shost
= sdev
->host
;
2006 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2007 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2008 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2009 struct _sas_device
*sas_device
;
2010 struct _raid_device
*raid_device
;
2011 unsigned long flags
;
2016 u16 handle
, volume_handle
= 0;
2017 u64 volume_wwid
= 0;
2020 sas_device_priv_data
= sdev
->hostdata
;
2021 sas_device_priv_data
->configured_lun
= 1;
2022 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2023 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2024 handle
= sas_target_priv_data
->handle
;
2026 /* raid volume handling */
2027 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2029 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2030 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
2031 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2033 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2034 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2035 __LINE__
, __func__
));
2039 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2040 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2041 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2042 __LINE__
, __func__
));
2046 * WARPDRIVE: Initialize the required data for Direct IO
2048 _scsih_init_warpdrive_properties(ioc
, raid_device
);
2050 /* RAID Queue Depth Support
2051 * IS volume = underlying qdepth of drive type, either
2052 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2053 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2055 if (raid_device
->device_info
&
2056 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2057 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2060 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2061 if (raid_device
->device_info
&
2062 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2068 switch (raid_device
->volume_type
) {
2069 case MPI2_RAID_VOL_TYPE_RAID0
:
2072 case MPI2_RAID_VOL_TYPE_RAID1E
:
2073 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2074 if (ioc
->manu_pg10
.OEMIdentifier
&&
2075 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2076 MFG10_GF0_R10_DISPLAY
) &&
2077 !(raid_device
->num_pds
% 2))
2082 case MPI2_RAID_VOL_TYPE_RAID1
:
2083 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2086 case MPI2_RAID_VOL_TYPE_RAID10
:
2087 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2090 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2092 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2097 if (!ioc
->hide_ir_msg
)
2098 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2099 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2100 r_level
, raid_device
->handle
,
2101 (unsigned long long)raid_device
->wwid
,
2102 raid_device
->num_pds
, ds
);
2103 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2104 /* raid transport support */
2105 if (!ioc
->is_warpdrive
)
2106 _scsih_set_level(sdev
, raid_device
->volume_type
);
2110 /* non-raid handling */
2111 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2112 if (mpt2sas_config_get_volume_handle(ioc
, handle
,
2114 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2115 "failure at %s:%d/%s()!\n", ioc
->name
,
2116 __FILE__
, __LINE__
, __func__
));
2119 if (volume_handle
&& mpt2sas_config_get_volume_wwid(ioc
,
2120 volume_handle
, &volume_wwid
)) {
2121 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2122 "failure at %s:%d/%s()!\n", ioc
->name
,
2123 __FILE__
, __LINE__
, __func__
));
2128 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2129 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2130 sas_device_priv_data
->sas_target
->sas_address
);
2132 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2133 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2134 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2135 __LINE__
, __func__
));
2138 sas_device
->volume_handle
= volume_handle
;
2139 sas_device
->volume_wwid
= volume_wwid
;
2140 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2141 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2145 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2146 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2148 else if (sas_device
->device_info
&
2149 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2152 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2153 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2154 ds
, sas_device
->handle
,
2155 (unsigned long long)sas_device
->sas_address
,
2157 (unsigned long long)sas_device
->device_name
);
2158 sdev_printk(KERN_INFO
, sdev
, "%s: "
2159 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
2160 (unsigned long long) sas_device
->enclosure_logical_id
,
2163 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2165 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2168 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2171 sas_read_port_mode_page(sdev
);
2172 _scsih_enable_tlr(ioc
, sdev
);
2178 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2179 * @sdev: scsi device struct
2180 * @bdev: pointer to block device context
2181 * @capacity: device size (in 512 byte sectors)
2182 * @params: three element array to place output:
2183 * params[0] number of heads (max 255)
2184 * params[1] number of sectors (max 63)
2185 * params[2] number of cylinders
2190 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2191 sector_t capacity
, int params
[])
2201 dummy
= heads
* sectors
;
2202 cylinders
= capacity
;
2203 sector_div(cylinders
, dummy
);
2206 * Handle extended translation size for logical drives
2209 if ((ulong
)capacity
>= 0x200000) {
2212 dummy
= heads
* sectors
;
2213 cylinders
= capacity
;
2214 sector_div(cylinders
, dummy
);
2219 params
[1] = sectors
;
2220 params
[2] = cylinders
;
2226 * _scsih_response_code - translation of device response code
2227 * @ioc: per adapter object
2228 * @response_code: response code returned by the device
2233 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
2237 switch (response_code
) {
2238 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2239 desc
= "task management request completed";
2241 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2242 desc
= "invalid frame";
2244 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2245 desc
= "task management request not supported";
2247 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2248 desc
= "task management request failed";
2250 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2251 desc
= "task management request succeeded";
2253 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2254 desc
= "invalid lun";
2257 desc
= "overlapped tag attempted";
2259 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2260 desc
= "task queued, however not sent to target";
2266 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
2267 ioc
->name
, response_code
, desc
);
2271 * _scsih_tm_done - tm completion routine
2272 * @ioc: per adapter object
2273 * @smid: system request message index
2274 * @msix_index: MSIX table index supplied by the OS
2275 * @reply: reply message frame(lower 32bit addr)
2278 * The callback handler when using scsih_issue_tm.
2280 * Return 1 meaning mf should be freed from _base_interrupt
2281 * 0 means the mf is freed from this function.
2284 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2286 MPI2DefaultReply_t
*mpi_reply
;
2288 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
2290 if (ioc
->tm_cmds
.smid
!= smid
)
2292 mpt2sas_base_flush_reply_queues(ioc
);
2293 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
2294 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2296 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2297 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
2299 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
2300 complete(&ioc
->tm_cmds
.done
);
2305 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2306 * @ioc: per adapter object
2307 * @handle: device handle
2309 * During taskmangement request, we need to freeze the device queue.
2312 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2314 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2315 struct scsi_device
*sdev
;
2318 shost_for_each_device(sdev
, ioc
->shost
) {
2321 sas_device_priv_data
= sdev
->hostdata
;
2322 if (!sas_device_priv_data
)
2324 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2325 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2327 ioc
->ignore_loginfos
= 1;
2333 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2334 * @ioc: per adapter object
2335 * @handle: device handle
2337 * During taskmangement request, we need to freeze the device queue.
2340 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2342 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2343 struct scsi_device
*sdev
;
2346 shost_for_each_device(sdev
, ioc
->shost
) {
2349 sas_device_priv_data
= sdev
->hostdata
;
2350 if (!sas_device_priv_data
)
2352 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2353 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2355 ioc
->ignore_loginfos
= 0;
2362 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2363 * @ioc: per adapter struct
2364 * @device_handle: device handle
2365 * @channel: the channel assigned by the OS
2366 * @id: the id assigned by the OS
2368 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2369 * @smid_task: smid assigned to the task
2370 * @timeout: timeout in seconds
2371 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2374 * A generic API for sending task management requests to firmware.
2376 * The callback index is set inside `ioc->tm_cb_idx`.
2378 * Return SUCCESS or FAILED.
2381 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2382 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2383 enum mutex_type m_type
)
2385 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2386 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2389 unsigned long timeleft
;
2390 struct scsiio_tracker
*scsi_lookup
= NULL
;
2393 if (m_type
== TM_MUTEX_ON
)
2394 mutex_lock(&ioc
->tm_cmds
.mutex
);
2395 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2396 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2397 __func__
, ioc
->name
);
2402 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2403 ioc
->pci_error_recovery
) {
2404 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2405 __func__
, ioc
->name
);
2410 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2411 if (ioc_state
& MPI2_DOORBELL_USED
) {
2412 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2413 "active!\n", ioc
->name
));
2414 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2416 rc
= (!rc
) ? SUCCESS
: FAILED
;
2420 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2421 mpt2sas_base_fault_info(ioc
, ioc_state
&
2422 MPI2_DOORBELL_DATA_MASK
);
2423 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2425 rc
= (!rc
) ? SUCCESS
: FAILED
;
2429 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2431 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2432 ioc
->name
, __func__
);
2437 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2438 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2440 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2441 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2443 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2444 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2445 ioc
->tm_cmds
.smid
= smid
;
2446 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2447 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2448 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2449 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2450 mpi_request
->TaskType
= type
;
2451 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2452 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2453 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2454 init_completion(&ioc
->tm_cmds
.done
);
2455 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2456 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2457 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2458 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2459 ioc
->name
, __func__
);
2460 _debug_dump_mf(mpi_request
,
2461 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2462 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2463 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2465 rc
= (!rc
) ? SUCCESS
: FAILED
;
2466 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2467 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2472 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2473 mpi_reply
= ioc
->tm_cmds
.reply
;
2474 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2475 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2476 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2477 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2478 le32_to_cpu(mpi_reply
->TerminationCount
)));
2479 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2480 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2481 if (mpi_reply
->IOCStatus
)
2482 _debug_dump_mf(mpi_request
,
2483 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2488 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2490 if (scsi_lookup
->scmd
== NULL
)
2495 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2496 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2502 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2503 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2504 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2509 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2517 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2518 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2519 if (m_type
== TM_MUTEX_ON
)
2520 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2525 if (m_type
== TM_MUTEX_ON
)
2526 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2531 * _scsih_tm_display_info - displays info about the device
2532 * @ioc: per adapter struct
2533 * @scmd: pointer to scsi command object
2535 * Called by task management callback handlers.
2538 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2540 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2541 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2542 struct _sas_device
*sas_device
= NULL
;
2543 unsigned long flags
;
2544 char *device_str
= NULL
;
2548 if (ioc
->hide_ir_msg
)
2549 device_str
= "WarpDrive";
2551 device_str
= "volume";
2553 scsi_print_command(scmd
);
2554 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2555 starget_printk(KERN_INFO
, starget
, "%s handle(0x%04x), "
2556 "%s wwid(0x%016llx)\n", device_str
, priv_target
->handle
,
2557 device_str
, (unsigned long long)priv_target
->sas_address
);
2559 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2560 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2561 priv_target
->sas_address
);
2563 if (priv_target
->flags
&
2564 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2565 starget_printk(KERN_INFO
, starget
,
2566 "volume handle(0x%04x), "
2567 "volume wwid(0x%016llx)\n",
2568 sas_device
->volume_handle
,
2569 (unsigned long long)sas_device
->volume_wwid
);
2571 starget_printk(KERN_INFO
, starget
,
2572 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2574 (unsigned long long)sas_device
->sas_address
,
2576 starget_printk(KERN_INFO
, starget
,
2577 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2578 (unsigned long long)sas_device
->enclosure_logical_id
,
2581 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2586 * _scsih_abort - eh threads main abort routine
2587 * @scmd: pointer to scsi command object
2589 * Returns SUCCESS if command aborted else FAILED
2592 _scsih_abort(struct scsi_cmnd
*scmd
)
2594 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2595 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2600 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2601 "scmd(%p)\n", scmd
);
2602 _scsih_tm_display_info(ioc
, scmd
);
2604 sas_device_priv_data
= scmd
->device
->hostdata
;
2605 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2606 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2607 "scmd(%p)\n", scmd
);
2608 scmd
->result
= DID_NO_CONNECT
<< 16;
2609 scmd
->scsi_done(scmd
);
2614 /* search for the command */
2615 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2617 scmd
->result
= DID_RESET
<< 16;
2622 /* for hidden raid components and volumes this is not supported */
2623 if (sas_device_priv_data
->sas_target
->flags
&
2624 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2625 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2626 scmd
->result
= DID_RESET
<< 16;
2631 mpt2sas_halt_firmware(ioc
);
2633 handle
= sas_device_priv_data
->sas_target
->handle
;
2634 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2635 scmd
->device
->id
, scmd
->device
->lun
,
2636 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2639 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2640 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2645 * _scsih_dev_reset - eh threads main device reset routine
2646 * @scmd: pointer to scsi command object
2648 * Returns SUCCESS if command aborted else FAILED
2651 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2653 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2654 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2655 struct _sas_device
*sas_device
;
2656 unsigned long flags
;
2660 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2662 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2663 "scmd(%p)\n", scmd
);
2664 _scsih_tm_display_info(ioc
, scmd
);
2666 sas_device_priv_data
= scmd
->device
->hostdata
;
2667 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2668 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2669 "scmd(%p)\n", scmd
);
2670 scmd
->result
= DID_NO_CONNECT
<< 16;
2671 scmd
->scsi_done(scmd
);
2676 /* for hidden raid components obtain the volume_handle */
2678 if (sas_device_priv_data
->sas_target
->flags
&
2679 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2680 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2681 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2682 sas_device_priv_data
->sas_target
->handle
);
2684 handle
= sas_device
->volume_handle
;
2685 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2687 handle
= sas_device_priv_data
->sas_target
->handle
;
2690 scmd
->result
= DID_RESET
<< 16;
2695 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2696 scmd
->device
->id
, scmd
->device
->lun
,
2697 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2700 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2701 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2706 * _scsih_target_reset - eh threads main target reset routine
2707 * @scmd: pointer to scsi command object
2709 * Returns SUCCESS if command aborted else FAILED
2712 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2714 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2715 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2716 struct _sas_device
*sas_device
;
2717 unsigned long flags
;
2720 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2722 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2723 "scmd(%p)\n", scmd
);
2724 _scsih_tm_display_info(ioc
, scmd
);
2726 sas_device_priv_data
= scmd
->device
->hostdata
;
2727 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2728 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2729 "scmd(%p)\n", scmd
);
2730 scmd
->result
= DID_NO_CONNECT
<< 16;
2731 scmd
->scsi_done(scmd
);
2736 /* for hidden raid components obtain the volume_handle */
2738 if (sas_device_priv_data
->sas_target
->flags
&
2739 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2740 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2741 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2742 sas_device_priv_data
->sas_target
->handle
);
2744 handle
= sas_device
->volume_handle
;
2745 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2747 handle
= sas_device_priv_data
->sas_target
->handle
;
2750 scmd
->result
= DID_RESET
<< 16;
2755 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2756 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2760 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2761 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2766 * _scsih_host_reset - eh threads main host reset routine
2767 * @scmd: pointer to scsi command object
2769 * Returns SUCCESS if command aborted else FAILED
2772 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2774 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2777 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2779 scsi_print_command(scmd
);
2781 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2783 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2784 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2785 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2791 * _scsih_fw_event_add - insert and queue up fw_event
2792 * @ioc: per adapter object
2793 * @fw_event: object describing the event
2794 * Context: This function will acquire ioc->fw_event_lock.
2796 * This adds the firmware event object into link list, then queues it up to
2797 * be processed from user context.
2802 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2804 unsigned long flags
;
2806 if (ioc
->firmware_event_thread
== NULL
)
2809 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2810 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2811 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2812 queue_delayed_work(ioc
->firmware_event_thread
,
2813 &fw_event
->delayed_work
, 0);
2814 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2818 * _scsih_fw_event_free - delete fw_event
2819 * @ioc: per adapter object
2820 * @fw_event: object describing the event
2821 * Context: This function will acquire ioc->fw_event_lock.
2823 * This removes firmware event object from link list, frees associated memory.
2828 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2831 unsigned long flags
;
2833 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2834 list_del(&fw_event
->list
);
2835 kfree(fw_event
->event_data
);
2837 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2842 * _scsih_error_recovery_delete_devices - remove devices not responding
2843 * @ioc: per adapter object
2848 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER
*ioc
)
2850 struct fw_event_work
*fw_event
;
2852 if (ioc
->is_driver_loading
)
2855 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2859 fw_event
->event
= MPT2SAS_REMOVE_UNRESPONDING_DEVICES
;
2860 fw_event
->ioc
= ioc
;
2861 _scsih_fw_event_add(ioc
, fw_event
);
2865 * mpt2sas_port_enable_complete - port enable completed (fake event)
2866 * @ioc: per adapter object
2871 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER
*ioc
)
2873 struct fw_event_work
*fw_event
;
2875 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2878 fw_event
->event
= MPT2SAS_PORT_ENABLE_COMPLETE
;
2879 fw_event
->ioc
= ioc
;
2880 _scsih_fw_event_add(ioc
, fw_event
);
2884 * _scsih_fw_event_cleanup_queue - cleanup event queue
2885 * @ioc: per adapter object
2887 * Walk the firmware event queue, either killing timers, or waiting
2888 * for outstanding events to complete
2893 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2895 struct fw_event_work
*fw_event
, *next
;
2897 if (list_empty(&ioc
->fw_event_list
) ||
2898 !ioc
->firmware_event_thread
|| in_interrupt())
2901 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2902 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2903 _scsih_fw_event_free(ioc
, fw_event
);
2906 fw_event
->cancel_pending_work
= 1;
2911 * _scsih_ublock_io_all_device - unblock every device
2912 * @ioc: per adapter object
2914 * change the device state from block to running
2917 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2919 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2920 struct scsi_device
*sdev
;
2922 shost_for_each_device(sdev
, ioc
->shost
) {
2923 sas_device_priv_data
= sdev
->hostdata
;
2924 if (!sas_device_priv_data
)
2926 if (!sas_device_priv_data
->block
)
2928 sas_device_priv_data
->block
= 0;
2929 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_running, "
2931 sas_device_priv_data
->sas_target
->handle
));
2932 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2936 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2937 * @ioc: per adapter object
2938 * @handle: device handle
2940 * During device pull we need to appropiately set the sdev state.
2943 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
2945 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2946 struct scsi_device
*sdev
;
2948 shost_for_each_device(sdev
, ioc
->shost
) {
2949 sas_device_priv_data
= sdev
->hostdata
;
2950 if (!sas_device_priv_data
)
2952 if (!sas_device_priv_data
->block
)
2954 if (sas_device_priv_data
->sas_target
->sas_address
==
2956 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2957 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2958 "sas address(0x%016llx)\n", ioc
->name
,
2959 (unsigned long long)sas_address
));
2960 sas_device_priv_data
->block
= 0;
2961 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2967 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2968 * @ioc: per adapter object
2969 * @handle: device handle
2971 * During device pull we need to appropiately set the sdev state.
2974 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2976 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2977 struct scsi_device
*sdev
;
2979 shost_for_each_device(sdev
, ioc
->shost
) {
2980 sas_device_priv_data
= sdev
->hostdata
;
2981 if (!sas_device_priv_data
)
2983 if (sas_device_priv_data
->block
)
2985 sas_device_priv_data
->block
= 1;
2986 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_blocked, "
2988 sas_device_priv_data
->sas_target
->handle
));
2989 scsi_internal_device_block(sdev
);
2995 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2996 * @ioc: per adapter object
2997 * @handle: device handle
2999 * During device pull we need to appropiately set the sdev state.
3002 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3004 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3005 struct scsi_device
*sdev
;
3007 shost_for_each_device(sdev
, ioc
->shost
) {
3008 sas_device_priv_data
= sdev
->hostdata
;
3009 if (!sas_device_priv_data
)
3011 if (sas_device_priv_data
->block
)
3013 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
3014 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3015 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
3016 "handle(0x%04x)\n", ioc
->name
, handle
));
3017 sas_device_priv_data
->block
= 1;
3018 scsi_internal_device_block(sdev
);
3024 * _scsih_block_io_to_children_attached_to_ex
3025 * @ioc: per adapter object
3026 * @sas_expander: the sas_device object
3028 * This routine set sdev state to SDEV_BLOCK for all devices
3029 * attached to this expander. This function called when expander is
3033 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
3034 struct _sas_node
*sas_expander
)
3036 struct _sas_port
*mpt2sas_port
;
3037 struct _sas_device
*sas_device
;
3038 struct _sas_node
*expander_sibling
;
3039 unsigned long flags
;
3044 list_for_each_entry(mpt2sas_port
,
3045 &sas_expander
->sas_port_list
, port_list
) {
3046 if (mpt2sas_port
->remote_identify
.device_type
==
3048 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3050 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3051 mpt2sas_port
->remote_identify
.sas_address
);
3053 set_bit(sas_device
->handle
,
3054 ioc
->blocking_handles
);
3055 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3059 list_for_each_entry(mpt2sas_port
,
3060 &sas_expander
->sas_port_list
, port_list
) {
3062 if (mpt2sas_port
->remote_identify
.device_type
==
3063 SAS_EDGE_EXPANDER_DEVICE
||
3064 mpt2sas_port
->remote_identify
.device_type
==
3065 SAS_FANOUT_EXPANDER_DEVICE
) {
3067 mpt2sas_scsih_expander_find_by_sas_address(
3068 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
3069 _scsih_block_io_to_children_attached_to_ex(ioc
,
3076 * _scsih_block_io_to_children_attached_directly
3077 * @ioc: per adapter object
3078 * @event_data: topology change event data
3080 * This routine set sdev state to SDEV_BLOCK for all devices
3081 * direct attached during device pull.
3084 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
3085 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3092 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3093 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3096 phy_number
= event_data
->StartPhyNum
+ i
;
3097 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3098 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3099 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3100 _scsih_block_io_device(ioc
, handle
);
3105 * _scsih_tm_tr_send - send task management request
3106 * @ioc: per adapter object
3107 * @handle: device handle
3108 * Context: interrupt time.
3110 * This code is to initiate the device removal handshake protocol
3111 * with controller firmware. This function will issue target reset
3112 * using high priority request queue. It will send a sas iounit
3113 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3115 * This is designed to send muliple task management request at the same
3116 * time to the fifo. If the fifo is full, we will append the request,
3117 * and process it in a future completion.
3120 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3122 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3124 struct _sas_device
*sas_device
;
3125 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
3126 u64 sas_address
= 0;
3127 unsigned long flags
;
3128 struct _tr_list
*delayed_tr
;
3131 if (ioc
->remove_host
) {
3132 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3133 "removed: handle(0x%04x)\n", __func__
, ioc
->name
, handle
));
3135 } else if (ioc
->pci_error_recovery
) {
3136 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3137 "error recovery: handle(0x%04x)\n", __func__
, ioc
->name
,
3141 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3142 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3143 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3144 "operational: handle(0x%04x)\n", __func__
, ioc
->name
,
3149 /* if PD, then return */
3150 if (test_bit(handle
, ioc
->pd_handles
))
3153 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3154 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3155 if (sas_device
&& sas_device
->starget
&&
3156 sas_device
->starget
->hostdata
) {
3157 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3158 sas_target_priv_data
->deleted
= 1;
3159 sas_address
= sas_device
->sas_address
;
3161 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3163 if (sas_target_priv_data
) {
3164 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"setting delete flag: "
3165 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, handle
,
3166 (unsigned long long)sas_address
));
3167 _scsih_ublock_io_device(ioc
, sas_address
);
3168 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
3171 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3173 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3176 INIT_LIST_HEAD(&delayed_tr
->list
);
3177 delayed_tr
->handle
= handle
;
3178 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3179 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3180 "DELAYED:tr:handle(0x%04x), (open)\n",
3181 ioc
->name
, handle
));
3185 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3186 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3187 ioc
->tm_tr_cb_idx
));
3188 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3189 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3190 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3191 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3192 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3193 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3199 * _scsih_sas_control_complete - completion routine
3200 * @ioc: per adapter object
3201 * @smid: system request message index
3202 * @msix_index: MSIX table index supplied by the OS
3203 * @reply: reply message frame(lower 32bit addr)
3204 * Context: interrupt time.
3206 * This is the sas iounit control completion routine.
3207 * This code is part of the code to initiate the device removal
3208 * handshake protocol with controller firmware.
3210 * Return 1 meaning mf should be freed from _base_interrupt
3211 * 0 means the mf is freed from this function.
3214 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3215 u8 msix_index
, u32 reply
)
3217 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3218 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3219 if (likely(mpi_reply
)) {
3220 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3221 "sc_complete:handle(0x%04x), (open) "
3222 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3223 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3224 le16_to_cpu(mpi_reply
->IOCStatus
),
3225 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3227 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3228 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3234 * _scsih_tm_tr_volume_send - send target reset request for volumes
3235 * @ioc: per adapter object
3236 * @handle: device handle
3237 * Context: interrupt time.
3239 * This is designed to send muliple task management request at the same
3240 * time to the fifo. If the fifo is full, we will append the request,
3241 * and process it in a future completion.
3244 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3246 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3248 struct _tr_list
*delayed_tr
;
3250 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3251 ioc
->pci_error_recovery
) {
3252 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3253 "progress!\n", __func__
, ioc
->name
));
3257 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3259 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3262 INIT_LIST_HEAD(&delayed_tr
->list
);
3263 delayed_tr
->handle
= handle
;
3264 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3265 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3266 "DELAYED:tr:handle(0x%04x), (open)\n",
3267 ioc
->name
, handle
));
3271 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3272 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3273 ioc
->tm_tr_volume_cb_idx
));
3274 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3275 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3276 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3277 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3278 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3279 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3283 * _scsih_tm_volume_tr_complete - target reset completion
3284 * @ioc: per adapter object
3285 * @smid: system request message index
3286 * @msix_index: MSIX table index supplied by the OS
3287 * @reply: reply message frame(lower 32bit addr)
3288 * Context: interrupt time.
3290 * Return 1 meaning mf should be freed from _base_interrupt
3291 * 0 means the mf is freed from this function.
3294 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3295 u8 msix_index
, u32 reply
)
3298 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3299 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3300 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3302 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3303 ioc
->pci_error_recovery
) {
3304 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3305 "progress!\n", __func__
, ioc
->name
));
3308 if (unlikely(!mpi_reply
)) {
3309 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3310 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3313 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3314 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3315 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3316 dewtprintk(ioc
, printk("spurious interrupt: "
3317 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
3318 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3322 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3323 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3324 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3325 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3326 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3327 le32_to_cpu(mpi_reply
->TerminationCount
)));
3329 return _scsih_check_for_pending_tm(ioc
, smid
);
3333 * _scsih_tm_tr_complete -
3334 * @ioc: per adapter object
3335 * @smid: system request message index
3336 * @msix_index: MSIX table index supplied by the OS
3337 * @reply: reply message frame(lower 32bit addr)
3338 * Context: interrupt time.
3340 * This is the target reset completion routine.
3341 * This code is part of the code to initiate the device removal
3342 * handshake protocol with controller firmware.
3343 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3345 * Return 1 meaning mf should be freed from _base_interrupt
3346 * 0 means the mf is freed from this function.
3349 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3353 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3354 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3355 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3356 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3360 if (ioc
->remove_host
) {
3361 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3362 "removed\n", __func__
, ioc
->name
));
3364 } else if (ioc
->pci_error_recovery
) {
3365 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3366 "error recovery\n", __func__
, ioc
->name
));
3369 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3370 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3371 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3372 "operational\n", __func__
, ioc
->name
));
3375 if (unlikely(!mpi_reply
)) {
3376 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3377 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3380 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3381 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3382 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3383 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
3384 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
3385 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3389 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3390 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3391 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3392 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3393 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3394 le32_to_cpu(mpi_reply
->TerminationCount
)));
3396 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3397 if (!smid_sas_ctrl
) {
3398 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3399 ioc
->name
, __func__
);
3403 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
3404 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
3405 ioc
->tm_sas_control_cb_idx
));
3406 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3407 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3408 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3409 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3410 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3411 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3413 return _scsih_check_for_pending_tm(ioc
, smid
);
3417 * _scsih_check_for_pending_tm - check for pending task management
3418 * @ioc: per adapter object
3419 * @smid: system request message index
3421 * This will check delayed target reset list, and feed the
3424 * Return 1 meaning mf should be freed from _base_interrupt
3425 * 0 means the mf is freed from this function.
3428 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3430 struct _tr_list
*delayed_tr
;
3432 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3433 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3434 struct _tr_list
, list
);
3435 mpt2sas_base_free_smid(ioc
, smid
);
3436 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3437 list_del(&delayed_tr
->list
);
3442 if (!list_empty(&ioc
->delayed_tr_list
)) {
3443 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3444 struct _tr_list
, list
);
3445 mpt2sas_base_free_smid(ioc
, smid
);
3446 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3447 list_del(&delayed_tr
->list
);
3456 * _scsih_check_topo_delete_events - sanity check on topo events
3457 * @ioc: per adapter object
3458 * @event_data: the event data payload
3460 * This routine added to better handle cable breaker.
3462 * This handles the case where driver receives multiple expander
3463 * add and delete events in a single shot. When there is a delete event
3464 * the routine will void any pending add events waiting in the event queue.
3469 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3470 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3472 struct fw_event_work
*fw_event
;
3473 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3474 u16 expander_handle
;
3475 struct _sas_node
*sas_expander
;
3476 unsigned long flags
;
3480 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3481 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3484 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3485 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3486 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3487 _scsih_tm_tr_send(ioc
, handle
);
3490 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3491 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3492 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3495 if (event_data
->ExpStatus
==
3496 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3497 /* put expander attached devices into blocking state */
3498 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3499 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3501 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3502 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3504 handle
= find_first_bit(ioc
->blocking_handles
,
3505 ioc
->facts
.MaxDevHandle
);
3506 if (handle
< ioc
->facts
.MaxDevHandle
)
3507 _scsih_block_io_device(ioc
, handle
);
3508 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3509 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3510 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3512 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3515 /* mark ignore flag for pending events */
3516 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3517 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3518 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3521 local_event_data
= fw_event
->event_data
;
3522 if (local_event_data
->ExpStatus
==
3523 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3524 local_event_data
->ExpStatus
==
3525 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3526 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3528 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3529 "setting ignoring flag\n", ioc
->name
));
3530 fw_event
->ignore
= 1;
3534 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3538 * _scsih_set_volume_delete_flag - setting volume delete flag
3539 * @ioc: per adapter object
3540 * @handle: device handle
3546 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3548 struct _raid_device
*raid_device
;
3549 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3550 unsigned long flags
;
3552 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3553 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3554 if (raid_device
&& raid_device
->starget
&&
3555 raid_device
->starget
->hostdata
) {
3556 sas_target_priv_data
=
3557 raid_device
->starget
->hostdata
;
3558 sas_target_priv_data
->deleted
= 1;
3559 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3560 "setting delete flag: handle(0x%04x), "
3561 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3562 (unsigned long long) raid_device
->wwid
));
3564 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3568 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3569 * @handle: input handle
3570 * @a: handle for volume a
3571 * @b: handle for volume b
3573 * IR firmware only supports two raid volumes. The purpose of this
3574 * routine is to set the volume handle in either a or b. When the given
3575 * input handle is non-zero, or when a and b have not been set before.
3578 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3580 if (!handle
|| handle
== *a
|| handle
== *b
)
3589 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3590 * @ioc: per adapter object
3591 * @event_data: the event data payload
3592 * Context: interrupt time.
3594 * This routine will send target reset to volume, followed by target
3595 * resets to the PDs. This is called when a PD has been removed, or
3596 * volume has been deleted or removed. When the target reset is sent
3597 * to volume, the PD target resets need to be queued to start upon
3598 * completion of the volume target reset.
3603 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3604 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3606 Mpi2EventIrConfigElement_t
*element
;
3608 u16 handle
, volume_handle
, a
, b
;
3609 struct _tr_list
*delayed_tr
;
3614 if (ioc
->is_warpdrive
)
3617 /* Volume Resets for Deleted or Removed */
3618 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3619 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3620 if (element
->ReasonCode
==
3621 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3622 element
->ReasonCode
==
3623 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3624 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3625 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3626 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3630 /* Volume Resets for UNHIDE events */
3631 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3632 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3633 if (le32_to_cpu(event_data
->Flags
) &
3634 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3636 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3637 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3638 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3643 _scsih_tm_tr_volume_send(ioc
, a
);
3645 _scsih_tm_tr_volume_send(ioc
, b
);
3647 /* PD target resets */
3648 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3649 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3650 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3652 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3653 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3654 clear_bit(handle
, ioc
->pd_handles
);
3656 _scsih_tm_tr_send(ioc
, handle
);
3657 else if (volume_handle
== a
|| volume_handle
== b
) {
3658 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3659 BUG_ON(!delayed_tr
);
3660 INIT_LIST_HEAD(&delayed_tr
->list
);
3661 delayed_tr
->handle
= handle
;
3662 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3663 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3664 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3667 _scsih_tm_tr_send(ioc
, handle
);
3673 * _scsih_check_volume_delete_events - set delete flag for volumes
3674 * @ioc: per adapter object
3675 * @event_data: the event data payload
3676 * Context: interrupt time.
3678 * This will handle the case when the cable connected to entire volume is
3679 * pulled. We will take care of setting the deleted flag so normal IO will
3685 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3686 Mpi2EventDataIrVolume_t
*event_data
)
3690 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3692 state
= le32_to_cpu(event_data
->NewValue
);
3693 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3694 MPI2_RAID_VOL_STATE_FAILED
)
3695 _scsih_set_volume_delete_flag(ioc
,
3696 le16_to_cpu(event_data
->VolDevHandle
));
3700 * _scsih_flush_running_cmds - completing outstanding commands.
3701 * @ioc: per adapter object
3703 * The flushing out of all pending scmd commands following host reset,
3704 * where all IO is dropped to the floor.
3709 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3711 struct scsi_cmnd
*scmd
;
3715 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3716 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3720 mpt2sas_base_free_smid(ioc
, smid
);
3721 scsi_dma_unmap(scmd
);
3722 if (ioc
->pci_error_recovery
)
3723 scmd
->result
= DID_NO_CONNECT
<< 16;
3725 scmd
->result
= DID_RESET
<< 16;
3726 scmd
->scsi_done(scmd
);
3728 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3733 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3734 * @scmd: pointer to scsi command object
3735 * @mpi_request: pointer to the SCSI_IO reqest message frame
3737 * Supporting protection 1 and 3.
3742 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3745 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3746 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3748 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3751 if (prot_op
== SCSI_PROT_READ_STRIP
)
3752 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3753 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3754 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3758 switch (prot_type
) {
3759 case SCSI_PROT_DIF_TYPE1
:
3760 case SCSI_PROT_DIF_TYPE2
:
3763 * enable ref/guard checking
3764 * auto increment ref tag
3766 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3767 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3768 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3769 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3770 cpu_to_be32(scsi_get_lba(scmd
));
3773 case SCSI_PROT_DIF_TYPE3
:
3776 * enable guard checking
3778 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3781 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3782 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3786 * _scsih_eedp_error_handling - return sense code for EEDP errors
3787 * @scmd: pointer to scsi command object
3788 * @ioc_status: ioc status
3793 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3797 switch (ioc_status
) {
3798 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3801 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3804 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3812 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10, ascq
);
3813 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
3814 SAM_STAT_CHECK_CONDITION
;
3818 * _scsih_scsi_direct_io_get - returns direct io flag
3819 * @ioc: per adapter object
3820 * @smid: system request message index
3822 * Returns the smid stored scmd pointer.
3825 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3827 return ioc
->scsi_lookup
[smid
- 1].direct_io
;
3831 * _scsih_scsi_direct_io_set - sets direct io flag
3832 * @ioc: per adapter object
3833 * @smid: system request message index
3834 * @direct_io: Zero or non-zero value to set in the direct_io flag
3839 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 direct_io
)
3841 ioc
->scsi_lookup
[smid
- 1].direct_io
= direct_io
;
3846 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3847 * @ioc: per adapter object
3848 * @scmd: pointer to scsi command object
3849 * @raid_device: pointer to raid device data structure
3850 * @mpi_request: pointer to the SCSI_IO reqest message frame
3851 * @smid: system request message index
3856 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3857 struct _raid_device
*raid_device
, Mpi2SCSIIORequest_t
*mpi_request
,
3860 u32 v_lba
, p_lba
, stripe_off
, stripe_unit
, column
, io_size
;
3861 u32 stripe_sz
, stripe_exp
;
3862 u8 num_pds
, *cdb_ptr
, i
;
3863 u8 cdb0
= scmd
->cmnd
[0];
3867 * Try Direct I/O to RAID memeber disks
3869 if (cdb0
== READ_16
|| cdb0
== READ_10
||
3870 cdb0
== WRITE_16
|| cdb0
== WRITE_10
) {
3871 cdb_ptr
= mpi_request
->CDB
.CDB32
;
3873 if ((cdb0
< READ_16
) || !(cdb_ptr
[2] | cdb_ptr
[3] | cdb_ptr
[4]
3875 io_size
= scsi_bufflen(scmd
) >>
3876 raid_device
->block_exponent
;
3877 i
= (cdb0
< READ_16
) ? 2 : 6;
3878 /* get virtual lba */
3879 v_lba
= be32_to_cpu(*(__be32
*)(&cdb_ptr
[i
]));
3881 if (((u64
)v_lba
+ (u64
)io_size
- 1) <=
3882 (u32
)raid_device
->max_lba
) {
3883 stripe_sz
= raid_device
->stripe_sz
;
3884 stripe_exp
= raid_device
->stripe_exponent
;
3885 stripe_off
= v_lba
& (stripe_sz
- 1);
3887 /* Check whether IO falls within a stripe */
3888 if ((stripe_off
+ io_size
) <= stripe_sz
) {
3889 num_pds
= raid_device
->num_pds
;
3890 p_lba
= v_lba
>> stripe_exp
;
3891 stripe_unit
= p_lba
/ num_pds
;
3892 column
= p_lba
% num_pds
;
3893 p_lba
= (stripe_unit
<< stripe_exp
) +
3895 mpi_request
->DevHandle
=
3896 cpu_to_le16(raid_device
->
3898 (*(__be32
*)(&cdb_ptr
[i
])) =
3901 * WD: To indicate this I/O is directI/O
3903 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3907 io_size
= scsi_bufflen(scmd
) >>
3908 raid_device
->block_exponent
;
3909 /* get virtual lba */
3910 v_llba
= be64_to_cpu(*(__be64
*)(&cdb_ptr
[2]));
3912 if ((v_llba
+ (u64
)io_size
- 1) <=
3913 raid_device
->max_lba
) {
3914 stripe_sz
= raid_device
->stripe_sz
;
3915 stripe_exp
= raid_device
->stripe_exponent
;
3916 stripe_off
= (u32
) (v_llba
& (stripe_sz
- 1));
3918 /* Check whether IO falls within a stripe */
3919 if ((stripe_off
+ io_size
) <= stripe_sz
) {
3920 num_pds
= raid_device
->num_pds
;
3921 p_lba
= (u32
)(v_llba
>> stripe_exp
);
3922 stripe_unit
= p_lba
/ num_pds
;
3923 column
= p_lba
% num_pds
;
3924 p_lba
= (stripe_unit
<< stripe_exp
) +
3926 mpi_request
->DevHandle
=
3927 cpu_to_le16(raid_device
->
3929 (*(__be64
*)(&cdb_ptr
[2])) =
3930 cpu_to_be64((u64
)p_lba
);
3932 * WD: To indicate this I/O is directI/O
3934 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3942 * _scsih_qcmd - main scsi request entry point
3943 * @scmd: pointer to scsi command object
3944 * @done: function pointer to be invoked on completion
3946 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3948 * Returns 0 on success. If there's a failure, return either:
3949 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3950 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3953 _scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
3955 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
3956 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3957 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3958 struct _raid_device
*raid_device
;
3959 Mpi2SCSIIORequest_t
*mpi_request
;
3963 sas_device_priv_data
= scmd
->device
->hostdata
;
3964 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3965 scmd
->result
= DID_NO_CONNECT
<< 16;
3966 scmd
->scsi_done(scmd
);
3970 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3971 scmd
->result
= DID_NO_CONNECT
<< 16;
3972 scmd
->scsi_done(scmd
);
3976 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3977 /* invalid device handle */
3978 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3979 scmd
->result
= DID_NO_CONNECT
<< 16;
3980 scmd
->scsi_done(scmd
);
3984 /* host recovery or link resets sent via IOCTLs */
3985 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3986 return SCSI_MLQUEUE_HOST_BUSY
;
3987 /* device busy with task management */
3988 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3989 return SCSI_MLQUEUE_DEVICE_BUSY
;
3990 /* device has been deleted */
3991 else if (sas_target_priv_data
->deleted
) {
3992 scmd
->result
= DID_NO_CONNECT
<< 16;
3993 scmd
->scsi_done(scmd
);
3997 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3998 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3999 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4000 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4002 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4005 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
4006 if (scmd
->device
->tagged_supported
) {
4007 if (scmd
->device
->ordered_tags
)
4008 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
4010 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4012 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4014 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4015 /* Make sure Device is not raid volume.
4016 * We do not expose raid functionality to upper layer for warpdrive.
4018 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4019 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4020 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4022 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4024 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
4025 ioc
->name
, __func__
);
4028 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4029 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
4030 _scsih_setup_eedp(scmd
, mpi_request
);
4031 if (scmd
->cmd_len
== 32)
4032 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4033 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4034 if (sas_device_priv_data
->sas_target
->flags
&
4035 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4036 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4038 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4039 mpi_request
->DevHandle
=
4040 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4041 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4042 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4043 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4044 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4045 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4046 mpi_request
->SenseBufferLowAddress
=
4047 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
4048 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4049 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
4050 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
4051 mpi_request
->VF_ID
= 0; /* TODO */
4052 mpi_request
->VP_ID
= 0;
4053 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4055 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4057 if (!mpi_request
->DataLength
) {
4058 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4060 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
4061 mpt2sas_base_free_smid(ioc
, smid
);
4066 raid_device
= sas_target_priv_data
->raid_device
;
4067 if (raid_device
&& raid_device
->direct_io_enabled
)
4068 _scsih_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4071 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
4072 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4073 le16_to_cpu(mpi_request
->DevHandle
));
4075 mpt2sas_base_put_smid_default(ioc
, smid
);
4079 return SCSI_MLQUEUE_HOST_BUSY
;
4083 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4084 * @sense_buffer: sense data returned by target
4085 * @data: normalized skey/asc/ascq
4090 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4092 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4093 /* descriptor format */
4094 data
->skey
= sense_buffer
[1] & 0x0F;
4095 data
->asc
= sense_buffer
[2];
4096 data
->ascq
= sense_buffer
[3];
4099 data
->skey
= sense_buffer
[2] & 0x0F;
4100 data
->asc
= sense_buffer
[12];
4101 data
->ascq
= sense_buffer
[13];
4105 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4107 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4108 * @ioc: per adapter object
4109 * @scmd: pointer to scsi command object
4110 * @mpi_reply: reply mf payload returned from firmware
4112 * scsi_status - SCSI Status code returned from target device
4113 * scsi_state - state info associated with SCSI_IO determined by ioc
4114 * ioc_status - ioc supplied status info
4119 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4120 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4124 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4125 MPI2_IOCSTATUS_MASK
;
4126 u8 scsi_state
= mpi_reply
->SCSIState
;
4127 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4128 char *desc_ioc_state
= NULL
;
4129 char *desc_scsi_status
= NULL
;
4130 char *desc_scsi_state
= ioc
->tmp_string
;
4131 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4132 struct _sas_device
*sas_device
= NULL
;
4133 unsigned long flags
;
4134 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4135 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
4136 char *device_str
= NULL
;
4141 if (ioc
->hide_ir_msg
)
4142 device_str
= "WarpDrive";
4144 device_str
= "volume";
4146 if (log_info
== 0x31170000)
4149 switch (ioc_status
) {
4150 case MPI2_IOCSTATUS_SUCCESS
:
4151 desc_ioc_state
= "success";
4153 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4154 desc_ioc_state
= "invalid function";
4156 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4157 desc_ioc_state
= "scsi recovered error";
4159 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4160 desc_ioc_state
= "scsi invalid dev handle";
4162 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4163 desc_ioc_state
= "scsi device not there";
4165 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4166 desc_ioc_state
= "scsi data overrun";
4168 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4169 desc_ioc_state
= "scsi data underrun";
4171 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4172 desc_ioc_state
= "scsi io data error";
4174 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4175 desc_ioc_state
= "scsi protocol error";
4177 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4178 desc_ioc_state
= "scsi task terminated";
4180 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4181 desc_ioc_state
= "scsi residual mismatch";
4183 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4184 desc_ioc_state
= "scsi task mgmt failed";
4186 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4187 desc_ioc_state
= "scsi ioc terminated";
4189 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4190 desc_ioc_state
= "scsi ext terminated";
4192 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4193 desc_ioc_state
= "eedp guard error";
4195 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4196 desc_ioc_state
= "eedp ref tag error";
4198 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4199 desc_ioc_state
= "eedp app tag error";
4202 desc_ioc_state
= "unknown";
4206 switch (scsi_status
) {
4207 case MPI2_SCSI_STATUS_GOOD
:
4208 desc_scsi_status
= "good";
4210 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4211 desc_scsi_status
= "check condition";
4213 case MPI2_SCSI_STATUS_CONDITION_MET
:
4214 desc_scsi_status
= "condition met";
4216 case MPI2_SCSI_STATUS_BUSY
:
4217 desc_scsi_status
= "busy";
4219 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4220 desc_scsi_status
= "intermediate";
4222 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4223 desc_scsi_status
= "intermediate condmet";
4225 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4226 desc_scsi_status
= "reservation conflict";
4228 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4229 desc_scsi_status
= "command terminated";
4231 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4232 desc_scsi_status
= "task set full";
4234 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4235 desc_scsi_status
= "aca active";
4237 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4238 desc_scsi_status
= "task aborted";
4241 desc_scsi_status
= "unknown";
4245 desc_scsi_state
[0] = '\0';
4247 desc_scsi_state
= " ";
4248 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4249 strcat(desc_scsi_state
, "response info ");
4250 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4251 strcat(desc_scsi_state
, "state terminated ");
4252 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4253 strcat(desc_scsi_state
, "no status ");
4254 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4255 strcat(desc_scsi_state
, "autosense failed ");
4256 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4257 strcat(desc_scsi_state
, "autosense valid ");
4259 scsi_print_command(scmd
);
4261 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4262 printk(MPT2SAS_WARN_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4263 device_str
, (unsigned long long)priv_target
->sas_address
);
4265 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4266 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4267 priv_target
->sas_address
);
4269 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
4270 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
4272 printk(MPT2SAS_WARN_FMT
4273 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4274 ioc
->name
, sas_device
->enclosure_logical_id
,
4277 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4280 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4281 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4282 desc_ioc_state
, ioc_status
, smid
);
4283 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
4284 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4285 scsi_get_resid(scmd
));
4286 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
4287 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4288 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4289 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
4290 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
4291 scsi_status
, desc_scsi_state
, scsi_state
);
4293 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4294 struct sense_info data
;
4295 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4296 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
4297 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
4298 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4301 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4302 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4303 response_bytes
= (u8
*)&response_info
;
4304 _scsih_response_code(ioc
, response_bytes
[0]);
4310 * _scsih_turn_on_fault_led - illuminate Fault LED
4311 * @ioc: per adapter object
4312 * @handle: device handle
4318 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4320 Mpi2SepReply_t mpi_reply
;
4321 Mpi2SepRequest_t mpi_request
;
4323 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4324 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4325 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4326 mpi_request
.SlotStatus
=
4327 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4328 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4329 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4330 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4331 &mpi_request
)) != 0) {
4332 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4333 __FILE__
, __LINE__
, __func__
);
4337 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4338 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
4339 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4340 le16_to_cpu(mpi_reply
.IOCStatus
),
4341 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4347 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4348 * @ioc: per adapter object
4349 * @handle: device handle
4350 * Context: interrupt.
4355 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4357 struct fw_event_work
*fw_event
;
4359 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4362 fw_event
->event
= MPT2SAS_TURN_ON_FAULT_LED
;
4363 fw_event
->device_handle
= handle
;
4364 fw_event
->ioc
= ioc
;
4365 _scsih_fw_event_add(ioc
, fw_event
);
4369 * _scsih_smart_predicted_fault - process smart errors
4370 * @ioc: per adapter object
4371 * @handle: device handle
4372 * Context: interrupt.
4377 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4379 struct scsi_target
*starget
;
4380 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4381 Mpi2EventNotificationReply_t
*event_reply
;
4382 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4383 struct _sas_device
*sas_device
;
4385 unsigned long flags
;
4387 /* only handle non-raid devices */
4388 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4389 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4391 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4394 starget
= sas_device
->starget
;
4395 sas_target_priv_data
= starget
->hostdata
;
4397 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4398 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4399 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4402 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
4403 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4405 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4406 _scsih_send_event_to_turn_on_fault_led(ioc
, handle
);
4408 /* insert into event log */
4409 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4410 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4411 event_reply
= kzalloc(sz
, GFP_ATOMIC
);
4413 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4414 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4418 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4419 event_reply
->Event
=
4420 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4421 event_reply
->MsgLength
= sz
/4;
4422 event_reply
->EventDataLength
=
4423 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4424 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4425 event_reply
->EventData
;
4426 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4427 event_data
->ASC
= 0x5D;
4428 event_data
->DevHandle
= cpu_to_le16(handle
);
4429 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4430 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
4435 * _scsih_io_done - scsi request callback
4436 * @ioc: per adapter object
4437 * @smid: system request message index
4438 * @msix_index: MSIX table index supplied by the OS
4439 * @reply: reply message frame(lower 32bit addr)
4441 * Callback handler when using _scsih_qcmd.
4443 * Return 1 meaning mf should be freed from _base_interrupt
4444 * 0 means the mf is freed from this function.
4447 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4449 Mpi2SCSIIORequest_t
*mpi_request
;
4450 Mpi2SCSIIOReply_t
*mpi_reply
;
4451 struct scsi_cmnd
*scmd
;
4457 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4458 u32 response_code
= 0;
4459 unsigned long flags
;
4461 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4462 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4466 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4468 if (mpi_reply
== NULL
) {
4469 scmd
->result
= DID_OK
<< 16;
4473 sas_device_priv_data
= scmd
->device
->hostdata
;
4474 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4475 sas_device_priv_data
->sas_target
->deleted
) {
4476 scmd
->result
= DID_NO_CONNECT
<< 16;
4479 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4481 * WARPDRIVE: If direct_io is set then it is directIO,
4482 * the failed direct I/O should be redirected to volume
4484 if (_scsih_scsi_direct_io_get(ioc
, smid
) &&
4485 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4486 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4487 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4488 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4489 _scsih_scsi_direct_io_set(ioc
, smid
, 0);
4490 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4491 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4492 mpi_request
->DevHandle
=
4493 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4494 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4495 sas_device_priv_data
->sas_target
->handle
);
4500 /* turning off TLR */
4501 scsi_state
= mpi_reply
->SCSIState
;
4502 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4504 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4505 if (!sas_device_priv_data
->tlr_snoop_check
) {
4506 sas_device_priv_data
->tlr_snoop_check
++;
4507 /* Make sure Device is not raid volume.
4508 * We do not expose raid functionality to upper layer for warpdrive.
4510 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4511 sas_is_tlr_enabled(scmd
->device
) &&
4512 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4513 sas_disable_tlr(scmd
->device
);
4514 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4518 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4519 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4520 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4521 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4524 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4525 scsi_status
= mpi_reply
->SCSIStatus
;
4527 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4528 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4529 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4530 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4531 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4534 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4535 struct sense_info data
;
4536 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
4538 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4539 le32_to_cpu(mpi_reply
->SenseCount
));
4540 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4541 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4542 /* failure prediction threshold exceeded */
4543 if (data
.asc
== 0x5D)
4544 _scsih_smart_predicted_fault(ioc
,
4545 le16_to_cpu(mpi_reply
->DevHandle
));
4548 switch (ioc_status
) {
4549 case MPI2_IOCSTATUS_BUSY
:
4550 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4551 scmd
->result
= SAM_STAT_BUSY
;
4554 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4555 scmd
->result
= DID_NO_CONNECT
<< 16;
4558 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4559 if (sas_device_priv_data
->block
) {
4560 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4563 scmd
->result
= DID_SOFT_ERROR
<< 16;
4565 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4566 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4567 scmd
->result
= DID_RESET
<< 16;
4570 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4571 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4572 scmd
->result
= DID_SOFT_ERROR
<< 16;
4574 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4577 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4578 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4580 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4583 if (xfer_cnt
< scmd
->underflow
) {
4584 if (scsi_status
== SAM_STAT_BUSY
)
4585 scmd
->result
= SAM_STAT_BUSY
;
4587 scmd
->result
= DID_SOFT_ERROR
<< 16;
4588 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4589 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4590 scmd
->result
= DID_SOFT_ERROR
<< 16;
4591 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4592 scmd
->result
= DID_RESET
<< 16;
4593 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4594 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4595 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4596 scmd
->result
= (DRIVER_SENSE
<< 24) |
4597 SAM_STAT_CHECK_CONDITION
;
4598 scmd
->sense_buffer
[0] = 0x70;
4599 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4600 scmd
->sense_buffer
[12] = 0x20;
4601 scmd
->sense_buffer
[13] = 0;
4605 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4606 scsi_set_resid(scmd
, 0);
4607 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4608 case MPI2_IOCSTATUS_SUCCESS
:
4609 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4610 if (response_code
==
4611 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4612 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4613 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4614 scmd
->result
= DID_SOFT_ERROR
<< 16;
4615 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4616 scmd
->result
= DID_RESET
<< 16;
4619 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4620 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4621 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4622 _scsih_eedp_error_handling(scmd
, ioc_status
);
4624 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4625 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4626 case MPI2_IOCSTATUS_INVALID_SGL
:
4627 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4628 case MPI2_IOCSTATUS_INVALID_FIELD
:
4629 case MPI2_IOCSTATUS_INVALID_STATE
:
4630 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4631 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4633 scmd
->result
= DID_SOFT_ERROR
<< 16;
4638 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4639 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4640 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4644 scsi_dma_unmap(scmd
);
4645 scmd
->scsi_done(scmd
);
4650 * _scsih_sas_host_refresh - refreshing sas host object contents
4651 * @ioc: per adapter object
4654 * During port enable, fw will send topology events for every device. Its
4655 * possible that the handles may change from the previous setting, so this
4656 * code keeping handles updating if changed.
4661 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4666 Mpi2ConfigReply_t mpi_reply
;
4667 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4668 u16 attached_handle
;
4671 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4672 "updating handles for sas_host(0x%016llx)\n",
4673 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4675 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4676 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4677 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4678 if (!sas_iounit_pg0
) {
4679 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4680 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4684 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4685 sas_iounit_pg0
, sz
)) != 0)
4687 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4688 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4690 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4691 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4693 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4694 PhyData
[0].ControllerDevHandle
);
4695 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4696 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4698 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4699 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4700 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4701 attached_handle
, i
, link_rate
);
4704 kfree(sas_iounit_pg0
);
4708 * _scsih_sas_host_add - create sas host object
4709 * @ioc: per adapter object
4711 * Creating host side data object, stored in ioc->sas_hba
4716 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4719 Mpi2ConfigReply_t mpi_reply
;
4720 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4721 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4722 Mpi2SasPhyPage0_t phy_pg0
;
4723 Mpi2SasDevicePage0_t sas_device_pg0
;
4724 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4727 u16 device_missing_delay
;
4729 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4730 if (!ioc
->sas_hba
.num_phys
) {
4731 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4732 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4736 /* sas_iounit page 0 */
4737 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4738 sizeof(Mpi2SasIOUnit0PhyData_t
));
4739 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4740 if (!sas_iounit_pg0
) {
4741 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4742 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4745 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4746 sas_iounit_pg0
, sz
))) {
4747 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4748 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4751 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4752 MPI2_IOCSTATUS_MASK
;
4753 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4754 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4755 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4759 /* sas_iounit page 1 */
4760 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4761 sizeof(Mpi2SasIOUnit1PhyData_t
));
4762 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4763 if (!sas_iounit_pg1
) {
4764 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4768 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4769 sas_iounit_pg1
, sz
))) {
4770 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4771 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4774 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4775 MPI2_IOCSTATUS_MASK
;
4776 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4777 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4778 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4782 ioc
->io_missing_delay
=
4783 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4784 device_missing_delay
=
4785 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4786 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4787 ioc
->device_missing_delay
= (device_missing_delay
&
4788 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4790 ioc
->device_missing_delay
= device_missing_delay
&
4791 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4793 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4794 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4795 sizeof(struct _sas_phy
), GFP_KERNEL
);
4796 if (!ioc
->sas_hba
.phy
) {
4797 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4798 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4801 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4802 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4804 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4805 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4808 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4809 MPI2_IOCSTATUS_MASK
;
4810 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4811 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4812 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4817 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4818 PhyData
[0].ControllerDevHandle
);
4819 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4820 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4821 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4822 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4824 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4825 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4826 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4827 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4830 ioc
->sas_hba
.enclosure_handle
=
4831 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4832 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4833 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4834 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4835 (unsigned long long) ioc
->sas_hba
.sas_address
,
4836 ioc
->sas_hba
.num_phys
) ;
4838 if (ioc
->sas_hba
.enclosure_handle
) {
4839 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4841 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4842 ioc
->sas_hba
.enclosure_handle
))) {
4843 ioc
->sas_hba
.enclosure_logical_id
=
4844 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4849 kfree(sas_iounit_pg1
);
4850 kfree(sas_iounit_pg0
);
4854 * _scsih_expander_add - creating expander object
4855 * @ioc: per adapter object
4856 * @handle: expander handle
4858 * Creating expander object, stored in ioc->sas_expander_list.
4860 * Return 0 for success, else error.
4863 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4865 struct _sas_node
*sas_expander
;
4866 Mpi2ConfigReply_t mpi_reply
;
4867 Mpi2ExpanderPage0_t expander_pg0
;
4868 Mpi2ExpanderPage1_t expander_pg1
;
4869 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4872 u64 sas_address
, sas_address_parent
= 0;
4874 unsigned long flags
;
4875 struct _sas_port
*mpt2sas_port
= NULL
;
4881 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4884 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4885 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4886 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4887 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4891 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4892 MPI2_IOCSTATUS_MASK
;
4893 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4894 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4895 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4899 /* handle out of order topology events */
4900 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4901 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4903 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4904 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4907 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4908 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4909 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4910 sas_address_parent
);
4911 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4912 if (!sas_expander
) {
4913 rc
= _scsih_expander_add(ioc
, parent_handle
);
4919 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4920 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4921 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4923 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4928 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4930 if (!sas_expander
) {
4931 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4932 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4936 sas_expander
->handle
= handle
;
4937 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4938 sas_expander
->sas_address_parent
= sas_address_parent
;
4939 sas_expander
->sas_address
= sas_address
;
4941 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4942 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4943 handle
, parent_handle
, (unsigned long long)
4944 sas_expander
->sas_address
, sas_expander
->num_phys
);
4946 if (!sas_expander
->num_phys
)
4948 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4949 sizeof(struct _sas_phy
), GFP_KERNEL
);
4950 if (!sas_expander
->phy
) {
4951 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4952 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4957 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4958 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4959 sas_address_parent
);
4960 if (!mpt2sas_port
) {
4961 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4962 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4966 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4968 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4969 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4970 &expander_pg1
, i
, handle
))) {
4971 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4972 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4976 sas_expander
->phy
[i
].handle
= handle
;
4977 sas_expander
->phy
[i
].phy_id
= i
;
4979 if ((mpt2sas_transport_add_expander_phy(ioc
,
4980 &sas_expander
->phy
[i
], expander_pg1
,
4981 sas_expander
->parent_dev
))) {
4982 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4983 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4989 if (sas_expander
->enclosure_handle
) {
4990 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4991 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4992 sas_expander
->enclosure_handle
))) {
4993 sas_expander
->enclosure_logical_id
=
4994 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4998 _scsih_expander_node_add(ioc
, sas_expander
);
5004 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5005 sas_address_parent
);
5006 kfree(sas_expander
);
5011 * _scsih_done - scsih callback handler.
5012 * @ioc: per adapter object
5013 * @smid: system request message index
5014 * @msix_index: MSIX table index supplied by the OS
5015 * @reply: reply message frame(lower 32bit addr)
5017 * Callback handler when sending internal generated message frames.
5018 * The callback index passed is `ioc->scsih_cb_idx`
5020 * Return 1 meaning mf should be freed from _base_interrupt
5021 * 0 means the mf is freed from this function.
5024 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5026 MPI2DefaultReply_t
*mpi_reply
;
5028 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5029 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
5031 if (ioc
->scsih_cmds
.smid
!= smid
)
5033 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
5035 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5036 mpi_reply
->MsgLength
*4);
5037 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
5039 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
5040 complete(&ioc
->scsih_cmds
.done
);
5045 * mpt2sas_expander_remove - removing expander object
5046 * @ioc: per adapter object
5047 * @sas_address: expander sas_address
5052 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5054 struct _sas_node
*sas_expander
;
5055 unsigned long flags
;
5057 if (ioc
->shost_recovery
)
5060 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5061 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5064 list_del(&sas_expander
->list
);
5065 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5067 _scsih_expander_node_remove(ioc
, sas_expander
);
5071 * _scsih_check_access_status - check access flags
5072 * @ioc: per adapter object
5073 * @sas_address: sas address
5074 * @handle: sas device handle
5075 * @access_flags: errors returned during discovery of the device
5077 * Return 0 for success, else failure
5080 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5081 u16 handle
, u8 access_status
)
5086 switch (access_status
) {
5087 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5091 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5092 desc
= "sata capability failed";
5094 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5095 desc
= "sata affiliation conflict";
5097 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5098 desc
= "route not addressable";
5100 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5101 desc
= "smp error not addressable";
5103 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5104 desc
= "device blocked";
5106 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5107 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5108 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5109 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5110 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5111 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5112 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5113 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5114 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5115 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5116 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5117 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5118 desc
= "sata initialization failed";
5128 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
5129 "handle(0x%04x)\n", ioc
->name
, desc
,
5130 (unsigned long long)sas_address
, handle
);
5135 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5137 Mpi2ConfigReply_t mpi_reply
;
5138 Mpi2SasDevicePage0_t sas_device_pg0
;
5139 struct _sas_device
*sas_device
;
5141 unsigned long flags
;
5143 struct scsi_target
*starget
;
5144 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5148 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5149 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5152 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5153 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5156 /* check if this is end device */
5157 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5158 if (!(_scsih_is_end_device(device_info
)))
5161 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5162 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5163 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5167 printk(MPT2SAS_ERR_FMT
"device is not present "
5168 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
5169 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5173 if (unlikely(sas_device
->handle
!= handle
)) {
5174 starget
= sas_device
->starget
;
5175 sas_target_priv_data
= starget
->hostdata
;
5176 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
5177 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
5178 sas_target_priv_data
->handle
= handle
;
5179 sas_device
->handle
= handle
;
5182 /* check if device is present */
5183 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5184 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5185 printk(MPT2SAS_ERR_FMT
"device is not present "
5186 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
5187 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5191 /* check if there were any issues with discovery */
5192 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5193 sas_device_pg0
.AccessStatus
)) {
5194 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5197 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5198 _scsih_ublock_io_device(ioc
, sas_address
);
5203 * _scsih_add_device - creating sas device object
5204 * @ioc: per adapter object
5205 * @handle: sas device handle
5206 * @phy_num: phy number end device attached to
5207 * @is_pd: is this hidden raid component
5209 * Creating end device object, stored in ioc->sas_device_list.
5211 * Returns 0 for success, non-zero for failure.
5214 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
5216 Mpi2ConfigReply_t mpi_reply
;
5217 Mpi2SasDevicePage0_t sas_device_pg0
;
5218 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5219 struct _sas_device
*sas_device
;
5223 unsigned long flags
;
5225 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5226 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5227 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5228 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5232 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5233 MPI2_IOCSTATUS_MASK
;
5234 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5235 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5236 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5240 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5242 /* check if device is present */
5243 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5244 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5245 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5246 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5247 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
5248 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
5252 /* check if there were any issues with discovery */
5253 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5254 sas_device_pg0
.AccessStatus
))
5257 /* check if this is end device */
5258 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5259 if (!(_scsih_is_end_device(device_info
))) {
5260 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5261 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5266 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5267 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5269 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5274 sas_device
= kzalloc(sizeof(struct _sas_device
),
5277 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5278 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5282 sas_device
->handle
= handle
;
5283 if (_scsih_get_sas_address(ioc
, le16_to_cpu
5284 (sas_device_pg0
.ParentDevHandle
),
5285 &sas_device
->sas_address_parent
) != 0)
5286 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5287 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5288 sas_device
->enclosure_handle
=
5289 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5291 le16_to_cpu(sas_device_pg0
.Slot
);
5292 sas_device
->device_info
= device_info
;
5293 sas_device
->sas_address
= sas_address
;
5294 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5296 /* get enclosure_logical_id */
5297 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
5298 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5299 sas_device
->enclosure_handle
)))
5300 sas_device
->enclosure_logical_id
=
5301 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5303 /* get device name */
5304 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5306 if (ioc
->wait_for_discovery_to_complete
)
5307 _scsih_sas_device_init_add(ioc
, sas_device
);
5309 _scsih_sas_device_add(ioc
, sas_device
);
5315 * _scsih_remove_device - removing sas device object
5316 * @ioc: per adapter object
5317 * @sas_device_delete: the sas_device object
5322 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
5323 struct _sas_device
*sas_device
)
5325 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5327 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
5328 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5329 sas_device
->handle
, (unsigned long long)
5330 sas_device
->sas_address
));
5332 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5333 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5334 sas_target_priv_data
->deleted
= 1;
5335 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5336 sas_target_priv_data
->handle
=
5337 MPT2SAS_INVALID_DEVICE_HANDLE
;
5340 if (!ioc
->hide_drives
)
5341 mpt2sas_transport_port_remove(ioc
,
5342 sas_device
->sas_address
,
5343 sas_device
->sas_address_parent
);
5345 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
5346 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
5347 (unsigned long long) sas_device
->sas_address
);
5349 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
5350 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5351 sas_device
->handle
, (unsigned long long)
5352 sas_device
->sas_address
));
5356 * _scsih_device_remove_by_handle - removing device object by handle
5357 * @ioc: per adapter object
5358 * @handle: device handle
5363 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5365 struct _sas_device
*sas_device
;
5366 unsigned long flags
;
5368 if (ioc
->shost_recovery
)
5371 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5372 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5374 list_del(&sas_device
->list
);
5375 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5377 _scsih_remove_device(ioc
, sas_device
);
5381 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5382 * @ioc: per adapter object
5383 * @sas_address: device sas_address
5388 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
5391 struct _sas_device
*sas_device
;
5392 unsigned long flags
;
5394 if (ioc
->shost_recovery
)
5397 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5398 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5401 list_del(&sas_device
->list
);
5402 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5404 _scsih_remove_device(ioc
, sas_device
);
5406 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5408 * _scsih_sas_topology_change_event_debug - debug for topology event
5409 * @ioc: per adapter object
5410 * @event_data: event data payload
5414 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5415 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5421 char *status_str
= NULL
;
5422 u8 link_rate
, prev_link_rate
;
5424 switch (event_data
->ExpStatus
) {
5425 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5428 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5429 status_str
= "remove";
5431 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5433 status_str
= "responding";
5435 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5436 status_str
= "remove delay";
5439 status_str
= "unknown status";
5442 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
5443 ioc
->name
, status_str
);
5444 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
5445 "start_phy(%02d), count(%d)\n",
5446 le16_to_cpu(event_data
->ExpanderDevHandle
),
5447 le16_to_cpu(event_data
->EnclosureHandle
),
5448 event_data
->StartPhyNum
, event_data
->NumEntries
);
5449 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5450 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5453 phy_number
= event_data
->StartPhyNum
+ i
;
5454 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5455 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5456 switch (reason_code
) {
5457 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5458 status_str
= "target add";
5460 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5461 status_str
= "target remove";
5463 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5464 status_str
= "delay target remove";
5466 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5467 status_str
= "link rate change";
5469 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5470 status_str
= "target responding";
5473 status_str
= "unknown";
5476 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5477 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5478 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
5479 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5480 handle
, status_str
, link_rate
, prev_link_rate
);
5487 * _scsih_sas_topology_change_event - handle topology changes
5488 * @ioc: per adapter object
5489 * @fw_event: The fw_event_work object
5494 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5495 struct fw_event_work
*fw_event
)
5498 u16 parent_handle
, handle
;
5500 u8 phy_number
, max_phys
;
5501 struct _sas_node
*sas_expander
;
5503 unsigned long flags
;
5504 u8 link_rate
, prev_link_rate
;
5505 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
5507 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5508 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5509 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5512 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5515 if (!ioc
->sas_hba
.num_phys
)
5516 _scsih_sas_host_add(ioc
);
5518 _scsih_sas_host_refresh(ioc
);
5520 if (fw_event
->ignore
) {
5521 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
5522 "event\n", ioc
->name
));
5526 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5528 /* handle expander add */
5529 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5530 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5533 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5534 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
5537 sas_address
= sas_expander
->sas_address
;
5538 max_phys
= sas_expander
->num_phys
;
5539 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5540 sas_address
= ioc
->sas_hba
.sas_address
;
5541 max_phys
= ioc
->sas_hba
.num_phys
;
5543 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5546 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5548 /* handle siblings events */
5549 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5550 if (fw_event
->ignore
) {
5551 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
5552 "expander event\n", ioc
->name
));
5555 if (ioc
->shost_recovery
|| ioc
->remove_host
||
5556 ioc
->pci_error_recovery
)
5558 phy_number
= event_data
->StartPhyNum
+ i
;
5559 if (phy_number
>= max_phys
)
5561 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5562 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5563 if ((event_data
->PHY
[i
].PhyStatus
&
5564 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5565 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5567 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5570 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5571 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5572 switch (reason_code
) {
5573 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5575 if (ioc
->shost_recovery
)
5578 if (link_rate
== prev_link_rate
)
5581 mpt2sas_transport_update_links(ioc
, sas_address
,
5582 handle
, phy_number
, link_rate
);
5584 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5587 _scsih_check_device(ioc
, handle
);
5589 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5591 if (ioc
->shost_recovery
)
5594 mpt2sas_transport_update_links(ioc
, sas_address
,
5595 handle
, phy_number
, link_rate
);
5597 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5599 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5601 _scsih_device_remove_by_handle(ioc
, handle
);
5606 /* handle expander removal */
5607 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5609 mpt2sas_expander_remove(ioc
, sas_address
);
5613 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5615 * _scsih_sas_device_status_change_event_debug - debug for device event
5616 * @event_data: event data payload
5622 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5623 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5625 char *reason_str
= NULL
;
5627 switch (event_data
->ReasonCode
) {
5628 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5629 reason_str
= "smart data";
5631 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5632 reason_str
= "unsupported device discovered";
5634 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5635 reason_str
= "internal device reset";
5637 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5638 reason_str
= "internal task abort";
5640 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5641 reason_str
= "internal task abort set";
5643 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5644 reason_str
= "internal clear task set";
5646 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5647 reason_str
= "internal query task";
5649 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5650 reason_str
= "sata init failure";
5652 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5653 reason_str
= "internal device reset complete";
5655 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5656 reason_str
= "internal task abort complete";
5658 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5659 reason_str
= "internal async notification";
5661 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5662 reason_str
= "expander reduced functionality";
5664 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5665 reason_str
= "expander reduced functionality complete";
5668 reason_str
= "unknown reason";
5671 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5672 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5673 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5674 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5675 le16_to_cpu(event_data
->TaskTag
));
5676 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5677 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5678 event_data
->ASC
, event_data
->ASCQ
);
5679 printk(KERN_INFO
"\n");
5684 * _scsih_sas_device_status_change_event - handle device status change
5685 * @ioc: per adapter object
5686 * @fw_event: The fw_event_work object
5692 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5693 struct fw_event_work
*fw_event
)
5695 struct MPT2SAS_TARGET
*target_priv_data
;
5696 struct _sas_device
*sas_device
;
5698 unsigned long flags
;
5699 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5700 fw_event
->event_data
;
5702 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5703 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5704 _scsih_sas_device_status_change_event_debug(ioc
,
5708 /* In MPI Revision K (0xC), the internal device reset complete was
5709 * implemented, so avoid setting tm_busy flag for older firmware.
5711 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5714 if (event_data
->ReasonCode
!=
5715 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5716 event_data
->ReasonCode
!=
5717 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5720 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5721 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5722 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5725 if (!sas_device
|| !sas_device
->starget
) {
5726 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5730 target_priv_data
= sas_device
->starget
->hostdata
;
5731 if (!target_priv_data
) {
5732 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5736 if (event_data
->ReasonCode
==
5737 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5738 target_priv_data
->tm_busy
= 1;
5740 target_priv_data
->tm_busy
= 0;
5741 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5744 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5746 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5747 * @ioc: per adapter object
5748 * @event_data: event data payload
5754 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5755 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5757 char *reason_str
= NULL
;
5759 switch (event_data
->ReasonCode
) {
5760 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5761 reason_str
= "enclosure add";
5763 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5764 reason_str
= "enclosure remove";
5767 reason_str
= "unknown reason";
5771 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5772 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5773 " number slots(%d)\n", ioc
->name
, reason_str
,
5774 le16_to_cpu(event_data
->EnclosureHandle
),
5775 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5776 le16_to_cpu(event_data
->StartSlot
));
5781 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5782 * @ioc: per adapter object
5783 * @fw_event: The fw_event_work object
5789 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5790 struct fw_event_work
*fw_event
)
5792 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5793 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5794 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5795 fw_event
->event_data
);
5800 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5801 * @ioc: per adapter object
5802 * @fw_event: The fw_event_work object
5808 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER
*ioc
,
5809 struct fw_event_work
*fw_event
)
5811 struct scsi_cmnd
*scmd
;
5812 struct scsi_device
*sdev
;
5815 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5816 u32 termination_count
;
5818 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5819 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5821 unsigned long flags
;
5824 u8 task_abort_retries
;
5826 mutex_lock(&ioc
->tm_cmds
.mutex
);
5828 "%s: enter: phy number(%d), width(%d)\n",
5829 ioc
->name
, __func__
, event_data
->PhyNum
,
5830 event_data
->PortWidth
);
5832 _scsih_block_io_all_device(ioc
);
5834 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5835 mpi_reply
= ioc
->tm_cmds
.reply
;
5836 broadcast_aen_retry
:
5838 /* sanity checks for retrying this loop */
5839 if (max_retries
++ == 5) {
5840 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: giving up\n",
5841 ioc
->name
, __func__
));
5843 } else if (max_retries
> 1)
5844 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %d retry\n",
5845 ioc
->name
, __func__
, max_retries
- 1));
5847 termination_count
= 0;
5849 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5850 if (ioc
->shost_recovery
)
5852 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5855 sdev
= scmd
->device
;
5856 sas_device_priv_data
= sdev
->hostdata
;
5857 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5859 /* skip hidden raid components */
5860 if (sas_device_priv_data
->sas_target
->flags
&
5861 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5864 if (sas_device_priv_data
->sas_target
->flags
&
5865 MPT_TARGET_FLAGS_VOLUME
)
5868 handle
= sas_device_priv_data
->sas_target
->handle
;
5869 lun
= sas_device_priv_data
->lun
;
5872 if (ioc
->shost_recovery
)
5875 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5876 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5877 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5880 sdev_printk(KERN_WARNING
, sdev
,
5881 "mpt2sas_scsih_issue_tm: FAILED when sending "
5882 "QUERY_TASK: scmd(%p)\n", scmd
);
5883 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5884 goto broadcast_aen_retry
;
5886 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5887 & MPI2_IOCSTATUS_MASK
;
5888 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5889 sdev_printk(KERN_WARNING
, sdev
, "query task: FAILED "
5890 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status
,
5892 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5893 goto broadcast_aen_retry
;
5896 /* see if IO is still owned by IOC and target */
5897 if (mpi_reply
->ResponseCode
==
5898 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5899 mpi_reply
->ResponseCode
==
5900 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5901 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5904 task_abort_retries
= 0;
5906 if (task_abort_retries
++ == 60) {
5907 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5908 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5910 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5911 goto broadcast_aen_retry
;
5914 if (ioc
->shost_recovery
)
5917 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5918 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5921 sdev_printk(KERN_WARNING
, sdev
,
5922 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5923 "scmd(%p)\n", scmd
);
5927 if (task_abort_retries
> 1)
5928 sdev_printk(KERN_WARNING
, sdev
,
5929 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5931 task_abort_retries
- 1, scmd
);
5933 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5934 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5937 if (ioc
->broadcast_aen_pending
) {
5938 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: loop back due to"
5939 " pending AEN\n", ioc
->name
, __func__
));
5940 ioc
->broadcast_aen_pending
= 0;
5941 goto broadcast_aen_retry
;
5945 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5948 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5949 "%s - exit, query_count = %d termination_count = %d\n",
5950 ioc
->name
, __func__
, query_count
, termination_count
));
5952 ioc
->broadcast_aen_busy
= 0;
5953 if (!ioc
->shost_recovery
)
5954 _scsih_ublock_io_all_device(ioc
);
5955 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5959 * _scsih_sas_discovery_event - handle discovery events
5960 * @ioc: per adapter object
5961 * @fw_event: The fw_event_work object
5967 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5968 struct fw_event_work
*fw_event
)
5970 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5972 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5973 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5974 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5975 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5977 if (event_data
->DiscoveryStatus
)
5978 printk("discovery_status(0x%08x)",
5979 le32_to_cpu(event_data
->DiscoveryStatus
));
5984 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5985 !ioc
->sas_hba
.num_phys
) {
5986 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
5987 /* Wait for the reset to complete */
5988 while (ioc
->shost_recovery
)
5991 _scsih_sas_host_add(ioc
);
5996 * _scsih_reprobe_lun - reprobing lun
5997 * @sdev: scsi device struct
5998 * @no_uld_attach: sdev->no_uld_attach flag setting
6002 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6006 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6007 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6008 sdev
->no_uld_attach
? "hidding" : "exposing");
6009 rc
= scsi_device_reprobe(sdev
);
6013 * _scsih_sas_volume_add - add new volume
6014 * @ioc: per adapter object
6015 * @element: IR config element data
6021 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
6022 Mpi2EventIrConfigElement_t
*element
)
6024 struct _raid_device
*raid_device
;
6025 unsigned long flags
;
6027 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6030 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6032 printk(MPT2SAS_ERR_FMT
6033 "failure at %s:%d/%s()!\n", ioc
->name
,
6034 __FILE__
, __LINE__
, __func__
);
6038 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6039 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6040 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6045 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6047 printk(MPT2SAS_ERR_FMT
6048 "failure at %s:%d/%s()!\n", ioc
->name
,
6049 __FILE__
, __LINE__
, __func__
);
6053 raid_device
->id
= ioc
->sas_id
++;
6054 raid_device
->channel
= RAID_CHANNEL
;
6055 raid_device
->handle
= handle
;
6056 raid_device
->wwid
= wwid
;
6057 _scsih_raid_device_add(ioc
, raid_device
);
6058 if (!ioc
->wait_for_discovery_to_complete
) {
6059 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6060 raid_device
->id
, 0);
6062 _scsih_raid_device_remove(ioc
, raid_device
);
6064 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6065 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6066 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6071 * _scsih_sas_volume_delete - delete volume
6072 * @ioc: per adapter object
6073 * @handle: volume device handle
6079 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
6081 struct _raid_device
*raid_device
;
6082 unsigned long flags
;
6083 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6084 struct scsi_target
*starget
= NULL
;
6086 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6087 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6089 if (raid_device
->starget
) {
6090 starget
= raid_device
->starget
;
6091 sas_target_priv_data
= starget
->hostdata
;
6092 sas_target_priv_data
->deleted
= 1;
6094 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6095 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6096 (unsigned long long) raid_device
->wwid
);
6097 list_del(&raid_device
->list
);
6100 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6102 scsi_remove_target(&starget
->dev
);
6106 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6107 * @ioc: per adapter object
6108 * @element: IR config element data
6114 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
6115 Mpi2EventIrConfigElement_t
*element
)
6117 struct _sas_device
*sas_device
;
6118 struct scsi_target
*starget
= NULL
;
6119 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6120 unsigned long flags
;
6121 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6123 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6124 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6126 sas_device
->volume_handle
= 0;
6127 sas_device
->volume_wwid
= 0;
6128 clear_bit(handle
, ioc
->pd_handles
);
6129 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6130 starget
= sas_device
->starget
;
6131 sas_target_priv_data
= starget
->hostdata
;
6132 sas_target_priv_data
->flags
&=
6133 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6136 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6140 /* exposing raid component */
6142 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6146 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6147 * @ioc: per adapter object
6148 * @element: IR config element data
6154 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
6155 Mpi2EventIrConfigElement_t
*element
)
6157 struct _sas_device
*sas_device
;
6158 struct scsi_target
*starget
= NULL
;
6159 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6160 unsigned long flags
;
6161 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6162 u16 volume_handle
= 0;
6163 u64 volume_wwid
= 0;
6165 mpt2sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6167 mpt2sas_config_get_volume_wwid(ioc
, volume_handle
,
6170 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6171 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6173 set_bit(handle
, ioc
->pd_handles
);
6174 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6175 starget
= sas_device
->starget
;
6176 sas_target_priv_data
= starget
->hostdata
;
6177 sas_target_priv_data
->flags
|=
6178 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6179 sas_device
->volume_handle
= volume_handle
;
6180 sas_device
->volume_wwid
= volume_wwid
;
6183 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6187 /* hiding raid component */
6189 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6193 * _scsih_sas_pd_delete - delete pd component
6194 * @ioc: per adapter object
6195 * @element: IR config element data
6201 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
6202 Mpi2EventIrConfigElement_t
*element
)
6204 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6206 _scsih_device_remove_by_handle(ioc
, handle
);
6210 * _scsih_sas_pd_add - remove pd component
6211 * @ioc: per adapter object
6212 * @element: IR config element data
6218 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
6219 Mpi2EventIrConfigElement_t
*element
)
6221 struct _sas_device
*sas_device
;
6222 unsigned long flags
;
6223 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6224 Mpi2ConfigReply_t mpi_reply
;
6225 Mpi2SasDevicePage0_t sas_device_pg0
;
6230 set_bit(handle
, ioc
->pd_handles
);
6232 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6233 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6234 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6238 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6239 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6240 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6241 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6245 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6246 MPI2_IOCSTATUS_MASK
;
6247 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6248 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6249 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6253 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6254 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6255 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6256 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6258 _scsih_add_device(ioc
, handle
, 0, 1);
6261 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6263 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6264 * @ioc: per adapter object
6265 * @event_data: event data payload
6271 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6272 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6274 Mpi2EventIrConfigElement_t
*element
;
6277 char *reason_str
= NULL
, *element_str
= NULL
;
6279 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6281 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
6282 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6283 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6284 "foreign" : "native", event_data
->NumElements
);
6285 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6286 switch (element
->ReasonCode
) {
6287 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6290 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6291 reason_str
= "remove";
6293 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6294 reason_str
= "no change";
6296 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6297 reason_str
= "hide";
6299 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6300 reason_str
= "unhide";
6302 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6303 reason_str
= "volume_created";
6305 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6306 reason_str
= "volume_deleted";
6308 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6309 reason_str
= "pd_created";
6311 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6312 reason_str
= "pd_deleted";
6315 reason_str
= "unknown reason";
6318 element_type
= le16_to_cpu(element
->ElementFlags
) &
6319 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6320 switch (element_type
) {
6321 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6322 element_str
= "volume";
6324 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6325 element_str
= "phys disk";
6327 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6328 element_str
= "hot spare";
6331 element_str
= "unknown element";
6334 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
6335 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6336 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6337 le16_to_cpu(element
->PhysDiskDevHandle
),
6338 element
->PhysDiskNum
);
6344 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6345 * @ioc: per adapter object
6346 * @fw_event: The fw_event_work object
6352 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
6353 struct fw_event_work
*fw_event
)
6355 Mpi2EventIrConfigElement_t
*element
;
6358 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
6360 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6361 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6362 && !ioc
->hide_ir_msg
)
6363 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6367 if (ioc
->shost_recovery
)
6370 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6371 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6373 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6374 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6376 switch (element
->ReasonCode
) {
6377 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6378 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6379 if (!foreign_config
)
6380 _scsih_sas_volume_add(ioc
, element
);
6382 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6383 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6384 if (!foreign_config
)
6385 _scsih_sas_volume_delete(ioc
,
6386 le16_to_cpu(element
->VolDevHandle
));
6388 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6389 if (!ioc
->is_warpdrive
)
6390 _scsih_sas_pd_hide(ioc
, element
);
6392 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6393 if (!ioc
->is_warpdrive
)
6394 _scsih_sas_pd_expose(ioc
, element
);
6396 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6397 if (!ioc
->is_warpdrive
)
6398 _scsih_sas_pd_add(ioc
, element
);
6400 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6401 if (!ioc
->is_warpdrive
)
6402 _scsih_sas_pd_delete(ioc
, element
);
6409 * _scsih_sas_ir_volume_event - IR volume event
6410 * @ioc: per adapter object
6411 * @fw_event: The fw_event_work object
6417 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
6418 struct fw_event_work
*fw_event
)
6421 unsigned long flags
;
6422 struct _raid_device
*raid_device
;
6426 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
6428 if (ioc
->shost_recovery
)
6431 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6434 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6435 state
= le32_to_cpu(event_data
->NewValue
);
6436 if (!ioc
->hide_ir_msg
)
6437 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6438 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6439 le32_to_cpu(event_data
->PreviousValue
), state
));
6442 case MPI2_RAID_VOL_STATE_MISSING
:
6443 case MPI2_RAID_VOL_STATE_FAILED
:
6444 _scsih_sas_volume_delete(ioc
, handle
);
6447 case MPI2_RAID_VOL_STATE_ONLINE
:
6448 case MPI2_RAID_VOL_STATE_DEGRADED
:
6449 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6451 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6452 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6453 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6458 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6460 printk(MPT2SAS_ERR_FMT
6461 "failure at %s:%d/%s()!\n", ioc
->name
,
6462 __FILE__
, __LINE__
, __func__
);
6466 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6468 printk(MPT2SAS_ERR_FMT
6469 "failure at %s:%d/%s()!\n", ioc
->name
,
6470 __FILE__
, __LINE__
, __func__
);
6474 raid_device
->id
= ioc
->sas_id
++;
6475 raid_device
->channel
= RAID_CHANNEL
;
6476 raid_device
->handle
= handle
;
6477 raid_device
->wwid
= wwid
;
6478 _scsih_raid_device_add(ioc
, raid_device
);
6479 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6480 raid_device
->id
, 0);
6482 _scsih_raid_device_remove(ioc
, raid_device
);
6485 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6492 * _scsih_sas_ir_physical_disk_event - PD event
6493 * @ioc: per adapter object
6494 * @fw_event: The fw_event_work object
6500 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
6501 struct fw_event_work
*fw_event
)
6503 u16 handle
, parent_handle
;
6505 struct _sas_device
*sas_device
;
6506 unsigned long flags
;
6507 Mpi2ConfigReply_t mpi_reply
;
6508 Mpi2SasDevicePage0_t sas_device_pg0
;
6510 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
6513 if (ioc
->shost_recovery
)
6516 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6519 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6520 state
= le32_to_cpu(event_data
->NewValue
);
6522 if (!ioc
->hide_ir_msg
)
6523 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6524 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6525 le32_to_cpu(event_data
->PreviousValue
), state
));
6528 case MPI2_RAID_PD_STATE_ONLINE
:
6529 case MPI2_RAID_PD_STATE_DEGRADED
:
6530 case MPI2_RAID_PD_STATE_REBUILDING
:
6531 case MPI2_RAID_PD_STATE_OPTIMAL
:
6532 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6534 if (!ioc
->is_warpdrive
)
6535 set_bit(handle
, ioc
->pd_handles
);
6537 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6538 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6539 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6544 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6545 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6547 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6548 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6552 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6553 MPI2_IOCSTATUS_MASK
;
6554 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6555 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6556 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6560 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6561 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6562 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6563 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6565 _scsih_add_device(ioc
, handle
, 0, 1);
6569 case MPI2_RAID_PD_STATE_OFFLINE
:
6570 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6571 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6577 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6579 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6580 * @ioc: per adapter object
6581 * @event_data: event data payload
6587 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6588 Mpi2EventDataIrOperationStatus_t
*event_data
)
6590 char *reason_str
= NULL
;
6592 switch (event_data
->RAIDOperation
) {
6593 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6594 reason_str
= "resync";
6596 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6597 reason_str
= "online capacity expansion";
6599 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6600 reason_str
= "consistency check";
6602 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6603 reason_str
= "background init";
6605 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6606 reason_str
= "make data consistent";
6613 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
6614 "\thandle(0x%04x), percent complete(%d)\n",
6615 ioc
->name
, reason_str
,
6616 le16_to_cpu(event_data
->VolDevHandle
),
6617 event_data
->PercentComplete
);
6622 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6623 * @ioc: per adapter object
6624 * @fw_event: The fw_event_work object
6630 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
6631 struct fw_event_work
*fw_event
)
6633 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
6634 static struct _raid_device
*raid_device
;
6635 unsigned long flags
;
6638 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6639 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6640 && !ioc
->hide_ir_msg
)
6641 _scsih_sas_ir_operation_status_event_debug(ioc
,
6645 /* code added for raid transport support */
6646 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6648 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6649 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6650 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6652 raid_device
->percent_complete
=
6653 event_data
->PercentComplete
;
6654 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6659 * _scsih_prep_device_scan - initialize parameters prior to device scan
6660 * @ioc: per adapter object
6662 * Set the deleted flag prior to device scan. If the device is found during
6663 * the scan, then we clear the deleted flag.
6666 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
6668 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
6669 struct scsi_device
*sdev
;
6671 shost_for_each_device(sdev
, ioc
->shost
) {
6672 sas_device_priv_data
= sdev
->hostdata
;
6673 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6674 sas_device_priv_data
->sas_target
->deleted
= 1;
6679 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6680 * @ioc: per adapter object
6681 * @sas_address: sas address
6682 * @slot: enclosure slot id
6683 * @handle: device handle
6685 * After host reset, find out whether devices are still responding.
6686 * Used in _scsi_remove_unresponsive_sas_devices.
6691 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6692 u16 slot
, u16 handle
)
6694 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
6695 struct scsi_target
*starget
;
6696 struct _sas_device
*sas_device
;
6697 unsigned long flags
;
6699 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6700 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6701 if (sas_device
->sas_address
== sas_address
&&
6702 sas_device
->slot
== slot
) {
6703 sas_device
->responding
= 1;
6704 starget
= sas_device
->starget
;
6705 if (starget
&& starget
->hostdata
) {
6706 sas_target_priv_data
= starget
->hostdata
;
6707 sas_target_priv_data
->tm_busy
= 0;
6708 sas_target_priv_data
->deleted
= 0;
6710 sas_target_priv_data
= NULL
;
6712 starget_printk(KERN_INFO
, starget
,
6713 "handle(0x%04x), sas_addr(0x%016llx), "
6714 "enclosure logical id(0x%016llx), "
6715 "slot(%d)\n", handle
,
6716 (unsigned long long)sas_device
->sas_address
,
6717 (unsigned long long)
6718 sas_device
->enclosure_logical_id
,
6720 if (sas_device
->handle
== handle
)
6722 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6723 sas_device
->handle
);
6724 sas_device
->handle
= handle
;
6725 if (sas_target_priv_data
)
6726 sas_target_priv_data
->handle
= handle
;
6731 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6735 * _scsih_search_responding_sas_devices -
6736 * @ioc: per adapter object
6738 * After host reset, find out whether devices are still responding.
6744 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6746 Mpi2SasDevicePage0_t sas_device_pg0
;
6747 Mpi2ConfigReply_t mpi_reply
;
6754 printk(MPT2SAS_INFO_FMT
"search for end-devices: start\n", ioc
->name
);
6756 if (list_empty(&ioc
->sas_device_list
))
6760 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6761 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6763 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6764 MPI2_IOCSTATUS_MASK
;
6765 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6767 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6768 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6769 if (!(_scsih_is_end_device(device_info
)))
6771 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6772 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6773 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6777 printk(MPT2SAS_INFO_FMT
"search for end-devices: complete\n",
6782 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6783 * @ioc: per adapter object
6784 * @wwid: world wide identifier for raid volume
6785 * @handle: device handle
6787 * After host reset, find out whether devices are still responding.
6788 * Used in _scsi_remove_unresponsive_raid_devices.
6793 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6796 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6797 struct scsi_target
*starget
;
6798 struct _raid_device
*raid_device
;
6799 unsigned long flags
;
6801 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6802 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6803 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6804 starget
= raid_device
->starget
;
6805 if (starget
&& starget
->hostdata
) {
6806 sas_target_priv_data
= starget
->hostdata
;
6807 sas_target_priv_data
->deleted
= 0;
6809 sas_target_priv_data
= NULL
;
6810 raid_device
->responding
= 1;
6811 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6812 starget_printk(KERN_INFO
, raid_device
->starget
,
6813 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6814 (unsigned long long)raid_device
->wwid
);
6816 * WARPDRIVE: The handles of the PDs might have changed
6817 * across the host reset so re-initialize the
6818 * required data for Direct IO
6820 _scsih_init_warpdrive_properties(ioc
, raid_device
);
6821 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6822 if (raid_device
->handle
== handle
) {
6823 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6827 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6828 raid_device
->handle
);
6829 raid_device
->handle
= handle
;
6830 if (sas_target_priv_data
)
6831 sas_target_priv_data
->handle
= handle
;
6832 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6837 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6841 * _scsih_search_responding_raid_devices -
6842 * @ioc: per adapter object
6844 * After host reset, find out whether devices are still responding.
6850 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6852 Mpi2RaidVolPage1_t volume_pg1
;
6853 Mpi2RaidVolPage0_t volume_pg0
;
6854 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6855 Mpi2ConfigReply_t mpi_reply
;
6860 if (!ioc
->ir_firmware
)
6863 printk(MPT2SAS_INFO_FMT
"search for raid volumes: start\n",
6866 if (list_empty(&ioc
->raid_device_list
))
6870 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6871 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6872 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6873 MPI2_IOCSTATUS_MASK
;
6874 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6876 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6878 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6879 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6880 sizeof(Mpi2RaidVolPage0_t
)))
6883 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6884 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6885 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6886 _scsih_mark_responding_raid_device(ioc
,
6887 le64_to_cpu(volume_pg1
.WWID
), handle
);
6890 /* refresh the pd_handles */
6891 if (!ioc
->is_warpdrive
) {
6892 phys_disk_num
= 0xFF;
6893 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6894 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6895 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6897 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6898 MPI2_IOCSTATUS_MASK
;
6899 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6901 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6902 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6903 set_bit(handle
, ioc
->pd_handles
);
6907 printk(MPT2SAS_INFO_FMT
"search for responding raid volumes: "
6908 "complete\n", ioc
->name
);
6912 * _scsih_mark_responding_expander - mark a expander as responding
6913 * @ioc: per adapter object
6914 * @sas_address: sas address
6917 * After host reset, find out whether devices are still responding.
6918 * Used in _scsi_remove_unresponsive_expanders.
6923 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6926 struct _sas_node
*sas_expander
;
6927 unsigned long flags
;
6930 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6931 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6932 if (sas_expander
->sas_address
!= sas_address
)
6934 sas_expander
->responding
= 1;
6935 if (sas_expander
->handle
== handle
)
6937 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6938 " from(0x%04x) to (0x%04x)!!!\n",
6939 (unsigned long long)sas_expander
->sas_address
,
6940 sas_expander
->handle
, handle
);
6941 sas_expander
->handle
= handle
;
6942 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6943 sas_expander
->phy
[i
].handle
= handle
;
6947 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6951 * _scsih_search_responding_expanders -
6952 * @ioc: per adapter object
6954 * After host reset, find out whether devices are still responding.
6960 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6962 Mpi2ExpanderPage0_t expander_pg0
;
6963 Mpi2ConfigReply_t mpi_reply
;
6968 printk(MPT2SAS_INFO_FMT
"search for expanders: start\n", ioc
->name
);
6970 if (list_empty(&ioc
->sas_expander_list
))
6974 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6975 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6977 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6978 MPI2_IOCSTATUS_MASK
;
6979 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6982 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6983 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6984 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6985 "sas_addr(0x%016llx)\n", handle
,
6986 (unsigned long long)sas_address
);
6987 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6991 printk(MPT2SAS_INFO_FMT
"search for expanders: complete\n", ioc
->name
);
6995 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6996 * @ioc: per adapter object
7001 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
7003 struct _sas_device
*sas_device
, *sas_device_next
;
7004 struct _sas_node
*sas_expander
, *sas_expander_next
;
7005 struct _raid_device
*raid_device
, *raid_device_next
;
7006 struct list_head tmp_list
;
7007 unsigned long flags
;
7009 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: start\n",
7012 /* removing unresponding end devices */
7013 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: end-devices\n",
7015 list_for_each_entry_safe(sas_device
, sas_device_next
,
7016 &ioc
->sas_device_list
, list
) {
7017 if (!sas_device
->responding
)
7018 mpt2sas_device_remove_by_sas_address(ioc
,
7019 sas_device
->sas_address
);
7021 sas_device
->responding
= 0;
7024 /* removing unresponding volumes */
7025 if (ioc
->ir_firmware
) {
7026 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: "
7027 "volumes\n", ioc
->name
);
7028 list_for_each_entry_safe(raid_device
, raid_device_next
,
7029 &ioc
->raid_device_list
, list
) {
7030 if (!raid_device
->responding
)
7031 _scsih_sas_volume_delete(ioc
,
7032 raid_device
->handle
);
7034 raid_device
->responding
= 0;
7037 /* removing unresponding expanders */
7038 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: expanders\n",
7040 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7041 INIT_LIST_HEAD(&tmp_list
);
7042 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7043 &ioc
->sas_expander_list
, list
) {
7044 if (!sas_expander
->responding
)
7045 list_move_tail(&sas_expander
->list
, &tmp_list
);
7047 sas_expander
->responding
= 0;
7049 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7050 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7052 list_del(&sas_expander
->list
);
7053 _scsih_expander_node_remove(ioc
, sas_expander
);
7055 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: complete\n",
7057 /* unblock devices */
7058 _scsih_ublock_io_all_device(ioc
);
7062 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER
*ioc
,
7063 struct _sas_node
*sas_expander
, u16 handle
)
7065 Mpi2ExpanderPage1_t expander_pg1
;
7066 Mpi2ConfigReply_t mpi_reply
;
7069 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7070 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7071 &expander_pg1
, i
, handle
))) {
7072 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7073 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7077 mpt2sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7078 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7079 expander_pg1
.NegotiatedLinkRate
>> 4);
7084 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7085 * @ioc: per adapter object
7090 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER
*ioc
)
7092 Mpi2ExpanderPage0_t expander_pg0
;
7093 Mpi2SasDevicePage0_t sas_device_pg0
;
7094 Mpi2RaidVolPage1_t volume_pg1
;
7095 Mpi2RaidVolPage0_t volume_pg0
;
7096 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7097 Mpi2EventIrConfigElement_t element
;
7098 Mpi2ConfigReply_t mpi_reply
;
7101 u16 handle
, parent_handle
;
7103 struct _sas_device
*sas_device
;
7104 struct _sas_node
*expander_device
;
7105 static struct _raid_device
*raid_device
;
7107 unsigned long flags
;
7109 printk(MPT2SAS_INFO_FMT
"scan devices: start\n", ioc
->name
);
7111 _scsih_sas_host_refresh(ioc
);
7113 printk(MPT2SAS_INFO_FMT
"\tscan devices: expanders start\n",
7117 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7118 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7119 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7120 MPI2_IOCSTATUS_MASK
;
7121 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7122 printk(MPT2SAS_INFO_FMT
"\tbreak from expander scan: "
7123 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7124 ioc
->name
, ioc_status
,
7125 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7128 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7129 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7130 expander_device
= mpt2sas_scsih_expander_find_by_sas_address(
7131 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7132 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7133 if (expander_device
)
7134 _scsih_refresh_expander_links(ioc
, expander_device
,
7137 printk(MPT2SAS_INFO_FMT
"\tBEFORE 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
));
7141 _scsih_expander_add(ioc
, handle
);
7142 printk(MPT2SAS_INFO_FMT
"\tAFTER adding expander: "
7143 "handle (0x%04x), sas_addr(0x%016llx)\n",
7144 ioc
->name
, handle
, (unsigned long long)
7145 le64_to_cpu(expander_pg0
.SASAddress
));
7149 printk(MPT2SAS_INFO_FMT
"\tscan devices: expanders complete\n",
7152 if (!ioc
->ir_firmware
)
7155 printk(MPT2SAS_INFO_FMT
"\tscan devices phys disk start\n", ioc
->name
);
7157 phys_disk_num
= 0xFF;
7158 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7159 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7161 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7162 MPI2_IOCSTATUS_MASK
;
7163 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7164 printk(MPT2SAS_INFO_FMT
"\tbreak from phys disk scan:"
7165 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7166 ioc
->name
, ioc_status
,
7167 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7170 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7171 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7172 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7173 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
7174 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7177 if (mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7178 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7181 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7182 MPI2_IOCSTATUS_MASK
;
7183 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7184 printk(MPT2SAS_INFO_FMT
"\tbreak from phys disk scan "
7185 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7186 ioc
->name
, ioc_status
,
7187 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7190 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7191 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7193 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding phys disk: "
7194 " handle (0x%04x), sas_addr(0x%016llx)\n",
7195 ioc
->name
, handle
, (unsigned long long)
7196 le64_to_cpu(sas_device_pg0
.SASAddress
));
7197 mpt2sas_transport_update_links(ioc
, sas_address
,
7198 handle
, sas_device_pg0
.PhyNum
,
7199 MPI2_SAS_NEG_LINK_RATE_1_5
);
7200 set_bit(handle
, ioc
->pd_handles
);
7202 /* This will retry adding the end device.
7203 * _scsih_add_device() will decide on retries and
7204 * return "1" when it should be retried
7206 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7210 printk(MPT2SAS_INFO_FMT
"\tAFTER adding phys disk: "
7211 " handle (0x%04x), sas_addr(0x%016llx)\n",
7212 ioc
->name
, handle
, (unsigned long long)
7213 le64_to_cpu(sas_device_pg0
.SASAddress
));
7217 printk(MPT2SAS_INFO_FMT
"\tscan devices: phys disk complete\n",
7220 printk(MPT2SAS_INFO_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7223 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7224 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7225 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7226 MPI2_IOCSTATUS_MASK
;
7227 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7228 printk(MPT2SAS_INFO_FMT
"\tbreak from volume scan: "
7229 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7230 ioc
->name
, ioc_status
,
7231 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7234 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7235 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7236 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7237 le64_to_cpu(volume_pg1
.WWID
));
7238 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7241 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7242 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7243 sizeof(Mpi2RaidVolPage0_t
)))
7245 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7246 MPI2_IOCSTATUS_MASK
;
7247 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7248 printk(MPT2SAS_INFO_FMT
"\tbreak from volume scan: "
7249 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7250 ioc
->name
, ioc_status
,
7251 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7254 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7255 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7256 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7257 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7258 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7259 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7260 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding volume: "
7261 " handle (0x%04x)\n", ioc
->name
,
7262 volume_pg1
.DevHandle
);
7263 _scsih_sas_volume_add(ioc
, &element
);
7264 printk(MPT2SAS_INFO_FMT
"\tAFTER adding volume: "
7265 " handle (0x%04x)\n", ioc
->name
,
7266 volume_pg1
.DevHandle
);
7270 printk(MPT2SAS_INFO_FMT
"\tscan devices: volumes complete\n",
7275 printk(MPT2SAS_INFO_FMT
"\tscan devices: end devices start\n",
7279 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7280 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7282 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7283 MPI2_IOCSTATUS_MASK
;
7284 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7285 printk(MPT2SAS_INFO_FMT
"\tbreak from end device scan:"
7286 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7287 ioc
->name
, ioc_status
,
7288 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7291 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7292 if (!(_scsih_is_end_device(
7293 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7295 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7296 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
7297 le64_to_cpu(sas_device_pg0
.SASAddress
));
7298 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7301 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7302 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7303 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding end device: "
7304 "handle (0x%04x), sas_addr(0x%016llx)\n",
7305 ioc
->name
, handle
, (unsigned long long)
7306 le64_to_cpu(sas_device_pg0
.SASAddress
));
7307 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
7308 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7310 /* This will retry adding the end device.
7311 * _scsih_add_device() will decide on retries and
7312 * return "1" when it should be retried
7314 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7318 printk(MPT2SAS_INFO_FMT
"\tAFTER adding end device: "
7319 "handle (0x%04x), sas_addr(0x%016llx)\n",
7320 ioc
->name
, handle
, (unsigned long long)
7321 le64_to_cpu(sas_device_pg0
.SASAddress
));
7325 printk(MPT2SAS_INFO_FMT
"\tscan devices: end devices complete\n",
7328 printk(MPT2SAS_INFO_FMT
"scan devices: complete\n", ioc
->name
);
7333 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7334 * @ioc: per adapter object
7335 * @reset_phase: phase
7337 * The handler for doing any required cleanup or initialization.
7339 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7340 * MPT2_IOC_DONE_RESET
7345 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
7347 switch (reset_phase
) {
7348 case MPT2_IOC_PRE_RESET
:
7349 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7350 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7352 case MPT2_IOC_AFTER_RESET
:
7353 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7354 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7355 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
7356 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
7357 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7358 complete(&ioc
->scsih_cmds
.done
);
7360 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
7361 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
7362 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7363 complete(&ioc
->tm_cmds
.done
);
7365 _scsih_fw_event_cleanup_queue(ioc
);
7366 _scsih_flush_running_cmds(ioc
);
7368 case MPT2_IOC_DONE_RESET
:
7369 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7370 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7371 _scsih_sas_host_refresh(ioc
);
7372 _scsih_prep_device_scan(ioc
);
7373 _scsih_search_responding_sas_devices(ioc
);
7374 _scsih_search_responding_raid_devices(ioc
);
7375 _scsih_search_responding_expanders(ioc
);
7376 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7377 !ioc
->sas_hba
.num_phys
)) {
7378 _scsih_prep_device_scan(ioc
);
7379 _scsih_search_responding_sas_devices(ioc
);
7380 _scsih_search_responding_raid_devices(ioc
);
7381 _scsih_search_responding_expanders(ioc
);
7382 _scsih_error_recovery_delete_devices(ioc
);
7389 * _firmware_event_work - delayed task for processing firmware events
7390 * @ioc: per adapter object
7391 * @work: equal to the fw_event_work object
7397 _firmware_event_work(struct work_struct
*work
)
7399 struct fw_event_work
*fw_event
= container_of(work
,
7400 struct fw_event_work
, delayed_work
.work
);
7401 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
7403 /* the queue is being flushed so ignore this event */
7404 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
7405 ioc
->pci_error_recovery
) {
7406 _scsih_fw_event_free(ioc
, fw_event
);
7410 switch (fw_event
->event
) {
7411 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES
:
7412 while (scsi_host_in_recovery(ioc
->shost
) || ioc
->shost_recovery
)
7414 _scsih_remove_unresponding_sas_devices(ioc
);
7415 _scsih_scan_for_devices_after_reset(ioc
);
7417 case MPT2SAS_PORT_ENABLE_COMPLETE
:
7418 ioc
->start_scan
= 0;
7420 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7421 mpt2sas_base_update_missing_delay(ioc
, missing_delay
[0],
7424 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"port enable: complete "
7425 "from worker thread\n", ioc
->name
));
7427 case MPT2SAS_TURN_ON_FAULT_LED
:
7428 _scsih_turn_on_fault_led(ioc
, fw_event
->device_handle
);
7430 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7431 _scsih_sas_topology_change_event(ioc
, fw_event
);
7433 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7434 _scsih_sas_device_status_change_event(ioc
,
7437 case MPI2_EVENT_SAS_DISCOVERY
:
7438 _scsih_sas_discovery_event(ioc
,
7441 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7442 _scsih_sas_broadcast_primitive_event(ioc
,
7445 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7446 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7449 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7450 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7452 case MPI2_EVENT_IR_VOLUME
:
7453 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7455 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7456 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7458 case MPI2_EVENT_IR_OPERATION_STATUS
:
7459 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7462 _scsih_fw_event_free(ioc
, fw_event
);
7466 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7467 * @ioc: per adapter object
7468 * @msix_index: MSIX table index supplied by the OS
7469 * @reply: reply message frame(lower 32bit addr)
7470 * Context: interrupt.
7472 * This function merely adds a new work task into ioc->firmware_event_thread.
7473 * The tasks are worked from _firmware_event_work in user context.
7478 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
7481 struct fw_event_work
*fw_event
;
7482 Mpi2EventNotificationReply_t
*mpi_reply
;
7486 /* events turned off due to host reset or driver unloading */
7487 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7490 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
7492 if (unlikely(!mpi_reply
)) {
7493 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7494 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7498 event
= le16_to_cpu(mpi_reply
->Event
);
7502 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7504 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7505 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7506 mpi_reply
->EventData
;
7508 if (baen_data
->Primitive
!=
7509 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7512 if (ioc
->broadcast_aen_busy
) {
7513 ioc
->broadcast_aen_pending
++;
7516 ioc
->broadcast_aen_busy
= 1;
7520 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7521 _scsih_check_topo_delete_events(ioc
,
7522 (Mpi2EventDataSasTopologyChangeList_t
*)
7523 mpi_reply
->EventData
);
7525 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7526 _scsih_check_ir_config_unhide_events(ioc
,
7527 (Mpi2EventDataIrConfigChangeList_t
*)
7528 mpi_reply
->EventData
);
7530 case MPI2_EVENT_IR_VOLUME
:
7531 _scsih_check_volume_delete_events(ioc
,
7532 (Mpi2EventDataIrVolume_t
*)
7533 mpi_reply
->EventData
);
7535 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7537 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7540 if (!ioc
->is_warpdrive
)
7543 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7544 mpi_reply
->EventData
;
7545 log_code
= (__le32
*)log_entry
->LogData
;
7547 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7548 != MPT2_WARPDRIVE_LOGENTRY
)
7551 switch (le32_to_cpu(*log_code
)) {
7552 case MPT2_WARPDRIVE_LC_SSDT
:
7553 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7554 "IO Throttling has occurred in the WarpDrive "
7555 "subsystem. Check WarpDrive documentation for "
7556 "additional details.\n", ioc
->name
);
7558 case MPT2_WARPDRIVE_LC_SSDLW
:
7559 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7560 "Program/Erase Cycles for the WarpDrive subsystem "
7561 "in degraded range. Check WarpDrive documentation "
7562 "for additional details.\n", ioc
->name
);
7564 case MPT2_WARPDRIVE_LC_SSDLF
:
7565 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7566 "There are no Program/Erase Cycles for the "
7567 "WarpDrive subsystem. The storage device will be "
7568 "in read-only mode. Check WarpDrive documentation "
7569 "for additional details.\n", ioc
->name
);
7571 case MPT2_WARPDRIVE_LC_BRMF
:
7572 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7573 "The Backup Rail Monitor has failed on the "
7574 "WarpDrive subsystem. Check WarpDrive "
7575 "documentation for additional details.\n",
7582 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7583 case MPI2_EVENT_IR_OPERATION_STATUS
:
7584 case MPI2_EVENT_SAS_DISCOVERY
:
7585 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7586 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7589 default: /* ignore the rest */
7593 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
7595 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7596 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7599 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7600 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
7601 if (!fw_event
->event_data
) {
7602 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7603 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7608 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
7610 fw_event
->ioc
= ioc
;
7611 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7612 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7613 fw_event
->event
= event
;
7614 _scsih_fw_event_add(ioc
, fw_event
);
7618 /* shost template */
7619 static struct scsi_host_template scsih_driver_template
= {
7620 .module
= THIS_MODULE
,
7621 .name
= "Fusion MPT SAS Host",
7622 .proc_name
= MPT2SAS_DRIVER_NAME
,
7623 .queuecommand
= _scsih_qcmd
,
7624 .target_alloc
= _scsih_target_alloc
,
7625 .slave_alloc
= _scsih_slave_alloc
,
7626 .slave_configure
= _scsih_slave_configure
,
7627 .target_destroy
= _scsih_target_destroy
,
7628 .slave_destroy
= _scsih_slave_destroy
,
7629 .scan_finished
= _scsih_scan_finished
,
7630 .scan_start
= _scsih_scan_start
,
7631 .change_queue_depth
= _scsih_change_queue_depth
,
7632 .change_queue_type
= _scsih_change_queue_type
,
7633 .eh_abort_handler
= _scsih_abort
,
7634 .eh_device_reset_handler
= _scsih_dev_reset
,
7635 .eh_target_reset_handler
= _scsih_target_reset
,
7636 .eh_host_reset_handler
= _scsih_host_reset
,
7637 .bios_param
= _scsih_bios_param
,
7640 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
7641 .max_sectors
= 32767,
7643 .use_clustering
= ENABLE_CLUSTERING
,
7644 .shost_attrs
= mpt2sas_host_attrs
,
7645 .sdev_attrs
= mpt2sas_dev_attrs
,
7649 * _scsih_expander_node_remove - removing expander device from list.
7650 * @ioc: per adapter object
7651 * @sas_expander: the sas_device object
7652 * Context: Calling function should acquire ioc->sas_node_lock.
7654 * Removing object and freeing associated memory from the
7655 * ioc->sas_expander_list.
7660 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
7661 struct _sas_node
*sas_expander
)
7663 struct _sas_port
*mpt2sas_port
, *next
;
7665 /* remove sibling ports attached to this expander */
7666 list_for_each_entry_safe(mpt2sas_port
, next
,
7667 &sas_expander
->sas_port_list
, port_list
) {
7668 if (ioc
->shost_recovery
)
7670 if (mpt2sas_port
->remote_identify
.device_type
==
7672 mpt2sas_device_remove_by_sas_address(ioc
,
7673 mpt2sas_port
->remote_identify
.sas_address
);
7674 else if (mpt2sas_port
->remote_identify
.device_type
==
7675 SAS_EDGE_EXPANDER_DEVICE
||
7676 mpt2sas_port
->remote_identify
.device_type
==
7677 SAS_FANOUT_EXPANDER_DEVICE
)
7678 mpt2sas_expander_remove(ioc
,
7679 mpt2sas_port
->remote_identify
.sas_address
);
7682 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7683 sas_expander
->sas_address_parent
);
7685 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
7686 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7687 sas_expander
->handle
, (unsigned long long)
7688 sas_expander
->sas_address
);
7690 kfree(sas_expander
->phy
);
7691 kfree(sas_expander
);
7695 * _scsih_ir_shutdown - IR shutdown notification
7696 * @ioc: per adapter object
7698 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7699 * the host system is shutting down.
7704 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
7706 Mpi2RaidActionRequest_t
*mpi_request
;
7707 Mpi2RaidActionReply_t
*mpi_reply
;
7710 /* is IR firmware build loaded ? */
7711 if (!ioc
->ir_firmware
)
7714 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7716 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
7717 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
7718 ioc
->name
, __func__
);
7721 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
7723 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7725 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
7726 ioc
->name
, __func__
);
7727 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7731 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
7732 ioc
->scsih_cmds
.smid
= smid
;
7733 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7735 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7736 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7738 if (!ioc
->hide_ir_msg
)
7739 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
7740 init_completion(&ioc
->scsih_cmds
.done
);
7741 mpt2sas_base_put_smid_default(ioc
, smid
);
7742 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7744 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
7745 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
7746 ioc
->name
, __func__
);
7750 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
7751 mpi_reply
= ioc
->scsih_cmds
.reply
;
7753 if (!ioc
->hide_ir_msg
)
7754 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
7755 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7756 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7757 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7761 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7762 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7766 * _scsih_shutdown - routine call during system shutdown
7767 * @pdev: PCI device struct
7772 _scsih_shutdown(struct pci_dev
*pdev
)
7774 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7775 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7776 struct workqueue_struct
*wq
;
7777 unsigned long flags
;
7779 ioc
->remove_host
= 1;
7780 _scsih_fw_event_cleanup_queue(ioc
);
7782 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7783 wq
= ioc
->firmware_event_thread
;
7784 ioc
->firmware_event_thread
= NULL
;
7785 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7787 destroy_workqueue(wq
);
7789 _scsih_ir_shutdown(ioc
);
7790 mpt2sas_base_detach(ioc
);
7794 * _scsih_remove - detach and remove add host
7795 * @pdev: PCI device struct
7797 * Routine called when unloading the driver.
7801 _scsih_remove(struct pci_dev
*pdev
)
7803 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7804 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7805 struct _sas_port
*mpt2sas_port
, *next_port
;
7806 struct _raid_device
*raid_device
, *next
;
7807 struct MPT2SAS_TARGET
*sas_target_priv_data
;
7808 struct workqueue_struct
*wq
;
7809 unsigned long flags
;
7811 ioc
->remove_host
= 1;
7812 _scsih_fw_event_cleanup_queue(ioc
);
7814 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7815 wq
= ioc
->firmware_event_thread
;
7816 ioc
->firmware_event_thread
= NULL
;
7817 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7819 destroy_workqueue(wq
);
7821 /* release all the volumes */
7822 _scsih_ir_shutdown(ioc
);
7823 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7825 if (raid_device
->starget
) {
7826 sas_target_priv_data
=
7827 raid_device
->starget
->hostdata
;
7828 sas_target_priv_data
->deleted
= 1;
7829 scsi_remove_target(&raid_device
->starget
->dev
);
7831 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
7832 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
7833 (unsigned long long) raid_device
->wwid
);
7834 _scsih_raid_device_remove(ioc
, raid_device
);
7837 /* free ports attached to the sas_host */
7838 list_for_each_entry_safe(mpt2sas_port
, next_port
,
7839 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7840 if (mpt2sas_port
->remote_identify
.device_type
==
7842 mpt2sas_device_remove_by_sas_address(ioc
,
7843 mpt2sas_port
->remote_identify
.sas_address
);
7844 else if (mpt2sas_port
->remote_identify
.device_type
==
7845 SAS_EDGE_EXPANDER_DEVICE
||
7846 mpt2sas_port
->remote_identify
.device_type
==
7847 SAS_FANOUT_EXPANDER_DEVICE
)
7848 mpt2sas_expander_remove(ioc
,
7849 mpt2sas_port
->remote_identify
.sas_address
);
7852 /* free phys attached to the sas_host */
7853 if (ioc
->sas_hba
.num_phys
) {
7854 kfree(ioc
->sas_hba
.phy
);
7855 ioc
->sas_hba
.phy
= NULL
;
7856 ioc
->sas_hba
.num_phys
= 0;
7859 sas_remove_host(shost
);
7860 mpt2sas_base_detach(ioc
);
7861 list_del(&ioc
->list
);
7862 scsi_remove_host(shost
);
7863 scsi_host_put(shost
);
7867 * _scsih_probe_boot_devices - reports 1st device
7868 * @ioc: per adapter object
7870 * If specified in bios page 2, this routine reports the 1st
7871 * device scsi-ml or sas transport for persistent boot device
7872 * purposes. Please refer to function _scsih_determine_boot_device()
7875 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
7879 struct _sas_device
*sas_device
;
7880 struct _raid_device
*raid_device
;
7882 u64 sas_address_parent
;
7884 unsigned long flags
;
7887 /* no Bios, return immediately */
7888 if (!ioc
->bios_pg3
.BiosVersion
)
7893 if (ioc
->req_boot_device
.device
) {
7894 device
= ioc
->req_boot_device
.device
;
7895 is_raid
= ioc
->req_boot_device
.is_raid
;
7896 } else if (ioc
->req_alt_boot_device
.device
) {
7897 device
= ioc
->req_alt_boot_device
.device
;
7898 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7899 } else if (ioc
->current_boot_device
.device
) {
7900 device
= ioc
->current_boot_device
.device
;
7901 is_raid
= ioc
->current_boot_device
.is_raid
;
7908 raid_device
= device
;
7909 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7910 raid_device
->id
, 0);
7912 _scsih_raid_device_remove(ioc
, raid_device
);
7914 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7915 sas_device
= device
;
7916 handle
= sas_device
->handle
;
7917 sas_address_parent
= sas_device
->sas_address_parent
;
7918 sas_address
= sas_device
->sas_address
;
7919 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7920 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7922 if (ioc
->hide_drives
)
7924 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7925 sas_device
->sas_address_parent
)) {
7926 _scsih_sas_device_remove(ioc
, sas_device
);
7927 } else if (!sas_device
->starget
) {
7928 if (!ioc
->is_driver_loading
) {
7929 mpt2sas_transport_port_remove(ioc
,
7931 sas_address_parent
);
7932 _scsih_sas_device_remove(ioc
, sas_device
);
7939 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7940 * @ioc: per adapter object
7942 * Called during initial loading of the driver.
7945 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
7947 struct _raid_device
*raid_device
, *raid_next
;
7950 list_for_each_entry_safe(raid_device
, raid_next
,
7951 &ioc
->raid_device_list
, list
) {
7952 if (raid_device
->starget
)
7954 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7955 raid_device
->id
, 0);
7957 _scsih_raid_device_remove(ioc
, raid_device
);
7962 * _scsih_probe_sas - reporting sas devices to sas transport
7963 * @ioc: per adapter object
7965 * Called during initial loading of the driver.
7968 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
7970 struct _sas_device
*sas_device
, *next
;
7971 unsigned long flags
;
7973 /* SAS Device List */
7974 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7977 if (ioc
->hide_drives
)
7980 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7981 sas_device
->sas_address_parent
)) {
7982 list_del(&sas_device
->list
);
7985 } else if (!sas_device
->starget
) {
7986 if (!ioc
->is_driver_loading
) {
7987 mpt2sas_transport_port_remove(ioc
,
7988 sas_device
->sas_address
,
7989 sas_device
->sas_address_parent
);
7990 list_del(&sas_device
->list
);
7995 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7996 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7997 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8002 * _scsih_probe_devices - probing for devices
8003 * @ioc: per adapter object
8005 * Called during initial loading of the driver.
8008 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
8010 u16 volume_mapping_flags
;
8012 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8013 return; /* return when IOC doesn't support initiator mode */
8015 _scsih_probe_boot_devices(ioc
);
8017 if (ioc
->ir_firmware
) {
8018 volume_mapping_flags
=
8019 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8020 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8021 if (volume_mapping_flags
==
8022 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8023 _scsih_probe_raid(ioc
);
8024 _scsih_probe_sas(ioc
);
8026 _scsih_probe_sas(ioc
);
8027 _scsih_probe_raid(ioc
);
8030 _scsih_probe_sas(ioc
);
8035 * _scsih_scan_start - scsi lld callback for .scan_start
8036 * @shost: SCSI host pointer
8038 * The shost has the ability to discover targets on its own instead
8039 * of scanning the entire bus. In our implemention, we will kick off
8040 * firmware discovery.
8043 _scsih_scan_start(struct Scsi_Host
*shost
)
8045 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8048 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8049 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8051 if (disable_discovery
> 0)
8054 ioc
->start_scan
= 1;
8055 rc
= mpt2sas_port_enable(ioc
);
8058 printk(MPT2SAS_INFO_FMT
"port enable: FAILED\n", ioc
->name
);
8062 * _scsih_scan_finished - scsi lld callback for .scan_finished
8063 * @shost: SCSI host pointer
8064 * @time: elapsed time of the scan in jiffies
8066 * This function will be called periodically until it returns 1 with the
8067 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8068 * we wait for firmware discovery to complete, then return 1.
8071 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8073 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8075 if (disable_discovery
> 0) {
8076 ioc
->is_driver_loading
= 0;
8077 ioc
->wait_for_discovery_to_complete
= 0;
8081 if (time
>= (300 * HZ
)) {
8082 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
8083 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with timeout "
8084 "(timeout=300s)\n", ioc
->name
);
8085 ioc
->is_driver_loading
= 0;
8089 if (ioc
->start_scan
)
8092 if (ioc
->start_scan_failed
) {
8093 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with "
8094 "(ioc_status=0x%08x)\n", ioc
->name
, ioc
->start_scan_failed
);
8095 ioc
->is_driver_loading
= 0;
8096 ioc
->wait_for_discovery_to_complete
= 0;
8097 ioc
->remove_host
= 1;
8101 printk(MPT2SAS_INFO_FMT
"port enable: SUCCESS\n", ioc
->name
);
8102 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
8104 if (ioc
->wait_for_discovery_to_complete
) {
8105 ioc
->wait_for_discovery_to_complete
= 0;
8106 _scsih_probe_devices(ioc
);
8108 mpt2sas_base_start_watchdog(ioc
);
8109 ioc
->is_driver_loading
= 0;
8115 * _scsih_probe - attach and add scsi host
8116 * @pdev: PCI device struct
8117 * @id: pci device id
8119 * Returns 0 success, anything else error.
8122 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8124 struct MPT2SAS_ADAPTER
*ioc
;
8125 struct Scsi_Host
*shost
;
8127 shost
= scsi_host_alloc(&scsih_driver_template
,
8128 sizeof(struct MPT2SAS_ADAPTER
));
8132 /* init local params */
8133 ioc
= shost_priv(shost
);
8134 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
8135 INIT_LIST_HEAD(&ioc
->list
);
8136 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
8138 ioc
->id
= mpt_ids
++;
8139 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
8141 if (id
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8142 ioc
->is_warpdrive
= 1;
8143 ioc
->hide_ir_msg
= 1;
8145 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8146 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8147 ioc
->tm_cb_idx
= tm_cb_idx
;
8148 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8149 ioc
->base_cb_idx
= base_cb_idx
;
8150 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8151 ioc
->transport_cb_idx
= transport_cb_idx
;
8152 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8153 ioc
->config_cb_idx
= config_cb_idx
;
8154 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8155 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8156 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8157 ioc
->logging_level
= logging_level
;
8158 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8159 /* misc semaphores and spin locks */
8160 mutex_init(&ioc
->reset_in_progress_mutex
);
8161 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8162 spin_lock_init(&ioc
->scsi_lookup_lock
);
8163 spin_lock_init(&ioc
->sas_device_lock
);
8164 spin_lock_init(&ioc
->sas_node_lock
);
8165 spin_lock_init(&ioc
->fw_event_lock
);
8166 spin_lock_init(&ioc
->raid_device_lock
);
8168 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8169 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8170 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8171 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8172 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8173 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8174 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8175 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8176 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8178 /* init shost parameters */
8179 shost
->max_cmd_len
= 32;
8180 shost
->max_lun
= max_lun
;
8181 shost
->transportt
= mpt2sas_transport_template
;
8182 shost
->unique_id
= ioc
->id
;
8184 if (max_sectors
!= 0xFFFF) {
8185 if (max_sectors
< 64) {
8186 shost
->max_sectors
= 64;
8187 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8188 "for max_sectors, range is 64 to 32767. Assigning "
8189 "value of 64.\n", ioc
->name
, max_sectors
);
8190 } else if (max_sectors
> 32767) {
8191 shost
->max_sectors
= 32767;
8192 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8193 "for max_sectors, range is 64 to 8192. Assigning "
8194 "default value of 32767.\n", ioc
->name
,
8197 shost
->max_sectors
= max_sectors
& 0xFFFE;
8198 printk(MPT2SAS_INFO_FMT
"The max_sectors value is "
8199 "set to %d\n", ioc
->name
, shost
->max_sectors
);
8203 if ((scsi_add_host(shost
, &pdev
->dev
))) {
8204 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8205 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8206 list_del(&ioc
->list
);
8207 goto out_add_shost_fail
;
8210 /* register EEDP capabilities with SCSI layer */
8212 scsi_host_set_prot(shost
, prot_mask
);
8214 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8215 | SHOST_DIF_TYPE2_PROTECTION
8216 | SHOST_DIF_TYPE3_PROTECTION
);
8218 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8221 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8222 "fw_event%d", ioc
->id
);
8223 ioc
->firmware_event_thread
= create_singlethread_workqueue(
8224 ioc
->firmware_event_name
);
8225 if (!ioc
->firmware_event_thread
) {
8226 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8227 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8228 goto out_thread_fail
;
8231 ioc
->is_driver_loading
= 1;
8232 if ((mpt2sas_base_attach(ioc
))) {
8233 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8234 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8235 goto out_attach_fail
;
8238 if (ioc
->is_warpdrive
) {
8239 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8240 ioc
->hide_drives
= 0;
8241 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8242 ioc
->hide_drives
= 1;
8244 if (_scsih_get_num_volumes(ioc
))
8245 ioc
->hide_drives
= 1;
8247 ioc
->hide_drives
= 0;
8250 ioc
->hide_drives
= 0;
8251 scsi_scan_host(shost
);
8256 destroy_workqueue(ioc
->firmware_event_thread
);
8258 list_del(&ioc
->list
);
8259 scsi_remove_host(shost
);
8261 scsi_host_put(shost
);
8267 * _scsih_suspend - power management suspend main entry point
8268 * @pdev: PCI device struct
8269 * @state: PM state change to (usually PCI_D3)
8271 * Returns 0 success, anything else error.
8274 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8276 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8277 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8278 pci_power_t device_state
;
8280 mpt2sas_base_stop_watchdog(ioc
);
8281 scsi_block_requests(shost
);
8282 _scsih_ir_shutdown(ioc
);
8283 device_state
= pci_choose_state(pdev
, state
);
8284 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
8285 "operating state [D%d]\n", ioc
->name
, pdev
,
8286 pci_name(pdev
), device_state
);
8288 mpt2sas_base_free_resources(ioc
);
8289 pci_save_state(pdev
);
8290 pci_set_power_state(pdev
, device_state
);
8295 * _scsih_resume - power management resume main entry point
8296 * @pdev: PCI device struct
8298 * Returns 0 success, anything else error.
8301 _scsih_resume(struct pci_dev
*pdev
)
8303 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8304 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8305 pci_power_t device_state
= pdev
->current_state
;
8308 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
8309 "operating state [D%d]\n", ioc
->name
, pdev
,
8310 pci_name(pdev
), device_state
);
8312 pci_set_power_state(pdev
, PCI_D0
);
8313 pci_enable_wake(pdev
, PCI_D0
, 0);
8314 pci_restore_state(pdev
);
8316 r
= mpt2sas_base_map_resources(ioc
);
8320 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8321 scsi_unblock_requests(shost
);
8322 mpt2sas_base_start_watchdog(ioc
);
8325 #endif /* CONFIG_PM */
8328 * _scsih_pci_error_detected - Called when a PCI error is detected.
8329 * @pdev: PCI device struct
8330 * @state: PCI channel state
8332 * Description: Called when a PCI error is detected.
8335 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8337 static pci_ers_result_t
8338 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8340 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8341 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8343 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
8347 case pci_channel_io_normal
:
8348 return PCI_ERS_RESULT_CAN_RECOVER
;
8349 case pci_channel_io_frozen
:
8350 /* Fatal error, prepare for slot reset */
8351 ioc
->pci_error_recovery
= 1;
8352 scsi_block_requests(ioc
->shost
);
8353 mpt2sas_base_stop_watchdog(ioc
);
8354 mpt2sas_base_free_resources(ioc
);
8355 return PCI_ERS_RESULT_NEED_RESET
;
8356 case pci_channel_io_perm_failure
:
8357 /* Permanent error, prepare for device removal */
8358 ioc
->pci_error_recovery
= 1;
8359 mpt2sas_base_stop_watchdog(ioc
);
8360 _scsih_flush_running_cmds(ioc
);
8361 return PCI_ERS_RESULT_DISCONNECT
;
8363 return PCI_ERS_RESULT_NEED_RESET
;
8367 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8368 * @pdev: PCI device struct
8370 * Description: This routine is called by the pci error recovery
8371 * code after the PCI slot has been reset, just before we
8372 * should resume normal operations.
8374 static pci_ers_result_t
8375 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
8377 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8378 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8381 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
8384 ioc
->pci_error_recovery
= 0;
8386 pci_restore_state(pdev
);
8387 rc
= mpt2sas_base_map_resources(ioc
);
8389 return PCI_ERS_RESULT_DISCONNECT
;
8392 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8395 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
8396 (rc
== 0) ? "success" : "failed");
8399 return PCI_ERS_RESULT_RECOVERED
;
8401 return PCI_ERS_RESULT_DISCONNECT
;
8405 * _scsih_pci_resume() - resume normal ops after PCI reset
8406 * @pdev: pointer to PCI device
8408 * Called when the error recovery driver tells us that its
8409 * OK to resume normal operation. Use completion to allow
8410 * halted scsi ops to resume.
8413 _scsih_pci_resume(struct pci_dev
*pdev
)
8415 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8416 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8418 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8420 pci_cleanup_aer_uncorrect_error_status(pdev
);
8421 mpt2sas_base_start_watchdog(ioc
);
8422 scsi_unblock_requests(ioc
->shost
);
8426 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8427 * @pdev: pointer to PCI device
8429 static pci_ers_result_t
8430 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8432 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8433 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8435 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
8438 /* TODO - dump whatever for debugging purposes */
8440 /* Request a slot reset. */
8441 return PCI_ERS_RESULT_NEED_RESET
;
8444 static const struct pci_error_handlers _scsih_err_handler
= {
8445 .error_detected
= _scsih_pci_error_detected
,
8446 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8447 .slot_reset
= _scsih_pci_slot_reset
,
8448 .resume
= _scsih_pci_resume
,
8451 static struct pci_driver scsih_driver
= {
8452 .name
= MPT2SAS_DRIVER_NAME
,
8453 .id_table
= scsih_pci_table
,
8454 .probe
= _scsih_probe
,
8455 .remove
= _scsih_remove
,
8456 .shutdown
= _scsih_shutdown
,
8457 .err_handler
= &_scsih_err_handler
,
8459 .suspend
= _scsih_suspend
,
8460 .resume
= _scsih_resume
,
8464 /* raid transport support */
8465 static struct raid_function_template mpt2sas_raid_functions
= {
8466 .cookie
= &scsih_driver_template
,
8467 .is_raid
= _scsih_is_raid
,
8468 .get_resync
= _scsih_get_resync
,
8469 .get_state
= _scsih_get_state
,
8473 * _scsih_init - main entry point for this driver.
8475 * Returns 0 success, anything else error.
8483 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
8484 MPT2SAS_DRIVER_VERSION
);
8486 mpt2sas_transport_template
=
8487 sas_attach_transport(&mpt2sas_transport_functions
);
8488 if (!mpt2sas_transport_template
)
8490 /* raid transport support */
8491 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
8492 if (!mpt2sas_raid_template
) {
8493 sas_release_transport(mpt2sas_transport_template
);
8497 mpt2sas_base_initialize_callback_handler();
8499 /* queuecommand callback hander */
8500 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
8502 /* task management callback handler */
8503 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
8505 /* base internal commands callback handler */
8506 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
8507 port_enable_cb_idx
= mpt2sas_base_register_callback_handler(
8508 mpt2sas_port_enable_done
);
8510 /* transport internal commands callback handler */
8511 transport_cb_idx
= mpt2sas_base_register_callback_handler(
8512 mpt2sas_transport_done
);
8514 /* scsih internal commands callback handler */
8515 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
8517 /* configuration page API internal commands callback handler */
8518 config_cb_idx
= mpt2sas_base_register_callback_handler(
8519 mpt2sas_config_done
);
8521 /* ctl module callback handler */
8522 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
8524 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
8525 _scsih_tm_tr_complete
);
8527 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
8528 _scsih_tm_volume_tr_complete
);
8530 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
8531 _scsih_sas_control_complete
);
8535 error
= pci_register_driver(&scsih_driver
);
8537 /* raid transport support */
8538 raid_class_release(mpt2sas_raid_template
);
8539 sas_release_transport(mpt2sas_transport_template
);
8546 * _scsih_exit - exit point for this driver (when it is a module).
8548 * Returns 0 success, anything else error.
8553 printk(KERN_INFO
"mpt2sas version %s unloading\n",
8554 MPT2SAS_DRIVER_VERSION
);
8556 pci_unregister_driver(&scsih_driver
);
8560 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
8561 mpt2sas_base_release_callback_handler(tm_cb_idx
);
8562 mpt2sas_base_release_callback_handler(base_cb_idx
);
8563 mpt2sas_base_release_callback_handler(port_enable_cb_idx
);
8564 mpt2sas_base_release_callback_handler(transport_cb_idx
);
8565 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
8566 mpt2sas_base_release_callback_handler(config_cb_idx
);
8567 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
8569 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
8570 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8571 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8573 /* raid transport support */
8574 raid_class_release(mpt2sas_raid_template
);
8575 sas_release_transport(mpt2sas_transport_template
);
8579 module_init(_scsih_init
);
8580 module_exit(_scsih_exit
);