2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2014 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include <asm/unaligned.h>
60 #include "mpt2sas_base.h"
62 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
63 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
64 MODULE_LICENSE("GPL");
65 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
67 #define RAID_CHANNEL 1
70 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
71 struct _sas_node
*sas_expander
);
72 static void _firmware_event_work(struct work_struct
*work
);
74 static u8
_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
);
76 static void _scsih_scan_start(struct Scsi_Host
*shost
);
77 static int _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
);
79 /* global parameters */
80 LIST_HEAD(mpt2sas_ioc_list
);
82 /* local parameters */
83 static u8 scsi_io_cb_idx
= -1;
84 static u8 tm_cb_idx
= -1;
85 static u8 ctl_cb_idx
= -1;
86 static u8 base_cb_idx
= -1;
87 static u8 port_enable_cb_idx
= -1;
88 static u8 transport_cb_idx
= -1;
89 static u8 scsih_cb_idx
= -1;
90 static u8 config_cb_idx
= -1;
93 static u8 tm_tr_cb_idx
= -1 ;
94 static u8 tm_tr_volume_cb_idx
= -1 ;
95 static u8 tm_sas_control_cb_idx
= -1;
97 /* command line options */
98 static u32 logging_level
;
99 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
102 static ushort max_sectors
= 0xFFFF;
103 module_param(max_sectors
, ushort
, 0);
104 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
106 static int missing_delay
[2] = {-1, -1};
107 module_param_array(missing_delay
, int, NULL
, 0);
108 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
110 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
111 #define MPT2SAS_MAX_LUN (16895)
112 static int max_lun
= MPT2SAS_MAX_LUN
;
113 module_param(max_lun
, int, 0);
114 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
116 /* diag_buffer_enable is bitwise
118 * bit 1 set = SNAPSHOT
119 * bit 2 set = EXTENDED
121 * Either bit can be set, or both
123 static int diag_buffer_enable
= -1;
124 module_param(diag_buffer_enable
, int, 0);
125 MODULE_PARM_DESC(diag_buffer_enable
, " post diag buffers "
126 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
128 static int disable_discovery
= -1;
129 module_param(disable_discovery
, int, 0);
130 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
132 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
133 static int prot_mask
= 0;
134 module_param(prot_mask
, int, 0);
135 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
138 * struct sense_info - common structure for obtaining sense keys
140 * @asc: additional sense code
141 * @ascq: additional sense code qualifier
150 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
151 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
152 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
154 * struct fw_event_work - firmware event struct
155 * @list: link list framework
156 * @work: work object (ioc->fault_reset_work_q)
157 * @cancel_pending_work: flag set during reset handling
158 * @ioc: per adapter object
159 * @device_handle: device handle
160 * @VF_ID: virtual function id
161 * @VP_ID: virtual port id
162 * @ignore: flag meaning this event has been marked to ignore
163 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
164 * @event_data: reply event data payload follows
166 * This object stored on ioc->fw_event_list.
168 struct fw_event_work
{
169 struct list_head list
;
170 u8 cancel_pending_work
;
171 struct delayed_work delayed_work
;
172 struct MPT2SAS_ADAPTER
*ioc
;
178 char event_data
[0] __aligned(4);
181 /* raid transport support */
182 static struct raid_template
*mpt2sas_raid_template
;
185 * struct _scsi_io_transfer - scsi io transfer
186 * @handle: sas device handle (assigned by firmware)
187 * @is_raid: flag set for hidden raid components
188 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
189 * @data_length: data transfer length
190 * @data_dma: dma pointer to data
193 * @cdb_length: cdb length
195 * @timeout: timeout for this command
196 * @VF_ID: virtual function id
197 * @VP_ID: virtual port id
198 * @valid_reply: flag set for reply message
199 * @sense_length: sense length
200 * @ioc_status: ioc status
201 * @scsi_state: scsi state
202 * @scsi_status: scsi staus
203 * @log_info: log information
204 * @transfer_length: data length transfer when there is a reply message
206 * Used for sending internal scsi commands to devices within this module.
207 * Refer to _scsi_send_scsi_io().
209 struct _scsi_io_transfer
{
212 enum dma_data_direction dir
;
215 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
223 /* the following bits are only valid when 'valid_reply = 1' */
233 * The pci device ids are defined in mpi/mpi2_cnfg.h.
235 static struct pci_device_id scsih_pci_table
[] = {
236 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
237 PCI_ANY_ID
, PCI_ANY_ID
},
239 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
240 PCI_ANY_ID
, PCI_ANY_ID
},
241 /* Liberator ~ 2108 */
242 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
243 PCI_ANY_ID
, PCI_ANY_ID
},
244 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
245 PCI_ANY_ID
, PCI_ANY_ID
},
246 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
247 PCI_ANY_ID
, PCI_ANY_ID
},
249 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
250 PCI_ANY_ID
, PCI_ANY_ID
},
251 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
252 PCI_ANY_ID
, PCI_ANY_ID
},
253 /* Thunderbolt ~ 2208 */
254 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
255 PCI_ANY_ID
, PCI_ANY_ID
},
256 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
257 PCI_ANY_ID
, PCI_ANY_ID
},
258 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
259 PCI_ANY_ID
, PCI_ANY_ID
},
260 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
261 PCI_ANY_ID
, PCI_ANY_ID
},
262 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
263 PCI_ANY_ID
, PCI_ANY_ID
},
264 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
265 PCI_ANY_ID
, PCI_ANY_ID
},
267 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
268 PCI_ANY_ID
, PCI_ANY_ID
},
269 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
270 PCI_ANY_ID
, PCI_ANY_ID
},
271 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
272 PCI_ANY_ID
, PCI_ANY_ID
},
274 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
275 PCI_ANY_ID
, PCI_ANY_ID
},
276 {0} /* Terminating entry */
278 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
281 * _scsih_set_debug_level - global setting of ioc->logging_level.
283 * Note: The logging levels are defined in mpt2sas_debug.h.
286 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
288 int ret
= param_set_int(val
, kp
);
289 struct MPT2SAS_ADAPTER
*ioc
;
294 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
295 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
296 ioc
->logging_level
= logging_level
;
299 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
300 &logging_level
, 0644);
303 * _scsih_srch_boot_sas_address - search based on sas_address
304 * @sas_address: sas address
305 * @boot_device: boot device object from bios page 2
307 * Returns 1 when there's a match, 0 means no match.
310 _scsih_srch_boot_sas_address(u64 sas_address
,
311 Mpi2BootDeviceSasWwid_t
*boot_device
)
313 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
317 * _scsih_srch_boot_device_name - search based on device name
318 * @device_name: device name specified in INDENTIFY fram
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_device_name(u64 device_name
,
325 Mpi2BootDeviceDeviceName_t
*boot_device
)
327 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
331 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
332 * @enclosure_logical_id: enclosure logical id
333 * @slot_number: slot number
334 * @boot_device: boot device object from bios page 2
336 * Returns 1 when there's a match, 0 means no match.
339 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
340 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
342 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
343 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
344 SlotNumber
)) ? 1 : 0;
348 * _scsih_is_boot_device - search for matching boot device.
349 * @sas_address: sas address
350 * @device_name: device name specified in INDENTIFY fram
351 * @enclosure_logical_id: enclosure logical id
352 * @slot_number: slot number
353 * @form: specifies boot device form
354 * @boot_device: boot device object from bios page 2
356 * Returns 1 when there's a match, 0 means no match.
359 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
360 u64 enclosure_logical_id
, u16 slot
, u8 form
,
361 Mpi2BiosPage2BootDevice_t
*boot_device
)
366 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
369 rc
= _scsih_srch_boot_sas_address(
370 sas_address
, &boot_device
->SasWwid
);
372 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
373 if (!enclosure_logical_id
)
375 rc
= _scsih_srch_boot_encl_slot(
376 enclosure_logical_id
,
377 slot
, &boot_device
->EnclosureSlot
);
379 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
382 rc
= _scsih_srch_boot_device_name(
383 device_name
, &boot_device
->DeviceName
);
385 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
393 * _scsih_get_sas_address - set the sas_address for given device handle
394 * @handle: device handle
395 * @sas_address: sas address
397 * Returns 0 success, non-zero when failure
400 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
403 Mpi2SasDevicePage0_t sas_device_pg0
;
404 Mpi2ConfigReply_t mpi_reply
;
408 if (handle
<= ioc
->sas_hba
.num_phys
) {
409 *sas_address
= ioc
->sas_hba
.sas_address
;
413 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
414 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
415 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
416 __FILE__
, __LINE__
, __func__
);
420 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
421 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
422 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
426 /* we hit this becuase the given parent handle doesn't exist */
427 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
429 /* else error case */
430 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x), "
431 "failure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
432 __FILE__
, __LINE__
, __func__
);
437 * _scsih_determine_boot_device - determine boot device.
438 * @ioc: per adapter object
439 * @device: either sas_device or raid_device object
440 * @is_raid: [flag] 1 = raid object, 0 = sas object
442 * Determines whether this device should be first reported device to
443 * to scsi-ml or sas transport, this purpose is for persistent boot device.
444 * There are primary, alternate, and current entries in bios page 2. The order
445 * priority is primary, alternate, then current. This routine saves
446 * the corresponding device object and is_raid flag in the ioc object.
447 * The saved data to be used later in _scsih_probe_boot_devices().
450 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
451 void *device
, u8 is_raid
)
453 struct _sas_device
*sas_device
;
454 struct _raid_device
*raid_device
;
457 u64 enclosure_logical_id
;
460 /* only process this function when driver loads */
461 if (!ioc
->is_driver_loading
)
464 /* no Bios, return immediately */
465 if (!ioc
->bios_pg3
.BiosVersion
)
470 sas_address
= sas_device
->sas_address
;
471 device_name
= sas_device
->device_name
;
472 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
473 slot
= sas_device
->slot
;
475 raid_device
= device
;
476 sas_address
= raid_device
->wwid
;
478 enclosure_logical_id
= 0;
482 if (!ioc
->req_boot_device
.device
) {
483 if (_scsih_is_boot_device(sas_address
, device_name
,
484 enclosure_logical_id
, slot
,
485 (ioc
->bios_pg2
.ReqBootDeviceForm
&
486 MPI2_BIOSPAGE2_FORM_MASK
),
487 &ioc
->bios_pg2
.RequestedBootDevice
)) {
488 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
489 "%s: req_boot_device(0x%016llx)\n",
491 (unsigned long long)sas_address
));
492 ioc
->req_boot_device
.device
= device
;
493 ioc
->req_boot_device
.is_raid
= is_raid
;
497 if (!ioc
->req_alt_boot_device
.device
) {
498 if (_scsih_is_boot_device(sas_address
, device_name
,
499 enclosure_logical_id
, slot
,
500 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
501 MPI2_BIOSPAGE2_FORM_MASK
),
502 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
503 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
504 "%s: req_alt_boot_device(0x%016llx)\n",
506 (unsigned long long)sas_address
));
507 ioc
->req_alt_boot_device
.device
= device
;
508 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
512 if (!ioc
->current_boot_device
.device
) {
513 if (_scsih_is_boot_device(sas_address
, device_name
,
514 enclosure_logical_id
, slot
,
515 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
516 MPI2_BIOSPAGE2_FORM_MASK
),
517 &ioc
->bios_pg2
.CurrentBootDevice
)) {
518 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
519 "%s: current_boot_device(0x%016llx)\n",
521 (unsigned long long)sas_address
));
522 ioc
->current_boot_device
.device
= device
;
523 ioc
->current_boot_device
.is_raid
= is_raid
;
529 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
530 * @ioc: per adapter object
531 * @sas_address: sas address
532 * Context: Calling function should acquire ioc->sas_device_lock
534 * This searches for sas_device based on sas_address, then return sas_device
538 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
541 struct _sas_device
*sas_device
;
543 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
544 if (sas_device
->sas_address
== sas_address
)
547 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
548 if (sas_device
->sas_address
== sas_address
)
555 * _scsih_sas_device_find_by_handle - sas device search
556 * @ioc: per adapter object
557 * @handle: sas device handle (assigned by firmware)
558 * Context: Calling function should acquire ioc->sas_device_lock
560 * This searches for sas_device based on sas_address, then return sas_device
563 static struct _sas_device
*
564 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
566 struct _sas_device
*sas_device
;
568 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
569 if (sas_device
->handle
== handle
)
572 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
573 if (sas_device
->handle
== handle
)
580 * _scsih_sas_device_remove - remove sas_device from list.
581 * @ioc: per adapter object
582 * @sas_device: the sas_device object
583 * Context: This function will acquire ioc->sas_device_lock.
585 * Removing object and freeing associated memory from the ioc->sas_device_list.
588 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
589 struct _sas_device
*sas_device
)
596 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
597 list_del(&sas_device
->list
);
599 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
604 * _scsih_sas_device_add - insert sas_device to the list.
605 * @ioc: per adapter object
606 * @sas_device: the sas_device object
607 * Context: This function will acquire ioc->sas_device_lock.
609 * Adding new object to the ioc->sas_device_list.
612 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
613 struct _sas_device
*sas_device
)
617 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
618 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
619 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
621 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
622 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
623 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
625 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
626 sas_device
->sas_address_parent
)) {
627 _scsih_sas_device_remove(ioc
, sas_device
);
628 } else if (!sas_device
->starget
) {
629 /* When asyn scanning is enabled, its not possible to remove
630 * devices while scanning is turned on due to an oops in
631 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
633 if (!ioc
->is_driver_loading
) {
634 mpt2sas_transport_port_remove(ioc
,
635 sas_device
->sas_address
,
636 sas_device
->sas_address_parent
);
637 _scsih_sas_device_remove(ioc
, sas_device
);
643 * _scsih_sas_device_init_add - insert sas_device to the list.
644 * @ioc: per adapter object
645 * @sas_device: the sas_device object
646 * Context: This function will acquire ioc->sas_device_lock.
648 * Adding new object at driver load time to the ioc->sas_device_init_list.
651 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
652 struct _sas_device
*sas_device
)
656 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
657 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
658 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
660 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
661 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
662 _scsih_determine_boot_device(ioc
, sas_device
, 0);
663 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
667 * _scsih_raid_device_find_by_id - raid device search
668 * @ioc: per adapter object
669 * @id: sas device target id
670 * @channel: sas device channel
671 * Context: Calling function should acquire ioc->raid_device_lock
673 * This searches for raid_device based on target id, then return raid_device
676 static struct _raid_device
*
677 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
679 struct _raid_device
*raid_device
, *r
;
682 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
683 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
694 * _scsih_raid_device_find_by_handle - raid device search
695 * @ioc: per adapter object
696 * @handle: sas device handle (assigned by firmware)
697 * Context: Calling function should acquire ioc->raid_device_lock
699 * This searches for raid_device based on handle, then return raid_device
702 static struct _raid_device
*
703 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
705 struct _raid_device
*raid_device
, *r
;
708 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
709 if (raid_device
->handle
!= handle
)
720 * _scsih_raid_device_find_by_wwid - raid device search
721 * @ioc: per adapter object
722 * @handle: sas device handle (assigned by firmware)
723 * Context: Calling function should acquire ioc->raid_device_lock
725 * This searches for raid_device based on wwid, then return raid_device
728 static struct _raid_device
*
729 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
731 struct _raid_device
*raid_device
, *r
;
734 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
735 if (raid_device
->wwid
!= wwid
)
746 * _scsih_raid_device_add - add raid_device object
747 * @ioc: per adapter object
748 * @raid_device: raid_device object
750 * This is added to the raid_device_list link list.
753 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
754 struct _raid_device
*raid_device
)
758 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
759 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
760 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
762 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
763 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
764 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
768 * _scsih_raid_device_remove - delete raid_device object
769 * @ioc: per adapter object
770 * @raid_device: raid_device object
774 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
775 struct _raid_device
*raid_device
)
779 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
780 list_del(&raid_device
->list
);
782 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
786 * mpt2sas_scsih_expander_find_by_handle - expander device search
787 * @ioc: per adapter object
788 * @handle: expander handle (assigned by firmware)
789 * Context: Calling function should acquire ioc->sas_device_lock
791 * This searches for expander device based on handle, then returns the
795 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
797 struct _sas_node
*sas_expander
, *r
;
800 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
801 if (sas_expander
->handle
!= handle
)
811 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
812 * @ioc: per adapter object
813 * @sas_address: sas address
814 * Context: Calling function should acquire ioc->sas_node_lock.
816 * This searches for expander device based on sas_address, then returns the
820 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
823 struct _sas_node
*sas_expander
, *r
;
826 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
827 if (sas_expander
->sas_address
!= sas_address
)
837 * _scsih_expander_node_add - insert expander device to the list.
838 * @ioc: per adapter object
839 * @sas_expander: the sas_device object
840 * Context: This function will acquire ioc->sas_node_lock.
842 * Adding new object to the ioc->sas_expander_list.
847 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
848 struct _sas_node
*sas_expander
)
852 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
853 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
854 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
858 * _scsih_is_end_device - determines if device is an end device
859 * @device_info: bitfield providing information about the device.
862 * Returns 1 if end device.
865 _scsih_is_end_device(u32 device_info
)
867 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
868 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
869 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
870 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
877 * _scsih_scsi_lookup_get - returns scmd entry
878 * @ioc: per adapter object
879 * @smid: system request message index
881 * Returns the smid stored scmd pointer.
883 static struct scsi_cmnd
*
884 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
886 return ioc
->scsi_lookup
[smid
- 1].scmd
;
890 * _scsih_scsi_lookup_get_clear - returns scmd entry
891 * @ioc: per adapter object
892 * @smid: system request message index
894 * Returns the smid stored scmd pointer.
895 * Then will derefrence the stored scmd pointer.
897 static inline struct scsi_cmnd
*
898 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
901 struct scsi_cmnd
*scmd
;
903 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
904 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
905 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
906 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
912 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
913 * @ioc: per adapter object
914 * @smid: system request message index
915 * @scmd: pointer to scsi command object
916 * Context: This function will acquire ioc->scsi_lookup_lock.
918 * This will search for a scmd pointer in the scsi_lookup array,
919 * returning the revelent smid. A returned value of zero means invalid.
922 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
929 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
931 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
932 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
933 smid
= ioc
->scsi_lookup
[i
].smid
;
938 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
943 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
944 * @ioc: per adapter object
947 * Context: This function will acquire ioc->scsi_lookup_lock.
949 * This will search for a matching channel:id in the scsi_lookup array,
950 * returning 1 if found.
953 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
960 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
962 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
963 if (ioc
->scsi_lookup
[i
].scmd
&&
964 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
965 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
971 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
976 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
977 * @ioc: per adapter object
981 * Context: This function will acquire ioc->scsi_lookup_lock.
983 * This will search for a matching channel:id:lun in the scsi_lookup array,
984 * returning 1 if found.
987 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
988 unsigned int lun
, int channel
)
994 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
996 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
997 if (ioc
->scsi_lookup
[i
].scmd
&&
998 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
999 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1000 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1006 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1011 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1012 * @ioc: per adapter object
1013 * @smid: smid associated to an IO request
1015 * Returns chain tracker(from ioc->free_chain_list)
1017 static struct chain_tracker
*
1018 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1020 struct chain_tracker
*chain_req
;
1021 unsigned long flags
;
1023 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1024 if (list_empty(&ioc
->free_chain_list
)) {
1025 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1026 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
"chain buffers not "
1027 "available\n", ioc
->name
));
1030 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1031 struct chain_tracker
, tracker_list
);
1032 list_del_init(&chain_req
->tracker_list
);
1033 list_add_tail(&chain_req
->tracker_list
,
1034 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1035 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1040 * _scsih_build_scatter_gather - main sg creation routine
1041 * @ioc: per adapter object
1042 * @scmd: scsi command
1043 * @smid: system request message index
1046 * The main routine that builds scatter gather table from a given
1047 * scsi request sent via the .queuecommand main handler.
1049 * Returns 0 success, anything else error
1052 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
1053 struct scsi_cmnd
*scmd
, u16 smid
)
1055 Mpi2SCSIIORequest_t
*mpi_request
;
1056 dma_addr_t chain_dma
;
1057 struct scatterlist
*sg_scmd
;
1058 void *sg_local
, *chain
;
1063 u32 sges_in_segment
;
1065 u32 sgl_flags_last_element
;
1066 u32 sgl_flags_end_buffer
;
1067 struct chain_tracker
*chain_req
;
1069 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1071 /* init scatter gather flags */
1072 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1073 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1074 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1075 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1076 << MPI2_SGE_FLAGS_SHIFT
;
1077 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1078 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1079 << MPI2_SGE_FLAGS_SHIFT
;
1080 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1082 sg_scmd
= scsi_sglist(scmd
);
1083 sges_left
= scsi_dma_map(scmd
);
1084 if (sges_left
< 0) {
1085 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1086 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1090 sg_local
= &mpi_request
->SGL
;
1091 sges_in_segment
= ioc
->max_sges_in_main_message
;
1092 if (sges_left
<= sges_in_segment
)
1093 goto fill_in_last_segment
;
1095 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1096 (sges_in_segment
* ioc
->sge_size
))/4;
1098 /* fill in main message segment when there is a chain following */
1099 while (sges_in_segment
) {
1100 if (sges_in_segment
== 1)
1101 ioc
->base_add_sg_single(sg_local
,
1102 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1103 sg_dma_address(sg_scmd
));
1105 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1106 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1107 sg_scmd
= sg_next(sg_scmd
);
1108 sg_local
+= ioc
->sge_size
;
1113 /* initializing the chain flags and pointers */
1114 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1115 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1118 chain
= chain_req
->chain_buffer
;
1119 chain_dma
= chain_req
->chain_buffer_dma
;
1121 sges_in_segment
= (sges_left
<=
1122 ioc
->max_sges_in_chain_message
) ? sges_left
:
1123 ioc
->max_sges_in_chain_message
;
1124 chain_offset
= (sges_left
== sges_in_segment
) ?
1125 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1126 chain_length
= sges_in_segment
* ioc
->sge_size
;
1128 chain_offset
= chain_offset
<<
1129 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1130 chain_length
+= ioc
->sge_size
;
1132 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1133 chain_length
, chain_dma
);
1136 goto fill_in_last_segment
;
1138 /* fill in chain segments */
1139 while (sges_in_segment
) {
1140 if (sges_in_segment
== 1)
1141 ioc
->base_add_sg_single(sg_local
,
1142 sgl_flags_last_element
|
1143 sg_dma_len(sg_scmd
),
1144 sg_dma_address(sg_scmd
));
1146 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1147 sg_dma_len(sg_scmd
),
1148 sg_dma_address(sg_scmd
));
1149 sg_scmd
= sg_next(sg_scmd
);
1150 sg_local
+= ioc
->sge_size
;
1155 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1158 chain
= chain_req
->chain_buffer
;
1159 chain_dma
= chain_req
->chain_buffer_dma
;
1163 fill_in_last_segment
:
1165 /* fill the last segment */
1168 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1169 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1171 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1172 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1173 sg_scmd
= sg_next(sg_scmd
);
1174 sg_local
+= ioc
->sge_size
;
1182 * _scsih_adjust_queue_depth - setting device queue depth
1183 * @sdev: scsi device struct
1184 * @qdepth: requested queue depth
1190 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1192 struct Scsi_Host
*shost
= sdev
->host
;
1194 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1195 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1196 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1197 struct _sas_device
*sas_device
;
1198 unsigned long flags
;
1200 max_depth
= shost
->can_queue
;
1202 /* limit max device queue for SATA to 32 */
1203 sas_device_priv_data
= sdev
->hostdata
;
1204 if (!sas_device_priv_data
)
1206 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1207 if (!sas_target_priv_data
)
1209 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1211 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1212 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1213 sas_device_priv_data
->sas_target
->sas_address
);
1214 if (sas_device
&& sas_device
->device_info
&
1215 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1216 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1217 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1221 if (!sdev
->tagged_supported
)
1223 if (qdepth
> max_depth
)
1225 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1229 * _scsih_change_queue_depth - setting device queue depth
1230 * @sdev: scsi device struct
1231 * @qdepth: requested queue depth
1232 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1233 * (see include/scsi/scsi_host.h for definition)
1235 * Returns queue depth.
1238 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1240 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1241 _scsih_adjust_queue_depth(sdev
, qdepth
);
1242 else if (reason
== SCSI_QDEPTH_QFULL
)
1243 scsi_track_queue_full(sdev
, qdepth
);
1247 if (sdev
->inquiry_len
> 7)
1248 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1249 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1250 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1251 sdev
->ordered_tags
, sdev
->scsi_level
,
1252 (sdev
->inquiry
[7] & 2) >> 1);
1254 return sdev
->queue_depth
;
1258 * _scsih_change_queue_type - changing device queue tag type
1259 * @sdev: scsi device struct
1260 * @tag_type: requested tag type
1262 * Returns queue tag type.
1265 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1267 if (sdev
->tagged_supported
) {
1268 scsi_set_tag_type(sdev
, tag_type
);
1270 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1272 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1280 * _scsih_target_alloc - target add routine
1281 * @starget: scsi target struct
1283 * Returns 0 if ok. Any other return is assumed to be an error and
1284 * the device is ignored.
1287 _scsih_target_alloc(struct scsi_target
*starget
)
1289 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1290 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1291 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1292 struct _sas_device
*sas_device
;
1293 struct _raid_device
*raid_device
;
1294 unsigned long flags
;
1295 struct sas_rphy
*rphy
;
1297 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1299 if (!sas_target_priv_data
)
1302 starget
->hostdata
= sas_target_priv_data
;
1303 sas_target_priv_data
->starget
= starget
;
1304 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1307 if (starget
->channel
== RAID_CHANNEL
) {
1308 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1309 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1312 sas_target_priv_data
->handle
= raid_device
->handle
;
1313 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1314 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1315 if (ioc
->is_warpdrive
)
1316 sas_target_priv_data
->raid_device
= raid_device
;
1317 raid_device
->starget
= starget
;
1319 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1323 /* sas/sata devices */
1324 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1325 rphy
= dev_to_rphy(starget
->dev
.parent
);
1326 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1327 rphy
->identify
.sas_address
);
1330 sas_target_priv_data
->handle
= sas_device
->handle
;
1331 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1332 sas_device
->starget
= starget
;
1333 sas_device
->id
= starget
->id
;
1334 sas_device
->channel
= starget
->channel
;
1335 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1336 sas_target_priv_data
->flags
|=
1337 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1339 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1345 * _scsih_target_destroy - target destroy routine
1346 * @starget: scsi target struct
1351 _scsih_target_destroy(struct scsi_target
*starget
)
1353 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1354 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1355 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1356 struct _sas_device
*sas_device
;
1357 struct _raid_device
*raid_device
;
1358 unsigned long flags
;
1359 struct sas_rphy
*rphy
;
1361 sas_target_priv_data
= starget
->hostdata
;
1362 if (!sas_target_priv_data
)
1365 if (starget
->channel
== RAID_CHANNEL
) {
1366 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1367 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1370 raid_device
->starget
= NULL
;
1371 raid_device
->sdev
= NULL
;
1373 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1377 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1378 rphy
= dev_to_rphy(starget
->dev
.parent
);
1379 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1380 rphy
->identify
.sas_address
);
1381 if (sas_device
&& (sas_device
->starget
== starget
) &&
1382 (sas_device
->id
== starget
->id
) &&
1383 (sas_device
->channel
== starget
->channel
))
1384 sas_device
->starget
= NULL
;
1386 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1389 kfree(sas_target_priv_data
);
1390 starget
->hostdata
= NULL
;
1394 * _scsih_slave_alloc - device add routine
1395 * @sdev: scsi device struct
1397 * Returns 0 if ok. Any other return is assumed to be an error and
1398 * the device is ignored.
1401 _scsih_slave_alloc(struct scsi_device
*sdev
)
1403 struct Scsi_Host
*shost
;
1404 struct MPT2SAS_ADAPTER
*ioc
;
1405 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1406 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1407 struct scsi_target
*starget
;
1408 struct _raid_device
*raid_device
;
1409 struct _sas_device
*sas_device
;
1410 unsigned long flags
;
1412 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1414 if (!sas_device_priv_data
)
1417 sas_device_priv_data
->lun
= sdev
->lun
;
1418 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1420 starget
= scsi_target(sdev
);
1421 sas_target_priv_data
= starget
->hostdata
;
1422 sas_target_priv_data
->num_luns
++;
1423 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1424 sdev
->hostdata
= sas_device_priv_data
;
1425 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1426 sdev
->no_uld_attach
= 1;
1428 shost
= dev_to_shost(&starget
->dev
);
1429 ioc
= shost_priv(shost
);
1430 if (starget
->channel
== RAID_CHANNEL
) {
1431 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1432 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1433 starget
->id
, starget
->channel
);
1435 raid_device
->sdev
= sdev
; /* raid is single lun */
1436 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1439 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1440 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1441 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1442 sas_target_priv_data
->sas_address
);
1443 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1444 sdev_printk(KERN_INFO
, sdev
,
1445 "%s : sas_device->starget set to starget @ %d\n",
1446 __func__
, __LINE__
);
1447 sas_device
->starget
= starget
;
1449 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1456 * _scsih_slave_destroy - device destroy routine
1457 * @sdev: scsi device struct
1462 _scsih_slave_destroy(struct scsi_device
*sdev
)
1464 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1465 struct scsi_target
*starget
;
1466 struct Scsi_Host
*shost
;
1467 struct MPT2SAS_ADAPTER
*ioc
;
1468 struct _sas_device
*sas_device
;
1469 unsigned long flags
;
1471 if (!sdev
->hostdata
)
1474 starget
= scsi_target(sdev
);
1475 sas_target_priv_data
= starget
->hostdata
;
1476 sas_target_priv_data
->num_luns
--;
1478 shost
= dev_to_shost(&starget
->dev
);
1479 ioc
= shost_priv(shost
);
1481 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1482 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1483 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1484 sas_target_priv_data
->sas_address
);
1485 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1486 sas_device
->starget
= NULL
;
1487 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1490 kfree(sdev
->hostdata
);
1491 sdev
->hostdata
= NULL
;
1495 * _scsih_display_sata_capabilities - sata capabilities
1496 * @ioc: per adapter object
1497 * @handle: device handle
1498 * @sdev: scsi device struct
1501 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1502 u16 handle
, struct scsi_device
*sdev
)
1504 Mpi2ConfigReply_t mpi_reply
;
1505 Mpi2SasDevicePage0_t sas_device_pg0
;
1510 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1511 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1512 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1513 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1517 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1518 MPI2_IOCSTATUS_MASK
;
1519 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1520 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1521 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1525 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1526 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1528 sdev_printk(KERN_INFO
, sdev
,
1529 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1530 "sw_preserve(%s)\n",
1531 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1532 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1533 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1535 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1536 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1537 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1541 * _scsih_is_raid - return boolean indicating device is raid volume
1542 * @dev the device struct object
1545 _scsih_is_raid(struct device
*dev
)
1547 struct scsi_device
*sdev
= to_scsi_device(dev
);
1548 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1550 if (ioc
->is_warpdrive
)
1552 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1556 * _scsih_get_resync - get raid volume resync percent complete
1557 * @dev the device struct object
1560 _scsih_get_resync(struct device
*dev
)
1562 struct scsi_device
*sdev
= to_scsi_device(dev
);
1563 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1564 static struct _raid_device
*raid_device
;
1565 unsigned long flags
;
1566 Mpi2RaidVolPage0_t vol_pg0
;
1567 Mpi2ConfigReply_t mpi_reply
;
1568 u32 volume_status_flags
;
1569 u8 percent_complete
;
1572 percent_complete
= 0;
1574 if (ioc
->is_warpdrive
)
1577 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1578 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1581 handle
= raid_device
->handle
;
1582 percent_complete
= raid_device
->percent_complete
;
1584 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1589 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1590 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1591 sizeof(Mpi2RaidVolPage0_t
))) {
1592 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1593 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1594 percent_complete
= 0;
1598 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1599 if (!(volume_status_flags
&
1600 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1601 percent_complete
= 0;
1604 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1608 * _scsih_get_state - get raid volume level
1609 * @dev the device struct object
1612 _scsih_get_state(struct device
*dev
)
1614 struct scsi_device
*sdev
= to_scsi_device(dev
);
1615 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1616 static struct _raid_device
*raid_device
;
1617 unsigned long flags
;
1618 Mpi2RaidVolPage0_t vol_pg0
;
1619 Mpi2ConfigReply_t mpi_reply
;
1621 enum raid_state state
= RAID_STATE_UNKNOWN
;
1624 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1625 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1628 handle
= raid_device
->handle
;
1629 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1634 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1635 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1636 sizeof(Mpi2RaidVolPage0_t
))) {
1637 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1638 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1642 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1643 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1644 state
= RAID_STATE_RESYNCING
;
1648 switch (vol_pg0
.VolumeState
) {
1649 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1650 case MPI2_RAID_VOL_STATE_ONLINE
:
1651 state
= RAID_STATE_ACTIVE
;
1653 case MPI2_RAID_VOL_STATE_DEGRADED
:
1654 state
= RAID_STATE_DEGRADED
;
1656 case MPI2_RAID_VOL_STATE_FAILED
:
1657 case MPI2_RAID_VOL_STATE_MISSING
:
1658 state
= RAID_STATE_OFFLINE
;
1662 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1666 * _scsih_set_level - set raid level
1667 * @sdev: scsi device struct
1668 * @volume_type: volume type
1671 _scsih_set_level(struct scsi_device
*sdev
, u8 volume_type
)
1673 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1675 switch (volume_type
) {
1676 case MPI2_RAID_VOL_TYPE_RAID0
:
1677 level
= RAID_LEVEL_0
;
1679 case MPI2_RAID_VOL_TYPE_RAID10
:
1680 level
= RAID_LEVEL_10
;
1682 case MPI2_RAID_VOL_TYPE_RAID1E
:
1683 level
= RAID_LEVEL_1E
;
1685 case MPI2_RAID_VOL_TYPE_RAID1
:
1686 level
= RAID_LEVEL_1
;
1690 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1694 * _scsih_get_volume_capabilities - volume capabilities
1695 * @ioc: per adapter object
1696 * @sas_device: the raid_device object
1698 * Returns 0 for success, else 1
1701 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1702 struct _raid_device
*raid_device
)
1704 Mpi2RaidVolPage0_t
*vol_pg0
;
1705 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1706 Mpi2SasDevicePage0_t sas_device_pg0
;
1707 Mpi2ConfigReply_t mpi_reply
;
1711 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1712 &num_pds
)) || !num_pds
) {
1713 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1714 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1719 raid_device
->num_pds
= num_pds
;
1720 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1721 sizeof(Mpi2RaidVol0PhysDisk_t
));
1722 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1724 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1725 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1730 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1731 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1732 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1733 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1739 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1741 /* figure out what the underlying devices are by
1742 * obtaining the device_info bits for the 1st device
1744 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1745 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1746 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1747 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1748 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1749 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1750 raid_device
->device_info
=
1751 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1759 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1760 * @ioc: per adapter object
1763 _scsih_disable_ddio(struct MPT2SAS_ADAPTER
*ioc
)
1765 Mpi2RaidVolPage1_t vol_pg1
;
1766 Mpi2ConfigReply_t mpi_reply
;
1767 struct _raid_device
*raid_device
;
1770 unsigned long flags
;
1773 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1774 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1775 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1776 MPI2_IOCSTATUS_MASK
;
1777 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1779 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1780 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1781 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1783 raid_device
->direct_io_enabled
= 0;
1784 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1791 * _scsih_get_num_volumes - Get number of volumes in the ioc
1792 * @ioc: per adapter object
1795 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER
*ioc
)
1797 Mpi2RaidVolPage1_t vol_pg1
;
1798 Mpi2ConfigReply_t mpi_reply
;
1804 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1805 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1806 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1807 MPI2_IOCSTATUS_MASK
;
1808 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1811 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1818 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1819 * @ioc: per adapter object
1820 * @raid_device: the raid_device object
1823 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER
*ioc
,
1824 struct _raid_device
*raid_device
)
1826 Mpi2RaidVolPage0_t
*vol_pg0
;
1827 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1828 Mpi2ConfigReply_t mpi_reply
;
1831 unsigned long stripe_sz
, block_sz
;
1832 u8 stripe_exp
, block_exp
;
1835 if (!ioc
->is_warpdrive
)
1838 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
) {
1839 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1840 "globally as drives are exposed\n", ioc
->name
);
1843 if (_scsih_get_num_volumes(ioc
) > 1) {
1844 _scsih_disable_ddio(ioc
);
1845 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1846 "globally as number of drives > 1\n", ioc
->name
);
1849 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1850 &num_pds
)) || !num_pds
) {
1851 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1852 "Failure in computing number of drives\n", ioc
->name
);
1856 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1857 sizeof(Mpi2RaidVol0PhysDisk_t
));
1858 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1860 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1861 "Memory allocation failure for RVPG0\n", ioc
->name
);
1865 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1866 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1867 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1868 "Failure in retrieving RVPG0\n", ioc
->name
);
1874 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1875 * assumed for WARPDRIVE, disable direct I/O
1877 if (num_pds
> MPT_MAX_WARPDRIVE_PDS
) {
1878 printk(MPT2SAS_WARN_FMT
"WarpDrive : Direct IO is disabled "
1879 "for the drive with handle(0x%04x): num_mem=%d, "
1880 "max_mem_allowed=%d\n", ioc
->name
, raid_device
->handle
,
1881 num_pds
, MPT_MAX_WARPDRIVE_PDS
);
1885 for (count
= 0; count
< num_pds
; count
++) {
1886 if (mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1887 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1888 vol_pg0
->PhysDisk
[count
].PhysDiskNum
) ||
1889 le16_to_cpu(pd_pg0
.DevHandle
) ==
1890 MPT2SAS_INVALID_DEVICE_HANDLE
) {
1891 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1892 "disabled for the drive with handle(0x%04x) member"
1893 "handle retrieval failed for member number=%d\n",
1894 ioc
->name
, raid_device
->handle
,
1895 vol_pg0
->PhysDisk
[count
].PhysDiskNum
);
1898 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1899 dev_max_lba
= le64_to_cpu(pd_pg0
.DeviceMaxLBA
);
1900 if (dev_max_lba
>> 32) {
1901 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1902 "disabled for the drive with handle(0x%04x) member"
1903 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1904 ioc
->name
, raid_device
->handle
,
1905 le16_to_cpu(pd_pg0
.DevHandle
),
1906 (unsigned long long)dev_max_lba
);
1910 raid_device
->pd_handle
[count
] = le16_to_cpu(pd_pg0
.DevHandle
);
1914 * Assumption for WD: Direct I/O is not supported if the volume is
1917 if (raid_device
->volume_type
!= MPI2_RAID_VOL_TYPE_RAID0
) {
1918 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1919 "for the drive with handle(0x%04x): type=%d, "
1920 "s_sz=%uK, blk_size=%u\n", ioc
->name
,
1921 raid_device
->handle
, raid_device
->volume_type
,
1922 (le32_to_cpu(vol_pg0
->StripeSize
) *
1923 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024,
1924 le16_to_cpu(vol_pg0
->BlockSize
));
1928 stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1929 stripe_exp
= find_first_bit(&stripe_sz
, 32);
1930 if (stripe_exp
== 32) {
1931 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1932 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1933 ioc
->name
, raid_device
->handle
,
1934 (le32_to_cpu(vol_pg0
->StripeSize
) *
1935 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024);
1938 raid_device
->stripe_exponent
= stripe_exp
;
1939 block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1940 block_exp
= find_first_bit(&block_sz
, 16);
1941 if (block_exp
== 16) {
1942 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1943 "for the drive with handle(0x%04x) invalid block sz %u\n",
1944 ioc
->name
, raid_device
->handle
,
1945 le16_to_cpu(vol_pg0
->BlockSize
));
1948 raid_device
->block_exponent
= block_exp
;
1949 raid_device
->direct_io_enabled
= 1;
1951 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is Enabled for the drive"
1952 " with handle(0x%04x)\n", ioc
->name
, raid_device
->handle
);
1954 * WARPDRIVE: Though the following fields are not used for direct IO,
1955 * stored for future purpose:
1957 raid_device
->max_lba
= le64_to_cpu(vol_pg0
->MaxLBA
);
1958 raid_device
->stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1959 raid_device
->block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1966 raid_device
->direct_io_enabled
= 0;
1967 for (count
= 0; count
< num_pds
; count
++)
1968 raid_device
->pd_handle
[count
] = 0;
1974 * _scsih_enable_tlr - setting TLR flags
1975 * @ioc: per adapter object
1976 * @sdev: scsi device struct
1978 * Enabling Transaction Layer Retries for tape devices when
1979 * vpd page 0x90 is present
1983 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1986 if (sdev
->type
!= TYPE_TAPE
)
1989 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1992 sas_enable_tlr(sdev
);
1993 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1994 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2000 * _scsih_slave_configure - device configure routine.
2001 * @sdev: scsi device struct
2003 * Returns 0 if ok. Any other return is assumed to be an error and
2004 * the device is ignored.
2007 _scsih_slave_configure(struct scsi_device
*sdev
)
2009 struct Scsi_Host
*shost
= sdev
->host
;
2010 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2011 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2012 struct MPT2SAS_TARGET
*sas_target_priv_data
;
2013 struct _sas_device
*sas_device
;
2014 struct _raid_device
*raid_device
;
2015 unsigned long flags
;
2020 u16 handle
, volume_handle
= 0;
2021 u64 volume_wwid
= 0;
2024 sas_device_priv_data
= sdev
->hostdata
;
2025 sas_device_priv_data
->configured_lun
= 1;
2026 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2027 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2028 handle
= sas_target_priv_data
->handle
;
2030 /* raid volume handling */
2031 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2033 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2034 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
2035 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2037 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2038 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2039 __LINE__
, __func__
));
2043 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2044 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2045 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2046 __LINE__
, __func__
));
2050 * WARPDRIVE: Initialize the required data for Direct IO
2052 _scsih_init_warpdrive_properties(ioc
, raid_device
);
2054 /* RAID Queue Depth Support
2055 * IS volume = underlying qdepth of drive type, either
2056 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2057 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2059 if (raid_device
->device_info
&
2060 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2061 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2064 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2065 if (raid_device
->device_info
&
2066 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2072 switch (raid_device
->volume_type
) {
2073 case MPI2_RAID_VOL_TYPE_RAID0
:
2076 case MPI2_RAID_VOL_TYPE_RAID1E
:
2077 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2078 if (ioc
->manu_pg10
.OEMIdentifier
&&
2079 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2080 MFG10_GF0_R10_DISPLAY
) &&
2081 !(raid_device
->num_pds
% 2))
2086 case MPI2_RAID_VOL_TYPE_RAID1
:
2087 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2090 case MPI2_RAID_VOL_TYPE_RAID10
:
2091 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2094 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2096 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2101 if (!ioc
->hide_ir_msg
)
2102 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2103 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2104 r_level
, raid_device
->handle
,
2105 (unsigned long long)raid_device
->wwid
,
2106 raid_device
->num_pds
, ds
);
2107 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2108 /* raid transport support */
2109 if (!ioc
->is_warpdrive
)
2110 _scsih_set_level(sdev
, raid_device
->volume_type
);
2114 /* non-raid handling */
2115 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2116 if (mpt2sas_config_get_volume_handle(ioc
, handle
,
2118 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2119 "failure at %s:%d/%s()!\n", ioc
->name
,
2120 __FILE__
, __LINE__
, __func__
));
2123 if (volume_handle
&& mpt2sas_config_get_volume_wwid(ioc
,
2124 volume_handle
, &volume_wwid
)) {
2125 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2126 "failure at %s:%d/%s()!\n", ioc
->name
,
2127 __FILE__
, __LINE__
, __func__
));
2132 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2133 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2134 sas_device_priv_data
->sas_target
->sas_address
);
2136 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2137 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2138 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2139 __LINE__
, __func__
));
2142 sas_device
->volume_handle
= volume_handle
;
2143 sas_device
->volume_wwid
= volume_wwid
;
2144 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2145 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2149 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2150 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2152 else if (sas_device
->device_info
&
2153 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2156 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2157 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2158 ds
, sas_device
->handle
,
2159 (unsigned long long)sas_device
->sas_address
,
2161 (unsigned long long)sas_device
->device_name
);
2162 sdev_printk(KERN_INFO
, sdev
, "%s: "
2163 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
2164 (unsigned long long) sas_device
->enclosure_logical_id
,
2167 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2169 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2172 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2175 sas_read_port_mode_page(sdev
);
2176 _scsih_enable_tlr(ioc
, sdev
);
2182 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2183 * @sdev: scsi device struct
2184 * @bdev: pointer to block device context
2185 * @capacity: device size (in 512 byte sectors)
2186 * @params: three element array to place output:
2187 * params[0] number of heads (max 255)
2188 * params[1] number of sectors (max 63)
2189 * params[2] number of cylinders
2194 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2195 sector_t capacity
, int params
[])
2205 dummy
= heads
* sectors
;
2206 cylinders
= capacity
;
2207 sector_div(cylinders
, dummy
);
2210 * Handle extended translation size for logical drives
2213 if ((ulong
)capacity
>= 0x200000) {
2216 dummy
= heads
* sectors
;
2217 cylinders
= capacity
;
2218 sector_div(cylinders
, dummy
);
2223 params
[1] = sectors
;
2224 params
[2] = cylinders
;
2230 * _scsih_response_code - translation of device response code
2231 * @ioc: per adapter object
2232 * @response_code: response code returned by the device
2237 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
2241 switch (response_code
) {
2242 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2243 desc
= "task management request completed";
2245 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2246 desc
= "invalid frame";
2248 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2249 desc
= "task management request not supported";
2251 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2252 desc
= "task management request failed";
2254 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2255 desc
= "task management request succeeded";
2257 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2258 desc
= "invalid lun";
2261 desc
= "overlapped tag attempted";
2263 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2264 desc
= "task queued, however not sent to target";
2270 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
2271 ioc
->name
, response_code
, desc
);
2275 * _scsih_tm_done - tm completion routine
2276 * @ioc: per adapter object
2277 * @smid: system request message index
2278 * @msix_index: MSIX table index supplied by the OS
2279 * @reply: reply message frame(lower 32bit addr)
2282 * The callback handler when using scsih_issue_tm.
2284 * Return 1 meaning mf should be freed from _base_interrupt
2285 * 0 means the mf is freed from this function.
2288 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2290 MPI2DefaultReply_t
*mpi_reply
;
2292 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
2294 if (ioc
->tm_cmds
.smid
!= smid
)
2296 mpt2sas_base_flush_reply_queues(ioc
);
2297 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
2298 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2300 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2301 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
2303 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
2304 complete(&ioc
->tm_cmds
.done
);
2309 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2310 * @ioc: per adapter object
2311 * @handle: device handle
2313 * During taskmangement request, we need to freeze the device queue.
2316 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2318 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2319 struct scsi_device
*sdev
;
2322 shost_for_each_device(sdev
, ioc
->shost
) {
2325 sas_device_priv_data
= sdev
->hostdata
;
2326 if (!sas_device_priv_data
)
2328 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2329 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2331 ioc
->ignore_loginfos
= 1;
2337 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2338 * @ioc: per adapter object
2339 * @handle: device handle
2341 * During taskmangement request, we need to freeze the device queue.
2344 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2346 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2347 struct scsi_device
*sdev
;
2350 shost_for_each_device(sdev
, ioc
->shost
) {
2353 sas_device_priv_data
= sdev
->hostdata
;
2354 if (!sas_device_priv_data
)
2356 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2357 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2359 ioc
->ignore_loginfos
= 0;
2366 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2367 * @ioc: per adapter struct
2368 * @device_handle: device handle
2369 * @channel: the channel assigned by the OS
2370 * @id: the id assigned by the OS
2372 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2373 * @smid_task: smid assigned to the task
2374 * @timeout: timeout in seconds
2375 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2378 * A generic API for sending task management requests to firmware.
2380 * The callback index is set inside `ioc->tm_cb_idx`.
2382 * Return SUCCESS or FAILED.
2385 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2386 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2387 enum mutex_type m_type
)
2389 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2390 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2393 unsigned long timeleft
;
2394 struct scsiio_tracker
*scsi_lookup
= NULL
;
2397 if (m_type
== TM_MUTEX_ON
)
2398 mutex_lock(&ioc
->tm_cmds
.mutex
);
2399 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2400 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2401 __func__
, ioc
->name
);
2406 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2407 ioc
->pci_error_recovery
) {
2408 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2409 __func__
, ioc
->name
);
2414 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2415 if (ioc_state
& MPI2_DOORBELL_USED
) {
2416 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2417 "active!\n", ioc
->name
));
2418 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2420 rc
= (!rc
) ? SUCCESS
: FAILED
;
2424 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2425 mpt2sas_base_fault_info(ioc
, ioc_state
&
2426 MPI2_DOORBELL_DATA_MASK
);
2427 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2429 rc
= (!rc
) ? SUCCESS
: FAILED
;
2433 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2435 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2436 ioc
->name
, __func__
);
2441 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2442 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2444 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2445 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2447 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2448 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2449 ioc
->tm_cmds
.smid
= smid
;
2450 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2451 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2452 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2453 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2454 mpi_request
->TaskType
= type
;
2455 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2456 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2457 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2458 init_completion(&ioc
->tm_cmds
.done
);
2459 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2460 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2461 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2462 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2463 ioc
->name
, __func__
);
2464 _debug_dump_mf(mpi_request
,
2465 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2466 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2467 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2469 rc
= (!rc
) ? SUCCESS
: FAILED
;
2470 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2471 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2476 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2477 mpi_reply
= ioc
->tm_cmds
.reply
;
2478 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2479 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2480 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2481 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2482 le32_to_cpu(mpi_reply
->TerminationCount
)));
2483 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2484 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2485 if (mpi_reply
->IOCStatus
)
2486 _debug_dump_mf(mpi_request
,
2487 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2492 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2494 if (scsi_lookup
->scmd
== NULL
)
2499 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2500 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2506 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2507 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2508 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2513 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2521 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2522 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2523 if (m_type
== TM_MUTEX_ON
)
2524 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2529 if (m_type
== TM_MUTEX_ON
)
2530 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2535 * _scsih_tm_display_info - displays info about the device
2536 * @ioc: per adapter struct
2537 * @scmd: pointer to scsi command object
2539 * Called by task management callback handlers.
2542 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2544 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2545 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2546 struct _sas_device
*sas_device
= NULL
;
2547 unsigned long flags
;
2548 char *device_str
= NULL
;
2552 if (ioc
->hide_ir_msg
)
2553 device_str
= "WarpDrive";
2555 device_str
= "volume";
2557 scsi_print_command(scmd
);
2558 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2559 starget_printk(KERN_INFO
, starget
, "%s handle(0x%04x), "
2560 "%s wwid(0x%016llx)\n", device_str
, priv_target
->handle
,
2561 device_str
, (unsigned long long)priv_target
->sas_address
);
2563 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2564 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2565 priv_target
->sas_address
);
2567 if (priv_target
->flags
&
2568 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2569 starget_printk(KERN_INFO
, starget
,
2570 "volume handle(0x%04x), "
2571 "volume wwid(0x%016llx)\n",
2572 sas_device
->volume_handle
,
2573 (unsigned long long)sas_device
->volume_wwid
);
2575 starget_printk(KERN_INFO
, starget
,
2576 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2578 (unsigned long long)sas_device
->sas_address
,
2580 starget_printk(KERN_INFO
, starget
,
2581 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2582 (unsigned long long)sas_device
->enclosure_logical_id
,
2585 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2590 * _scsih_abort - eh threads main abort routine
2591 * @scmd: pointer to scsi command object
2593 * Returns SUCCESS if command aborted else FAILED
2596 _scsih_abort(struct scsi_cmnd
*scmd
)
2598 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2599 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2604 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2605 "scmd(%p)\n", scmd
);
2606 _scsih_tm_display_info(ioc
, scmd
);
2608 sas_device_priv_data
= scmd
->device
->hostdata
;
2609 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2610 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2611 "scmd(%p)\n", scmd
);
2612 scmd
->result
= DID_NO_CONNECT
<< 16;
2613 scmd
->scsi_done(scmd
);
2618 /* search for the command */
2619 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2621 scmd
->result
= DID_RESET
<< 16;
2626 /* for hidden raid components and volumes this is not supported */
2627 if (sas_device_priv_data
->sas_target
->flags
&
2628 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2629 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2630 scmd
->result
= DID_RESET
<< 16;
2635 mpt2sas_halt_firmware(ioc
);
2637 handle
= sas_device_priv_data
->sas_target
->handle
;
2638 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2639 scmd
->device
->id
, scmd
->device
->lun
,
2640 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2643 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2644 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2649 * _scsih_dev_reset - eh threads main device reset routine
2650 * @scmd: pointer to scsi command object
2652 * Returns SUCCESS if command aborted else FAILED
2655 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2657 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2658 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2659 struct _sas_device
*sas_device
;
2660 unsigned long flags
;
2664 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2666 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2667 "scmd(%p)\n", scmd
);
2668 _scsih_tm_display_info(ioc
, scmd
);
2670 sas_device_priv_data
= scmd
->device
->hostdata
;
2671 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2672 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2673 "scmd(%p)\n", scmd
);
2674 scmd
->result
= DID_NO_CONNECT
<< 16;
2675 scmd
->scsi_done(scmd
);
2680 /* for hidden raid components obtain the volume_handle */
2682 if (sas_device_priv_data
->sas_target
->flags
&
2683 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2684 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2685 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2686 sas_device_priv_data
->sas_target
->handle
);
2688 handle
= sas_device
->volume_handle
;
2689 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2691 handle
= sas_device_priv_data
->sas_target
->handle
;
2694 scmd
->result
= DID_RESET
<< 16;
2699 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2700 scmd
->device
->id
, scmd
->device
->lun
,
2701 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2704 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2705 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2710 * _scsih_target_reset - eh threads main target reset routine
2711 * @scmd: pointer to scsi command object
2713 * Returns SUCCESS if command aborted else FAILED
2716 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2718 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2719 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2720 struct _sas_device
*sas_device
;
2721 unsigned long flags
;
2724 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2726 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2727 "scmd(%p)\n", scmd
);
2728 _scsih_tm_display_info(ioc
, scmd
);
2730 sas_device_priv_data
= scmd
->device
->hostdata
;
2731 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2732 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2733 "scmd(%p)\n", scmd
);
2734 scmd
->result
= DID_NO_CONNECT
<< 16;
2735 scmd
->scsi_done(scmd
);
2740 /* for hidden raid components obtain the volume_handle */
2742 if (sas_device_priv_data
->sas_target
->flags
&
2743 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2744 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2745 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2746 sas_device_priv_data
->sas_target
->handle
);
2748 handle
= sas_device
->volume_handle
;
2749 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2751 handle
= sas_device_priv_data
->sas_target
->handle
;
2754 scmd
->result
= DID_RESET
<< 16;
2759 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2760 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2764 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2765 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2770 * _scsih_host_reset - eh threads main host reset routine
2771 * @scmd: pointer to scsi command object
2773 * Returns SUCCESS if command aborted else FAILED
2776 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2778 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2781 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2783 scsi_print_command(scmd
);
2785 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2787 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2788 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2789 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2795 * _scsih_fw_event_add - insert and queue up fw_event
2796 * @ioc: per adapter object
2797 * @fw_event: object describing the event
2798 * Context: This function will acquire ioc->fw_event_lock.
2800 * This adds the firmware event object into link list, then queues it up to
2801 * be processed from user context.
2806 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2808 unsigned long flags
;
2810 if (ioc
->firmware_event_thread
== NULL
)
2813 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2814 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2815 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2816 queue_delayed_work(ioc
->firmware_event_thread
,
2817 &fw_event
->delayed_work
, 0);
2818 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2822 * _scsih_fw_event_free - delete fw_event
2823 * @ioc: per adapter object
2824 * @fw_event: object describing the event
2825 * Context: This function will acquire ioc->fw_event_lock.
2827 * This removes firmware event object from link list, frees associated memory.
2832 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2835 unsigned long flags
;
2837 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2838 list_del(&fw_event
->list
);
2840 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2845 * _scsih_error_recovery_delete_devices - remove devices not responding
2846 * @ioc: per adapter object
2851 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER
*ioc
)
2853 struct fw_event_work
*fw_event
;
2855 if (ioc
->is_driver_loading
)
2858 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2862 fw_event
->event
= MPT2SAS_REMOVE_UNRESPONDING_DEVICES
;
2863 fw_event
->ioc
= ioc
;
2864 _scsih_fw_event_add(ioc
, fw_event
);
2868 * mpt2sas_port_enable_complete - port enable completed (fake event)
2869 * @ioc: per adapter object
2874 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER
*ioc
)
2876 struct fw_event_work
*fw_event
;
2878 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2881 fw_event
->event
= MPT2SAS_PORT_ENABLE_COMPLETE
;
2882 fw_event
->ioc
= ioc
;
2883 _scsih_fw_event_add(ioc
, fw_event
);
2887 * _scsih_fw_event_cleanup_queue - cleanup event queue
2888 * @ioc: per adapter object
2890 * Walk the firmware event queue, either killing timers, or waiting
2891 * for outstanding events to complete
2896 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2898 struct fw_event_work
*fw_event
, *next
;
2900 if (list_empty(&ioc
->fw_event_list
) ||
2901 !ioc
->firmware_event_thread
|| in_interrupt())
2904 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2905 if (cancel_delayed_work_sync(&fw_event
->delayed_work
)) {
2906 _scsih_fw_event_free(ioc
, fw_event
);
2913 * _scsih_ublock_io_all_device - unblock every device
2914 * @ioc: per adapter object
2916 * change the device state from block to running
2919 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2921 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2922 struct scsi_device
*sdev
;
2924 shost_for_each_device(sdev
, ioc
->shost
) {
2925 sas_device_priv_data
= sdev
->hostdata
;
2926 if (!sas_device_priv_data
)
2928 if (!sas_device_priv_data
->block
)
2930 sas_device_priv_data
->block
= 0;
2931 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_running, "
2933 sas_device_priv_data
->sas_target
->handle
));
2934 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2938 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2939 * @ioc: per adapter object
2940 * @handle: device handle
2942 * During device pull we need to appropiately set the sdev state.
2945 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
2947 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2948 struct scsi_device
*sdev
;
2950 shost_for_each_device(sdev
, ioc
->shost
) {
2951 sas_device_priv_data
= sdev
->hostdata
;
2952 if (!sas_device_priv_data
)
2954 if (!sas_device_priv_data
->block
)
2956 if (sas_device_priv_data
->sas_target
->sas_address
==
2958 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2959 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2960 "sas address(0x%016llx)\n", ioc
->name
,
2961 (unsigned long long)sas_address
));
2962 sas_device_priv_data
->block
= 0;
2963 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2969 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2970 * @ioc: per adapter object
2971 * @handle: device handle
2973 * During device pull we need to appropiately set the sdev state.
2976 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2978 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2979 struct scsi_device
*sdev
;
2981 shost_for_each_device(sdev
, ioc
->shost
) {
2982 sas_device_priv_data
= sdev
->hostdata
;
2983 if (!sas_device_priv_data
)
2985 if (sas_device_priv_data
->block
)
2987 sas_device_priv_data
->block
= 1;
2988 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_blocked, "
2990 sas_device_priv_data
->sas_target
->handle
));
2991 scsi_internal_device_block(sdev
);
2997 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2998 * @ioc: per adapter object
2999 * @handle: device handle
3001 * During device pull we need to appropiately set the sdev state.
3004 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3006 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3007 struct scsi_device
*sdev
;
3009 shost_for_each_device(sdev
, ioc
->shost
) {
3010 sas_device_priv_data
= sdev
->hostdata
;
3011 if (!sas_device_priv_data
)
3013 if (sas_device_priv_data
->block
)
3015 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
3016 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3017 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
3018 "handle(0x%04x)\n", ioc
->name
, handle
));
3019 sas_device_priv_data
->block
= 1;
3020 scsi_internal_device_block(sdev
);
3026 * _scsih_block_io_to_children_attached_to_ex
3027 * @ioc: per adapter object
3028 * @sas_expander: the sas_device object
3030 * This routine set sdev state to SDEV_BLOCK for all devices
3031 * attached to this expander. This function called when expander is
3035 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
3036 struct _sas_node
*sas_expander
)
3038 struct _sas_port
*mpt2sas_port
;
3039 struct _sas_device
*sas_device
;
3040 struct _sas_node
*expander_sibling
;
3041 unsigned long flags
;
3046 list_for_each_entry(mpt2sas_port
,
3047 &sas_expander
->sas_port_list
, port_list
) {
3048 if (mpt2sas_port
->remote_identify
.device_type
==
3050 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3052 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3053 mpt2sas_port
->remote_identify
.sas_address
);
3055 set_bit(sas_device
->handle
,
3056 ioc
->blocking_handles
);
3057 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3061 list_for_each_entry(mpt2sas_port
,
3062 &sas_expander
->sas_port_list
, port_list
) {
3064 if (mpt2sas_port
->remote_identify
.device_type
==
3065 SAS_EDGE_EXPANDER_DEVICE
||
3066 mpt2sas_port
->remote_identify
.device_type
==
3067 SAS_FANOUT_EXPANDER_DEVICE
) {
3069 mpt2sas_scsih_expander_find_by_sas_address(
3070 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
3071 _scsih_block_io_to_children_attached_to_ex(ioc
,
3078 * _scsih_block_io_to_children_attached_directly
3079 * @ioc: per adapter object
3080 * @event_data: topology change event data
3082 * This routine set sdev state to SDEV_BLOCK for all devices
3083 * direct attached during device pull.
3086 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
3087 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3094 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3095 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3098 phy_number
= event_data
->StartPhyNum
+ i
;
3099 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3100 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3101 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3102 _scsih_block_io_device(ioc
, handle
);
3107 * _scsih_tm_tr_send - send task management request
3108 * @ioc: per adapter object
3109 * @handle: device handle
3110 * Context: interrupt time.
3112 * This code is to initiate the device removal handshake protocol
3113 * with controller firmware. This function will issue target reset
3114 * using high priority request queue. It will send a sas iounit
3115 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3117 * This is designed to send muliple task management request at the same
3118 * time to the fifo. If the fifo is full, we will append the request,
3119 * and process it in a future completion.
3122 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3124 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3126 struct _sas_device
*sas_device
;
3127 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
3128 u64 sas_address
= 0;
3129 unsigned long flags
;
3130 struct _tr_list
*delayed_tr
;
3133 if (ioc
->remove_host
) {
3134 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3135 "removed: handle(0x%04x)\n", __func__
, ioc
->name
, handle
));
3137 } else if (ioc
->pci_error_recovery
) {
3138 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3139 "error recovery: handle(0x%04x)\n", __func__
, ioc
->name
,
3143 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3144 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3145 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3146 "operational: handle(0x%04x)\n", __func__
, ioc
->name
,
3151 /* if PD, then return */
3152 if (test_bit(handle
, ioc
->pd_handles
))
3155 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3156 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3157 if (sas_device
&& sas_device
->starget
&&
3158 sas_device
->starget
->hostdata
) {
3159 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3160 sas_target_priv_data
->deleted
= 1;
3161 sas_address
= sas_device
->sas_address
;
3163 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3165 if (sas_target_priv_data
) {
3166 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"setting delete flag: "
3167 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, handle
,
3168 (unsigned long long)sas_address
));
3169 _scsih_ublock_io_device(ioc
, sas_address
);
3170 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
3173 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3175 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3178 INIT_LIST_HEAD(&delayed_tr
->list
);
3179 delayed_tr
->handle
= handle
;
3180 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3181 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3182 "DELAYED:tr:handle(0x%04x), (open)\n",
3183 ioc
->name
, handle
));
3187 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3188 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3189 ioc
->tm_tr_cb_idx
));
3190 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3191 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3192 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3193 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3194 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3195 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3201 * _scsih_sas_control_complete - completion routine
3202 * @ioc: per adapter object
3203 * @smid: system request message index
3204 * @msix_index: MSIX table index supplied by the OS
3205 * @reply: reply message frame(lower 32bit addr)
3206 * Context: interrupt time.
3208 * This is the sas iounit control completion routine.
3209 * This code is part of the code to initiate the device removal
3210 * handshake protocol with controller firmware.
3212 * Return 1 meaning mf should be freed from _base_interrupt
3213 * 0 means the mf is freed from this function.
3216 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3217 u8 msix_index
, u32 reply
)
3219 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3220 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3221 if (likely(mpi_reply
)) {
3222 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3223 "sc_complete:handle(0x%04x), (open) "
3224 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3225 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3226 le16_to_cpu(mpi_reply
->IOCStatus
),
3227 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3229 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3230 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3236 * _scsih_tm_tr_volume_send - send target reset request for volumes
3237 * @ioc: per adapter object
3238 * @handle: device handle
3239 * Context: interrupt time.
3241 * This is designed to send muliple task management request at the same
3242 * time to the fifo. If the fifo is full, we will append the request,
3243 * and process it in a future completion.
3246 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3248 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3250 struct _tr_list
*delayed_tr
;
3252 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3253 ioc
->pci_error_recovery
) {
3254 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3255 "progress!\n", __func__
, ioc
->name
));
3259 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3261 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3264 INIT_LIST_HEAD(&delayed_tr
->list
);
3265 delayed_tr
->handle
= handle
;
3266 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3267 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3268 "DELAYED:tr:handle(0x%04x), (open)\n",
3269 ioc
->name
, handle
));
3273 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3274 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3275 ioc
->tm_tr_volume_cb_idx
));
3276 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3277 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3278 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3279 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3280 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3281 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3285 * _scsih_tm_volume_tr_complete - target reset completion
3286 * @ioc: per adapter object
3287 * @smid: system request message index
3288 * @msix_index: MSIX table index supplied by the OS
3289 * @reply: reply message frame(lower 32bit addr)
3290 * Context: interrupt time.
3292 * Return 1 meaning mf should be freed from _base_interrupt
3293 * 0 means the mf is freed from this function.
3296 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3297 u8 msix_index
, u32 reply
)
3300 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3301 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3302 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3304 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3305 ioc
->pci_error_recovery
) {
3306 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3307 "progress!\n", __func__
, ioc
->name
));
3310 if (unlikely(!mpi_reply
)) {
3311 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3312 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3315 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3316 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3317 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3318 dewtprintk(ioc
, printk("spurious interrupt: "
3319 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
3320 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3324 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3325 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3326 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3327 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3328 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3329 le32_to_cpu(mpi_reply
->TerminationCount
)));
3331 return _scsih_check_for_pending_tm(ioc
, smid
);
3335 * _scsih_tm_tr_complete -
3336 * @ioc: per adapter object
3337 * @smid: system request message index
3338 * @msix_index: MSIX table index supplied by the OS
3339 * @reply: reply message frame(lower 32bit addr)
3340 * Context: interrupt time.
3342 * This is the target reset completion routine.
3343 * This code is part of the code to initiate the device removal
3344 * handshake protocol with controller firmware.
3345 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3347 * Return 1 meaning mf should be freed from _base_interrupt
3348 * 0 means the mf is freed from this function.
3351 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3355 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3356 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3357 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3358 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3362 if (ioc
->remove_host
) {
3363 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3364 "removed\n", __func__
, ioc
->name
));
3366 } else if (ioc
->pci_error_recovery
) {
3367 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3368 "error recovery\n", __func__
, ioc
->name
));
3371 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3372 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3373 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3374 "operational\n", __func__
, ioc
->name
));
3377 if (unlikely(!mpi_reply
)) {
3378 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3379 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3382 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3383 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3384 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3385 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
3386 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
3387 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3391 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3392 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3393 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3394 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3395 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3396 le32_to_cpu(mpi_reply
->TerminationCount
)));
3398 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3399 if (!smid_sas_ctrl
) {
3400 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3401 ioc
->name
, __func__
);
3405 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
3406 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
3407 ioc
->tm_sas_control_cb_idx
));
3408 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3409 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3410 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3411 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3412 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3413 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3415 return _scsih_check_for_pending_tm(ioc
, smid
);
3419 * _scsih_check_for_pending_tm - check for pending task management
3420 * @ioc: per adapter object
3421 * @smid: system request message index
3423 * This will check delayed target reset list, and feed the
3426 * Return 1 meaning mf should be freed from _base_interrupt
3427 * 0 means the mf is freed from this function.
3430 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3432 struct _tr_list
*delayed_tr
;
3434 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3435 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3436 struct _tr_list
, list
);
3437 mpt2sas_base_free_smid(ioc
, smid
);
3438 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3439 list_del(&delayed_tr
->list
);
3444 if (!list_empty(&ioc
->delayed_tr_list
)) {
3445 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3446 struct _tr_list
, list
);
3447 mpt2sas_base_free_smid(ioc
, smid
);
3448 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3449 list_del(&delayed_tr
->list
);
3458 * _scsih_check_topo_delete_events - sanity check on topo events
3459 * @ioc: per adapter object
3460 * @event_data: the event data payload
3462 * This routine added to better handle cable breaker.
3464 * This handles the case where driver receives multiple expander
3465 * add and delete events in a single shot. When there is a delete event
3466 * the routine will void any pending add events waiting in the event queue.
3471 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3472 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3474 struct fw_event_work
*fw_event
;
3475 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3476 u16 expander_handle
;
3477 struct _sas_node
*sas_expander
;
3478 unsigned long flags
;
3482 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3483 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3486 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3487 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3488 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3489 _scsih_tm_tr_send(ioc
, handle
);
3492 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3493 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3494 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3497 if (event_data
->ExpStatus
==
3498 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3499 /* put expander attached devices into blocking state */
3500 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3501 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3503 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3504 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3506 handle
= find_first_bit(ioc
->blocking_handles
,
3507 ioc
->facts
.MaxDevHandle
);
3508 if (handle
< ioc
->facts
.MaxDevHandle
)
3509 _scsih_block_io_device(ioc
, handle
);
3510 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3511 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3512 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3514 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3517 /* mark ignore flag for pending events */
3518 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3519 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3520 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3523 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3524 fw_event
->event_data
;
3525 if (local_event_data
->ExpStatus
==
3526 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3527 local_event_data
->ExpStatus
==
3528 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3529 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3531 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3532 "setting ignoring flag\n", ioc
->name
));
3533 fw_event
->ignore
= 1;
3537 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3541 * _scsih_set_volume_delete_flag - setting volume delete flag
3542 * @ioc: per adapter object
3543 * @handle: device handle
3549 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3551 struct _raid_device
*raid_device
;
3552 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3553 unsigned long flags
;
3555 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3556 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3557 if (raid_device
&& raid_device
->starget
&&
3558 raid_device
->starget
->hostdata
) {
3559 sas_target_priv_data
=
3560 raid_device
->starget
->hostdata
;
3561 sas_target_priv_data
->deleted
= 1;
3562 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3563 "setting delete flag: handle(0x%04x), "
3564 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3565 (unsigned long long) raid_device
->wwid
));
3567 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3571 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3572 * @handle: input handle
3573 * @a: handle for volume a
3574 * @b: handle for volume b
3576 * IR firmware only supports two raid volumes. The purpose of this
3577 * routine is to set the volume handle in either a or b. When the given
3578 * input handle is non-zero, or when a and b have not been set before.
3581 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3583 if (!handle
|| handle
== *a
|| handle
== *b
)
3592 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3593 * @ioc: per adapter object
3594 * @event_data: the event data payload
3595 * Context: interrupt time.
3597 * This routine will send target reset to volume, followed by target
3598 * resets to the PDs. This is called when a PD has been removed, or
3599 * volume has been deleted or removed. When the target reset is sent
3600 * to volume, the PD target resets need to be queued to start upon
3601 * completion of the volume target reset.
3606 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3607 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3609 Mpi2EventIrConfigElement_t
*element
;
3611 u16 handle
, volume_handle
, a
, b
;
3612 struct _tr_list
*delayed_tr
;
3617 if (ioc
->is_warpdrive
)
3620 /* Volume Resets for Deleted or Removed */
3621 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3622 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3623 if (element
->ReasonCode
==
3624 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3625 element
->ReasonCode
==
3626 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3627 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3628 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3629 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3633 /* Volume Resets for UNHIDE events */
3634 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3635 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3636 if (le32_to_cpu(event_data
->Flags
) &
3637 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3639 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3640 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3641 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3646 _scsih_tm_tr_volume_send(ioc
, a
);
3648 _scsih_tm_tr_volume_send(ioc
, b
);
3650 /* PD target resets */
3651 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3652 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3653 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3655 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3656 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3657 clear_bit(handle
, ioc
->pd_handles
);
3659 _scsih_tm_tr_send(ioc
, handle
);
3660 else if (volume_handle
== a
|| volume_handle
== b
) {
3661 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3662 BUG_ON(!delayed_tr
);
3663 INIT_LIST_HEAD(&delayed_tr
->list
);
3664 delayed_tr
->handle
= handle
;
3665 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3666 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3667 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3670 _scsih_tm_tr_send(ioc
, handle
);
3676 * _scsih_check_volume_delete_events - set delete flag for volumes
3677 * @ioc: per adapter object
3678 * @event_data: the event data payload
3679 * Context: interrupt time.
3681 * This will handle the case when the cable connected to entire volume is
3682 * pulled. We will take care of setting the deleted flag so normal IO will
3688 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3689 Mpi2EventDataIrVolume_t
*event_data
)
3693 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3695 state
= le32_to_cpu(event_data
->NewValue
);
3696 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3697 MPI2_RAID_VOL_STATE_FAILED
)
3698 _scsih_set_volume_delete_flag(ioc
,
3699 le16_to_cpu(event_data
->VolDevHandle
));
3703 * _scsih_flush_running_cmds - completing outstanding commands.
3704 * @ioc: per adapter object
3706 * The flushing out of all pending scmd commands following host reset,
3707 * where all IO is dropped to the floor.
3712 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3714 struct scsi_cmnd
*scmd
;
3718 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3719 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3723 mpt2sas_base_free_smid(ioc
, smid
);
3724 scsi_dma_unmap(scmd
);
3725 if (ioc
->pci_error_recovery
)
3726 scmd
->result
= DID_NO_CONNECT
<< 16;
3728 scmd
->result
= DID_RESET
<< 16;
3729 scmd
->scsi_done(scmd
);
3731 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3736 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3737 * @scmd: pointer to scsi command object
3738 * @mpi_request: pointer to the SCSI_IO reqest message frame
3740 * Supporting protection 1 and 3.
3745 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3748 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3749 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3751 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3754 if (prot_op
== SCSI_PROT_READ_STRIP
)
3755 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3756 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3757 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3761 switch (prot_type
) {
3762 case SCSI_PROT_DIF_TYPE1
:
3763 case SCSI_PROT_DIF_TYPE2
:
3766 * enable ref/guard checking
3767 * auto increment ref tag
3769 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3770 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3771 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3772 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3773 cpu_to_be32(scsi_get_lba(scmd
));
3776 case SCSI_PROT_DIF_TYPE3
:
3779 * enable guard checking
3781 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3784 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3785 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3789 * _scsih_eedp_error_handling - return sense code for EEDP errors
3790 * @scmd: pointer to scsi command object
3791 * @ioc_status: ioc status
3796 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3800 switch (ioc_status
) {
3801 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3804 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3807 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3815 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10, ascq
);
3816 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
3817 SAM_STAT_CHECK_CONDITION
;
3821 * _scsih_scsi_direct_io_get - returns direct io flag
3822 * @ioc: per adapter object
3823 * @smid: system request message index
3825 * Returns the smid stored scmd pointer.
3828 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3830 return ioc
->scsi_lookup
[smid
- 1].direct_io
;
3834 * _scsih_scsi_direct_io_set - sets direct io flag
3835 * @ioc: per adapter object
3836 * @smid: system request message index
3837 * @direct_io: Zero or non-zero value to set in the direct_io flag
3842 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 direct_io
)
3844 ioc
->scsi_lookup
[smid
- 1].direct_io
= direct_io
;
3849 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3850 * @ioc: per adapter object
3851 * @scmd: pointer to scsi command object
3852 * @raid_device: pointer to raid device data structure
3853 * @mpi_request: pointer to the SCSI_IO reqest message frame
3854 * @smid: system request message index
3859 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3860 struct _raid_device
*raid_device
, Mpi2SCSIIORequest_t
*mpi_request
,
3863 sector_t v_lba
, p_lba
, stripe_off
, stripe_unit
, column
, io_size
;
3864 u32 stripe_sz
, stripe_exp
;
3865 u8 num_pds
, cmd
= scmd
->cmnd
[0];
3867 if (cmd
!= READ_10
&& cmd
!= WRITE_10
&&
3868 cmd
!= READ_16
&& cmd
!= WRITE_16
)
3871 if (cmd
== READ_10
|| cmd
== WRITE_10
)
3872 v_lba
= get_unaligned_be32(&mpi_request
->CDB
.CDB32
[2]);
3874 v_lba
= get_unaligned_be64(&mpi_request
->CDB
.CDB32
[2]);
3876 io_size
= scsi_bufflen(scmd
) >> raid_device
->block_exponent
;
3878 if (v_lba
+ io_size
- 1 > raid_device
->max_lba
)
3881 stripe_sz
= raid_device
->stripe_sz
;
3882 stripe_exp
= raid_device
->stripe_exponent
;
3883 stripe_off
= v_lba
& (stripe_sz
- 1);
3885 /* Return unless IO falls within a stripe */
3886 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
) + stripe_off
;
3894 mpi_request
->DevHandle
= cpu_to_le16(raid_device
->pd_handle
[column
]);
3896 if (cmd
== READ_10
|| cmd
== WRITE_10
)
3897 put_unaligned_be32(lower_32_bits(p_lba
),
3898 &mpi_request
->CDB
.CDB32
[2]);
3900 put_unaligned_be64(p_lba
, &mpi_request
->CDB
.CDB32
[2]);
3902 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3906 * _scsih_qcmd - main scsi request entry point
3907 * @scmd: pointer to scsi command object
3908 * @done: function pointer to be invoked on completion
3910 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3912 * Returns 0 on success. If there's a failure, return either:
3913 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3914 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3917 _scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
3919 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
3920 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3921 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3922 struct _raid_device
*raid_device
;
3923 Mpi2SCSIIORequest_t
*mpi_request
;
3927 sas_device_priv_data
= scmd
->device
->hostdata
;
3928 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3929 scmd
->result
= DID_NO_CONNECT
<< 16;
3930 scmd
->scsi_done(scmd
);
3934 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3935 scmd
->result
= DID_NO_CONNECT
<< 16;
3936 scmd
->scsi_done(scmd
);
3940 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3941 /* invalid device handle */
3942 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3943 scmd
->result
= DID_NO_CONNECT
<< 16;
3944 scmd
->scsi_done(scmd
);
3948 /* host recovery or link resets sent via IOCTLs */
3949 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3950 return SCSI_MLQUEUE_HOST_BUSY
;
3951 /* device busy with task management */
3952 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3953 return SCSI_MLQUEUE_DEVICE_BUSY
;
3954 /* device has been deleted */
3955 else if (sas_target_priv_data
->deleted
) {
3956 scmd
->result
= DID_NO_CONNECT
<< 16;
3957 scmd
->scsi_done(scmd
);
3961 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3962 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3963 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3964 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3966 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3969 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3970 if (scmd
->device
->tagged_supported
) {
3971 if (scmd
->device
->ordered_tags
)
3972 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3974 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3976 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3978 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3979 /* Make sure Device is not raid volume.
3980 * We do not expose raid functionality to upper layer for warpdrive.
3982 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3983 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3984 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3986 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3988 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3989 ioc
->name
, __func__
);
3992 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3993 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3994 _scsih_setup_eedp(scmd
, mpi_request
);
3995 if (scmd
->cmd_len
== 32)
3996 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3997 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3998 if (sas_device_priv_data
->sas_target
->flags
&
3999 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4000 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4002 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4003 mpi_request
->DevHandle
=
4004 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4005 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4006 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4007 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4008 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4009 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4010 mpi_request
->SenseBufferLowAddress
=
4011 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
4012 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4013 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
4014 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
4015 mpi_request
->VF_ID
= 0; /* TODO */
4016 mpi_request
->VP_ID
= 0;
4017 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4019 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4021 if (!mpi_request
->DataLength
) {
4022 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4024 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
4025 mpt2sas_base_free_smid(ioc
, smid
);
4030 raid_device
= sas_target_priv_data
->raid_device
;
4031 if (raid_device
&& raid_device
->direct_io_enabled
)
4032 _scsih_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4035 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
4036 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4037 le16_to_cpu(mpi_request
->DevHandle
));
4039 mpt2sas_base_put_smid_default(ioc
, smid
);
4043 return SCSI_MLQUEUE_HOST_BUSY
;
4047 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4048 * @sense_buffer: sense data returned by target
4049 * @data: normalized skey/asc/ascq
4054 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4056 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4057 /* descriptor format */
4058 data
->skey
= sense_buffer
[1] & 0x0F;
4059 data
->asc
= sense_buffer
[2];
4060 data
->ascq
= sense_buffer
[3];
4063 data
->skey
= sense_buffer
[2] & 0x0F;
4064 data
->asc
= sense_buffer
[12];
4065 data
->ascq
= sense_buffer
[13];
4069 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4071 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4072 * @ioc: per adapter object
4073 * @scmd: pointer to scsi command object
4074 * @mpi_reply: reply mf payload returned from firmware
4076 * scsi_status - SCSI Status code returned from target device
4077 * scsi_state - state info associated with SCSI_IO determined by ioc
4078 * ioc_status - ioc supplied status info
4083 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4084 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4088 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4089 MPI2_IOCSTATUS_MASK
;
4090 u8 scsi_state
= mpi_reply
->SCSIState
;
4091 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4092 char *desc_ioc_state
= NULL
;
4093 char *desc_scsi_status
= NULL
;
4094 char *desc_scsi_state
= ioc
->tmp_string
;
4095 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4096 struct _sas_device
*sas_device
= NULL
;
4097 unsigned long flags
;
4098 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4099 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
4100 char *device_str
= NULL
;
4105 if (ioc
->hide_ir_msg
)
4106 device_str
= "WarpDrive";
4108 device_str
= "volume";
4110 if (log_info
== 0x31170000)
4113 switch (ioc_status
) {
4114 case MPI2_IOCSTATUS_SUCCESS
:
4115 desc_ioc_state
= "success";
4117 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4118 desc_ioc_state
= "invalid function";
4120 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4121 desc_ioc_state
= "scsi recovered error";
4123 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4124 desc_ioc_state
= "scsi invalid dev handle";
4126 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4127 desc_ioc_state
= "scsi device not there";
4129 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4130 desc_ioc_state
= "scsi data overrun";
4132 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4133 desc_ioc_state
= "scsi data underrun";
4135 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4136 desc_ioc_state
= "scsi io data error";
4138 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4139 desc_ioc_state
= "scsi protocol error";
4141 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4142 desc_ioc_state
= "scsi task terminated";
4144 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4145 desc_ioc_state
= "scsi residual mismatch";
4147 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4148 desc_ioc_state
= "scsi task mgmt failed";
4150 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4151 desc_ioc_state
= "scsi ioc terminated";
4153 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4154 desc_ioc_state
= "scsi ext terminated";
4156 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4157 desc_ioc_state
= "eedp guard error";
4159 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4160 desc_ioc_state
= "eedp ref tag error";
4162 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4163 desc_ioc_state
= "eedp app tag error";
4166 desc_ioc_state
= "unknown";
4170 switch (scsi_status
) {
4171 case MPI2_SCSI_STATUS_GOOD
:
4172 desc_scsi_status
= "good";
4174 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4175 desc_scsi_status
= "check condition";
4177 case MPI2_SCSI_STATUS_CONDITION_MET
:
4178 desc_scsi_status
= "condition met";
4180 case MPI2_SCSI_STATUS_BUSY
:
4181 desc_scsi_status
= "busy";
4183 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4184 desc_scsi_status
= "intermediate";
4186 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4187 desc_scsi_status
= "intermediate condmet";
4189 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4190 desc_scsi_status
= "reservation conflict";
4192 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4193 desc_scsi_status
= "command terminated";
4195 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4196 desc_scsi_status
= "task set full";
4198 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4199 desc_scsi_status
= "aca active";
4201 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4202 desc_scsi_status
= "task aborted";
4205 desc_scsi_status
= "unknown";
4209 desc_scsi_state
[0] = '\0';
4211 desc_scsi_state
= " ";
4212 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4213 strcat(desc_scsi_state
, "response info ");
4214 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4215 strcat(desc_scsi_state
, "state terminated ");
4216 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4217 strcat(desc_scsi_state
, "no status ");
4218 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4219 strcat(desc_scsi_state
, "autosense failed ");
4220 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4221 strcat(desc_scsi_state
, "autosense valid ");
4223 scsi_print_command(scmd
);
4225 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4226 printk(MPT2SAS_WARN_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4227 device_str
, (unsigned long long)priv_target
->sas_address
);
4229 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4230 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4231 priv_target
->sas_address
);
4233 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
4234 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
4236 printk(MPT2SAS_WARN_FMT
4237 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4238 ioc
->name
, sas_device
->enclosure_logical_id
,
4241 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4244 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4245 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4246 desc_ioc_state
, ioc_status
, smid
);
4247 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
4248 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4249 scsi_get_resid(scmd
));
4250 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
4251 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4252 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4253 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
4254 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
4255 scsi_status
, desc_scsi_state
, scsi_state
);
4257 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4258 struct sense_info data
;
4259 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4260 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
4261 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
4262 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4265 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4266 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4267 response_bytes
= (u8
*)&response_info
;
4268 _scsih_response_code(ioc
, response_bytes
[0]);
4274 * _scsih_turn_on_pfa_led - illuminate PFA LED
4275 * @ioc: per adapter object
4276 * @handle: device handle
4282 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4284 Mpi2SepReply_t mpi_reply
;
4285 Mpi2SepRequest_t mpi_request
;
4286 struct _sas_device
*sas_device
;
4288 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4292 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4293 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4294 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4295 mpi_request
.SlotStatus
=
4296 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4297 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4298 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4299 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4300 &mpi_request
)) != 0) {
4301 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4302 __FILE__
, __LINE__
, __func__
);
4305 sas_device
->pfa_led_on
= 1;
4308 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4309 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
4310 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4311 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4312 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4318 * _scsih_turn_off_pfa_led - turn off PFA LED
4319 * @ioc: per adapter object
4320 * @sas_device: sas device whose PFA LED has to turned off
4326 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER
*ioc
,
4327 struct _sas_device
*sas_device
)
4329 Mpi2SepReply_t mpi_reply
;
4330 Mpi2SepRequest_t mpi_request
;
4332 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4333 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4334 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4335 mpi_request
.SlotStatus
= 0;
4336 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4337 mpi_request
.DevHandle
= 0;
4338 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4339 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4340 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4341 &mpi_request
)) != 0) {
4342 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4343 __FILE__
, __LINE__
, __func__
);
4347 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4348 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
4349 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4350 le16_to_cpu(mpi_reply
.IOCStatus
),
4351 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4357 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4358 * @ioc: per adapter object
4359 * @handle: device handle
4360 * Context: interrupt.
4365 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4367 struct fw_event_work
*fw_event
;
4369 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4372 fw_event
->event
= MPT2SAS_TURN_ON_PFA_LED
;
4373 fw_event
->device_handle
= handle
;
4374 fw_event
->ioc
= ioc
;
4375 _scsih_fw_event_add(ioc
, fw_event
);
4379 * _scsih_smart_predicted_fault - process smart errors
4380 * @ioc: per adapter object
4381 * @handle: device handle
4382 * Context: interrupt.
4387 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4389 struct scsi_target
*starget
;
4390 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4391 Mpi2EventNotificationReply_t
*event_reply
;
4392 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4393 struct _sas_device
*sas_device
;
4395 unsigned long flags
;
4397 /* only handle non-raid devices */
4398 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4399 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4401 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4404 starget
= sas_device
->starget
;
4405 sas_target_priv_data
= starget
->hostdata
;
4407 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4408 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4409 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4412 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
4413 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4415 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4416 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4418 /* insert into event log */
4419 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4420 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4421 event_reply
= kzalloc(sz
, GFP_ATOMIC
);
4423 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4424 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4428 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4429 event_reply
->Event
=
4430 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4431 event_reply
->MsgLength
= sz
/4;
4432 event_reply
->EventDataLength
=
4433 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4434 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4435 event_reply
->EventData
;
4436 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4437 event_data
->ASC
= 0x5D;
4438 event_data
->DevHandle
= cpu_to_le16(handle
);
4439 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4440 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
4445 * _scsih_io_done - scsi request callback
4446 * @ioc: per adapter object
4447 * @smid: system request message index
4448 * @msix_index: MSIX table index supplied by the OS
4449 * @reply: reply message frame(lower 32bit addr)
4451 * Callback handler when using _scsih_qcmd.
4453 * Return 1 meaning mf should be freed from _base_interrupt
4454 * 0 means the mf is freed from this function.
4457 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4459 Mpi2SCSIIORequest_t
*mpi_request
;
4460 Mpi2SCSIIOReply_t
*mpi_reply
;
4461 struct scsi_cmnd
*scmd
;
4467 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4468 u32 response_code
= 0;
4469 unsigned long flags
;
4471 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4472 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4476 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4478 if (mpi_reply
== NULL
) {
4479 scmd
->result
= DID_OK
<< 16;
4483 sas_device_priv_data
= scmd
->device
->hostdata
;
4484 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4485 sas_device_priv_data
->sas_target
->deleted
) {
4486 scmd
->result
= DID_NO_CONNECT
<< 16;
4489 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4491 * WARPDRIVE: If direct_io is set then it is directIO,
4492 * the failed direct I/O should be redirected to volume
4494 if (_scsih_scsi_direct_io_get(ioc
, smid
) &&
4495 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4496 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4497 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4498 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4499 _scsih_scsi_direct_io_set(ioc
, smid
, 0);
4500 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4501 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4502 mpi_request
->DevHandle
=
4503 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4504 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4505 sas_device_priv_data
->sas_target
->handle
);
4510 /* turning off TLR */
4511 scsi_state
= mpi_reply
->SCSIState
;
4512 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4514 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4515 if (!sas_device_priv_data
->tlr_snoop_check
) {
4516 sas_device_priv_data
->tlr_snoop_check
++;
4517 /* Make sure Device is not raid volume.
4518 * We do not expose raid functionality to upper layer for warpdrive.
4520 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4521 sas_is_tlr_enabled(scmd
->device
) &&
4522 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4523 sas_disable_tlr(scmd
->device
);
4524 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4528 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4529 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4530 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4531 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4534 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4535 scsi_status
= mpi_reply
->SCSIStatus
;
4537 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4538 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4539 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4540 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4541 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4544 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4545 struct sense_info data
;
4546 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
4548 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4549 le32_to_cpu(mpi_reply
->SenseCount
));
4550 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4551 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4552 /* failure prediction threshold exceeded */
4553 if (data
.asc
== 0x5D)
4554 _scsih_smart_predicted_fault(ioc
,
4555 le16_to_cpu(mpi_reply
->DevHandle
));
4558 switch (ioc_status
) {
4559 case MPI2_IOCSTATUS_BUSY
:
4560 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4561 scmd
->result
= SAM_STAT_BUSY
;
4564 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4565 scmd
->result
= DID_NO_CONNECT
<< 16;
4568 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4569 if (sas_device_priv_data
->block
) {
4570 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4573 scmd
->result
= DID_SOFT_ERROR
<< 16;
4575 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4576 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4577 scmd
->result
= DID_RESET
<< 16;
4580 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4581 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4582 scmd
->result
= DID_SOFT_ERROR
<< 16;
4584 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4587 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4588 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4590 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4593 if (xfer_cnt
< scmd
->underflow
) {
4594 if (scsi_status
== SAM_STAT_BUSY
)
4595 scmd
->result
= SAM_STAT_BUSY
;
4597 scmd
->result
= DID_SOFT_ERROR
<< 16;
4598 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4599 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4600 scmd
->result
= DID_SOFT_ERROR
<< 16;
4601 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4602 scmd
->result
= DID_RESET
<< 16;
4603 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4604 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4605 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4606 scmd
->result
= (DRIVER_SENSE
<< 24) |
4607 SAM_STAT_CHECK_CONDITION
;
4608 scmd
->sense_buffer
[0] = 0x70;
4609 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4610 scmd
->sense_buffer
[12] = 0x20;
4611 scmd
->sense_buffer
[13] = 0;
4615 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4616 scsi_set_resid(scmd
, 0);
4617 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4618 case MPI2_IOCSTATUS_SUCCESS
:
4619 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4620 if (response_code
==
4621 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4622 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4623 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4624 scmd
->result
= DID_SOFT_ERROR
<< 16;
4625 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4626 scmd
->result
= DID_RESET
<< 16;
4629 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4630 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4631 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4632 _scsih_eedp_error_handling(scmd
, ioc_status
);
4634 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4635 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4636 case MPI2_IOCSTATUS_INVALID_SGL
:
4637 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4638 case MPI2_IOCSTATUS_INVALID_FIELD
:
4639 case MPI2_IOCSTATUS_INVALID_STATE
:
4640 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4641 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4643 scmd
->result
= DID_SOFT_ERROR
<< 16;
4648 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4649 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4650 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4654 scsi_dma_unmap(scmd
);
4655 scmd
->scsi_done(scmd
);
4660 * _scsih_sas_host_refresh - refreshing sas host object contents
4661 * @ioc: per adapter object
4664 * During port enable, fw will send topology events for every device. Its
4665 * possible that the handles may change from the previous setting, so this
4666 * code keeping handles updating if changed.
4671 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4676 Mpi2ConfigReply_t mpi_reply
;
4677 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4678 u16 attached_handle
;
4681 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4682 "updating handles for sas_host(0x%016llx)\n",
4683 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4685 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4686 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4687 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4688 if (!sas_iounit_pg0
) {
4689 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4690 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4694 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4695 sas_iounit_pg0
, sz
)) != 0)
4697 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4698 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4700 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4701 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4703 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4704 PhyData
[0].ControllerDevHandle
);
4705 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4706 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4708 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4709 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4710 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4711 attached_handle
, i
, link_rate
);
4714 kfree(sas_iounit_pg0
);
4718 * _scsih_sas_host_add - create sas host object
4719 * @ioc: per adapter object
4721 * Creating host side data object, stored in ioc->sas_hba
4726 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4729 Mpi2ConfigReply_t mpi_reply
;
4730 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4731 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4732 Mpi2SasPhyPage0_t phy_pg0
;
4733 Mpi2SasDevicePage0_t sas_device_pg0
;
4734 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4737 u16 device_missing_delay
;
4739 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4740 if (!ioc
->sas_hba
.num_phys
) {
4741 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4742 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4746 /* sas_iounit page 0 */
4747 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4748 sizeof(Mpi2SasIOUnit0PhyData_t
));
4749 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4750 if (!sas_iounit_pg0
) {
4751 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4752 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4755 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4756 sas_iounit_pg0
, sz
))) {
4757 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4758 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4761 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4762 MPI2_IOCSTATUS_MASK
;
4763 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4764 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4769 /* sas_iounit page 1 */
4770 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4771 sizeof(Mpi2SasIOUnit1PhyData_t
));
4772 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4773 if (!sas_iounit_pg1
) {
4774 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4775 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4778 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4779 sas_iounit_pg1
, sz
))) {
4780 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4781 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4784 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4785 MPI2_IOCSTATUS_MASK
;
4786 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4787 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4788 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4792 ioc
->io_missing_delay
=
4793 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4794 device_missing_delay
=
4795 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4796 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4797 ioc
->device_missing_delay
= (device_missing_delay
&
4798 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4800 ioc
->device_missing_delay
= device_missing_delay
&
4801 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4803 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4804 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4805 sizeof(struct _sas_phy
), GFP_KERNEL
);
4806 if (!ioc
->sas_hba
.phy
) {
4807 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4808 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4811 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4812 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4814 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4815 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4818 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4819 MPI2_IOCSTATUS_MASK
;
4820 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4821 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4822 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4827 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4828 PhyData
[0].ControllerDevHandle
);
4829 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4830 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4831 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4832 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4834 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4835 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4836 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4837 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4840 ioc
->sas_hba
.enclosure_handle
=
4841 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4842 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4843 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4844 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4845 (unsigned long long) ioc
->sas_hba
.sas_address
,
4846 ioc
->sas_hba
.num_phys
) ;
4848 if (ioc
->sas_hba
.enclosure_handle
) {
4849 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4851 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4852 ioc
->sas_hba
.enclosure_handle
))) {
4853 ioc
->sas_hba
.enclosure_logical_id
=
4854 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4859 kfree(sas_iounit_pg1
);
4860 kfree(sas_iounit_pg0
);
4864 * _scsih_expander_add - creating expander object
4865 * @ioc: per adapter object
4866 * @handle: expander handle
4868 * Creating expander object, stored in ioc->sas_expander_list.
4870 * Return 0 for success, else error.
4873 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4875 struct _sas_node
*sas_expander
;
4876 Mpi2ConfigReply_t mpi_reply
;
4877 Mpi2ExpanderPage0_t expander_pg0
;
4878 Mpi2ExpanderPage1_t expander_pg1
;
4879 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4882 u64 sas_address
, sas_address_parent
= 0;
4884 unsigned long flags
;
4885 struct _sas_port
*mpt2sas_port
= NULL
;
4891 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4894 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4895 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4896 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4897 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4901 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4902 MPI2_IOCSTATUS_MASK
;
4903 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4904 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4905 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4909 /* handle out of order topology events */
4910 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4911 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4913 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4914 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4917 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4918 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4919 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4920 sas_address_parent
);
4921 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4922 if (!sas_expander
) {
4923 rc
= _scsih_expander_add(ioc
, parent_handle
);
4929 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4930 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4931 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4933 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4938 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4940 if (!sas_expander
) {
4941 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4946 sas_expander
->handle
= handle
;
4947 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4948 sas_expander
->sas_address_parent
= sas_address_parent
;
4949 sas_expander
->sas_address
= sas_address
;
4951 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4952 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4953 handle
, parent_handle
, (unsigned long long)
4954 sas_expander
->sas_address
, sas_expander
->num_phys
);
4956 if (!sas_expander
->num_phys
)
4958 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4959 sizeof(struct _sas_phy
), GFP_KERNEL
);
4960 if (!sas_expander
->phy
) {
4961 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4962 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4967 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4968 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4969 sas_address_parent
);
4970 if (!mpt2sas_port
) {
4971 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4972 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4976 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4978 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4979 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4980 &expander_pg1
, i
, handle
))) {
4981 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4982 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4986 sas_expander
->phy
[i
].handle
= handle
;
4987 sas_expander
->phy
[i
].phy_id
= i
;
4989 if ((mpt2sas_transport_add_expander_phy(ioc
,
4990 &sas_expander
->phy
[i
], expander_pg1
,
4991 sas_expander
->parent_dev
))) {
4992 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4993 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4999 if (sas_expander
->enclosure_handle
) {
5000 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5001 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5002 sas_expander
->enclosure_handle
))) {
5003 sas_expander
->enclosure_logical_id
=
5004 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5008 _scsih_expander_node_add(ioc
, sas_expander
);
5014 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5015 sas_address_parent
);
5016 kfree(sas_expander
);
5021 * _scsih_done - scsih callback handler.
5022 * @ioc: per adapter object
5023 * @smid: system request message index
5024 * @msix_index: MSIX table index supplied by the OS
5025 * @reply: reply message frame(lower 32bit addr)
5027 * Callback handler when sending internal generated message frames.
5028 * The callback index passed is `ioc->scsih_cb_idx`
5030 * Return 1 meaning mf should be freed from _base_interrupt
5031 * 0 means the mf is freed from this function.
5034 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5036 MPI2DefaultReply_t
*mpi_reply
;
5038 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5039 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
5041 if (ioc
->scsih_cmds
.smid
!= smid
)
5043 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
5045 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5046 mpi_reply
->MsgLength
*4);
5047 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
5049 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
5050 complete(&ioc
->scsih_cmds
.done
);
5055 * mpt2sas_expander_remove - removing expander object
5056 * @ioc: per adapter object
5057 * @sas_address: expander sas_address
5062 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5064 struct _sas_node
*sas_expander
;
5065 unsigned long flags
;
5067 if (ioc
->shost_recovery
)
5070 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5071 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5074 list_del(&sas_expander
->list
);
5075 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5077 _scsih_expander_node_remove(ioc
, sas_expander
);
5081 * _scsih_check_access_status - check access flags
5082 * @ioc: per adapter object
5083 * @sas_address: sas address
5084 * @handle: sas device handle
5085 * @access_flags: errors returned during discovery of the device
5087 * Return 0 for success, else failure
5090 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5091 u16 handle
, u8 access_status
)
5096 switch (access_status
) {
5097 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5102 desc
= "sata capability failed";
5104 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5105 desc
= "sata affiliation conflict";
5107 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5108 desc
= "route not addressable";
5110 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5111 desc
= "smp error not addressable";
5113 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5114 desc
= "device blocked";
5116 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5117 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5118 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5119 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5120 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5121 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5122 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5123 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5124 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5125 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5126 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5127 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5128 desc
= "sata initialization failed";
5138 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
5139 "handle(0x%04x)\n", ioc
->name
, desc
,
5140 (unsigned long long)sas_address
, handle
);
5145 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5147 Mpi2ConfigReply_t mpi_reply
;
5148 Mpi2SasDevicePage0_t sas_device_pg0
;
5149 struct _sas_device
*sas_device
;
5151 unsigned long flags
;
5153 struct scsi_target
*starget
;
5154 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5158 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5159 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5162 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5163 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5166 /* check if this is end device */
5167 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5168 if (!(_scsih_is_end_device(device_info
)))
5171 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5172 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5173 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5177 printk(MPT2SAS_ERR_FMT
"device is not present "
5178 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
5179 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5183 if (unlikely(sas_device
->handle
!= handle
)) {
5184 starget
= sas_device
->starget
;
5185 sas_target_priv_data
= starget
->hostdata
;
5186 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
5187 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
5188 sas_target_priv_data
->handle
= handle
;
5189 sas_device
->handle
= handle
;
5192 /* check if device is present */
5193 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5194 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5195 printk(MPT2SAS_ERR_FMT
"device is not present "
5196 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
5197 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5201 /* check if there were any issues with discovery */
5202 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5203 sas_device_pg0
.AccessStatus
)) {
5204 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5207 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5208 _scsih_ublock_io_device(ioc
, sas_address
);
5213 * _scsih_add_device - creating sas device object
5214 * @ioc: per adapter object
5215 * @handle: sas device handle
5216 * @phy_num: phy number end device attached to
5217 * @is_pd: is this hidden raid component
5219 * Creating end device object, stored in ioc->sas_device_list.
5221 * Returns 0 for success, non-zero for failure.
5224 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
5226 Mpi2ConfigReply_t mpi_reply
;
5227 Mpi2SasDevicePage0_t sas_device_pg0
;
5228 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5229 struct _sas_device
*sas_device
;
5233 unsigned long flags
;
5235 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5236 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5237 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5238 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5242 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5243 MPI2_IOCSTATUS_MASK
;
5244 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5245 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5246 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5250 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5252 /* check if device is present */
5253 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5254 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5255 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5256 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5257 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
5258 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
5262 /* check if there were any issues with discovery */
5263 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5264 sas_device_pg0
.AccessStatus
))
5267 /* check if this is end device */
5268 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5269 if (!(_scsih_is_end_device(device_info
))) {
5270 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5271 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5276 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5277 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5279 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5284 sas_device
= kzalloc(sizeof(struct _sas_device
),
5287 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5288 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5292 sas_device
->handle
= handle
;
5293 if (_scsih_get_sas_address(ioc
, le16_to_cpu
5294 (sas_device_pg0
.ParentDevHandle
),
5295 &sas_device
->sas_address_parent
) != 0)
5296 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5297 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5298 sas_device
->enclosure_handle
=
5299 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5301 le16_to_cpu(sas_device_pg0
.Slot
);
5302 sas_device
->device_info
= device_info
;
5303 sas_device
->sas_address
= sas_address
;
5304 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5306 /* get enclosure_logical_id */
5307 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
5308 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5309 sas_device
->enclosure_handle
)))
5310 sas_device
->enclosure_logical_id
=
5311 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5313 /* get device name */
5314 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5316 if (ioc
->wait_for_discovery_to_complete
)
5317 _scsih_sas_device_init_add(ioc
, sas_device
);
5319 _scsih_sas_device_add(ioc
, sas_device
);
5325 * _scsih_remove_device - removing sas device object
5326 * @ioc: per adapter object
5327 * @sas_device_delete: the sas_device object
5332 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
5333 struct _sas_device
*sas_device
)
5335 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5337 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5338 (sas_device
->pfa_led_on
)) {
5339 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5340 sas_device
->pfa_led_on
= 0;
5343 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
5344 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5345 sas_device
->handle
, (unsigned long long)
5346 sas_device
->sas_address
));
5348 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5349 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5350 sas_target_priv_data
->deleted
= 1;
5351 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5352 sas_target_priv_data
->handle
=
5353 MPT2SAS_INVALID_DEVICE_HANDLE
;
5356 if (!ioc
->hide_drives
)
5357 mpt2sas_transport_port_remove(ioc
,
5358 sas_device
->sas_address
,
5359 sas_device
->sas_address_parent
);
5361 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
5362 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
5363 (unsigned long long) sas_device
->sas_address
);
5365 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
5366 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5367 sas_device
->handle
, (unsigned long long)
5368 sas_device
->sas_address
));
5372 * _scsih_device_remove_by_handle - removing device object by handle
5373 * @ioc: per adapter object
5374 * @handle: device handle
5379 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5381 struct _sas_device
*sas_device
;
5382 unsigned long flags
;
5384 if (ioc
->shost_recovery
)
5387 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5388 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5390 list_del(&sas_device
->list
);
5391 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5393 _scsih_remove_device(ioc
, sas_device
);
5397 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5398 * @ioc: per adapter object
5399 * @sas_address: device sas_address
5404 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
5407 struct _sas_device
*sas_device
;
5408 unsigned long flags
;
5410 if (ioc
->shost_recovery
)
5413 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5414 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5417 list_del(&sas_device
->list
);
5418 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5420 _scsih_remove_device(ioc
, sas_device
);
5422 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5424 * _scsih_sas_topology_change_event_debug - debug for topology event
5425 * @ioc: per adapter object
5426 * @event_data: event data payload
5430 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5431 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5437 char *status_str
= NULL
;
5438 u8 link_rate
, prev_link_rate
;
5440 switch (event_data
->ExpStatus
) {
5441 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5444 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5445 status_str
= "remove";
5447 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5449 status_str
= "responding";
5451 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5452 status_str
= "remove delay";
5455 status_str
= "unknown status";
5458 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
5459 ioc
->name
, status_str
);
5460 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
5461 "start_phy(%02d), count(%d)\n",
5462 le16_to_cpu(event_data
->ExpanderDevHandle
),
5463 le16_to_cpu(event_data
->EnclosureHandle
),
5464 event_data
->StartPhyNum
, event_data
->NumEntries
);
5465 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5466 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5469 phy_number
= event_data
->StartPhyNum
+ i
;
5470 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5471 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5472 switch (reason_code
) {
5473 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5474 status_str
= "target add";
5476 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5477 status_str
= "target remove";
5479 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5480 status_str
= "delay target remove";
5482 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5483 status_str
= "link rate change";
5485 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5486 status_str
= "target responding";
5489 status_str
= "unknown";
5492 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5493 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5494 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
5495 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5496 handle
, status_str
, link_rate
, prev_link_rate
);
5503 * _scsih_sas_topology_change_event - handle topology changes
5504 * @ioc: per adapter object
5505 * @fw_event: The fw_event_work object
5510 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5511 struct fw_event_work
*fw_event
)
5514 u16 parent_handle
, handle
;
5516 u8 phy_number
, max_phys
;
5517 struct _sas_node
*sas_expander
;
5519 unsigned long flags
;
5520 u8 link_rate
, prev_link_rate
;
5521 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5522 (Mpi2EventDataSasTopologyChangeList_t
*)
5523 fw_event
->event_data
;
5525 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5526 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5527 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5530 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5533 if (!ioc
->sas_hba
.num_phys
)
5534 _scsih_sas_host_add(ioc
);
5536 _scsih_sas_host_refresh(ioc
);
5538 if (fw_event
->ignore
) {
5539 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
5540 "event\n", ioc
->name
));
5544 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5546 /* handle expander add */
5547 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5548 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5551 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5552 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
5555 sas_address
= sas_expander
->sas_address
;
5556 max_phys
= sas_expander
->num_phys
;
5557 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5558 sas_address
= ioc
->sas_hba
.sas_address
;
5559 max_phys
= ioc
->sas_hba
.num_phys
;
5561 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5564 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5566 /* handle siblings events */
5567 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5568 if (fw_event
->ignore
) {
5569 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
5570 "expander event\n", ioc
->name
));
5573 if (ioc
->shost_recovery
|| ioc
->remove_host
||
5574 ioc
->pci_error_recovery
)
5576 phy_number
= event_data
->StartPhyNum
+ i
;
5577 if (phy_number
>= max_phys
)
5579 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5580 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5581 if ((event_data
->PHY
[i
].PhyStatus
&
5582 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5583 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5585 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5588 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5589 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5590 switch (reason_code
) {
5591 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5593 if (ioc
->shost_recovery
)
5596 if (link_rate
== prev_link_rate
)
5599 mpt2sas_transport_update_links(ioc
, sas_address
,
5600 handle
, phy_number
, link_rate
);
5602 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5605 _scsih_check_device(ioc
, handle
);
5607 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5609 if (ioc
->shost_recovery
)
5612 mpt2sas_transport_update_links(ioc
, sas_address
,
5613 handle
, phy_number
, link_rate
);
5615 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5617 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5619 _scsih_device_remove_by_handle(ioc
, handle
);
5624 /* handle expander removal */
5625 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5627 mpt2sas_expander_remove(ioc
, sas_address
);
5631 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5633 * _scsih_sas_device_status_change_event_debug - debug for device event
5634 * @event_data: event data payload
5640 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5641 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5643 char *reason_str
= NULL
;
5645 switch (event_data
->ReasonCode
) {
5646 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5647 reason_str
= "smart data";
5649 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5650 reason_str
= "unsupported device discovered";
5652 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5653 reason_str
= "internal device reset";
5655 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5656 reason_str
= "internal task abort";
5658 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5659 reason_str
= "internal task abort set";
5661 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5662 reason_str
= "internal clear task set";
5664 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5665 reason_str
= "internal query task";
5667 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5668 reason_str
= "sata init failure";
5670 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5671 reason_str
= "internal device reset complete";
5673 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5674 reason_str
= "internal task abort complete";
5676 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5677 reason_str
= "internal async notification";
5679 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5680 reason_str
= "expander reduced functionality";
5682 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5683 reason_str
= "expander reduced functionality complete";
5686 reason_str
= "unknown reason";
5689 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5690 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5691 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5692 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5693 le16_to_cpu(event_data
->TaskTag
));
5694 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5695 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5696 event_data
->ASC
, event_data
->ASCQ
);
5697 printk(KERN_INFO
"\n");
5702 * _scsih_sas_device_status_change_event - handle device status change
5703 * @ioc: per adapter object
5704 * @fw_event: The fw_event_work object
5710 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5711 struct fw_event_work
*fw_event
)
5713 struct MPT2SAS_TARGET
*target_priv_data
;
5714 struct _sas_device
*sas_device
;
5716 unsigned long flags
;
5717 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5718 (Mpi2EventDataSasDeviceStatusChange_t
*)
5719 fw_event
->event_data
;
5721 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5722 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5723 _scsih_sas_device_status_change_event_debug(ioc
,
5727 /* In MPI Revision K (0xC), the internal device reset complete was
5728 * implemented, so avoid setting tm_busy flag for older firmware.
5730 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5733 if (event_data
->ReasonCode
!=
5734 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5735 event_data
->ReasonCode
!=
5736 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5739 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5740 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5741 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5744 if (!sas_device
|| !sas_device
->starget
) {
5745 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5749 target_priv_data
= sas_device
->starget
->hostdata
;
5750 if (!target_priv_data
) {
5751 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5755 if (event_data
->ReasonCode
==
5756 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5757 target_priv_data
->tm_busy
= 1;
5759 target_priv_data
->tm_busy
= 0;
5760 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5763 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5765 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5766 * @ioc: per adapter object
5767 * @event_data: event data payload
5773 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5774 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5776 char *reason_str
= NULL
;
5778 switch (event_data
->ReasonCode
) {
5779 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5780 reason_str
= "enclosure add";
5782 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5783 reason_str
= "enclosure remove";
5786 reason_str
= "unknown reason";
5790 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5791 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5792 " number slots(%d)\n", ioc
->name
, reason_str
,
5793 le16_to_cpu(event_data
->EnclosureHandle
),
5794 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5795 le16_to_cpu(event_data
->StartSlot
));
5800 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5801 * @ioc: per adapter object
5802 * @fw_event: The fw_event_work object
5808 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5809 struct fw_event_work
*fw_event
)
5811 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5812 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5813 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5814 (Mpi2EventDataSasEnclDevStatusChange_t
*)
5815 fw_event
->event_data
);
5820 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5821 * @ioc: per adapter object
5822 * @fw_event: The fw_event_work object
5828 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER
*ioc
,
5829 struct fw_event_work
*fw_event
)
5831 struct scsi_cmnd
*scmd
;
5832 struct scsi_device
*sdev
;
5835 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5836 u32 termination_count
;
5838 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5839 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
5840 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5841 fw_event
->event_data
;
5843 unsigned long flags
;
5846 u8 task_abort_retries
;
5848 mutex_lock(&ioc
->tm_cmds
.mutex
);
5850 "%s: enter: phy number(%d), width(%d)\n",
5851 ioc
->name
, __func__
, event_data
->PhyNum
,
5852 event_data
->PortWidth
);
5854 _scsih_block_io_all_device(ioc
);
5856 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5857 mpi_reply
= ioc
->tm_cmds
.reply
;
5858 broadcast_aen_retry
:
5860 /* sanity checks for retrying this loop */
5861 if (max_retries
++ == 5) {
5862 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: giving up\n",
5863 ioc
->name
, __func__
));
5865 } else if (max_retries
> 1)
5866 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %d retry\n",
5867 ioc
->name
, __func__
, max_retries
- 1));
5869 termination_count
= 0;
5871 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5872 if (ioc
->shost_recovery
)
5874 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5877 sdev
= scmd
->device
;
5878 sas_device_priv_data
= sdev
->hostdata
;
5879 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5881 /* skip hidden raid components */
5882 if (sas_device_priv_data
->sas_target
->flags
&
5883 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5886 if (sas_device_priv_data
->sas_target
->flags
&
5887 MPT_TARGET_FLAGS_VOLUME
)
5890 handle
= sas_device_priv_data
->sas_target
->handle
;
5891 lun
= sas_device_priv_data
->lun
;
5894 if (ioc
->shost_recovery
)
5897 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5898 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5899 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5902 sdev_printk(KERN_WARNING
, sdev
,
5903 "mpt2sas_scsih_issue_tm: FAILED when sending "
5904 "QUERY_TASK: scmd(%p)\n", scmd
);
5905 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5906 goto broadcast_aen_retry
;
5908 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5909 & MPI2_IOCSTATUS_MASK
;
5910 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5911 sdev_printk(KERN_WARNING
, sdev
, "query task: FAILED "
5912 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status
,
5914 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5915 goto broadcast_aen_retry
;
5918 /* see if IO is still owned by IOC and target */
5919 if (mpi_reply
->ResponseCode
==
5920 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5921 mpi_reply
->ResponseCode
==
5922 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5923 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5926 task_abort_retries
= 0;
5928 if (task_abort_retries
++ == 60) {
5929 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5930 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5932 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5933 goto broadcast_aen_retry
;
5936 if (ioc
->shost_recovery
)
5939 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5940 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5943 sdev_printk(KERN_WARNING
, sdev
,
5944 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5945 "scmd(%p)\n", scmd
);
5949 if (task_abort_retries
> 1)
5950 sdev_printk(KERN_WARNING
, sdev
,
5951 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5953 task_abort_retries
- 1, scmd
);
5955 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5956 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5959 if (ioc
->broadcast_aen_pending
) {
5960 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: loop back due to"
5961 " pending AEN\n", ioc
->name
, __func__
));
5962 ioc
->broadcast_aen_pending
= 0;
5963 goto broadcast_aen_retry
;
5967 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5970 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5971 "%s - exit, query_count = %d termination_count = %d\n",
5972 ioc
->name
, __func__
, query_count
, termination_count
));
5974 ioc
->broadcast_aen_busy
= 0;
5975 if (!ioc
->shost_recovery
)
5976 _scsih_ublock_io_all_device(ioc
);
5977 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5981 * _scsih_sas_discovery_event - handle discovery events
5982 * @ioc: per adapter object
5983 * @fw_event: The fw_event_work object
5989 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5990 struct fw_event_work
*fw_event
)
5992 Mpi2EventDataSasDiscovery_t
*event_data
=
5993 (Mpi2EventDataSasDiscovery_t
*)
5994 fw_event
->event_data
;
5996 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5997 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5998 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5999 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
6001 if (event_data
->DiscoveryStatus
)
6002 printk("discovery_status(0x%08x)",
6003 le32_to_cpu(event_data
->DiscoveryStatus
));
6008 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
6009 !ioc
->sas_hba
.num_phys
) {
6010 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
6011 /* Wait for the reset to complete */
6012 while (ioc
->shost_recovery
)
6015 _scsih_sas_host_add(ioc
);
6020 * _scsih_reprobe_lun - reprobing lun
6021 * @sdev: scsi device struct
6022 * @no_uld_attach: sdev->no_uld_attach flag setting
6026 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6030 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6031 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6032 sdev
->no_uld_attach
? "hidding" : "exposing");
6033 rc
= scsi_device_reprobe(sdev
);
6037 * _scsih_sas_volume_add - add new volume
6038 * @ioc: per adapter object
6039 * @element: IR config element data
6045 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
6046 Mpi2EventIrConfigElement_t
*element
)
6048 struct _raid_device
*raid_device
;
6049 unsigned long flags
;
6051 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6054 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6056 printk(MPT2SAS_ERR_FMT
6057 "failure at %s:%d/%s()!\n", ioc
->name
,
6058 __FILE__
, __LINE__
, __func__
);
6062 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6063 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6064 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6069 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6071 printk(MPT2SAS_ERR_FMT
6072 "failure at %s:%d/%s()!\n", ioc
->name
,
6073 __FILE__
, __LINE__
, __func__
);
6077 raid_device
->id
= ioc
->sas_id
++;
6078 raid_device
->channel
= RAID_CHANNEL
;
6079 raid_device
->handle
= handle
;
6080 raid_device
->wwid
= wwid
;
6081 _scsih_raid_device_add(ioc
, raid_device
);
6082 if (!ioc
->wait_for_discovery_to_complete
) {
6083 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6084 raid_device
->id
, 0);
6086 _scsih_raid_device_remove(ioc
, raid_device
);
6088 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6089 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6090 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6095 * _scsih_sas_volume_delete - delete volume
6096 * @ioc: per adapter object
6097 * @handle: volume device handle
6103 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
6105 struct _raid_device
*raid_device
;
6106 unsigned long flags
;
6107 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6108 struct scsi_target
*starget
= NULL
;
6110 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6111 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6113 if (raid_device
->starget
) {
6114 starget
= raid_device
->starget
;
6115 sas_target_priv_data
= starget
->hostdata
;
6116 sas_target_priv_data
->deleted
= 1;
6118 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6119 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6120 (unsigned long long) raid_device
->wwid
);
6121 list_del(&raid_device
->list
);
6124 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6126 scsi_remove_target(&starget
->dev
);
6130 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6131 * @ioc: per adapter object
6132 * @element: IR config element data
6138 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
6139 Mpi2EventIrConfigElement_t
*element
)
6141 struct _sas_device
*sas_device
;
6142 struct scsi_target
*starget
= NULL
;
6143 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6144 unsigned long flags
;
6145 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6147 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6148 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6150 sas_device
->volume_handle
= 0;
6151 sas_device
->volume_wwid
= 0;
6152 clear_bit(handle
, ioc
->pd_handles
);
6153 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6154 starget
= sas_device
->starget
;
6155 sas_target_priv_data
= starget
->hostdata
;
6156 sas_target_priv_data
->flags
&=
6157 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6160 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6164 /* exposing raid component */
6166 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6170 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6171 * @ioc: per adapter object
6172 * @element: IR config element data
6178 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
6179 Mpi2EventIrConfigElement_t
*element
)
6181 struct _sas_device
*sas_device
;
6182 struct scsi_target
*starget
= NULL
;
6183 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6184 unsigned long flags
;
6185 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6186 u16 volume_handle
= 0;
6187 u64 volume_wwid
= 0;
6189 mpt2sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6191 mpt2sas_config_get_volume_wwid(ioc
, volume_handle
,
6194 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6195 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6197 set_bit(handle
, ioc
->pd_handles
);
6198 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6199 starget
= sas_device
->starget
;
6200 sas_target_priv_data
= starget
->hostdata
;
6201 sas_target_priv_data
->flags
|=
6202 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6203 sas_device
->volume_handle
= volume_handle
;
6204 sas_device
->volume_wwid
= volume_wwid
;
6207 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6211 /* hiding raid component */
6213 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6217 * _scsih_sas_pd_delete - delete pd component
6218 * @ioc: per adapter object
6219 * @element: IR config element data
6225 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
6226 Mpi2EventIrConfigElement_t
*element
)
6228 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6230 _scsih_device_remove_by_handle(ioc
, handle
);
6234 * _scsih_sas_pd_add - remove pd component
6235 * @ioc: per adapter object
6236 * @element: IR config element data
6242 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
6243 Mpi2EventIrConfigElement_t
*element
)
6245 struct _sas_device
*sas_device
;
6246 unsigned long flags
;
6247 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6248 Mpi2ConfigReply_t mpi_reply
;
6249 Mpi2SasDevicePage0_t sas_device_pg0
;
6254 set_bit(handle
, ioc
->pd_handles
);
6256 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6257 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6258 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6262 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6263 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6264 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6265 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6269 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6270 MPI2_IOCSTATUS_MASK
;
6271 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6272 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6273 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6277 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6278 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6279 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6280 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6282 _scsih_add_device(ioc
, handle
, 0, 1);
6285 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6287 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6288 * @ioc: per adapter object
6289 * @event_data: event data payload
6295 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6296 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6298 Mpi2EventIrConfigElement_t
*element
;
6301 char *reason_str
= NULL
, *element_str
= NULL
;
6303 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6305 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
6306 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6307 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6308 "foreign" : "native", event_data
->NumElements
);
6309 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6310 switch (element
->ReasonCode
) {
6311 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6314 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6315 reason_str
= "remove";
6317 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6318 reason_str
= "no change";
6320 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6321 reason_str
= "hide";
6323 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6324 reason_str
= "unhide";
6326 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6327 reason_str
= "volume_created";
6329 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6330 reason_str
= "volume_deleted";
6332 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6333 reason_str
= "pd_created";
6335 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6336 reason_str
= "pd_deleted";
6339 reason_str
= "unknown reason";
6342 element_type
= le16_to_cpu(element
->ElementFlags
) &
6343 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6344 switch (element_type
) {
6345 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6346 element_str
= "volume";
6348 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6349 element_str
= "phys disk";
6351 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6352 element_str
= "hot spare";
6355 element_str
= "unknown element";
6358 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
6359 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6360 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6361 le16_to_cpu(element
->PhysDiskDevHandle
),
6362 element
->PhysDiskNum
);
6368 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6369 * @ioc: per adapter object
6370 * @fw_event: The fw_event_work object
6376 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
6377 struct fw_event_work
*fw_event
)
6379 Mpi2EventIrConfigElement_t
*element
;
6382 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6383 (Mpi2EventDataIrConfigChangeList_t
*)
6384 fw_event
->event_data
;
6386 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6387 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6388 && !ioc
->hide_ir_msg
)
6389 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6393 if (ioc
->shost_recovery
)
6396 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6397 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6399 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6400 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6402 switch (element
->ReasonCode
) {
6403 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6404 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6405 if (!foreign_config
)
6406 _scsih_sas_volume_add(ioc
, element
);
6408 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6409 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6410 if (!foreign_config
)
6411 _scsih_sas_volume_delete(ioc
,
6412 le16_to_cpu(element
->VolDevHandle
));
6414 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6415 if (!ioc
->is_warpdrive
)
6416 _scsih_sas_pd_hide(ioc
, element
);
6418 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6419 if (!ioc
->is_warpdrive
)
6420 _scsih_sas_pd_expose(ioc
, element
);
6422 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6423 if (!ioc
->is_warpdrive
)
6424 _scsih_sas_pd_add(ioc
, element
);
6426 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6427 if (!ioc
->is_warpdrive
)
6428 _scsih_sas_pd_delete(ioc
, element
);
6435 * _scsih_sas_ir_volume_event - IR volume event
6436 * @ioc: per adapter object
6437 * @fw_event: The fw_event_work object
6443 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
6444 struct fw_event_work
*fw_event
)
6447 unsigned long flags
;
6448 struct _raid_device
*raid_device
;
6452 Mpi2EventDataIrVolume_t
*event_data
=
6453 (Mpi2EventDataIrVolume_t
*)
6454 fw_event
->event_data
;
6456 if (ioc
->shost_recovery
)
6459 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6462 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6463 state
= le32_to_cpu(event_data
->NewValue
);
6464 if (!ioc
->hide_ir_msg
)
6465 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6466 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6467 le32_to_cpu(event_data
->PreviousValue
), state
));
6470 case MPI2_RAID_VOL_STATE_MISSING
:
6471 case MPI2_RAID_VOL_STATE_FAILED
:
6472 _scsih_sas_volume_delete(ioc
, handle
);
6475 case MPI2_RAID_VOL_STATE_ONLINE
:
6476 case MPI2_RAID_VOL_STATE_DEGRADED
:
6477 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6479 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6480 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6481 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6486 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6488 printk(MPT2SAS_ERR_FMT
6489 "failure at %s:%d/%s()!\n", ioc
->name
,
6490 __FILE__
, __LINE__
, __func__
);
6494 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6496 printk(MPT2SAS_ERR_FMT
6497 "failure at %s:%d/%s()!\n", ioc
->name
,
6498 __FILE__
, __LINE__
, __func__
);
6502 raid_device
->id
= ioc
->sas_id
++;
6503 raid_device
->channel
= RAID_CHANNEL
;
6504 raid_device
->handle
= handle
;
6505 raid_device
->wwid
= wwid
;
6506 _scsih_raid_device_add(ioc
, raid_device
);
6507 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6508 raid_device
->id
, 0);
6510 _scsih_raid_device_remove(ioc
, raid_device
);
6513 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6520 * _scsih_sas_ir_physical_disk_event - PD event
6521 * @ioc: per adapter object
6522 * @fw_event: The fw_event_work object
6528 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
6529 struct fw_event_work
*fw_event
)
6531 u16 handle
, parent_handle
;
6533 struct _sas_device
*sas_device
;
6534 unsigned long flags
;
6535 Mpi2ConfigReply_t mpi_reply
;
6536 Mpi2SasDevicePage0_t sas_device_pg0
;
6538 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6539 (Mpi2EventDataIrPhysicalDisk_t
*)
6540 fw_event
->event_data
;
6543 if (ioc
->shost_recovery
)
6546 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6549 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6550 state
= le32_to_cpu(event_data
->NewValue
);
6552 if (!ioc
->hide_ir_msg
)
6553 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6554 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6555 le32_to_cpu(event_data
->PreviousValue
), state
));
6558 case MPI2_RAID_PD_STATE_ONLINE
:
6559 case MPI2_RAID_PD_STATE_DEGRADED
:
6560 case MPI2_RAID_PD_STATE_REBUILDING
:
6561 case MPI2_RAID_PD_STATE_OPTIMAL
:
6562 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6564 if (!ioc
->is_warpdrive
)
6565 set_bit(handle
, ioc
->pd_handles
);
6567 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6568 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6569 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6574 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6575 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6577 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6578 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6582 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6583 MPI2_IOCSTATUS_MASK
;
6584 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6585 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6586 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6590 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6591 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6592 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6593 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6595 _scsih_add_device(ioc
, handle
, 0, 1);
6599 case MPI2_RAID_PD_STATE_OFFLINE
:
6600 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6601 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6607 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6609 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6610 * @ioc: per adapter object
6611 * @event_data: event data payload
6617 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6618 Mpi2EventDataIrOperationStatus_t
*event_data
)
6620 char *reason_str
= NULL
;
6622 switch (event_data
->RAIDOperation
) {
6623 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6624 reason_str
= "resync";
6626 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6627 reason_str
= "online capacity expansion";
6629 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6630 reason_str
= "consistency check";
6632 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6633 reason_str
= "background init";
6635 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6636 reason_str
= "make data consistent";
6643 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
6644 "\thandle(0x%04x), percent complete(%d)\n",
6645 ioc
->name
, reason_str
,
6646 le16_to_cpu(event_data
->VolDevHandle
),
6647 event_data
->PercentComplete
);
6652 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6653 * @ioc: per adapter object
6654 * @fw_event: The fw_event_work object
6660 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
6661 struct fw_event_work
*fw_event
)
6663 Mpi2EventDataIrOperationStatus_t
*event_data
=
6664 (Mpi2EventDataIrOperationStatus_t
*)
6665 fw_event
->event_data
;
6666 static struct _raid_device
*raid_device
;
6667 unsigned long flags
;
6670 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6671 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6672 && !ioc
->hide_ir_msg
)
6673 _scsih_sas_ir_operation_status_event_debug(ioc
,
6677 /* code added for raid transport support */
6678 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6680 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6681 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6682 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6684 raid_device
->percent_complete
=
6685 event_data
->PercentComplete
;
6686 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6691 * _scsih_prep_device_scan - initialize parameters prior to device scan
6692 * @ioc: per adapter object
6694 * Set the deleted flag prior to device scan. If the device is found during
6695 * the scan, then we clear the deleted flag.
6698 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
6700 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
6701 struct scsi_device
*sdev
;
6703 shost_for_each_device(sdev
, ioc
->shost
) {
6704 sas_device_priv_data
= sdev
->hostdata
;
6705 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6706 sas_device_priv_data
->sas_target
->deleted
= 1;
6711 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6712 * @ioc: per adapter object
6713 * @sas_address: sas address
6714 * @slot: enclosure slot id
6715 * @handle: device handle
6717 * After host reset, find out whether devices are still responding.
6718 * Used in _scsi_remove_unresponsive_sas_devices.
6723 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6724 u16 slot
, u16 handle
)
6726 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
6727 struct scsi_target
*starget
;
6728 struct _sas_device
*sas_device
;
6729 unsigned long flags
;
6731 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6732 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6733 if (sas_device
->sas_address
== sas_address
&&
6734 sas_device
->slot
== slot
) {
6735 sas_device
->responding
= 1;
6736 starget
= sas_device
->starget
;
6737 if (starget
&& starget
->hostdata
) {
6738 sas_target_priv_data
= starget
->hostdata
;
6739 sas_target_priv_data
->tm_busy
= 0;
6740 sas_target_priv_data
->deleted
= 0;
6742 sas_target_priv_data
= NULL
;
6744 starget_printk(KERN_INFO
, starget
,
6745 "handle(0x%04x), sas_addr(0x%016llx), "
6746 "enclosure logical id(0x%016llx), "
6747 "slot(%d)\n", handle
,
6748 (unsigned long long)sas_device
->sas_address
,
6749 (unsigned long long)
6750 sas_device
->enclosure_logical_id
,
6752 if (sas_device
->handle
== handle
)
6754 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6755 sas_device
->handle
);
6756 sas_device
->handle
= handle
;
6757 if (sas_target_priv_data
)
6758 sas_target_priv_data
->handle
= handle
;
6763 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6767 * _scsih_search_responding_sas_devices -
6768 * @ioc: per adapter object
6770 * After host reset, find out whether devices are still responding.
6776 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6778 Mpi2SasDevicePage0_t sas_device_pg0
;
6779 Mpi2ConfigReply_t mpi_reply
;
6786 printk(MPT2SAS_INFO_FMT
"search for end-devices: start\n", ioc
->name
);
6788 if (list_empty(&ioc
->sas_device_list
))
6792 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6793 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6795 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6796 MPI2_IOCSTATUS_MASK
;
6797 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6799 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6800 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6801 if (!(_scsih_is_end_device(device_info
)))
6803 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6804 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6805 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6809 printk(MPT2SAS_INFO_FMT
"search for end-devices: complete\n",
6814 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6815 * @ioc: per adapter object
6816 * @wwid: world wide identifier for raid volume
6817 * @handle: device handle
6819 * After host reset, find out whether devices are still responding.
6820 * Used in _scsi_remove_unresponsive_raid_devices.
6825 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6828 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6829 struct scsi_target
*starget
;
6830 struct _raid_device
*raid_device
;
6831 unsigned long flags
;
6833 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6834 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6835 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6836 starget
= raid_device
->starget
;
6837 if (starget
&& starget
->hostdata
) {
6838 sas_target_priv_data
= starget
->hostdata
;
6839 sas_target_priv_data
->deleted
= 0;
6841 sas_target_priv_data
= NULL
;
6842 raid_device
->responding
= 1;
6843 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6844 starget_printk(KERN_INFO
, raid_device
->starget
,
6845 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6846 (unsigned long long)raid_device
->wwid
);
6848 * WARPDRIVE: The handles of the PDs might have changed
6849 * across the host reset so re-initialize the
6850 * required data for Direct IO
6852 _scsih_init_warpdrive_properties(ioc
, raid_device
);
6853 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6854 if (raid_device
->handle
== handle
) {
6855 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6859 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6860 raid_device
->handle
);
6861 raid_device
->handle
= handle
;
6862 if (sas_target_priv_data
)
6863 sas_target_priv_data
->handle
= handle
;
6864 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6869 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6873 * _scsih_search_responding_raid_devices -
6874 * @ioc: per adapter object
6876 * After host reset, find out whether devices are still responding.
6882 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6884 Mpi2RaidVolPage1_t volume_pg1
;
6885 Mpi2RaidVolPage0_t volume_pg0
;
6886 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6887 Mpi2ConfigReply_t mpi_reply
;
6892 if (!ioc
->ir_firmware
)
6895 printk(MPT2SAS_INFO_FMT
"search for raid volumes: start\n",
6898 if (list_empty(&ioc
->raid_device_list
))
6902 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6903 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6904 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6905 MPI2_IOCSTATUS_MASK
;
6906 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6908 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6910 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6911 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6912 sizeof(Mpi2RaidVolPage0_t
)))
6915 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6916 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6917 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6918 _scsih_mark_responding_raid_device(ioc
,
6919 le64_to_cpu(volume_pg1
.WWID
), handle
);
6922 /* refresh the pd_handles */
6923 if (!ioc
->is_warpdrive
) {
6924 phys_disk_num
= 0xFF;
6925 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6926 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6927 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6929 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6930 MPI2_IOCSTATUS_MASK
;
6931 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6933 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6934 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6935 set_bit(handle
, ioc
->pd_handles
);
6939 printk(MPT2SAS_INFO_FMT
"search for responding raid volumes: "
6940 "complete\n", ioc
->name
);
6944 * _scsih_mark_responding_expander - mark a expander as responding
6945 * @ioc: per adapter object
6946 * @sas_address: sas address
6949 * After host reset, find out whether devices are still responding.
6950 * Used in _scsi_remove_unresponsive_expanders.
6955 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6958 struct _sas_node
*sas_expander
;
6959 unsigned long flags
;
6962 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6963 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6964 if (sas_expander
->sas_address
!= sas_address
)
6966 sas_expander
->responding
= 1;
6967 if (sas_expander
->handle
== handle
)
6969 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6970 " from(0x%04x) to (0x%04x)!!!\n",
6971 (unsigned long long)sas_expander
->sas_address
,
6972 sas_expander
->handle
, handle
);
6973 sas_expander
->handle
= handle
;
6974 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6975 sas_expander
->phy
[i
].handle
= handle
;
6979 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6983 * _scsih_search_responding_expanders -
6984 * @ioc: per adapter object
6986 * After host reset, find out whether devices are still responding.
6992 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6994 Mpi2ExpanderPage0_t expander_pg0
;
6995 Mpi2ConfigReply_t mpi_reply
;
7000 printk(MPT2SAS_INFO_FMT
"search for expanders: start\n", ioc
->name
);
7002 if (list_empty(&ioc
->sas_expander_list
))
7006 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7007 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7009 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7010 MPI2_IOCSTATUS_MASK
;
7011 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
7014 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7015 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
7016 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
7017 "sas_addr(0x%016llx)\n", handle
,
7018 (unsigned long long)sas_address
);
7019 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7023 printk(MPT2SAS_INFO_FMT
"search for expanders: complete\n", ioc
->name
);
7027 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7028 * @ioc: per adapter object
7033 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
7035 struct _sas_device
*sas_device
, *sas_device_next
;
7036 struct _sas_node
*sas_expander
, *sas_expander_next
;
7037 struct _raid_device
*raid_device
, *raid_device_next
;
7038 struct list_head tmp_list
;
7039 unsigned long flags
;
7041 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: start\n",
7044 /* removing unresponding end devices */
7045 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: end-devices\n",
7047 list_for_each_entry_safe(sas_device
, sas_device_next
,
7048 &ioc
->sas_device_list
, list
) {
7049 if (!sas_device
->responding
)
7050 mpt2sas_device_remove_by_sas_address(ioc
,
7051 sas_device
->sas_address
);
7053 sas_device
->responding
= 0;
7056 /* removing unresponding volumes */
7057 if (ioc
->ir_firmware
) {
7058 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: "
7059 "volumes\n", ioc
->name
);
7060 list_for_each_entry_safe(raid_device
, raid_device_next
,
7061 &ioc
->raid_device_list
, list
) {
7062 if (!raid_device
->responding
)
7063 _scsih_sas_volume_delete(ioc
,
7064 raid_device
->handle
);
7066 raid_device
->responding
= 0;
7069 /* removing unresponding expanders */
7070 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: expanders\n",
7072 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7073 INIT_LIST_HEAD(&tmp_list
);
7074 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7075 &ioc
->sas_expander_list
, list
) {
7076 if (!sas_expander
->responding
)
7077 list_move_tail(&sas_expander
->list
, &tmp_list
);
7079 sas_expander
->responding
= 0;
7081 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7082 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7084 list_del(&sas_expander
->list
);
7085 _scsih_expander_node_remove(ioc
, sas_expander
);
7087 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: complete\n",
7089 /* unblock devices */
7090 _scsih_ublock_io_all_device(ioc
);
7094 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER
*ioc
,
7095 struct _sas_node
*sas_expander
, u16 handle
)
7097 Mpi2ExpanderPage1_t expander_pg1
;
7098 Mpi2ConfigReply_t mpi_reply
;
7101 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7102 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7103 &expander_pg1
, i
, handle
))) {
7104 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7105 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7109 mpt2sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7110 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7111 expander_pg1
.NegotiatedLinkRate
>> 4);
7116 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7117 * @ioc: per adapter object
7122 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER
*ioc
)
7124 Mpi2ExpanderPage0_t expander_pg0
;
7125 Mpi2SasDevicePage0_t sas_device_pg0
;
7126 Mpi2RaidVolPage1_t volume_pg1
;
7127 Mpi2RaidVolPage0_t volume_pg0
;
7128 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7129 Mpi2EventIrConfigElement_t element
;
7130 Mpi2ConfigReply_t mpi_reply
;
7133 u16 handle
, parent_handle
;
7135 struct _sas_device
*sas_device
;
7136 struct _sas_node
*expander_device
;
7137 static struct _raid_device
*raid_device
;
7139 unsigned long flags
;
7141 printk(MPT2SAS_INFO_FMT
"scan devices: start\n", ioc
->name
);
7143 _scsih_sas_host_refresh(ioc
);
7145 printk(MPT2SAS_INFO_FMT
"\tscan devices: expanders start\n",
7149 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7150 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7151 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7152 MPI2_IOCSTATUS_MASK
;
7153 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7154 printk(MPT2SAS_INFO_FMT
"\tbreak from expander scan: "
7155 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7156 ioc
->name
, ioc_status
,
7157 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7160 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7161 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7162 expander_device
= mpt2sas_scsih_expander_find_by_sas_address(
7163 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7164 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7165 if (expander_device
)
7166 _scsih_refresh_expander_links(ioc
, expander_device
,
7169 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding expander: "
7170 "handle (0x%04x), sas_addr(0x%016llx)\n",
7171 ioc
->name
, handle
, (unsigned long long)
7172 le64_to_cpu(expander_pg0
.SASAddress
));
7173 _scsih_expander_add(ioc
, handle
);
7174 printk(MPT2SAS_INFO_FMT
"\tAFTER adding expander: "
7175 "handle (0x%04x), sas_addr(0x%016llx)\n",
7176 ioc
->name
, handle
, (unsigned long long)
7177 le64_to_cpu(expander_pg0
.SASAddress
));
7181 printk(MPT2SAS_INFO_FMT
"\tscan devices: expanders complete\n",
7184 if (!ioc
->ir_firmware
)
7187 printk(MPT2SAS_INFO_FMT
"\tscan devices phys disk start\n", ioc
->name
);
7189 phys_disk_num
= 0xFF;
7190 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7191 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7193 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7194 MPI2_IOCSTATUS_MASK
;
7195 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7196 printk(MPT2SAS_INFO_FMT
"\tbreak from phys disk scan:"
7197 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7198 ioc
->name
, ioc_status
,
7199 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7202 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7203 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7204 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7205 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
7206 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7209 if (mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7210 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7213 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7214 MPI2_IOCSTATUS_MASK
;
7215 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7216 printk(MPT2SAS_INFO_FMT
"\tbreak from phys disk scan "
7217 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7218 ioc
->name
, ioc_status
,
7219 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7222 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7223 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7225 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding phys disk: "
7226 " handle (0x%04x), sas_addr(0x%016llx)\n",
7227 ioc
->name
, handle
, (unsigned long long)
7228 le64_to_cpu(sas_device_pg0
.SASAddress
));
7229 mpt2sas_transport_update_links(ioc
, sas_address
,
7230 handle
, sas_device_pg0
.PhyNum
,
7231 MPI2_SAS_NEG_LINK_RATE_1_5
);
7232 set_bit(handle
, ioc
->pd_handles
);
7234 /* This will retry adding the end device.
7235 * _scsih_add_device() will decide on retries and
7236 * return "1" when it should be retried
7238 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7242 printk(MPT2SAS_INFO_FMT
"\tAFTER adding phys disk: "
7243 " handle (0x%04x), sas_addr(0x%016llx)\n",
7244 ioc
->name
, handle
, (unsigned long long)
7245 le64_to_cpu(sas_device_pg0
.SASAddress
));
7249 printk(MPT2SAS_INFO_FMT
"\tscan devices: phys disk complete\n",
7252 printk(MPT2SAS_INFO_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7255 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7256 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7257 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7258 MPI2_IOCSTATUS_MASK
;
7259 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7260 printk(MPT2SAS_INFO_FMT
"\tbreak from volume scan: "
7261 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7262 ioc
->name
, ioc_status
,
7263 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7266 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7267 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7268 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7269 le64_to_cpu(volume_pg1
.WWID
));
7270 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7273 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7274 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7275 sizeof(Mpi2RaidVolPage0_t
)))
7277 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7278 MPI2_IOCSTATUS_MASK
;
7279 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7280 printk(MPT2SAS_INFO_FMT
"\tbreak from volume scan: "
7281 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7282 ioc
->name
, ioc_status
,
7283 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7286 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7287 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7288 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7289 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7290 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7291 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7292 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding volume: "
7293 " handle (0x%04x)\n", ioc
->name
,
7294 volume_pg1
.DevHandle
);
7295 _scsih_sas_volume_add(ioc
, &element
);
7296 printk(MPT2SAS_INFO_FMT
"\tAFTER adding volume: "
7297 " handle (0x%04x)\n", ioc
->name
,
7298 volume_pg1
.DevHandle
);
7302 printk(MPT2SAS_INFO_FMT
"\tscan devices: volumes complete\n",
7307 printk(MPT2SAS_INFO_FMT
"\tscan devices: end devices start\n",
7311 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7312 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7314 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7315 MPI2_IOCSTATUS_MASK
;
7316 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7317 printk(MPT2SAS_INFO_FMT
"\tbreak from end device scan:"
7318 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7319 ioc
->name
, ioc_status
,
7320 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7323 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7324 if (!(_scsih_is_end_device(
7325 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7327 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7328 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
7329 le64_to_cpu(sas_device_pg0
.SASAddress
));
7330 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7333 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7334 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7335 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding end device: "
7336 "handle (0x%04x), sas_addr(0x%016llx)\n",
7337 ioc
->name
, handle
, (unsigned long long)
7338 le64_to_cpu(sas_device_pg0
.SASAddress
));
7339 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
7340 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7342 /* This will retry adding the end device.
7343 * _scsih_add_device() will decide on retries and
7344 * return "1" when it should be retried
7346 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7350 printk(MPT2SAS_INFO_FMT
"\tAFTER adding end device: "
7351 "handle (0x%04x), sas_addr(0x%016llx)\n",
7352 ioc
->name
, handle
, (unsigned long long)
7353 le64_to_cpu(sas_device_pg0
.SASAddress
));
7357 printk(MPT2SAS_INFO_FMT
"\tscan devices: end devices complete\n",
7360 printk(MPT2SAS_INFO_FMT
"scan devices: complete\n", ioc
->name
);
7365 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7366 * @ioc: per adapter object
7367 * @reset_phase: phase
7369 * The handler for doing any required cleanup or initialization.
7371 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7372 * MPT2_IOC_DONE_RESET
7377 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
7379 switch (reset_phase
) {
7380 case MPT2_IOC_PRE_RESET
:
7381 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7382 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7384 case MPT2_IOC_AFTER_RESET
:
7385 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7386 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7387 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
7388 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
7389 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7390 complete(&ioc
->scsih_cmds
.done
);
7392 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
7393 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
7394 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7395 complete(&ioc
->tm_cmds
.done
);
7397 _scsih_fw_event_cleanup_queue(ioc
);
7398 _scsih_flush_running_cmds(ioc
);
7400 case MPT2_IOC_DONE_RESET
:
7401 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7402 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7403 _scsih_sas_host_refresh(ioc
);
7404 _scsih_prep_device_scan(ioc
);
7405 _scsih_search_responding_sas_devices(ioc
);
7406 _scsih_search_responding_raid_devices(ioc
);
7407 _scsih_search_responding_expanders(ioc
);
7408 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7409 !ioc
->sas_hba
.num_phys
)) {
7410 _scsih_prep_device_scan(ioc
);
7411 _scsih_search_responding_sas_devices(ioc
);
7412 _scsih_search_responding_raid_devices(ioc
);
7413 _scsih_search_responding_expanders(ioc
);
7414 _scsih_error_recovery_delete_devices(ioc
);
7421 * _firmware_event_work - delayed task for processing firmware events
7422 * @ioc: per adapter object
7423 * @work: equal to the fw_event_work object
7429 _firmware_event_work(struct work_struct
*work
)
7431 struct fw_event_work
*fw_event
= container_of(work
,
7432 struct fw_event_work
, delayed_work
.work
);
7433 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
7435 /* the queue is being flushed so ignore this event */
7436 if (ioc
->remove_host
||
7437 ioc
->pci_error_recovery
) {
7438 _scsih_fw_event_free(ioc
, fw_event
);
7442 switch (fw_event
->event
) {
7443 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES
:
7444 while (scsi_host_in_recovery(ioc
->shost
) || ioc
->shost_recovery
)
7446 _scsih_remove_unresponding_sas_devices(ioc
);
7447 _scsih_scan_for_devices_after_reset(ioc
);
7449 case MPT2SAS_PORT_ENABLE_COMPLETE
:
7450 ioc
->start_scan
= 0;
7452 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7453 mpt2sas_base_update_missing_delay(ioc
, missing_delay
[0],
7456 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"port enable: complete "
7457 "from worker thread\n", ioc
->name
));
7459 case MPT2SAS_TURN_ON_PFA_LED
:
7460 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7462 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7463 _scsih_sas_topology_change_event(ioc
, fw_event
);
7465 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7466 _scsih_sas_device_status_change_event(ioc
,
7469 case MPI2_EVENT_SAS_DISCOVERY
:
7470 _scsih_sas_discovery_event(ioc
,
7473 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7474 _scsih_sas_broadcast_primitive_event(ioc
,
7477 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7478 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7481 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7482 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7484 case MPI2_EVENT_IR_VOLUME
:
7485 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7487 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7488 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7490 case MPI2_EVENT_IR_OPERATION_STATUS
:
7491 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7494 _scsih_fw_event_free(ioc
, fw_event
);
7498 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7499 * @ioc: per adapter object
7500 * @msix_index: MSIX table index supplied by the OS
7501 * @reply: reply message frame(lower 32bit addr)
7502 * Context: interrupt.
7504 * This function merely adds a new work task into ioc->firmware_event_thread.
7505 * The tasks are worked from _firmware_event_work in user context.
7510 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
7513 struct fw_event_work
*fw_event
;
7514 Mpi2EventNotificationReply_t
*mpi_reply
;
7518 /* events turned off due to host reset or driver unloading */
7519 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7522 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
7524 if (unlikely(!mpi_reply
)) {
7525 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7526 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7530 event
= le16_to_cpu(mpi_reply
->Event
);
7534 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7536 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7537 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7538 mpi_reply
->EventData
;
7540 if (baen_data
->Primitive
!=
7541 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7544 if (ioc
->broadcast_aen_busy
) {
7545 ioc
->broadcast_aen_pending
++;
7548 ioc
->broadcast_aen_busy
= 1;
7552 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7553 _scsih_check_topo_delete_events(ioc
,
7554 (Mpi2EventDataSasTopologyChangeList_t
*)
7555 mpi_reply
->EventData
);
7557 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7558 _scsih_check_ir_config_unhide_events(ioc
,
7559 (Mpi2EventDataIrConfigChangeList_t
*)
7560 mpi_reply
->EventData
);
7562 case MPI2_EVENT_IR_VOLUME
:
7563 _scsih_check_volume_delete_events(ioc
,
7564 (Mpi2EventDataIrVolume_t
*)
7565 mpi_reply
->EventData
);
7567 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7569 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7572 if (!ioc
->is_warpdrive
)
7575 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7576 mpi_reply
->EventData
;
7577 log_code
= (__le32
*)log_entry
->LogData
;
7579 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7580 != MPT2_WARPDRIVE_LOGENTRY
)
7583 switch (le32_to_cpu(*log_code
)) {
7584 case MPT2_WARPDRIVE_LC_SSDT
:
7585 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7586 "IO Throttling has occurred in the WarpDrive "
7587 "subsystem. Check WarpDrive documentation for "
7588 "additional details.\n", ioc
->name
);
7590 case MPT2_WARPDRIVE_LC_SSDLW
:
7591 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7592 "Program/Erase Cycles for the WarpDrive subsystem "
7593 "in degraded range. Check WarpDrive documentation "
7594 "for additional details.\n", ioc
->name
);
7596 case MPT2_WARPDRIVE_LC_SSDLF
:
7597 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7598 "There are no Program/Erase Cycles for the "
7599 "WarpDrive subsystem. The storage device will be "
7600 "in read-only mode. Check WarpDrive documentation "
7601 "for additional details.\n", ioc
->name
);
7603 case MPT2_WARPDRIVE_LC_BRMF
:
7604 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7605 "The Backup Rail Monitor has failed on the "
7606 "WarpDrive subsystem. Check WarpDrive "
7607 "documentation for additional details.\n",
7614 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7615 case MPI2_EVENT_IR_OPERATION_STATUS
:
7616 case MPI2_EVENT_SAS_DISCOVERY
:
7617 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7618 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7621 default: /* ignore the rest */
7625 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7626 fw_event
= kzalloc(sizeof(*fw_event
) + sz
, GFP_ATOMIC
);
7628 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7629 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7633 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7634 fw_event
->ioc
= ioc
;
7635 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7636 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7637 fw_event
->event
= event
;
7638 _scsih_fw_event_add(ioc
, fw_event
);
7642 /* shost template */
7643 static struct scsi_host_template scsih_driver_template
= {
7644 .module
= THIS_MODULE
,
7645 .name
= "Fusion MPT SAS Host",
7646 .proc_name
= MPT2SAS_DRIVER_NAME
,
7647 .queuecommand
= _scsih_qcmd
,
7648 .target_alloc
= _scsih_target_alloc
,
7649 .slave_alloc
= _scsih_slave_alloc
,
7650 .slave_configure
= _scsih_slave_configure
,
7651 .target_destroy
= _scsih_target_destroy
,
7652 .slave_destroy
= _scsih_slave_destroy
,
7653 .scan_finished
= _scsih_scan_finished
,
7654 .scan_start
= _scsih_scan_start
,
7655 .change_queue_depth
= _scsih_change_queue_depth
,
7656 .change_queue_type
= _scsih_change_queue_type
,
7657 .eh_abort_handler
= _scsih_abort
,
7658 .eh_device_reset_handler
= _scsih_dev_reset
,
7659 .eh_target_reset_handler
= _scsih_target_reset
,
7660 .eh_host_reset_handler
= _scsih_host_reset
,
7661 .bios_param
= _scsih_bios_param
,
7664 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
7665 .max_sectors
= 32767,
7667 .use_clustering
= ENABLE_CLUSTERING
,
7668 .shost_attrs
= mpt2sas_host_attrs
,
7669 .sdev_attrs
= mpt2sas_dev_attrs
,
7673 * _scsih_expander_node_remove - removing expander device from list.
7674 * @ioc: per adapter object
7675 * @sas_expander: the sas_device object
7676 * Context: Calling function should acquire ioc->sas_node_lock.
7678 * Removing object and freeing associated memory from the
7679 * ioc->sas_expander_list.
7684 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
7685 struct _sas_node
*sas_expander
)
7687 struct _sas_port
*mpt2sas_port
, *next
;
7689 /* remove sibling ports attached to this expander */
7690 list_for_each_entry_safe(mpt2sas_port
, next
,
7691 &sas_expander
->sas_port_list
, port_list
) {
7692 if (ioc
->shost_recovery
)
7694 if (mpt2sas_port
->remote_identify
.device_type
==
7696 mpt2sas_device_remove_by_sas_address(ioc
,
7697 mpt2sas_port
->remote_identify
.sas_address
);
7698 else if (mpt2sas_port
->remote_identify
.device_type
==
7699 SAS_EDGE_EXPANDER_DEVICE
||
7700 mpt2sas_port
->remote_identify
.device_type
==
7701 SAS_FANOUT_EXPANDER_DEVICE
)
7702 mpt2sas_expander_remove(ioc
,
7703 mpt2sas_port
->remote_identify
.sas_address
);
7706 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7707 sas_expander
->sas_address_parent
);
7709 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
7710 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7711 sas_expander
->handle
, (unsigned long long)
7712 sas_expander
->sas_address
);
7714 kfree(sas_expander
->phy
);
7715 kfree(sas_expander
);
7719 * _scsih_ir_shutdown - IR shutdown notification
7720 * @ioc: per adapter object
7722 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7723 * the host system is shutting down.
7728 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
7730 Mpi2RaidActionRequest_t
*mpi_request
;
7731 Mpi2RaidActionReply_t
*mpi_reply
;
7734 /* is IR firmware build loaded ? */
7735 if (!ioc
->ir_firmware
)
7738 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7740 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
7741 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
7742 ioc
->name
, __func__
);
7745 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
7747 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7749 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
7750 ioc
->name
, __func__
);
7751 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7755 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
7756 ioc
->scsih_cmds
.smid
= smid
;
7757 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7759 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7760 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7762 if (!ioc
->hide_ir_msg
)
7763 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
7764 init_completion(&ioc
->scsih_cmds
.done
);
7765 mpt2sas_base_put_smid_default(ioc
, smid
);
7766 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7768 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
7769 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
7770 ioc
->name
, __func__
);
7774 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
7775 mpi_reply
= ioc
->scsih_cmds
.reply
;
7777 if (!ioc
->hide_ir_msg
)
7778 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
7779 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7780 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7781 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7785 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7786 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7790 * _scsih_shutdown - routine call during system shutdown
7791 * @pdev: PCI device struct
7796 _scsih_shutdown(struct pci_dev
*pdev
)
7798 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7799 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7800 struct workqueue_struct
*wq
;
7801 unsigned long flags
;
7803 ioc
->remove_host
= 1;
7804 _scsih_fw_event_cleanup_queue(ioc
);
7806 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7807 wq
= ioc
->firmware_event_thread
;
7808 ioc
->firmware_event_thread
= NULL
;
7809 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7811 destroy_workqueue(wq
);
7813 _scsih_ir_shutdown(ioc
);
7814 mpt2sas_base_detach(ioc
);
7818 * _scsih_remove - detach and remove add host
7819 * @pdev: PCI device struct
7821 * Routine called when unloading the driver.
7825 _scsih_remove(struct pci_dev
*pdev
)
7827 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7828 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7829 struct _sas_port
*mpt2sas_port
, *next_port
;
7830 struct _raid_device
*raid_device
, *next
;
7831 struct MPT2SAS_TARGET
*sas_target_priv_data
;
7832 struct workqueue_struct
*wq
;
7833 unsigned long flags
;
7835 ioc
->remove_host
= 1;
7836 _scsih_fw_event_cleanup_queue(ioc
);
7838 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7839 wq
= ioc
->firmware_event_thread
;
7840 ioc
->firmware_event_thread
= NULL
;
7841 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7843 destroy_workqueue(wq
);
7845 /* release all the volumes */
7846 _scsih_ir_shutdown(ioc
);
7847 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7849 if (raid_device
->starget
) {
7850 sas_target_priv_data
=
7851 raid_device
->starget
->hostdata
;
7852 sas_target_priv_data
->deleted
= 1;
7853 scsi_remove_target(&raid_device
->starget
->dev
);
7855 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
7856 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
7857 (unsigned long long) raid_device
->wwid
);
7858 _scsih_raid_device_remove(ioc
, raid_device
);
7861 /* free ports attached to the sas_host */
7862 list_for_each_entry_safe(mpt2sas_port
, next_port
,
7863 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7864 if (mpt2sas_port
->remote_identify
.device_type
==
7866 mpt2sas_device_remove_by_sas_address(ioc
,
7867 mpt2sas_port
->remote_identify
.sas_address
);
7868 else if (mpt2sas_port
->remote_identify
.device_type
==
7869 SAS_EDGE_EXPANDER_DEVICE
||
7870 mpt2sas_port
->remote_identify
.device_type
==
7871 SAS_FANOUT_EXPANDER_DEVICE
)
7872 mpt2sas_expander_remove(ioc
,
7873 mpt2sas_port
->remote_identify
.sas_address
);
7876 /* free phys attached to the sas_host */
7877 if (ioc
->sas_hba
.num_phys
) {
7878 kfree(ioc
->sas_hba
.phy
);
7879 ioc
->sas_hba
.phy
= NULL
;
7880 ioc
->sas_hba
.num_phys
= 0;
7883 sas_remove_host(shost
);
7884 scsi_remove_host(shost
);
7885 mpt2sas_base_detach(ioc
);
7886 list_del(&ioc
->list
);
7887 scsi_host_put(shost
);
7891 * _scsih_probe_boot_devices - reports 1st device
7892 * @ioc: per adapter object
7894 * If specified in bios page 2, this routine reports the 1st
7895 * device scsi-ml or sas transport for persistent boot device
7896 * purposes. Please refer to function _scsih_determine_boot_device()
7899 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
7903 struct _sas_device
*sas_device
;
7904 struct _raid_device
*raid_device
;
7906 u64 sas_address_parent
;
7908 unsigned long flags
;
7911 /* no Bios, return immediately */
7912 if (!ioc
->bios_pg3
.BiosVersion
)
7917 if (ioc
->req_boot_device
.device
) {
7918 device
= ioc
->req_boot_device
.device
;
7919 is_raid
= ioc
->req_boot_device
.is_raid
;
7920 } else if (ioc
->req_alt_boot_device
.device
) {
7921 device
= ioc
->req_alt_boot_device
.device
;
7922 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7923 } else if (ioc
->current_boot_device
.device
) {
7924 device
= ioc
->current_boot_device
.device
;
7925 is_raid
= ioc
->current_boot_device
.is_raid
;
7932 raid_device
= device
;
7933 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7934 raid_device
->id
, 0);
7936 _scsih_raid_device_remove(ioc
, raid_device
);
7938 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7939 sas_device
= device
;
7940 handle
= sas_device
->handle
;
7941 sas_address_parent
= sas_device
->sas_address_parent
;
7942 sas_address
= sas_device
->sas_address
;
7943 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7944 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7946 if (ioc
->hide_drives
)
7948 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7949 sas_device
->sas_address_parent
)) {
7950 _scsih_sas_device_remove(ioc
, sas_device
);
7951 } else if (!sas_device
->starget
) {
7952 if (!ioc
->is_driver_loading
) {
7953 mpt2sas_transport_port_remove(ioc
,
7955 sas_address_parent
);
7956 _scsih_sas_device_remove(ioc
, sas_device
);
7963 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7964 * @ioc: per adapter object
7966 * Called during initial loading of the driver.
7969 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
7971 struct _raid_device
*raid_device
, *raid_next
;
7974 list_for_each_entry_safe(raid_device
, raid_next
,
7975 &ioc
->raid_device_list
, list
) {
7976 if (raid_device
->starget
)
7978 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7979 raid_device
->id
, 0);
7981 _scsih_raid_device_remove(ioc
, raid_device
);
7986 * _scsih_probe_sas - reporting sas devices to sas transport
7987 * @ioc: per adapter object
7989 * Called during initial loading of the driver.
7992 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
7994 struct _sas_device
*sas_device
, *next
;
7995 unsigned long flags
;
7997 /* SAS Device List */
7998 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
8001 if (ioc
->hide_drives
)
8004 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
8005 sas_device
->sas_address_parent
)) {
8006 list_del(&sas_device
->list
);
8009 } else if (!sas_device
->starget
) {
8010 if (!ioc
->is_driver_loading
) {
8011 mpt2sas_transport_port_remove(ioc
,
8012 sas_device
->sas_address
,
8013 sas_device
->sas_address_parent
);
8014 list_del(&sas_device
->list
);
8019 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8020 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8021 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8026 * _scsih_probe_devices - probing for devices
8027 * @ioc: per adapter object
8029 * Called during initial loading of the driver.
8032 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
8034 u16 volume_mapping_flags
;
8036 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8037 return; /* return when IOC doesn't support initiator mode */
8039 _scsih_probe_boot_devices(ioc
);
8041 if (ioc
->ir_firmware
) {
8042 volume_mapping_flags
=
8043 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8044 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8045 if (volume_mapping_flags
==
8046 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8047 _scsih_probe_raid(ioc
);
8048 _scsih_probe_sas(ioc
);
8050 _scsih_probe_sas(ioc
);
8051 _scsih_probe_raid(ioc
);
8054 _scsih_probe_sas(ioc
);
8059 * _scsih_scan_start - scsi lld callback for .scan_start
8060 * @shost: SCSI host pointer
8062 * The shost has the ability to discover targets on its own instead
8063 * of scanning the entire bus. In our implemention, we will kick off
8064 * firmware discovery.
8067 _scsih_scan_start(struct Scsi_Host
*shost
)
8069 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8072 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8073 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8075 if (disable_discovery
> 0)
8078 ioc
->start_scan
= 1;
8079 rc
= mpt2sas_port_enable(ioc
);
8082 printk(MPT2SAS_INFO_FMT
"port enable: FAILED\n", ioc
->name
);
8086 * _scsih_scan_finished - scsi lld callback for .scan_finished
8087 * @shost: SCSI host pointer
8088 * @time: elapsed time of the scan in jiffies
8090 * This function will be called periodically until it returns 1 with the
8091 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8092 * we wait for firmware discovery to complete, then return 1.
8095 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8097 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8099 if (disable_discovery
> 0) {
8100 ioc
->is_driver_loading
= 0;
8101 ioc
->wait_for_discovery_to_complete
= 0;
8105 if (time
>= (300 * HZ
)) {
8106 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
8107 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with timeout "
8108 "(timeout=300s)\n", ioc
->name
);
8109 ioc
->is_driver_loading
= 0;
8113 if (ioc
->start_scan
)
8116 if (ioc
->start_scan_failed
) {
8117 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with "
8118 "(ioc_status=0x%08x)\n", ioc
->name
, ioc
->start_scan_failed
);
8119 ioc
->is_driver_loading
= 0;
8120 ioc
->wait_for_discovery_to_complete
= 0;
8121 ioc
->remove_host
= 1;
8125 printk(MPT2SAS_INFO_FMT
"port enable: SUCCESS\n", ioc
->name
);
8126 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
8128 if (ioc
->wait_for_discovery_to_complete
) {
8129 ioc
->wait_for_discovery_to_complete
= 0;
8130 _scsih_probe_devices(ioc
);
8132 mpt2sas_base_start_watchdog(ioc
);
8133 ioc
->is_driver_loading
= 0;
8139 * _scsih_probe - attach and add scsi host
8140 * @pdev: PCI device struct
8141 * @id: pci device id
8143 * Returns 0 success, anything else error.
8146 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8148 struct MPT2SAS_ADAPTER
*ioc
;
8149 struct Scsi_Host
*shost
;
8152 shost
= scsi_host_alloc(&scsih_driver_template
,
8153 sizeof(struct MPT2SAS_ADAPTER
));
8157 /* init local params */
8158 ioc
= shost_priv(shost
);
8159 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
8160 INIT_LIST_HEAD(&ioc
->list
);
8161 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
8163 ioc
->id
= mpt_ids
++;
8164 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
8166 if (id
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8167 ioc
->is_warpdrive
= 1;
8168 ioc
->hide_ir_msg
= 1;
8170 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8171 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8172 ioc
->tm_cb_idx
= tm_cb_idx
;
8173 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8174 ioc
->base_cb_idx
= base_cb_idx
;
8175 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8176 ioc
->transport_cb_idx
= transport_cb_idx
;
8177 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8178 ioc
->config_cb_idx
= config_cb_idx
;
8179 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8180 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8181 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8182 ioc
->logging_level
= logging_level
;
8183 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8184 /* misc semaphores and spin locks */
8185 mutex_init(&ioc
->reset_in_progress_mutex
);
8186 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8187 spin_lock_init(&ioc
->scsi_lookup_lock
);
8188 spin_lock_init(&ioc
->sas_device_lock
);
8189 spin_lock_init(&ioc
->sas_node_lock
);
8190 spin_lock_init(&ioc
->fw_event_lock
);
8191 spin_lock_init(&ioc
->raid_device_lock
);
8193 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8194 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8195 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8196 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8197 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8198 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8199 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8200 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8201 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8203 /* init shost parameters */
8204 shost
->max_cmd_len
= 32;
8205 shost
->max_lun
= max_lun
;
8206 shost
->transportt
= mpt2sas_transport_template
;
8207 shost
->unique_id
= ioc
->id
;
8209 if (max_sectors
!= 0xFFFF) {
8210 if (max_sectors
< 64) {
8211 shost
->max_sectors
= 64;
8212 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8213 "for max_sectors, range is 64 to 32767. Assigning "
8214 "value of 64.\n", ioc
->name
, max_sectors
);
8215 } else if (max_sectors
> 32767) {
8216 shost
->max_sectors
= 32767;
8217 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8218 "for max_sectors, range is 64 to 8192. Assigning "
8219 "default value of 32767.\n", ioc
->name
,
8222 shost
->max_sectors
= max_sectors
& 0xFFFE;
8223 printk(MPT2SAS_INFO_FMT
"The max_sectors value is "
8224 "set to %d\n", ioc
->name
, shost
->max_sectors
);
8228 /* register EEDP capabilities with SCSI layer */
8230 scsi_host_set_prot(shost
, prot_mask
);
8232 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8233 | SHOST_DIF_TYPE2_PROTECTION
8234 | SHOST_DIF_TYPE3_PROTECTION
);
8236 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8239 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8240 "fw_event%d", ioc
->id
);
8241 ioc
->firmware_event_thread
= create_singlethread_workqueue(
8242 ioc
->firmware_event_name
);
8243 if (!ioc
->firmware_event_thread
) {
8244 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8245 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8247 goto out_thread_fail
;
8250 ioc
->is_driver_loading
= 1;
8251 if ((mpt2sas_base_attach(ioc
))) {
8252 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8253 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8255 goto out_attach_fail
;
8258 if (ioc
->is_warpdrive
) {
8259 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8260 ioc
->hide_drives
= 0;
8261 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8262 ioc
->hide_drives
= 1;
8264 if (_scsih_get_num_volumes(ioc
))
8265 ioc
->hide_drives
= 1;
8267 ioc
->hide_drives
= 0;
8270 ioc
->hide_drives
= 0;
8272 rv
= scsi_add_host(shost
, &pdev
->dev
);
8274 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8275 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8276 goto out_add_shost_fail
;
8279 scsi_scan_host(shost
);
8284 mpt2sas_base_detach(ioc
);
8286 destroy_workqueue(ioc
->firmware_event_thread
);
8288 list_del(&ioc
->list
);
8289 scsi_host_put(shost
);
8295 * _scsih_suspend - power management suspend main entry point
8296 * @pdev: PCI device struct
8297 * @state: PM state change to (usually PCI_D3)
8299 * Returns 0 success, anything else error.
8302 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8304 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8305 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8306 pci_power_t device_state
;
8308 mpt2sas_base_stop_watchdog(ioc
);
8309 scsi_block_requests(shost
);
8310 _scsih_ir_shutdown(ioc
);
8311 device_state
= pci_choose_state(pdev
, state
);
8312 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
8313 "operating state [D%d]\n", ioc
->name
, pdev
,
8314 pci_name(pdev
), device_state
);
8316 mpt2sas_base_free_resources(ioc
);
8317 pci_save_state(pdev
);
8318 pci_set_power_state(pdev
, device_state
);
8323 * _scsih_resume - power management resume main entry point
8324 * @pdev: PCI device struct
8326 * Returns 0 success, anything else error.
8329 _scsih_resume(struct pci_dev
*pdev
)
8331 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8332 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8333 pci_power_t device_state
= pdev
->current_state
;
8336 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
8337 "operating state [D%d]\n", ioc
->name
, pdev
,
8338 pci_name(pdev
), device_state
);
8340 pci_set_power_state(pdev
, PCI_D0
);
8341 pci_enable_wake(pdev
, PCI_D0
, 0);
8342 pci_restore_state(pdev
);
8344 r
= mpt2sas_base_map_resources(ioc
);
8348 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8349 scsi_unblock_requests(shost
);
8350 mpt2sas_base_start_watchdog(ioc
);
8353 #endif /* CONFIG_PM */
8356 * _scsih_pci_error_detected - Called when a PCI error is detected.
8357 * @pdev: PCI device struct
8358 * @state: PCI channel state
8360 * Description: Called when a PCI error is detected.
8363 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8365 static pci_ers_result_t
8366 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8368 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8369 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8371 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
8375 case pci_channel_io_normal
:
8376 return PCI_ERS_RESULT_CAN_RECOVER
;
8377 case pci_channel_io_frozen
:
8378 /* Fatal error, prepare for slot reset */
8379 ioc
->pci_error_recovery
= 1;
8380 scsi_block_requests(ioc
->shost
);
8381 mpt2sas_base_stop_watchdog(ioc
);
8382 mpt2sas_base_free_resources(ioc
);
8383 return PCI_ERS_RESULT_NEED_RESET
;
8384 case pci_channel_io_perm_failure
:
8385 /* Permanent error, prepare for device removal */
8386 ioc
->pci_error_recovery
= 1;
8387 mpt2sas_base_stop_watchdog(ioc
);
8388 _scsih_flush_running_cmds(ioc
);
8389 return PCI_ERS_RESULT_DISCONNECT
;
8391 return PCI_ERS_RESULT_NEED_RESET
;
8395 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8396 * @pdev: PCI device struct
8398 * Description: This routine is called by the pci error recovery
8399 * code after the PCI slot has been reset, just before we
8400 * should resume normal operations.
8402 static pci_ers_result_t
8403 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
8405 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8406 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8409 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
8412 ioc
->pci_error_recovery
= 0;
8414 pci_restore_state(pdev
);
8415 rc
= mpt2sas_base_map_resources(ioc
);
8417 return PCI_ERS_RESULT_DISCONNECT
;
8420 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8423 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
8424 (rc
== 0) ? "success" : "failed");
8427 return PCI_ERS_RESULT_RECOVERED
;
8429 return PCI_ERS_RESULT_DISCONNECT
;
8433 * _scsih_pci_resume() - resume normal ops after PCI reset
8434 * @pdev: pointer to PCI device
8436 * Called when the error recovery driver tells us that its
8437 * OK to resume normal operation. Use completion to allow
8438 * halted scsi ops to resume.
8441 _scsih_pci_resume(struct pci_dev
*pdev
)
8443 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8444 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8446 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8448 pci_cleanup_aer_uncorrect_error_status(pdev
);
8449 mpt2sas_base_start_watchdog(ioc
);
8450 scsi_unblock_requests(ioc
->shost
);
8454 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8455 * @pdev: pointer to PCI device
8457 static pci_ers_result_t
8458 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8460 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8461 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8463 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
8466 /* TODO - dump whatever for debugging purposes */
8468 /* Request a slot reset. */
8469 return PCI_ERS_RESULT_NEED_RESET
;
8472 static const struct pci_error_handlers _scsih_err_handler
= {
8473 .error_detected
= _scsih_pci_error_detected
,
8474 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8475 .slot_reset
= _scsih_pci_slot_reset
,
8476 .resume
= _scsih_pci_resume
,
8479 static struct pci_driver scsih_driver
= {
8480 .name
= MPT2SAS_DRIVER_NAME
,
8481 .id_table
= scsih_pci_table
,
8482 .probe
= _scsih_probe
,
8483 .remove
= _scsih_remove
,
8484 .shutdown
= _scsih_shutdown
,
8485 .err_handler
= &_scsih_err_handler
,
8487 .suspend
= _scsih_suspend
,
8488 .resume
= _scsih_resume
,
8492 /* raid transport support */
8493 static struct raid_function_template mpt2sas_raid_functions
= {
8494 .cookie
= &scsih_driver_template
,
8495 .is_raid
= _scsih_is_raid
,
8496 .get_resync
= _scsih_get_resync
,
8497 .get_state
= _scsih_get_state
,
8501 * _scsih_init - main entry point for this driver.
8503 * Returns 0 success, anything else error.
8511 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
8512 MPT2SAS_DRIVER_VERSION
);
8514 mpt2sas_transport_template
=
8515 sas_attach_transport(&mpt2sas_transport_functions
);
8516 if (!mpt2sas_transport_template
)
8518 /* raid transport support */
8519 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
8520 if (!mpt2sas_raid_template
) {
8521 sas_release_transport(mpt2sas_transport_template
);
8525 mpt2sas_base_initialize_callback_handler();
8527 /* queuecommand callback hander */
8528 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
8530 /* task management callback handler */
8531 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
8533 /* base internal commands callback handler */
8534 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
8535 port_enable_cb_idx
= mpt2sas_base_register_callback_handler(
8536 mpt2sas_port_enable_done
);
8538 /* transport internal commands callback handler */
8539 transport_cb_idx
= mpt2sas_base_register_callback_handler(
8540 mpt2sas_transport_done
);
8542 /* scsih internal commands callback handler */
8543 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
8545 /* configuration page API internal commands callback handler */
8546 config_cb_idx
= mpt2sas_base_register_callback_handler(
8547 mpt2sas_config_done
);
8549 /* ctl module callback handler */
8550 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
8552 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
8553 _scsih_tm_tr_complete
);
8555 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
8556 _scsih_tm_volume_tr_complete
);
8558 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
8559 _scsih_sas_control_complete
);
8563 error
= pci_register_driver(&scsih_driver
);
8565 /* raid transport support */
8566 raid_class_release(mpt2sas_raid_template
);
8567 sas_release_transport(mpt2sas_transport_template
);
8574 * _scsih_exit - exit point for this driver (when it is a module).
8576 * Returns 0 success, anything else error.
8581 printk(KERN_INFO
"mpt2sas version %s unloading\n",
8582 MPT2SAS_DRIVER_VERSION
);
8584 pci_unregister_driver(&scsih_driver
);
8588 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
8589 mpt2sas_base_release_callback_handler(tm_cb_idx
);
8590 mpt2sas_base_release_callback_handler(base_cb_idx
);
8591 mpt2sas_base_release_callback_handler(port_enable_cb_idx
);
8592 mpt2sas_base_release_callback_handler(transport_cb_idx
);
8593 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
8594 mpt2sas_base_release_callback_handler(config_cb_idx
);
8595 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
8597 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
8598 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8599 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8601 /* raid transport support */
8602 raid_class_release(mpt2sas_raid_template
);
8603 sas_release_transport(mpt2sas_transport_template
);
8607 module_init(_scsih_init
);
8608 module_exit(_scsih_exit
);