2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2010 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/init.h>
47 #include <linux/errno.h>
48 #include <linux/blkdev.h>
49 #include <linux/sched.h>
50 #include <linux/workqueue.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/interrupt.h>
54 #include <linux/aer.h>
55 #include <linux/raid_class.h>
56 #include <linux/slab.h>
58 #include "mpt2sas_base.h"
60 MODULE_AUTHOR(MPT2SAS_AUTHOR
);
61 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION
);
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(MPT2SAS_DRIVER_VERSION
);
65 #define RAID_CHANNEL 1
68 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
69 struct _sas_node
*sas_expander
);
70 static void _firmware_event_work(struct work_struct
*work
);
72 static u8
_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
);
74 static void _scsih_scan_start(struct Scsi_Host
*shost
);
75 static int _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
);
77 /* global parameters */
78 LIST_HEAD(mpt2sas_ioc_list
);
80 /* local parameters */
81 static u8 scsi_io_cb_idx
= -1;
82 static u8 tm_cb_idx
= -1;
83 static u8 ctl_cb_idx
= -1;
84 static u8 base_cb_idx
= -1;
85 static u8 port_enable_cb_idx
= -1;
86 static u8 transport_cb_idx
= -1;
87 static u8 scsih_cb_idx
= -1;
88 static u8 config_cb_idx
= -1;
91 static u8 tm_tr_cb_idx
= -1 ;
92 static u8 tm_tr_volume_cb_idx
= -1 ;
93 static u8 tm_sas_control_cb_idx
= -1;
95 /* command line options */
96 static u32 logging_level
;
97 MODULE_PARM_DESC(logging_level
, " bits for enabling additional logging info "
100 static ushort max_sectors
= 0xFFFF;
101 module_param(max_sectors
, ushort
, 0);
102 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 8192 default=8192");
104 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
105 #define MPT2SAS_MAX_LUN (16895)
106 static int max_lun
= MPT2SAS_MAX_LUN
;
107 module_param(max_lun
, int, 0);
108 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
110 /* diag_buffer_enable is bitwise
112 * bit 1 set = SNAPSHOT
113 * bit 2 set = EXTENDED
115 * Either bit can be set, or both
117 static int diag_buffer_enable
= -1;
118 module_param(diag_buffer_enable
, int, 0);
119 MODULE_PARM_DESC(diag_buffer_enable
, " post diag buffers "
120 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
123 * struct sense_info - common structure for obtaining sense keys
125 * @asc: additional sense code
126 * @ascq: additional sense code qualifier
135 #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
136 #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
137 #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
139 * struct fw_event_work - firmware event struct
140 * @list: link list framework
141 * @work: work object (ioc->fault_reset_work_q)
142 * @cancel_pending_work: flag set during reset handling
143 * @ioc: per adapter object
144 * @device_handle: device handle
145 * @VF_ID: virtual function id
146 * @VP_ID: virtual port id
147 * @ignore: flag meaning this event has been marked to ignore
148 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
149 * @event_data: reply event data payload follows
151 * This object stored on ioc->fw_event_list.
153 struct fw_event_work
{
154 struct list_head list
;
155 u8 cancel_pending_work
;
156 struct delayed_work delayed_work
;
157 struct MPT2SAS_ADAPTER
*ioc
;
166 /* raid transport support */
167 static struct raid_template
*mpt2sas_raid_template
;
170 * struct _scsi_io_transfer - scsi io transfer
171 * @handle: sas device handle (assigned by firmware)
172 * @is_raid: flag set for hidden raid components
173 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
174 * @data_length: data transfer length
175 * @data_dma: dma pointer to data
178 * @cdb_length: cdb length
180 * @timeout: timeout for this command
181 * @VF_ID: virtual function id
182 * @VP_ID: virtual port id
183 * @valid_reply: flag set for reply message
184 * @sense_length: sense length
185 * @ioc_status: ioc status
186 * @scsi_state: scsi state
187 * @scsi_status: scsi staus
188 * @log_info: log information
189 * @transfer_length: data length transfer when there is a reply message
191 * Used for sending internal scsi commands to devices within this module.
192 * Refer to _scsi_send_scsi_io().
194 struct _scsi_io_transfer
{
197 enum dma_data_direction dir
;
200 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
208 /* the following bits are only valid when 'valid_reply = 1' */
218 * The pci device ids are defined in mpi/mpi2_cnfg.h.
220 static struct pci_device_id scsih_pci_table
[] = {
221 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
222 PCI_ANY_ID
, PCI_ANY_ID
},
224 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
225 PCI_ANY_ID
, PCI_ANY_ID
},
226 /* Liberator ~ 2108 */
227 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
228 PCI_ANY_ID
, PCI_ANY_ID
},
229 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
230 PCI_ANY_ID
, PCI_ANY_ID
},
231 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
232 PCI_ANY_ID
, PCI_ANY_ID
},
234 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
235 PCI_ANY_ID
, PCI_ANY_ID
},
236 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
237 PCI_ANY_ID
, PCI_ANY_ID
},
238 /* Thunderbolt ~ 2208 */
239 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
240 PCI_ANY_ID
, PCI_ANY_ID
},
241 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
242 PCI_ANY_ID
, PCI_ANY_ID
},
243 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
244 PCI_ANY_ID
, PCI_ANY_ID
},
245 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
246 PCI_ANY_ID
, PCI_ANY_ID
},
247 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
248 PCI_ANY_ID
, PCI_ANY_ID
},
249 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
250 PCI_ANY_ID
, PCI_ANY_ID
},
252 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
253 PCI_ANY_ID
, PCI_ANY_ID
},
254 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
255 PCI_ANY_ID
, PCI_ANY_ID
},
256 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
257 PCI_ANY_ID
, PCI_ANY_ID
},
259 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
260 PCI_ANY_ID
, PCI_ANY_ID
},
261 {0} /* Terminating entry */
263 MODULE_DEVICE_TABLE(pci
, scsih_pci_table
);
266 * _scsih_set_debug_level - global setting of ioc->logging_level.
268 * Note: The logging levels are defined in mpt2sas_debug.h.
271 _scsih_set_debug_level(const char *val
, struct kernel_param
*kp
)
273 int ret
= param_set_int(val
, kp
);
274 struct MPT2SAS_ADAPTER
*ioc
;
279 printk(KERN_INFO
"setting logging_level(0x%08x)\n", logging_level
);
280 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
281 ioc
->logging_level
= logging_level
;
284 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
285 &logging_level
, 0644);
288 * _scsih_srch_boot_sas_address - search based on sas_address
289 * @sas_address: sas address
290 * @boot_device: boot device object from bios page 2
292 * Returns 1 when there's a match, 0 means no match.
295 _scsih_srch_boot_sas_address(u64 sas_address
,
296 Mpi2BootDeviceSasWwid_t
*boot_device
)
298 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
302 * _scsih_srch_boot_device_name - search based on device name
303 * @device_name: device name specified in INDENTIFY fram
304 * @boot_device: boot device object from bios page 2
306 * Returns 1 when there's a match, 0 means no match.
309 _scsih_srch_boot_device_name(u64 device_name
,
310 Mpi2BootDeviceDeviceName_t
*boot_device
)
312 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
316 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
317 * @enclosure_logical_id: enclosure logical id
318 * @slot_number: slot number
319 * @boot_device: boot device object from bios page 2
321 * Returns 1 when there's a match, 0 means no match.
324 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
325 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
327 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
328 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
329 SlotNumber
)) ? 1 : 0;
333 * _scsih_is_boot_device - search for matching boot device.
334 * @sas_address: sas address
335 * @device_name: device name specified in INDENTIFY fram
336 * @enclosure_logical_id: enclosure logical id
337 * @slot_number: slot number
338 * @form: specifies boot device form
339 * @boot_device: boot device object from bios page 2
341 * Returns 1 when there's a match, 0 means no match.
344 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
345 u64 enclosure_logical_id
, u16 slot
, u8 form
,
346 Mpi2BiosPage2BootDevice_t
*boot_device
)
351 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
354 rc
= _scsih_srch_boot_sas_address(
355 sas_address
, &boot_device
->SasWwid
);
357 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
358 if (!enclosure_logical_id
)
360 rc
= _scsih_srch_boot_encl_slot(
361 enclosure_logical_id
,
362 slot
, &boot_device
->EnclosureSlot
);
364 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
367 rc
= _scsih_srch_boot_device_name(
368 device_name
, &boot_device
->DeviceName
);
370 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
378 * _scsih_get_sas_address - set the sas_address for given device handle
379 * @handle: device handle
380 * @sas_address: sas address
382 * Returns 0 success, non-zero when failure
385 _scsih_get_sas_address(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
,
388 Mpi2SasDevicePage0_t sas_device_pg0
;
389 Mpi2ConfigReply_t mpi_reply
;
393 if (handle
<= ioc
->sas_hba
.num_phys
) {
394 *sas_address
= ioc
->sas_hba
.sas_address
;
398 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
400 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
401 __FILE__
, __LINE__
, __func__
);
405 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
406 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
407 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
411 /* we hit this becuase the given parent handle doesn't exist */
412 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
414 /* else error case */
415 printk(MPT2SAS_ERR_FMT
"handle(0x%04x), ioc_status(0x%04x), "
416 "failure at %s:%d/%s()!\n", ioc
->name
, handle
, ioc_status
,
417 __FILE__
, __LINE__
, __func__
);
422 * _scsih_determine_boot_device - determine boot device.
423 * @ioc: per adapter object
424 * @device: either sas_device or raid_device object
425 * @is_raid: [flag] 1 = raid object, 0 = sas object
427 * Determines whether this device should be first reported device to
428 * to scsi-ml or sas transport, this purpose is for persistent boot device.
429 * There are primary, alternate, and current entries in bios page 2. The order
430 * priority is primary, alternate, then current. This routine saves
431 * the corresponding device object and is_raid flag in the ioc object.
432 * The saved data to be used later in _scsih_probe_boot_devices().
435 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER
*ioc
,
436 void *device
, u8 is_raid
)
438 struct _sas_device
*sas_device
;
439 struct _raid_device
*raid_device
;
442 u64 enclosure_logical_id
;
445 /* only process this function when driver loads */
446 if (!ioc
->is_driver_loading
)
449 /* no Bios, return immediately */
450 if (!ioc
->bios_pg3
.BiosVersion
)
455 sas_address
= sas_device
->sas_address
;
456 device_name
= sas_device
->device_name
;
457 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
458 slot
= sas_device
->slot
;
460 raid_device
= device
;
461 sas_address
= raid_device
->wwid
;
463 enclosure_logical_id
= 0;
467 if (!ioc
->req_boot_device
.device
) {
468 if (_scsih_is_boot_device(sas_address
, device_name
,
469 enclosure_logical_id
, slot
,
470 (ioc
->bios_pg2
.ReqBootDeviceForm
&
471 MPI2_BIOSPAGE2_FORM_MASK
),
472 &ioc
->bios_pg2
.RequestedBootDevice
)) {
473 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
474 "%s: req_boot_device(0x%016llx)\n",
476 (unsigned long long)sas_address
));
477 ioc
->req_boot_device
.device
= device
;
478 ioc
->req_boot_device
.is_raid
= is_raid
;
482 if (!ioc
->req_alt_boot_device
.device
) {
483 if (_scsih_is_boot_device(sas_address
, device_name
,
484 enclosure_logical_id
, slot
,
485 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
486 MPI2_BIOSPAGE2_FORM_MASK
),
487 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
488 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
489 "%s: req_alt_boot_device(0x%016llx)\n",
491 (unsigned long long)sas_address
));
492 ioc
->req_alt_boot_device
.device
= device
;
493 ioc
->req_alt_boot_device
.is_raid
= is_raid
;
497 if (!ioc
->current_boot_device
.device
) {
498 if (_scsih_is_boot_device(sas_address
, device_name
,
499 enclosure_logical_id
, slot
,
500 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
501 MPI2_BIOSPAGE2_FORM_MASK
),
502 &ioc
->bios_pg2
.CurrentBootDevice
)) {
503 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
504 "%s: current_boot_device(0x%016llx)\n",
506 (unsigned long long)sas_address
));
507 ioc
->current_boot_device
.device
= device
;
508 ioc
->current_boot_device
.is_raid
= is_raid
;
514 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
515 * @ioc: per adapter object
516 * @sas_address: sas address
517 * Context: Calling function should acquire ioc->sas_device_lock
519 * This searches for sas_device based on sas_address, then return sas_device
523 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
526 struct _sas_device
*sas_device
;
528 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
529 if (sas_device
->sas_address
== sas_address
)
532 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
533 if (sas_device
->sas_address
== sas_address
)
540 * _scsih_sas_device_find_by_handle - sas device search
541 * @ioc: per adapter object
542 * @handle: sas device handle (assigned by firmware)
543 * Context: Calling function should acquire ioc->sas_device_lock
545 * This searches for sas_device based on sas_address, then return sas_device
548 static struct _sas_device
*
549 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
551 struct _sas_device
*sas_device
;
553 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
554 if (sas_device
->handle
== handle
)
557 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
558 if (sas_device
->handle
== handle
)
565 * _scsih_sas_device_remove - remove sas_device from list.
566 * @ioc: per adapter object
567 * @sas_device: the sas_device object
568 * Context: This function will acquire ioc->sas_device_lock.
570 * Removing object and freeing associated memory from the ioc->sas_device_list.
573 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
574 struct _sas_device
*sas_device
)
581 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
582 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
583 sas_device
->sas_address
)) {
584 list_del(&sas_device
->list
);
587 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
591 * _scsih_sas_device_add - insert sas_device to the list.
592 * @ioc: per adapter object
593 * @sas_device: the sas_device object
594 * Context: This function will acquire ioc->sas_device_lock.
596 * Adding new object to the ioc->sas_device_list.
599 _scsih_sas_device_add(struct MPT2SAS_ADAPTER
*ioc
,
600 struct _sas_device
*sas_device
)
604 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
605 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
606 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
608 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
609 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
610 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
612 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
613 sas_device
->sas_address_parent
))
614 _scsih_sas_device_remove(ioc
, sas_device
);
618 * _scsih_sas_device_init_add - insert sas_device to the list.
619 * @ioc: per adapter object
620 * @sas_device: the sas_device object
621 * Context: This function will acquire ioc->sas_device_lock.
623 * Adding new object at driver load time to the ioc->sas_device_init_list.
626 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
627 struct _sas_device
*sas_device
)
631 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
632 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
633 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
635 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
636 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
637 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
638 _scsih_determine_boot_device(ioc
, sas_device
, 0);
642 * _scsih_raid_device_find_by_id - raid device search
643 * @ioc: per adapter object
644 * @id: sas device target id
645 * @channel: sas device channel
646 * Context: Calling function should acquire ioc->raid_device_lock
648 * This searches for raid_device based on target id, then return raid_device
651 static struct _raid_device
*
652 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
654 struct _raid_device
*raid_device
, *r
;
657 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
658 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
669 * _scsih_raid_device_find_by_handle - raid device search
670 * @ioc: per adapter object
671 * @handle: sas device handle (assigned by firmware)
672 * Context: Calling function should acquire ioc->raid_device_lock
674 * This searches for raid_device based on handle, then return raid_device
677 static struct _raid_device
*
678 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
680 struct _raid_device
*raid_device
, *r
;
683 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
684 if (raid_device
->handle
!= handle
)
695 * _scsih_raid_device_find_by_wwid - 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 wwid, then return raid_device
703 static struct _raid_device
*
704 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
706 struct _raid_device
*raid_device
, *r
;
709 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
710 if (raid_device
->wwid
!= wwid
)
721 * _scsih_raid_device_add - add raid_device object
722 * @ioc: per adapter object
723 * @raid_device: raid_device object
725 * This is added to the raid_device_list link list.
728 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
729 struct _raid_device
*raid_device
)
733 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
734 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
735 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
737 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
738 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
739 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
743 * _scsih_raid_device_remove - delete raid_device object
744 * @ioc: per adapter object
745 * @raid_device: raid_device object
747 * This is removed from the raid_device_list link list.
750 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
751 struct _raid_device
*raid_device
)
755 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
756 list_del(&raid_device
->list
);
757 memset(raid_device
, 0, sizeof(struct _raid_device
));
759 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
763 * mpt2sas_scsih_expander_find_by_handle - expander device search
764 * @ioc: per adapter object
765 * @handle: expander handle (assigned by firmware)
766 * Context: Calling function should acquire ioc->sas_device_lock
768 * This searches for expander device based on handle, then returns the
772 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
774 struct _sas_node
*sas_expander
, *r
;
777 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
778 if (sas_expander
->handle
!= handle
)
788 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
789 * @ioc: per adapter object
790 * @sas_address: sas address
791 * Context: Calling function should acquire ioc->sas_node_lock.
793 * This searches for expander device based on sas_address, then returns the
797 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
800 struct _sas_node
*sas_expander
, *r
;
803 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
804 if (sas_expander
->sas_address
!= sas_address
)
814 * _scsih_expander_node_add - insert expander device to the list.
815 * @ioc: per adapter object
816 * @sas_expander: the sas_device object
817 * Context: This function will acquire ioc->sas_node_lock.
819 * Adding new object to the ioc->sas_expander_list.
824 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
825 struct _sas_node
*sas_expander
)
829 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
830 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
831 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
835 * _scsih_is_end_device - determines if device is an end device
836 * @device_info: bitfield providing information about the device.
839 * Returns 1 if end device.
842 _scsih_is_end_device(u32 device_info
)
844 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
845 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
846 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
847 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
854 * _scsih_scsi_lookup_get - returns scmd entry
855 * @ioc: per adapter object
856 * @smid: system request message index
858 * Returns the smid stored scmd pointer.
860 static struct scsi_cmnd
*
861 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
863 return ioc
->scsi_lookup
[smid
- 1].scmd
;
867 * _scsih_scsi_lookup_get_clear - returns scmd entry
868 * @ioc: per adapter object
869 * @smid: system request message index
871 * Returns the smid stored scmd pointer.
872 * Then will derefrence the stored scmd pointer.
874 static inline struct scsi_cmnd
*
875 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
878 struct scsi_cmnd
*scmd
;
880 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
881 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
882 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
883 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
889 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
890 * @ioc: per adapter object
891 * @smid: system request message index
892 * @scmd: pointer to scsi command object
893 * Context: This function will acquire ioc->scsi_lookup_lock.
895 * This will search for a scmd pointer in the scsi_lookup array,
896 * returning the revelent smid. A returned value of zero means invalid.
899 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
906 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
908 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
909 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
910 smid
= ioc
->scsi_lookup
[i
].smid
;
915 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
920 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
921 * @ioc: per adapter object
924 * Context: This function will acquire ioc->scsi_lookup_lock.
926 * This will search for a matching channel:id in the scsi_lookup array,
927 * returning 1 if found.
930 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
937 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
939 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
940 if (ioc
->scsi_lookup
[i
].scmd
&&
941 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
942 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
948 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
953 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
954 * @ioc: per adapter object
958 * Context: This function will acquire ioc->scsi_lookup_lock.
960 * This will search for a matching channel:id:lun in the scsi_lookup array,
961 * returning 1 if found.
964 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
965 unsigned int lun
, int channel
)
971 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
973 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
974 if (ioc
->scsi_lookup
[i
].scmd
&&
975 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
976 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
977 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
983 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
988 * _scsih_get_chain_buffer_tracker - obtain chain tracker
989 * @ioc: per adapter object
990 * @smid: smid associated to an IO request
992 * Returns chain tracker(from ioc->free_chain_list)
994 static struct chain_tracker
*
995 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
997 struct chain_tracker
*chain_req
;
1000 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1001 if (list_empty(&ioc
->free_chain_list
)) {
1002 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1003 printk(MPT2SAS_WARN_FMT
"chain buffers not available\n",
1007 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1008 struct chain_tracker
, tracker_list
);
1009 list_del_init(&chain_req
->tracker_list
);
1010 list_add_tail(&chain_req
->tracker_list
,
1011 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1012 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1017 * _scsih_build_scatter_gather - main sg creation routine
1018 * @ioc: per adapter object
1019 * @scmd: scsi command
1020 * @smid: system request message index
1023 * The main routine that builds scatter gather table from a given
1024 * scsi request sent via the .queuecommand main handler.
1026 * Returns 0 success, anything else error
1029 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
1030 struct scsi_cmnd
*scmd
, u16 smid
)
1032 Mpi2SCSIIORequest_t
*mpi_request
;
1033 dma_addr_t chain_dma
;
1034 struct scatterlist
*sg_scmd
;
1035 void *sg_local
, *chain
;
1040 u32 sges_in_segment
;
1042 u32 sgl_flags_last_element
;
1043 u32 sgl_flags_end_buffer
;
1044 struct chain_tracker
*chain_req
;
1046 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1048 /* init scatter gather flags */
1049 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1050 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1051 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1052 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1053 << MPI2_SGE_FLAGS_SHIFT
;
1054 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1055 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1056 << MPI2_SGE_FLAGS_SHIFT
;
1057 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1059 sg_scmd
= scsi_sglist(scmd
);
1060 sges_left
= scsi_dma_map(scmd
);
1061 if (sges_left
< 0) {
1062 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1063 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1067 sg_local
= &mpi_request
->SGL
;
1068 sges_in_segment
= ioc
->max_sges_in_main_message
;
1069 if (sges_left
<= sges_in_segment
)
1070 goto fill_in_last_segment
;
1072 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1073 (sges_in_segment
* ioc
->sge_size
))/4;
1075 /* fill in main message segment when there is a chain following */
1076 while (sges_in_segment
) {
1077 if (sges_in_segment
== 1)
1078 ioc
->base_add_sg_single(sg_local
,
1079 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1080 sg_dma_address(sg_scmd
));
1082 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1083 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1084 sg_scmd
= sg_next(sg_scmd
);
1085 sg_local
+= ioc
->sge_size
;
1090 /* initializing the chain flags and pointers */
1091 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1092 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1095 chain
= chain_req
->chain_buffer
;
1096 chain_dma
= chain_req
->chain_buffer_dma
;
1098 sges_in_segment
= (sges_left
<=
1099 ioc
->max_sges_in_chain_message
) ? sges_left
:
1100 ioc
->max_sges_in_chain_message
;
1101 chain_offset
= (sges_left
== sges_in_segment
) ?
1102 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1103 chain_length
= sges_in_segment
* ioc
->sge_size
;
1105 chain_offset
= chain_offset
<<
1106 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1107 chain_length
+= ioc
->sge_size
;
1109 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1110 chain_length
, chain_dma
);
1113 goto fill_in_last_segment
;
1115 /* fill in chain segments */
1116 while (sges_in_segment
) {
1117 if (sges_in_segment
== 1)
1118 ioc
->base_add_sg_single(sg_local
,
1119 sgl_flags_last_element
|
1120 sg_dma_len(sg_scmd
),
1121 sg_dma_address(sg_scmd
));
1123 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1124 sg_dma_len(sg_scmd
),
1125 sg_dma_address(sg_scmd
));
1126 sg_scmd
= sg_next(sg_scmd
);
1127 sg_local
+= ioc
->sge_size
;
1132 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1135 chain
= chain_req
->chain_buffer
;
1136 chain_dma
= chain_req
->chain_buffer_dma
;
1140 fill_in_last_segment
:
1142 /* fill the last segment */
1145 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1146 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1148 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1149 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1150 sg_scmd
= sg_next(sg_scmd
);
1151 sg_local
+= ioc
->sge_size
;
1159 * _scsih_adjust_queue_depth - setting device queue depth
1160 * @sdev: scsi device struct
1161 * @qdepth: requested queue depth
1167 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1169 struct Scsi_Host
*shost
= sdev
->host
;
1171 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1172 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1173 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1174 struct _sas_device
*sas_device
;
1175 unsigned long flags
;
1177 max_depth
= shost
->can_queue
;
1179 /* limit max device queue for SATA to 32 */
1180 sas_device_priv_data
= sdev
->hostdata
;
1181 if (!sas_device_priv_data
)
1183 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1184 if (!sas_target_priv_data
)
1186 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1188 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1189 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1190 sas_device_priv_data
->sas_target
->sas_address
);
1191 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1192 if (sas_device
&& sas_device
->device_info
&
1193 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1194 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1198 if (!sdev
->tagged_supported
)
1200 if (qdepth
> max_depth
)
1202 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1206 * _scsih_change_queue_depth - setting device queue depth
1207 * @sdev: scsi device struct
1208 * @qdepth: requested queue depth
1209 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1210 * (see include/scsi/scsi_host.h for definition)
1212 * Returns queue depth.
1215 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1217 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1218 _scsih_adjust_queue_depth(sdev
, qdepth
);
1219 else if (reason
== SCSI_QDEPTH_QFULL
)
1220 scsi_track_queue_full(sdev
, qdepth
);
1224 if (sdev
->inquiry_len
> 7)
1225 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1226 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1227 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1228 sdev
->ordered_tags
, sdev
->scsi_level
,
1229 (sdev
->inquiry
[7] & 2) >> 1);
1231 return sdev
->queue_depth
;
1235 * _scsih_change_queue_type - changing device queue tag type
1236 * @sdev: scsi device struct
1237 * @tag_type: requested tag type
1239 * Returns queue tag type.
1242 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1244 if (sdev
->tagged_supported
) {
1245 scsi_set_tag_type(sdev
, tag_type
);
1247 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1249 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1257 * _scsih_target_alloc - target add routine
1258 * @starget: scsi target struct
1260 * Returns 0 if ok. Any other return is assumed to be an error and
1261 * the device is ignored.
1264 _scsih_target_alloc(struct scsi_target
*starget
)
1266 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1267 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1268 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1269 struct _sas_device
*sas_device
;
1270 struct _raid_device
*raid_device
;
1271 unsigned long flags
;
1272 struct sas_rphy
*rphy
;
1274 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1275 if (!sas_target_priv_data
)
1278 starget
->hostdata
= sas_target_priv_data
;
1279 sas_target_priv_data
->starget
= starget
;
1280 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1283 if (starget
->channel
== RAID_CHANNEL
) {
1284 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1285 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1288 sas_target_priv_data
->handle
= raid_device
->handle
;
1289 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1290 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1291 sas_target_priv_data
->raid_device
= raid_device
;
1292 raid_device
->starget
= starget
;
1294 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1298 /* sas/sata devices */
1299 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1300 rphy
= dev_to_rphy(starget
->dev
.parent
);
1301 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1302 rphy
->identify
.sas_address
);
1305 sas_target_priv_data
->handle
= sas_device
->handle
;
1306 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1307 sas_device
->starget
= starget
;
1308 sas_device
->id
= starget
->id
;
1309 sas_device
->channel
= starget
->channel
;
1310 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1311 sas_target_priv_data
->flags
|=
1312 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1314 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1320 * _scsih_target_destroy - target destroy routine
1321 * @starget: scsi target struct
1326 _scsih_target_destroy(struct scsi_target
*starget
)
1328 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1329 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1330 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1331 struct _sas_device
*sas_device
;
1332 struct _raid_device
*raid_device
;
1333 unsigned long flags
;
1334 struct sas_rphy
*rphy
;
1336 sas_target_priv_data
= starget
->hostdata
;
1337 if (!sas_target_priv_data
)
1340 if (starget
->channel
== RAID_CHANNEL
) {
1341 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1342 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1345 raid_device
->starget
= NULL
;
1346 raid_device
->sdev
= NULL
;
1348 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1352 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1353 rphy
= dev_to_rphy(starget
->dev
.parent
);
1354 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1355 rphy
->identify
.sas_address
);
1356 if (sas_device
&& (sas_device
->starget
== starget
) &&
1357 (sas_device
->id
== starget
->id
) &&
1358 (sas_device
->channel
== starget
->channel
))
1359 sas_device
->starget
= NULL
;
1361 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1364 kfree(sas_target_priv_data
);
1365 starget
->hostdata
= NULL
;
1369 * _scsih_slave_alloc - device add routine
1370 * @sdev: scsi device struct
1372 * Returns 0 if ok. Any other return is assumed to be an error and
1373 * the device is ignored.
1376 _scsih_slave_alloc(struct scsi_device
*sdev
)
1378 struct Scsi_Host
*shost
;
1379 struct MPT2SAS_ADAPTER
*ioc
;
1380 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1381 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1382 struct scsi_target
*starget
;
1383 struct _raid_device
*raid_device
;
1384 unsigned long flags
;
1386 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1387 if (!sas_device_priv_data
)
1390 sas_device_priv_data
->lun
= sdev
->lun
;
1391 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1393 starget
= scsi_target(sdev
);
1394 sas_target_priv_data
= starget
->hostdata
;
1395 sas_target_priv_data
->num_luns
++;
1396 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1397 sdev
->hostdata
= sas_device_priv_data
;
1398 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1399 sdev
->no_uld_attach
= 1;
1401 shost
= dev_to_shost(&starget
->dev
);
1402 ioc
= shost_priv(shost
);
1403 if (starget
->channel
== RAID_CHANNEL
) {
1404 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1405 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1406 starget
->id
, starget
->channel
);
1408 raid_device
->sdev
= sdev
; /* raid is single lun */
1409 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1416 * _scsih_slave_destroy - device destroy routine
1417 * @sdev: scsi device struct
1422 _scsih_slave_destroy(struct scsi_device
*sdev
)
1424 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1425 struct scsi_target
*starget
;
1427 if (!sdev
->hostdata
)
1430 starget
= scsi_target(sdev
);
1431 sas_target_priv_data
= starget
->hostdata
;
1432 sas_target_priv_data
->num_luns
--;
1433 kfree(sdev
->hostdata
);
1434 sdev
->hostdata
= NULL
;
1438 * _scsih_display_sata_capabilities - sata capabilities
1439 * @ioc: per adapter object
1440 * @sas_device: the sas_device object
1441 * @sdev: scsi device struct
1444 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1445 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1447 Mpi2ConfigReply_t mpi_reply
;
1448 Mpi2SasDevicePage0_t sas_device_pg0
;
1453 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1454 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1455 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1456 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1460 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1461 MPI2_IOCSTATUS_MASK
;
1462 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1463 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1464 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1468 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1469 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1471 sdev_printk(KERN_INFO
, sdev
,
1472 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1473 "sw_preserve(%s)\n",
1474 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1475 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1476 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1478 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1479 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1480 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1484 * _scsih_is_raid - return boolean indicating device is raid volume
1485 * @dev the device struct object
1488 _scsih_is_raid(struct device
*dev
)
1490 struct scsi_device
*sdev
= to_scsi_device(dev
);
1491 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1493 if (ioc
->is_warpdrive
)
1495 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1499 * _scsih_get_resync - get raid volume resync percent complete
1500 * @dev the device struct object
1503 _scsih_get_resync(struct device
*dev
)
1505 struct scsi_device
*sdev
= to_scsi_device(dev
);
1506 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1507 static struct _raid_device
*raid_device
;
1508 unsigned long flags
;
1509 Mpi2RaidVolPage0_t vol_pg0
;
1510 Mpi2ConfigReply_t mpi_reply
;
1511 u32 volume_status_flags
;
1512 u8 percent_complete
= 0;
1514 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1515 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1517 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1519 if (!raid_device
|| ioc
->is_warpdrive
)
1522 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1523 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1524 sizeof(Mpi2RaidVolPage0_t
))) {
1525 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1526 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1530 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1531 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1532 percent_complete
= raid_device
->percent_complete
;
1534 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1538 * _scsih_get_state - get raid volume level
1539 * @dev the device struct object
1542 _scsih_get_state(struct device
*dev
)
1544 struct scsi_device
*sdev
= to_scsi_device(dev
);
1545 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1546 static struct _raid_device
*raid_device
;
1547 unsigned long flags
;
1548 Mpi2RaidVolPage0_t vol_pg0
;
1549 Mpi2ConfigReply_t mpi_reply
;
1551 enum raid_state state
= RAID_STATE_UNKNOWN
;
1553 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1554 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1556 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1561 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1562 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1563 sizeof(Mpi2RaidVolPage0_t
))) {
1564 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1565 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1569 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1570 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1571 state
= RAID_STATE_RESYNCING
;
1575 switch (vol_pg0
.VolumeState
) {
1576 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1577 case MPI2_RAID_VOL_STATE_ONLINE
:
1578 state
= RAID_STATE_ACTIVE
;
1580 case MPI2_RAID_VOL_STATE_DEGRADED
:
1581 state
= RAID_STATE_DEGRADED
;
1583 case MPI2_RAID_VOL_STATE_FAILED
:
1584 case MPI2_RAID_VOL_STATE_MISSING
:
1585 state
= RAID_STATE_OFFLINE
;
1589 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1593 * _scsih_set_level - set raid level
1594 * @sdev: scsi device struct
1595 * @raid_device: raid_device object
1598 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1600 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1602 switch (raid_device
->volume_type
) {
1603 case MPI2_RAID_VOL_TYPE_RAID0
:
1604 level
= RAID_LEVEL_0
;
1606 case MPI2_RAID_VOL_TYPE_RAID10
:
1607 level
= RAID_LEVEL_10
;
1609 case MPI2_RAID_VOL_TYPE_RAID1E
:
1610 level
= RAID_LEVEL_1E
;
1612 case MPI2_RAID_VOL_TYPE_RAID1
:
1613 level
= RAID_LEVEL_1
;
1617 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1621 * _scsih_get_volume_capabilities - volume capabilities
1622 * @ioc: per adapter object
1623 * @sas_device: the raid_device object
1626 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1627 struct _raid_device
*raid_device
)
1629 Mpi2RaidVolPage0_t
*vol_pg0
;
1630 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1631 Mpi2SasDevicePage0_t sas_device_pg0
;
1632 Mpi2ConfigReply_t mpi_reply
;
1636 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1637 &num_pds
)) || !num_pds
) {
1638 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1639 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1643 raid_device
->num_pds
= num_pds
;
1644 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1645 sizeof(Mpi2RaidVol0PhysDisk_t
));
1646 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1648 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1649 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1653 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1654 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1655 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1656 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1661 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1663 /* figure out what the underlying devices are by
1664 * obtaining the device_info bits for the 1st device
1666 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1667 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1668 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1669 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1670 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1671 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1672 raid_device
->device_info
=
1673 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1680 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1681 * @ioc: per adapter object
1684 _scsih_disable_ddio(struct MPT2SAS_ADAPTER
*ioc
)
1686 Mpi2RaidVolPage1_t vol_pg1
;
1687 Mpi2ConfigReply_t mpi_reply
;
1688 struct _raid_device
*raid_device
;
1693 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1694 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1695 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1696 MPI2_IOCSTATUS_MASK
;
1697 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1699 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1700 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1702 raid_device
->direct_io_enabled
= 0;
1709 * _scsih_get_num_volumes - Get number of volumes in the ioc
1710 * @ioc: per adapter object
1713 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER
*ioc
)
1715 Mpi2RaidVolPage1_t vol_pg1
;
1716 Mpi2ConfigReply_t mpi_reply
;
1722 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1723 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1724 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1725 MPI2_IOCSTATUS_MASK
;
1726 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1729 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1736 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1737 * @ioc: per adapter object
1738 * @raid_device: the raid_device object
1741 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER
*ioc
,
1742 struct _raid_device
*raid_device
)
1744 Mpi2RaidVolPage0_t
*vol_pg0
;
1745 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1746 Mpi2ConfigReply_t mpi_reply
;
1749 u64 mb
= 1024 * 1024;
1750 u64 tb_2
= 2 * mb
* mb
;
1755 if (!ioc
->is_warpdrive
)
1758 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
) {
1759 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1760 "globally as drives are exposed\n", ioc
->name
);
1763 if (_scsih_get_num_volumes(ioc
) > 1) {
1764 _scsih_disable_ddio(ioc
);
1765 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1766 "globally as number of drives > 1\n", ioc
->name
);
1769 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1770 &num_pds
)) || !num_pds
) {
1771 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1772 "Failure in computing number of drives\n", ioc
->name
);
1776 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1777 sizeof(Mpi2RaidVol0PhysDisk_t
));
1778 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1780 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1781 "Memory allocation failure for RVPG0\n", ioc
->name
);
1785 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1786 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1787 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1788 "Failure in retrieving RVPG0\n", ioc
->name
);
1794 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1795 * assumed for WARPDRIVE, disable direct I/O
1797 if (num_pds
> MPT_MAX_WARPDRIVE_PDS
) {
1798 printk(MPT2SAS_WARN_FMT
"WarpDrive : Direct IO is disabled "
1799 "for the drive with handle(0x%04x): num_mem=%d, "
1800 "max_mem_allowed=%d\n", ioc
->name
, raid_device
->handle
,
1801 num_pds
, MPT_MAX_WARPDRIVE_PDS
);
1805 for (count
= 0; count
< num_pds
; count
++) {
1806 if (mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1807 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1808 vol_pg0
->PhysDisk
[count
].PhysDiskNum
) ||
1809 pd_pg0
.DevHandle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
1810 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1811 "disabled for the drive with handle(0x%04x) member"
1812 "handle retrieval failed for member number=%d\n",
1813 ioc
->name
, raid_device
->handle
,
1814 vol_pg0
->PhysDisk
[count
].PhysDiskNum
);
1817 raid_device
->pd_handle
[count
] = le16_to_cpu(pd_pg0
.DevHandle
);
1821 * Assumption for WD: Direct I/O is not supported if the volume is
1822 * not RAID0, if the stripe size is not 64KB, if the block size is
1823 * not 512 and if the volume size is >2TB
1825 if (raid_device
->volume_type
!= MPI2_RAID_VOL_TYPE_RAID0
||
1826 le16_to_cpu(vol_pg0
->BlockSize
) != 512) {
1827 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1828 "for the drive with handle(0x%04x): type=%d, "
1829 "s_sz=%uK, blk_size=%u\n", ioc
->name
,
1830 raid_device
->handle
, raid_device
->volume_type
,
1831 le32_to_cpu(vol_pg0
->StripeSize
)/2,
1832 le16_to_cpu(vol_pg0
->BlockSize
));
1836 capacity
= (u64
) le16_to_cpu(vol_pg0
->BlockSize
) *
1837 (le64_to_cpu(vol_pg0
->MaxLBA
) + 1);
1839 if (capacity
> tb_2
) {
1840 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1841 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1842 ioc
->name
, raid_device
->handle
);
1846 stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1848 for (i
= 0; i
< 32; i
++) {
1855 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1856 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1857 ioc
->name
, raid_device
->handle
,
1858 le32_to_cpu(vol_pg0
->StripeSize
)/2);
1861 raid_device
->stripe_exponent
= stripe_exp
;
1862 raid_device
->direct_io_enabled
= 1;
1864 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is Enabled for the drive"
1865 " with handle(0x%04x)\n", ioc
->name
, raid_device
->handle
);
1867 * WARPDRIVE: Though the following fields are not used for direct IO,
1868 * stored for future purpose:
1870 raid_device
->max_lba
= le64_to_cpu(vol_pg0
->MaxLBA
);
1871 raid_device
->stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1872 raid_device
->block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1879 raid_device
->direct_io_enabled
= 0;
1880 for (count
= 0; count
< num_pds
; count
++)
1881 raid_device
->pd_handle
[count
] = 0;
1887 * _scsih_enable_tlr - setting TLR flags
1888 * @ioc: per adapter object
1889 * @sdev: scsi device struct
1891 * Enabling Transaction Layer Retries for tape devices when
1892 * vpd page 0x90 is present
1896 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1899 if (sdev
->type
!= TYPE_TAPE
)
1902 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1905 sas_enable_tlr(sdev
);
1906 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1907 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1913 * _scsih_slave_configure - device configure routine.
1914 * @sdev: scsi device struct
1916 * Returns 0 if ok. Any other return is assumed to be an error and
1917 * the device is ignored.
1920 _scsih_slave_configure(struct scsi_device
*sdev
)
1922 struct Scsi_Host
*shost
= sdev
->host
;
1923 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1924 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1925 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1926 struct _sas_device
*sas_device
;
1927 struct _raid_device
*raid_device
;
1928 unsigned long flags
;
1935 sas_device_priv_data
= sdev
->hostdata
;
1936 sas_device_priv_data
->configured_lun
= 1;
1937 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1938 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1940 /* raid volume handling */
1941 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1943 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1944 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1945 sas_target_priv_data
->handle
);
1946 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1948 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1949 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1953 _scsih_get_volume_capabilities(ioc
, raid_device
);
1956 * WARPDRIVE: Initialize the required data for Direct IO
1958 _scsih_init_warpdrive_properties(ioc
, raid_device
);
1960 /* RAID Queue Depth Support
1961 * IS volume = underlying qdepth of drive type, either
1962 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1963 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1965 if (raid_device
->device_info
&
1966 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1967 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1970 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1971 if (raid_device
->device_info
&
1972 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1978 switch (raid_device
->volume_type
) {
1979 case MPI2_RAID_VOL_TYPE_RAID0
:
1982 case MPI2_RAID_VOL_TYPE_RAID1E
:
1983 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1984 if (ioc
->manu_pg10
.OEMIdentifier
&&
1985 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1986 MFG10_GF0_R10_DISPLAY
) &&
1987 !(raid_device
->num_pds
% 2))
1992 case MPI2_RAID_VOL_TYPE_RAID1
:
1993 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1996 case MPI2_RAID_VOL_TYPE_RAID10
:
1997 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2000 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2002 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2007 if (!ioc
->hide_ir_msg
)
2008 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2009 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2010 r_level
, raid_device
->handle
,
2011 (unsigned long long)raid_device
->wwid
,
2012 raid_device
->num_pds
, ds
);
2013 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2014 /* raid transport support */
2015 if (!ioc
->is_warpdrive
)
2016 _scsih_set_level(sdev
, raid_device
);
2020 /* non-raid handling */
2021 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2022 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2023 sas_device_priv_data
->sas_target
->sas_address
);
2024 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2026 if (sas_target_priv_data
->flags
&
2027 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2028 mpt2sas_config_get_volume_handle(ioc
,
2029 sas_device
->handle
, &sas_device
->volume_handle
);
2030 mpt2sas_config_get_volume_wwid(ioc
,
2031 sas_device
->volume_handle
,
2032 &sas_device
->volume_wwid
);
2034 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2035 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2039 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2040 if (sas_device
->device_info
&
2041 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2043 else if (sas_device
->device_info
&
2044 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2048 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2049 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2050 ds
, sas_device
->handle
,
2051 (unsigned long long)sas_device
->sas_address
,
2053 (unsigned long long)sas_device
->device_name
);
2054 sdev_printk(KERN_INFO
, sdev
, "%s: "
2055 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
2056 (unsigned long long) sas_device
->enclosure_logical_id
,
2060 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
2063 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2066 sas_read_port_mode_page(sdev
);
2067 _scsih_enable_tlr(ioc
, sdev
);
2073 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2074 * @sdev: scsi device struct
2075 * @bdev: pointer to block device context
2076 * @capacity: device size (in 512 byte sectors)
2077 * @params: three element array to place output:
2078 * params[0] number of heads (max 255)
2079 * params[1] number of sectors (max 63)
2080 * params[2] number of cylinders
2085 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2086 sector_t capacity
, int params
[])
2096 dummy
= heads
* sectors
;
2097 cylinders
= capacity
;
2098 sector_div(cylinders
, dummy
);
2101 * Handle extended translation size for logical drives
2104 if ((ulong
)capacity
>= 0x200000) {
2107 dummy
= heads
* sectors
;
2108 cylinders
= capacity
;
2109 sector_div(cylinders
, dummy
);
2114 params
[1] = sectors
;
2115 params
[2] = cylinders
;
2121 * _scsih_response_code - translation of device response code
2122 * @ioc: per adapter object
2123 * @response_code: response code returned by the device
2128 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
2132 switch (response_code
) {
2133 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2134 desc
= "task management request completed";
2136 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2137 desc
= "invalid frame";
2139 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2140 desc
= "task management request not supported";
2142 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2143 desc
= "task management request failed";
2145 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2146 desc
= "task management request succeeded";
2148 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2149 desc
= "invalid lun";
2152 desc
= "overlapped tag attempted";
2154 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2155 desc
= "task queued, however not sent to target";
2161 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
2162 ioc
->name
, response_code
, desc
);
2166 * _scsih_tm_done - tm completion routine
2167 * @ioc: per adapter object
2168 * @smid: system request message index
2169 * @msix_index: MSIX table index supplied by the OS
2170 * @reply: reply message frame(lower 32bit addr)
2173 * The callback handler when using scsih_issue_tm.
2175 * Return 1 meaning mf should be freed from _base_interrupt
2176 * 0 means the mf is freed from this function.
2179 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2181 MPI2DefaultReply_t
*mpi_reply
;
2183 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
2185 if (ioc
->tm_cmds
.smid
!= smid
)
2187 mpt2sas_base_flush_reply_queues(ioc
);
2188 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
2189 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2191 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2192 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
2194 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
2195 complete(&ioc
->tm_cmds
.done
);
2200 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2201 * @ioc: per adapter object
2202 * @handle: device handle
2204 * During taskmangement request, we need to freeze the device queue.
2207 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2209 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2210 struct scsi_device
*sdev
;
2213 shost_for_each_device(sdev
, ioc
->shost
) {
2216 sas_device_priv_data
= sdev
->hostdata
;
2217 if (!sas_device_priv_data
)
2219 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2220 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2222 ioc
->ignore_loginfos
= 1;
2228 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2229 * @ioc: per adapter object
2230 * @handle: device handle
2232 * During taskmangement request, we need to freeze the device queue.
2235 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2237 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2238 struct scsi_device
*sdev
;
2241 shost_for_each_device(sdev
, ioc
->shost
) {
2244 sas_device_priv_data
= sdev
->hostdata
;
2245 if (!sas_device_priv_data
)
2247 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2248 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2250 ioc
->ignore_loginfos
= 0;
2257 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2258 * @ioc: per adapter struct
2259 * @device_handle: device handle
2260 * @channel: the channel assigned by the OS
2261 * @id: the id assigned by the OS
2263 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2264 * @smid_task: smid assigned to the task
2265 * @timeout: timeout in seconds
2266 * @serial_number: the serial_number from scmd
2267 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2270 * A generic API for sending task management requests to firmware.
2272 * The callback index is set inside `ioc->tm_cb_idx`.
2274 * Return SUCCESS or FAILED.
2277 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2278 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2279 unsigned long serial_number
, enum mutex_type m_type
)
2281 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2282 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2285 unsigned long timeleft
;
2286 struct scsiio_tracker
*scsi_lookup
= NULL
;
2289 if (m_type
== TM_MUTEX_ON
)
2290 mutex_lock(&ioc
->tm_cmds
.mutex
);
2291 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2292 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2293 __func__
, ioc
->name
);
2298 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2299 ioc
->pci_error_recovery
) {
2300 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2301 __func__
, ioc
->name
);
2306 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2307 if (ioc_state
& MPI2_DOORBELL_USED
) {
2308 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2309 "active!\n", ioc
->name
));
2310 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2312 rc
= (!rc
) ? SUCCESS
: FAILED
;
2316 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2317 mpt2sas_base_fault_info(ioc
, ioc_state
&
2318 MPI2_DOORBELL_DATA_MASK
);
2319 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2321 rc
= (!rc
) ? SUCCESS
: FAILED
;
2325 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2327 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2328 ioc
->name
, __func__
);
2333 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2334 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2336 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2337 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2339 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2340 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2341 ioc
->tm_cmds
.smid
= smid
;
2342 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2343 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2344 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2345 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2346 mpi_request
->TaskType
= type
;
2347 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2348 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2349 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2350 init_completion(&ioc
->tm_cmds
.done
);
2351 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2352 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2353 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2354 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2355 ioc
->name
, __func__
);
2356 _debug_dump_mf(mpi_request
,
2357 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2358 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2359 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2361 rc
= (!rc
) ? SUCCESS
: FAILED
;
2362 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2363 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2368 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2369 mpi_reply
= ioc
->tm_cmds
.reply
;
2370 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2371 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2372 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2373 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2374 le32_to_cpu(mpi_reply
->TerminationCount
)));
2375 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2376 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2377 if (mpi_reply
->IOCStatus
)
2378 _debug_dump_mf(mpi_request
,
2379 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2384 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2386 if (scsi_lookup
->scmd
== NULL
)
2391 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2392 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2398 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2399 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2400 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2405 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2413 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2414 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2415 if (m_type
== TM_MUTEX_ON
)
2416 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2421 if (m_type
== TM_MUTEX_ON
)
2422 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2427 * _scsih_tm_display_info - displays info about the device
2428 * @ioc: per adapter struct
2429 * @scmd: pointer to scsi command object
2431 * Called by task management callback handlers.
2434 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2436 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2437 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2438 struct _sas_device
*sas_device
= NULL
;
2439 unsigned long flags
;
2440 char *device_str
= NULL
;
2444 if (ioc
->hide_ir_msg
)
2445 device_str
= "WarpDrive";
2447 device_str
= "volume";
2449 scsi_print_command(scmd
);
2450 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2451 starget_printk(KERN_INFO
, starget
, "%s handle(0x%04x), "
2452 "%s wwid(0x%016llx)\n", device_str
, priv_target
->handle
,
2453 device_str
, (unsigned long long)priv_target
->sas_address
);
2455 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2456 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2457 priv_target
->sas_address
);
2459 if (priv_target
->flags
&
2460 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2461 starget_printk(KERN_INFO
, starget
,
2462 "volume handle(0x%04x), "
2463 "volume wwid(0x%016llx)\n",
2464 sas_device
->volume_handle
,
2465 (unsigned long long)sas_device
->volume_wwid
);
2467 starget_printk(KERN_INFO
, starget
,
2468 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2470 (unsigned long long)sas_device
->sas_address
,
2472 starget_printk(KERN_INFO
, starget
,
2473 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2474 (unsigned long long)sas_device
->enclosure_logical_id
,
2477 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2482 * _scsih_abort - eh threads main abort routine
2483 * @scmd: pointer to scsi command object
2485 * Returns SUCCESS if command aborted else FAILED
2488 _scsih_abort(struct scsi_cmnd
*scmd
)
2490 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2491 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2496 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2497 "scmd(%p)\n", scmd
);
2498 _scsih_tm_display_info(ioc
, scmd
);
2500 sas_device_priv_data
= scmd
->device
->hostdata
;
2501 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2502 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2503 "scmd(%p)\n", scmd
);
2504 scmd
->result
= DID_NO_CONNECT
<< 16;
2505 scmd
->scsi_done(scmd
);
2510 /* search for the command */
2511 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2513 scmd
->result
= DID_RESET
<< 16;
2518 /* for hidden raid components and volumes this is not supported */
2519 if (sas_device_priv_data
->sas_target
->flags
&
2520 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2521 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2522 scmd
->result
= DID_RESET
<< 16;
2527 mpt2sas_halt_firmware(ioc
);
2529 handle
= sas_device_priv_data
->sas_target
->handle
;
2530 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2531 scmd
->device
->id
, scmd
->device
->lun
,
2532 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
2533 scmd
->serial_number
, TM_MUTEX_ON
);
2536 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2537 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2542 * _scsih_dev_reset - eh threads main device reset routine
2543 * @scmd: pointer to scsi command object
2545 * Returns SUCCESS if command aborted else FAILED
2548 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2550 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2551 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2552 struct _sas_device
*sas_device
;
2553 unsigned long flags
;
2557 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2559 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2560 "scmd(%p)\n", scmd
);
2561 _scsih_tm_display_info(ioc
, scmd
);
2563 sas_device_priv_data
= scmd
->device
->hostdata
;
2564 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2565 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2566 "scmd(%p)\n", scmd
);
2567 scmd
->result
= DID_NO_CONNECT
<< 16;
2568 scmd
->scsi_done(scmd
);
2573 /* for hidden raid components obtain the volume_handle */
2575 if (sas_device_priv_data
->sas_target
->flags
&
2576 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2577 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2578 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2579 sas_device_priv_data
->sas_target
->handle
);
2581 handle
= sas_device
->volume_handle
;
2582 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2584 handle
= sas_device_priv_data
->sas_target
->handle
;
2587 scmd
->result
= DID_RESET
<< 16;
2592 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2593 scmd
->device
->id
, scmd
->device
->lun
,
2594 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, 0,
2598 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2599 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2604 * _scsih_target_reset - eh threads main target reset routine
2605 * @scmd: pointer to scsi command object
2607 * Returns SUCCESS if command aborted else FAILED
2610 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2612 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2613 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2614 struct _sas_device
*sas_device
;
2615 unsigned long flags
;
2618 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2620 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2621 "scmd(%p)\n", scmd
);
2622 _scsih_tm_display_info(ioc
, scmd
);
2624 sas_device_priv_data
= scmd
->device
->hostdata
;
2625 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2626 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2627 "scmd(%p)\n", scmd
);
2628 scmd
->result
= DID_NO_CONNECT
<< 16;
2629 scmd
->scsi_done(scmd
);
2634 /* for hidden raid components obtain the volume_handle */
2636 if (sas_device_priv_data
->sas_target
->flags
&
2637 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2638 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2639 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2640 sas_device_priv_data
->sas_target
->handle
);
2642 handle
= sas_device
->volume_handle
;
2643 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2645 handle
= sas_device_priv_data
->sas_target
->handle
;
2648 scmd
->result
= DID_RESET
<< 16;
2653 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2654 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2655 30, 0, TM_MUTEX_ON
);
2658 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2659 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2664 * _scsih_host_reset - eh threads main host reset routine
2665 * @scmd: pointer to scsi command object
2667 * Returns SUCCESS if command aborted else FAILED
2670 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2672 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2675 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2677 scsi_print_command(scmd
);
2679 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2681 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2682 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2683 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2689 * _scsih_fw_event_add - insert and queue up fw_event
2690 * @ioc: per adapter object
2691 * @fw_event: object describing the event
2692 * Context: This function will acquire ioc->fw_event_lock.
2694 * This adds the firmware event object into link list, then queues it up to
2695 * be processed from user context.
2700 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2702 unsigned long flags
;
2704 if (ioc
->firmware_event_thread
== NULL
)
2707 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2708 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2709 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2710 queue_delayed_work(ioc
->firmware_event_thread
,
2711 &fw_event
->delayed_work
, 0);
2712 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2716 * _scsih_fw_event_free - delete fw_event
2717 * @ioc: per adapter object
2718 * @fw_event: object describing the event
2719 * Context: This function will acquire ioc->fw_event_lock.
2721 * This removes firmware event object from link list, frees associated memory.
2726 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2729 unsigned long flags
;
2731 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2732 list_del(&fw_event
->list
);
2733 kfree(fw_event
->event_data
);
2735 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2740 * _scsih_error_recovery_delete_devices - remove devices not responding
2741 * @ioc: per adapter object
2746 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER
*ioc
)
2748 struct fw_event_work
*fw_event
;
2750 if (ioc
->is_driver_loading
)
2752 fw_event
->event
= MPT2SAS_REMOVE_UNRESPONDING_DEVICES
;
2753 fw_event
->ioc
= ioc
;
2754 _scsih_fw_event_add(ioc
, fw_event
);
2758 * mpt2sas_port_enable_complete - port enable completed (fake event)
2759 * @ioc: per adapter object
2764 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER
*ioc
)
2766 struct fw_event_work
*fw_event
;
2768 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2771 fw_event
->event
= MPT2SAS_PORT_ENABLE_COMPLETE
;
2772 fw_event
->ioc
= ioc
;
2773 _scsih_fw_event_add(ioc
, fw_event
);
2777 * _scsih_fw_event_cleanup_queue - cleanup event queue
2778 * @ioc: per adapter object
2780 * Walk the firmware event queue, either killing timers, or waiting
2781 * for outstanding events to complete
2786 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2788 struct fw_event_work
*fw_event
, *next
;
2790 if (list_empty(&ioc
->fw_event_list
) ||
2791 !ioc
->firmware_event_thread
|| in_interrupt())
2794 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2795 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2796 _scsih_fw_event_free(ioc
, fw_event
);
2799 fw_event
->cancel_pending_work
= 1;
2804 * _scsih_ublock_io_all_device - unblock every device
2805 * @ioc: per adapter object
2807 * change the device state from block to running
2810 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2812 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2813 struct scsi_device
*sdev
;
2815 shost_for_each_device(sdev
, ioc
->shost
) {
2816 sas_device_priv_data
= sdev
->hostdata
;
2817 if (!sas_device_priv_data
)
2819 if (!sas_device_priv_data
->block
)
2821 sas_device_priv_data
->block
= 0;
2822 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_running, "
2824 sas_device_priv_data
->sas_target
->handle
));
2825 scsi_internal_device_unblock(sdev
);
2829 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2830 * @ioc: per adapter object
2831 * @handle: device handle
2833 * During device pull we need to appropiately set the sdev state.
2836 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2838 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2839 struct scsi_device
*sdev
;
2841 shost_for_each_device(sdev
, ioc
->shost
) {
2842 sas_device_priv_data
= sdev
->hostdata
;
2843 if (!sas_device_priv_data
)
2845 if (!sas_device_priv_data
->block
)
2847 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2848 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2849 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2850 "handle(0x%04x)\n", ioc
->name
, handle
));
2851 sas_device_priv_data
->block
= 0;
2852 scsi_internal_device_unblock(sdev
);
2858 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2859 * @ioc: per adapter object
2860 * @handle: device handle
2862 * During device pull we need to appropiately set the sdev state.
2865 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2867 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2868 struct scsi_device
*sdev
;
2870 shost_for_each_device(sdev
, ioc
->shost
) {
2871 sas_device_priv_data
= sdev
->hostdata
;
2872 if (!sas_device_priv_data
)
2874 if (sas_device_priv_data
->block
)
2876 sas_device_priv_data
->block
= 1;
2877 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_blocked, "
2879 sas_device_priv_data
->sas_target
->handle
));
2880 scsi_internal_device_block(sdev
);
2886 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2887 * @ioc: per adapter object
2888 * @handle: device handle
2890 * During device pull we need to appropiately set the sdev state.
2893 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2895 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2896 struct scsi_device
*sdev
;
2898 shost_for_each_device(sdev
, ioc
->shost
) {
2899 sas_device_priv_data
= sdev
->hostdata
;
2900 if (!sas_device_priv_data
)
2902 if (sas_device_priv_data
->block
)
2904 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2905 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2906 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2907 "handle(0x%04x)\n", ioc
->name
, handle
));
2908 sas_device_priv_data
->block
= 1;
2909 scsi_internal_device_block(sdev
);
2915 * _scsih_block_io_to_children_attached_to_ex
2916 * @ioc: per adapter object
2917 * @sas_expander: the sas_device object
2919 * This routine set sdev state to SDEV_BLOCK for all devices
2920 * attached to this expander. This function called when expander is
2924 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2925 struct _sas_node
*sas_expander
)
2927 struct _sas_port
*mpt2sas_port
;
2928 struct _sas_device
*sas_device
;
2929 struct _sas_node
*expander_sibling
;
2930 unsigned long flags
;
2935 list_for_each_entry(mpt2sas_port
,
2936 &sas_expander
->sas_port_list
, port_list
) {
2937 if (mpt2sas_port
->remote_identify
.device_type
==
2939 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2941 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2942 mpt2sas_port
->remote_identify
.sas_address
);
2943 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2946 _scsih_block_io_device(ioc
, sas_device
->handle
);
2950 list_for_each_entry(mpt2sas_port
,
2951 &sas_expander
->sas_port_list
, port_list
) {
2953 if (mpt2sas_port
->remote_identify
.device_type
==
2954 SAS_EDGE_EXPANDER_DEVICE
||
2955 mpt2sas_port
->remote_identify
.device_type
==
2956 SAS_FANOUT_EXPANDER_DEVICE
) {
2958 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2960 mpt2sas_scsih_expander_find_by_sas_address(
2961 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2962 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2963 _scsih_block_io_to_children_attached_to_ex(ioc
,
2970 * _scsih_block_io_to_children_attached_directly
2971 * @ioc: per adapter object
2972 * @event_data: topology change event data
2974 * This routine set sdev state to SDEV_BLOCK for all devices
2975 * direct attached during device pull.
2978 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
2979 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
2986 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
2987 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
2990 phy_number
= event_data
->StartPhyNum
+ i
;
2991 reason_code
= event_data
->PHY
[i
].PhyStatus
&
2992 MPI2_EVENT_SAS_TOPO_RC_MASK
;
2993 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
2994 _scsih_block_io_device(ioc
, handle
);
2999 * _scsih_tm_tr_send - send task management request
3000 * @ioc: per adapter object
3001 * @handle: device handle
3002 * Context: interrupt time.
3004 * This code is to initiate the device removal handshake protocol
3005 * with controller firmware. This function will issue target reset
3006 * using high priority request queue. It will send a sas iounit
3007 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3009 * This is designed to send muliple task management request at the same
3010 * time to the fifo. If the fifo is full, we will append the request,
3011 * and process it in a future completion.
3014 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3016 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3018 struct _sas_device
*sas_device
;
3019 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
3020 u64 sas_address
= 0;
3021 unsigned long flags
;
3022 struct _tr_list
*delayed_tr
;
3025 if (ioc
->remove_host
) {
3026 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3027 "removed: handle(0x%04x)\n", __func__
, ioc
->name
, handle
));
3029 } else if (ioc
->pci_error_recovery
) {
3030 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3031 "error recovery: handle(0x%04x)\n", __func__
, ioc
->name
,
3035 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3036 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3037 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3038 "operational: handle(0x%04x)\n", __func__
, ioc
->name
,
3043 /* if PD, then return */
3044 if (test_bit(handle
, ioc
->pd_handles
))
3047 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3048 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3049 if (sas_device
&& sas_device
->starget
&&
3050 sas_device
->starget
->hostdata
) {
3051 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3052 sas_target_priv_data
->deleted
= 1;
3053 sas_address
= sas_device
->sas_address
;
3055 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3057 if (sas_target_priv_data
) {
3058 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"setting delete flag: "
3059 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, handle
,
3060 (unsigned long long)sas_address
));
3061 _scsih_ublock_io_device(ioc
, handle
);
3062 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
3065 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3067 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3070 INIT_LIST_HEAD(&delayed_tr
->list
);
3071 delayed_tr
->handle
= handle
;
3072 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3073 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3074 "DELAYED:tr:handle(0x%04x), (open)\n",
3075 ioc
->name
, handle
));
3079 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3080 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3081 ioc
->tm_tr_cb_idx
));
3082 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3083 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3084 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3085 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3086 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3087 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3093 * _scsih_sas_control_complete - completion routine
3094 * @ioc: per adapter object
3095 * @smid: system request message index
3096 * @msix_index: MSIX table index supplied by the OS
3097 * @reply: reply message frame(lower 32bit addr)
3098 * Context: interrupt time.
3100 * This is the sas iounit control completion routine.
3101 * This code is part of the code to initiate the device removal
3102 * handshake protocol with controller firmware.
3104 * Return 1 meaning mf should be freed from _base_interrupt
3105 * 0 means the mf is freed from this function.
3108 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3109 u8 msix_index
, u32 reply
)
3111 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3112 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3113 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3115 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3116 "sc_complete:handle(0x%04x), (open) "
3117 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3118 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3119 le16_to_cpu(mpi_reply
->IOCStatus
),
3120 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3125 * _scsih_tm_tr_volume_send - send target reset request for volumes
3126 * @ioc: per adapter object
3127 * @handle: device handle
3128 * Context: interrupt time.
3130 * This is designed to send muliple task management request at the same
3131 * time to the fifo. If the fifo is full, we will append the request,
3132 * and process it in a future completion.
3135 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3137 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3139 struct _tr_list
*delayed_tr
;
3141 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3142 ioc
->pci_error_recovery
) {
3143 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3144 "progress!\n", __func__
, ioc
->name
));
3148 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3150 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3153 INIT_LIST_HEAD(&delayed_tr
->list
);
3154 delayed_tr
->handle
= handle
;
3155 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3156 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3157 "DELAYED:tr:handle(0x%04x), (open)\n",
3158 ioc
->name
, handle
));
3162 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3163 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3164 ioc
->tm_tr_volume_cb_idx
));
3165 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3166 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3167 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3168 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3169 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3170 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3174 * _scsih_tm_volume_tr_complete - target reset completion
3175 * @ioc: per adapter object
3176 * @smid: system request message index
3177 * @msix_index: MSIX table index supplied by the OS
3178 * @reply: reply message frame(lower 32bit addr)
3179 * Context: interrupt time.
3181 * Return 1 meaning mf should be freed from _base_interrupt
3182 * 0 means the mf is freed from this function.
3185 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3186 u8 msix_index
, u32 reply
)
3189 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3190 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3191 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3193 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3194 ioc
->pci_error_recovery
) {
3195 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3196 "progress!\n", __func__
, ioc
->name
));
3200 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3201 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3202 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3203 dewtprintk(ioc
, printk("spurious interrupt: "
3204 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
3205 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3209 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3210 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3211 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3212 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3213 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3214 le32_to_cpu(mpi_reply
->TerminationCount
)));
3216 return _scsih_check_for_pending_tm(ioc
, smid
);
3220 * _scsih_tm_tr_complete -
3221 * @ioc: per adapter object
3222 * @smid: system request message index
3223 * @msix_index: MSIX table index supplied by the OS
3224 * @reply: reply message frame(lower 32bit addr)
3225 * Context: interrupt time.
3227 * This is the target reset completion routine.
3228 * This code is part of the code to initiate the device removal
3229 * handshake protocol with controller firmware.
3230 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3232 * Return 1 meaning mf should be freed from _base_interrupt
3233 * 0 means the mf is freed from this function.
3236 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3240 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3241 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3242 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3243 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3247 if (ioc
->remove_host
) {
3248 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3249 "removed\n", __func__
, ioc
->name
));
3251 } else if (ioc
->pci_error_recovery
) {
3252 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3253 "error recovery\n", __func__
, ioc
->name
));
3256 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3257 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3258 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3259 "operational\n", __func__
, ioc
->name
));
3263 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3264 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3265 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3266 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
3267 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
3268 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3272 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3273 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3274 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3275 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3276 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3277 le32_to_cpu(mpi_reply
->TerminationCount
)));
3279 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3280 if (!smid_sas_ctrl
) {
3281 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3282 ioc
->name
, __func__
);
3286 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
3287 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
3288 ioc
->tm_sas_control_cb_idx
));
3289 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3290 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3291 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3292 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3293 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3294 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3296 return _scsih_check_for_pending_tm(ioc
, smid
);
3300 * _scsih_check_for_pending_tm - check for pending task management
3301 * @ioc: per adapter object
3302 * @smid: system request message index
3304 * This will check delayed target reset list, and feed the
3307 * Return 1 meaning mf should be freed from _base_interrupt
3308 * 0 means the mf is freed from this function.
3311 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3313 struct _tr_list
*delayed_tr
;
3315 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3316 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3317 struct _tr_list
, list
);
3318 mpt2sas_base_free_smid(ioc
, smid
);
3319 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3320 list_del(&delayed_tr
->list
);
3325 if (!list_empty(&ioc
->delayed_tr_list
)) {
3326 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3327 struct _tr_list
, list
);
3328 mpt2sas_base_free_smid(ioc
, smid
);
3329 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3330 list_del(&delayed_tr
->list
);
3339 * _scsih_check_topo_delete_events - sanity check on topo events
3340 * @ioc: per adapter object
3341 * @event_data: the event data payload
3343 * This routine added to better handle cable breaker.
3345 * This handles the case where driver receives multiple expander
3346 * add and delete events in a single shot. When there is a delete event
3347 * the routine will void any pending add events waiting in the event queue.
3352 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3353 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3355 struct fw_event_work
*fw_event
;
3356 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3357 u16 expander_handle
;
3358 struct _sas_node
*sas_expander
;
3359 unsigned long flags
;
3363 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3364 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3367 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3368 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3369 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3370 _scsih_tm_tr_send(ioc
, handle
);
3373 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3374 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3375 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3379 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3380 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
3381 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3382 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3384 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3385 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3386 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3387 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3389 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3392 /* mark ignore flag for pending events */
3393 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3394 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3395 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3398 local_event_data
= fw_event
->event_data
;
3399 if (local_event_data
->ExpStatus
==
3400 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3401 local_event_data
->ExpStatus
==
3402 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3403 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3405 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3406 "setting ignoring flag\n", ioc
->name
));
3407 fw_event
->ignore
= 1;
3411 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3415 * _scsih_set_volume_delete_flag - setting volume delete flag
3416 * @ioc: per adapter object
3417 * @handle: device handle
3423 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3425 struct _raid_device
*raid_device
;
3426 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3427 unsigned long flags
;
3429 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3430 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3431 if (raid_device
&& raid_device
->starget
&&
3432 raid_device
->starget
->hostdata
) {
3433 sas_target_priv_data
=
3434 raid_device
->starget
->hostdata
;
3435 sas_target_priv_data
->deleted
= 1;
3436 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3437 "setting delete flag: handle(0x%04x), "
3438 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3439 (unsigned long long) raid_device
->wwid
));
3441 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3445 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3446 * @handle: input handle
3447 * @a: handle for volume a
3448 * @b: handle for volume b
3450 * IR firmware only supports two raid volumes. The purpose of this
3451 * routine is to set the volume handle in either a or b. When the given
3452 * input handle is non-zero, or when a and b have not been set before.
3455 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3457 if (!handle
|| handle
== *a
|| handle
== *b
)
3466 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3467 * @ioc: per adapter object
3468 * @event_data: the event data payload
3469 * Context: interrupt time.
3471 * This routine will send target reset to volume, followed by target
3472 * resets to the PDs. This is called when a PD has been removed, or
3473 * volume has been deleted or removed. When the target reset is sent
3474 * to volume, the PD target resets need to be queued to start upon
3475 * completion of the volume target reset.
3480 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3481 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3483 Mpi2EventIrConfigElement_t
*element
;
3485 u16 handle
, volume_handle
, a
, b
;
3486 struct _tr_list
*delayed_tr
;
3491 if (ioc
->is_warpdrive
)
3494 /* Volume Resets for Deleted or Removed */
3495 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3496 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3497 if (element
->ReasonCode
==
3498 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3499 element
->ReasonCode
==
3500 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3501 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3502 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3503 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3507 /* Volume Resets for UNHIDE events */
3508 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3509 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3510 if (le32_to_cpu(event_data
->Flags
) &
3511 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3513 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3514 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3515 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3520 _scsih_tm_tr_volume_send(ioc
, a
);
3522 _scsih_tm_tr_volume_send(ioc
, b
);
3524 /* PD target resets */
3525 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3526 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3527 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3529 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3530 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3531 clear_bit(handle
, ioc
->pd_handles
);
3533 _scsih_tm_tr_send(ioc
, handle
);
3534 else if (volume_handle
== a
|| volume_handle
== b
) {
3535 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3536 BUG_ON(!delayed_tr
);
3537 INIT_LIST_HEAD(&delayed_tr
->list
);
3538 delayed_tr
->handle
= handle
;
3539 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3540 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3541 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3544 _scsih_tm_tr_send(ioc
, handle
);
3550 * _scsih_check_volume_delete_events - set delete flag for volumes
3551 * @ioc: per adapter object
3552 * @event_data: the event data payload
3553 * Context: interrupt time.
3555 * This will handle the case when the cable connected to entire volume is
3556 * pulled. We will take care of setting the deleted flag so normal IO will
3562 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3563 Mpi2EventDataIrVolume_t
*event_data
)
3567 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3569 state
= le32_to_cpu(event_data
->NewValue
);
3570 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3571 MPI2_RAID_VOL_STATE_FAILED
)
3572 _scsih_set_volume_delete_flag(ioc
,
3573 le16_to_cpu(event_data
->VolDevHandle
));
3577 * _scsih_flush_running_cmds - completing outstanding commands.
3578 * @ioc: per adapter object
3580 * The flushing out of all pending scmd commands following host reset,
3581 * where all IO is dropped to the floor.
3586 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3588 struct scsi_cmnd
*scmd
;
3592 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3593 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3597 mpt2sas_base_free_smid(ioc
, smid
);
3598 scsi_dma_unmap(scmd
);
3599 if (ioc
->pci_error_recovery
)
3600 scmd
->result
= DID_NO_CONNECT
<< 16;
3602 scmd
->result
= DID_RESET
<< 16;
3603 scmd
->scsi_done(scmd
);
3605 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3610 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3611 * @scmd: pointer to scsi command object
3612 * @mpi_request: pointer to the SCSI_IO reqest message frame
3614 * Supporting protection 1 and 3.
3619 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3622 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3623 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3625 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3628 if (prot_op
== SCSI_PROT_READ_STRIP
)
3629 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3630 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3631 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3635 switch (prot_type
) {
3636 case SCSI_PROT_DIF_TYPE1
:
3637 case SCSI_PROT_DIF_TYPE2
:
3640 * enable ref/guard checking
3641 * auto increment ref tag
3643 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3644 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3645 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3646 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3647 cpu_to_be32(scsi_get_lba(scmd
));
3650 case SCSI_PROT_DIF_TYPE3
:
3653 * enable guard checking
3655 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3658 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3659 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3663 * _scsih_eedp_error_handling - return sense code for EEDP errors
3664 * @scmd: pointer to scsi command object
3665 * @ioc_status: ioc status
3670 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3676 switch (ioc_status
) {
3677 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3680 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3683 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3691 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3692 sk
= ILLEGAL_REQUEST
;
3693 host_byte
= DID_ABORT
;
3695 sk
= ABORTED_COMMAND
;
3699 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3700 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3701 SAM_STAT_CHECK_CONDITION
;
3705 * _scsih_scsi_direct_io_get - returns direct io flag
3706 * @ioc: per adapter object
3707 * @smid: system request message index
3709 * Returns the smid stored scmd pointer.
3712 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3714 return ioc
->scsi_lookup
[smid
- 1].direct_io
;
3718 * _scsih_scsi_direct_io_set - sets direct io flag
3719 * @ioc: per adapter object
3720 * @smid: system request message index
3721 * @direct_io: Zero or non-zero value to set in the direct_io flag
3726 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 direct_io
)
3728 ioc
->scsi_lookup
[smid
- 1].direct_io
= direct_io
;
3733 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3734 * @ioc: per adapter object
3735 * @scmd: pointer to scsi command object
3736 * @raid_device: pointer to raid device data structure
3737 * @mpi_request: pointer to the SCSI_IO reqest message frame
3738 * @smid: system request message index
3743 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3744 struct _raid_device
*raid_device
, Mpi2SCSIIORequest_t
*mpi_request
,
3747 u32 v_lba
, p_lba
, stripe_off
, stripe_unit
, column
, io_size
;
3748 u32 stripe_sz
, stripe_exp
;
3749 u8 num_pds
, *cdb_ptr
, *tmp_ptr
, *lba_ptr1
, *lba_ptr2
;
3750 u8 cdb0
= scmd
->cmnd
[0];
3753 * Try Direct I/O to RAID memeber disks
3755 if (cdb0
== READ_16
|| cdb0
== READ_10
||
3756 cdb0
== WRITE_16
|| cdb0
== WRITE_10
) {
3757 cdb_ptr
= mpi_request
->CDB
.CDB32
;
3759 if ((cdb0
< READ_16
) || !(cdb_ptr
[2] | cdb_ptr
[3] | cdb_ptr
[4]
3761 io_size
= scsi_bufflen(scmd
) >> 9;
3762 /* get virtual lba */
3763 lba_ptr1
= lba_ptr2
= (cdb0
< READ_16
) ? &cdb_ptr
[2] :
3765 tmp_ptr
= (u8
*)&v_lba
+ 3;
3766 *tmp_ptr
-- = *lba_ptr1
++;
3767 *tmp_ptr
-- = *lba_ptr1
++;
3768 *tmp_ptr
-- = *lba_ptr1
++;
3769 *tmp_ptr
= *lba_ptr1
;
3771 if (((u64
)v_lba
+ (u64
)io_size
- 1) <=
3772 (u32
)raid_device
->max_lba
) {
3773 stripe_sz
= raid_device
->stripe_sz
;
3774 stripe_exp
= raid_device
->stripe_exponent
;
3775 stripe_off
= v_lba
& (stripe_sz
- 1);
3777 /* Check whether IO falls within a stripe */
3778 if ((stripe_off
+ io_size
) <= stripe_sz
) {
3779 num_pds
= raid_device
->num_pds
;
3780 p_lba
= v_lba
>> stripe_exp
;
3781 stripe_unit
= p_lba
/ num_pds
;
3782 column
= p_lba
% num_pds
;
3783 p_lba
= (stripe_unit
<< stripe_exp
) +
3785 mpi_request
->DevHandle
=
3786 cpu_to_le16(raid_device
->
3788 tmp_ptr
= (u8
*)&p_lba
+ 3;
3789 *lba_ptr2
++ = *tmp_ptr
--;
3790 *lba_ptr2
++ = *tmp_ptr
--;
3791 *lba_ptr2
++ = *tmp_ptr
--;
3792 *lba_ptr2
= *tmp_ptr
;
3794 * WD: To indicate this I/O is directI/O
3796 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3804 * _scsih_qcmd - main scsi request entry point
3805 * @scmd: pointer to scsi command object
3806 * @done: function pointer to be invoked on completion
3808 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3810 * Returns 0 on success. If there's a failure, return either:
3811 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3812 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3815 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3817 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3818 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3819 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3820 struct _raid_device
*raid_device
;
3821 Mpi2SCSIIORequest_t
*mpi_request
;
3825 scmd
->scsi_done
= done
;
3826 sas_device_priv_data
= scmd
->device
->hostdata
;
3827 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3828 scmd
->result
= DID_NO_CONNECT
<< 16;
3829 scmd
->scsi_done(scmd
);
3833 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3834 scmd
->result
= DID_NO_CONNECT
<< 16;
3835 scmd
->scsi_done(scmd
);
3839 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3840 /* invalid device handle */
3841 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3842 scmd
->result
= DID_NO_CONNECT
<< 16;
3843 scmd
->scsi_done(scmd
);
3847 /* host recovery or link resets sent via IOCTLs */
3848 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3849 return SCSI_MLQUEUE_HOST_BUSY
;
3850 /* device busy with task management */
3851 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3852 return SCSI_MLQUEUE_DEVICE_BUSY
;
3853 /* device has been deleted */
3854 else if (sas_target_priv_data
->deleted
) {
3855 scmd
->result
= DID_NO_CONNECT
<< 16;
3856 scmd
->scsi_done(scmd
);
3860 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3861 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3862 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3863 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3865 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3868 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3869 if (scmd
->device
->tagged_supported
) {
3870 if (scmd
->device
->ordered_tags
)
3871 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3873 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3875 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3876 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3878 mpi_control
|= (0x500);
3881 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3882 /* Make sure Device is not raid volume.
3883 * We do not expose raid functionality to upper layer for warpdrive.
3885 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3886 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3887 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3889 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3891 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3892 ioc
->name
, __func__
);
3895 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3896 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3897 _scsih_setup_eedp(scmd
, mpi_request
);
3898 if (scmd
->cmd_len
== 32)
3899 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3900 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3901 if (sas_device_priv_data
->sas_target
->flags
&
3902 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3903 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3905 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3906 mpi_request
->DevHandle
=
3907 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3908 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3909 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3910 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3911 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3912 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3913 mpi_request
->SenseBufferLowAddress
=
3914 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3915 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3916 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3917 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3918 mpi_request
->VF_ID
= 0; /* TODO */
3919 mpi_request
->VP_ID
= 0;
3920 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3922 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3924 if (!mpi_request
->DataLength
) {
3925 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3927 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3928 mpt2sas_base_free_smid(ioc
, smid
);
3933 raid_device
= sas_target_priv_data
->raid_device
;
3934 if (raid_device
&& raid_device
->direct_io_enabled
)
3935 _scsih_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
3938 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3939 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3940 le16_to_cpu(mpi_request
->DevHandle
));
3942 mpt2sas_base_put_smid_default(ioc
, smid
);
3946 return SCSI_MLQUEUE_HOST_BUSY
;
3949 static DEF_SCSI_QCMD(_scsih_qcmd
)
3952 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3953 * @sense_buffer: sense data returned by target
3954 * @data: normalized skey/asc/ascq
3959 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3961 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3962 /* descriptor format */
3963 data
->skey
= sense_buffer
[1] & 0x0F;
3964 data
->asc
= sense_buffer
[2];
3965 data
->ascq
= sense_buffer
[3];
3968 data
->skey
= sense_buffer
[2] & 0x0F;
3969 data
->asc
= sense_buffer
[12];
3970 data
->ascq
= sense_buffer
[13];
3974 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3976 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
3977 * @ioc: per adapter object
3978 * @scmd: pointer to scsi command object
3979 * @mpi_reply: reply mf payload returned from firmware
3981 * scsi_status - SCSI Status code returned from target device
3982 * scsi_state - state info associated with SCSI_IO determined by ioc
3983 * ioc_status - ioc supplied status info
3988 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3989 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
3993 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
3994 MPI2_IOCSTATUS_MASK
;
3995 u8 scsi_state
= mpi_reply
->SCSIState
;
3996 u8 scsi_status
= mpi_reply
->SCSIStatus
;
3997 char *desc_ioc_state
= NULL
;
3998 char *desc_scsi_status
= NULL
;
3999 char *desc_scsi_state
= ioc
->tmp_string
;
4000 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4001 struct _sas_device
*sas_device
= NULL
;
4002 unsigned long flags
;
4003 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4004 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
4005 char *device_str
= NULL
;
4010 if (ioc
->hide_ir_msg
)
4011 device_str
= "WarpDrive";
4013 device_str
= "volume";
4015 if (log_info
== 0x31170000)
4018 switch (ioc_status
) {
4019 case MPI2_IOCSTATUS_SUCCESS
:
4020 desc_ioc_state
= "success";
4022 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4023 desc_ioc_state
= "invalid function";
4025 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4026 desc_ioc_state
= "scsi recovered error";
4028 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4029 desc_ioc_state
= "scsi invalid dev handle";
4031 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4032 desc_ioc_state
= "scsi device not there";
4034 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4035 desc_ioc_state
= "scsi data overrun";
4037 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4038 desc_ioc_state
= "scsi data underrun";
4040 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4041 desc_ioc_state
= "scsi io data error";
4043 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4044 desc_ioc_state
= "scsi protocol error";
4046 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4047 desc_ioc_state
= "scsi task terminated";
4049 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4050 desc_ioc_state
= "scsi residual mismatch";
4052 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4053 desc_ioc_state
= "scsi task mgmt failed";
4055 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4056 desc_ioc_state
= "scsi ioc terminated";
4058 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4059 desc_ioc_state
= "scsi ext terminated";
4061 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4062 desc_ioc_state
= "eedp guard error";
4064 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4065 desc_ioc_state
= "eedp ref tag error";
4067 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4068 desc_ioc_state
= "eedp app tag error";
4071 desc_ioc_state
= "unknown";
4075 switch (scsi_status
) {
4076 case MPI2_SCSI_STATUS_GOOD
:
4077 desc_scsi_status
= "good";
4079 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4080 desc_scsi_status
= "check condition";
4082 case MPI2_SCSI_STATUS_CONDITION_MET
:
4083 desc_scsi_status
= "condition met";
4085 case MPI2_SCSI_STATUS_BUSY
:
4086 desc_scsi_status
= "busy";
4088 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4089 desc_scsi_status
= "intermediate";
4091 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4092 desc_scsi_status
= "intermediate condmet";
4094 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4095 desc_scsi_status
= "reservation conflict";
4097 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4098 desc_scsi_status
= "command terminated";
4100 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4101 desc_scsi_status
= "task set full";
4103 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4104 desc_scsi_status
= "aca active";
4106 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4107 desc_scsi_status
= "task aborted";
4110 desc_scsi_status
= "unknown";
4114 desc_scsi_state
[0] = '\0';
4116 desc_scsi_state
= " ";
4117 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4118 strcat(desc_scsi_state
, "response info ");
4119 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4120 strcat(desc_scsi_state
, "state terminated ");
4121 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4122 strcat(desc_scsi_state
, "no status ");
4123 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4124 strcat(desc_scsi_state
, "autosense failed ");
4125 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4126 strcat(desc_scsi_state
, "autosense valid ");
4128 scsi_print_command(scmd
);
4130 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4131 printk(MPT2SAS_WARN_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4132 device_str
, (unsigned long long)priv_target
->sas_address
);
4134 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4135 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4136 priv_target
->sas_address
);
4138 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
4139 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
4141 printk(MPT2SAS_WARN_FMT
4142 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4143 ioc
->name
, sas_device
->enclosure_logical_id
,
4146 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4149 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4150 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4151 desc_ioc_state
, ioc_status
, smid
);
4152 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
4153 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4154 scsi_get_resid(scmd
));
4155 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
4156 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4157 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4158 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
4159 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
4160 scsi_status
, desc_scsi_state
, scsi_state
);
4162 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4163 struct sense_info data
;
4164 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4165 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
4166 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
4167 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4170 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4171 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4172 response_bytes
= (u8
*)&response_info
;
4173 _scsih_response_code(ioc
, response_bytes
[0]);
4179 * _scsih_turn_on_fault_led - illuminate Fault LED
4180 * @ioc: per adapter object
4181 * @handle: device handle
4187 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4189 Mpi2SepReply_t mpi_reply
;
4190 Mpi2SepRequest_t mpi_request
;
4192 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4193 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4194 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4195 mpi_request
.SlotStatus
=
4196 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4197 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4198 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4199 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4200 &mpi_request
)) != 0) {
4201 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4202 __FILE__
, __LINE__
, __func__
);
4206 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4207 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
4208 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4209 le16_to_cpu(mpi_reply
.IOCStatus
),
4210 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4216 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4217 * @ioc: per adapter object
4218 * @handle: device handle
4219 * Context: interrupt.
4224 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4226 struct fw_event_work
*fw_event
;
4228 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4231 fw_event
->event
= MPT2SAS_TURN_ON_FAULT_LED
;
4232 fw_event
->device_handle
= handle
;
4233 fw_event
->ioc
= ioc
;
4234 _scsih_fw_event_add(ioc
, fw_event
);
4238 * _scsih_smart_predicted_fault - process smart errors
4239 * @ioc: per adapter object
4240 * @handle: device handle
4241 * Context: interrupt.
4246 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4248 struct scsi_target
*starget
;
4249 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4250 Mpi2EventNotificationReply_t
*event_reply
;
4251 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4252 struct _sas_device
*sas_device
;
4254 unsigned long flags
;
4256 /* only handle non-raid devices */
4257 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4258 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4260 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4263 starget
= sas_device
->starget
;
4264 sas_target_priv_data
= starget
->hostdata
;
4266 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4267 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4268 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4271 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
4272 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4274 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4275 _scsih_send_event_to_turn_on_fault_led(ioc
, handle
);
4277 /* insert into event log */
4278 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4279 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4280 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4282 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4283 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4287 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4288 event_reply
->Event
=
4289 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4290 event_reply
->MsgLength
= sz
/4;
4291 event_reply
->EventDataLength
=
4292 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4293 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4294 event_reply
->EventData
;
4295 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4296 event_data
->ASC
= 0x5D;
4297 event_data
->DevHandle
= cpu_to_le16(handle
);
4298 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4299 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
4304 * _scsih_io_done - scsi request callback
4305 * @ioc: per adapter object
4306 * @smid: system request message index
4307 * @msix_index: MSIX table index supplied by the OS
4308 * @reply: reply message frame(lower 32bit addr)
4310 * Callback handler when using _scsih_qcmd.
4312 * Return 1 meaning mf should be freed from _base_interrupt
4313 * 0 means the mf is freed from this function.
4316 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4318 Mpi2SCSIIORequest_t
*mpi_request
;
4319 Mpi2SCSIIOReply_t
*mpi_reply
;
4320 struct scsi_cmnd
*scmd
;
4326 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4327 u32 response_code
= 0;
4328 unsigned long flags
;
4330 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4331 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4335 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4337 if (mpi_reply
== NULL
) {
4338 scmd
->result
= DID_OK
<< 16;
4342 sas_device_priv_data
= scmd
->device
->hostdata
;
4343 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4344 sas_device_priv_data
->sas_target
->deleted
) {
4345 scmd
->result
= DID_NO_CONNECT
<< 16;
4349 * WARPDRIVE: If direct_io is set then it is directIO,
4350 * the failed direct I/O should be redirected to volume
4352 if (_scsih_scsi_direct_io_get(ioc
, smid
)) {
4353 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4354 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4355 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4356 _scsih_scsi_direct_io_set(ioc
, smid
, 0);
4357 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4358 mpi_request
->DevHandle
=
4359 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4360 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4361 sas_device_priv_data
->sas_target
->handle
);
4366 /* turning off TLR */
4367 scsi_state
= mpi_reply
->SCSIState
;
4368 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4370 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4371 if (!sas_device_priv_data
->tlr_snoop_check
) {
4372 sas_device_priv_data
->tlr_snoop_check
++;
4373 /* Make sure Device is not raid volume.
4374 * We do not expose raid functionality to upper layer for warpdrive.
4376 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4377 sas_is_tlr_enabled(scmd
->device
) &&
4378 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4379 sas_disable_tlr(scmd
->device
);
4380 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4384 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4385 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4386 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4387 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4388 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4391 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4392 scsi_status
= mpi_reply
->SCSIStatus
;
4394 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4395 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4396 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4397 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4398 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4401 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4402 struct sense_info data
;
4403 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
4405 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4406 le32_to_cpu(mpi_reply
->SenseCount
));
4407 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4408 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4409 /* failure prediction threshold exceeded */
4410 if (data
.asc
== 0x5D)
4411 _scsih_smart_predicted_fault(ioc
,
4412 le16_to_cpu(mpi_reply
->DevHandle
));
4415 switch (ioc_status
) {
4416 case MPI2_IOCSTATUS_BUSY
:
4417 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4418 scmd
->result
= SAM_STAT_BUSY
;
4421 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4422 scmd
->result
= DID_NO_CONNECT
<< 16;
4425 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4426 if (sas_device_priv_data
->block
) {
4427 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4430 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4431 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4432 scmd
->result
= DID_RESET
<< 16;
4435 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4436 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4437 scmd
->result
= DID_SOFT_ERROR
<< 16;
4439 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4442 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4443 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4445 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4448 if (xfer_cnt
< scmd
->underflow
) {
4449 if (scsi_status
== SAM_STAT_BUSY
)
4450 scmd
->result
= SAM_STAT_BUSY
;
4452 scmd
->result
= DID_SOFT_ERROR
<< 16;
4453 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4454 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4455 scmd
->result
= DID_SOFT_ERROR
<< 16;
4456 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4457 scmd
->result
= DID_RESET
<< 16;
4458 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4459 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4460 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4461 scmd
->result
= (DRIVER_SENSE
<< 24) |
4462 SAM_STAT_CHECK_CONDITION
;
4463 scmd
->sense_buffer
[0] = 0x70;
4464 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4465 scmd
->sense_buffer
[12] = 0x20;
4466 scmd
->sense_buffer
[13] = 0;
4470 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4471 scsi_set_resid(scmd
, 0);
4472 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4473 case MPI2_IOCSTATUS_SUCCESS
:
4474 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4475 if (response_code
==
4476 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4477 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4478 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4479 scmd
->result
= DID_SOFT_ERROR
<< 16;
4480 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4481 scmd
->result
= DID_RESET
<< 16;
4484 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4485 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4486 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4487 _scsih_eedp_error_handling(scmd
, ioc_status
);
4489 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4490 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4491 case MPI2_IOCSTATUS_INVALID_SGL
:
4492 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4493 case MPI2_IOCSTATUS_INVALID_FIELD
:
4494 case MPI2_IOCSTATUS_INVALID_STATE
:
4495 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4496 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4498 scmd
->result
= DID_SOFT_ERROR
<< 16;
4503 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4504 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4505 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4509 scsi_dma_unmap(scmd
);
4510 scmd
->scsi_done(scmd
);
4515 * _scsih_sas_host_refresh - refreshing sas host object contents
4516 * @ioc: per adapter object
4519 * During port enable, fw will send topology events for every device. Its
4520 * possible that the handles may change from the previous setting, so this
4521 * code keeping handles updating if changed.
4526 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4531 Mpi2ConfigReply_t mpi_reply
;
4532 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4533 u16 attached_handle
;
4536 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4537 "updating handles for sas_host(0x%016llx)\n",
4538 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4540 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4541 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4542 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4543 if (!sas_iounit_pg0
) {
4544 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4545 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4549 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4550 sas_iounit_pg0
, sz
)) != 0)
4552 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4553 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4555 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4556 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4558 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4559 PhyData
[0].ControllerDevHandle
);
4560 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4561 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4563 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4564 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4565 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4566 attached_handle
, i
, link_rate
);
4569 kfree(sas_iounit_pg0
);
4573 * _scsih_sas_host_add - create sas host object
4574 * @ioc: per adapter object
4576 * Creating host side data object, stored in ioc->sas_hba
4581 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4584 Mpi2ConfigReply_t mpi_reply
;
4585 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4586 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4587 Mpi2SasPhyPage0_t phy_pg0
;
4588 Mpi2SasDevicePage0_t sas_device_pg0
;
4589 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4592 u16 device_missing_delay
;
4594 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4595 if (!ioc
->sas_hba
.num_phys
) {
4596 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4597 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4601 /* sas_iounit page 0 */
4602 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4603 sizeof(Mpi2SasIOUnit0PhyData_t
));
4604 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4605 if (!sas_iounit_pg0
) {
4606 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4607 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4610 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4611 sas_iounit_pg0
, sz
))) {
4612 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4613 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4616 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4617 MPI2_IOCSTATUS_MASK
;
4618 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4619 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4620 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4624 /* sas_iounit page 1 */
4625 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4626 sizeof(Mpi2SasIOUnit1PhyData_t
));
4627 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4628 if (!sas_iounit_pg1
) {
4629 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4630 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4633 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4634 sas_iounit_pg1
, sz
))) {
4635 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4636 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4639 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4640 MPI2_IOCSTATUS_MASK
;
4641 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4642 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4643 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4647 ioc
->io_missing_delay
=
4648 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4649 device_missing_delay
=
4650 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4651 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4652 ioc
->device_missing_delay
= (device_missing_delay
&
4653 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4655 ioc
->device_missing_delay
= device_missing_delay
&
4656 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4658 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4659 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4660 sizeof(struct _sas_phy
), GFP_KERNEL
);
4661 if (!ioc
->sas_hba
.phy
) {
4662 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4663 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4666 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4667 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4669 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4670 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4673 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4674 MPI2_IOCSTATUS_MASK
;
4675 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4676 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4677 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4682 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4683 PhyData
[0].ControllerDevHandle
);
4684 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4685 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4686 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4687 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4689 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4690 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4691 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4692 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4695 ioc
->sas_hba
.enclosure_handle
=
4696 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4697 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4698 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4699 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4700 (unsigned long long) ioc
->sas_hba
.sas_address
,
4701 ioc
->sas_hba
.num_phys
) ;
4703 if (ioc
->sas_hba
.enclosure_handle
) {
4704 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4706 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4707 ioc
->sas_hba
.enclosure_handle
))) {
4708 ioc
->sas_hba
.enclosure_logical_id
=
4709 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4714 kfree(sas_iounit_pg1
);
4715 kfree(sas_iounit_pg0
);
4719 * _scsih_expander_add - creating expander object
4720 * @ioc: per adapter object
4721 * @handle: expander handle
4723 * Creating expander object, stored in ioc->sas_expander_list.
4725 * Return 0 for success, else error.
4728 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4730 struct _sas_node
*sas_expander
;
4731 Mpi2ConfigReply_t mpi_reply
;
4732 Mpi2ExpanderPage0_t expander_pg0
;
4733 Mpi2ExpanderPage1_t expander_pg1
;
4734 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4737 u64 sas_address
, sas_address_parent
= 0;
4739 unsigned long flags
;
4740 struct _sas_port
*mpt2sas_port
= NULL
;
4746 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4749 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4750 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4751 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4752 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4756 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4757 MPI2_IOCSTATUS_MASK
;
4758 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4759 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4760 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4764 /* handle out of order topology events */
4765 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4766 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4768 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4769 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4772 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4773 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4774 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4775 sas_address_parent
);
4776 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4777 if (!sas_expander
) {
4778 rc
= _scsih_expander_add(ioc
, parent_handle
);
4784 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4785 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4786 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4788 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4793 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4795 if (!sas_expander
) {
4796 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4797 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4801 sas_expander
->handle
= handle
;
4802 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4803 sas_expander
->sas_address_parent
= sas_address_parent
;
4804 sas_expander
->sas_address
= sas_address
;
4806 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4807 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4808 handle
, parent_handle
, (unsigned long long)
4809 sas_expander
->sas_address
, sas_expander
->num_phys
);
4811 if (!sas_expander
->num_phys
)
4813 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4814 sizeof(struct _sas_phy
), GFP_KERNEL
);
4815 if (!sas_expander
->phy
) {
4816 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4817 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4822 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4823 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4824 sas_address_parent
);
4825 if (!mpt2sas_port
) {
4826 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4827 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4831 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4833 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4834 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4835 &expander_pg1
, i
, handle
))) {
4836 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4837 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4841 sas_expander
->phy
[i
].handle
= handle
;
4842 sas_expander
->phy
[i
].phy_id
= i
;
4844 if ((mpt2sas_transport_add_expander_phy(ioc
,
4845 &sas_expander
->phy
[i
], expander_pg1
,
4846 sas_expander
->parent_dev
))) {
4847 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4848 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4854 if (sas_expander
->enclosure_handle
) {
4855 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4856 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4857 sas_expander
->enclosure_handle
))) {
4858 sas_expander
->enclosure_logical_id
=
4859 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4863 _scsih_expander_node_add(ioc
, sas_expander
);
4869 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4870 sas_address_parent
);
4871 kfree(sas_expander
);
4876 * _scsih_done - scsih callback handler.
4877 * @ioc: per adapter object
4878 * @smid: system request message index
4879 * @msix_index: MSIX table index supplied by the OS
4880 * @reply: reply message frame(lower 32bit addr)
4882 * Callback handler when sending internal generated message frames.
4883 * The callback index passed is `ioc->scsih_cb_idx`
4885 * Return 1 meaning mf should be freed from _base_interrupt
4886 * 0 means the mf is freed from this function.
4889 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4891 MPI2DefaultReply_t
*mpi_reply
;
4893 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4894 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4896 if (ioc
->scsih_cmds
.smid
!= smid
)
4898 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4900 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4901 mpi_reply
->MsgLength
*4);
4902 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4904 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4905 complete(&ioc
->scsih_cmds
.done
);
4910 * mpt2sas_expander_remove - removing expander object
4911 * @ioc: per adapter object
4912 * @sas_address: expander sas_address
4917 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4919 struct _sas_node
*sas_expander
;
4920 unsigned long flags
;
4922 if (ioc
->shost_recovery
)
4925 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4926 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4928 if (!sas_expander
) {
4929 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4932 list_del(&sas_expander
->list
);
4933 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4934 _scsih_expander_node_remove(ioc
, sas_expander
);
4938 * _scsih_check_access_status - check access flags
4939 * @ioc: per adapter object
4940 * @sas_address: sas address
4941 * @handle: sas device handle
4942 * @access_flags: errors returned during discovery of the device
4944 * Return 0 for success, else failure
4947 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4948 u16 handle
, u8 access_status
)
4953 switch (access_status
) {
4954 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4955 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4958 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4959 desc
= "sata capability failed";
4961 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4962 desc
= "sata affiliation conflict";
4964 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4965 desc
= "route not addressable";
4967 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4968 desc
= "smp error not addressable";
4970 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4971 desc
= "device blocked";
4973 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
4974 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
4975 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
4976 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
4977 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
4978 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
4979 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
4980 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
4981 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
4982 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
4983 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
4984 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
4985 desc
= "sata initialization failed";
4995 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
4996 "handle(0x%04x)\n", ioc
->name
, desc
,
4997 (unsigned long long)sas_address
, handle
);
5002 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5004 Mpi2ConfigReply_t mpi_reply
;
5005 Mpi2SasDevicePage0_t sas_device_pg0
;
5006 struct _sas_device
*sas_device
;
5008 unsigned long flags
;
5010 struct scsi_target
*starget
;
5011 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5014 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5015 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5018 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5019 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5022 /* check if this is end device */
5023 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5024 if (!(_scsih_is_end_device(device_info
)))
5027 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5028 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5029 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5033 printk(MPT2SAS_ERR_FMT
"device is not present "
5034 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
5035 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5039 if (unlikely(sas_device
->handle
!= handle
)) {
5040 starget
= sas_device
->starget
;
5041 sas_target_priv_data
= starget
->hostdata
;
5042 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
5043 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
5044 sas_target_priv_data
->handle
= handle
;
5045 sas_device
->handle
= handle
;
5047 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5049 /* check if device is present */
5050 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5051 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5052 printk(MPT2SAS_ERR_FMT
"device is not present "
5053 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
5057 /* check if there were any issues with discovery */
5058 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5059 sas_device_pg0
.AccessStatus
))
5061 _scsih_ublock_io_device(ioc
, handle
);
5066 * _scsih_add_device - creating sas device object
5067 * @ioc: per adapter object
5068 * @handle: sas device handle
5069 * @phy_num: phy number end device attached to
5070 * @is_pd: is this hidden raid component
5072 * Creating end device object, stored in ioc->sas_device_list.
5074 * Returns 0 for success, non-zero for failure.
5077 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
5079 Mpi2ConfigReply_t mpi_reply
;
5080 Mpi2SasDevicePage0_t sas_device_pg0
;
5081 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5082 struct _sas_device
*sas_device
;
5086 unsigned long flags
;
5088 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5089 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5090 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5091 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5095 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5096 MPI2_IOCSTATUS_MASK
;
5097 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5098 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5099 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5103 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5105 /* check if device is present */
5106 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5107 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5108 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5109 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5110 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
5111 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
5115 /* check if there were any issues with discovery */
5116 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5117 sas_device_pg0
.AccessStatus
))
5120 /* check if this is end device */
5121 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5122 if (!(_scsih_is_end_device(device_info
))) {
5123 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5124 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5129 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5130 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5132 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5137 sas_device
= kzalloc(sizeof(struct _sas_device
),
5140 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5141 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5145 sas_device
->handle
= handle
;
5146 if (_scsih_get_sas_address(ioc
, le16_to_cpu
5147 (sas_device_pg0
.ParentDevHandle
),
5148 &sas_device
->sas_address_parent
) != 0)
5149 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5150 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5151 sas_device
->enclosure_handle
=
5152 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5154 le16_to_cpu(sas_device_pg0
.Slot
);
5155 sas_device
->device_info
= device_info
;
5156 sas_device
->sas_address
= sas_address
;
5157 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5159 /* get enclosure_logical_id */
5160 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
5161 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5162 sas_device
->enclosure_handle
)))
5163 sas_device
->enclosure_logical_id
=
5164 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5166 /* get device name */
5167 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5169 if (ioc
->wait_for_discovery_to_complete
)
5170 _scsih_sas_device_init_add(ioc
, sas_device
);
5172 _scsih_sas_device_add(ioc
, sas_device
);
5178 * _scsih_remove_device - removing sas device object
5179 * @ioc: per adapter object
5180 * @sas_device_delete: the sas_device object
5185 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
5186 struct _sas_device
*sas_device
)
5188 struct _sas_device sas_device_backup
;
5189 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5194 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
5195 _scsih_sas_device_remove(ioc
, sas_device
);
5197 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
5198 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5199 sas_device_backup
.handle
, (unsigned long long)
5200 sas_device_backup
.sas_address
));
5202 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
5203 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
5204 sas_target_priv_data
->deleted
= 1;
5205 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
5206 sas_target_priv_data
->handle
=
5207 MPT2SAS_INVALID_DEVICE_HANDLE
;
5210 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
5212 if (!ioc
->hide_drives
)
5213 mpt2sas_transport_port_remove(ioc
,
5214 sas_device_backup
.sas_address
,
5215 sas_device_backup
.sas_address_parent
);
5217 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
5218 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
5219 (unsigned long long) sas_device_backup
.sas_address
);
5221 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
5222 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5223 sas_device_backup
.handle
, (unsigned long long)
5224 sas_device_backup
.sas_address
));
5228 * mpt2sas_device_remove - removing device object
5229 * @ioc: per adapter object
5230 * @sas_address: expander sas_address
5235 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5237 struct _sas_device
*sas_device
;
5238 unsigned long flags
;
5240 if (ioc
->shost_recovery
)
5243 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5244 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5247 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5250 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5251 _scsih_remove_device(ioc
, sas_device
);
5254 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5256 * _scsih_sas_topology_change_event_debug - debug for topology event
5257 * @ioc: per adapter object
5258 * @event_data: event data payload
5262 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5263 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5269 char *status_str
= NULL
;
5270 u8 link_rate
, prev_link_rate
;
5272 switch (event_data
->ExpStatus
) {
5273 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5276 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5277 status_str
= "remove";
5279 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5281 status_str
= "responding";
5283 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5284 status_str
= "remove delay";
5287 status_str
= "unknown status";
5290 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
5291 ioc
->name
, status_str
);
5292 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
5293 "start_phy(%02d), count(%d)\n",
5294 le16_to_cpu(event_data
->ExpanderDevHandle
),
5295 le16_to_cpu(event_data
->EnclosureHandle
),
5296 event_data
->StartPhyNum
, event_data
->NumEntries
);
5297 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5298 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5301 phy_number
= event_data
->StartPhyNum
+ i
;
5302 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5303 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5304 switch (reason_code
) {
5305 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5306 status_str
= "target add";
5308 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5309 status_str
= "target remove";
5311 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5312 status_str
= "delay target remove";
5314 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5315 status_str
= "link rate change";
5317 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5318 status_str
= "target responding";
5321 status_str
= "unknown";
5324 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5325 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5326 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
5327 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5328 handle
, status_str
, link_rate
, prev_link_rate
);
5335 * _scsih_sas_topology_change_event - handle topology changes
5336 * @ioc: per adapter object
5337 * @fw_event: The fw_event_work object
5342 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5343 struct fw_event_work
*fw_event
)
5346 u16 parent_handle
, handle
;
5348 u8 phy_number
, max_phys
;
5349 struct _sas_node
*sas_expander
;
5350 struct _sas_device
*sas_device
;
5352 unsigned long flags
;
5353 u8 link_rate
, prev_link_rate
;
5354 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
5356 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5357 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5358 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5361 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5364 if (!ioc
->sas_hba
.num_phys
)
5365 _scsih_sas_host_add(ioc
);
5367 _scsih_sas_host_refresh(ioc
);
5369 if (fw_event
->ignore
) {
5370 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
5371 "event\n", ioc
->name
));
5375 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5377 /* handle expander add */
5378 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5379 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5382 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5383 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
5385 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5387 sas_address
= sas_expander
->sas_address
;
5388 max_phys
= sas_expander
->num_phys
;
5389 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5390 sas_address
= ioc
->sas_hba
.sas_address
;
5391 max_phys
= ioc
->sas_hba
.num_phys
;
5395 /* handle siblings events */
5396 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5397 if (fw_event
->ignore
) {
5398 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
5399 "expander event\n", ioc
->name
));
5402 if (ioc
->shost_recovery
|| ioc
->remove_host
||
5403 ioc
->pci_error_recovery
)
5405 phy_number
= event_data
->StartPhyNum
+ i
;
5406 if (phy_number
>= max_phys
)
5408 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5409 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5410 if ((event_data
->PHY
[i
].PhyStatus
&
5411 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5412 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5414 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5417 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5418 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5419 switch (reason_code
) {
5420 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5422 if (ioc
->shost_recovery
)
5425 if (link_rate
== prev_link_rate
)
5428 mpt2sas_transport_update_links(ioc
, sas_address
,
5429 handle
, phy_number
, link_rate
);
5431 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5434 _scsih_check_device(ioc
, handle
);
5436 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5438 if (ioc
->shost_recovery
)
5441 mpt2sas_transport_update_links(ioc
, sas_address
,
5442 handle
, phy_number
, link_rate
);
5444 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5446 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5448 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5449 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
5452 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
5456 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5457 _scsih_remove_device(ioc
, sas_device
);
5462 /* handle expander removal */
5463 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5465 mpt2sas_expander_remove(ioc
, sas_address
);
5469 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5471 * _scsih_sas_device_status_change_event_debug - debug for device event
5472 * @event_data: event data payload
5478 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5479 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5481 char *reason_str
= NULL
;
5483 switch (event_data
->ReasonCode
) {
5484 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5485 reason_str
= "smart data";
5487 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5488 reason_str
= "unsupported device discovered";
5490 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5491 reason_str
= "internal device reset";
5493 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5494 reason_str
= "internal task abort";
5496 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5497 reason_str
= "internal task abort set";
5499 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5500 reason_str
= "internal clear task set";
5502 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5503 reason_str
= "internal query task";
5505 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5506 reason_str
= "sata init failure";
5508 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5509 reason_str
= "internal device reset complete";
5511 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5512 reason_str
= "internal task abort complete";
5514 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5515 reason_str
= "internal async notification";
5517 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5518 reason_str
= "expander reduced functionality";
5520 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5521 reason_str
= "expander reduced functionality complete";
5524 reason_str
= "unknown reason";
5527 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5528 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5529 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5530 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5531 le16_to_cpu(event_data
->TaskTag
));
5532 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5533 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5534 event_data
->ASC
, event_data
->ASCQ
);
5535 printk(KERN_INFO
"\n");
5540 * _scsih_sas_device_status_change_event - handle device status change
5541 * @ioc: per adapter object
5542 * @fw_event: The fw_event_work object
5548 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5549 struct fw_event_work
*fw_event
)
5551 struct MPT2SAS_TARGET
*target_priv_data
;
5552 struct _sas_device
*sas_device
;
5554 unsigned long flags
;
5555 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5556 fw_event
->event_data
;
5558 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5559 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5560 _scsih_sas_device_status_change_event_debug(ioc
,
5564 /* In MPI Revision K (0xC), the internal device reset complete was
5565 * implemented, so avoid setting tm_busy flag for older firmware.
5567 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5570 if (event_data
->ReasonCode
!=
5571 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5572 event_data
->ReasonCode
!=
5573 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5576 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5577 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5578 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5580 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5582 if (!sas_device
|| !sas_device
->starget
)
5585 target_priv_data
= sas_device
->starget
->hostdata
;
5586 if (!target_priv_data
)
5589 if (event_data
->ReasonCode
==
5590 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5591 target_priv_data
->tm_busy
= 1;
5593 target_priv_data
->tm_busy
= 0;
5596 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5598 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5599 * @ioc: per adapter object
5600 * @event_data: event data payload
5606 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5607 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5609 char *reason_str
= NULL
;
5611 switch (event_data
->ReasonCode
) {
5612 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5613 reason_str
= "enclosure add";
5615 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5616 reason_str
= "enclosure remove";
5619 reason_str
= "unknown reason";
5623 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5624 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5625 " number slots(%d)\n", ioc
->name
, reason_str
,
5626 le16_to_cpu(event_data
->EnclosureHandle
),
5627 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5628 le16_to_cpu(event_data
->StartSlot
));
5633 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5634 * @ioc: per adapter object
5635 * @fw_event: The fw_event_work object
5641 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5642 struct fw_event_work
*fw_event
)
5644 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5645 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5646 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5647 fw_event
->event_data
);
5652 * _scsih_sas_broadcast_primative_event - handle broadcast events
5653 * @ioc: per adapter object
5654 * @fw_event: The fw_event_work object
5660 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5661 struct fw_event_work
*fw_event
)
5663 struct scsi_cmnd
*scmd
;
5664 struct scsi_device
*sdev
;
5667 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5668 u32 termination_count
;
5670 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5671 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5673 unsigned long flags
;
5676 u8 task_abort_retries
;
5678 mutex_lock(&ioc
->tm_cmds
.mutex
);
5679 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: phy number(%d), "
5680 "width(%d)\n", ioc
->name
, __func__
, event_data
->PhyNum
,
5681 event_data
->PortWidth
));
5683 _scsih_block_io_all_device(ioc
);
5685 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5686 mpi_reply
= ioc
->tm_cmds
.reply
;
5687 broadcast_aen_retry
:
5689 /* sanity checks for retrying this loop */
5690 if (max_retries
++ == 5) {
5691 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: giving up\n",
5692 ioc
->name
, __func__
));
5694 } else if (max_retries
> 1)
5695 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %d retry\n",
5696 ioc
->name
, __func__
, max_retries
- 1));
5698 termination_count
= 0;
5700 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5701 if (ioc
->shost_recovery
)
5703 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5706 sdev
= scmd
->device
;
5707 sas_device_priv_data
= sdev
->hostdata
;
5708 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5710 /* skip hidden raid components */
5711 if (sas_device_priv_data
->sas_target
->flags
&
5712 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5715 if (sas_device_priv_data
->sas_target
->flags
&
5716 MPT_TARGET_FLAGS_VOLUME
)
5719 handle
= sas_device_priv_data
->sas_target
->handle
;
5720 lun
= sas_device_priv_data
->lun
;
5723 if (ioc
->shost_recovery
)
5726 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5727 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5728 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, 0,
5731 sdev_printk(KERN_WARNING
, sdev
,
5732 "mpt2sas_scsih_issue_tm: FAILED when sending "
5733 "QUERY_TASK: scmd(%p)\n", scmd
);
5734 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5735 goto broadcast_aen_retry
;
5737 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5738 & MPI2_IOCSTATUS_MASK
;
5739 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5740 sdev_printk(KERN_WARNING
, sdev
, "query task: FAILED "
5741 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status
,
5743 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5744 goto broadcast_aen_retry
;
5747 /* see if IO is still owned by IOC and target */
5748 if (mpi_reply
->ResponseCode
==
5749 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5750 mpi_reply
->ResponseCode
==
5751 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5752 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5755 task_abort_retries
= 0;
5757 if (task_abort_retries
++ == 60) {
5758 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5759 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5761 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5762 goto broadcast_aen_retry
;
5765 if (ioc
->shost_recovery
)
5768 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5769 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5770 scmd
->serial_number
, TM_MUTEX_OFF
);
5772 sdev_printk(KERN_WARNING
, sdev
,
5773 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5774 "scmd(%p)\n", scmd
);
5778 if (task_abort_retries
> 1)
5779 sdev_printk(KERN_WARNING
, sdev
,
5780 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5782 task_abort_retries
- 1, scmd
);
5784 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5785 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5788 if (ioc
->broadcast_aen_pending
) {
5789 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: loop back due to"
5790 " pending AEN\n", ioc
->name
, __func__
));
5791 ioc
->broadcast_aen_pending
= 0;
5792 goto broadcast_aen_retry
;
5796 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5799 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5800 "%s - exit, query_count = %d termination_count = %d\n",
5801 ioc
->name
, __func__
, query_count
, termination_count
));
5803 ioc
->broadcast_aen_busy
= 0;
5804 if (!ioc
->shost_recovery
)
5805 _scsih_ublock_io_all_device(ioc
);
5806 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5810 * _scsih_sas_discovery_event - handle discovery events
5811 * @ioc: per adapter object
5812 * @fw_event: The fw_event_work object
5818 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5819 struct fw_event_work
*fw_event
)
5821 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5823 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5824 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5825 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5826 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5828 if (event_data
->DiscoveryStatus
)
5829 printk("discovery_status(0x%08x)",
5830 le32_to_cpu(event_data
->DiscoveryStatus
));
5835 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5836 !ioc
->sas_hba
.num_phys
)
5837 _scsih_sas_host_add(ioc
);
5841 * _scsih_reprobe_lun - reprobing lun
5842 * @sdev: scsi device struct
5843 * @no_uld_attach: sdev->no_uld_attach flag setting
5847 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5851 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5852 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5853 sdev
->no_uld_attach
? "hidding" : "exposing");
5854 rc
= scsi_device_reprobe(sdev
);
5858 * _scsih_reprobe_target - reprobing target
5859 * @starget: scsi target struct
5860 * @no_uld_attach: sdev->no_uld_attach flag setting
5862 * Note: no_uld_attach flag determines whether the disk device is attached
5863 * to block layer. A value of `1` means to not attach.
5866 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5868 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5871 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5873 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5875 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5876 _scsih_reprobe_lun
);
5879 * _scsih_sas_volume_add - add new volume
5880 * @ioc: per adapter object
5881 * @element: IR config element data
5887 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5888 Mpi2EventIrConfigElement_t
*element
)
5890 struct _raid_device
*raid_device
;
5891 unsigned long flags
;
5893 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5896 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5898 printk(MPT2SAS_ERR_FMT
5899 "failure at %s:%d/%s()!\n", ioc
->name
,
5900 __FILE__
, __LINE__
, __func__
);
5904 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5905 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5906 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5911 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5913 printk(MPT2SAS_ERR_FMT
5914 "failure at %s:%d/%s()!\n", ioc
->name
,
5915 __FILE__
, __LINE__
, __func__
);
5919 raid_device
->id
= ioc
->sas_id
++;
5920 raid_device
->channel
= RAID_CHANNEL
;
5921 raid_device
->handle
= handle
;
5922 raid_device
->wwid
= wwid
;
5923 _scsih_raid_device_add(ioc
, raid_device
);
5924 if (!ioc
->wait_for_discovery_to_complete
) {
5925 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5926 raid_device
->id
, 0);
5928 _scsih_raid_device_remove(ioc
, raid_device
);
5930 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5934 * _scsih_sas_volume_delete - delete volume
5935 * @ioc: per adapter object
5936 * @handle: volume device handle
5942 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5944 struct _raid_device
*raid_device
;
5945 unsigned long flags
;
5946 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5948 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5949 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5950 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5953 if (raid_device
->starget
) {
5954 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5955 sas_target_priv_data
->deleted
= 1;
5956 scsi_remove_target(&raid_device
->starget
->dev
);
5958 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5959 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5960 (unsigned long long) raid_device
->wwid
);
5961 _scsih_raid_device_remove(ioc
, raid_device
);
5965 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5966 * @ioc: per adapter object
5967 * @element: IR config element data
5973 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
5974 Mpi2EventIrConfigElement_t
*element
)
5976 struct _sas_device
*sas_device
;
5977 unsigned long flags
;
5978 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
5980 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5981 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
5982 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5986 /* exposing raid component */
5987 sas_device
->volume_handle
= 0;
5988 sas_device
->volume_wwid
= 0;
5989 clear_bit(handle
, ioc
->pd_handles
);
5990 _scsih_reprobe_target(sas_device
->starget
, 0);
5994 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5995 * @ioc: per adapter object
5996 * @element: IR config element data
6002 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
6003 Mpi2EventIrConfigElement_t
*element
)
6005 struct _sas_device
*sas_device
;
6006 unsigned long flags
;
6007 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6009 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6010 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6011 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6015 /* hiding raid component */
6016 mpt2sas_config_get_volume_handle(ioc
, handle
,
6017 &sas_device
->volume_handle
);
6018 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
6019 &sas_device
->volume_wwid
);
6020 set_bit(handle
, ioc
->pd_handles
);
6021 _scsih_reprobe_target(sas_device
->starget
, 1);
6026 * _scsih_sas_pd_delete - delete pd component
6027 * @ioc: per adapter object
6028 * @element: IR config element data
6034 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
6035 Mpi2EventIrConfigElement_t
*element
)
6037 struct _sas_device
*sas_device
;
6038 unsigned long flags
;
6039 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6041 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6042 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6043 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6046 _scsih_remove_device(ioc
, sas_device
);
6050 * _scsih_sas_pd_add - remove pd component
6051 * @ioc: per adapter object
6052 * @element: IR config element data
6058 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
6059 Mpi2EventIrConfigElement_t
*element
)
6061 struct _sas_device
*sas_device
;
6062 unsigned long flags
;
6063 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6064 Mpi2ConfigReply_t mpi_reply
;
6065 Mpi2SasDevicePage0_t sas_device_pg0
;
6070 set_bit(handle
, ioc
->pd_handles
);
6072 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6073 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6074 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6078 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6079 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6080 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6081 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6085 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6086 MPI2_IOCSTATUS_MASK
;
6087 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6088 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6089 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6093 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6094 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6095 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6096 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6098 _scsih_add_device(ioc
, handle
, 0, 1);
6101 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6103 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6104 * @ioc: per adapter object
6105 * @event_data: event data payload
6111 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6112 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6114 Mpi2EventIrConfigElement_t
*element
;
6117 char *reason_str
= NULL
, *element_str
= NULL
;
6119 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6121 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
6122 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6123 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6124 "foreign" : "native", event_data
->NumElements
);
6125 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6126 switch (element
->ReasonCode
) {
6127 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6130 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6131 reason_str
= "remove";
6133 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6134 reason_str
= "no change";
6136 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6137 reason_str
= "hide";
6139 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6140 reason_str
= "unhide";
6142 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6143 reason_str
= "volume_created";
6145 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6146 reason_str
= "volume_deleted";
6148 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6149 reason_str
= "pd_created";
6151 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6152 reason_str
= "pd_deleted";
6155 reason_str
= "unknown reason";
6158 element_type
= le16_to_cpu(element
->ElementFlags
) &
6159 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6160 switch (element_type
) {
6161 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6162 element_str
= "volume";
6164 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6165 element_str
= "phys disk";
6167 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6168 element_str
= "hot spare";
6171 element_str
= "unknown element";
6174 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
6175 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6176 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6177 le16_to_cpu(element
->PhysDiskDevHandle
),
6178 element
->PhysDiskNum
);
6184 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6185 * @ioc: per adapter object
6186 * @fw_event: The fw_event_work object
6192 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
6193 struct fw_event_work
*fw_event
)
6195 Mpi2EventIrConfigElement_t
*element
;
6198 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
6200 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6201 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6202 && !ioc
->hide_ir_msg
)
6203 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6207 if (ioc
->shost_recovery
)
6210 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6211 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6213 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6214 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6216 switch (element
->ReasonCode
) {
6217 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6218 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6219 if (!foreign_config
)
6220 _scsih_sas_volume_add(ioc
, element
);
6222 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6223 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6224 if (!foreign_config
)
6225 _scsih_sas_volume_delete(ioc
,
6226 le16_to_cpu(element
->VolDevHandle
));
6228 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6229 if (!ioc
->is_warpdrive
)
6230 _scsih_sas_pd_hide(ioc
, element
);
6232 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6233 if (!ioc
->is_warpdrive
)
6234 _scsih_sas_pd_expose(ioc
, element
);
6236 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6237 if (!ioc
->is_warpdrive
)
6238 _scsih_sas_pd_add(ioc
, element
);
6240 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6241 if (!ioc
->is_warpdrive
)
6242 _scsih_sas_pd_delete(ioc
, element
);
6249 * _scsih_sas_ir_volume_event - IR volume event
6250 * @ioc: per adapter object
6251 * @fw_event: The fw_event_work object
6257 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
6258 struct fw_event_work
*fw_event
)
6261 unsigned long flags
;
6262 struct _raid_device
*raid_device
;
6266 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
6268 if (ioc
->shost_recovery
)
6271 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6274 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6275 state
= le32_to_cpu(event_data
->NewValue
);
6276 if (!ioc
->hide_ir_msg
)
6277 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6278 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6279 le32_to_cpu(event_data
->PreviousValue
), state
));
6282 case MPI2_RAID_VOL_STATE_MISSING
:
6283 case MPI2_RAID_VOL_STATE_FAILED
:
6284 _scsih_sas_volume_delete(ioc
, handle
);
6287 case MPI2_RAID_VOL_STATE_ONLINE
:
6288 case MPI2_RAID_VOL_STATE_DEGRADED
:
6289 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6291 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6292 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6293 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6298 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6300 printk(MPT2SAS_ERR_FMT
6301 "failure at %s:%d/%s()!\n", ioc
->name
,
6302 __FILE__
, __LINE__
, __func__
);
6306 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6308 printk(MPT2SAS_ERR_FMT
6309 "failure at %s:%d/%s()!\n", ioc
->name
,
6310 __FILE__
, __LINE__
, __func__
);
6314 raid_device
->id
= ioc
->sas_id
++;
6315 raid_device
->channel
= RAID_CHANNEL
;
6316 raid_device
->handle
= handle
;
6317 raid_device
->wwid
= wwid
;
6318 _scsih_raid_device_add(ioc
, raid_device
);
6319 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6320 raid_device
->id
, 0);
6322 _scsih_raid_device_remove(ioc
, raid_device
);
6325 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6332 * _scsih_sas_ir_physical_disk_event - PD event
6333 * @ioc: per adapter object
6334 * @fw_event: The fw_event_work object
6340 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
6341 struct fw_event_work
*fw_event
)
6343 u16 handle
, parent_handle
;
6345 struct _sas_device
*sas_device
;
6346 unsigned long flags
;
6347 Mpi2ConfigReply_t mpi_reply
;
6348 Mpi2SasDevicePage0_t sas_device_pg0
;
6350 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
6353 if (ioc
->shost_recovery
)
6356 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6359 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6360 state
= le32_to_cpu(event_data
->NewValue
);
6362 if (!ioc
->hide_ir_msg
)
6363 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6364 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6365 le32_to_cpu(event_data
->PreviousValue
), state
));
6368 case MPI2_RAID_PD_STATE_ONLINE
:
6369 case MPI2_RAID_PD_STATE_DEGRADED
:
6370 case MPI2_RAID_PD_STATE_REBUILDING
:
6371 case MPI2_RAID_PD_STATE_OPTIMAL
:
6372 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6374 if (!ioc
->is_warpdrive
)
6375 set_bit(handle
, ioc
->pd_handles
);
6377 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6378 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6379 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6384 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6385 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6387 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6388 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6392 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6393 MPI2_IOCSTATUS_MASK
;
6394 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6395 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6396 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6400 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6401 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6402 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6403 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6405 _scsih_add_device(ioc
, handle
, 0, 1);
6409 case MPI2_RAID_PD_STATE_OFFLINE
:
6410 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6411 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6417 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6419 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6420 * @ioc: per adapter object
6421 * @event_data: event data payload
6427 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6428 Mpi2EventDataIrOperationStatus_t
*event_data
)
6430 char *reason_str
= NULL
;
6432 switch (event_data
->RAIDOperation
) {
6433 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6434 reason_str
= "resync";
6436 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6437 reason_str
= "online capacity expansion";
6439 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6440 reason_str
= "consistency check";
6442 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6443 reason_str
= "background init";
6445 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6446 reason_str
= "make data consistent";
6453 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
6454 "\thandle(0x%04x), percent complete(%d)\n",
6455 ioc
->name
, reason_str
,
6456 le16_to_cpu(event_data
->VolDevHandle
),
6457 event_data
->PercentComplete
);
6462 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6463 * @ioc: per adapter object
6464 * @fw_event: The fw_event_work object
6470 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
6471 struct fw_event_work
*fw_event
)
6473 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
6474 static struct _raid_device
*raid_device
;
6475 unsigned long flags
;
6478 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6479 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6480 && !ioc
->hide_ir_msg
)
6481 _scsih_sas_ir_operation_status_event_debug(ioc
,
6485 /* code added for raid transport support */
6486 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6488 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6490 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6491 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6492 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6497 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
6498 raid_device
->percent_complete
=
6499 event_data
->PercentComplete
;
6504 * _scsih_prep_device_scan - initialize parameters prior to device scan
6505 * @ioc: per adapter object
6507 * Set the deleted flag prior to device scan. If the device is found during
6508 * the scan, then we clear the deleted flag.
6511 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
6513 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
6514 struct scsi_device
*sdev
;
6516 shost_for_each_device(sdev
, ioc
->shost
) {
6517 sas_device_priv_data
= sdev
->hostdata
;
6518 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6519 sas_device_priv_data
->sas_target
->deleted
= 1;
6524 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6525 * @ioc: per adapter object
6526 * @sas_address: sas address
6527 * @slot: enclosure slot id
6528 * @handle: device handle
6530 * After host reset, find out whether devices are still responding.
6531 * Used in _scsi_remove_unresponsive_sas_devices.
6536 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6537 u16 slot
, u16 handle
)
6539 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
6540 struct scsi_target
*starget
;
6541 struct _sas_device
*sas_device
;
6542 unsigned long flags
;
6544 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6545 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6546 if (sas_device
->sas_address
== sas_address
&&
6547 sas_device
->slot
== slot
) {
6548 sas_device
->responding
= 1;
6549 starget
= sas_device
->starget
;
6550 if (starget
&& starget
->hostdata
) {
6551 sas_target_priv_data
= starget
->hostdata
;
6552 sas_target_priv_data
->tm_busy
= 0;
6553 sas_target_priv_data
->deleted
= 0;
6555 sas_target_priv_data
= NULL
;
6557 starget_printk(KERN_INFO
, starget
,
6558 "handle(0x%04x), sas_addr(0x%016llx), "
6559 "enclosure logical id(0x%016llx), "
6560 "slot(%d)\n", handle
,
6561 (unsigned long long)sas_device
->sas_address
,
6562 (unsigned long long)
6563 sas_device
->enclosure_logical_id
,
6565 if (sas_device
->handle
== handle
)
6567 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6568 sas_device
->handle
);
6569 sas_device
->handle
= handle
;
6570 if (sas_target_priv_data
)
6571 sas_target_priv_data
->handle
= handle
;
6576 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6580 * _scsih_search_responding_sas_devices -
6581 * @ioc: per adapter object
6583 * After host reset, find out whether devices are still responding.
6589 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6591 Mpi2SasDevicePage0_t sas_device_pg0
;
6592 Mpi2ConfigReply_t mpi_reply
;
6599 printk(MPT2SAS_INFO_FMT
"search for end-devices: start\n", ioc
->name
);
6601 if (list_empty(&ioc
->sas_device_list
))
6605 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6606 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6608 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6609 MPI2_IOCSTATUS_MASK
;
6610 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6612 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6613 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6614 if (!(_scsih_is_end_device(device_info
)))
6616 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6617 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6618 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6622 printk(MPT2SAS_INFO_FMT
"search for end-devices: complete\n",
6627 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6628 * @ioc: per adapter object
6629 * @wwid: world wide identifier for raid volume
6630 * @handle: device handle
6632 * After host reset, find out whether devices are still responding.
6633 * Used in _scsi_remove_unresponsive_raid_devices.
6638 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6641 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6642 struct scsi_target
*starget
;
6643 struct _raid_device
*raid_device
;
6644 unsigned long flags
;
6646 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6647 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6648 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6649 starget
= raid_device
->starget
;
6650 if (starget
&& starget
->hostdata
) {
6651 sas_target_priv_data
= starget
->hostdata
;
6652 sas_target_priv_data
->deleted
= 0;
6654 sas_target_priv_data
= NULL
;
6655 raid_device
->responding
= 1;
6656 starget_printk(KERN_INFO
, raid_device
->starget
,
6657 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6658 (unsigned long long)raid_device
->wwid
);
6660 * WARPDRIVE: The handles of the PDs might have changed
6661 * across the host reset so re-initialize the
6662 * required data for Direct IO
6664 _scsih_init_warpdrive_properties(ioc
, raid_device
);
6665 if (raid_device
->handle
== handle
)
6667 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6668 raid_device
->handle
);
6669 raid_device
->handle
= handle
;
6670 if (sas_target_priv_data
)
6671 sas_target_priv_data
->handle
= handle
;
6676 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6680 * _scsih_search_responding_raid_devices -
6681 * @ioc: per adapter object
6683 * After host reset, find out whether devices are still responding.
6689 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6691 Mpi2RaidVolPage1_t volume_pg1
;
6692 Mpi2RaidVolPage0_t volume_pg0
;
6693 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6694 Mpi2ConfigReply_t mpi_reply
;
6699 if (!ioc
->ir_firmware
)
6702 printk(MPT2SAS_INFO_FMT
"search for raid volumes: start\n",
6705 if (list_empty(&ioc
->raid_device_list
))
6709 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6710 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6711 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6712 MPI2_IOCSTATUS_MASK
;
6713 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6715 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6717 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6718 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6719 sizeof(Mpi2RaidVolPage0_t
)))
6722 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6723 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6724 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6725 _scsih_mark_responding_raid_device(ioc
,
6726 le64_to_cpu(volume_pg1
.WWID
), handle
);
6729 /* refresh the pd_handles */
6730 if (!ioc
->is_warpdrive
) {
6731 phys_disk_num
= 0xFF;
6732 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6733 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6734 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6736 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6737 MPI2_IOCSTATUS_MASK
;
6738 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6740 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6741 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6742 set_bit(handle
, ioc
->pd_handles
);
6746 printk(MPT2SAS_INFO_FMT
"search for responding raid volumes: "
6747 "complete\n", ioc
->name
);
6751 * _scsih_mark_responding_expander - mark a expander as responding
6752 * @ioc: per adapter object
6753 * @sas_address: sas address
6756 * After host reset, find out whether devices are still responding.
6757 * Used in _scsi_remove_unresponsive_expanders.
6762 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6765 struct _sas_node
*sas_expander
;
6766 unsigned long flags
;
6769 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6770 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6771 if (sas_expander
->sas_address
!= sas_address
)
6773 sas_expander
->responding
= 1;
6774 if (sas_expander
->handle
== handle
)
6776 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6777 " from(0x%04x) to (0x%04x)!!!\n",
6778 (unsigned long long)sas_expander
->sas_address
,
6779 sas_expander
->handle
, handle
);
6780 sas_expander
->handle
= handle
;
6781 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6782 sas_expander
->phy
[i
].handle
= handle
;
6786 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6790 * _scsih_search_responding_expanders -
6791 * @ioc: per adapter object
6793 * After host reset, find out whether devices are still responding.
6799 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6801 Mpi2ExpanderPage0_t expander_pg0
;
6802 Mpi2ConfigReply_t mpi_reply
;
6807 printk(MPT2SAS_INFO_FMT
"search for expanders: start\n", ioc
->name
);
6809 if (list_empty(&ioc
->sas_expander_list
))
6813 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6814 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6816 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6817 MPI2_IOCSTATUS_MASK
;
6818 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6821 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6822 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6823 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6824 "sas_addr(0x%016llx)\n", handle
,
6825 (unsigned long long)sas_address
);
6826 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6830 printk(MPT2SAS_INFO_FMT
"search for expanders: complete\n", ioc
->name
);
6834 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6835 * @ioc: per adapter object
6840 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6842 struct _sas_device
*sas_device
, *sas_device_next
;
6843 struct _sas_node
*sas_expander
;
6844 struct _raid_device
*raid_device
, *raid_device_next
;
6846 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: start\n",
6849 list_for_each_entry_safe(sas_device
, sas_device_next
,
6850 &ioc
->sas_device_list
, list
) {
6851 if (sas_device
->responding
) {
6852 sas_device
->responding
= 0;
6855 if (sas_device
->starget
)
6856 starget_printk(KERN_INFO
, sas_device
->starget
,
6857 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6858 "enclosure logical id(0x%016llx), slot(%d)\n",
6860 (unsigned long long)sas_device
->sas_address
,
6861 (unsigned long long)
6862 sas_device
->enclosure_logical_id
,
6864 _scsih_remove_device(ioc
, sas_device
);
6867 if (!ioc
->ir_firmware
)
6868 goto retry_expander_search
;
6870 list_for_each_entry_safe(raid_device
, raid_device_next
,
6871 &ioc
->raid_device_list
, list
) {
6872 if (raid_device
->responding
) {
6873 raid_device
->responding
= 0;
6876 if (raid_device
->starget
) {
6877 starget_printk(KERN_INFO
, raid_device
->starget
,
6878 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6879 raid_device
->handle
,
6880 (unsigned long long)raid_device
->wwid
);
6881 scsi_remove_target(&raid_device
->starget
->dev
);
6883 _scsih_raid_device_remove(ioc
, raid_device
);
6886 retry_expander_search
:
6887 sas_expander
= NULL
;
6888 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6889 if (sas_expander
->responding
) {
6890 sas_expander
->responding
= 0;
6893 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6894 goto retry_expander_search
;
6896 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: complete\n",
6898 /* unblock devices */
6899 _scsih_ublock_io_all_device(ioc
);
6903 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER
*ioc
,
6904 struct _sas_node
*sas_expander
, u16 handle
)
6906 Mpi2ExpanderPage1_t expander_pg1
;
6907 Mpi2ConfigReply_t mpi_reply
;
6910 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
6911 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
6912 &expander_pg1
, i
, handle
))) {
6913 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6914 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6918 mpt2sas_transport_update_links(ioc
, sas_expander
->sas_address
,
6919 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
6920 expander_pg1
.NegotiatedLinkRate
>> 4);
6925 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6926 * @ioc: per adapter object
6931 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER
*ioc
)
6933 Mpi2ExpanderPage0_t expander_pg0
;
6934 Mpi2SasDevicePage0_t sas_device_pg0
;
6935 Mpi2RaidVolPage1_t volume_pg1
;
6936 Mpi2RaidVolPage0_t volume_pg0
;
6937 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6938 Mpi2EventIrConfigElement_t element
;
6939 Mpi2ConfigReply_t mpi_reply
;
6942 u16 handle
, parent_handle
;
6944 struct _sas_device
*sas_device
;
6945 struct _sas_node
*expander_device
;
6946 static struct _raid_device
*raid_device
;
6948 printk(MPT2SAS_INFO_FMT
"scan devices: start\n", ioc
->name
);
6950 _scsih_sas_host_refresh(ioc
);
6954 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6955 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6956 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6957 MPI2_IOCSTATUS_MASK
;
6958 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6960 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6961 expander_device
= mpt2sas_scsih_expander_find_by_sas_address(
6962 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
6963 if (expander_device
)
6964 _scsih_refresh_expander_links(ioc
, expander_device
,
6967 _scsih_expander_add(ioc
, handle
);
6970 if (!ioc
->ir_firmware
)
6974 phys_disk_num
= 0xFF;
6975 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6976 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6978 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6979 MPI2_IOCSTATUS_MASK
;
6980 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6982 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6983 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6984 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6987 if (mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6988 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6991 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6992 if (!_scsih_get_sas_address(ioc
, parent_handle
,
6994 mpt2sas_transport_update_links(ioc
, sas_address
,
6995 handle
, sas_device_pg0
.PhyNum
,
6996 MPI2_SAS_NEG_LINK_RATE_1_5
);
6997 set_bit(handle
, ioc
->pd_handles
);
6998 _scsih_add_device(ioc
, handle
, 0, 1);
7004 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7005 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7006 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7007 MPI2_IOCSTATUS_MASK
;
7008 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7010 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7011 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7012 le64_to_cpu(volume_pg1
.WWID
));
7015 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7016 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7017 sizeof(Mpi2RaidVolPage0_t
)))
7019 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7020 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7021 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7022 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7023 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7024 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7025 _scsih_sas_volume_add(ioc
, &element
);
7033 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7034 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7036 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7037 MPI2_IOCSTATUS_MASK
;
7038 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7040 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7041 if (!(_scsih_is_end_device(
7042 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7044 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
7045 le64_to_cpu(sas_device_pg0
.SASAddress
));
7048 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7049 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7050 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
7051 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7052 _scsih_add_device(ioc
, handle
, 0, 0);
7056 printk(MPT2SAS_INFO_FMT
"scan devices: complete\n", ioc
->name
);
7061 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7062 * @ioc: per adapter object
7063 * @reset_phase: phase
7065 * The handler for doing any required cleanup or initialization.
7067 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7068 * MPT2_IOC_DONE_RESET
7073 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
7075 switch (reset_phase
) {
7076 case MPT2_IOC_PRE_RESET
:
7077 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7078 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7080 case MPT2_IOC_AFTER_RESET
:
7081 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7082 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7083 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
7084 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
7085 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7086 complete(&ioc
->scsih_cmds
.done
);
7088 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
7089 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
7090 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7091 complete(&ioc
->tm_cmds
.done
);
7093 _scsih_fw_event_cleanup_queue(ioc
);
7094 _scsih_flush_running_cmds(ioc
);
7096 case MPT2_IOC_DONE_RESET
:
7097 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7098 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7099 _scsih_sas_host_refresh(ioc
);
7100 _scsih_prep_device_scan(ioc
);
7101 _scsih_search_responding_sas_devices(ioc
);
7102 _scsih_search_responding_raid_devices(ioc
);
7103 _scsih_search_responding_expanders(ioc
);
7104 if (!ioc
->is_driver_loading
) {
7105 _scsih_prep_device_scan(ioc
);
7106 _scsih_search_responding_sas_devices(ioc
);
7107 _scsih_search_responding_raid_devices(ioc
);
7108 _scsih_search_responding_expanders(ioc
);
7109 _scsih_error_recovery_delete_devices(ioc
);
7116 * _firmware_event_work - delayed task for processing firmware events
7117 * @ioc: per adapter object
7118 * @work: equal to the fw_event_work object
7124 _firmware_event_work(struct work_struct
*work
)
7126 struct fw_event_work
*fw_event
= container_of(work
,
7127 struct fw_event_work
, delayed_work
.work
);
7128 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
7130 /* the queue is being flushed so ignore this event */
7131 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
7132 ioc
->pci_error_recovery
) {
7133 _scsih_fw_event_free(ioc
, fw_event
);
7137 switch (fw_event
->event
) {
7138 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES
:
7139 while (scsi_host_in_recovery(ioc
->shost
))
7141 _scsih_remove_unresponding_sas_devices(ioc
);
7142 _scsih_scan_for_devices_after_reset(ioc
);
7144 case MPT2SAS_PORT_ENABLE_COMPLETE
:
7145 ioc
->start_scan
= 0;
7149 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"port enable: complete "
7150 "from worker thread\n", ioc
->name
));
7152 case MPT2SAS_TURN_ON_FAULT_LED
:
7153 _scsih_turn_on_fault_led(ioc
, fw_event
->device_handle
);
7155 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7156 _scsih_sas_topology_change_event(ioc
, fw_event
);
7158 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7159 _scsih_sas_device_status_change_event(ioc
,
7162 case MPI2_EVENT_SAS_DISCOVERY
:
7163 _scsih_sas_discovery_event(ioc
,
7166 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7167 _scsih_sas_broadcast_primative_event(ioc
,
7170 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7171 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7174 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7175 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7177 case MPI2_EVENT_IR_VOLUME
:
7178 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7180 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7181 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7183 case MPI2_EVENT_IR_OPERATION_STATUS
:
7184 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7187 _scsih_fw_event_free(ioc
, fw_event
);
7191 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7192 * @ioc: per adapter object
7193 * @msix_index: MSIX table index supplied by the OS
7194 * @reply: reply message frame(lower 32bit addr)
7195 * Context: interrupt.
7197 * This function merely adds a new work task into ioc->firmware_event_thread.
7198 * The tasks are worked from _firmware_event_work in user context.
7200 * Return 1 meaning mf should be freed from _base_interrupt
7201 * 0 means the mf is freed from this function.
7204 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
7207 struct fw_event_work
*fw_event
;
7208 Mpi2EventNotificationReply_t
*mpi_reply
;
7212 /* events turned off due to host reset or driver unloading */
7213 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7216 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
7217 event
= le16_to_cpu(mpi_reply
->Event
);
7221 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7223 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7224 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7225 mpi_reply
->EventData
;
7227 if (baen_data
->Primitive
!=
7228 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7231 if (ioc
->broadcast_aen_busy
) {
7232 ioc
->broadcast_aen_pending
++;
7235 ioc
->broadcast_aen_busy
= 1;
7239 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7240 _scsih_check_topo_delete_events(ioc
,
7241 (Mpi2EventDataSasTopologyChangeList_t
*)
7242 mpi_reply
->EventData
);
7244 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7245 _scsih_check_ir_config_unhide_events(ioc
,
7246 (Mpi2EventDataIrConfigChangeList_t
*)
7247 mpi_reply
->EventData
);
7249 case MPI2_EVENT_IR_VOLUME
:
7250 _scsih_check_volume_delete_events(ioc
,
7251 (Mpi2EventDataIrVolume_t
*)
7252 mpi_reply
->EventData
);
7254 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7256 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7259 if (!ioc
->is_warpdrive
)
7262 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7263 mpi_reply
->EventData
;
7264 log_code
= (u32
*)log_entry
->LogData
;
7266 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7267 != MPT2_WARPDRIVE_LOGENTRY
)
7270 switch (le32_to_cpu(*log_code
)) {
7271 case MPT2_WARPDRIVE_LC_SSDT
:
7272 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7273 "IO Throttling has occurred in the WarpDrive "
7274 "subsystem. Check WarpDrive documentation for "
7275 "additional details.\n", ioc
->name
);
7277 case MPT2_WARPDRIVE_LC_SSDLW
:
7278 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7279 "Program/Erase Cycles for the WarpDrive subsystem "
7280 "in degraded range. Check WarpDrive documentation "
7281 "for additional details.\n", ioc
->name
);
7283 case MPT2_WARPDRIVE_LC_SSDLF
:
7284 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7285 "There are no Program/Erase Cycles for the "
7286 "WarpDrive subsystem. The storage device will be "
7287 "in read-only mode. Check WarpDrive documentation "
7288 "for additional details.\n", ioc
->name
);
7290 case MPT2_WARPDRIVE_LC_BRMF
:
7291 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7292 "The Backup Rail Monitor has failed on the "
7293 "WarpDrive subsystem. Check WarpDrive "
7294 "documentation for additional details.\n",
7301 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7302 case MPI2_EVENT_IR_OPERATION_STATUS
:
7303 case MPI2_EVENT_SAS_DISCOVERY
:
7304 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7305 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7308 default: /* ignore the rest */
7312 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
7314 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7315 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7318 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7319 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
7320 if (!fw_event
->event_data
) {
7321 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7322 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7327 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
7329 fw_event
->ioc
= ioc
;
7330 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7331 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7332 fw_event
->event
= event
;
7333 _scsih_fw_event_add(ioc
, fw_event
);
7337 /* shost template */
7338 static struct scsi_host_template scsih_driver_template
= {
7339 .module
= THIS_MODULE
,
7340 .name
= "Fusion MPT SAS Host",
7341 .proc_name
= MPT2SAS_DRIVER_NAME
,
7342 .queuecommand
= _scsih_qcmd
,
7343 .target_alloc
= _scsih_target_alloc
,
7344 .slave_alloc
= _scsih_slave_alloc
,
7345 .slave_configure
= _scsih_slave_configure
,
7346 .target_destroy
= _scsih_target_destroy
,
7347 .slave_destroy
= _scsih_slave_destroy
,
7348 .scan_finished
= _scsih_scan_finished
,
7349 .scan_start
= _scsih_scan_start
,
7350 .change_queue_depth
= _scsih_change_queue_depth
,
7351 .change_queue_type
= _scsih_change_queue_type
,
7352 .eh_abort_handler
= _scsih_abort
,
7353 .eh_device_reset_handler
= _scsih_dev_reset
,
7354 .eh_target_reset_handler
= _scsih_target_reset
,
7355 .eh_host_reset_handler
= _scsih_host_reset
,
7356 .bios_param
= _scsih_bios_param
,
7359 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
7360 .max_sectors
= 8192,
7362 .use_clustering
= ENABLE_CLUSTERING
,
7363 .shost_attrs
= mpt2sas_host_attrs
,
7364 .sdev_attrs
= mpt2sas_dev_attrs
,
7368 * _scsih_expander_node_remove - removing expander device from list.
7369 * @ioc: per adapter object
7370 * @sas_expander: the sas_device object
7371 * Context: Calling function should acquire ioc->sas_node_lock.
7373 * Removing object and freeing associated memory from the
7374 * ioc->sas_expander_list.
7379 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
7380 struct _sas_node
*sas_expander
)
7382 struct _sas_port
*mpt2sas_port
, *next
;
7384 /* remove sibling ports attached to this expander */
7385 list_for_each_entry_safe(mpt2sas_port
, next
,
7386 &sas_expander
->sas_port_list
, port_list
) {
7387 if (ioc
->shost_recovery
)
7389 if (mpt2sas_port
->remote_identify
.device_type
==
7391 mpt2sas_device_remove(ioc
,
7392 mpt2sas_port
->remote_identify
.sas_address
);
7393 else if (mpt2sas_port
->remote_identify
.device_type
==
7394 SAS_EDGE_EXPANDER_DEVICE
||
7395 mpt2sas_port
->remote_identify
.device_type
==
7396 SAS_FANOUT_EXPANDER_DEVICE
)
7397 mpt2sas_expander_remove(ioc
,
7398 mpt2sas_port
->remote_identify
.sas_address
);
7401 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7402 sas_expander
->sas_address_parent
);
7404 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
7405 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7406 sas_expander
->handle
, (unsigned long long)
7407 sas_expander
->sas_address
);
7409 kfree(sas_expander
->phy
);
7410 kfree(sas_expander
);
7414 * _scsih_ir_shutdown - IR shutdown notification
7415 * @ioc: per adapter object
7417 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7418 * the host system is shutting down.
7423 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
7425 Mpi2RaidActionRequest_t
*mpi_request
;
7426 Mpi2RaidActionReply_t
*mpi_reply
;
7429 /* is IR firmware build loaded ? */
7430 if (!ioc
->ir_firmware
)
7433 /* are there any volumes ? */
7434 if (list_empty(&ioc
->raid_device_list
))
7437 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7439 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
7440 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
7441 ioc
->name
, __func__
);
7444 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
7446 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7448 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
7449 ioc
->name
, __func__
);
7450 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7454 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
7455 ioc
->scsih_cmds
.smid
= smid
;
7456 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7458 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7459 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7461 if (!ioc
->hide_ir_msg
)
7462 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
7463 init_completion(&ioc
->scsih_cmds
.done
);
7464 mpt2sas_base_put_smid_default(ioc
, smid
);
7465 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7467 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
7468 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
7469 ioc
->name
, __func__
);
7473 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
7474 mpi_reply
= ioc
->scsih_cmds
.reply
;
7476 if (!ioc
->hide_ir_msg
)
7477 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
7478 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7479 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7480 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7484 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7485 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7489 * _scsih_shutdown - routine call during system shutdown
7490 * @pdev: PCI device struct
7495 _scsih_shutdown(struct pci_dev
*pdev
)
7497 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7498 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7499 struct workqueue_struct
*wq
;
7500 unsigned long flags
;
7502 ioc
->remove_host
= 1;
7503 _scsih_fw_event_cleanup_queue(ioc
);
7505 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7506 wq
= ioc
->firmware_event_thread
;
7507 ioc
->firmware_event_thread
= NULL
;
7508 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7510 destroy_workqueue(wq
);
7512 _scsih_ir_shutdown(ioc
);
7513 mpt2sas_base_detach(ioc
);
7517 * _scsih_remove - detach and remove add host
7518 * @pdev: PCI device struct
7520 * Routine called when unloading the driver.
7523 static void __devexit
7524 _scsih_remove(struct pci_dev
*pdev
)
7526 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7527 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7528 struct _sas_port
*mpt2sas_port
, *next_port
;
7529 struct _raid_device
*raid_device
, *next
;
7530 struct MPT2SAS_TARGET
*sas_target_priv_data
;
7531 struct workqueue_struct
*wq
;
7532 unsigned long flags
;
7534 ioc
->remove_host
= 1;
7535 _scsih_fw_event_cleanup_queue(ioc
);
7537 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7538 wq
= ioc
->firmware_event_thread
;
7539 ioc
->firmware_event_thread
= NULL
;
7540 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7542 destroy_workqueue(wq
);
7544 /* release all the volumes */
7545 _scsih_ir_shutdown(ioc
);
7546 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7548 if (raid_device
->starget
) {
7549 sas_target_priv_data
=
7550 raid_device
->starget
->hostdata
;
7551 sas_target_priv_data
->deleted
= 1;
7552 scsi_remove_target(&raid_device
->starget
->dev
);
7554 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
7555 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
7556 (unsigned long long) raid_device
->wwid
);
7557 _scsih_raid_device_remove(ioc
, raid_device
);
7560 /* free ports attached to the sas_host */
7561 list_for_each_entry_safe(mpt2sas_port
, next_port
,
7562 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7563 if (mpt2sas_port
->remote_identify
.device_type
==
7565 mpt2sas_device_remove(ioc
,
7566 mpt2sas_port
->remote_identify
.sas_address
);
7567 else if (mpt2sas_port
->remote_identify
.device_type
==
7568 SAS_EDGE_EXPANDER_DEVICE
||
7569 mpt2sas_port
->remote_identify
.device_type
==
7570 SAS_FANOUT_EXPANDER_DEVICE
)
7571 mpt2sas_expander_remove(ioc
,
7572 mpt2sas_port
->remote_identify
.sas_address
);
7575 /* free phys attached to the sas_host */
7576 if (ioc
->sas_hba
.num_phys
) {
7577 kfree(ioc
->sas_hba
.phy
);
7578 ioc
->sas_hba
.phy
= NULL
;
7579 ioc
->sas_hba
.num_phys
= 0;
7582 sas_remove_host(shost
);
7583 mpt2sas_base_detach(ioc
);
7584 list_del(&ioc
->list
);
7585 scsi_remove_host(shost
);
7586 scsi_host_put(shost
);
7590 * _scsih_probe_boot_devices - reports 1st device
7591 * @ioc: per adapter object
7593 * If specified in bios page 2, this routine reports the 1st
7594 * device scsi-ml or sas transport for persistent boot device
7595 * purposes. Please refer to function _scsih_determine_boot_device()
7598 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
7602 struct _sas_device
*sas_device
;
7603 struct _raid_device
*raid_device
;
7605 u64 sas_address_parent
;
7607 unsigned long flags
;
7610 /* no Bios, return immediately */
7611 if (!ioc
->bios_pg3
.BiosVersion
)
7616 if (ioc
->req_boot_device
.device
) {
7617 device
= ioc
->req_boot_device
.device
;
7618 is_raid
= ioc
->req_boot_device
.is_raid
;
7619 } else if (ioc
->req_alt_boot_device
.device
) {
7620 device
= ioc
->req_alt_boot_device
.device
;
7621 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7622 } else if (ioc
->current_boot_device
.device
) {
7623 device
= ioc
->current_boot_device
.device
;
7624 is_raid
= ioc
->current_boot_device
.is_raid
;
7631 raid_device
= device
;
7632 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7633 raid_device
->id
, 0);
7635 _scsih_raid_device_remove(ioc
, raid_device
);
7637 sas_device
= device
;
7638 handle
= sas_device
->handle
;
7639 sas_address_parent
= sas_device
->sas_address_parent
;
7640 sas_address
= sas_device
->sas_address
;
7641 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7642 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7643 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7645 if (ioc
->hide_drives
)
7647 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7648 sas_device
->sas_address_parent
)) {
7649 _scsih_sas_device_remove(ioc
, sas_device
);
7650 } else if (!sas_device
->starget
) {
7651 mpt2sas_transport_port_remove(ioc
, sas_address
,
7652 sas_address_parent
);
7653 _scsih_sas_device_remove(ioc
, sas_device
);
7659 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7660 * @ioc: per adapter object
7662 * Called during initial loading of the driver.
7665 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
7667 struct _raid_device
*raid_device
, *raid_next
;
7670 list_for_each_entry_safe(raid_device
, raid_next
,
7671 &ioc
->raid_device_list
, list
) {
7672 if (raid_device
->starget
)
7674 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7675 raid_device
->id
, 0);
7677 _scsih_raid_device_remove(ioc
, raid_device
);
7682 * _scsih_probe_sas - reporting sas devices to sas transport
7683 * @ioc: per adapter object
7685 * Called during initial loading of the driver.
7688 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
7690 struct _sas_device
*sas_device
, *next
;
7691 unsigned long flags
;
7693 /* SAS Device List */
7694 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7697 if (ioc
->hide_drives
)
7700 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7701 sas_device
->sas_address_parent
)) {
7702 list_del(&sas_device
->list
);
7705 } else if (!sas_device
->starget
) {
7706 mpt2sas_transport_port_remove(ioc
,
7707 sas_device
->sas_address
,
7708 sas_device
->sas_address_parent
);
7709 list_del(&sas_device
->list
);
7714 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7715 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7716 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7721 * _scsih_probe_devices - probing for devices
7722 * @ioc: per adapter object
7724 * Called during initial loading of the driver.
7727 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
7729 u16 volume_mapping_flags
;
7731 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
7732 return; /* return when IOC doesn't support initiator mode */
7734 _scsih_probe_boot_devices(ioc
);
7736 if (ioc
->ir_firmware
) {
7737 volume_mapping_flags
=
7738 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
7739 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
7740 if (volume_mapping_flags
==
7741 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
7742 _scsih_probe_raid(ioc
);
7743 _scsih_probe_sas(ioc
);
7745 _scsih_probe_sas(ioc
);
7746 _scsih_probe_raid(ioc
);
7749 _scsih_probe_sas(ioc
);
7754 * _scsih_scan_start - scsi lld callback for .scan_start
7755 * @shost: SCSI host pointer
7757 * The shost has the ability to discover targets on its own instead
7758 * of scanning the entire bus. In our implemention, we will kick off
7759 * firmware discovery.
7762 _scsih_scan_start(struct Scsi_Host
*shost
)
7764 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7767 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
7768 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
7770 ioc
->start_scan
= 1;
7771 rc
= mpt2sas_port_enable(ioc
);
7774 printk(MPT2SAS_INFO_FMT
"port enable: FAILED\n", ioc
->name
);
7778 * _scsih_scan_finished - scsi lld callback for .scan_finished
7779 * @shost: SCSI host pointer
7780 * @time: elapsed time of the scan in jiffies
7782 * This function will be called periodically until it returns 1 with the
7783 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7784 * we wait for firmware discovery to complete, then return 1.
7787 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
7789 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7791 if (time
>= (300 * HZ
)) {
7792 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
7793 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with timeout "
7794 "(timeout=300s)\n", ioc
->name
);
7795 ioc
->is_driver_loading
= 0;
7799 if (ioc
->start_scan
)
7802 if (ioc
->start_scan_failed
) {
7803 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with "
7804 "(ioc_status=0x%08x)\n", ioc
->name
, ioc
->start_scan_failed
);
7805 ioc
->is_driver_loading
= 0;
7806 ioc
->wait_for_discovery_to_complete
= 0;
7807 ioc
->remove_host
= 1;
7811 printk(MPT2SAS_INFO_FMT
"port enable: SUCCESS\n", ioc
->name
);
7812 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
7814 if (ioc
->wait_for_discovery_to_complete
) {
7815 ioc
->wait_for_discovery_to_complete
= 0;
7816 _scsih_probe_devices(ioc
);
7818 mpt2sas_base_start_watchdog(ioc
);
7819 ioc
->is_driver_loading
= 0;
7825 * _scsih_probe - attach and add scsi host
7826 * @pdev: PCI device struct
7827 * @id: pci device id
7829 * Returns 0 success, anything else error.
7832 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
7834 struct MPT2SAS_ADAPTER
*ioc
;
7835 struct Scsi_Host
*shost
;
7837 shost
= scsi_host_alloc(&scsih_driver_template
,
7838 sizeof(struct MPT2SAS_ADAPTER
));
7842 /* init local params */
7843 ioc
= shost_priv(shost
);
7844 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
7845 INIT_LIST_HEAD(&ioc
->list
);
7846 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
7848 ioc
->id
= mpt_ids
++;
7849 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
7851 if (id
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
7852 ioc
->is_warpdrive
= 1;
7853 ioc
->hide_ir_msg
= 1;
7855 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
7856 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
7857 ioc
->tm_cb_idx
= tm_cb_idx
;
7858 ioc
->ctl_cb_idx
= ctl_cb_idx
;
7859 ioc
->base_cb_idx
= base_cb_idx
;
7860 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
7861 ioc
->transport_cb_idx
= transport_cb_idx
;
7862 ioc
->scsih_cb_idx
= scsih_cb_idx
;
7863 ioc
->config_cb_idx
= config_cb_idx
;
7864 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
7865 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
7866 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
7867 ioc
->logging_level
= logging_level
;
7868 /* misc semaphores and spin locks */
7869 mutex_init(&ioc
->reset_in_progress_mutex
);
7870 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
7871 spin_lock_init(&ioc
->scsi_lookup_lock
);
7872 spin_lock_init(&ioc
->sas_device_lock
);
7873 spin_lock_init(&ioc
->sas_node_lock
);
7874 spin_lock_init(&ioc
->fw_event_lock
);
7875 spin_lock_init(&ioc
->raid_device_lock
);
7877 INIT_LIST_HEAD(&ioc
->sas_device_list
);
7878 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
7879 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
7880 INIT_LIST_HEAD(&ioc
->fw_event_list
);
7881 INIT_LIST_HEAD(&ioc
->raid_device_list
);
7882 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
7883 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
7884 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
7886 /* init shost parameters */
7887 shost
->max_cmd_len
= 32;
7888 shost
->max_lun
= max_lun
;
7889 shost
->transportt
= mpt2sas_transport_template
;
7890 shost
->unique_id
= ioc
->id
;
7892 if (max_sectors
!= 0xFFFF) {
7893 if (max_sectors
< 64) {
7894 shost
->max_sectors
= 64;
7895 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
7896 "for max_sectors, range is 64 to 8192. Assigning "
7897 "value of 64.\n", ioc
->name
, max_sectors
);
7898 } else if (max_sectors
> 8192) {
7899 shost
->max_sectors
= 8192;
7900 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
7901 "for max_sectors, range is 64 to 8192. Assigning "
7902 "default value of 8192.\n", ioc
->name
,
7905 shost
->max_sectors
= max_sectors
& 0xFFFE;
7906 printk(MPT2SAS_INFO_FMT
"The max_sectors value is "
7907 "set to %d\n", ioc
->name
, shost
->max_sectors
);
7911 if ((scsi_add_host(shost
, &pdev
->dev
))) {
7912 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7913 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7914 list_del(&ioc
->list
);
7915 goto out_add_shost_fail
;
7918 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
7919 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
7920 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
7923 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
7924 "fw_event%d", ioc
->id
);
7925 ioc
->firmware_event_thread
= create_singlethread_workqueue(
7926 ioc
->firmware_event_name
);
7927 if (!ioc
->firmware_event_thread
) {
7928 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7929 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7930 goto out_thread_fail
;
7933 ioc
->is_driver_loading
= 1;
7934 if ((mpt2sas_base_attach(ioc
))) {
7935 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7936 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7937 goto out_attach_fail
;
7940 scsi_scan_host(shost
);
7941 if (ioc
->is_warpdrive
) {
7942 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
7943 ioc
->hide_drives
= 0;
7944 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
7945 ioc
->hide_drives
= 1;
7947 if (_scsih_get_num_volumes(ioc
))
7948 ioc
->hide_drives
= 1;
7950 ioc
->hide_drives
= 0;
7953 ioc
->hide_drives
= 0;
7955 _scsih_probe_devices(ioc
);
7959 destroy_workqueue(ioc
->firmware_event_thread
);
7961 list_del(&ioc
->list
);
7962 scsi_remove_host(shost
);
7963 scsi_host_put(shost
);
7970 * _scsih_suspend - power management suspend main entry point
7971 * @pdev: PCI device struct
7972 * @state: PM state change to (usually PCI_D3)
7974 * Returns 0 success, anything else error.
7977 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7979 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7980 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7981 pci_power_t device_state
;
7983 mpt2sas_base_stop_watchdog(ioc
);
7984 scsi_block_requests(shost
);
7985 device_state
= pci_choose_state(pdev
, state
);
7986 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
7987 "operating state [D%d]\n", ioc
->name
, pdev
,
7988 pci_name(pdev
), device_state
);
7990 mpt2sas_base_free_resources(ioc
);
7991 pci_save_state(pdev
);
7992 pci_disable_device(pdev
);
7993 pci_set_power_state(pdev
, device_state
);
7998 * _scsih_resume - power management resume main entry point
7999 * @pdev: PCI device struct
8001 * Returns 0 success, anything else error.
8004 _scsih_resume(struct pci_dev
*pdev
)
8006 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8007 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8008 pci_power_t device_state
= pdev
->current_state
;
8011 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
8012 "operating state [D%d]\n", ioc
->name
, pdev
,
8013 pci_name(pdev
), device_state
);
8015 pci_set_power_state(pdev
, PCI_D0
);
8016 pci_enable_wake(pdev
, PCI_D0
, 0);
8017 pci_restore_state(pdev
);
8019 r
= mpt2sas_base_map_resources(ioc
);
8023 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8024 scsi_unblock_requests(shost
);
8025 mpt2sas_base_start_watchdog(ioc
);
8028 #endif /* CONFIG_PM */
8031 * _scsih_pci_error_detected - Called when a PCI error is detected.
8032 * @pdev: PCI device struct
8033 * @state: PCI channel state
8035 * Description: Called when a PCI error is detected.
8038 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8040 static pci_ers_result_t
8041 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8043 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8044 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8046 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
8050 case pci_channel_io_normal
:
8051 return PCI_ERS_RESULT_CAN_RECOVER
;
8052 case pci_channel_io_frozen
:
8053 /* Fatal error, prepare for slot reset */
8054 ioc
->pci_error_recovery
= 1;
8055 scsi_block_requests(ioc
->shost
);
8056 mpt2sas_base_stop_watchdog(ioc
);
8057 mpt2sas_base_free_resources(ioc
);
8058 return PCI_ERS_RESULT_NEED_RESET
;
8059 case pci_channel_io_perm_failure
:
8060 /* Permanent error, prepare for device removal */
8061 ioc
->pci_error_recovery
= 1;
8062 mpt2sas_base_stop_watchdog(ioc
);
8063 _scsih_flush_running_cmds(ioc
);
8064 return PCI_ERS_RESULT_DISCONNECT
;
8066 return PCI_ERS_RESULT_NEED_RESET
;
8070 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8071 * @pdev: PCI device struct
8073 * Description: This routine is called by the pci error recovery
8074 * code after the PCI slot has been reset, just before we
8075 * should resume normal operations.
8077 static pci_ers_result_t
8078 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
8080 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8081 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8084 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
8087 ioc
->pci_error_recovery
= 0;
8089 pci_restore_state(pdev
);
8090 rc
= mpt2sas_base_map_resources(ioc
);
8092 return PCI_ERS_RESULT_DISCONNECT
;
8095 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8098 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
8099 (rc
== 0) ? "success" : "failed");
8102 return PCI_ERS_RESULT_RECOVERED
;
8104 return PCI_ERS_RESULT_DISCONNECT
;
8108 * _scsih_pci_resume() - resume normal ops after PCI reset
8109 * @pdev: pointer to PCI device
8111 * Called when the error recovery driver tells us that its
8112 * OK to resume normal operation. Use completion to allow
8113 * halted scsi ops to resume.
8116 _scsih_pci_resume(struct pci_dev
*pdev
)
8118 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8119 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8121 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8123 pci_cleanup_aer_uncorrect_error_status(pdev
);
8124 mpt2sas_base_start_watchdog(ioc
);
8125 scsi_unblock_requests(ioc
->shost
);
8129 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8130 * @pdev: pointer to PCI device
8132 static pci_ers_result_t
8133 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8135 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8136 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8138 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
8141 /* TODO - dump whatever for debugging purposes */
8143 /* Request a slot reset. */
8144 return PCI_ERS_RESULT_NEED_RESET
;
8147 static struct pci_error_handlers _scsih_err_handler
= {
8148 .error_detected
= _scsih_pci_error_detected
,
8149 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8150 .slot_reset
= _scsih_pci_slot_reset
,
8151 .resume
= _scsih_pci_resume
,
8154 static struct pci_driver scsih_driver
= {
8155 .name
= MPT2SAS_DRIVER_NAME
,
8156 .id_table
= scsih_pci_table
,
8157 .probe
= _scsih_probe
,
8158 .remove
= __devexit_p(_scsih_remove
),
8159 .shutdown
= _scsih_shutdown
,
8160 .err_handler
= &_scsih_err_handler
,
8162 .suspend
= _scsih_suspend
,
8163 .resume
= _scsih_resume
,
8167 /* raid transport support */
8168 static struct raid_function_template mpt2sas_raid_functions
= {
8169 .cookie
= &scsih_driver_template
,
8170 .is_raid
= _scsih_is_raid
,
8171 .get_resync
= _scsih_get_resync
,
8172 .get_state
= _scsih_get_state
,
8176 * _scsih_init - main entry point for this driver.
8178 * Returns 0 success, anything else error.
8186 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
8187 MPT2SAS_DRIVER_VERSION
);
8189 mpt2sas_transport_template
=
8190 sas_attach_transport(&mpt2sas_transport_functions
);
8191 if (!mpt2sas_transport_template
)
8193 /* raid transport support */
8194 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
8195 if (!mpt2sas_raid_template
) {
8196 sas_release_transport(mpt2sas_transport_template
);
8200 mpt2sas_base_initialize_callback_handler();
8202 /* queuecommand callback hander */
8203 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
8205 /* task management callback handler */
8206 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
8208 /* base internal commands callback handler */
8209 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
8210 port_enable_cb_idx
= mpt2sas_base_register_callback_handler(
8211 mpt2sas_port_enable_done
);
8213 /* transport internal commands callback handler */
8214 transport_cb_idx
= mpt2sas_base_register_callback_handler(
8215 mpt2sas_transport_done
);
8217 /* scsih internal commands callback handler */
8218 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
8220 /* configuration page API internal commands callback handler */
8221 config_cb_idx
= mpt2sas_base_register_callback_handler(
8222 mpt2sas_config_done
);
8224 /* ctl module callback handler */
8225 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
8227 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
8228 _scsih_tm_tr_complete
);
8230 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
8231 _scsih_tm_volume_tr_complete
);
8233 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
8234 _scsih_sas_control_complete
);
8238 error
= pci_register_driver(&scsih_driver
);
8240 /* raid transport support */
8241 raid_class_release(mpt2sas_raid_template
);
8242 sas_release_transport(mpt2sas_transport_template
);
8249 * _scsih_exit - exit point for this driver (when it is a module).
8251 * Returns 0 success, anything else error.
8256 printk(KERN_INFO
"mpt2sas version %s unloading\n",
8257 MPT2SAS_DRIVER_VERSION
);
8259 pci_unregister_driver(&scsih_driver
);
8263 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
8264 mpt2sas_base_release_callback_handler(tm_cb_idx
);
8265 mpt2sas_base_release_callback_handler(base_cb_idx
);
8266 mpt2sas_base_release_callback_handler(port_enable_cb_idx
);
8267 mpt2sas_base_release_callback_handler(transport_cb_idx
);
8268 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
8269 mpt2sas_base_release_callback_handler(config_cb_idx
);
8270 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
8272 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
8273 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8274 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8276 /* raid transport support */
8277 raid_class_release(mpt2sas_raid_template
);
8278 sas_release_transport(mpt2sas_transport_template
);
8282 module_init(_scsih_init
);
8283 module_exit(_scsih_exit
);