2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2014 LSI Corporation
6 * Copyright (C) 20013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <linux/slab.h>
59 #include <asm/unaligned.h>
61 #include "mpt2sas_base.h"
63 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
64 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
65 MODULE_LICENSE("GPL");
66 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
68 #define RAID_CHANNEL 1
71 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
72 struct _sas_node
*sas_expander
);
73 static void _firmware_event_work(struct work_struct
*work
);
75 static u8
_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
);
77 static void _scsih_scan_start(struct Scsi_Host
*shost
);
78 static int _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
);
80 /* global parameters */
81 LIST_HEAD(mpt2sas_ioc_list
);
83 /* local parameters */
84 static u8 scsi_io_cb_idx
= -1;
85 static u8 tm_cb_idx
= -1;
86 static u8 ctl_cb_idx
= -1;
87 static u8 base_cb_idx
= -1;
88 static u8 port_enable_cb_idx
= -1;
89 static u8 transport_cb_idx
= -1;
90 static u8 scsih_cb_idx
= -1;
91 static u8 config_cb_idx
= -1;
94 static u8 tm_tr_cb_idx
= -1 ;
95 static u8 tm_tr_volume_cb_idx
= -1 ;
96 static u8 tm_sas_control_cb_idx
= -1;
98 /* command line options */
99 static u32 logging_level
;
100 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
103 static ushort max_sectors
= 0xFFFF;
104 module_param(max_sectors
, ushort
, 0);
105 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
107 static int missing_delay
[2] = {-1, -1};
108 module_param_array(missing_delay
, int, NULL
, 0);
109 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
111 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
112 #define MPT2SAS_MAX_LUN (16895)
113 static int max_lun
= MPT2SAS_MAX_LUN
;
114 module_param(max_lun
, int, 0);
115 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
117 /* diag_buffer_enable is bitwise
119 * bit 1 set = SNAPSHOT
120 * bit 2 set = EXTENDED
122 * Either bit can be set, or both
124 static int diag_buffer_enable
= -1;
125 module_param(diag_buffer_enable
, int, 0);
126 MODULE_PARM_DESC(diag_buffer_enable
, " post diag buffers "
127 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
129 static int disable_discovery
= -1;
130 module_param(disable_discovery
, int, 0);
131 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
133 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
134 static int prot_mask
= 0;
135 module_param(prot_mask
, int, 0);
136 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
139 * struct sense_info - common structure for obtaining sense keys
141 * @asc: additional sense code
142 * @ascq: additional sense code qualifier
151 #define MPT2SAS_TURN_ON_PFA_LED (0xFFFC)
152 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
153 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
155 * struct fw_event_work - firmware event struct
156 * @list: link list framework
157 * @work: work object (ioc->fault_reset_work_q)
158 * @cancel_pending_work: flag set during reset handling
159 * @ioc: per adapter object
160 * @device_handle: device handle
161 * @VF_ID: virtual function id
162 * @VP_ID: virtual port id
163 * @ignore: flag meaning this event has been marked to ignore
164 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
165 * @event_data: reply event data payload follows
167 * This object stored on ioc->fw_event_list.
169 struct fw_event_work
{
170 struct list_head list
;
171 u8 cancel_pending_work
;
172 struct delayed_work delayed_work
;
173 struct MPT2SAS_ADAPTER
*ioc
;
179 char event_data
[0] __aligned(4);
182 /* raid transport support */
183 static struct raid_template
*mpt2sas_raid_template
;
186 * struct _scsi_io_transfer - scsi io transfer
187 * @handle: sas device handle (assigned by firmware)
188 * @is_raid: flag set for hidden raid components
189 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
190 * @data_length: data transfer length
191 * @data_dma: dma pointer to data
194 * @cdb_length: cdb length
196 * @timeout: timeout for this command
197 * @VF_ID: virtual function id
198 * @VP_ID: virtual port id
199 * @valid_reply: flag set for reply message
200 * @sense_length: sense length
201 * @ioc_status: ioc status
202 * @scsi_state: scsi state
203 * @scsi_status: scsi staus
204 * @log_info: log information
205 * @transfer_length: data length transfer when there is a reply message
207 * Used for sending internal scsi commands to devices within this module.
208 * Refer to _scsi_send_scsi_io().
210 struct _scsi_io_transfer
{
213 enum dma_data_direction dir
;
216 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
224 /* the following bits are only valid when 'valid_reply = 1' */
234 * The pci device ids are defined in mpi/mpi2_cnfg.h.
236 static struct pci_device_id scsih_pci_table
[] = {
237 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
238 PCI_ANY_ID
, PCI_ANY_ID
},
240 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
241 PCI_ANY_ID
, PCI_ANY_ID
},
242 /* Liberator ~ 2108 */
243 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
244 PCI_ANY_ID
, PCI_ANY_ID
},
245 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
246 PCI_ANY_ID
, PCI_ANY_ID
},
247 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
248 PCI_ANY_ID
, PCI_ANY_ID
},
250 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
251 PCI_ANY_ID
, PCI_ANY_ID
},
252 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
253 PCI_ANY_ID
, PCI_ANY_ID
},
254 /* Thunderbolt ~ 2208 */
255 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
256 PCI_ANY_ID
, PCI_ANY_ID
},
257 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
258 PCI_ANY_ID
, PCI_ANY_ID
},
259 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
260 PCI_ANY_ID
, PCI_ANY_ID
},
261 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
262 PCI_ANY_ID
, PCI_ANY_ID
},
263 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
264 PCI_ANY_ID
, PCI_ANY_ID
},
265 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
266 PCI_ANY_ID
, PCI_ANY_ID
},
268 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
269 PCI_ANY_ID
, PCI_ANY_ID
},
270 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
271 PCI_ANY_ID
, PCI_ANY_ID
},
272 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
273 PCI_ANY_ID
, PCI_ANY_ID
},
275 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
276 PCI_ANY_ID
, PCI_ANY_ID
},
277 {0} /* Terminating entry */
279 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
282 * _scsih_set_debug_level - global setting of ioc->logging_level.
284 * Note: The logging levels are defined in mpt2sas_debug.h.
287 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
289 int ret
= param_set_int(val
, kp
);
290 struct MPT2SAS_ADAPTER
*ioc
;
295 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
296 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
297 ioc
->logging_level
= logging_level
;
300 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
301 &logging_level
, 0644);
304 * _scsih_srch_boot_sas_address - search based on sas_address
305 * @sas_address: sas address
306 * @boot_device: boot device object from bios page 2
308 * Returns 1 when there's a match, 0 means no match.
311 _scsih_srch_boot_sas_address(u64 sas_address
,
312 Mpi2BootDeviceSasWwid_t
*boot_device
)
314 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
318 * _scsih_srch_boot_device_name - search based on device name
319 * @device_name: device name specified in INDENTIFY fram
320 * @boot_device: boot device object from bios page 2
322 * Returns 1 when there's a match, 0 means no match.
325 _scsih_srch_boot_device_name(u64 device_name
,
326 Mpi2BootDeviceDeviceName_t
*boot_device
)
328 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
332 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
333 * @enclosure_logical_id: enclosure logical id
334 * @slot_number: slot number
335 * @boot_device: boot device object from bios page 2
337 * Returns 1 when there's a match, 0 means no match.
340 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
341 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
343 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
344 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
345 SlotNumber
)) ? 1 : 0;
349 * _scsih_is_boot_device - search for matching boot device.
350 * @sas_address: sas address
351 * @device_name: device name specified in INDENTIFY fram
352 * @enclosure_logical_id: enclosure logical id
353 * @slot_number: slot number
354 * @form: specifies boot device form
355 * @boot_device: boot device object from bios page 2
357 * Returns 1 when there's a match, 0 means no match.
360 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
361 u64 enclosure_logical_id
, u16 slot
, u8 form
,
362 Mpi2BiosPage2BootDevice_t
*boot_device
)
367 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
370 rc
= _scsih_srch_boot_sas_address(
371 sas_address
, &boot_device
->SasWwid
);
373 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
374 if (!enclosure_logical_id
)
376 rc
= _scsih_srch_boot_encl_slot(
377 enclosure_logical_id
,
378 slot
, &boot_device
->EnclosureSlot
);
380 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
383 rc
= _scsih_srch_boot_device_name(
384 device_name
, &boot_device
->DeviceName
);
386 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
394 * _scsih_get_sas_address - set the sas_address for given device handle
395 * @handle: device handle
396 * @sas_address: sas address
398 * Returns 0 success, non-zero when failure
401 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
404 Mpi2SasDevicePage0_t sas_device_pg0
;
405 Mpi2ConfigReply_t mpi_reply
;
409 if (handle
<= ioc
->sas_hba
.num_phys
) {
410 *sas_address
= ioc
->sas_hba
.sas_address
;
414 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
415 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
416 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
417 __FILE__
, __LINE__
, __func__
);
421 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
422 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
423 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
427 /* we hit this becuase the given parent handle doesn't exist */
428 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
430 /* else error case */
431 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x), "
432 "failure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
433 __FILE__
, __LINE__
, __func__
);
438 * _scsih_determine_boot_device - determine boot device.
439 * @ioc: per adapter object
440 * @device: either sas_device or raid_device object
441 * @is_raid: [flag] 1 = raid object, 0 = sas object
443 * Determines whether this device should be first reported device to
444 * to scsi-ml or sas transport, this purpose is for persistent boot device.
445 * There are primary, alternate, and current entries in bios page 2. The order
446 * priority is primary, alternate, then current. This routine saves
447 * the corresponding device object and is_raid flag in the ioc object.
448 * The saved data to be used later in _scsih_probe_boot_devices().
451 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
452 void *device
, u8 is_raid
)
454 struct _sas_device
*sas_device
;
455 struct _raid_device
*raid_device
;
458 u64 enclosure_logical_id
;
461 /* only process this function when driver loads */
462 if (!ioc
->is_driver_loading
)
465 /* no Bios, return immediately */
466 if (!ioc
->bios_pg3
.BiosVersion
)
471 sas_address
= sas_device
->sas_address
;
472 device_name
= sas_device
->device_name
;
473 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
474 slot
= sas_device
->slot
;
476 raid_device
= device
;
477 sas_address
= raid_device
->wwid
;
479 enclosure_logical_id
= 0;
483 if (!ioc
->req_boot_device
.device
) {
484 if (_scsih_is_boot_device(sas_address
, device_name
,
485 enclosure_logical_id
, slot
,
486 (ioc
->bios_pg2
.ReqBootDeviceForm
&
487 MPI2_BIOSPAGE2_FORM_MASK
),
488 &ioc
->bios_pg2
.RequestedBootDevice
)) {
489 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
490 "%s: req_boot_device(0x%016llx)\n",
492 (unsigned long long)sas_address
));
493 ioc
->req_boot_device
.device
= device
;
494 ioc
->req_boot_device
.is_raid
= is_raid
;
498 if (!ioc
->req_alt_boot_device
.device
) {
499 if (_scsih_is_boot_device(sas_address
, device_name
,
500 enclosure_logical_id
, slot
,
501 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
502 MPI2_BIOSPAGE2_FORM_MASK
),
503 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
504 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
505 "%s: req_alt_boot_device(0x%016llx)\n",
507 (unsigned long long)sas_address
));
508 ioc
->req_alt_boot_device
.device
= device
;
509 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
513 if (!ioc
->current_boot_device
.device
) {
514 if (_scsih_is_boot_device(sas_address
, device_name
,
515 enclosure_logical_id
, slot
,
516 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
517 MPI2_BIOSPAGE2_FORM_MASK
),
518 &ioc
->bios_pg2
.CurrentBootDevice
)) {
519 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
520 "%s: current_boot_device(0x%016llx)\n",
522 (unsigned long long)sas_address
));
523 ioc
->current_boot_device
.device
= device
;
524 ioc
->current_boot_device
.is_raid
= is_raid
;
530 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
531 * @ioc: per adapter object
532 * @sas_address: sas address
533 * Context: Calling function should acquire ioc->sas_device_lock
535 * This searches for sas_device based on sas_address, then return sas_device
539 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
542 struct _sas_device
*sas_device
;
544 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
545 if (sas_device
->sas_address
== sas_address
)
548 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
549 if (sas_device
->sas_address
== sas_address
)
556 * _scsih_sas_device_find_by_handle - sas device search
557 * @ioc: per adapter object
558 * @handle: sas device handle (assigned by firmware)
559 * Context: Calling function should acquire ioc->sas_device_lock
561 * This searches for sas_device based on sas_address, then return sas_device
564 static struct _sas_device
*
565 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
567 struct _sas_device
*sas_device
;
569 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
570 if (sas_device
->handle
== handle
)
573 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
574 if (sas_device
->handle
== handle
)
581 * _scsih_sas_device_remove - remove sas_device from list.
582 * @ioc: per adapter object
583 * @sas_device: the sas_device object
584 * Context: This function will acquire ioc->sas_device_lock.
586 * Removing object and freeing associated memory from the ioc->sas_device_list.
589 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
590 struct _sas_device
*sas_device
)
597 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
598 list_del(&sas_device
->list
);
600 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
605 * _scsih_sas_device_add - insert sas_device to the list.
606 * @ioc: per adapter object
607 * @sas_device: the sas_device object
608 * Context: This function will acquire ioc->sas_device_lock.
610 * Adding new object to the ioc->sas_device_list.
613 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
614 struct _sas_device
*sas_device
)
618 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
619 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
620 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
622 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
623 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
624 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
626 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
627 sas_device
->sas_address_parent
)) {
628 _scsih_sas_device_remove(ioc
, sas_device
);
629 } else if (!sas_device
->starget
) {
630 /* When asyn scanning is enabled, its not possible to remove
631 * devices while scanning is turned on due to an oops in
632 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
634 if (!ioc
->is_driver_loading
) {
635 mpt2sas_transport_port_remove(ioc
,
636 sas_device
->sas_address
,
637 sas_device
->sas_address_parent
);
638 _scsih_sas_device_remove(ioc
, sas_device
);
644 * _scsih_sas_device_init_add - insert sas_device to the list.
645 * @ioc: per adapter object
646 * @sas_device: the sas_device object
647 * Context: This function will acquire ioc->sas_device_lock.
649 * Adding new object at driver load time to the ioc->sas_device_init_list.
652 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
653 struct _sas_device
*sas_device
)
657 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
658 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
659 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
661 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
662 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
663 _scsih_determine_boot_device(ioc
, sas_device
, 0);
664 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
668 * _scsih_raid_device_find_by_id - raid device search
669 * @ioc: per adapter object
670 * @id: sas device target id
671 * @channel: sas device channel
672 * Context: Calling function should acquire ioc->raid_device_lock
674 * This searches for raid_device based on target id, then return raid_device
677 static struct _raid_device
*
678 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
680 struct _raid_device
*raid_device
, *r
;
683 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
684 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
695 * _scsih_raid_device_find_by_handle - raid device search
696 * @ioc: per adapter object
697 * @handle: sas device handle (assigned by firmware)
698 * Context: Calling function should acquire ioc->raid_device_lock
700 * This searches for raid_device based on handle, then return raid_device
703 static struct _raid_device
*
704 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
706 struct _raid_device
*raid_device
, *r
;
709 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
710 if (raid_device
->handle
!= handle
)
721 * _scsih_raid_device_find_by_wwid - raid device search
722 * @ioc: per adapter object
723 * @handle: sas device handle (assigned by firmware)
724 * Context: Calling function should acquire ioc->raid_device_lock
726 * This searches for raid_device based on wwid, then return raid_device
729 static struct _raid_device
*
730 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
732 struct _raid_device
*raid_device
, *r
;
735 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
736 if (raid_device
->wwid
!= wwid
)
747 * _scsih_raid_device_add - add raid_device object
748 * @ioc: per adapter object
749 * @raid_device: raid_device object
751 * This is added to the raid_device_list link list.
754 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
755 struct _raid_device
*raid_device
)
759 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
760 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
761 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
763 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
764 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
765 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
769 * _scsih_raid_device_remove - delete raid_device object
770 * @ioc: per adapter object
771 * @raid_device: raid_device object
775 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
776 struct _raid_device
*raid_device
)
780 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
781 list_del(&raid_device
->list
);
783 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
787 * mpt2sas_scsih_expander_find_by_handle - expander device search
788 * @ioc: per adapter object
789 * @handle: expander handle (assigned by firmware)
790 * Context: Calling function should acquire ioc->sas_device_lock
792 * This searches for expander device based on handle, then returns the
796 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
798 struct _sas_node
*sas_expander
, *r
;
801 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
802 if (sas_expander
->handle
!= handle
)
812 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
813 * @ioc: per adapter object
814 * @sas_address: sas address
815 * Context: Calling function should acquire ioc->sas_node_lock.
817 * This searches for expander device based on sas_address, then returns the
821 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
824 struct _sas_node
*sas_expander
, *r
;
827 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
828 if (sas_expander
->sas_address
!= sas_address
)
838 * _scsih_expander_node_add - insert expander device to the list.
839 * @ioc: per adapter object
840 * @sas_expander: the sas_device object
841 * Context: This function will acquire ioc->sas_node_lock.
843 * Adding new object to the ioc->sas_expander_list.
848 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
849 struct _sas_node
*sas_expander
)
853 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
854 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
855 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
859 * _scsih_is_end_device - determines if device is an end device
860 * @device_info: bitfield providing information about the device.
863 * Returns 1 if end device.
866 _scsih_is_end_device(u32 device_info
)
868 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
869 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
870 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
871 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
878 * _scsih_scsi_lookup_get - returns scmd entry
879 * @ioc: per adapter object
880 * @smid: system request message index
882 * Returns the smid stored scmd pointer.
884 static struct scsi_cmnd
*
885 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
887 return ioc
->scsi_lookup
[smid
- 1].scmd
;
891 * _scsih_scsi_lookup_get_clear - returns scmd entry
892 * @ioc: per adapter object
893 * @smid: system request message index
895 * Returns the smid stored scmd pointer.
896 * Then will derefrence the stored scmd pointer.
898 static inline struct scsi_cmnd
*
899 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
902 struct scsi_cmnd
*scmd
;
904 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
905 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
906 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
907 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
913 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
914 * @ioc: per adapter object
915 * @smid: system request message index
916 * @scmd: pointer to scsi command object
917 * Context: This function will acquire ioc->scsi_lookup_lock.
919 * This will search for a scmd pointer in the scsi_lookup array,
920 * returning the revelent smid. A returned value of zero means invalid.
923 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
930 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
932 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
933 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
934 smid
= ioc
->scsi_lookup
[i
].smid
;
939 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
944 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
945 * @ioc: per adapter object
948 * Context: This function will acquire ioc->scsi_lookup_lock.
950 * This will search for a matching channel:id in the scsi_lookup array,
951 * returning 1 if found.
954 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
961 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
963 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
964 if (ioc
->scsi_lookup
[i
].scmd
&&
965 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
966 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
972 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
977 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
978 * @ioc: per adapter object
982 * Context: This function will acquire ioc->scsi_lookup_lock.
984 * This will search for a matching channel:id:lun in the scsi_lookup array,
985 * returning 1 if found.
988 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
989 unsigned int lun
, int channel
)
995 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
997 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
998 if (ioc
->scsi_lookup
[i
].scmd
&&
999 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
1000 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
1001 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
1007 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1012 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1013 * @ioc: per adapter object
1014 * @smid: smid associated to an IO request
1016 * Returns chain tracker(from ioc->free_chain_list)
1018 static struct chain_tracker
*
1019 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1021 struct chain_tracker
*chain_req
;
1022 unsigned long flags
;
1024 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1025 if (list_empty(&ioc
->free_chain_list
)) {
1026 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1027 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
"chain buffers not "
1028 "available\n", ioc
->name
));
1031 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1032 struct chain_tracker
, tracker_list
);
1033 list_del_init(&chain_req
->tracker_list
);
1034 list_add_tail(&chain_req
->tracker_list
,
1035 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1036 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1041 * _scsih_build_scatter_gather - main sg creation routine
1042 * @ioc: per adapter object
1043 * @scmd: scsi command
1044 * @smid: system request message index
1047 * The main routine that builds scatter gather table from a given
1048 * scsi request sent via the .queuecommand main handler.
1050 * Returns 0 success, anything else error
1053 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
1054 struct scsi_cmnd
*scmd
, u16 smid
)
1056 Mpi2SCSIIORequest_t
*mpi_request
;
1057 dma_addr_t chain_dma
;
1058 struct scatterlist
*sg_scmd
;
1059 void *sg_local
, *chain
;
1064 u32 sges_in_segment
;
1066 u32 sgl_flags_last_element
;
1067 u32 sgl_flags_end_buffer
;
1068 struct chain_tracker
*chain_req
;
1070 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1072 /* init scatter gather flags */
1073 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1074 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1075 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1076 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1077 << MPI2_SGE_FLAGS_SHIFT
;
1078 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1079 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1080 << MPI2_SGE_FLAGS_SHIFT
;
1081 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1083 sg_scmd
= scsi_sglist(scmd
);
1084 sges_left
= scsi_dma_map(scmd
);
1085 if (sges_left
< 0) {
1086 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1087 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1091 sg_local
= &mpi_request
->SGL
;
1092 sges_in_segment
= ioc
->max_sges_in_main_message
;
1093 if (sges_left
<= sges_in_segment
)
1094 goto fill_in_last_segment
;
1096 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1097 (sges_in_segment
* ioc
->sge_size
))/4;
1099 /* fill in main message segment when there is a chain following */
1100 while (sges_in_segment
) {
1101 if (sges_in_segment
== 1)
1102 ioc
->base_add_sg_single(sg_local
,
1103 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1104 sg_dma_address(sg_scmd
));
1106 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1107 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1108 sg_scmd
= sg_next(sg_scmd
);
1109 sg_local
+= ioc
->sge_size
;
1114 /* initializing the chain flags and pointers */
1115 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1116 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1119 chain
= chain_req
->chain_buffer
;
1120 chain_dma
= chain_req
->chain_buffer_dma
;
1122 sges_in_segment
= (sges_left
<=
1123 ioc
->max_sges_in_chain_message
) ? sges_left
:
1124 ioc
->max_sges_in_chain_message
;
1125 chain_offset
= (sges_left
== sges_in_segment
) ?
1126 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1127 chain_length
= sges_in_segment
* ioc
->sge_size
;
1129 chain_offset
= chain_offset
<<
1130 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1131 chain_length
+= ioc
->sge_size
;
1133 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1134 chain_length
, chain_dma
);
1137 goto fill_in_last_segment
;
1139 /* fill in chain segments */
1140 while (sges_in_segment
) {
1141 if (sges_in_segment
== 1)
1142 ioc
->base_add_sg_single(sg_local
,
1143 sgl_flags_last_element
|
1144 sg_dma_len(sg_scmd
),
1145 sg_dma_address(sg_scmd
));
1147 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1148 sg_dma_len(sg_scmd
),
1149 sg_dma_address(sg_scmd
));
1150 sg_scmd
= sg_next(sg_scmd
);
1151 sg_local
+= ioc
->sge_size
;
1156 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1159 chain
= chain_req
->chain_buffer
;
1160 chain_dma
= chain_req
->chain_buffer_dma
;
1164 fill_in_last_segment
:
1166 /* fill the last segment */
1169 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1170 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1172 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1173 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1174 sg_scmd
= sg_next(sg_scmd
);
1175 sg_local
+= ioc
->sge_size
;
1183 * _scsih_change_queue_depth - setting device queue depth
1184 * @sdev: scsi device struct
1185 * @qdepth: requested queue depth
1187 * Returns queue depth.
1190 _scsih_change_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
);
1220 if (!sdev
->tagged_supported
)
1222 if (qdepth
> max_depth
)
1224 return scsi_change_queue_depth(sdev
, qdepth
);
1228 * _scsih_target_alloc - target add routine
1229 * @starget: scsi target struct
1231 * Returns 0 if ok. Any other return is assumed to be an error and
1232 * the device is ignored.
1235 _scsih_target_alloc(struct scsi_target
*starget
)
1237 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1238 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1239 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1240 struct _sas_device
*sas_device
;
1241 struct _raid_device
*raid_device
;
1242 unsigned long flags
;
1243 struct sas_rphy
*rphy
;
1245 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1247 if (!sas_target_priv_data
)
1250 starget
->hostdata
= sas_target_priv_data
;
1251 sas_target_priv_data
->starget
= starget
;
1252 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1255 if (starget
->channel
== RAID_CHANNEL
) {
1256 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1257 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1260 sas_target_priv_data
->handle
= raid_device
->handle
;
1261 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1262 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1263 if (ioc
->is_warpdrive
)
1264 sas_target_priv_data
->raid_device
= raid_device
;
1265 raid_device
->starget
= starget
;
1267 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1271 /* sas/sata devices */
1272 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1273 rphy
= dev_to_rphy(starget
->dev
.parent
);
1274 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1275 rphy
->identify
.sas_address
);
1278 sas_target_priv_data
->handle
= sas_device
->handle
;
1279 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1280 sas_device
->starget
= starget
;
1281 sas_device
->id
= starget
->id
;
1282 sas_device
->channel
= starget
->channel
;
1283 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1284 sas_target_priv_data
->flags
|=
1285 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1287 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1293 * _scsih_target_destroy - target destroy routine
1294 * @starget: scsi target struct
1299 _scsih_target_destroy(struct scsi_target
*starget
)
1301 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1302 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1303 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1304 struct _sas_device
*sas_device
;
1305 struct _raid_device
*raid_device
;
1306 unsigned long flags
;
1307 struct sas_rphy
*rphy
;
1309 sas_target_priv_data
= starget
->hostdata
;
1310 if (!sas_target_priv_data
)
1313 if (starget
->channel
== RAID_CHANNEL
) {
1314 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1315 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1318 raid_device
->starget
= NULL
;
1319 raid_device
->sdev
= NULL
;
1321 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1325 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1326 rphy
= dev_to_rphy(starget
->dev
.parent
);
1327 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1328 rphy
->identify
.sas_address
);
1329 if (sas_device
&& (sas_device
->starget
== starget
) &&
1330 (sas_device
->id
== starget
->id
) &&
1331 (sas_device
->channel
== starget
->channel
))
1332 sas_device
->starget
= NULL
;
1334 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1337 kfree(sas_target_priv_data
);
1338 starget
->hostdata
= NULL
;
1342 * _scsih_slave_alloc - device add routine
1343 * @sdev: scsi device struct
1345 * Returns 0 if ok. Any other return is assumed to be an error and
1346 * the device is ignored.
1349 _scsih_slave_alloc(struct scsi_device
*sdev
)
1351 struct Scsi_Host
*shost
;
1352 struct MPT2SAS_ADAPTER
*ioc
;
1353 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1354 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1355 struct scsi_target
*starget
;
1356 struct _raid_device
*raid_device
;
1357 struct _sas_device
*sas_device
;
1358 unsigned long flags
;
1360 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1362 if (!sas_device_priv_data
)
1365 sas_device_priv_data
->lun
= sdev
->lun
;
1366 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1368 starget
= scsi_target(sdev
);
1369 sas_target_priv_data
= starget
->hostdata
;
1370 sas_target_priv_data
->num_luns
++;
1371 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1372 sdev
->hostdata
= sas_device_priv_data
;
1373 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1374 sdev
->no_uld_attach
= 1;
1376 shost
= dev_to_shost(&starget
->dev
);
1377 ioc
= shost_priv(shost
);
1378 if (starget
->channel
== RAID_CHANNEL
) {
1379 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1380 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1381 starget
->id
, starget
->channel
);
1383 raid_device
->sdev
= sdev
; /* raid is single lun */
1384 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1387 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1388 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1389 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1390 sas_target_priv_data
->sas_address
);
1391 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1392 sdev_printk(KERN_INFO
, sdev
,
1393 "%s : sas_device->starget set to starget @ %d\n",
1394 __func__
, __LINE__
);
1395 sas_device
->starget
= starget
;
1397 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1404 * _scsih_slave_destroy - device destroy routine
1405 * @sdev: scsi device struct
1410 _scsih_slave_destroy(struct scsi_device
*sdev
)
1412 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1413 struct scsi_target
*starget
;
1414 struct Scsi_Host
*shost
;
1415 struct MPT2SAS_ADAPTER
*ioc
;
1416 struct _sas_device
*sas_device
;
1417 unsigned long flags
;
1419 if (!sdev
->hostdata
)
1422 starget
= scsi_target(sdev
);
1423 sas_target_priv_data
= starget
->hostdata
;
1424 sas_target_priv_data
->num_luns
--;
1426 shost
= dev_to_shost(&starget
->dev
);
1427 ioc
= shost_priv(shost
);
1429 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1430 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1431 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1432 sas_target_priv_data
->sas_address
);
1433 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1434 sas_device
->starget
= NULL
;
1435 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1438 kfree(sdev
->hostdata
);
1439 sdev
->hostdata
= NULL
;
1443 * _scsih_display_sata_capabilities - sata capabilities
1444 * @ioc: per adapter object
1445 * @handle: device handle
1446 * @sdev: scsi device struct
1449 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1450 u16 handle
, struct scsi_device
*sdev
)
1452 Mpi2ConfigReply_t mpi_reply
;
1453 Mpi2SasDevicePage0_t sas_device_pg0
;
1458 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1459 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1460 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1461 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1465 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1466 MPI2_IOCSTATUS_MASK
;
1467 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1468 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1469 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1473 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1474 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1476 sdev_printk(KERN_INFO
, sdev
,
1477 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1478 "sw_preserve(%s)\n",
1479 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1480 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1481 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1483 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1484 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1485 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1489 * _scsih_is_raid - return boolean indicating device is raid volume
1490 * @dev the device struct object
1493 _scsih_is_raid(struct device
*dev
)
1495 struct scsi_device
*sdev
= to_scsi_device(dev
);
1496 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1498 if (ioc
->is_warpdrive
)
1500 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1504 * _scsih_get_resync - get raid volume resync percent complete
1505 * @dev the device struct object
1508 _scsih_get_resync(struct device
*dev
)
1510 struct scsi_device
*sdev
= to_scsi_device(dev
);
1511 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1512 static struct _raid_device
*raid_device
;
1513 unsigned long flags
;
1514 Mpi2RaidVolPage0_t vol_pg0
;
1515 Mpi2ConfigReply_t mpi_reply
;
1516 u32 volume_status_flags
;
1517 u8 percent_complete
;
1520 percent_complete
= 0;
1522 if (ioc
->is_warpdrive
)
1525 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1526 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1529 handle
= raid_device
->handle
;
1530 percent_complete
= raid_device
->percent_complete
;
1532 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1537 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1538 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1539 sizeof(Mpi2RaidVolPage0_t
))) {
1540 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1541 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1542 percent_complete
= 0;
1546 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1547 if (!(volume_status_flags
&
1548 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
1549 percent_complete
= 0;
1552 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1556 * _scsih_get_state - get raid volume level
1557 * @dev the device struct object
1560 _scsih_get_state(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
;
1569 enum raid_state state
= RAID_STATE_UNKNOWN
;
1572 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1573 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1576 handle
= raid_device
->handle
;
1577 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1582 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1583 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1584 sizeof(Mpi2RaidVolPage0_t
))) {
1585 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1586 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1590 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1591 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1592 state
= RAID_STATE_RESYNCING
;
1596 switch (vol_pg0
.VolumeState
) {
1597 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1598 case MPI2_RAID_VOL_STATE_ONLINE
:
1599 state
= RAID_STATE_ACTIVE
;
1601 case MPI2_RAID_VOL_STATE_DEGRADED
:
1602 state
= RAID_STATE_DEGRADED
;
1604 case MPI2_RAID_VOL_STATE_FAILED
:
1605 case MPI2_RAID_VOL_STATE_MISSING
:
1606 state
= RAID_STATE_OFFLINE
;
1610 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1614 * _scsih_set_level - set raid level
1615 * @sdev: scsi device struct
1616 * @volume_type: volume type
1619 _scsih_set_level(struct scsi_device
*sdev
, u8 volume_type
)
1621 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1623 switch (volume_type
) {
1624 case MPI2_RAID_VOL_TYPE_RAID0
:
1625 level
= RAID_LEVEL_0
;
1627 case MPI2_RAID_VOL_TYPE_RAID10
:
1628 level
= RAID_LEVEL_10
;
1630 case MPI2_RAID_VOL_TYPE_RAID1E
:
1631 level
= RAID_LEVEL_1E
;
1633 case MPI2_RAID_VOL_TYPE_RAID1
:
1634 level
= RAID_LEVEL_1
;
1638 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1642 * _scsih_get_volume_capabilities - volume capabilities
1643 * @ioc: per adapter object
1644 * @sas_device: the raid_device object
1646 * Returns 0 for success, else 1
1649 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1650 struct _raid_device
*raid_device
)
1652 Mpi2RaidVolPage0_t
*vol_pg0
;
1653 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1654 Mpi2SasDevicePage0_t sas_device_pg0
;
1655 Mpi2ConfigReply_t mpi_reply
;
1659 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1660 &num_pds
)) || !num_pds
) {
1661 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1662 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1667 raid_device
->num_pds
= num_pds
;
1668 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1669 sizeof(Mpi2RaidVol0PhysDisk_t
));
1670 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1672 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1673 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1678 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1679 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1680 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1681 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1687 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1689 /* figure out what the underlying devices are by
1690 * obtaining the device_info bits for the 1st device
1692 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1693 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1694 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1695 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1696 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1697 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1698 raid_device
->device_info
=
1699 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1707 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1708 * @ioc: per adapter object
1711 _scsih_disable_ddio(struct MPT2SAS_ADAPTER
*ioc
)
1713 Mpi2RaidVolPage1_t vol_pg1
;
1714 Mpi2ConfigReply_t mpi_reply
;
1715 struct _raid_device
*raid_device
;
1718 unsigned long flags
;
1721 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1722 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1723 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1724 MPI2_IOCSTATUS_MASK
;
1725 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1727 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1728 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1729 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1731 raid_device
->direct_io_enabled
= 0;
1732 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1739 * _scsih_get_num_volumes - Get number of volumes in the ioc
1740 * @ioc: per adapter object
1743 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER
*ioc
)
1745 Mpi2RaidVolPage1_t vol_pg1
;
1746 Mpi2ConfigReply_t mpi_reply
;
1752 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1753 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1754 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1755 MPI2_IOCSTATUS_MASK
;
1756 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1759 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1766 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1767 * @ioc: per adapter object
1768 * @raid_device: the raid_device object
1771 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER
*ioc
,
1772 struct _raid_device
*raid_device
)
1774 Mpi2RaidVolPage0_t
*vol_pg0
;
1775 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1776 Mpi2ConfigReply_t mpi_reply
;
1779 unsigned long stripe_sz
, block_sz
;
1780 u8 stripe_exp
, block_exp
;
1783 if (!ioc
->is_warpdrive
)
1786 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
) {
1787 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1788 "globally as drives are exposed\n", ioc
->name
);
1791 if (_scsih_get_num_volumes(ioc
) > 1) {
1792 _scsih_disable_ddio(ioc
);
1793 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1794 "globally as number of drives > 1\n", ioc
->name
);
1797 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1798 &num_pds
)) || !num_pds
) {
1799 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1800 "Failure in computing number of drives\n", ioc
->name
);
1804 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1805 sizeof(Mpi2RaidVol0PhysDisk_t
));
1806 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1808 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1809 "Memory allocation failure for RVPG0\n", ioc
->name
);
1813 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1814 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1815 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1816 "Failure in retrieving RVPG0\n", ioc
->name
);
1822 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1823 * assumed for WARPDRIVE, disable direct I/O
1825 if (num_pds
> MPT_MAX_WARPDRIVE_PDS
) {
1826 printk(MPT2SAS_WARN_FMT
"WarpDrive : Direct IO is disabled "
1827 "for the drive with handle(0x%04x): num_mem=%d, "
1828 "max_mem_allowed=%d\n", ioc
->name
, raid_device
->handle
,
1829 num_pds
, MPT_MAX_WARPDRIVE_PDS
);
1833 for (count
= 0; count
< num_pds
; count
++) {
1834 if (mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1835 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1836 vol_pg0
->PhysDisk
[count
].PhysDiskNum
) ||
1837 le16_to_cpu(pd_pg0
.DevHandle
) ==
1838 MPT2SAS_INVALID_DEVICE_HANDLE
) {
1839 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1840 "disabled for the drive with handle(0x%04x) member"
1841 "handle retrieval failed for member number=%d\n",
1842 ioc
->name
, raid_device
->handle
,
1843 vol_pg0
->PhysDisk
[count
].PhysDiskNum
);
1846 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1847 dev_max_lba
= le64_to_cpu(pd_pg0
.DeviceMaxLBA
);
1848 if (dev_max_lba
>> 32) {
1849 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1850 "disabled for the drive with handle(0x%04x) member"
1851 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1852 ioc
->name
, raid_device
->handle
,
1853 le16_to_cpu(pd_pg0
.DevHandle
),
1854 (unsigned long long)dev_max_lba
);
1858 raid_device
->pd_handle
[count
] = le16_to_cpu(pd_pg0
.DevHandle
);
1862 * Assumption for WD: Direct I/O is not supported if the volume is
1865 if (raid_device
->volume_type
!= MPI2_RAID_VOL_TYPE_RAID0
) {
1866 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1867 "for the drive with handle(0x%04x): type=%d, "
1868 "s_sz=%uK, blk_size=%u\n", ioc
->name
,
1869 raid_device
->handle
, raid_device
->volume_type
,
1870 (le32_to_cpu(vol_pg0
->StripeSize
) *
1871 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024,
1872 le16_to_cpu(vol_pg0
->BlockSize
));
1876 stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1877 stripe_exp
= find_first_bit(&stripe_sz
, 32);
1878 if (stripe_exp
== 32) {
1879 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1880 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1881 ioc
->name
, raid_device
->handle
,
1882 (le32_to_cpu(vol_pg0
->StripeSize
) *
1883 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024);
1886 raid_device
->stripe_exponent
= stripe_exp
;
1887 block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1888 block_exp
= find_first_bit(&block_sz
, 16);
1889 if (block_exp
== 16) {
1890 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1891 "for the drive with handle(0x%04x) invalid block sz %u\n",
1892 ioc
->name
, raid_device
->handle
,
1893 le16_to_cpu(vol_pg0
->BlockSize
));
1896 raid_device
->block_exponent
= block_exp
;
1897 raid_device
->direct_io_enabled
= 1;
1899 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is Enabled for the drive"
1900 " with handle(0x%04x)\n", ioc
->name
, raid_device
->handle
);
1902 * WARPDRIVE: Though the following fields are not used for direct IO,
1903 * stored for future purpose:
1905 raid_device
->max_lba
= le64_to_cpu(vol_pg0
->MaxLBA
);
1906 raid_device
->stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1907 raid_device
->block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1914 raid_device
->direct_io_enabled
= 0;
1915 for (count
= 0; count
< num_pds
; count
++)
1916 raid_device
->pd_handle
[count
] = 0;
1922 * _scsih_enable_tlr - setting TLR flags
1923 * @ioc: per adapter object
1924 * @sdev: scsi device struct
1926 * Enabling Transaction Layer Retries for tape devices when
1927 * vpd page 0x90 is present
1931 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1934 if (sdev
->type
!= TYPE_TAPE
)
1937 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1940 sas_enable_tlr(sdev
);
1941 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1942 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1948 * _scsih_slave_configure - device configure routine.
1949 * @sdev: scsi device struct
1951 * Returns 0 if ok. Any other return is assumed to be an error and
1952 * the device is ignored.
1955 _scsih_slave_configure(struct scsi_device
*sdev
)
1957 struct Scsi_Host
*shost
= sdev
->host
;
1958 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1959 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1960 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1961 struct _sas_device
*sas_device
;
1962 struct _raid_device
*raid_device
;
1963 unsigned long flags
;
1968 u16 handle
, volume_handle
= 0;
1969 u64 volume_wwid
= 0;
1972 sas_device_priv_data
= sdev
->hostdata
;
1973 sas_device_priv_data
->configured_lun
= 1;
1974 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1975 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1976 handle
= sas_target_priv_data
->handle
;
1978 /* raid volume handling */
1979 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1981 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1982 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1983 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1985 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1986 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1987 __LINE__
, __func__
));
1991 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1992 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1993 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1994 __LINE__
, __func__
));
1998 * WARPDRIVE: Initialize the required data for Direct IO
2000 _scsih_init_warpdrive_properties(ioc
, raid_device
);
2002 /* RAID Queue Depth Support
2003 * IS volume = underlying qdepth of drive type, either
2004 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2005 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2007 if (raid_device
->device_info
&
2008 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2009 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2012 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2013 if (raid_device
->device_info
&
2014 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2020 switch (raid_device
->volume_type
) {
2021 case MPI2_RAID_VOL_TYPE_RAID0
:
2024 case MPI2_RAID_VOL_TYPE_RAID1E
:
2025 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2026 if (ioc
->manu_pg10
.OEMIdentifier
&&
2027 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2028 MFG10_GF0_R10_DISPLAY
) &&
2029 !(raid_device
->num_pds
% 2))
2034 case MPI2_RAID_VOL_TYPE_RAID1
:
2035 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2038 case MPI2_RAID_VOL_TYPE_RAID10
:
2039 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2042 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2044 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2049 if (!ioc
->hide_ir_msg
)
2050 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2051 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2052 r_level
, raid_device
->handle
,
2053 (unsigned long long)raid_device
->wwid
,
2054 raid_device
->num_pds
, ds
);
2055 _scsih_change_queue_depth(sdev
, qdepth
);
2056 /* raid transport support */
2057 if (!ioc
->is_warpdrive
)
2058 _scsih_set_level(sdev
, raid_device
->volume_type
);
2062 /* non-raid handling */
2063 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2064 if (mpt2sas_config_get_volume_handle(ioc
, handle
,
2066 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2067 "failure at %s:%d/%s()!\n", ioc
->name
,
2068 __FILE__
, __LINE__
, __func__
));
2071 if (volume_handle
&& mpt2sas_config_get_volume_wwid(ioc
,
2072 volume_handle
, &volume_wwid
)) {
2073 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2074 "failure at %s:%d/%s()!\n", ioc
->name
,
2075 __FILE__
, __LINE__
, __func__
));
2080 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2081 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2082 sas_device_priv_data
->sas_target
->sas_address
);
2084 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2085 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2086 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
2087 __LINE__
, __func__
));
2090 sas_device
->volume_handle
= volume_handle
;
2091 sas_device
->volume_wwid
= volume_wwid
;
2092 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2093 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2097 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2098 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2100 else if (sas_device
->device_info
&
2101 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2104 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2105 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2106 ds
, sas_device
->handle
,
2107 (unsigned long long)sas_device
->sas_address
,
2109 (unsigned long long)sas_device
->device_name
);
2110 sdev_printk(KERN_INFO
, sdev
, "%s: "
2111 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
2112 (unsigned long long) sas_device
->enclosure_logical_id
,
2115 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2117 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2120 _scsih_change_queue_depth(sdev
, qdepth
);
2123 sas_read_port_mode_page(sdev
);
2124 _scsih_enable_tlr(ioc
, sdev
);
2130 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2131 * @sdev: scsi device struct
2132 * @bdev: pointer to block device context
2133 * @capacity: device size (in 512 byte sectors)
2134 * @params: three element array to place output:
2135 * params[0] number of heads (max 255)
2136 * params[1] number of sectors (max 63)
2137 * params[2] number of cylinders
2142 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2143 sector_t capacity
, int params
[])
2153 dummy
= heads
* sectors
;
2154 cylinders
= capacity
;
2155 sector_div(cylinders
, dummy
);
2158 * Handle extended translation size for logical drives
2161 if ((ulong
)capacity
>= 0x200000) {
2164 dummy
= heads
* sectors
;
2165 cylinders
= capacity
;
2166 sector_div(cylinders
, dummy
);
2171 params
[1] = sectors
;
2172 params
[2] = cylinders
;
2178 * _scsih_response_code - translation of device response code
2179 * @ioc: per adapter object
2180 * @response_code: response code returned by the device
2185 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
2189 switch (response_code
) {
2190 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2191 desc
= "task management request completed";
2193 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2194 desc
= "invalid frame";
2196 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2197 desc
= "task management request not supported";
2199 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2200 desc
= "task management request failed";
2202 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2203 desc
= "task management request succeeded";
2205 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2206 desc
= "invalid lun";
2209 desc
= "overlapped tag attempted";
2211 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2212 desc
= "task queued, however not sent to target";
2218 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
2219 ioc
->name
, response_code
, desc
);
2223 * _scsih_tm_done - tm completion routine
2224 * @ioc: per adapter object
2225 * @smid: system request message index
2226 * @msix_index: MSIX table index supplied by the OS
2227 * @reply: reply message frame(lower 32bit addr)
2230 * The callback handler when using scsih_issue_tm.
2232 * Return 1 meaning mf should be freed from _base_interrupt
2233 * 0 means the mf is freed from this function.
2236 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2238 MPI2DefaultReply_t
*mpi_reply
;
2240 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
2242 if (ioc
->tm_cmds
.smid
!= smid
)
2244 mpt2sas_base_flush_reply_queues(ioc
);
2245 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
2246 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2248 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2249 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
2251 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
2252 complete(&ioc
->tm_cmds
.done
);
2257 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2258 * @ioc: per adapter object
2259 * @handle: device handle
2261 * During taskmangement request, we need to freeze the device queue.
2264 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2266 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2267 struct scsi_device
*sdev
;
2270 shost_for_each_device(sdev
, ioc
->shost
) {
2273 sas_device_priv_data
= sdev
->hostdata
;
2274 if (!sas_device_priv_data
)
2276 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2277 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2279 ioc
->ignore_loginfos
= 1;
2285 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2286 * @ioc: per adapter object
2287 * @handle: device handle
2289 * During taskmangement request, we need to freeze the device queue.
2292 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2294 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2295 struct scsi_device
*sdev
;
2298 shost_for_each_device(sdev
, ioc
->shost
) {
2301 sas_device_priv_data
= sdev
->hostdata
;
2302 if (!sas_device_priv_data
)
2304 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2305 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2307 ioc
->ignore_loginfos
= 0;
2314 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2315 * @ioc: per adapter struct
2316 * @device_handle: device handle
2317 * @channel: the channel assigned by the OS
2318 * @id: the id assigned by the OS
2320 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2321 * @smid_task: smid assigned to the task
2322 * @timeout: timeout in seconds
2323 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2326 * A generic API for sending task management requests to firmware.
2328 * The callback index is set inside `ioc->tm_cb_idx`.
2330 * Return SUCCESS or FAILED.
2333 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2334 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2335 enum mutex_type m_type
)
2337 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2338 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2341 unsigned long timeleft
;
2342 struct scsiio_tracker
*scsi_lookup
= NULL
;
2345 if (m_type
== TM_MUTEX_ON
)
2346 mutex_lock(&ioc
->tm_cmds
.mutex
);
2347 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2348 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2349 __func__
, ioc
->name
);
2354 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2355 ioc
->pci_error_recovery
) {
2356 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2357 __func__
, ioc
->name
);
2362 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2363 if (ioc_state
& MPI2_DOORBELL_USED
) {
2364 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2365 "active!\n", ioc
->name
));
2366 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2368 rc
= (!rc
) ? SUCCESS
: FAILED
;
2372 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2373 mpt2sas_base_fault_info(ioc
, ioc_state
&
2374 MPI2_DOORBELL_DATA_MASK
);
2375 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2377 rc
= (!rc
) ? SUCCESS
: FAILED
;
2381 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2383 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2384 ioc
->name
, __func__
);
2389 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2390 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2392 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2393 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2395 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2396 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2397 ioc
->tm_cmds
.smid
= smid
;
2398 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2399 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2400 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2401 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2402 mpi_request
->TaskType
= type
;
2403 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2404 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2405 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2406 init_completion(&ioc
->tm_cmds
.done
);
2407 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2408 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2409 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2410 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2411 ioc
->name
, __func__
);
2412 _debug_dump_mf(mpi_request
,
2413 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2414 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2415 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2417 rc
= (!rc
) ? SUCCESS
: FAILED
;
2418 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2419 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2424 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2425 mpi_reply
= ioc
->tm_cmds
.reply
;
2426 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2427 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2428 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2429 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2430 le32_to_cpu(mpi_reply
->TerminationCount
)));
2431 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2432 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2433 if (mpi_reply
->IOCStatus
)
2434 _debug_dump_mf(mpi_request
,
2435 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2440 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2442 if (scsi_lookup
->scmd
== NULL
)
2447 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2448 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2454 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2455 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2456 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2461 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2469 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2470 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2471 if (m_type
== TM_MUTEX_ON
)
2472 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2477 if (m_type
== TM_MUTEX_ON
)
2478 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2483 * _scsih_tm_display_info - displays info about the device
2484 * @ioc: per adapter struct
2485 * @scmd: pointer to scsi command object
2487 * Called by task management callback handlers.
2490 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2492 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2493 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2494 struct _sas_device
*sas_device
= NULL
;
2495 unsigned long flags
;
2496 char *device_str
= NULL
;
2500 if (ioc
->hide_ir_msg
)
2501 device_str
= "WarpDrive";
2503 device_str
= "volume";
2505 scsi_print_command(scmd
);
2506 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2507 starget_printk(KERN_INFO
, starget
, "%s handle(0x%04x), "
2508 "%s wwid(0x%016llx)\n", device_str
, priv_target
->handle
,
2509 device_str
, (unsigned long long)priv_target
->sas_address
);
2511 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2512 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2513 priv_target
->sas_address
);
2515 if (priv_target
->flags
&
2516 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2517 starget_printk(KERN_INFO
, starget
,
2518 "volume handle(0x%04x), "
2519 "volume wwid(0x%016llx)\n",
2520 sas_device
->volume_handle
,
2521 (unsigned long long)sas_device
->volume_wwid
);
2523 starget_printk(KERN_INFO
, starget
,
2524 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2526 (unsigned long long)sas_device
->sas_address
,
2528 starget_printk(KERN_INFO
, starget
,
2529 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2530 (unsigned long long)sas_device
->enclosure_logical_id
,
2533 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2538 * _scsih_abort - eh threads main abort routine
2539 * @scmd: pointer to scsi command object
2541 * Returns SUCCESS if command aborted else FAILED
2544 _scsih_abort(struct scsi_cmnd
*scmd
)
2546 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2547 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2552 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2553 "scmd(%p)\n", scmd
);
2554 _scsih_tm_display_info(ioc
, scmd
);
2556 sas_device_priv_data
= scmd
->device
->hostdata
;
2557 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2558 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2559 "scmd(%p)\n", scmd
);
2560 scmd
->result
= DID_NO_CONNECT
<< 16;
2561 scmd
->scsi_done(scmd
);
2566 /* search for the command */
2567 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2569 scmd
->result
= DID_RESET
<< 16;
2574 /* for hidden raid components and volumes this is not supported */
2575 if (sas_device_priv_data
->sas_target
->flags
&
2576 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2577 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2578 scmd
->result
= DID_RESET
<< 16;
2583 mpt2sas_halt_firmware(ioc
);
2585 handle
= sas_device_priv_data
->sas_target
->handle
;
2586 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2587 scmd
->device
->id
, scmd
->device
->lun
,
2588 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30, TM_MUTEX_ON
);
2591 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2592 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2597 * _scsih_dev_reset - eh threads main device reset routine
2598 * @scmd: pointer to scsi command object
2600 * Returns SUCCESS if command aborted else FAILED
2603 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2605 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2606 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2607 struct _sas_device
*sas_device
;
2608 unsigned long flags
;
2612 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2614 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2615 "scmd(%p)\n", scmd
);
2616 _scsih_tm_display_info(ioc
, scmd
);
2618 sas_device_priv_data
= scmd
->device
->hostdata
;
2619 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2620 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2621 "scmd(%p)\n", scmd
);
2622 scmd
->result
= DID_NO_CONNECT
<< 16;
2623 scmd
->scsi_done(scmd
);
2628 /* for hidden raid components obtain the volume_handle */
2630 if (sas_device_priv_data
->sas_target
->flags
&
2631 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2632 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2633 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2634 sas_device_priv_data
->sas_target
->handle
);
2636 handle
= sas_device
->volume_handle
;
2637 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2639 handle
= sas_device_priv_data
->sas_target
->handle
;
2642 scmd
->result
= DID_RESET
<< 16;
2647 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2648 scmd
->device
->id
, scmd
->device
->lun
,
2649 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, TM_MUTEX_ON
);
2652 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2653 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2658 * _scsih_target_reset - eh threads main target reset routine
2659 * @scmd: pointer to scsi command object
2661 * Returns SUCCESS if command aborted else FAILED
2664 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2666 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2667 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2668 struct _sas_device
*sas_device
;
2669 unsigned long flags
;
2672 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2674 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2675 "scmd(%p)\n", scmd
);
2676 _scsih_tm_display_info(ioc
, scmd
);
2678 sas_device_priv_data
= scmd
->device
->hostdata
;
2679 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2680 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2681 "scmd(%p)\n", scmd
);
2682 scmd
->result
= DID_NO_CONNECT
<< 16;
2683 scmd
->scsi_done(scmd
);
2688 /* for hidden raid components obtain the volume_handle */
2690 if (sas_device_priv_data
->sas_target
->flags
&
2691 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2692 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2693 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2694 sas_device_priv_data
->sas_target
->handle
);
2696 handle
= sas_device
->volume_handle
;
2697 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2699 handle
= sas_device_priv_data
->sas_target
->handle
;
2702 scmd
->result
= DID_RESET
<< 16;
2707 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2708 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2712 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2713 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2718 * _scsih_host_reset - eh threads main host reset routine
2719 * @scmd: pointer to scsi command object
2721 * Returns SUCCESS if command aborted else FAILED
2724 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2726 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2729 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2731 scsi_print_command(scmd
);
2733 if (ioc
->is_driver_loading
) {
2734 printk(MPT2SAS_INFO_FMT
"Blocking the host reset\n",
2740 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2742 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2745 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2746 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2752 * _scsih_fw_event_add - insert and queue up fw_event
2753 * @ioc: per adapter object
2754 * @fw_event: object describing the event
2755 * Context: This function will acquire ioc->fw_event_lock.
2757 * This adds the firmware event object into link list, then queues it up to
2758 * be processed from user context.
2763 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2765 unsigned long flags
;
2767 if (ioc
->firmware_event_thread
== NULL
)
2770 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2771 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2772 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2773 queue_delayed_work(ioc
->firmware_event_thread
,
2774 &fw_event
->delayed_work
, 0);
2775 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2779 * _scsih_fw_event_free - delete fw_event
2780 * @ioc: per adapter object
2781 * @fw_event: object describing the event
2782 * Context: This function will acquire ioc->fw_event_lock.
2784 * This removes firmware event object from link list, frees associated memory.
2789 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2792 unsigned long flags
;
2794 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2795 list_del(&fw_event
->list
);
2797 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2802 * _scsih_error_recovery_delete_devices - remove devices not responding
2803 * @ioc: per adapter object
2808 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER
*ioc
)
2810 struct fw_event_work
*fw_event
;
2812 if (ioc
->is_driver_loading
)
2815 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2819 fw_event
->event
= MPT2SAS_REMOVE_UNRESPONDING_DEVICES
;
2820 fw_event
->ioc
= ioc
;
2821 _scsih_fw_event_add(ioc
, fw_event
);
2825 * mpt2sas_port_enable_complete - port enable completed (fake event)
2826 * @ioc: per adapter object
2831 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER
*ioc
)
2833 struct fw_event_work
*fw_event
;
2835 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2838 fw_event
->event
= MPT2SAS_PORT_ENABLE_COMPLETE
;
2839 fw_event
->ioc
= ioc
;
2840 _scsih_fw_event_add(ioc
, fw_event
);
2844 * _scsih_fw_event_cleanup_queue - cleanup event queue
2845 * @ioc: per adapter object
2847 * Walk the firmware event queue, either killing timers, or waiting
2848 * for outstanding events to complete
2853 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2855 struct fw_event_work
*fw_event
, *next
;
2857 if (list_empty(&ioc
->fw_event_list
) ||
2858 !ioc
->firmware_event_thread
|| in_interrupt())
2861 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2862 if (cancel_delayed_work_sync(&fw_event
->delayed_work
)) {
2863 _scsih_fw_event_free(ioc
, fw_event
);
2870 * _scsih_ublock_io_all_device - unblock every device
2871 * @ioc: per adapter object
2873 * change the device state from block to running
2876 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2878 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2879 struct scsi_device
*sdev
;
2881 shost_for_each_device(sdev
, ioc
->shost
) {
2882 sas_device_priv_data
= sdev
->hostdata
;
2883 if (!sas_device_priv_data
)
2885 if (!sas_device_priv_data
->block
)
2887 sas_device_priv_data
->block
= 0;
2888 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_running, "
2890 sas_device_priv_data
->sas_target
->handle
));
2891 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2895 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2896 * @ioc: per adapter object
2897 * @handle: device handle
2899 * During device pull we need to appropiately set the sdev state.
2902 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
2904 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2905 struct scsi_device
*sdev
;
2907 shost_for_each_device(sdev
, ioc
->shost
) {
2908 sas_device_priv_data
= sdev
->hostdata
;
2909 if (!sas_device_priv_data
)
2911 if (!sas_device_priv_data
->block
)
2913 if (sas_device_priv_data
->sas_target
->sas_address
==
2915 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2916 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2917 "sas address(0x%016llx)\n", ioc
->name
,
2918 (unsigned long long)sas_address
));
2919 sas_device_priv_data
->block
= 0;
2920 scsi_internal_device_unblock(sdev
, SDEV_RUNNING
);
2926 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2927 * @ioc: per adapter object
2928 * @handle: device handle
2930 * During device pull we need to appropiately set the sdev state.
2933 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2935 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2936 struct scsi_device
*sdev
;
2938 shost_for_each_device(sdev
, ioc
->shost
) {
2939 sas_device_priv_data
= sdev
->hostdata
;
2940 if (!sas_device_priv_data
)
2942 if (sas_device_priv_data
->block
)
2944 sas_device_priv_data
->block
= 1;
2945 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_blocked, "
2947 sas_device_priv_data
->sas_target
->handle
));
2948 scsi_internal_device_block(sdev
);
2954 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2955 * @ioc: per adapter object
2956 * @handle: device handle
2958 * During device pull we need to appropiately set the sdev state.
2961 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2963 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2964 struct scsi_device
*sdev
;
2966 shost_for_each_device(sdev
, ioc
->shost
) {
2967 sas_device_priv_data
= sdev
->hostdata
;
2968 if (!sas_device_priv_data
)
2970 if (sas_device_priv_data
->block
)
2972 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2973 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2974 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2975 "handle(0x%04x)\n", ioc
->name
, handle
));
2976 sas_device_priv_data
->block
= 1;
2977 scsi_internal_device_block(sdev
);
2983 * _scsih_block_io_to_children_attached_to_ex
2984 * @ioc: per adapter object
2985 * @sas_expander: the sas_device object
2987 * This routine set sdev state to SDEV_BLOCK for all devices
2988 * attached to this expander. This function called when expander is
2992 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2993 struct _sas_node
*sas_expander
)
2995 struct _sas_port
*mpt2sas_port
;
2996 struct _sas_device
*sas_device
;
2997 struct _sas_node
*expander_sibling
;
2998 unsigned long flags
;
3003 list_for_each_entry(mpt2sas_port
,
3004 &sas_expander
->sas_port_list
, port_list
) {
3005 if (mpt2sas_port
->remote_identify
.device_type
==
3007 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3009 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3010 mpt2sas_port
->remote_identify
.sas_address
);
3012 set_bit(sas_device
->handle
,
3013 ioc
->blocking_handles
);
3014 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3018 list_for_each_entry(mpt2sas_port
,
3019 &sas_expander
->sas_port_list
, port_list
) {
3021 if (mpt2sas_port
->remote_identify
.device_type
==
3022 SAS_EDGE_EXPANDER_DEVICE
||
3023 mpt2sas_port
->remote_identify
.device_type
==
3024 SAS_FANOUT_EXPANDER_DEVICE
) {
3026 mpt2sas_scsih_expander_find_by_sas_address(
3027 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
3028 _scsih_block_io_to_children_attached_to_ex(ioc
,
3035 * _scsih_block_io_to_children_attached_directly
3036 * @ioc: per adapter object
3037 * @event_data: topology change event data
3039 * This routine set sdev state to SDEV_BLOCK for all devices
3040 * direct attached during device pull.
3043 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
3044 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3051 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3052 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3055 phy_number
= event_data
->StartPhyNum
+ i
;
3056 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3057 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3058 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3059 _scsih_block_io_device(ioc
, handle
);
3064 * _scsih_tm_tr_send - send task management request
3065 * @ioc: per adapter object
3066 * @handle: device handle
3067 * Context: interrupt time.
3069 * This code is to initiate the device removal handshake protocol
3070 * with controller firmware. This function will issue target reset
3071 * using high priority request queue. It will send a sas iounit
3072 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3074 * This is designed to send muliple task management request at the same
3075 * time to the fifo. If the fifo is full, we will append the request,
3076 * and process it in a future completion.
3079 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3081 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3083 struct _sas_device
*sas_device
;
3084 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
3085 u64 sas_address
= 0;
3086 unsigned long flags
;
3087 struct _tr_list
*delayed_tr
;
3090 if (ioc
->remove_host
) {
3091 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3092 "removed: handle(0x%04x)\n", __func__
, ioc
->name
, handle
));
3094 } else if (ioc
->pci_error_recovery
) {
3095 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3096 "error recovery: handle(0x%04x)\n", __func__
, ioc
->name
,
3100 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3101 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3102 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3103 "operational: handle(0x%04x)\n", __func__
, ioc
->name
,
3108 /* if PD, then return */
3109 if (test_bit(handle
, ioc
->pd_handles
))
3112 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3113 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3114 if (sas_device
&& sas_device
->starget
&&
3115 sas_device
->starget
->hostdata
) {
3116 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3117 sas_target_priv_data
->deleted
= 1;
3118 sas_address
= sas_device
->sas_address
;
3120 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3122 if (sas_target_priv_data
) {
3123 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"setting delete flag: "
3124 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, handle
,
3125 (unsigned long long)sas_address
));
3126 _scsih_ublock_io_device(ioc
, sas_address
);
3127 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
3130 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3132 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3135 INIT_LIST_HEAD(&delayed_tr
->list
);
3136 delayed_tr
->handle
= handle
;
3137 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3138 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3139 "DELAYED:tr:handle(0x%04x), (open)\n",
3140 ioc
->name
, handle
));
3144 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3145 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3146 ioc
->tm_tr_cb_idx
));
3147 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3148 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3149 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3150 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3151 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3152 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3158 * _scsih_sas_control_complete - completion routine
3159 * @ioc: per adapter object
3160 * @smid: system request message index
3161 * @msix_index: MSIX table index supplied by the OS
3162 * @reply: reply message frame(lower 32bit addr)
3163 * Context: interrupt time.
3165 * This is the sas iounit control completion routine.
3166 * This code is part of the code to initiate the device removal
3167 * handshake protocol with controller firmware.
3169 * Return 1 meaning mf should be freed from _base_interrupt
3170 * 0 means the mf is freed from this function.
3173 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3174 u8 msix_index
, u32 reply
)
3176 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3177 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3178 if (likely(mpi_reply
)) {
3179 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3180 "sc_complete:handle(0x%04x), (open) "
3181 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3182 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3183 le16_to_cpu(mpi_reply
->IOCStatus
),
3184 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3186 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3187 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3193 * _scsih_tm_tr_volume_send - send target reset request for volumes
3194 * @ioc: per adapter object
3195 * @handle: device handle
3196 * Context: interrupt time.
3198 * This is designed to send muliple task management request at the same
3199 * time to the fifo. If the fifo is full, we will append the request,
3200 * and process it in a future completion.
3203 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3205 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3207 struct _tr_list
*delayed_tr
;
3209 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3210 ioc
->pci_error_recovery
) {
3211 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3212 "progress!\n", __func__
, ioc
->name
));
3216 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3218 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3221 INIT_LIST_HEAD(&delayed_tr
->list
);
3222 delayed_tr
->handle
= handle
;
3223 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3224 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3225 "DELAYED:tr:handle(0x%04x), (open)\n",
3226 ioc
->name
, handle
));
3230 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3231 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3232 ioc
->tm_tr_volume_cb_idx
));
3233 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3234 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3235 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3236 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3237 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3238 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3242 * _scsih_tm_volume_tr_complete - target reset completion
3243 * @ioc: per adapter object
3244 * @smid: system request message index
3245 * @msix_index: MSIX table index supplied by the OS
3246 * @reply: reply message frame(lower 32bit addr)
3247 * Context: interrupt time.
3249 * Return 1 meaning mf should be freed from _base_interrupt
3250 * 0 means the mf is freed from this function.
3253 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3254 u8 msix_index
, u32 reply
)
3257 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3258 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3259 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3261 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3262 ioc
->pci_error_recovery
) {
3263 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3264 "progress!\n", __func__
, ioc
->name
));
3267 if (unlikely(!mpi_reply
)) {
3268 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3269 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3272 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3273 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3274 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3275 dewtprintk(ioc
, printk("spurious interrupt: "
3276 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
3277 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3281 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3282 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3283 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3284 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3285 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3286 le32_to_cpu(mpi_reply
->TerminationCount
)));
3288 return _scsih_check_for_pending_tm(ioc
, smid
);
3292 * _scsih_tm_tr_complete -
3293 * @ioc: per adapter object
3294 * @smid: system request message index
3295 * @msix_index: MSIX table index supplied by the OS
3296 * @reply: reply message frame(lower 32bit addr)
3297 * Context: interrupt time.
3299 * This is the target reset completion routine.
3300 * This code is part of the code to initiate the device removal
3301 * handshake protocol with controller firmware.
3302 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3304 * Return 1 meaning mf should be freed from _base_interrupt
3305 * 0 means the mf is freed from this function.
3308 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3312 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3313 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3314 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3315 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3319 if (ioc
->remove_host
) {
3320 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3321 "removed\n", __func__
, ioc
->name
));
3323 } else if (ioc
->pci_error_recovery
) {
3324 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3325 "error recovery\n", __func__
, ioc
->name
));
3328 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3329 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3330 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3331 "operational\n", __func__
, ioc
->name
));
3334 if (unlikely(!mpi_reply
)) {
3335 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
3336 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3339 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3340 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3341 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3342 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
3343 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
3344 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3348 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3349 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3350 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3351 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3352 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3353 le32_to_cpu(mpi_reply
->TerminationCount
)));
3355 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3356 if (!smid_sas_ctrl
) {
3357 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3358 ioc
->name
, __func__
);
3362 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
3363 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
3364 ioc
->tm_sas_control_cb_idx
));
3365 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3366 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3367 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3368 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3369 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3370 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3372 return _scsih_check_for_pending_tm(ioc
, smid
);
3376 * _scsih_check_for_pending_tm - check for pending task management
3377 * @ioc: per adapter object
3378 * @smid: system request message index
3380 * This will check delayed target reset list, and feed the
3383 * Return 1 meaning mf should be freed from _base_interrupt
3384 * 0 means the mf is freed from this function.
3387 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3389 struct _tr_list
*delayed_tr
;
3391 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3392 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3393 struct _tr_list
, list
);
3394 mpt2sas_base_free_smid(ioc
, smid
);
3395 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3396 list_del(&delayed_tr
->list
);
3401 if (!list_empty(&ioc
->delayed_tr_list
)) {
3402 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3403 struct _tr_list
, list
);
3404 mpt2sas_base_free_smid(ioc
, smid
);
3405 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3406 list_del(&delayed_tr
->list
);
3415 * _scsih_check_topo_delete_events - sanity check on topo events
3416 * @ioc: per adapter object
3417 * @event_data: the event data payload
3419 * This routine added to better handle cable breaker.
3421 * This handles the case where driver receives multiple expander
3422 * add and delete events in a single shot. When there is a delete event
3423 * the routine will void any pending add events waiting in the event queue.
3428 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3429 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3431 struct fw_event_work
*fw_event
;
3432 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3433 u16 expander_handle
;
3434 struct _sas_node
*sas_expander
;
3435 unsigned long flags
;
3439 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3440 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3443 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3444 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3445 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3446 _scsih_tm_tr_send(ioc
, handle
);
3449 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3450 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3451 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3454 if (event_data
->ExpStatus
==
3455 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
3456 /* put expander attached devices into blocking state */
3457 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3458 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3460 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3461 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3463 handle
= find_first_bit(ioc
->blocking_handles
,
3464 ioc
->facts
.MaxDevHandle
);
3465 if (handle
< ioc
->facts
.MaxDevHandle
)
3466 _scsih_block_io_device(ioc
, handle
);
3467 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
3468 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3469 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3471 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3474 /* mark ignore flag for pending events */
3475 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3476 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3477 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3480 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
3481 fw_event
->event_data
;
3482 if (local_event_data
->ExpStatus
==
3483 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3484 local_event_data
->ExpStatus
==
3485 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3486 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3488 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3489 "setting ignoring flag\n", ioc
->name
));
3490 fw_event
->ignore
= 1;
3494 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3498 * _scsih_set_volume_delete_flag - setting volume delete flag
3499 * @ioc: per adapter object
3500 * @handle: device handle
3506 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3508 struct _raid_device
*raid_device
;
3509 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3510 unsigned long flags
;
3512 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3513 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3514 if (raid_device
&& raid_device
->starget
&&
3515 raid_device
->starget
->hostdata
) {
3516 sas_target_priv_data
=
3517 raid_device
->starget
->hostdata
;
3518 sas_target_priv_data
->deleted
= 1;
3519 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3520 "setting delete flag: handle(0x%04x), "
3521 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3522 (unsigned long long) raid_device
->wwid
));
3524 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3528 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3529 * @handle: input handle
3530 * @a: handle for volume a
3531 * @b: handle for volume b
3533 * IR firmware only supports two raid volumes. The purpose of this
3534 * routine is to set the volume handle in either a or b. When the given
3535 * input handle is non-zero, or when a and b have not been set before.
3538 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3540 if (!handle
|| handle
== *a
|| handle
== *b
)
3549 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3550 * @ioc: per adapter object
3551 * @event_data: the event data payload
3552 * Context: interrupt time.
3554 * This routine will send target reset to volume, followed by target
3555 * resets to the PDs. This is called when a PD has been removed, or
3556 * volume has been deleted or removed. When the target reset is sent
3557 * to volume, the PD target resets need to be queued to start upon
3558 * completion of the volume target reset.
3563 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3564 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3566 Mpi2EventIrConfigElement_t
*element
;
3568 u16 handle
, volume_handle
, a
, b
;
3569 struct _tr_list
*delayed_tr
;
3574 if (ioc
->is_warpdrive
)
3577 /* Volume Resets for Deleted or Removed */
3578 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3579 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3580 if (element
->ReasonCode
==
3581 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3582 element
->ReasonCode
==
3583 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3584 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3585 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3586 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3590 /* Volume Resets for UNHIDE events */
3591 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3592 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3593 if (le32_to_cpu(event_data
->Flags
) &
3594 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3596 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3597 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3598 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3603 _scsih_tm_tr_volume_send(ioc
, a
);
3605 _scsih_tm_tr_volume_send(ioc
, b
);
3607 /* PD target resets */
3608 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3609 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3610 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3612 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3613 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3614 clear_bit(handle
, ioc
->pd_handles
);
3616 _scsih_tm_tr_send(ioc
, handle
);
3617 else if (volume_handle
== a
|| volume_handle
== b
) {
3618 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3619 BUG_ON(!delayed_tr
);
3620 INIT_LIST_HEAD(&delayed_tr
->list
);
3621 delayed_tr
->handle
= handle
;
3622 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3623 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3624 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3627 _scsih_tm_tr_send(ioc
, handle
);
3633 * _scsih_check_volume_delete_events - set delete flag for volumes
3634 * @ioc: per adapter object
3635 * @event_data: the event data payload
3636 * Context: interrupt time.
3638 * This will handle the case when the cable connected to entire volume is
3639 * pulled. We will take care of setting the deleted flag so normal IO will
3645 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3646 Mpi2EventDataIrVolume_t
*event_data
)
3650 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3652 state
= le32_to_cpu(event_data
->NewValue
);
3653 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3654 MPI2_RAID_VOL_STATE_FAILED
)
3655 _scsih_set_volume_delete_flag(ioc
,
3656 le16_to_cpu(event_data
->VolDevHandle
));
3660 * _scsih_temp_threshold_events - display temperature threshold exceeded events
3661 * @ioc: per adapter object
3662 * @event_data: the temp threshold event data
3663 * Context: interrupt time.
3668 _scsih_temp_threshold_events(struct MPT2SAS_ADAPTER
*ioc
,
3669 Mpi2EventDataTemperature_t
*event_data
)
3671 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
3672 printk(MPT2SAS_ERR_FMT
"Temperature Threshold flags %s%s%s%s"
3673 " exceeded for Sensor: %d !!!\n", ioc
->name
,
3674 ((le16_to_cpu(event_data
->Status
) & 0x1) == 1) ? "0 " : " ",
3675 ((le16_to_cpu(event_data
->Status
) & 0x2) == 2) ? "1 " : " ",
3676 ((le16_to_cpu(event_data
->Status
) & 0x4) == 4) ? "2 " : " ",
3677 ((le16_to_cpu(event_data
->Status
) & 0x8) == 8) ? "3 " : " ",
3678 event_data
->SensorNum
);
3679 printk(MPT2SAS_ERR_FMT
"Current Temp In Celsius: %d\n",
3680 ioc
->name
, event_data
->CurrentTemperature
);
3685 * _scsih_flush_running_cmds - completing outstanding commands.
3686 * @ioc: per adapter object
3688 * The flushing out of all pending scmd commands following host reset,
3689 * where all IO is dropped to the floor.
3694 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3696 struct scsi_cmnd
*scmd
;
3700 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3701 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3705 mpt2sas_base_free_smid(ioc
, smid
);
3706 scsi_dma_unmap(scmd
);
3707 if (ioc
->pci_error_recovery
)
3708 scmd
->result
= DID_NO_CONNECT
<< 16;
3710 scmd
->result
= DID_RESET
<< 16;
3711 scmd
->scsi_done(scmd
);
3713 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3718 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3719 * @scmd: pointer to scsi command object
3720 * @mpi_request: pointer to the SCSI_IO reqest message frame
3722 * Supporting protection 1 and 3.
3727 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3730 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3731 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3733 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3736 if (prot_op
== SCSI_PROT_READ_STRIP
)
3737 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3738 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3739 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3743 switch (prot_type
) {
3744 case SCSI_PROT_DIF_TYPE1
:
3745 case SCSI_PROT_DIF_TYPE2
:
3748 * enable ref/guard checking
3749 * auto increment ref tag
3751 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3752 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3753 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3754 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3755 cpu_to_be32(scsi_get_lba(scmd
));
3758 case SCSI_PROT_DIF_TYPE3
:
3761 * enable guard checking
3763 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3766 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3767 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3771 * _scsih_eedp_error_handling - return sense code for EEDP errors
3772 * @scmd: pointer to scsi command object
3773 * @ioc_status: ioc status
3778 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3782 switch (ioc_status
) {
3783 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3786 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3789 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3797 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10, ascq
);
3798 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
3799 SAM_STAT_CHECK_CONDITION
;
3803 * _scsih_scsi_direct_io_get - returns direct io flag
3804 * @ioc: per adapter object
3805 * @smid: system request message index
3807 * Returns the smid stored scmd pointer.
3810 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3812 return ioc
->scsi_lookup
[smid
- 1].direct_io
;
3816 * _scsih_scsi_direct_io_set - sets direct io flag
3817 * @ioc: per adapter object
3818 * @smid: system request message index
3819 * @direct_io: Zero or non-zero value to set in the direct_io flag
3824 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 direct_io
)
3826 ioc
->scsi_lookup
[smid
- 1].direct_io
= direct_io
;
3831 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3832 * @ioc: per adapter object
3833 * @scmd: pointer to scsi command object
3834 * @raid_device: pointer to raid device data structure
3835 * @mpi_request: pointer to the SCSI_IO reqest message frame
3836 * @smid: system request message index
3841 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3842 struct _raid_device
*raid_device
, Mpi2SCSIIORequest_t
*mpi_request
,
3845 sector_t v_lba
, p_lba
, stripe_off
, column
, io_size
;
3846 u32 stripe_sz
, stripe_exp
;
3847 u8 num_pds
, cmd
= scmd
->cmnd
[0];
3849 if (cmd
!= READ_10
&& cmd
!= WRITE_10
&&
3850 cmd
!= READ_16
&& cmd
!= WRITE_16
)
3853 if (cmd
== READ_10
|| cmd
== WRITE_10
)
3854 v_lba
= get_unaligned_be32(&mpi_request
->CDB
.CDB32
[2]);
3856 v_lba
= get_unaligned_be64(&mpi_request
->CDB
.CDB32
[2]);
3858 io_size
= scsi_bufflen(scmd
) >> raid_device
->block_exponent
;
3860 if (v_lba
+ io_size
- 1 > raid_device
->max_lba
)
3863 stripe_sz
= raid_device
->stripe_sz
;
3864 stripe_exp
= raid_device
->stripe_exponent
;
3865 stripe_off
= v_lba
& (stripe_sz
- 1);
3867 /* Return unless IO falls within a stripe */
3868 if (stripe_off
+ io_size
> stripe_sz
)
3871 num_pds
= raid_device
->num_pds
;
3872 p_lba
= v_lba
>> stripe_exp
;
3873 column
= sector_div(p_lba
, num_pds
);
3874 p_lba
= (p_lba
<< stripe_exp
) + stripe_off
;
3876 mpi_request
->DevHandle
= cpu_to_le16(raid_device
->pd_handle
[column
]);
3878 if (cmd
== READ_10
|| cmd
== WRITE_10
)
3879 put_unaligned_be32(lower_32_bits(p_lba
),
3880 &mpi_request
->CDB
.CDB32
[2]);
3882 put_unaligned_be64(p_lba
, &mpi_request
->CDB
.CDB32
[2]);
3884 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3888 * _scsih_qcmd - main scsi request entry point
3889 * @scmd: pointer to scsi command object
3890 * @done: function pointer to be invoked on completion
3892 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3894 * Returns 0 on success. If there's a failure, return either:
3895 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3896 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3899 _scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
3901 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
3902 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3903 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3904 struct _raid_device
*raid_device
;
3905 Mpi2SCSIIORequest_t
*mpi_request
;
3909 sas_device_priv_data
= scmd
->device
->hostdata
;
3910 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3911 scmd
->result
= DID_NO_CONNECT
<< 16;
3912 scmd
->scsi_done(scmd
);
3916 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3917 scmd
->result
= DID_NO_CONNECT
<< 16;
3918 scmd
->scsi_done(scmd
);
3922 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3923 /* invalid device handle */
3924 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3925 scmd
->result
= DID_NO_CONNECT
<< 16;
3926 scmd
->scsi_done(scmd
);
3930 /* host recovery or link resets sent via IOCTLs */
3931 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3932 return SCSI_MLQUEUE_HOST_BUSY
;
3933 /* device busy with task management */
3934 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3935 return SCSI_MLQUEUE_DEVICE_BUSY
;
3936 /* device has been deleted */
3937 else if (sas_target_priv_data
->deleted
) {
3938 scmd
->result
= DID_NO_CONNECT
<< 16;
3939 scmd
->scsi_done(scmd
);
3943 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3944 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3945 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3946 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3948 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3951 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3953 /* Make sure Device is not raid volume.
3954 * We do not expose raid functionality to upper layer for warpdrive.
3956 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3957 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3958 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3960 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3962 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3963 ioc
->name
, __func__
);
3966 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3967 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3968 _scsih_setup_eedp(scmd
, mpi_request
);
3969 if (scmd
->cmd_len
== 32)
3970 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3971 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3972 if (sas_device_priv_data
->sas_target
->flags
&
3973 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3974 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3976 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3977 mpi_request
->DevHandle
=
3978 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3979 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3980 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3981 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3982 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3983 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3984 mpi_request
->SenseBufferLowAddress
=
3985 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3986 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3987 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3988 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3989 mpi_request
->VF_ID
= 0; /* TODO */
3990 mpi_request
->VP_ID
= 0;
3991 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3993 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3995 if (!mpi_request
->DataLength
) {
3996 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3998 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3999 mpt2sas_base_free_smid(ioc
, smid
);
4004 raid_device
= sas_target_priv_data
->raid_device
;
4005 if (raid_device
&& raid_device
->direct_io_enabled
)
4006 _scsih_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4009 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
4010 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4011 le16_to_cpu(mpi_request
->DevHandle
));
4013 mpt2sas_base_put_smid_default(ioc
, smid
);
4017 return SCSI_MLQUEUE_HOST_BUSY
;
4021 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4022 * @sense_buffer: sense data returned by target
4023 * @data: normalized skey/asc/ascq
4028 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4030 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4031 /* descriptor format */
4032 data
->skey
= sense_buffer
[1] & 0x0F;
4033 data
->asc
= sense_buffer
[2];
4034 data
->ascq
= sense_buffer
[3];
4037 data
->skey
= sense_buffer
[2] & 0x0F;
4038 data
->asc
= sense_buffer
[12];
4039 data
->ascq
= sense_buffer
[13];
4043 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4045 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4046 * @ioc: per adapter object
4047 * @scmd: pointer to scsi command object
4048 * @mpi_reply: reply mf payload returned from firmware
4050 * scsi_status - SCSI Status code returned from target device
4051 * scsi_state - state info associated with SCSI_IO determined by ioc
4052 * ioc_status - ioc supplied status info
4057 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4058 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4062 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4063 MPI2_IOCSTATUS_MASK
;
4064 u8 scsi_state
= mpi_reply
->SCSIState
;
4065 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4066 char *desc_ioc_state
= NULL
;
4067 char *desc_scsi_status
= NULL
;
4068 char *desc_scsi_state
= ioc
->tmp_string
;
4069 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4070 struct _sas_device
*sas_device
= NULL
;
4071 unsigned long flags
;
4072 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4073 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
4074 char *device_str
= NULL
;
4079 if (ioc
->hide_ir_msg
)
4080 device_str
= "WarpDrive";
4082 device_str
= "volume";
4084 if (log_info
== 0x31170000)
4087 switch (ioc_status
) {
4088 case MPI2_IOCSTATUS_SUCCESS
:
4089 desc_ioc_state
= "success";
4091 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4092 desc_ioc_state
= "invalid function";
4094 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4095 desc_ioc_state
= "scsi recovered error";
4097 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4098 desc_ioc_state
= "scsi invalid dev handle";
4100 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4101 desc_ioc_state
= "scsi device not there";
4103 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4104 desc_ioc_state
= "scsi data overrun";
4106 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4107 desc_ioc_state
= "scsi data underrun";
4109 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4110 desc_ioc_state
= "scsi io data error";
4112 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4113 desc_ioc_state
= "scsi protocol error";
4115 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4116 desc_ioc_state
= "scsi task terminated";
4118 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4119 desc_ioc_state
= "scsi residual mismatch";
4121 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4122 desc_ioc_state
= "scsi task mgmt failed";
4124 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4125 desc_ioc_state
= "scsi ioc terminated";
4127 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4128 desc_ioc_state
= "scsi ext terminated";
4130 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4131 desc_ioc_state
= "eedp guard error";
4133 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4134 desc_ioc_state
= "eedp ref tag error";
4136 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4137 desc_ioc_state
= "eedp app tag error";
4140 desc_ioc_state
= "unknown";
4144 switch (scsi_status
) {
4145 case MPI2_SCSI_STATUS_GOOD
:
4146 desc_scsi_status
= "good";
4148 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4149 desc_scsi_status
= "check condition";
4151 case MPI2_SCSI_STATUS_CONDITION_MET
:
4152 desc_scsi_status
= "condition met";
4154 case MPI2_SCSI_STATUS_BUSY
:
4155 desc_scsi_status
= "busy";
4157 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4158 desc_scsi_status
= "intermediate";
4160 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4161 desc_scsi_status
= "intermediate condmet";
4163 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4164 desc_scsi_status
= "reservation conflict";
4166 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4167 desc_scsi_status
= "command terminated";
4169 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4170 desc_scsi_status
= "task set full";
4172 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4173 desc_scsi_status
= "aca active";
4175 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4176 desc_scsi_status
= "task aborted";
4179 desc_scsi_status
= "unknown";
4183 desc_scsi_state
[0] = '\0';
4185 desc_scsi_state
= " ";
4186 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4187 strcat(desc_scsi_state
, "response info ");
4188 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4189 strcat(desc_scsi_state
, "state terminated ");
4190 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4191 strcat(desc_scsi_state
, "no status ");
4192 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4193 strcat(desc_scsi_state
, "autosense failed ");
4194 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4195 strcat(desc_scsi_state
, "autosense valid ");
4197 scsi_print_command(scmd
);
4199 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4200 printk(MPT2SAS_WARN_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4201 device_str
, (unsigned long long)priv_target
->sas_address
);
4203 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4204 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4205 priv_target
->sas_address
);
4207 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
4208 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
4210 printk(MPT2SAS_WARN_FMT
4211 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4212 ioc
->name
, sas_device
->enclosure_logical_id
,
4215 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4218 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4219 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4220 desc_ioc_state
, ioc_status
, smid
);
4221 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
4222 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4223 scsi_get_resid(scmd
));
4224 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
4225 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4226 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4227 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
4228 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
4229 scsi_status
, desc_scsi_state
, scsi_state
);
4231 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4232 struct sense_info data
;
4233 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4234 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
4235 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
4236 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4239 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4240 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4241 response_bytes
= (u8
*)&response_info
;
4242 _scsih_response_code(ioc
, response_bytes
[0]);
4248 * _scsih_turn_on_pfa_led - illuminate PFA LED
4249 * @ioc: per adapter object
4250 * @handle: device handle
4256 _scsih_turn_on_pfa_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4258 Mpi2SepReply_t mpi_reply
;
4259 Mpi2SepRequest_t mpi_request
;
4260 struct _sas_device
*sas_device
;
4262 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4266 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4267 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4268 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4269 mpi_request
.SlotStatus
=
4270 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4271 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4272 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4273 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4274 &mpi_request
)) != 0) {
4275 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4276 __FILE__
, __LINE__
, __func__
);
4279 sas_device
->pfa_led_on
= 1;
4282 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4283 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
4284 "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
4285 ioc
->name
, le16_to_cpu(mpi_reply
.IOCStatus
),
4286 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4292 * _scsih_turn_off_pfa_led - turn off PFA LED
4293 * @ioc: per adapter object
4294 * @sas_device: sas device whose PFA LED has to turned off
4300 _scsih_turn_off_pfa_led(struct MPT2SAS_ADAPTER
*ioc
,
4301 struct _sas_device
*sas_device
)
4303 Mpi2SepReply_t mpi_reply
;
4304 Mpi2SepRequest_t mpi_request
;
4306 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4307 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4308 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4309 mpi_request
.SlotStatus
= 0;
4310 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
4311 mpi_request
.DevHandle
= 0;
4312 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
4313 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
4314 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4315 &mpi_request
)) != 0) {
4316 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4317 __FILE__
, __LINE__
, __func__
);
4321 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4322 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
4323 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4324 le16_to_cpu(mpi_reply
.IOCStatus
),
4325 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4331 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
4332 * @ioc: per adapter object
4333 * @handle: device handle
4334 * Context: interrupt.
4339 _scsih_send_event_to_turn_on_pfa_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4341 struct fw_event_work
*fw_event
;
4343 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4346 fw_event
->event
= MPT2SAS_TURN_ON_PFA_LED
;
4347 fw_event
->device_handle
= handle
;
4348 fw_event
->ioc
= ioc
;
4349 _scsih_fw_event_add(ioc
, fw_event
);
4353 * _scsih_smart_predicted_fault - process smart errors
4354 * @ioc: per adapter object
4355 * @handle: device handle
4356 * Context: interrupt.
4361 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4363 struct scsi_target
*starget
;
4364 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4365 Mpi2EventNotificationReply_t
*event_reply
;
4366 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4367 struct _sas_device
*sas_device
;
4369 unsigned long flags
;
4371 /* only handle non-raid devices */
4372 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4373 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4375 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4378 starget
= sas_device
->starget
;
4379 sas_target_priv_data
= starget
->hostdata
;
4381 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4382 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4383 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4386 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
4387 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4389 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4390 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
4392 /* insert into event log */
4393 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4394 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4395 event_reply
= kzalloc(sz
, GFP_ATOMIC
);
4397 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4398 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4402 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4403 event_reply
->Event
=
4404 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4405 event_reply
->MsgLength
= sz
/4;
4406 event_reply
->EventDataLength
=
4407 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4408 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4409 event_reply
->EventData
;
4410 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4411 event_data
->ASC
= 0x5D;
4412 event_data
->DevHandle
= cpu_to_le16(handle
);
4413 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4414 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
4419 * _scsih_io_done - scsi request callback
4420 * @ioc: per adapter object
4421 * @smid: system request message index
4422 * @msix_index: MSIX table index supplied by the OS
4423 * @reply: reply message frame(lower 32bit addr)
4425 * Callback handler when using _scsih_qcmd.
4427 * Return 1 meaning mf should be freed from _base_interrupt
4428 * 0 means the mf is freed from this function.
4431 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4433 Mpi2SCSIIORequest_t
*mpi_request
;
4434 Mpi2SCSIIOReply_t
*mpi_reply
;
4435 struct scsi_cmnd
*scmd
;
4441 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4442 u32 response_code
= 0;
4443 unsigned long flags
;
4445 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4446 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4450 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4452 if (mpi_reply
== NULL
) {
4453 scmd
->result
= DID_OK
<< 16;
4457 sas_device_priv_data
= scmd
->device
->hostdata
;
4458 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4459 sas_device_priv_data
->sas_target
->deleted
) {
4460 scmd
->result
= DID_NO_CONNECT
<< 16;
4463 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4465 * WARPDRIVE: If direct_io is set then it is directIO,
4466 * the failed direct I/O should be redirected to volume
4468 if (_scsih_scsi_direct_io_get(ioc
, smid
) &&
4469 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4470 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4471 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4472 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4473 _scsih_scsi_direct_io_set(ioc
, smid
, 0);
4474 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4475 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4476 mpi_request
->DevHandle
=
4477 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4478 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4479 sas_device_priv_data
->sas_target
->handle
);
4484 /* turning off TLR */
4485 scsi_state
= mpi_reply
->SCSIState
;
4486 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4488 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4489 if (!sas_device_priv_data
->tlr_snoop_check
) {
4490 sas_device_priv_data
->tlr_snoop_check
++;
4491 /* Make sure Device is not raid volume.
4492 * We do not expose raid functionality to upper layer for warpdrive.
4494 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4495 sas_is_tlr_enabled(scmd
->device
) &&
4496 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4497 sas_disable_tlr(scmd
->device
);
4498 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4502 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4503 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4504 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4505 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4508 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4509 scsi_status
= mpi_reply
->SCSIStatus
;
4511 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4512 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4513 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4514 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4515 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4518 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4519 struct sense_info data
;
4520 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
4522 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4523 le32_to_cpu(mpi_reply
->SenseCount
));
4524 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4525 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4526 /* failure prediction threshold exceeded */
4527 if (data
.asc
== 0x5D)
4528 _scsih_smart_predicted_fault(ioc
,
4529 le16_to_cpu(mpi_reply
->DevHandle
));
4532 switch (ioc_status
) {
4533 case MPI2_IOCSTATUS_BUSY
:
4534 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4535 scmd
->result
= SAM_STAT_BUSY
;
4538 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4539 scmd
->result
= DID_NO_CONNECT
<< 16;
4542 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4543 if (sas_device_priv_data
->block
) {
4544 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4547 if (log_info
== 0x32010081) {
4548 scmd
->result
= DID_RESET
<< 16;
4551 scmd
->result
= DID_SOFT_ERROR
<< 16;
4553 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4554 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4555 scmd
->result
= DID_RESET
<< 16;
4558 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4559 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4560 scmd
->result
= DID_SOFT_ERROR
<< 16;
4562 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4565 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4566 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4568 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4571 if (xfer_cnt
< scmd
->underflow
) {
4572 if (scsi_status
== SAM_STAT_BUSY
)
4573 scmd
->result
= SAM_STAT_BUSY
;
4575 scmd
->result
= DID_SOFT_ERROR
<< 16;
4576 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4577 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4578 scmd
->result
= DID_SOFT_ERROR
<< 16;
4579 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4580 scmd
->result
= DID_RESET
<< 16;
4581 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4582 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4583 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4584 scmd
->result
= (DRIVER_SENSE
<< 24) |
4585 SAM_STAT_CHECK_CONDITION
;
4586 scmd
->sense_buffer
[0] = 0x70;
4587 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4588 scmd
->sense_buffer
[12] = 0x20;
4589 scmd
->sense_buffer
[13] = 0;
4593 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4594 scsi_set_resid(scmd
, 0);
4595 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4596 case MPI2_IOCSTATUS_SUCCESS
:
4597 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4598 if (response_code
==
4599 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4600 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4601 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4602 scmd
->result
= DID_SOFT_ERROR
<< 16;
4603 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4604 scmd
->result
= DID_RESET
<< 16;
4607 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4608 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4609 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4610 _scsih_eedp_error_handling(scmd
, ioc_status
);
4612 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4613 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4614 case MPI2_IOCSTATUS_INVALID_SGL
:
4615 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4616 case MPI2_IOCSTATUS_INVALID_FIELD
:
4617 case MPI2_IOCSTATUS_INVALID_STATE
:
4618 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4619 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4621 scmd
->result
= DID_SOFT_ERROR
<< 16;
4626 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4627 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4628 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4632 scsi_dma_unmap(scmd
);
4633 scmd
->scsi_done(scmd
);
4638 * _scsih_sas_host_refresh - refreshing sas host object contents
4639 * @ioc: per adapter object
4642 * During port enable, fw will send topology events for every device. Its
4643 * possible that the handles may change from the previous setting, so this
4644 * code keeping handles updating if changed.
4649 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4654 Mpi2ConfigReply_t mpi_reply
;
4655 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4656 u16 attached_handle
;
4659 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4660 "updating handles for sas_host(0x%016llx)\n",
4661 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4663 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4664 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4665 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4666 if (!sas_iounit_pg0
) {
4667 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4668 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4672 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4673 sas_iounit_pg0
, sz
)) != 0)
4675 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4676 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4678 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4679 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4681 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4682 PhyData
[0].ControllerDevHandle
);
4683 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4684 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4686 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4687 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4688 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4689 attached_handle
, i
, link_rate
);
4692 kfree(sas_iounit_pg0
);
4696 * _scsih_sas_host_add - create sas host object
4697 * @ioc: per adapter object
4699 * Creating host side data object, stored in ioc->sas_hba
4704 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4707 Mpi2ConfigReply_t mpi_reply
;
4708 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4709 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4710 Mpi2SasPhyPage0_t phy_pg0
;
4711 Mpi2SasDevicePage0_t sas_device_pg0
;
4712 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4715 u16 device_missing_delay
;
4717 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4718 if (!ioc
->sas_hba
.num_phys
) {
4719 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4720 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4724 /* sas_iounit page 0 */
4725 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4726 sizeof(Mpi2SasIOUnit0PhyData_t
));
4727 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4728 if (!sas_iounit_pg0
) {
4729 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4730 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4733 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4734 sas_iounit_pg0
, sz
))) {
4735 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4736 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4739 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4740 MPI2_IOCSTATUS_MASK
;
4741 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4742 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4743 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4747 /* sas_iounit page 1 */
4748 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4749 sizeof(Mpi2SasIOUnit1PhyData_t
));
4750 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4751 if (!sas_iounit_pg1
) {
4752 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4753 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4756 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4757 sas_iounit_pg1
, sz
))) {
4758 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4759 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4762 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4763 MPI2_IOCSTATUS_MASK
;
4764 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4765 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4766 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4770 ioc
->io_missing_delay
=
4771 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4772 device_missing_delay
=
4773 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4774 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4775 ioc
->device_missing_delay
= (device_missing_delay
&
4776 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4778 ioc
->device_missing_delay
= device_missing_delay
&
4779 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4781 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4782 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4783 sizeof(struct _sas_phy
), GFP_KERNEL
);
4784 if (!ioc
->sas_hba
.phy
) {
4785 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4786 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4789 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4790 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4792 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4793 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4796 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4797 MPI2_IOCSTATUS_MASK
;
4798 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4799 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4800 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4805 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4806 PhyData
[0].ControllerDevHandle
);
4807 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4808 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4809 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4810 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4812 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4813 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4814 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4815 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4818 ioc
->sas_hba
.enclosure_handle
=
4819 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4820 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4821 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4822 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4823 (unsigned long long) ioc
->sas_hba
.sas_address
,
4824 ioc
->sas_hba
.num_phys
) ;
4826 if (ioc
->sas_hba
.enclosure_handle
) {
4827 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4829 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4830 ioc
->sas_hba
.enclosure_handle
))) {
4831 ioc
->sas_hba
.enclosure_logical_id
=
4832 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4837 kfree(sas_iounit_pg1
);
4838 kfree(sas_iounit_pg0
);
4842 * _scsih_expander_add - creating expander object
4843 * @ioc: per adapter object
4844 * @handle: expander handle
4846 * Creating expander object, stored in ioc->sas_expander_list.
4848 * Return 0 for success, else error.
4851 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4853 struct _sas_node
*sas_expander
;
4854 Mpi2ConfigReply_t mpi_reply
;
4855 Mpi2ExpanderPage0_t expander_pg0
;
4856 Mpi2ExpanderPage1_t expander_pg1
;
4857 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4860 u64 sas_address
, sas_address_parent
= 0;
4862 unsigned long flags
;
4863 struct _sas_port
*mpt2sas_port
= NULL
;
4869 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4872 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4873 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4874 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4875 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4879 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4880 MPI2_IOCSTATUS_MASK
;
4881 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4882 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4883 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4887 /* handle out of order topology events */
4888 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4889 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4891 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4892 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4895 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4896 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4897 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4898 sas_address_parent
);
4899 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4900 if (!sas_expander
) {
4901 rc
= _scsih_expander_add(ioc
, parent_handle
);
4907 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4908 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4909 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4911 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4916 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4918 if (!sas_expander
) {
4919 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4920 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4924 sas_expander
->handle
= handle
;
4925 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4926 sas_expander
->sas_address_parent
= sas_address_parent
;
4927 sas_expander
->sas_address
= sas_address
;
4929 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4930 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4931 handle
, parent_handle
, (unsigned long long)
4932 sas_expander
->sas_address
, sas_expander
->num_phys
);
4934 if (!sas_expander
->num_phys
)
4936 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4937 sizeof(struct _sas_phy
), GFP_KERNEL
);
4938 if (!sas_expander
->phy
) {
4939 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4940 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4945 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4946 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4947 sas_address_parent
);
4948 if (!mpt2sas_port
) {
4949 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4950 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4954 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4956 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4957 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4958 &expander_pg1
, i
, handle
))) {
4959 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4960 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4964 sas_expander
->phy
[i
].handle
= handle
;
4965 sas_expander
->phy
[i
].phy_id
= i
;
4967 if ((mpt2sas_transport_add_expander_phy(ioc
,
4968 &sas_expander
->phy
[i
], expander_pg1
,
4969 sas_expander
->parent_dev
))) {
4970 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4971 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4977 if (sas_expander
->enclosure_handle
) {
4978 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4979 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4980 sas_expander
->enclosure_handle
))) {
4981 sas_expander
->enclosure_logical_id
=
4982 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4986 _scsih_expander_node_add(ioc
, sas_expander
);
4992 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4993 sas_address_parent
);
4994 kfree(sas_expander
);
4999 * _scsih_done - scsih callback handler.
5000 * @ioc: per adapter object
5001 * @smid: system request message index
5002 * @msix_index: MSIX table index supplied by the OS
5003 * @reply: reply message frame(lower 32bit addr)
5005 * Callback handler when sending internal generated message frames.
5006 * The callback index passed is `ioc->scsih_cb_idx`
5008 * Return 1 meaning mf should be freed from _base_interrupt
5009 * 0 means the mf is freed from this function.
5012 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5014 MPI2DefaultReply_t
*mpi_reply
;
5016 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
5017 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
5019 if (ioc
->scsih_cmds
.smid
!= smid
)
5021 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
5023 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5024 mpi_reply
->MsgLength
*4);
5025 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
5027 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
5028 complete(&ioc
->scsih_cmds
.done
);
5033 * mpt2sas_expander_remove - removing expander object
5034 * @ioc: per adapter object
5035 * @sas_address: expander sas_address
5040 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5042 struct _sas_node
*sas_expander
;
5043 unsigned long flags
;
5045 if (ioc
->shost_recovery
)
5048 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5049 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5052 list_del(&sas_expander
->list
);
5053 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5055 _scsih_expander_node_remove(ioc
, sas_expander
);
5059 * _scsih_check_access_status - check access flags
5060 * @ioc: per adapter object
5061 * @sas_address: sas address
5062 * @handle: sas device handle
5063 * @access_flags: errors returned during discovery of the device
5065 * Return 0 for success, else failure
5068 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5069 u16 handle
, u8 access_status
)
5074 switch (access_status
) {
5075 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5076 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5079 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5080 desc
= "sata capability failed";
5082 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5083 desc
= "sata affiliation conflict";
5085 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5086 desc
= "route not addressable";
5088 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5089 desc
= "smp error not addressable";
5091 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5092 desc
= "device blocked";
5094 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5096 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5097 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5098 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5099 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5100 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5101 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5102 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5103 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5104 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5105 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5106 desc
= "sata initialization failed";
5116 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
5117 "handle(0x%04x)\n", ioc
->name
, desc
,
5118 (unsigned long long)sas_address
, handle
);
5123 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5125 Mpi2ConfigReply_t mpi_reply
;
5126 Mpi2SasDevicePage0_t sas_device_pg0
;
5127 struct _sas_device
*sas_device
;
5129 unsigned long flags
;
5131 struct scsi_target
*starget
;
5132 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5136 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5137 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5140 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5141 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5144 /* check if this is end device */
5145 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5146 if (!(_scsih_is_end_device(device_info
)))
5149 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5150 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5151 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5155 printk(MPT2SAS_ERR_FMT
"device is not present "
5156 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
5157 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5161 if (unlikely(sas_device
->handle
!= handle
)) {
5162 starget
= sas_device
->starget
;
5163 sas_target_priv_data
= starget
->hostdata
;
5164 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
5165 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
5166 sas_target_priv_data
->handle
= handle
;
5167 sas_device
->handle
= handle
;
5170 /* check if device is present */
5171 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5172 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5173 printk(MPT2SAS_ERR_FMT
"device is not present "
5174 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
5175 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5179 /* check if there were any issues with discovery */
5180 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5181 sas_device_pg0
.AccessStatus
)) {
5182 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5185 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5186 _scsih_ublock_io_device(ioc
, sas_address
);
5191 * _scsih_add_device - creating sas device object
5192 * @ioc: per adapter object
5193 * @handle: sas device handle
5194 * @phy_num: phy number end device attached to
5195 * @is_pd: is this hidden raid component
5197 * Creating end device object, stored in ioc->sas_device_list.
5199 * Returns 0 for success, non-zero for failure.
5202 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
5204 Mpi2ConfigReply_t mpi_reply
;
5205 Mpi2SasDevicePage0_t sas_device_pg0
;
5206 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5207 struct _sas_device
*sas_device
;
5211 unsigned long flags
;
5213 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5214 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5215 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5216 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5220 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5221 MPI2_IOCSTATUS_MASK
;
5222 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5223 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5224 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5228 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5230 /* check if device is present */
5231 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5232 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5233 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5234 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5235 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
5236 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
5240 /* check if there were any issues with discovery */
5241 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5242 sas_device_pg0
.AccessStatus
))
5245 /* check if this is end device */
5246 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5247 if (!(_scsih_is_end_device(device_info
))) {
5248 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5249 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5254 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5255 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5257 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5262 sas_device
= kzalloc(sizeof(struct _sas_device
),
5265 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5266 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5270 sas_device
->handle
= handle
;
5271 if (_scsih_get_sas_address(ioc
, le16_to_cpu
5272 (sas_device_pg0
.ParentDevHandle
),
5273 &sas_device
->sas_address_parent
) != 0)
5274 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5275 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5276 sas_device
->enclosure_handle
=
5277 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5279 le16_to_cpu(sas_device_pg0
.Slot
);
5280 sas_device
->device_info
= device_info
;
5281 sas_device
->sas_address
= sas_address
;
5282 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5284 /* get enclosure_logical_id */
5285 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
5286 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5287 sas_device
->enclosure_handle
)))
5288 sas_device
->enclosure_logical_id
=
5289 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5291 /* get device name */
5292 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5294 if (ioc
->wait_for_discovery_to_complete
)
5295 _scsih_sas_device_init_add(ioc
, sas_device
);
5297 _scsih_sas_device_add(ioc
, sas_device
);
5303 * _scsih_remove_device - removing sas device object
5304 * @ioc: per adapter object
5305 * @sas_device_delete: the sas_device object
5310 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
5311 struct _sas_device
*sas_device
)
5313 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5315 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
5316 (sas_device
->pfa_led_on
)) {
5317 _scsih_turn_off_pfa_led(ioc
, sas_device
);
5318 sas_device
->pfa_led_on
= 0;
5321 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
5322 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5323 sas_device
->handle
, (unsigned long long)
5324 sas_device
->sas_address
));
5326 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
5327 sas_target_priv_data
= sas_device
->starget
->hostdata
;
5328 sas_target_priv_data
->deleted
= 1;
5329 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
5330 sas_target_priv_data
->handle
=
5331 MPT2SAS_INVALID_DEVICE_HANDLE
;
5334 if (!ioc
->hide_drives
)
5335 mpt2sas_transport_port_remove(ioc
,
5336 sas_device
->sas_address
,
5337 sas_device
->sas_address_parent
);
5339 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
5340 "(0x%016llx)\n", ioc
->name
, sas_device
->handle
,
5341 (unsigned long long) sas_device
->sas_address
);
5343 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
5344 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5345 sas_device
->handle
, (unsigned long long)
5346 sas_device
->sas_address
));
5350 * _scsih_device_remove_by_handle - removing device object by handle
5351 * @ioc: per adapter object
5352 * @handle: device handle
5357 _scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5359 struct _sas_device
*sas_device
;
5360 unsigned long flags
;
5362 if (ioc
->shost_recovery
)
5365 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5366 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5368 list_del(&sas_device
->list
);
5369 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5371 _scsih_remove_device(ioc
, sas_device
);
5375 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
5376 * @ioc: per adapter object
5377 * @sas_address: device sas_address
5382 mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
5385 struct _sas_device
*sas_device
;
5386 unsigned long flags
;
5388 if (ioc
->shost_recovery
)
5391 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5392 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5395 list_del(&sas_device
->list
);
5396 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5398 _scsih_remove_device(ioc
, sas_device
);
5400 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5402 * _scsih_sas_topology_change_event_debug - debug for topology event
5403 * @ioc: per adapter object
5404 * @event_data: event data payload
5408 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5409 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5415 char *status_str
= NULL
;
5416 u8 link_rate
, prev_link_rate
;
5418 switch (event_data
->ExpStatus
) {
5419 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5422 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5423 status_str
= "remove";
5425 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5427 status_str
= "responding";
5429 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5430 status_str
= "remove delay";
5433 status_str
= "unknown status";
5436 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
5437 ioc
->name
, status_str
);
5438 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
5439 "start_phy(%02d), count(%d)\n",
5440 le16_to_cpu(event_data
->ExpanderDevHandle
),
5441 le16_to_cpu(event_data
->EnclosureHandle
),
5442 event_data
->StartPhyNum
, event_data
->NumEntries
);
5443 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5444 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5447 phy_number
= event_data
->StartPhyNum
+ i
;
5448 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5449 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5450 switch (reason_code
) {
5451 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5452 status_str
= "target add";
5454 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5455 status_str
= "target remove";
5457 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5458 status_str
= "delay target remove";
5460 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5461 status_str
= "link rate change";
5463 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5464 status_str
= "target responding";
5467 status_str
= "unknown";
5470 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5471 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5472 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
5473 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5474 handle
, status_str
, link_rate
, prev_link_rate
);
5481 * _scsih_sas_topology_change_event - handle topology changes
5482 * @ioc: per adapter object
5483 * @fw_event: The fw_event_work object
5488 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5489 struct fw_event_work
*fw_event
)
5492 u16 parent_handle
, handle
;
5494 u8 phy_number
, max_phys
;
5495 struct _sas_node
*sas_expander
;
5497 unsigned long flags
;
5498 u8 link_rate
, prev_link_rate
;
5499 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
5500 (Mpi2EventDataSasTopologyChangeList_t
*)
5501 fw_event
->event_data
;
5503 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5504 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5505 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5508 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5511 if (!ioc
->sas_hba
.num_phys
)
5512 _scsih_sas_host_add(ioc
);
5514 _scsih_sas_host_refresh(ioc
);
5516 if (fw_event
->ignore
) {
5517 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
5518 "event\n", ioc
->name
));
5522 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5524 /* handle expander add */
5525 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5526 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5529 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5530 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
5533 sas_address
= sas_expander
->sas_address
;
5534 max_phys
= sas_expander
->num_phys
;
5535 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5536 sas_address
= ioc
->sas_hba
.sas_address
;
5537 max_phys
= ioc
->sas_hba
.num_phys
;
5539 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5542 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5544 /* handle siblings events */
5545 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5546 if (fw_event
->ignore
) {
5547 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
5548 "expander event\n", ioc
->name
));
5551 if (ioc
->shost_recovery
|| ioc
->remove_host
||
5552 ioc
->pci_error_recovery
)
5554 phy_number
= event_data
->StartPhyNum
+ i
;
5555 if (phy_number
>= max_phys
)
5557 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5558 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5559 if ((event_data
->PHY
[i
].PhyStatus
&
5560 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5561 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5563 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5566 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5567 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5568 switch (reason_code
) {
5569 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5571 if (ioc
->shost_recovery
)
5574 if (link_rate
== prev_link_rate
)
5577 mpt2sas_transport_update_links(ioc
, sas_address
,
5578 handle
, phy_number
, link_rate
);
5580 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5583 _scsih_check_device(ioc
, handle
);
5585 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5587 if (ioc
->shost_recovery
)
5590 mpt2sas_transport_update_links(ioc
, sas_address
,
5591 handle
, phy_number
, link_rate
);
5593 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5595 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5597 _scsih_device_remove_by_handle(ioc
, handle
);
5602 /* handle expander removal */
5603 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5605 mpt2sas_expander_remove(ioc
, sas_address
);
5609 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5611 * _scsih_sas_device_status_change_event_debug - debug for device event
5612 * @event_data: event data payload
5618 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5619 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5621 char *reason_str
= NULL
;
5623 switch (event_data
->ReasonCode
) {
5624 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5625 reason_str
= "smart data";
5627 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5628 reason_str
= "unsupported device discovered";
5630 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5631 reason_str
= "internal device reset";
5633 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5634 reason_str
= "internal task abort";
5636 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5637 reason_str
= "internal task abort set";
5639 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5640 reason_str
= "internal clear task set";
5642 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5643 reason_str
= "internal query task";
5645 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5646 reason_str
= "sata init failure";
5648 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5649 reason_str
= "internal device reset complete";
5651 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5652 reason_str
= "internal task abort complete";
5654 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5655 reason_str
= "internal async notification";
5657 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5658 reason_str
= "expander reduced functionality";
5660 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5661 reason_str
= "expander reduced functionality complete";
5664 reason_str
= "unknown reason";
5667 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5668 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5669 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5670 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5671 le16_to_cpu(event_data
->TaskTag
));
5672 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5673 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5674 event_data
->ASC
, event_data
->ASCQ
);
5675 printk(KERN_INFO
"\n");
5680 * _scsih_sas_device_status_change_event - handle device status change
5681 * @ioc: per adapter object
5682 * @fw_event: The fw_event_work object
5688 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5689 struct fw_event_work
*fw_event
)
5691 struct MPT2SAS_TARGET
*target_priv_data
;
5692 struct _sas_device
*sas_device
;
5694 unsigned long flags
;
5695 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5696 (Mpi2EventDataSasDeviceStatusChange_t
*)
5697 fw_event
->event_data
;
5699 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5700 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5701 _scsih_sas_device_status_change_event_debug(ioc
,
5705 /* In MPI Revision K (0xC), the internal device reset complete was
5706 * implemented, so avoid setting tm_busy flag for older firmware.
5708 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5711 if (event_data
->ReasonCode
!=
5712 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5713 event_data
->ReasonCode
!=
5714 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5717 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5718 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5719 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5722 if (!sas_device
|| !sas_device
->starget
) {
5723 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5727 target_priv_data
= sas_device
->starget
->hostdata
;
5728 if (!target_priv_data
) {
5729 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5733 if (event_data
->ReasonCode
==
5734 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5735 target_priv_data
->tm_busy
= 1;
5737 target_priv_data
->tm_busy
= 0;
5738 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5741 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5743 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5744 * @ioc: per adapter object
5745 * @event_data: event data payload
5751 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5752 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5754 char *reason_str
= NULL
;
5756 switch (event_data
->ReasonCode
) {
5757 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5758 reason_str
= "enclosure add";
5760 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5761 reason_str
= "enclosure remove";
5764 reason_str
= "unknown reason";
5768 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5769 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5770 " number slots(%d)\n", ioc
->name
, reason_str
,
5771 le16_to_cpu(event_data
->EnclosureHandle
),
5772 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5773 le16_to_cpu(event_data
->StartSlot
));
5778 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5779 * @ioc: per adapter object
5780 * @fw_event: The fw_event_work object
5786 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5787 struct fw_event_work
*fw_event
)
5789 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5790 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5791 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5792 (Mpi2EventDataSasEnclDevStatusChange_t
*)
5793 fw_event
->event_data
);
5798 * _scsih_sas_broadcast_primitive_event - handle broadcast events
5799 * @ioc: per adapter object
5800 * @fw_event: The fw_event_work object
5806 _scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER
*ioc
,
5807 struct fw_event_work
*fw_event
)
5809 struct scsi_cmnd
*scmd
;
5810 struct scsi_device
*sdev
;
5813 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5814 u32 termination_count
;
5816 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5817 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
5818 (Mpi2EventDataSasBroadcastPrimitive_t
*)
5819 fw_event
->event_data
;
5821 unsigned long flags
;
5824 u8 task_abort_retries
;
5826 mutex_lock(&ioc
->tm_cmds
.mutex
);
5828 "%s: enter: phy number(%d), width(%d)\n",
5829 ioc
->name
, __func__
, event_data
->PhyNum
,
5830 event_data
->PortWidth
);
5832 _scsih_block_io_all_device(ioc
);
5834 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5835 mpi_reply
= ioc
->tm_cmds
.reply
;
5836 broadcast_aen_retry
:
5838 /* sanity checks for retrying this loop */
5839 if (max_retries
++ == 5) {
5840 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: giving up\n",
5841 ioc
->name
, __func__
));
5843 } else if (max_retries
> 1)
5844 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %d retry\n",
5845 ioc
->name
, __func__
, max_retries
- 1));
5847 termination_count
= 0;
5849 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5850 if (ioc
->shost_recovery
)
5852 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5855 sdev
= scmd
->device
;
5856 sas_device_priv_data
= sdev
->hostdata
;
5857 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5859 /* skip hidden raid components */
5860 if (sas_device_priv_data
->sas_target
->flags
&
5861 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5864 if (sas_device_priv_data
->sas_target
->flags
&
5865 MPT_TARGET_FLAGS_VOLUME
)
5868 handle
= sas_device_priv_data
->sas_target
->handle
;
5869 lun
= sas_device_priv_data
->lun
;
5872 if (ioc
->shost_recovery
)
5875 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5876 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5877 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30,
5880 sdev_printk(KERN_WARNING
, sdev
,
5881 "mpt2sas_scsih_issue_tm: FAILED when sending "
5882 "QUERY_TASK: scmd(%p)\n", scmd
);
5883 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5884 goto broadcast_aen_retry
;
5886 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5887 & MPI2_IOCSTATUS_MASK
;
5888 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5889 sdev_printk(KERN_WARNING
, sdev
, "query task: FAILED "
5890 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status
,
5892 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5893 goto broadcast_aen_retry
;
5896 /* see if IO is still owned by IOC and target */
5897 if (mpi_reply
->ResponseCode
==
5898 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5899 mpi_reply
->ResponseCode
==
5900 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5901 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5904 task_abort_retries
= 0;
5906 if (task_abort_retries
++ == 60) {
5907 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5908 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5910 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5911 goto broadcast_aen_retry
;
5914 if (ioc
->shost_recovery
)
5917 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5918 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5921 sdev_printk(KERN_WARNING
, sdev
,
5922 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5923 "scmd(%p)\n", scmd
);
5927 if (task_abort_retries
> 1)
5928 sdev_printk(KERN_WARNING
, sdev
,
5929 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5931 task_abort_retries
- 1, scmd
);
5933 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5934 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5937 if (ioc
->broadcast_aen_pending
) {
5938 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: loop back due to"
5939 " pending AEN\n", ioc
->name
, __func__
));
5940 ioc
->broadcast_aen_pending
= 0;
5941 goto broadcast_aen_retry
;
5945 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5948 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5949 "%s - exit, query_count = %d termination_count = %d\n",
5950 ioc
->name
, __func__
, query_count
, termination_count
));
5952 ioc
->broadcast_aen_busy
= 0;
5953 if (!ioc
->shost_recovery
)
5954 _scsih_ublock_io_all_device(ioc
);
5955 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5959 * _scsih_sas_discovery_event - handle discovery events
5960 * @ioc: per adapter object
5961 * @fw_event: The fw_event_work object
5967 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5968 struct fw_event_work
*fw_event
)
5970 Mpi2EventDataSasDiscovery_t
*event_data
=
5971 (Mpi2EventDataSasDiscovery_t
*)
5972 fw_event
->event_data
;
5974 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5975 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5976 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5977 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5979 if (event_data
->DiscoveryStatus
)
5980 printk("discovery_status(0x%08x)",
5981 le32_to_cpu(event_data
->DiscoveryStatus
));
5986 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5987 !ioc
->sas_hba
.num_phys
) {
5988 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
5989 /* Wait for the reset to complete */
5990 while (ioc
->shost_recovery
)
5993 _scsih_sas_host_add(ioc
);
5998 * _scsih_reprobe_lun - reprobing lun
5999 * @sdev: scsi device struct
6000 * @no_uld_attach: sdev->no_uld_attach flag setting
6004 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
6008 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
6009 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
6010 sdev
->no_uld_attach
? "hidding" : "exposing");
6011 rc
= scsi_device_reprobe(sdev
);
6015 * _scsih_sas_volume_add - add new volume
6016 * @ioc: per adapter object
6017 * @element: IR config element data
6023 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
6024 Mpi2EventIrConfigElement_t
*element
)
6026 struct _raid_device
*raid_device
;
6027 unsigned long flags
;
6029 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
6032 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6034 printk(MPT2SAS_ERR_FMT
6035 "failure at %s:%d/%s()!\n", ioc
->name
,
6036 __FILE__
, __LINE__
, __func__
);
6040 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6041 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6042 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6047 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6049 printk(MPT2SAS_ERR_FMT
6050 "failure at %s:%d/%s()!\n", ioc
->name
,
6051 __FILE__
, __LINE__
, __func__
);
6055 raid_device
->id
= ioc
->sas_id
++;
6056 raid_device
->channel
= RAID_CHANNEL
;
6057 raid_device
->handle
= handle
;
6058 raid_device
->wwid
= wwid
;
6059 _scsih_raid_device_add(ioc
, raid_device
);
6060 if (!ioc
->wait_for_discovery_to_complete
) {
6061 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6062 raid_device
->id
, 0);
6064 _scsih_raid_device_remove(ioc
, raid_device
);
6066 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6067 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6068 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6073 * _scsih_sas_volume_delete - delete volume
6074 * @ioc: per adapter object
6075 * @handle: volume device handle
6081 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
6083 struct _raid_device
*raid_device
;
6084 unsigned long flags
;
6085 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6086 struct scsi_target
*starget
= NULL
;
6088 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6089 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6091 if (raid_device
->starget
) {
6092 starget
= raid_device
->starget
;
6093 sas_target_priv_data
= starget
->hostdata
;
6094 sas_target_priv_data
->deleted
= 1;
6096 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6097 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6098 (unsigned long long) raid_device
->wwid
);
6099 list_del(&raid_device
->list
);
6102 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6104 scsi_remove_target(&starget
->dev
);
6108 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6109 * @ioc: per adapter object
6110 * @element: IR config element data
6116 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
6117 Mpi2EventIrConfigElement_t
*element
)
6119 struct _sas_device
*sas_device
;
6120 struct scsi_target
*starget
= NULL
;
6121 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6122 unsigned long flags
;
6123 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6125 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6126 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6128 sas_device
->volume_handle
= 0;
6129 sas_device
->volume_wwid
= 0;
6130 clear_bit(handle
, ioc
->pd_handles
);
6131 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6132 starget
= sas_device
->starget
;
6133 sas_target_priv_data
= starget
->hostdata
;
6134 sas_target_priv_data
->flags
&=
6135 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
6138 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6142 /* exposing raid component */
6144 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
6148 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6149 * @ioc: per adapter object
6150 * @element: IR config element data
6156 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
6157 Mpi2EventIrConfigElement_t
*element
)
6159 struct _sas_device
*sas_device
;
6160 struct scsi_target
*starget
= NULL
;
6161 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6162 unsigned long flags
;
6163 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6164 u16 volume_handle
= 0;
6165 u64 volume_wwid
= 0;
6167 mpt2sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
6169 mpt2sas_config_get_volume_wwid(ioc
, volume_handle
,
6172 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6173 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6175 set_bit(handle
, ioc
->pd_handles
);
6176 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6177 starget
= sas_device
->starget
;
6178 sas_target_priv_data
= starget
->hostdata
;
6179 sas_target_priv_data
->flags
|=
6180 MPT_TARGET_FLAGS_RAID_COMPONENT
;
6181 sas_device
->volume_handle
= volume_handle
;
6182 sas_device
->volume_wwid
= volume_wwid
;
6185 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6189 /* hiding raid component */
6191 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
6195 * _scsih_sas_pd_delete - delete pd component
6196 * @ioc: per adapter object
6197 * @element: IR config element data
6203 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
6204 Mpi2EventIrConfigElement_t
*element
)
6206 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6208 _scsih_device_remove_by_handle(ioc
, handle
);
6212 * _scsih_sas_pd_add - remove pd component
6213 * @ioc: per adapter object
6214 * @element: IR config element data
6220 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
6221 Mpi2EventIrConfigElement_t
*element
)
6223 struct _sas_device
*sas_device
;
6224 unsigned long flags
;
6225 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6226 Mpi2ConfigReply_t mpi_reply
;
6227 Mpi2SasDevicePage0_t sas_device_pg0
;
6232 set_bit(handle
, ioc
->pd_handles
);
6234 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6235 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6236 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6240 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6241 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6242 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6243 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6247 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6248 MPI2_IOCSTATUS_MASK
;
6249 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6250 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6251 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6255 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6256 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6257 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6258 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6260 _scsih_add_device(ioc
, handle
, 0, 1);
6263 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6265 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6266 * @ioc: per adapter object
6267 * @event_data: event data payload
6273 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6274 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6276 Mpi2EventIrConfigElement_t
*element
;
6279 char *reason_str
= NULL
, *element_str
= NULL
;
6281 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6283 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
6284 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6285 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6286 "foreign" : "native", event_data
->NumElements
);
6287 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6288 switch (element
->ReasonCode
) {
6289 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6292 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6293 reason_str
= "remove";
6295 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6296 reason_str
= "no change";
6298 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6299 reason_str
= "hide";
6301 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6302 reason_str
= "unhide";
6304 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6305 reason_str
= "volume_created";
6307 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6308 reason_str
= "volume_deleted";
6310 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6311 reason_str
= "pd_created";
6313 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6314 reason_str
= "pd_deleted";
6317 reason_str
= "unknown reason";
6320 element_type
= le16_to_cpu(element
->ElementFlags
) &
6321 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6322 switch (element_type
) {
6323 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6324 element_str
= "volume";
6326 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6327 element_str
= "phys disk";
6329 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6330 element_str
= "hot spare";
6333 element_str
= "unknown element";
6336 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
6337 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6338 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6339 le16_to_cpu(element
->PhysDiskDevHandle
),
6340 element
->PhysDiskNum
);
6346 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6347 * @ioc: per adapter object
6348 * @fw_event: The fw_event_work object
6354 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
6355 struct fw_event_work
*fw_event
)
6357 Mpi2EventIrConfigElement_t
*element
;
6360 Mpi2EventDataIrConfigChangeList_t
*event_data
=
6361 (Mpi2EventDataIrConfigChangeList_t
*)
6362 fw_event
->event_data
;
6364 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6365 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6366 && !ioc
->hide_ir_msg
)
6367 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6371 if (ioc
->shost_recovery
)
6374 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6375 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6377 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6378 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6380 switch (element
->ReasonCode
) {
6381 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6382 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6383 if (!foreign_config
)
6384 _scsih_sas_volume_add(ioc
, element
);
6386 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6387 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6388 if (!foreign_config
)
6389 _scsih_sas_volume_delete(ioc
,
6390 le16_to_cpu(element
->VolDevHandle
));
6392 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6393 if (!ioc
->is_warpdrive
)
6394 _scsih_sas_pd_hide(ioc
, element
);
6396 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6397 if (!ioc
->is_warpdrive
)
6398 _scsih_sas_pd_expose(ioc
, element
);
6400 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6401 if (!ioc
->is_warpdrive
)
6402 _scsih_sas_pd_add(ioc
, element
);
6404 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6405 if (!ioc
->is_warpdrive
)
6406 _scsih_sas_pd_delete(ioc
, element
);
6413 * _scsih_sas_ir_volume_event - IR volume event
6414 * @ioc: per adapter object
6415 * @fw_event: The fw_event_work object
6421 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
6422 struct fw_event_work
*fw_event
)
6425 unsigned long flags
;
6426 struct _raid_device
*raid_device
;
6430 Mpi2EventDataIrVolume_t
*event_data
=
6431 (Mpi2EventDataIrVolume_t
*)
6432 fw_event
->event_data
;
6434 if (ioc
->shost_recovery
)
6437 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6440 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6441 state
= le32_to_cpu(event_data
->NewValue
);
6442 if (!ioc
->hide_ir_msg
)
6443 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6444 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6445 le32_to_cpu(event_data
->PreviousValue
), state
));
6448 case MPI2_RAID_VOL_STATE_MISSING
:
6449 case MPI2_RAID_VOL_STATE_FAILED
:
6450 _scsih_sas_volume_delete(ioc
, handle
);
6453 case MPI2_RAID_VOL_STATE_ONLINE
:
6454 case MPI2_RAID_VOL_STATE_DEGRADED
:
6455 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6457 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6458 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6459 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6464 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6466 printk(MPT2SAS_ERR_FMT
6467 "failure at %s:%d/%s()!\n", ioc
->name
,
6468 __FILE__
, __LINE__
, __func__
);
6472 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6474 printk(MPT2SAS_ERR_FMT
6475 "failure at %s:%d/%s()!\n", ioc
->name
,
6476 __FILE__
, __LINE__
, __func__
);
6480 raid_device
->id
= ioc
->sas_id
++;
6481 raid_device
->channel
= RAID_CHANNEL
;
6482 raid_device
->handle
= handle
;
6483 raid_device
->wwid
= wwid
;
6484 _scsih_raid_device_add(ioc
, raid_device
);
6485 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6486 raid_device
->id
, 0);
6488 _scsih_raid_device_remove(ioc
, raid_device
);
6491 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6498 * _scsih_sas_ir_physical_disk_event - PD event
6499 * @ioc: per adapter object
6500 * @fw_event: The fw_event_work object
6506 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
6507 struct fw_event_work
*fw_event
)
6509 u16 handle
, parent_handle
;
6511 struct _sas_device
*sas_device
;
6512 unsigned long flags
;
6513 Mpi2ConfigReply_t mpi_reply
;
6514 Mpi2SasDevicePage0_t sas_device_pg0
;
6516 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
6517 (Mpi2EventDataIrPhysicalDisk_t
*)
6518 fw_event
->event_data
;
6521 if (ioc
->shost_recovery
)
6524 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6527 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6528 state
= le32_to_cpu(event_data
->NewValue
);
6530 if (!ioc
->hide_ir_msg
)
6531 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6532 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6533 le32_to_cpu(event_data
->PreviousValue
), state
));
6536 case MPI2_RAID_PD_STATE_ONLINE
:
6537 case MPI2_RAID_PD_STATE_DEGRADED
:
6538 case MPI2_RAID_PD_STATE_REBUILDING
:
6539 case MPI2_RAID_PD_STATE_OPTIMAL
:
6540 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6542 if (!ioc
->is_warpdrive
)
6543 set_bit(handle
, ioc
->pd_handles
);
6545 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6546 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6547 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6552 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6553 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6555 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6556 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6560 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6561 MPI2_IOCSTATUS_MASK
;
6562 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6563 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6564 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6568 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6569 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6570 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6571 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6573 _scsih_add_device(ioc
, handle
, 0, 1);
6577 case MPI2_RAID_PD_STATE_OFFLINE
:
6578 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6579 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6585 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6587 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6588 * @ioc: per adapter object
6589 * @event_data: event data payload
6595 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6596 Mpi2EventDataIrOperationStatus_t
*event_data
)
6598 char *reason_str
= NULL
;
6600 switch (event_data
->RAIDOperation
) {
6601 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6602 reason_str
= "resync";
6604 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6605 reason_str
= "online capacity expansion";
6607 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6608 reason_str
= "consistency check";
6610 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6611 reason_str
= "background init";
6613 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6614 reason_str
= "make data consistent";
6621 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
6622 "\thandle(0x%04x), percent complete(%d)\n",
6623 ioc
->name
, reason_str
,
6624 le16_to_cpu(event_data
->VolDevHandle
),
6625 event_data
->PercentComplete
);
6630 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6631 * @ioc: per adapter object
6632 * @fw_event: The fw_event_work object
6638 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
6639 struct fw_event_work
*fw_event
)
6641 Mpi2EventDataIrOperationStatus_t
*event_data
=
6642 (Mpi2EventDataIrOperationStatus_t
*)
6643 fw_event
->event_data
;
6644 static struct _raid_device
*raid_device
;
6645 unsigned long flags
;
6648 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6649 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6650 && !ioc
->hide_ir_msg
)
6651 _scsih_sas_ir_operation_status_event_debug(ioc
,
6655 /* code added for raid transport support */
6656 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6658 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6659 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6660 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6662 raid_device
->percent_complete
=
6663 event_data
->PercentComplete
;
6664 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6669 * _scsih_prep_device_scan - initialize parameters prior to device scan
6670 * @ioc: per adapter object
6672 * Set the deleted flag prior to device scan. If the device is found during
6673 * the scan, then we clear the deleted flag.
6676 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
6678 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
6679 struct scsi_device
*sdev
;
6681 shost_for_each_device(sdev
, ioc
->shost
) {
6682 sas_device_priv_data
= sdev
->hostdata
;
6683 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6684 sas_device_priv_data
->sas_target
->deleted
= 1;
6689 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6690 * @ioc: per adapter object
6691 * @sas_address: sas address
6692 * @slot: enclosure slot id
6693 * @handle: device handle
6695 * After host reset, find out whether devices are still responding.
6696 * Used in _scsi_remove_unresponsive_sas_devices.
6701 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6702 u16 slot
, u16 handle
)
6704 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
6705 struct scsi_target
*starget
;
6706 struct _sas_device
*sas_device
;
6707 unsigned long flags
;
6709 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6710 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6711 if (sas_device
->sas_address
== sas_address
&&
6712 sas_device
->slot
== slot
) {
6713 sas_device
->responding
= 1;
6714 starget
= sas_device
->starget
;
6715 if (starget
&& starget
->hostdata
) {
6716 sas_target_priv_data
= starget
->hostdata
;
6717 sas_target_priv_data
->tm_busy
= 0;
6718 sas_target_priv_data
->deleted
= 0;
6720 sas_target_priv_data
= NULL
;
6722 starget_printk(KERN_INFO
, starget
,
6723 "handle(0x%04x), sas_addr(0x%016llx), "
6724 "enclosure logical id(0x%016llx), "
6725 "slot(%d)\n", handle
,
6726 (unsigned long long)sas_device
->sas_address
,
6727 (unsigned long long)
6728 sas_device
->enclosure_logical_id
,
6730 if (sas_device
->handle
== handle
)
6732 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6733 sas_device
->handle
);
6734 sas_device
->handle
= handle
;
6735 if (sas_target_priv_data
)
6736 sas_target_priv_data
->handle
= handle
;
6741 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6745 * _scsih_search_responding_sas_devices -
6746 * @ioc: per adapter object
6748 * After host reset, find out whether devices are still responding.
6754 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6756 Mpi2SasDevicePage0_t sas_device_pg0
;
6757 Mpi2ConfigReply_t mpi_reply
;
6764 printk(MPT2SAS_INFO_FMT
"search for end-devices: start\n", ioc
->name
);
6766 if (list_empty(&ioc
->sas_device_list
))
6770 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6771 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6773 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6774 MPI2_IOCSTATUS_MASK
;
6775 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6777 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6778 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6779 if (!(_scsih_is_end_device(device_info
)))
6781 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6782 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6783 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6787 printk(MPT2SAS_INFO_FMT
"search for end-devices: complete\n",
6792 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6793 * @ioc: per adapter object
6794 * @wwid: world wide identifier for raid volume
6795 * @handle: device handle
6797 * After host reset, find out whether devices are still responding.
6798 * Used in _scsi_remove_unresponsive_raid_devices.
6803 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6806 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6807 struct scsi_target
*starget
;
6808 struct _raid_device
*raid_device
;
6809 unsigned long flags
;
6811 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6812 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6813 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6814 starget
= raid_device
->starget
;
6815 if (starget
&& starget
->hostdata
) {
6816 sas_target_priv_data
= starget
->hostdata
;
6817 sas_target_priv_data
->deleted
= 0;
6819 sas_target_priv_data
= NULL
;
6820 raid_device
->responding
= 1;
6821 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6822 starget_printk(KERN_INFO
, raid_device
->starget
,
6823 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6824 (unsigned long long)raid_device
->wwid
);
6826 * WARPDRIVE: The handles of the PDs might have changed
6827 * across the host reset so re-initialize the
6828 * required data for Direct IO
6830 _scsih_init_warpdrive_properties(ioc
, raid_device
);
6831 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6832 if (raid_device
->handle
== handle
) {
6833 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
6837 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6838 raid_device
->handle
);
6839 raid_device
->handle
= handle
;
6840 if (sas_target_priv_data
)
6841 sas_target_priv_data
->handle
= handle
;
6842 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6847 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6851 * _scsih_search_responding_raid_devices -
6852 * @ioc: per adapter object
6854 * After host reset, find out whether devices are still responding.
6860 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6862 Mpi2RaidVolPage1_t volume_pg1
;
6863 Mpi2RaidVolPage0_t volume_pg0
;
6864 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6865 Mpi2ConfigReply_t mpi_reply
;
6870 if (!ioc
->ir_firmware
)
6873 printk(MPT2SAS_INFO_FMT
"search for raid volumes: start\n",
6876 if (list_empty(&ioc
->raid_device_list
))
6880 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6881 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6882 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6883 MPI2_IOCSTATUS_MASK
;
6884 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6886 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6888 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6889 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6890 sizeof(Mpi2RaidVolPage0_t
)))
6893 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6894 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6895 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6896 _scsih_mark_responding_raid_device(ioc
,
6897 le64_to_cpu(volume_pg1
.WWID
), handle
);
6900 /* refresh the pd_handles */
6901 if (!ioc
->is_warpdrive
) {
6902 phys_disk_num
= 0xFF;
6903 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6904 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6905 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6907 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6908 MPI2_IOCSTATUS_MASK
;
6909 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6911 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6912 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6913 set_bit(handle
, ioc
->pd_handles
);
6917 printk(MPT2SAS_INFO_FMT
"search for responding raid volumes: "
6918 "complete\n", ioc
->name
);
6922 * _scsih_mark_responding_expander - mark a expander as responding
6923 * @ioc: per adapter object
6924 * @sas_address: sas address
6927 * After host reset, find out whether devices are still responding.
6928 * Used in _scsi_remove_unresponsive_expanders.
6933 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6936 struct _sas_node
*sas_expander
;
6937 unsigned long flags
;
6940 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6941 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6942 if (sas_expander
->sas_address
!= sas_address
)
6944 sas_expander
->responding
= 1;
6945 if (sas_expander
->handle
== handle
)
6947 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6948 " from(0x%04x) to (0x%04x)!!!\n",
6949 (unsigned long long)sas_expander
->sas_address
,
6950 sas_expander
->handle
, handle
);
6951 sas_expander
->handle
= handle
;
6952 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6953 sas_expander
->phy
[i
].handle
= handle
;
6957 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6961 * _scsih_search_responding_expanders -
6962 * @ioc: per adapter object
6964 * After host reset, find out whether devices are still responding.
6970 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6972 Mpi2ExpanderPage0_t expander_pg0
;
6973 Mpi2ConfigReply_t mpi_reply
;
6978 printk(MPT2SAS_INFO_FMT
"search for expanders: start\n", ioc
->name
);
6980 if (list_empty(&ioc
->sas_expander_list
))
6984 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6985 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6987 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6988 MPI2_IOCSTATUS_MASK
;
6989 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6992 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6993 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6994 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6995 "sas_addr(0x%016llx)\n", handle
,
6996 (unsigned long long)sas_address
);
6997 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
7001 printk(MPT2SAS_INFO_FMT
"search for expanders: complete\n", ioc
->name
);
7005 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
7006 * @ioc: per adapter object
7011 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
7013 struct _sas_device
*sas_device
, *sas_device_next
;
7014 struct _sas_node
*sas_expander
, *sas_expander_next
;
7015 struct _raid_device
*raid_device
, *raid_device_next
;
7016 struct list_head tmp_list
;
7017 unsigned long flags
;
7019 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: start\n",
7022 /* removing unresponding end devices */
7023 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: end-devices\n",
7025 list_for_each_entry_safe(sas_device
, sas_device_next
,
7026 &ioc
->sas_device_list
, list
) {
7027 if (!sas_device
->responding
)
7028 mpt2sas_device_remove_by_sas_address(ioc
,
7029 sas_device
->sas_address
);
7031 sas_device
->responding
= 0;
7034 /* removing unresponding volumes */
7035 if (ioc
->ir_firmware
) {
7036 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: "
7037 "volumes\n", ioc
->name
);
7038 list_for_each_entry_safe(raid_device
, raid_device_next
,
7039 &ioc
->raid_device_list
, list
) {
7040 if (!raid_device
->responding
)
7041 _scsih_sas_volume_delete(ioc
,
7042 raid_device
->handle
);
7044 raid_device
->responding
= 0;
7047 /* removing unresponding expanders */
7048 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: expanders\n",
7050 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7051 INIT_LIST_HEAD(&tmp_list
);
7052 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
7053 &ioc
->sas_expander_list
, list
) {
7054 if (!sas_expander
->responding
)
7055 list_move_tail(&sas_expander
->list
, &tmp_list
);
7057 sas_expander
->responding
= 0;
7059 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7060 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
7062 list_del(&sas_expander
->list
);
7063 _scsih_expander_node_remove(ioc
, sas_expander
);
7065 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: complete\n",
7067 /* unblock devices */
7068 _scsih_ublock_io_all_device(ioc
);
7072 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER
*ioc
,
7073 struct _sas_node
*sas_expander
, u16 handle
)
7075 Mpi2ExpanderPage1_t expander_pg1
;
7076 Mpi2ConfigReply_t mpi_reply
;
7079 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7080 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7081 &expander_pg1
, i
, handle
))) {
7082 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7083 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7087 mpt2sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7088 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7089 expander_pg1
.NegotiatedLinkRate
>> 4);
7094 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7095 * @ioc: per adapter object
7100 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER
*ioc
)
7102 Mpi2ExpanderPage0_t expander_pg0
;
7103 Mpi2SasDevicePage0_t sas_device_pg0
;
7104 Mpi2RaidVolPage1_t volume_pg1
;
7105 Mpi2RaidVolPage0_t volume_pg0
;
7106 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7107 Mpi2EventIrConfigElement_t element
;
7108 Mpi2ConfigReply_t mpi_reply
;
7111 u16 handle
, parent_handle
;
7113 struct _sas_device
*sas_device
;
7114 struct _sas_node
*expander_device
;
7115 static struct _raid_device
*raid_device
;
7117 unsigned long flags
;
7119 printk(MPT2SAS_INFO_FMT
"scan devices: start\n", ioc
->name
);
7121 _scsih_sas_host_refresh(ioc
);
7123 printk(MPT2SAS_INFO_FMT
"\tscan devices: expanders start\n",
7127 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7128 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7129 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7130 MPI2_IOCSTATUS_MASK
;
7131 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7132 printk(MPT2SAS_INFO_FMT
"\tbreak from expander scan: "
7133 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7134 ioc
->name
, ioc_status
,
7135 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7138 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7139 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
7140 expander_device
= mpt2sas_scsih_expander_find_by_sas_address(
7141 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7142 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
7143 if (expander_device
)
7144 _scsih_refresh_expander_links(ioc
, expander_device
,
7147 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding expander: "
7148 "handle (0x%04x), sas_addr(0x%016llx)\n",
7149 ioc
->name
, handle
, (unsigned long long)
7150 le64_to_cpu(expander_pg0
.SASAddress
));
7151 _scsih_expander_add(ioc
, handle
);
7152 printk(MPT2SAS_INFO_FMT
"\tAFTER adding expander: "
7153 "handle (0x%04x), sas_addr(0x%016llx)\n",
7154 ioc
->name
, handle
, (unsigned long long)
7155 le64_to_cpu(expander_pg0
.SASAddress
));
7159 printk(MPT2SAS_INFO_FMT
"\tscan devices: expanders complete\n",
7162 if (!ioc
->ir_firmware
)
7165 printk(MPT2SAS_INFO_FMT
"\tscan devices phys disk start\n", ioc
->name
);
7167 phys_disk_num
= 0xFF;
7168 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7169 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7171 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7172 MPI2_IOCSTATUS_MASK
;
7173 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7174 printk(MPT2SAS_INFO_FMT
"\tbreak from phys disk scan:"
7175 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7176 ioc
->name
, ioc_status
,
7177 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7180 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7181 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7182 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7183 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
7184 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7187 if (mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7188 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7191 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7192 MPI2_IOCSTATUS_MASK
;
7193 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7194 printk(MPT2SAS_INFO_FMT
"\tbreak from phys disk scan "
7195 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7196 ioc
->name
, ioc_status
,
7197 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7200 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7201 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7203 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding phys disk: "
7204 " handle (0x%04x), sas_addr(0x%016llx)\n",
7205 ioc
->name
, handle
, (unsigned long long)
7206 le64_to_cpu(sas_device_pg0
.SASAddress
));
7207 mpt2sas_transport_update_links(ioc
, sas_address
,
7208 handle
, sas_device_pg0
.PhyNum
,
7209 MPI2_SAS_NEG_LINK_RATE_1_5
);
7210 set_bit(handle
, ioc
->pd_handles
);
7212 /* This will retry adding the end device.
7213 * _scsih_add_device() will decide on retries and
7214 * return "1" when it should be retried
7216 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7220 printk(MPT2SAS_INFO_FMT
"\tAFTER adding phys disk: "
7221 " handle (0x%04x), sas_addr(0x%016llx)\n",
7222 ioc
->name
, handle
, (unsigned long long)
7223 le64_to_cpu(sas_device_pg0
.SASAddress
));
7227 printk(MPT2SAS_INFO_FMT
"\tscan devices: phys disk complete\n",
7230 printk(MPT2SAS_INFO_FMT
"\tscan devices: volumes start\n", ioc
->name
);
7233 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7234 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7235 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7236 MPI2_IOCSTATUS_MASK
;
7237 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7238 printk(MPT2SAS_INFO_FMT
"\tbreak from volume scan: "
7239 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7240 ioc
->name
, ioc_status
,
7241 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7244 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7245 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7246 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7247 le64_to_cpu(volume_pg1
.WWID
));
7248 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7251 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7252 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7253 sizeof(Mpi2RaidVolPage0_t
)))
7255 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7256 MPI2_IOCSTATUS_MASK
;
7257 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7258 printk(MPT2SAS_INFO_FMT
"\tbreak from volume scan: "
7259 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7260 ioc
->name
, ioc_status
,
7261 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7264 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7265 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7266 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7267 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7268 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7269 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7270 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding volume: "
7271 " handle (0x%04x)\n", ioc
->name
,
7272 volume_pg1
.DevHandle
);
7273 _scsih_sas_volume_add(ioc
, &element
);
7274 printk(MPT2SAS_INFO_FMT
"\tAFTER adding volume: "
7275 " handle (0x%04x)\n", ioc
->name
,
7276 volume_pg1
.DevHandle
);
7280 printk(MPT2SAS_INFO_FMT
"\tscan devices: volumes complete\n",
7285 printk(MPT2SAS_INFO_FMT
"\tscan devices: end devices start\n",
7289 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7290 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7292 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7293 MPI2_IOCSTATUS_MASK
;
7294 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7295 printk(MPT2SAS_INFO_FMT
"\tbreak from end device scan:"
7296 " ioc_status(0x%04x), loginfo(0x%08x)\n",
7297 ioc
->name
, ioc_status
,
7298 le32_to_cpu(mpi_reply
.IOCLogInfo
));
7301 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7302 if (!(_scsih_is_end_device(
7303 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7305 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7306 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
7307 le64_to_cpu(sas_device_pg0
.SASAddress
));
7308 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7311 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7312 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7313 printk(MPT2SAS_INFO_FMT
"\tBEFORE adding end device: "
7314 "handle (0x%04x), sas_addr(0x%016llx)\n",
7315 ioc
->name
, handle
, (unsigned long long)
7316 le64_to_cpu(sas_device_pg0
.SASAddress
));
7317 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
7318 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7320 /* This will retry adding the end device.
7321 * _scsih_add_device() will decide on retries and
7322 * return "1" when it should be retried
7324 while (_scsih_add_device(ioc
, handle
, retry_count
++,
7328 printk(MPT2SAS_INFO_FMT
"\tAFTER adding end device: "
7329 "handle (0x%04x), sas_addr(0x%016llx)\n",
7330 ioc
->name
, handle
, (unsigned long long)
7331 le64_to_cpu(sas_device_pg0
.SASAddress
));
7335 printk(MPT2SAS_INFO_FMT
"\tscan devices: end devices complete\n",
7338 printk(MPT2SAS_INFO_FMT
"scan devices: complete\n", ioc
->name
);
7343 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7344 * @ioc: per adapter object
7345 * @reset_phase: phase
7347 * The handler for doing any required cleanup or initialization.
7349 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7350 * MPT2_IOC_DONE_RESET
7355 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
7357 switch (reset_phase
) {
7358 case MPT2_IOC_PRE_RESET
:
7359 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7360 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7362 case MPT2_IOC_AFTER_RESET
:
7363 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7364 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7365 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
7366 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
7367 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7368 complete(&ioc
->scsih_cmds
.done
);
7370 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
7371 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
7372 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7373 complete(&ioc
->tm_cmds
.done
);
7375 _scsih_fw_event_cleanup_queue(ioc
);
7376 _scsih_flush_running_cmds(ioc
);
7378 case MPT2_IOC_DONE_RESET
:
7379 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7380 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7381 _scsih_sas_host_refresh(ioc
);
7382 _scsih_prep_device_scan(ioc
);
7383 _scsih_search_responding_sas_devices(ioc
);
7384 _scsih_search_responding_raid_devices(ioc
);
7385 _scsih_search_responding_expanders(ioc
);
7386 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
7387 !ioc
->sas_hba
.num_phys
)) {
7388 _scsih_prep_device_scan(ioc
);
7389 _scsih_search_responding_sas_devices(ioc
);
7390 _scsih_search_responding_raid_devices(ioc
);
7391 _scsih_search_responding_expanders(ioc
);
7392 _scsih_error_recovery_delete_devices(ioc
);
7399 * _firmware_event_work - delayed task for processing firmware events
7400 * @ioc: per adapter object
7401 * @work: equal to the fw_event_work object
7407 _firmware_event_work(struct work_struct
*work
)
7409 struct fw_event_work
*fw_event
= container_of(work
,
7410 struct fw_event_work
, delayed_work
.work
);
7411 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
7413 /* the queue is being flushed so ignore this event */
7414 if (ioc
->remove_host
||
7415 ioc
->pci_error_recovery
) {
7416 _scsih_fw_event_free(ioc
, fw_event
);
7420 switch (fw_event
->event
) {
7421 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES
:
7422 while (scsi_host_in_recovery(ioc
->shost
) || ioc
->shost_recovery
)
7424 _scsih_remove_unresponding_sas_devices(ioc
);
7425 _scsih_scan_for_devices_after_reset(ioc
);
7427 case MPT2SAS_PORT_ENABLE_COMPLETE
:
7428 ioc
->start_scan
= 0;
7430 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
7431 mpt2sas_base_update_missing_delay(ioc
, missing_delay
[0],
7434 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"port enable: complete "
7435 "from worker thread\n", ioc
->name
));
7437 case MPT2SAS_TURN_ON_PFA_LED
:
7438 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
7440 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7441 _scsih_sas_topology_change_event(ioc
, fw_event
);
7443 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7444 _scsih_sas_device_status_change_event(ioc
,
7447 case MPI2_EVENT_SAS_DISCOVERY
:
7448 _scsih_sas_discovery_event(ioc
,
7451 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7452 _scsih_sas_broadcast_primitive_event(ioc
,
7455 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7456 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7459 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7460 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7462 case MPI2_EVENT_IR_VOLUME
:
7463 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7465 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7466 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7468 case MPI2_EVENT_IR_OPERATION_STATUS
:
7469 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7472 _scsih_fw_event_free(ioc
, fw_event
);
7476 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7477 * @ioc: per adapter object
7478 * @msix_index: MSIX table index supplied by the OS
7479 * @reply: reply message frame(lower 32bit addr)
7480 * Context: interrupt.
7482 * This function merely adds a new work task into ioc->firmware_event_thread.
7483 * The tasks are worked from _firmware_event_work in user context.
7488 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
7491 struct fw_event_work
*fw_event
;
7492 Mpi2EventNotificationReply_t
*mpi_reply
;
7496 /* events turned off due to host reset or driver unloading */
7497 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7500 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
7502 if (unlikely(!mpi_reply
)) {
7503 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
7504 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7508 event
= le16_to_cpu(mpi_reply
->Event
);
7512 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7514 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7515 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7516 mpi_reply
->EventData
;
7518 if (baen_data
->Primitive
!=
7519 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7522 if (ioc
->broadcast_aen_busy
) {
7523 ioc
->broadcast_aen_pending
++;
7526 ioc
->broadcast_aen_busy
= 1;
7530 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7531 _scsih_check_topo_delete_events(ioc
,
7532 (Mpi2EventDataSasTopologyChangeList_t
*)
7533 mpi_reply
->EventData
);
7535 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7536 _scsih_check_ir_config_unhide_events(ioc
,
7537 (Mpi2EventDataIrConfigChangeList_t
*)
7538 mpi_reply
->EventData
);
7540 case MPI2_EVENT_IR_VOLUME
:
7541 _scsih_check_volume_delete_events(ioc
,
7542 (Mpi2EventDataIrVolume_t
*)
7543 mpi_reply
->EventData
);
7545 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7547 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7550 if (!ioc
->is_warpdrive
)
7553 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7554 mpi_reply
->EventData
;
7555 log_code
= (__le32
*)log_entry
->LogData
;
7557 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7558 != MPT2_WARPDRIVE_LOGENTRY
)
7561 switch (le32_to_cpu(*log_code
)) {
7562 case MPT2_WARPDRIVE_LC_SSDT
:
7563 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7564 "IO Throttling has occurred in the WarpDrive "
7565 "subsystem. Check WarpDrive documentation for "
7566 "additional details.\n", ioc
->name
);
7568 case MPT2_WARPDRIVE_LC_SSDLW
:
7569 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7570 "Program/Erase Cycles for the WarpDrive subsystem "
7571 "in degraded range. Check WarpDrive documentation "
7572 "for additional details.\n", ioc
->name
);
7574 case MPT2_WARPDRIVE_LC_SSDLF
:
7575 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7576 "There are no Program/Erase Cycles for the "
7577 "WarpDrive subsystem. The storage device will be "
7578 "in read-only mode. Check WarpDrive documentation "
7579 "for additional details.\n", ioc
->name
);
7581 case MPT2_WARPDRIVE_LC_BRMF
:
7582 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7583 "The Backup Rail Monitor has failed on the "
7584 "WarpDrive subsystem. Check WarpDrive "
7585 "documentation for additional details.\n",
7592 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7593 case MPI2_EVENT_IR_OPERATION_STATUS
:
7594 case MPI2_EVENT_SAS_DISCOVERY
:
7595 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7596 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7599 case MPI2_EVENT_TEMP_THRESHOLD
:
7600 _scsih_temp_threshold_events(ioc
,
7601 (Mpi2EventDataTemperature_t
*)
7602 mpi_reply
->EventData
);
7605 default: /* ignore the rest */
7609 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7610 fw_event
= kzalloc(sizeof(*fw_event
) + sz
, GFP_ATOMIC
);
7612 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7613 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7617 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
7618 fw_event
->ioc
= ioc
;
7619 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7620 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7621 fw_event
->event
= event
;
7622 _scsih_fw_event_add(ioc
, fw_event
);
7626 /* shost template */
7627 static struct scsi_host_template scsih_driver_template
= {
7628 .module
= THIS_MODULE
,
7629 .name
= "Fusion MPT SAS Host",
7630 .proc_name
= MPT2SAS_DRIVER_NAME
,
7631 .queuecommand
= _scsih_qcmd
,
7632 .target_alloc
= _scsih_target_alloc
,
7633 .slave_alloc
= _scsih_slave_alloc
,
7634 .slave_configure
= _scsih_slave_configure
,
7635 .target_destroy
= _scsih_target_destroy
,
7636 .slave_destroy
= _scsih_slave_destroy
,
7637 .scan_finished
= _scsih_scan_finished
,
7638 .scan_start
= _scsih_scan_start
,
7639 .change_queue_depth
= _scsih_change_queue_depth
,
7640 .eh_abort_handler
= _scsih_abort
,
7641 .eh_device_reset_handler
= _scsih_dev_reset
,
7642 .eh_target_reset_handler
= _scsih_target_reset
,
7643 .eh_host_reset_handler
= _scsih_host_reset
,
7644 .bios_param
= _scsih_bios_param
,
7647 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
7648 .max_sectors
= 32767,
7650 .use_clustering
= ENABLE_CLUSTERING
,
7651 .shost_attrs
= mpt2sas_host_attrs
,
7652 .sdev_attrs
= mpt2sas_dev_attrs
,
7653 .track_queue_depth
= 1,
7657 * _scsih_expander_node_remove - removing expander device from list.
7658 * @ioc: per adapter object
7659 * @sas_expander: the sas_device object
7660 * Context: Calling function should acquire ioc->sas_node_lock.
7662 * Removing object and freeing associated memory from the
7663 * ioc->sas_expander_list.
7668 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
7669 struct _sas_node
*sas_expander
)
7671 struct _sas_port
*mpt2sas_port
, *next
;
7673 /* remove sibling ports attached to this expander */
7674 list_for_each_entry_safe(mpt2sas_port
, next
,
7675 &sas_expander
->sas_port_list
, port_list
) {
7676 if (ioc
->shost_recovery
)
7678 if (mpt2sas_port
->remote_identify
.device_type
==
7680 mpt2sas_device_remove_by_sas_address(ioc
,
7681 mpt2sas_port
->remote_identify
.sas_address
);
7682 else if (mpt2sas_port
->remote_identify
.device_type
==
7683 SAS_EDGE_EXPANDER_DEVICE
||
7684 mpt2sas_port
->remote_identify
.device_type
==
7685 SAS_FANOUT_EXPANDER_DEVICE
)
7686 mpt2sas_expander_remove(ioc
,
7687 mpt2sas_port
->remote_identify
.sas_address
);
7690 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7691 sas_expander
->sas_address_parent
);
7693 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
7694 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7695 sas_expander
->handle
, (unsigned long long)
7696 sas_expander
->sas_address
);
7698 kfree(sas_expander
->phy
);
7699 kfree(sas_expander
);
7703 * _scsih_ir_shutdown - IR shutdown notification
7704 * @ioc: per adapter object
7706 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7707 * the host system is shutting down.
7712 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
7714 Mpi2RaidActionRequest_t
*mpi_request
;
7715 Mpi2RaidActionReply_t
*mpi_reply
;
7718 /* is IR firmware build loaded ? */
7719 if (!ioc
->ir_firmware
)
7722 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7724 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
7725 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
7726 ioc
->name
, __func__
);
7729 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
7731 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7733 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
7734 ioc
->name
, __func__
);
7735 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7739 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
7740 ioc
->scsih_cmds
.smid
= smid
;
7741 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7743 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7744 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7746 if (!ioc
->hide_ir_msg
)
7747 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
7748 init_completion(&ioc
->scsih_cmds
.done
);
7749 mpt2sas_base_put_smid_default(ioc
, smid
);
7750 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7752 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
7753 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
7754 ioc
->name
, __func__
);
7758 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
7759 mpi_reply
= ioc
->scsih_cmds
.reply
;
7761 if (!ioc
->hide_ir_msg
)
7762 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
7763 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7764 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7765 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7769 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7770 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7774 * _scsih_shutdown - routine call during system shutdown
7775 * @pdev: PCI device struct
7780 _scsih_shutdown(struct pci_dev
*pdev
)
7782 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7783 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7784 struct workqueue_struct
*wq
;
7785 unsigned long flags
;
7787 ioc
->remove_host
= 1;
7788 _scsih_fw_event_cleanup_queue(ioc
);
7790 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7791 wq
= ioc
->firmware_event_thread
;
7792 ioc
->firmware_event_thread
= NULL
;
7793 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7795 destroy_workqueue(wq
);
7797 _scsih_ir_shutdown(ioc
);
7798 mpt2sas_base_detach(ioc
);
7802 * _scsih_remove - detach and remove add host
7803 * @pdev: PCI device struct
7805 * Routine called when unloading the driver.
7809 _scsih_remove(struct pci_dev
*pdev
)
7811 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7812 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7813 struct _sas_port
*mpt2sas_port
, *next_port
;
7814 struct _raid_device
*raid_device
, *next
;
7815 struct MPT2SAS_TARGET
*sas_target_priv_data
;
7816 struct workqueue_struct
*wq
;
7817 unsigned long flags
;
7819 ioc
->remove_host
= 1;
7820 _scsih_fw_event_cleanup_queue(ioc
);
7822 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7823 wq
= ioc
->firmware_event_thread
;
7824 ioc
->firmware_event_thread
= NULL
;
7825 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7827 destroy_workqueue(wq
);
7829 /* release all the volumes */
7830 _scsih_ir_shutdown(ioc
);
7831 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7833 if (raid_device
->starget
) {
7834 sas_target_priv_data
=
7835 raid_device
->starget
->hostdata
;
7836 sas_target_priv_data
->deleted
= 1;
7837 scsi_remove_target(&raid_device
->starget
->dev
);
7839 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
7840 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
7841 (unsigned long long) raid_device
->wwid
);
7842 _scsih_raid_device_remove(ioc
, raid_device
);
7845 /* free ports attached to the sas_host */
7846 list_for_each_entry_safe(mpt2sas_port
, next_port
,
7847 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7848 if (mpt2sas_port
->remote_identify
.device_type
==
7850 mpt2sas_device_remove_by_sas_address(ioc
,
7851 mpt2sas_port
->remote_identify
.sas_address
);
7852 else if (mpt2sas_port
->remote_identify
.device_type
==
7853 SAS_EDGE_EXPANDER_DEVICE
||
7854 mpt2sas_port
->remote_identify
.device_type
==
7855 SAS_FANOUT_EXPANDER_DEVICE
)
7856 mpt2sas_expander_remove(ioc
,
7857 mpt2sas_port
->remote_identify
.sas_address
);
7860 /* free phys attached to the sas_host */
7861 if (ioc
->sas_hba
.num_phys
) {
7862 kfree(ioc
->sas_hba
.phy
);
7863 ioc
->sas_hba
.phy
= NULL
;
7864 ioc
->sas_hba
.num_phys
= 0;
7867 sas_remove_host(shost
);
7868 scsi_remove_host(shost
);
7869 mpt2sas_base_detach(ioc
);
7870 list_del(&ioc
->list
);
7871 scsi_host_put(shost
);
7875 * _scsih_probe_boot_devices - reports 1st device
7876 * @ioc: per adapter object
7878 * If specified in bios page 2, this routine reports the 1st
7879 * device scsi-ml or sas transport for persistent boot device
7880 * purposes. Please refer to function _scsih_determine_boot_device()
7883 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
7887 struct _sas_device
*sas_device
;
7888 struct _raid_device
*raid_device
;
7890 u64 sas_address_parent
;
7892 unsigned long flags
;
7895 /* no Bios, return immediately */
7896 if (!ioc
->bios_pg3
.BiosVersion
)
7901 if (ioc
->req_boot_device
.device
) {
7902 device
= ioc
->req_boot_device
.device
;
7903 is_raid
= ioc
->req_boot_device
.is_raid
;
7904 } else if (ioc
->req_alt_boot_device
.device
) {
7905 device
= ioc
->req_alt_boot_device
.device
;
7906 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7907 } else if (ioc
->current_boot_device
.device
) {
7908 device
= ioc
->current_boot_device
.device
;
7909 is_raid
= ioc
->current_boot_device
.is_raid
;
7916 raid_device
= device
;
7917 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7918 raid_device
->id
, 0);
7920 _scsih_raid_device_remove(ioc
, raid_device
);
7922 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7923 sas_device
= device
;
7924 handle
= sas_device
->handle
;
7925 sas_address_parent
= sas_device
->sas_address_parent
;
7926 sas_address
= sas_device
->sas_address
;
7927 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7928 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7930 if (ioc
->hide_drives
)
7932 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7933 sas_device
->sas_address_parent
)) {
7934 _scsih_sas_device_remove(ioc
, sas_device
);
7935 } else if (!sas_device
->starget
) {
7936 if (!ioc
->is_driver_loading
) {
7937 mpt2sas_transport_port_remove(ioc
,
7939 sas_address_parent
);
7940 _scsih_sas_device_remove(ioc
, sas_device
);
7947 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7948 * @ioc: per adapter object
7950 * Called during initial loading of the driver.
7953 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
7955 struct _raid_device
*raid_device
, *raid_next
;
7958 list_for_each_entry_safe(raid_device
, raid_next
,
7959 &ioc
->raid_device_list
, list
) {
7960 if (raid_device
->starget
)
7962 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7963 raid_device
->id
, 0);
7965 _scsih_raid_device_remove(ioc
, raid_device
);
7970 * _scsih_probe_sas - reporting sas devices to sas transport
7971 * @ioc: per adapter object
7973 * Called during initial loading of the driver.
7976 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
7978 struct _sas_device
*sas_device
, *next
;
7979 unsigned long flags
;
7981 /* SAS Device List */
7982 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7985 if (ioc
->hide_drives
)
7988 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7989 sas_device
->sas_address_parent
)) {
7990 list_del(&sas_device
->list
);
7993 } else if (!sas_device
->starget
) {
7994 if (!ioc
->is_driver_loading
) {
7995 mpt2sas_transport_port_remove(ioc
,
7996 sas_device
->sas_address
,
7997 sas_device
->sas_address_parent
);
7998 list_del(&sas_device
->list
);
8003 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8004 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
8005 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8010 * _scsih_probe_devices - probing for devices
8011 * @ioc: per adapter object
8013 * Called during initial loading of the driver.
8016 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
8018 u16 volume_mapping_flags
;
8020 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
8021 return; /* return when IOC doesn't support initiator mode */
8023 _scsih_probe_boot_devices(ioc
);
8025 if (ioc
->ir_firmware
) {
8026 volume_mapping_flags
=
8027 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
8028 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
8029 if (volume_mapping_flags
==
8030 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
8031 _scsih_probe_raid(ioc
);
8032 _scsih_probe_sas(ioc
);
8034 _scsih_probe_sas(ioc
);
8035 _scsih_probe_raid(ioc
);
8038 _scsih_probe_sas(ioc
);
8043 * _scsih_scan_start - scsi lld callback for .scan_start
8044 * @shost: SCSI host pointer
8046 * The shost has the ability to discover targets on its own instead
8047 * of scanning the entire bus. In our implemention, we will kick off
8048 * firmware discovery.
8051 _scsih_scan_start(struct Scsi_Host
*shost
)
8053 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8056 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
8057 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
8059 if (disable_discovery
> 0)
8062 ioc
->start_scan
= 1;
8063 rc
= mpt2sas_port_enable(ioc
);
8066 printk(MPT2SAS_INFO_FMT
"port enable: FAILED\n", ioc
->name
);
8070 * _scsih_scan_finished - scsi lld callback for .scan_finished
8071 * @shost: SCSI host pointer
8072 * @time: elapsed time of the scan in jiffies
8074 * This function will be called periodically until it returns 1 with the
8075 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
8076 * we wait for firmware discovery to complete, then return 1.
8079 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
8081 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8083 if (disable_discovery
> 0) {
8084 ioc
->is_driver_loading
= 0;
8085 ioc
->wait_for_discovery_to_complete
= 0;
8089 if (time
>= (300 * HZ
)) {
8090 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
8091 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with timeout "
8092 "(timeout=300s)\n", ioc
->name
);
8093 ioc
->is_driver_loading
= 0;
8097 if (ioc
->start_scan
)
8100 if (ioc
->start_scan_failed
) {
8101 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with "
8102 "(ioc_status=0x%08x)\n", ioc
->name
, ioc
->start_scan_failed
);
8103 ioc
->is_driver_loading
= 0;
8104 ioc
->wait_for_discovery_to_complete
= 0;
8105 ioc
->remove_host
= 1;
8109 printk(MPT2SAS_INFO_FMT
"port enable: SUCCESS\n", ioc
->name
);
8110 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
8112 if (ioc
->wait_for_discovery_to_complete
) {
8113 ioc
->wait_for_discovery_to_complete
= 0;
8114 _scsih_probe_devices(ioc
);
8116 mpt2sas_base_start_watchdog(ioc
);
8117 ioc
->is_driver_loading
= 0;
8123 * _scsih_probe - attach and add scsi host
8124 * @pdev: PCI device struct
8125 * @id: pci device id
8127 * Returns 0 success, anything else error.
8130 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
8132 struct MPT2SAS_ADAPTER
*ioc
;
8133 struct Scsi_Host
*shost
;
8136 shost
= scsi_host_alloc(&scsih_driver_template
,
8137 sizeof(struct MPT2SAS_ADAPTER
));
8141 /* init local params */
8142 ioc
= shost_priv(shost
);
8143 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
8144 INIT_LIST_HEAD(&ioc
->list
);
8145 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
8147 ioc
->id
= mpt_ids
++;
8148 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
8150 if (id
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
8151 ioc
->is_warpdrive
= 1;
8152 ioc
->hide_ir_msg
= 1;
8154 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
8155 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
8156 ioc
->tm_cb_idx
= tm_cb_idx
;
8157 ioc
->ctl_cb_idx
= ctl_cb_idx
;
8158 ioc
->base_cb_idx
= base_cb_idx
;
8159 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
8160 ioc
->transport_cb_idx
= transport_cb_idx
;
8161 ioc
->scsih_cb_idx
= scsih_cb_idx
;
8162 ioc
->config_cb_idx
= config_cb_idx
;
8163 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
8164 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
8165 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
8166 ioc
->logging_level
= logging_level
;
8167 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
8168 /* misc semaphores and spin locks */
8169 mutex_init(&ioc
->reset_in_progress_mutex
);
8170 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
8171 spin_lock_init(&ioc
->scsi_lookup_lock
);
8172 spin_lock_init(&ioc
->sas_device_lock
);
8173 spin_lock_init(&ioc
->sas_node_lock
);
8174 spin_lock_init(&ioc
->fw_event_lock
);
8175 spin_lock_init(&ioc
->raid_device_lock
);
8177 INIT_LIST_HEAD(&ioc
->sas_device_list
);
8178 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
8179 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
8180 INIT_LIST_HEAD(&ioc
->fw_event_list
);
8181 INIT_LIST_HEAD(&ioc
->raid_device_list
);
8182 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
8183 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
8184 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
8185 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
8187 /* init shost parameters */
8188 shost
->max_cmd_len
= 32;
8189 shost
->max_lun
= max_lun
;
8190 shost
->transportt
= mpt2sas_transport_template
;
8191 shost
->unique_id
= ioc
->id
;
8193 if (max_sectors
!= 0xFFFF) {
8194 if (max_sectors
< 64) {
8195 shost
->max_sectors
= 64;
8196 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8197 "for max_sectors, range is 64 to 32767. Assigning "
8198 "value of 64.\n", ioc
->name
, max_sectors
);
8199 } else if (max_sectors
> 32767) {
8200 shost
->max_sectors
= 32767;
8201 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8202 "for max_sectors, range is 64 to 8192. Assigning "
8203 "default value of 32767.\n", ioc
->name
,
8206 shost
->max_sectors
= max_sectors
& 0xFFFE;
8207 printk(MPT2SAS_INFO_FMT
"The max_sectors value is "
8208 "set to %d\n", ioc
->name
, shost
->max_sectors
);
8212 /* register EEDP capabilities with SCSI layer */
8214 scsi_host_set_prot(shost
, prot_mask
);
8216 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8217 | SHOST_DIF_TYPE2_PROTECTION
8218 | SHOST_DIF_TYPE3_PROTECTION
);
8220 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8223 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8224 "fw_event%d", ioc
->id
);
8225 ioc
->firmware_event_thread
= create_singlethread_workqueue(
8226 ioc
->firmware_event_name
);
8227 if (!ioc
->firmware_event_thread
) {
8228 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8229 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8231 goto out_thread_fail
;
8234 ioc
->is_driver_loading
= 1;
8235 if ((mpt2sas_base_attach(ioc
))) {
8236 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8237 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8239 goto out_attach_fail
;
8242 if (ioc
->is_warpdrive
) {
8243 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8244 ioc
->hide_drives
= 0;
8245 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8246 ioc
->hide_drives
= 1;
8248 if (_scsih_get_num_volumes(ioc
))
8249 ioc
->hide_drives
= 1;
8251 ioc
->hide_drives
= 0;
8254 ioc
->hide_drives
= 0;
8256 rv
= scsi_add_host(shost
, &pdev
->dev
);
8258 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8259 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8260 goto out_add_shost_fail
;
8263 scsi_scan_host(shost
);
8268 mpt2sas_base_detach(ioc
);
8270 destroy_workqueue(ioc
->firmware_event_thread
);
8272 list_del(&ioc
->list
);
8273 scsi_host_put(shost
);
8279 * _scsih_suspend - power management suspend main entry point
8280 * @pdev: PCI device struct
8281 * @state: PM state change to (usually PCI_D3)
8283 * Returns 0 success, anything else error.
8286 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8288 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8289 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8290 pci_power_t device_state
;
8292 mpt2sas_base_stop_watchdog(ioc
);
8293 scsi_block_requests(shost
);
8294 _scsih_ir_shutdown(ioc
);
8295 device_state
= pci_choose_state(pdev
, state
);
8296 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
8297 "operating state [D%d]\n", ioc
->name
, pdev
,
8298 pci_name(pdev
), device_state
);
8300 mpt2sas_base_free_resources(ioc
);
8301 pci_save_state(pdev
);
8302 pci_set_power_state(pdev
, device_state
);
8307 * _scsih_resume - power management resume main entry point
8308 * @pdev: PCI device struct
8310 * Returns 0 success, anything else error.
8313 _scsih_resume(struct pci_dev
*pdev
)
8315 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8316 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8317 pci_power_t device_state
= pdev
->current_state
;
8320 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
8321 "operating state [D%d]\n", ioc
->name
, pdev
,
8322 pci_name(pdev
), device_state
);
8324 pci_set_power_state(pdev
, PCI_D0
);
8325 pci_enable_wake(pdev
, PCI_D0
, 0);
8326 pci_restore_state(pdev
);
8328 r
= mpt2sas_base_map_resources(ioc
);
8332 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8333 scsi_unblock_requests(shost
);
8334 mpt2sas_base_start_watchdog(ioc
);
8337 #endif /* CONFIG_PM */
8340 * _scsih_pci_error_detected - Called when a PCI error is detected.
8341 * @pdev: PCI device struct
8342 * @state: PCI channel state
8344 * Description: Called when a PCI error is detected.
8347 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8349 static pci_ers_result_t
8350 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8352 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8353 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8355 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
8359 case pci_channel_io_normal
:
8360 return PCI_ERS_RESULT_CAN_RECOVER
;
8361 case pci_channel_io_frozen
:
8362 /* Fatal error, prepare for slot reset */
8363 ioc
->pci_error_recovery
= 1;
8364 scsi_block_requests(ioc
->shost
);
8365 mpt2sas_base_stop_watchdog(ioc
);
8366 mpt2sas_base_free_resources(ioc
);
8367 return PCI_ERS_RESULT_NEED_RESET
;
8368 case pci_channel_io_perm_failure
:
8369 /* Permanent error, prepare for device removal */
8370 ioc
->pci_error_recovery
= 1;
8371 mpt2sas_base_stop_watchdog(ioc
);
8372 _scsih_flush_running_cmds(ioc
);
8373 return PCI_ERS_RESULT_DISCONNECT
;
8375 return PCI_ERS_RESULT_NEED_RESET
;
8379 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8380 * @pdev: PCI device struct
8382 * Description: This routine is called by the pci error recovery
8383 * code after the PCI slot has been reset, just before we
8384 * should resume normal operations.
8386 static pci_ers_result_t
8387 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
8389 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8390 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8393 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
8396 ioc
->pci_error_recovery
= 0;
8398 pci_restore_state(pdev
);
8399 rc
= mpt2sas_base_map_resources(ioc
);
8401 return PCI_ERS_RESULT_DISCONNECT
;
8404 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8407 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
8408 (rc
== 0) ? "success" : "failed");
8411 return PCI_ERS_RESULT_RECOVERED
;
8413 return PCI_ERS_RESULT_DISCONNECT
;
8417 * _scsih_pci_resume() - resume normal ops after PCI reset
8418 * @pdev: pointer to PCI device
8420 * Called when the error recovery driver tells us that its
8421 * OK to resume normal operation. Use completion to allow
8422 * halted scsi ops to resume.
8425 _scsih_pci_resume(struct pci_dev
*pdev
)
8427 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8428 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8430 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8432 pci_cleanup_aer_uncorrect_error_status(pdev
);
8433 mpt2sas_base_start_watchdog(ioc
);
8434 scsi_unblock_requests(ioc
->shost
);
8438 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8439 * @pdev: pointer to PCI device
8441 static pci_ers_result_t
8442 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8444 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8445 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8447 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
8450 /* TODO - dump whatever for debugging purposes */
8452 /* Request a slot reset. */
8453 return PCI_ERS_RESULT_NEED_RESET
;
8456 static const struct pci_error_handlers _scsih_err_handler
= {
8457 .error_detected
= _scsih_pci_error_detected
,
8458 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8459 .slot_reset
= _scsih_pci_slot_reset
,
8460 .resume
= _scsih_pci_resume
,
8463 static struct pci_driver scsih_driver
= {
8464 .name
= MPT2SAS_DRIVER_NAME
,
8465 .id_table
= scsih_pci_table
,
8466 .probe
= _scsih_probe
,
8467 .remove
= _scsih_remove
,
8468 .shutdown
= _scsih_shutdown
,
8469 .err_handler
= &_scsih_err_handler
,
8471 .suspend
= _scsih_suspend
,
8472 .resume
= _scsih_resume
,
8476 /* raid transport support */
8477 static struct raid_function_template mpt2sas_raid_functions
= {
8478 .cookie
= &scsih_driver_template
,
8479 .is_raid
= _scsih_is_raid
,
8480 .get_resync
= _scsih_get_resync
,
8481 .get_state
= _scsih_get_state
,
8485 * _scsih_init - main entry point for this driver.
8487 * Returns 0 success, anything else error.
8495 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
8496 MPT2SAS_DRIVER_VERSION
);
8498 mpt2sas_transport_template
=
8499 sas_attach_transport(&mpt2sas_transport_functions
);
8500 if (!mpt2sas_transport_template
)
8502 /* raid transport support */
8503 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
8504 if (!mpt2sas_raid_template
) {
8505 sas_release_transport(mpt2sas_transport_template
);
8509 mpt2sas_base_initialize_callback_handler();
8511 /* queuecommand callback hander */
8512 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
8514 /* task management callback handler */
8515 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
8517 /* base internal commands callback handler */
8518 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
8519 port_enable_cb_idx
= mpt2sas_base_register_callback_handler(
8520 mpt2sas_port_enable_done
);
8522 /* transport internal commands callback handler */
8523 transport_cb_idx
= mpt2sas_base_register_callback_handler(
8524 mpt2sas_transport_done
);
8526 /* scsih internal commands callback handler */
8527 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
8529 /* configuration page API internal commands callback handler */
8530 config_cb_idx
= mpt2sas_base_register_callback_handler(
8531 mpt2sas_config_done
);
8533 /* ctl module callback handler */
8534 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
8536 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
8537 _scsih_tm_tr_complete
);
8539 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
8540 _scsih_tm_volume_tr_complete
);
8542 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
8543 _scsih_sas_control_complete
);
8547 error
= pci_register_driver(&scsih_driver
);
8549 /* raid transport support */
8550 raid_class_release(mpt2sas_raid_template
);
8551 sas_release_transport(mpt2sas_transport_template
);
8558 * _scsih_exit - exit point for this driver (when it is a module).
8560 * Returns 0 success, anything else error.
8565 printk(KERN_INFO
"mpt2sas version %s unloading\n",
8566 MPT2SAS_DRIVER_VERSION
);
8568 pci_unregister_driver(&scsih_driver
);
8572 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
8573 mpt2sas_base_release_callback_handler(tm_cb_idx
);
8574 mpt2sas_base_release_callback_handler(base_cb_idx
);
8575 mpt2sas_base_release_callback_handler(port_enable_cb_idx
);
8576 mpt2sas_base_release_callback_handler(transport_cb_idx
);
8577 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
8578 mpt2sas_base_release_callback_handler(config_cb_idx
);
8579 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
8581 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
8582 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8583 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8585 /* raid transport support */
8586 raid_class_release(mpt2sas_raid_template
);
8587 sas_release_transport(mpt2sas_transport_template
);
8591 module_init(_scsih_init
);
8592 module_exit(_scsih_exit
);