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
1625 * Returns 0 for success, else 1
1628 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1629 struct _raid_device
*raid_device
)
1631 Mpi2RaidVolPage0_t
*vol_pg0
;
1632 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1633 Mpi2SasDevicePage0_t sas_device_pg0
;
1634 Mpi2ConfigReply_t mpi_reply
;
1638 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1639 &num_pds
)) || !num_pds
) {
1640 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1641 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1646 raid_device
->num_pds
= num_pds
;
1647 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1648 sizeof(Mpi2RaidVol0PhysDisk_t
));
1649 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1651 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1652 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1657 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1658 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1659 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1660 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1666 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1668 /* figure out what the underlying devices are by
1669 * obtaining the device_info bits for the 1st device
1671 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1672 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1673 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1674 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1675 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1676 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1677 raid_device
->device_info
=
1678 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1686 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1687 * @ioc: per adapter object
1690 _scsih_disable_ddio(struct MPT2SAS_ADAPTER
*ioc
)
1692 Mpi2RaidVolPage1_t vol_pg1
;
1693 Mpi2ConfigReply_t mpi_reply
;
1694 struct _raid_device
*raid_device
;
1699 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1700 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1701 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1702 MPI2_IOCSTATUS_MASK
;
1703 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1705 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1706 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1708 raid_device
->direct_io_enabled
= 0;
1715 * _scsih_get_num_volumes - Get number of volumes in the ioc
1716 * @ioc: per adapter object
1719 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER
*ioc
)
1721 Mpi2RaidVolPage1_t vol_pg1
;
1722 Mpi2ConfigReply_t mpi_reply
;
1728 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1729 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1730 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1731 MPI2_IOCSTATUS_MASK
;
1732 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1735 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1742 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1743 * @ioc: per adapter object
1744 * @raid_device: the raid_device object
1747 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER
*ioc
,
1748 struct _raid_device
*raid_device
)
1750 Mpi2RaidVolPage0_t
*vol_pg0
;
1751 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1752 Mpi2ConfigReply_t mpi_reply
;
1755 u64 mb
= 1024 * 1024;
1756 u64 tb_2
= 2 * mb
* mb
;
1761 if (!ioc
->is_warpdrive
)
1764 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
) {
1765 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1766 "globally as drives are exposed\n", ioc
->name
);
1769 if (_scsih_get_num_volumes(ioc
) > 1) {
1770 _scsih_disable_ddio(ioc
);
1771 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1772 "globally as number of drives > 1\n", ioc
->name
);
1775 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1776 &num_pds
)) || !num_pds
) {
1777 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1778 "Failure in computing number of drives\n", ioc
->name
);
1782 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1783 sizeof(Mpi2RaidVol0PhysDisk_t
));
1784 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1786 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1787 "Memory allocation failure for RVPG0\n", ioc
->name
);
1791 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1792 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1793 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1794 "Failure in retrieving RVPG0\n", ioc
->name
);
1800 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1801 * assumed for WARPDRIVE, disable direct I/O
1803 if (num_pds
> MPT_MAX_WARPDRIVE_PDS
) {
1804 printk(MPT2SAS_WARN_FMT
"WarpDrive : Direct IO is disabled "
1805 "for the drive with handle(0x%04x): num_mem=%d, "
1806 "max_mem_allowed=%d\n", ioc
->name
, raid_device
->handle
,
1807 num_pds
, MPT_MAX_WARPDRIVE_PDS
);
1811 for (count
= 0; count
< num_pds
; count
++) {
1812 if (mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1813 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1814 vol_pg0
->PhysDisk
[count
].PhysDiskNum
) ||
1815 pd_pg0
.DevHandle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
1816 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1817 "disabled for the drive with handle(0x%04x) member"
1818 "handle retrieval failed for member number=%d\n",
1819 ioc
->name
, raid_device
->handle
,
1820 vol_pg0
->PhysDisk
[count
].PhysDiskNum
);
1823 raid_device
->pd_handle
[count
] = le16_to_cpu(pd_pg0
.DevHandle
);
1827 * Assumption for WD: Direct I/O is not supported if the volume is
1828 * not RAID0, if the stripe size is not 64KB, if the block size is
1829 * not 512 and if the volume size is >2TB
1831 if (raid_device
->volume_type
!= MPI2_RAID_VOL_TYPE_RAID0
||
1832 le16_to_cpu(vol_pg0
->BlockSize
) != 512) {
1833 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1834 "for the drive with handle(0x%04x): type=%d, "
1835 "s_sz=%uK, blk_size=%u\n", ioc
->name
,
1836 raid_device
->handle
, raid_device
->volume_type
,
1837 le32_to_cpu(vol_pg0
->StripeSize
)/2,
1838 le16_to_cpu(vol_pg0
->BlockSize
));
1842 capacity
= (u64
) le16_to_cpu(vol_pg0
->BlockSize
) *
1843 (le64_to_cpu(vol_pg0
->MaxLBA
) + 1);
1845 if (capacity
> tb_2
) {
1846 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1847 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1848 ioc
->name
, raid_device
->handle
);
1852 stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1854 for (i
= 0; i
< 32; i
++) {
1861 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1862 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1863 ioc
->name
, raid_device
->handle
,
1864 le32_to_cpu(vol_pg0
->StripeSize
)/2);
1867 raid_device
->stripe_exponent
= stripe_exp
;
1868 raid_device
->direct_io_enabled
= 1;
1870 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is Enabled for the drive"
1871 " with handle(0x%04x)\n", ioc
->name
, raid_device
->handle
);
1873 * WARPDRIVE: Though the following fields are not used for direct IO,
1874 * stored for future purpose:
1876 raid_device
->max_lba
= le64_to_cpu(vol_pg0
->MaxLBA
);
1877 raid_device
->stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1878 raid_device
->block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1885 raid_device
->direct_io_enabled
= 0;
1886 for (count
= 0; count
< num_pds
; count
++)
1887 raid_device
->pd_handle
[count
] = 0;
1893 * _scsih_enable_tlr - setting TLR flags
1894 * @ioc: per adapter object
1895 * @sdev: scsi device struct
1897 * Enabling Transaction Layer Retries for tape devices when
1898 * vpd page 0x90 is present
1902 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1905 if (sdev
->type
!= TYPE_TAPE
)
1908 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1911 sas_enable_tlr(sdev
);
1912 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1913 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1919 * _scsih_slave_configure - device configure routine.
1920 * @sdev: scsi device struct
1922 * Returns 0 if ok. Any other return is assumed to be an error and
1923 * the device is ignored.
1926 _scsih_slave_configure(struct scsi_device
*sdev
)
1928 struct Scsi_Host
*shost
= sdev
->host
;
1929 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1930 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1931 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1932 struct _sas_device
*sas_device
;
1933 struct _raid_device
*raid_device
;
1934 unsigned long flags
;
1941 sas_device_priv_data
= sdev
->hostdata
;
1942 sas_device_priv_data
->configured_lun
= 1;
1943 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1944 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1946 /* raid volume handling */
1947 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1949 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1950 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1951 sas_target_priv_data
->handle
);
1952 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1954 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1955 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1956 __LINE__
, __func__
));
1960 _scsih_get_volume_capabilities(ioc
, raid_device
);
1962 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1963 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1964 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1965 __LINE__
, __func__
));
1969 * WARPDRIVE: Initialize the required data for Direct IO
1971 _scsih_init_warpdrive_properties(ioc
, raid_device
);
1973 /* RAID Queue Depth Support
1974 * IS volume = underlying qdepth of drive type, either
1975 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1976 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1978 if (raid_device
->device_info
&
1979 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
1980 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
1983 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1984 if (raid_device
->device_info
&
1985 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1991 switch (raid_device
->volume_type
) {
1992 case MPI2_RAID_VOL_TYPE_RAID0
:
1995 case MPI2_RAID_VOL_TYPE_RAID1E
:
1996 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
1997 if (ioc
->manu_pg10
.OEMIdentifier
&&
1998 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
1999 MFG10_GF0_R10_DISPLAY
) &&
2000 !(raid_device
->num_pds
% 2))
2005 case MPI2_RAID_VOL_TYPE_RAID1
:
2006 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2009 case MPI2_RAID_VOL_TYPE_RAID10
:
2010 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2013 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2015 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2020 if (!ioc
->hide_ir_msg
)
2021 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2022 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2023 r_level
, raid_device
->handle
,
2024 (unsigned long long)raid_device
->wwid
,
2025 raid_device
->num_pds
, ds
);
2026 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2027 /* raid transport support */
2028 if (!ioc
->is_warpdrive
)
2029 _scsih_set_level(sdev
, raid_device
);
2033 /* non-raid handling */
2034 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2035 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2036 sas_device_priv_data
->sas_target
->sas_address
);
2037 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2039 if (sas_target_priv_data
->flags
&
2040 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2041 if (mpt2sas_config_get_volume_handle(ioc
,
2042 sas_device
->handle
, &sas_device
->volume_handle
)) {
2043 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2044 "failure at %s:%d/%s()!\n", ioc
->name
,
2045 __FILE__
, __LINE__
, __func__
));
2048 if (mpt2sas_config_get_volume_wwid(ioc
,
2049 sas_device
->volume_handle
,
2050 &sas_device
->volume_wwid
)) {
2051 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2052 "failure at %s:%d/%s()!\n", ioc
->name
,
2053 __FILE__
, __LINE__
, __func__
));
2057 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2058 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2062 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2063 if (sas_device
->device_info
&
2064 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2066 else if (sas_device
->device_info
&
2067 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2071 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2072 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2073 ds
, sas_device
->handle
,
2074 (unsigned long long)sas_device
->sas_address
,
2076 (unsigned long long)sas_device
->device_name
);
2077 sdev_printk(KERN_INFO
, sdev
, "%s: "
2078 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
2079 (unsigned long long) sas_device
->enclosure_logical_id
,
2083 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
2085 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2086 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2091 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2094 sas_read_port_mode_page(sdev
);
2095 _scsih_enable_tlr(ioc
, sdev
);
2101 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2102 * @sdev: scsi device struct
2103 * @bdev: pointer to block device context
2104 * @capacity: device size (in 512 byte sectors)
2105 * @params: three element array to place output:
2106 * params[0] number of heads (max 255)
2107 * params[1] number of sectors (max 63)
2108 * params[2] number of cylinders
2113 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2114 sector_t capacity
, int params
[])
2124 dummy
= heads
* sectors
;
2125 cylinders
= capacity
;
2126 sector_div(cylinders
, dummy
);
2129 * Handle extended translation size for logical drives
2132 if ((ulong
)capacity
>= 0x200000) {
2135 dummy
= heads
* sectors
;
2136 cylinders
= capacity
;
2137 sector_div(cylinders
, dummy
);
2142 params
[1] = sectors
;
2143 params
[2] = cylinders
;
2149 * _scsih_response_code - translation of device response code
2150 * @ioc: per adapter object
2151 * @response_code: response code returned by the device
2156 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
2160 switch (response_code
) {
2161 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2162 desc
= "task management request completed";
2164 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2165 desc
= "invalid frame";
2167 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2168 desc
= "task management request not supported";
2170 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2171 desc
= "task management request failed";
2173 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2174 desc
= "task management request succeeded";
2176 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2177 desc
= "invalid lun";
2180 desc
= "overlapped tag attempted";
2182 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2183 desc
= "task queued, however not sent to target";
2189 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
2190 ioc
->name
, response_code
, desc
);
2194 * _scsih_tm_done - tm completion routine
2195 * @ioc: per adapter object
2196 * @smid: system request message index
2197 * @msix_index: MSIX table index supplied by the OS
2198 * @reply: reply message frame(lower 32bit addr)
2201 * The callback handler when using scsih_issue_tm.
2203 * Return 1 meaning mf should be freed from _base_interrupt
2204 * 0 means the mf is freed from this function.
2207 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2209 MPI2DefaultReply_t
*mpi_reply
;
2211 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
2213 if (ioc
->tm_cmds
.smid
!= smid
)
2215 mpt2sas_base_flush_reply_queues(ioc
);
2216 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
2217 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2219 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2220 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
2222 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
2223 complete(&ioc
->tm_cmds
.done
);
2228 * mpt2sas_scsih_set_tm_flag - set 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_set_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
= 1;
2250 ioc
->ignore_loginfos
= 1;
2256 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2257 * @ioc: per adapter object
2258 * @handle: device handle
2260 * During taskmangement request, we need to freeze the device queue.
2263 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2265 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2266 struct scsi_device
*sdev
;
2269 shost_for_each_device(sdev
, ioc
->shost
) {
2272 sas_device_priv_data
= sdev
->hostdata
;
2273 if (!sas_device_priv_data
)
2275 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2276 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2278 ioc
->ignore_loginfos
= 0;
2285 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2286 * @ioc: per adapter struct
2287 * @device_handle: device handle
2288 * @channel: the channel assigned by the OS
2289 * @id: the id assigned by the OS
2291 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2292 * @smid_task: smid assigned to the task
2293 * @timeout: timeout in seconds
2294 * @serial_number: the serial_number from scmd
2295 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2298 * A generic API for sending task management requests to firmware.
2300 * The callback index is set inside `ioc->tm_cb_idx`.
2302 * Return SUCCESS or FAILED.
2305 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2306 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2307 unsigned long serial_number
, enum mutex_type m_type
)
2309 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2310 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2313 unsigned long timeleft
;
2314 struct scsiio_tracker
*scsi_lookup
= NULL
;
2317 if (m_type
== TM_MUTEX_ON
)
2318 mutex_lock(&ioc
->tm_cmds
.mutex
);
2319 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2320 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2321 __func__
, ioc
->name
);
2326 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2327 ioc
->pci_error_recovery
) {
2328 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2329 __func__
, ioc
->name
);
2334 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2335 if (ioc_state
& MPI2_DOORBELL_USED
) {
2336 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2337 "active!\n", ioc
->name
));
2338 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2340 rc
= (!rc
) ? SUCCESS
: FAILED
;
2344 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2345 mpt2sas_base_fault_info(ioc
, ioc_state
&
2346 MPI2_DOORBELL_DATA_MASK
);
2347 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2349 rc
= (!rc
) ? SUCCESS
: FAILED
;
2353 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2355 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2356 ioc
->name
, __func__
);
2361 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2362 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2364 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2365 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2367 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2368 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2369 ioc
->tm_cmds
.smid
= smid
;
2370 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2371 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2372 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2373 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2374 mpi_request
->TaskType
= type
;
2375 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2376 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2377 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2378 init_completion(&ioc
->tm_cmds
.done
);
2379 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2380 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2381 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2382 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2383 ioc
->name
, __func__
);
2384 _debug_dump_mf(mpi_request
,
2385 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2386 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2387 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2389 rc
= (!rc
) ? SUCCESS
: FAILED
;
2390 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2391 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2396 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2397 mpi_reply
= ioc
->tm_cmds
.reply
;
2398 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2399 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2400 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2401 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2402 le32_to_cpu(mpi_reply
->TerminationCount
)));
2403 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2404 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2405 if (mpi_reply
->IOCStatus
)
2406 _debug_dump_mf(mpi_request
,
2407 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2412 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2414 if (scsi_lookup
->scmd
== NULL
)
2419 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2420 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2426 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2427 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2428 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2433 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2441 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2442 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2443 if (m_type
== TM_MUTEX_ON
)
2444 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2449 if (m_type
== TM_MUTEX_ON
)
2450 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2455 * _scsih_tm_display_info - displays info about the device
2456 * @ioc: per adapter struct
2457 * @scmd: pointer to scsi command object
2459 * Called by task management callback handlers.
2462 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2464 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2465 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2466 struct _sas_device
*sas_device
= NULL
;
2467 unsigned long flags
;
2468 char *device_str
= NULL
;
2472 if (ioc
->hide_ir_msg
)
2473 device_str
= "WarpDrive";
2475 device_str
= "volume";
2477 scsi_print_command(scmd
);
2478 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2479 starget_printk(KERN_INFO
, starget
, "%s handle(0x%04x), "
2480 "%s wwid(0x%016llx)\n", device_str
, priv_target
->handle
,
2481 device_str
, (unsigned long long)priv_target
->sas_address
);
2483 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2484 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2485 priv_target
->sas_address
);
2487 if (priv_target
->flags
&
2488 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2489 starget_printk(KERN_INFO
, starget
,
2490 "volume handle(0x%04x), "
2491 "volume wwid(0x%016llx)\n",
2492 sas_device
->volume_handle
,
2493 (unsigned long long)sas_device
->volume_wwid
);
2495 starget_printk(KERN_INFO
, starget
,
2496 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2498 (unsigned long long)sas_device
->sas_address
,
2500 starget_printk(KERN_INFO
, starget
,
2501 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2502 (unsigned long long)sas_device
->enclosure_logical_id
,
2505 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2510 * _scsih_abort - eh threads main abort routine
2511 * @scmd: pointer to scsi command object
2513 * Returns SUCCESS if command aborted else FAILED
2516 _scsih_abort(struct scsi_cmnd
*scmd
)
2518 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2519 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2524 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2525 "scmd(%p)\n", scmd
);
2526 _scsih_tm_display_info(ioc
, scmd
);
2528 sas_device_priv_data
= scmd
->device
->hostdata
;
2529 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2530 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2531 "scmd(%p)\n", scmd
);
2532 scmd
->result
= DID_NO_CONNECT
<< 16;
2533 scmd
->scsi_done(scmd
);
2538 /* search for the command */
2539 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2541 scmd
->result
= DID_RESET
<< 16;
2546 /* for hidden raid components and volumes this is not supported */
2547 if (sas_device_priv_data
->sas_target
->flags
&
2548 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2549 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2550 scmd
->result
= DID_RESET
<< 16;
2555 mpt2sas_halt_firmware(ioc
);
2557 handle
= sas_device_priv_data
->sas_target
->handle
;
2558 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2559 scmd
->device
->id
, scmd
->device
->lun
,
2560 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
2561 scmd
->serial_number
, TM_MUTEX_ON
);
2564 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2565 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2570 * _scsih_dev_reset - eh threads main device reset routine
2571 * @scmd: pointer to scsi command object
2573 * Returns SUCCESS if command aborted else FAILED
2576 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2578 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2579 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2580 struct _sas_device
*sas_device
;
2581 unsigned long flags
;
2585 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2587 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2588 "scmd(%p)\n", scmd
);
2589 _scsih_tm_display_info(ioc
, scmd
);
2591 sas_device_priv_data
= scmd
->device
->hostdata
;
2592 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2593 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2594 "scmd(%p)\n", scmd
);
2595 scmd
->result
= DID_NO_CONNECT
<< 16;
2596 scmd
->scsi_done(scmd
);
2601 /* for hidden raid components obtain the volume_handle */
2603 if (sas_device_priv_data
->sas_target
->flags
&
2604 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2605 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2606 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2607 sas_device_priv_data
->sas_target
->handle
);
2609 handle
= sas_device
->volume_handle
;
2610 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2612 handle
= sas_device_priv_data
->sas_target
->handle
;
2615 scmd
->result
= DID_RESET
<< 16;
2620 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2621 scmd
->device
->id
, scmd
->device
->lun
,
2622 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, 0,
2626 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2627 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2632 * _scsih_target_reset - eh threads main target reset routine
2633 * @scmd: pointer to scsi command object
2635 * Returns SUCCESS if command aborted else FAILED
2638 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2640 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2641 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2642 struct _sas_device
*sas_device
;
2643 unsigned long flags
;
2646 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2648 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2649 "scmd(%p)\n", scmd
);
2650 _scsih_tm_display_info(ioc
, scmd
);
2652 sas_device_priv_data
= scmd
->device
->hostdata
;
2653 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2654 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2655 "scmd(%p)\n", scmd
);
2656 scmd
->result
= DID_NO_CONNECT
<< 16;
2657 scmd
->scsi_done(scmd
);
2662 /* for hidden raid components obtain the volume_handle */
2664 if (sas_device_priv_data
->sas_target
->flags
&
2665 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2666 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2667 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2668 sas_device_priv_data
->sas_target
->handle
);
2670 handle
= sas_device
->volume_handle
;
2671 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2673 handle
= sas_device_priv_data
->sas_target
->handle
;
2676 scmd
->result
= DID_RESET
<< 16;
2681 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2682 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2683 30, 0, TM_MUTEX_ON
);
2686 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2687 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2692 * _scsih_host_reset - eh threads main host reset routine
2693 * @scmd: pointer to scsi command object
2695 * Returns SUCCESS if command aborted else FAILED
2698 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2700 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2703 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2705 scsi_print_command(scmd
);
2707 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2709 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2710 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2711 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2717 * _scsih_fw_event_add - insert and queue up fw_event
2718 * @ioc: per adapter object
2719 * @fw_event: object describing the event
2720 * Context: This function will acquire ioc->fw_event_lock.
2722 * This adds the firmware event object into link list, then queues it up to
2723 * be processed from user context.
2728 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2730 unsigned long flags
;
2732 if (ioc
->firmware_event_thread
== NULL
)
2735 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2736 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2737 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2738 queue_delayed_work(ioc
->firmware_event_thread
,
2739 &fw_event
->delayed_work
, 0);
2740 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2744 * _scsih_fw_event_free - delete fw_event
2745 * @ioc: per adapter object
2746 * @fw_event: object describing the event
2747 * Context: This function will acquire ioc->fw_event_lock.
2749 * This removes firmware event object from link list, frees associated memory.
2754 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2757 unsigned long flags
;
2759 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2760 list_del(&fw_event
->list
);
2761 kfree(fw_event
->event_data
);
2763 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2768 * _scsih_error_recovery_delete_devices - remove devices not responding
2769 * @ioc: per adapter object
2774 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER
*ioc
)
2776 struct fw_event_work
*fw_event
;
2778 if (ioc
->is_driver_loading
)
2780 fw_event
->event
= MPT2SAS_REMOVE_UNRESPONDING_DEVICES
;
2781 fw_event
->ioc
= ioc
;
2782 _scsih_fw_event_add(ioc
, fw_event
);
2786 * mpt2sas_port_enable_complete - port enable completed (fake event)
2787 * @ioc: per adapter object
2792 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER
*ioc
)
2794 struct fw_event_work
*fw_event
;
2796 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2799 fw_event
->event
= MPT2SAS_PORT_ENABLE_COMPLETE
;
2800 fw_event
->ioc
= ioc
;
2801 _scsih_fw_event_add(ioc
, fw_event
);
2805 * _scsih_fw_event_cleanup_queue - cleanup event queue
2806 * @ioc: per adapter object
2808 * Walk the firmware event queue, either killing timers, or waiting
2809 * for outstanding events to complete
2814 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2816 struct fw_event_work
*fw_event
, *next
;
2818 if (list_empty(&ioc
->fw_event_list
) ||
2819 !ioc
->firmware_event_thread
|| in_interrupt())
2822 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2823 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2824 _scsih_fw_event_free(ioc
, fw_event
);
2827 fw_event
->cancel_pending_work
= 1;
2832 * _scsih_ublock_io_all_device - unblock every device
2833 * @ioc: per adapter object
2835 * change the device state from block to running
2838 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2840 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2841 struct scsi_device
*sdev
;
2843 shost_for_each_device(sdev
, ioc
->shost
) {
2844 sas_device_priv_data
= sdev
->hostdata
;
2845 if (!sas_device_priv_data
)
2847 if (!sas_device_priv_data
->block
)
2849 sas_device_priv_data
->block
= 0;
2850 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_running, "
2852 sas_device_priv_data
->sas_target
->handle
));
2853 scsi_internal_device_unblock(sdev
);
2857 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2858 * @ioc: per adapter object
2859 * @handle: device handle
2861 * During device pull we need to appropiately set the sdev state.
2864 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2866 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2867 struct scsi_device
*sdev
;
2869 shost_for_each_device(sdev
, ioc
->shost
) {
2870 sas_device_priv_data
= sdev
->hostdata
;
2871 if (!sas_device_priv_data
)
2873 if (!sas_device_priv_data
->block
)
2875 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2876 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2877 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2878 "handle(0x%04x)\n", ioc
->name
, handle
));
2879 sas_device_priv_data
->block
= 0;
2880 scsi_internal_device_unblock(sdev
);
2886 * _scsih_block_io_all_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_all_device(struct MPT2SAS_ADAPTER
*ioc
)
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 sas_device_priv_data
->block
= 1;
2905 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_blocked, "
2907 sas_device_priv_data
->sas_target
->handle
));
2908 scsi_internal_device_block(sdev
);
2914 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2915 * @ioc: per adapter object
2916 * @handle: device handle
2918 * During device pull we need to appropiately set the sdev state.
2921 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2923 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2924 struct scsi_device
*sdev
;
2926 shost_for_each_device(sdev
, ioc
->shost
) {
2927 sas_device_priv_data
= sdev
->hostdata
;
2928 if (!sas_device_priv_data
)
2930 if (sas_device_priv_data
->block
)
2932 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2933 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2934 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2935 "handle(0x%04x)\n", ioc
->name
, handle
));
2936 sas_device_priv_data
->block
= 1;
2937 scsi_internal_device_block(sdev
);
2943 * _scsih_block_io_to_children_attached_to_ex
2944 * @ioc: per adapter object
2945 * @sas_expander: the sas_device object
2947 * This routine set sdev state to SDEV_BLOCK for all devices
2948 * attached to this expander. This function called when expander is
2952 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2953 struct _sas_node
*sas_expander
)
2955 struct _sas_port
*mpt2sas_port
;
2956 struct _sas_device
*sas_device
;
2957 struct _sas_node
*expander_sibling
;
2958 unsigned long flags
;
2963 list_for_each_entry(mpt2sas_port
,
2964 &sas_expander
->sas_port_list
, port_list
) {
2965 if (mpt2sas_port
->remote_identify
.device_type
==
2967 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2969 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2970 mpt2sas_port
->remote_identify
.sas_address
);
2971 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2974 _scsih_block_io_device(ioc
, sas_device
->handle
);
2978 list_for_each_entry(mpt2sas_port
,
2979 &sas_expander
->sas_port_list
, port_list
) {
2981 if (mpt2sas_port
->remote_identify
.device_type
==
2982 SAS_EDGE_EXPANDER_DEVICE
||
2983 mpt2sas_port
->remote_identify
.device_type
==
2984 SAS_FANOUT_EXPANDER_DEVICE
) {
2986 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
2988 mpt2sas_scsih_expander_find_by_sas_address(
2989 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
2990 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
2991 _scsih_block_io_to_children_attached_to_ex(ioc
,
2998 * _scsih_block_io_to_children_attached_directly
2999 * @ioc: per adapter object
3000 * @event_data: topology change event data
3002 * This routine set sdev state to SDEV_BLOCK for all devices
3003 * direct attached during device pull.
3006 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
3007 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3014 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3015 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3018 phy_number
= event_data
->StartPhyNum
+ i
;
3019 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3020 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3021 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3022 _scsih_block_io_device(ioc
, handle
);
3027 * _scsih_tm_tr_send - send task management request
3028 * @ioc: per adapter object
3029 * @handle: device handle
3030 * Context: interrupt time.
3032 * This code is to initiate the device removal handshake protocol
3033 * with controller firmware. This function will issue target reset
3034 * using high priority request queue. It will send a sas iounit
3035 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3037 * This is designed to send muliple task management request at the same
3038 * time to the fifo. If the fifo is full, we will append the request,
3039 * and process it in a future completion.
3042 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3044 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3046 struct _sas_device
*sas_device
;
3047 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
3048 u64 sas_address
= 0;
3049 unsigned long flags
;
3050 struct _tr_list
*delayed_tr
;
3053 if (ioc
->remove_host
) {
3054 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3055 "removed: handle(0x%04x)\n", __func__
, ioc
->name
, handle
));
3057 } else if (ioc
->pci_error_recovery
) {
3058 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3059 "error recovery: handle(0x%04x)\n", __func__
, ioc
->name
,
3063 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3064 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3065 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3066 "operational: handle(0x%04x)\n", __func__
, ioc
->name
,
3071 /* if PD, then return */
3072 if (test_bit(handle
, ioc
->pd_handles
))
3075 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3076 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3077 if (sas_device
&& sas_device
->starget
&&
3078 sas_device
->starget
->hostdata
) {
3079 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3080 sas_target_priv_data
->deleted
= 1;
3081 sas_address
= sas_device
->sas_address
;
3083 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3085 if (sas_target_priv_data
) {
3086 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"setting delete flag: "
3087 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, handle
,
3088 (unsigned long long)sas_address
));
3089 _scsih_ublock_io_device(ioc
, handle
);
3090 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
3093 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3095 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3098 INIT_LIST_HEAD(&delayed_tr
->list
);
3099 delayed_tr
->handle
= handle
;
3100 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3101 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3102 "DELAYED:tr:handle(0x%04x), (open)\n",
3103 ioc
->name
, handle
));
3107 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3108 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3109 ioc
->tm_tr_cb_idx
));
3110 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3111 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3112 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3113 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3114 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3115 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3121 * _scsih_sas_control_complete - completion routine
3122 * @ioc: per adapter object
3123 * @smid: system request message index
3124 * @msix_index: MSIX table index supplied by the OS
3125 * @reply: reply message frame(lower 32bit addr)
3126 * Context: interrupt time.
3128 * This is the sas iounit control completion routine.
3129 * This code is part of the code to initiate the device removal
3130 * handshake protocol with controller firmware.
3132 * Return 1 meaning mf should be freed from _base_interrupt
3133 * 0 means the mf is freed from this function.
3136 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3137 u8 msix_index
, u32 reply
)
3139 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3140 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3141 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3143 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3144 "sc_complete:handle(0x%04x), (open) "
3145 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3146 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3147 le16_to_cpu(mpi_reply
->IOCStatus
),
3148 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3153 * _scsih_tm_tr_volume_send - send target reset request for volumes
3154 * @ioc: per adapter object
3155 * @handle: device handle
3156 * Context: interrupt time.
3158 * This is designed to send muliple task management request at the same
3159 * time to the fifo. If the fifo is full, we will append the request,
3160 * and process it in a future completion.
3163 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3165 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3167 struct _tr_list
*delayed_tr
;
3169 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3170 ioc
->pci_error_recovery
) {
3171 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3172 "progress!\n", __func__
, ioc
->name
));
3176 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3178 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3181 INIT_LIST_HEAD(&delayed_tr
->list
);
3182 delayed_tr
->handle
= handle
;
3183 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3184 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3185 "DELAYED:tr:handle(0x%04x), (open)\n",
3186 ioc
->name
, handle
));
3190 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3191 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3192 ioc
->tm_tr_volume_cb_idx
));
3193 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3194 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3195 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3196 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3197 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3198 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3202 * _scsih_tm_volume_tr_complete - target reset completion
3203 * @ioc: per adapter object
3204 * @smid: system request message index
3205 * @msix_index: MSIX table index supplied by the OS
3206 * @reply: reply message frame(lower 32bit addr)
3207 * Context: interrupt time.
3209 * Return 1 meaning mf should be freed from _base_interrupt
3210 * 0 means the mf is freed from this function.
3213 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3214 u8 msix_index
, u32 reply
)
3217 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3218 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3219 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3221 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3222 ioc
->pci_error_recovery
) {
3223 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3224 "progress!\n", __func__
, ioc
->name
));
3228 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3229 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3230 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3231 dewtprintk(ioc
, printk("spurious interrupt: "
3232 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
3233 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3237 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3238 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3239 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3240 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3241 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3242 le32_to_cpu(mpi_reply
->TerminationCount
)));
3244 return _scsih_check_for_pending_tm(ioc
, smid
);
3248 * _scsih_tm_tr_complete -
3249 * @ioc: per adapter object
3250 * @smid: system request message index
3251 * @msix_index: MSIX table index supplied by the OS
3252 * @reply: reply message frame(lower 32bit addr)
3253 * Context: interrupt time.
3255 * This is the target reset completion routine.
3256 * This code is part of the code to initiate the device removal
3257 * handshake protocol with controller firmware.
3258 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3260 * Return 1 meaning mf should be freed from _base_interrupt
3261 * 0 means the mf is freed from this function.
3264 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3268 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3269 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3270 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3271 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3275 if (ioc
->remove_host
) {
3276 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3277 "removed\n", __func__
, ioc
->name
));
3279 } else if (ioc
->pci_error_recovery
) {
3280 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3281 "error recovery\n", __func__
, ioc
->name
));
3284 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3285 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3286 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3287 "operational\n", __func__
, ioc
->name
));
3291 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3292 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3293 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3294 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
3295 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
3296 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3300 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3301 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3302 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3303 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3304 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3305 le32_to_cpu(mpi_reply
->TerminationCount
)));
3307 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3308 if (!smid_sas_ctrl
) {
3309 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3310 ioc
->name
, __func__
);
3314 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
3315 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
3316 ioc
->tm_sas_control_cb_idx
));
3317 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3318 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3319 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3320 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3321 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3322 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3324 return _scsih_check_for_pending_tm(ioc
, smid
);
3328 * _scsih_check_for_pending_tm - check for pending task management
3329 * @ioc: per adapter object
3330 * @smid: system request message index
3332 * This will check delayed target reset list, and feed the
3335 * Return 1 meaning mf should be freed from _base_interrupt
3336 * 0 means the mf is freed from this function.
3339 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3341 struct _tr_list
*delayed_tr
;
3343 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3344 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3345 struct _tr_list
, list
);
3346 mpt2sas_base_free_smid(ioc
, smid
);
3347 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3348 list_del(&delayed_tr
->list
);
3353 if (!list_empty(&ioc
->delayed_tr_list
)) {
3354 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3355 struct _tr_list
, list
);
3356 mpt2sas_base_free_smid(ioc
, smid
);
3357 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3358 list_del(&delayed_tr
->list
);
3367 * _scsih_check_topo_delete_events - sanity check on topo events
3368 * @ioc: per adapter object
3369 * @event_data: the event data payload
3371 * This routine added to better handle cable breaker.
3373 * This handles the case where driver receives multiple expander
3374 * add and delete events in a single shot. When there is a delete event
3375 * the routine will void any pending add events waiting in the event queue.
3380 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3381 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3383 struct fw_event_work
*fw_event
;
3384 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3385 u16 expander_handle
;
3386 struct _sas_node
*sas_expander
;
3387 unsigned long flags
;
3391 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3392 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3395 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3396 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3397 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3398 _scsih_tm_tr_send(ioc
, handle
);
3401 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3402 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3403 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3407 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3408 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
3409 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3410 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3412 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3413 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3414 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3415 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3417 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3420 /* mark ignore flag for pending events */
3421 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3422 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3423 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3426 local_event_data
= fw_event
->event_data
;
3427 if (local_event_data
->ExpStatus
==
3428 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3429 local_event_data
->ExpStatus
==
3430 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3431 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3433 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3434 "setting ignoring flag\n", ioc
->name
));
3435 fw_event
->ignore
= 1;
3439 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3443 * _scsih_set_volume_delete_flag - setting volume delete flag
3444 * @ioc: per adapter object
3445 * @handle: device handle
3451 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3453 struct _raid_device
*raid_device
;
3454 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3455 unsigned long flags
;
3457 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3458 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3459 if (raid_device
&& raid_device
->starget
&&
3460 raid_device
->starget
->hostdata
) {
3461 sas_target_priv_data
=
3462 raid_device
->starget
->hostdata
;
3463 sas_target_priv_data
->deleted
= 1;
3464 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3465 "setting delete flag: handle(0x%04x), "
3466 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3467 (unsigned long long) raid_device
->wwid
));
3469 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3473 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3474 * @handle: input handle
3475 * @a: handle for volume a
3476 * @b: handle for volume b
3478 * IR firmware only supports two raid volumes. The purpose of this
3479 * routine is to set the volume handle in either a or b. When the given
3480 * input handle is non-zero, or when a and b have not been set before.
3483 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3485 if (!handle
|| handle
== *a
|| handle
== *b
)
3494 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3495 * @ioc: per adapter object
3496 * @event_data: the event data payload
3497 * Context: interrupt time.
3499 * This routine will send target reset to volume, followed by target
3500 * resets to the PDs. This is called when a PD has been removed, or
3501 * volume has been deleted or removed. When the target reset is sent
3502 * to volume, the PD target resets need to be queued to start upon
3503 * completion of the volume target reset.
3508 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3509 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3511 Mpi2EventIrConfigElement_t
*element
;
3513 u16 handle
, volume_handle
, a
, b
;
3514 struct _tr_list
*delayed_tr
;
3519 if (ioc
->is_warpdrive
)
3522 /* Volume Resets for Deleted or Removed */
3523 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3524 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3525 if (element
->ReasonCode
==
3526 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3527 element
->ReasonCode
==
3528 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3529 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3530 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3531 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3535 /* Volume Resets for UNHIDE events */
3536 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3537 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3538 if (le32_to_cpu(event_data
->Flags
) &
3539 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3541 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3542 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3543 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3548 _scsih_tm_tr_volume_send(ioc
, a
);
3550 _scsih_tm_tr_volume_send(ioc
, b
);
3552 /* PD target resets */
3553 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3554 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3555 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3557 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3558 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3559 clear_bit(handle
, ioc
->pd_handles
);
3561 _scsih_tm_tr_send(ioc
, handle
);
3562 else if (volume_handle
== a
|| volume_handle
== b
) {
3563 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3564 BUG_ON(!delayed_tr
);
3565 INIT_LIST_HEAD(&delayed_tr
->list
);
3566 delayed_tr
->handle
= handle
;
3567 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3568 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3569 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3572 _scsih_tm_tr_send(ioc
, handle
);
3578 * _scsih_check_volume_delete_events - set delete flag for volumes
3579 * @ioc: per adapter object
3580 * @event_data: the event data payload
3581 * Context: interrupt time.
3583 * This will handle the case when the cable connected to entire volume is
3584 * pulled. We will take care of setting the deleted flag so normal IO will
3590 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3591 Mpi2EventDataIrVolume_t
*event_data
)
3595 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3597 state
= le32_to_cpu(event_data
->NewValue
);
3598 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3599 MPI2_RAID_VOL_STATE_FAILED
)
3600 _scsih_set_volume_delete_flag(ioc
,
3601 le16_to_cpu(event_data
->VolDevHandle
));
3605 * _scsih_flush_running_cmds - completing outstanding commands.
3606 * @ioc: per adapter object
3608 * The flushing out of all pending scmd commands following host reset,
3609 * where all IO is dropped to the floor.
3614 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3616 struct scsi_cmnd
*scmd
;
3620 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3621 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3625 mpt2sas_base_free_smid(ioc
, smid
);
3626 scsi_dma_unmap(scmd
);
3627 if (ioc
->pci_error_recovery
)
3628 scmd
->result
= DID_NO_CONNECT
<< 16;
3630 scmd
->result
= DID_RESET
<< 16;
3631 scmd
->scsi_done(scmd
);
3633 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3638 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3639 * @scmd: pointer to scsi command object
3640 * @mpi_request: pointer to the SCSI_IO reqest message frame
3642 * Supporting protection 1 and 3.
3647 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3650 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3651 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3653 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3656 if (prot_op
== SCSI_PROT_READ_STRIP
)
3657 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3658 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3659 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3663 switch (prot_type
) {
3664 case SCSI_PROT_DIF_TYPE1
:
3665 case SCSI_PROT_DIF_TYPE2
:
3668 * enable ref/guard checking
3669 * auto increment ref tag
3671 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3672 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3673 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3674 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3675 cpu_to_be32(scsi_get_lba(scmd
));
3678 case SCSI_PROT_DIF_TYPE3
:
3681 * enable guard checking
3683 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3686 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3687 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3691 * _scsih_eedp_error_handling - return sense code for EEDP errors
3692 * @scmd: pointer to scsi command object
3693 * @ioc_status: ioc status
3698 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3704 switch (ioc_status
) {
3705 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3708 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3711 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3719 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3720 sk
= ILLEGAL_REQUEST
;
3721 host_byte
= DID_ABORT
;
3723 sk
= ABORTED_COMMAND
;
3727 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3728 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3729 SAM_STAT_CHECK_CONDITION
;
3733 * _scsih_scsi_direct_io_get - returns direct io flag
3734 * @ioc: per adapter object
3735 * @smid: system request message index
3737 * Returns the smid stored scmd pointer.
3740 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3742 return ioc
->scsi_lookup
[smid
- 1].direct_io
;
3746 * _scsih_scsi_direct_io_set - sets direct io flag
3747 * @ioc: per adapter object
3748 * @smid: system request message index
3749 * @direct_io: Zero or non-zero value to set in the direct_io flag
3754 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 direct_io
)
3756 ioc
->scsi_lookup
[smid
- 1].direct_io
= direct_io
;
3761 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3762 * @ioc: per adapter object
3763 * @scmd: pointer to scsi command object
3764 * @raid_device: pointer to raid device data structure
3765 * @mpi_request: pointer to the SCSI_IO reqest message frame
3766 * @smid: system request message index
3771 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3772 struct _raid_device
*raid_device
, Mpi2SCSIIORequest_t
*mpi_request
,
3775 u32 v_lba
, p_lba
, stripe_off
, stripe_unit
, column
, io_size
;
3776 u32 stripe_sz
, stripe_exp
;
3777 u8 num_pds
, *cdb_ptr
, *tmp_ptr
, *lba_ptr1
, *lba_ptr2
;
3778 u8 cdb0
= scmd
->cmnd
[0];
3781 * Try Direct I/O to RAID memeber disks
3783 if (cdb0
== READ_16
|| cdb0
== READ_10
||
3784 cdb0
== WRITE_16
|| cdb0
== WRITE_10
) {
3785 cdb_ptr
= mpi_request
->CDB
.CDB32
;
3787 if ((cdb0
< READ_16
) || !(cdb_ptr
[2] | cdb_ptr
[3] | cdb_ptr
[4]
3789 io_size
= scsi_bufflen(scmd
) >> 9;
3790 /* get virtual lba */
3791 lba_ptr1
= lba_ptr2
= (cdb0
< READ_16
) ? &cdb_ptr
[2] :
3793 tmp_ptr
= (u8
*)&v_lba
+ 3;
3794 *tmp_ptr
-- = *lba_ptr1
++;
3795 *tmp_ptr
-- = *lba_ptr1
++;
3796 *tmp_ptr
-- = *lba_ptr1
++;
3797 *tmp_ptr
= *lba_ptr1
;
3799 if (((u64
)v_lba
+ (u64
)io_size
- 1) <=
3800 (u32
)raid_device
->max_lba
) {
3801 stripe_sz
= raid_device
->stripe_sz
;
3802 stripe_exp
= raid_device
->stripe_exponent
;
3803 stripe_off
= v_lba
& (stripe_sz
- 1);
3805 /* Check whether IO falls within a stripe */
3806 if ((stripe_off
+ io_size
) <= stripe_sz
) {
3807 num_pds
= raid_device
->num_pds
;
3808 p_lba
= v_lba
>> stripe_exp
;
3809 stripe_unit
= p_lba
/ num_pds
;
3810 column
= p_lba
% num_pds
;
3811 p_lba
= (stripe_unit
<< stripe_exp
) +
3813 mpi_request
->DevHandle
=
3814 cpu_to_le16(raid_device
->
3816 tmp_ptr
= (u8
*)&p_lba
+ 3;
3817 *lba_ptr2
++ = *tmp_ptr
--;
3818 *lba_ptr2
++ = *tmp_ptr
--;
3819 *lba_ptr2
++ = *tmp_ptr
--;
3820 *lba_ptr2
= *tmp_ptr
;
3822 * WD: To indicate this I/O is directI/O
3824 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3832 * _scsih_qcmd - main scsi request entry point
3833 * @scmd: pointer to scsi command object
3834 * @done: function pointer to be invoked on completion
3836 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3838 * Returns 0 on success. If there's a failure, return either:
3839 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3840 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3843 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3845 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3846 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3847 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3848 struct _raid_device
*raid_device
;
3849 Mpi2SCSIIORequest_t
*mpi_request
;
3853 scmd
->scsi_done
= done
;
3854 sas_device_priv_data
= scmd
->device
->hostdata
;
3855 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3856 scmd
->result
= DID_NO_CONNECT
<< 16;
3857 scmd
->scsi_done(scmd
);
3861 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3862 scmd
->result
= DID_NO_CONNECT
<< 16;
3863 scmd
->scsi_done(scmd
);
3867 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3868 /* invalid device handle */
3869 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3870 scmd
->result
= DID_NO_CONNECT
<< 16;
3871 scmd
->scsi_done(scmd
);
3875 /* host recovery or link resets sent via IOCTLs */
3876 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3877 return SCSI_MLQUEUE_HOST_BUSY
;
3878 /* device busy with task management */
3879 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3880 return SCSI_MLQUEUE_DEVICE_BUSY
;
3881 /* device has been deleted */
3882 else if (sas_target_priv_data
->deleted
) {
3883 scmd
->result
= DID_NO_CONNECT
<< 16;
3884 scmd
->scsi_done(scmd
);
3888 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3889 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3890 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3891 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3893 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3896 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3897 if (scmd
->device
->tagged_supported
) {
3898 if (scmd
->device
->ordered_tags
)
3899 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3901 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3903 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3904 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3906 mpi_control
|= (0x500);
3909 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3910 /* Make sure Device is not raid volume.
3911 * We do not expose raid functionality to upper layer for warpdrive.
3913 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3914 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3915 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3917 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3919 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3920 ioc
->name
, __func__
);
3923 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3924 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3925 _scsih_setup_eedp(scmd
, mpi_request
);
3926 if (scmd
->cmd_len
== 32)
3927 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3928 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3929 if (sas_device_priv_data
->sas_target
->flags
&
3930 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3931 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3933 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3934 mpi_request
->DevHandle
=
3935 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3936 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
3937 mpi_request
->Control
= cpu_to_le32(mpi_control
);
3938 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
3939 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
3940 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3941 mpi_request
->SenseBufferLowAddress
=
3942 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
3943 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
3944 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
3945 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
3946 mpi_request
->VF_ID
= 0; /* TODO */
3947 mpi_request
->VP_ID
= 0;
3948 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
3950 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
3952 if (!mpi_request
->DataLength
) {
3953 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
3955 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
3956 mpt2sas_base_free_smid(ioc
, smid
);
3961 raid_device
= sas_target_priv_data
->raid_device
;
3962 if (raid_device
&& raid_device
->direct_io_enabled
)
3963 _scsih_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
3966 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
3967 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
3968 le16_to_cpu(mpi_request
->DevHandle
));
3970 mpt2sas_base_put_smid_default(ioc
, smid
);
3974 return SCSI_MLQUEUE_HOST_BUSY
;
3977 static DEF_SCSI_QCMD(_scsih_qcmd
)
3980 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3981 * @sense_buffer: sense data returned by target
3982 * @data: normalized skey/asc/ascq
3987 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
3989 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
3990 /* descriptor format */
3991 data
->skey
= sense_buffer
[1] & 0x0F;
3992 data
->asc
= sense_buffer
[2];
3993 data
->ascq
= sense_buffer
[3];
3996 data
->skey
= sense_buffer
[2] & 0x0F;
3997 data
->asc
= sense_buffer
[12];
3998 data
->ascq
= sense_buffer
[13];
4002 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4004 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4005 * @ioc: per adapter object
4006 * @scmd: pointer to scsi command object
4007 * @mpi_reply: reply mf payload returned from firmware
4009 * scsi_status - SCSI Status code returned from target device
4010 * scsi_state - state info associated with SCSI_IO determined by ioc
4011 * ioc_status - ioc supplied status info
4016 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4017 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4021 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4022 MPI2_IOCSTATUS_MASK
;
4023 u8 scsi_state
= mpi_reply
->SCSIState
;
4024 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4025 char *desc_ioc_state
= NULL
;
4026 char *desc_scsi_status
= NULL
;
4027 char *desc_scsi_state
= ioc
->tmp_string
;
4028 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4029 struct _sas_device
*sas_device
= NULL
;
4030 unsigned long flags
;
4031 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4032 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
4033 char *device_str
= NULL
;
4038 if (ioc
->hide_ir_msg
)
4039 device_str
= "WarpDrive";
4041 device_str
= "volume";
4043 if (log_info
== 0x31170000)
4046 switch (ioc_status
) {
4047 case MPI2_IOCSTATUS_SUCCESS
:
4048 desc_ioc_state
= "success";
4050 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4051 desc_ioc_state
= "invalid function";
4053 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4054 desc_ioc_state
= "scsi recovered error";
4056 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4057 desc_ioc_state
= "scsi invalid dev handle";
4059 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4060 desc_ioc_state
= "scsi device not there";
4062 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4063 desc_ioc_state
= "scsi data overrun";
4065 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4066 desc_ioc_state
= "scsi data underrun";
4068 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4069 desc_ioc_state
= "scsi io data error";
4071 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4072 desc_ioc_state
= "scsi protocol error";
4074 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4075 desc_ioc_state
= "scsi task terminated";
4077 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4078 desc_ioc_state
= "scsi residual mismatch";
4080 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4081 desc_ioc_state
= "scsi task mgmt failed";
4083 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4084 desc_ioc_state
= "scsi ioc terminated";
4086 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4087 desc_ioc_state
= "scsi ext terminated";
4089 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4090 desc_ioc_state
= "eedp guard error";
4092 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4093 desc_ioc_state
= "eedp ref tag error";
4095 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4096 desc_ioc_state
= "eedp app tag error";
4099 desc_ioc_state
= "unknown";
4103 switch (scsi_status
) {
4104 case MPI2_SCSI_STATUS_GOOD
:
4105 desc_scsi_status
= "good";
4107 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4108 desc_scsi_status
= "check condition";
4110 case MPI2_SCSI_STATUS_CONDITION_MET
:
4111 desc_scsi_status
= "condition met";
4113 case MPI2_SCSI_STATUS_BUSY
:
4114 desc_scsi_status
= "busy";
4116 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4117 desc_scsi_status
= "intermediate";
4119 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4120 desc_scsi_status
= "intermediate condmet";
4122 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4123 desc_scsi_status
= "reservation conflict";
4125 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4126 desc_scsi_status
= "command terminated";
4128 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4129 desc_scsi_status
= "task set full";
4131 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4132 desc_scsi_status
= "aca active";
4134 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4135 desc_scsi_status
= "task aborted";
4138 desc_scsi_status
= "unknown";
4142 desc_scsi_state
[0] = '\0';
4144 desc_scsi_state
= " ";
4145 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4146 strcat(desc_scsi_state
, "response info ");
4147 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4148 strcat(desc_scsi_state
, "state terminated ");
4149 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4150 strcat(desc_scsi_state
, "no status ");
4151 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4152 strcat(desc_scsi_state
, "autosense failed ");
4153 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4154 strcat(desc_scsi_state
, "autosense valid ");
4156 scsi_print_command(scmd
);
4158 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4159 printk(MPT2SAS_WARN_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4160 device_str
, (unsigned long long)priv_target
->sas_address
);
4162 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4163 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4164 priv_target
->sas_address
);
4166 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
4167 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
4169 printk(MPT2SAS_WARN_FMT
4170 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4171 ioc
->name
, sas_device
->enclosure_logical_id
,
4174 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4177 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4178 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4179 desc_ioc_state
, ioc_status
, smid
);
4180 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
4181 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4182 scsi_get_resid(scmd
));
4183 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
4184 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4185 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4186 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
4187 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
4188 scsi_status
, desc_scsi_state
, scsi_state
);
4190 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4191 struct sense_info data
;
4192 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4193 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
4194 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
4195 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4198 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4199 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4200 response_bytes
= (u8
*)&response_info
;
4201 _scsih_response_code(ioc
, response_bytes
[0]);
4207 * _scsih_turn_on_fault_led - illuminate Fault LED
4208 * @ioc: per adapter object
4209 * @handle: device handle
4215 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4217 Mpi2SepReply_t mpi_reply
;
4218 Mpi2SepRequest_t mpi_request
;
4220 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4221 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4222 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4223 mpi_request
.SlotStatus
=
4224 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4225 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4226 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4227 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4228 &mpi_request
)) != 0) {
4229 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4230 __FILE__
, __LINE__
, __func__
);
4234 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4235 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
4236 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4237 le16_to_cpu(mpi_reply
.IOCStatus
),
4238 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4244 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4245 * @ioc: per adapter object
4246 * @handle: device handle
4247 * Context: interrupt.
4252 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4254 struct fw_event_work
*fw_event
;
4256 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4259 fw_event
->event
= MPT2SAS_TURN_ON_FAULT_LED
;
4260 fw_event
->device_handle
= handle
;
4261 fw_event
->ioc
= ioc
;
4262 _scsih_fw_event_add(ioc
, fw_event
);
4266 * _scsih_smart_predicted_fault - process smart errors
4267 * @ioc: per adapter object
4268 * @handle: device handle
4269 * Context: interrupt.
4274 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4276 struct scsi_target
*starget
;
4277 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4278 Mpi2EventNotificationReply_t
*event_reply
;
4279 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4280 struct _sas_device
*sas_device
;
4282 unsigned long flags
;
4284 /* only handle non-raid devices */
4285 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4286 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4288 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4291 starget
= sas_device
->starget
;
4292 sas_target_priv_data
= starget
->hostdata
;
4294 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4295 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4296 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4299 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
4300 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4302 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4303 _scsih_send_event_to_turn_on_fault_led(ioc
, handle
);
4305 /* insert into event log */
4306 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4307 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4308 event_reply
= kzalloc(sz
, GFP_KERNEL
);
4310 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4311 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4315 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4316 event_reply
->Event
=
4317 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4318 event_reply
->MsgLength
= sz
/4;
4319 event_reply
->EventDataLength
=
4320 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4321 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4322 event_reply
->EventData
;
4323 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4324 event_data
->ASC
= 0x5D;
4325 event_data
->DevHandle
= cpu_to_le16(handle
);
4326 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4327 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
4332 * _scsih_io_done - scsi request callback
4333 * @ioc: per adapter object
4334 * @smid: system request message index
4335 * @msix_index: MSIX table index supplied by the OS
4336 * @reply: reply message frame(lower 32bit addr)
4338 * Callback handler when using _scsih_qcmd.
4340 * Return 1 meaning mf should be freed from _base_interrupt
4341 * 0 means the mf is freed from this function.
4344 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4346 Mpi2SCSIIORequest_t
*mpi_request
;
4347 Mpi2SCSIIOReply_t
*mpi_reply
;
4348 struct scsi_cmnd
*scmd
;
4354 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4355 u32 response_code
= 0;
4356 unsigned long flags
;
4358 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4359 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4363 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4365 if (mpi_reply
== NULL
) {
4366 scmd
->result
= DID_OK
<< 16;
4370 sas_device_priv_data
= scmd
->device
->hostdata
;
4371 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4372 sas_device_priv_data
->sas_target
->deleted
) {
4373 scmd
->result
= DID_NO_CONNECT
<< 16;
4377 * WARPDRIVE: If direct_io is set then it is directIO,
4378 * the failed direct I/O should be redirected to volume
4380 if (_scsih_scsi_direct_io_get(ioc
, smid
)) {
4381 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4382 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4383 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4384 _scsih_scsi_direct_io_set(ioc
, smid
, 0);
4385 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4386 mpi_request
->DevHandle
=
4387 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4388 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4389 sas_device_priv_data
->sas_target
->handle
);
4394 /* turning off TLR */
4395 scsi_state
= mpi_reply
->SCSIState
;
4396 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4398 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4399 if (!sas_device_priv_data
->tlr_snoop_check
) {
4400 sas_device_priv_data
->tlr_snoop_check
++;
4401 /* Make sure Device is not raid volume.
4402 * We do not expose raid functionality to upper layer for warpdrive.
4404 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4405 sas_is_tlr_enabled(scmd
->device
) &&
4406 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4407 sas_disable_tlr(scmd
->device
);
4408 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4412 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4413 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4414 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4415 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4416 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4419 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4420 scsi_status
= mpi_reply
->SCSIStatus
;
4422 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4423 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4424 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4425 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4426 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4429 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4430 struct sense_info data
;
4431 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
4433 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4434 le32_to_cpu(mpi_reply
->SenseCount
));
4435 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4436 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4437 /* failure prediction threshold exceeded */
4438 if (data
.asc
== 0x5D)
4439 _scsih_smart_predicted_fault(ioc
,
4440 le16_to_cpu(mpi_reply
->DevHandle
));
4443 switch (ioc_status
) {
4444 case MPI2_IOCSTATUS_BUSY
:
4445 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4446 scmd
->result
= SAM_STAT_BUSY
;
4449 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4450 scmd
->result
= DID_NO_CONNECT
<< 16;
4453 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4454 if (sas_device_priv_data
->block
) {
4455 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4458 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4459 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4460 scmd
->result
= DID_RESET
<< 16;
4463 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4464 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4465 scmd
->result
= DID_SOFT_ERROR
<< 16;
4467 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4470 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4471 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4473 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4476 if (xfer_cnt
< scmd
->underflow
) {
4477 if (scsi_status
== SAM_STAT_BUSY
)
4478 scmd
->result
= SAM_STAT_BUSY
;
4480 scmd
->result
= DID_SOFT_ERROR
<< 16;
4481 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4482 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4483 scmd
->result
= DID_SOFT_ERROR
<< 16;
4484 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4485 scmd
->result
= DID_RESET
<< 16;
4486 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4487 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4488 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4489 scmd
->result
= (DRIVER_SENSE
<< 24) |
4490 SAM_STAT_CHECK_CONDITION
;
4491 scmd
->sense_buffer
[0] = 0x70;
4492 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4493 scmd
->sense_buffer
[12] = 0x20;
4494 scmd
->sense_buffer
[13] = 0;
4498 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4499 scsi_set_resid(scmd
, 0);
4500 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4501 case MPI2_IOCSTATUS_SUCCESS
:
4502 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4503 if (response_code
==
4504 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4505 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4506 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4507 scmd
->result
= DID_SOFT_ERROR
<< 16;
4508 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4509 scmd
->result
= DID_RESET
<< 16;
4512 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4513 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4514 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4515 _scsih_eedp_error_handling(scmd
, ioc_status
);
4517 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4518 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4519 case MPI2_IOCSTATUS_INVALID_SGL
:
4520 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4521 case MPI2_IOCSTATUS_INVALID_FIELD
:
4522 case MPI2_IOCSTATUS_INVALID_STATE
:
4523 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4524 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4526 scmd
->result
= DID_SOFT_ERROR
<< 16;
4531 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4532 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4533 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4537 scsi_dma_unmap(scmd
);
4538 scmd
->scsi_done(scmd
);
4543 * _scsih_sas_host_refresh - refreshing sas host object contents
4544 * @ioc: per adapter object
4547 * During port enable, fw will send topology events for every device. Its
4548 * possible that the handles may change from the previous setting, so this
4549 * code keeping handles updating if changed.
4554 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4559 Mpi2ConfigReply_t mpi_reply
;
4560 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4561 u16 attached_handle
;
4564 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4565 "updating handles for sas_host(0x%016llx)\n",
4566 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4568 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4569 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4570 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4571 if (!sas_iounit_pg0
) {
4572 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4573 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4577 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4578 sas_iounit_pg0
, sz
)) != 0)
4580 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4581 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4583 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4584 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4586 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4587 PhyData
[0].ControllerDevHandle
);
4588 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4589 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4591 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4592 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4593 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4594 attached_handle
, i
, link_rate
);
4597 kfree(sas_iounit_pg0
);
4601 * _scsih_sas_host_add - create sas host object
4602 * @ioc: per adapter object
4604 * Creating host side data object, stored in ioc->sas_hba
4609 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4612 Mpi2ConfigReply_t mpi_reply
;
4613 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4614 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4615 Mpi2SasPhyPage0_t phy_pg0
;
4616 Mpi2SasDevicePage0_t sas_device_pg0
;
4617 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4620 u16 device_missing_delay
;
4622 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4623 if (!ioc
->sas_hba
.num_phys
) {
4624 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4625 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4629 /* sas_iounit page 0 */
4630 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4631 sizeof(Mpi2SasIOUnit0PhyData_t
));
4632 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4633 if (!sas_iounit_pg0
) {
4634 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4635 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4638 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4639 sas_iounit_pg0
, sz
))) {
4640 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4641 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4644 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4645 MPI2_IOCSTATUS_MASK
;
4646 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4647 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4648 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4652 /* sas_iounit page 1 */
4653 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4654 sizeof(Mpi2SasIOUnit1PhyData_t
));
4655 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4656 if (!sas_iounit_pg1
) {
4657 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4658 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4661 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4662 sas_iounit_pg1
, sz
))) {
4663 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4664 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4667 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4668 MPI2_IOCSTATUS_MASK
;
4669 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4670 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4671 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4675 ioc
->io_missing_delay
=
4676 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4677 device_missing_delay
=
4678 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4679 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4680 ioc
->device_missing_delay
= (device_missing_delay
&
4681 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4683 ioc
->device_missing_delay
= device_missing_delay
&
4684 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4686 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4687 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4688 sizeof(struct _sas_phy
), GFP_KERNEL
);
4689 if (!ioc
->sas_hba
.phy
) {
4690 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4691 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4694 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4695 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4697 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4698 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4701 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4702 MPI2_IOCSTATUS_MASK
;
4703 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4704 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4705 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4710 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4711 PhyData
[0].ControllerDevHandle
);
4712 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4713 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4714 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4715 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4717 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4718 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4719 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4720 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4723 ioc
->sas_hba
.enclosure_handle
=
4724 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4725 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4726 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4727 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4728 (unsigned long long) ioc
->sas_hba
.sas_address
,
4729 ioc
->sas_hba
.num_phys
) ;
4731 if (ioc
->sas_hba
.enclosure_handle
) {
4732 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4734 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4735 ioc
->sas_hba
.enclosure_handle
))) {
4736 ioc
->sas_hba
.enclosure_logical_id
=
4737 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4742 kfree(sas_iounit_pg1
);
4743 kfree(sas_iounit_pg0
);
4747 * _scsih_expander_add - creating expander object
4748 * @ioc: per adapter object
4749 * @handle: expander handle
4751 * Creating expander object, stored in ioc->sas_expander_list.
4753 * Return 0 for success, else error.
4756 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4758 struct _sas_node
*sas_expander
;
4759 Mpi2ConfigReply_t mpi_reply
;
4760 Mpi2ExpanderPage0_t expander_pg0
;
4761 Mpi2ExpanderPage1_t expander_pg1
;
4762 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4765 u64 sas_address
, sas_address_parent
= 0;
4767 unsigned long flags
;
4768 struct _sas_port
*mpt2sas_port
= NULL
;
4774 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4777 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4778 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4779 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4780 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4784 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4785 MPI2_IOCSTATUS_MASK
;
4786 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4787 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4788 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4792 /* handle out of order topology events */
4793 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4794 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4796 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4797 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4800 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4801 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4802 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4803 sas_address_parent
);
4804 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4805 if (!sas_expander
) {
4806 rc
= _scsih_expander_add(ioc
, parent_handle
);
4812 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4813 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4814 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4816 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4821 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4823 if (!sas_expander
) {
4824 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4825 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4829 sas_expander
->handle
= handle
;
4830 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4831 sas_expander
->sas_address_parent
= sas_address_parent
;
4832 sas_expander
->sas_address
= sas_address
;
4834 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4835 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4836 handle
, parent_handle
, (unsigned long long)
4837 sas_expander
->sas_address
, sas_expander
->num_phys
);
4839 if (!sas_expander
->num_phys
)
4841 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4842 sizeof(struct _sas_phy
), GFP_KERNEL
);
4843 if (!sas_expander
->phy
) {
4844 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4845 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4850 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4851 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4852 sas_address_parent
);
4853 if (!mpt2sas_port
) {
4854 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4855 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4859 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4861 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4862 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4863 &expander_pg1
, i
, handle
))) {
4864 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4865 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4869 sas_expander
->phy
[i
].handle
= handle
;
4870 sas_expander
->phy
[i
].phy_id
= i
;
4872 if ((mpt2sas_transport_add_expander_phy(ioc
,
4873 &sas_expander
->phy
[i
], expander_pg1
,
4874 sas_expander
->parent_dev
))) {
4875 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4876 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4882 if (sas_expander
->enclosure_handle
) {
4883 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4884 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4885 sas_expander
->enclosure_handle
))) {
4886 sas_expander
->enclosure_logical_id
=
4887 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4891 _scsih_expander_node_add(ioc
, sas_expander
);
4897 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4898 sas_address_parent
);
4899 kfree(sas_expander
);
4904 * _scsih_done - scsih callback handler.
4905 * @ioc: per adapter object
4906 * @smid: system request message index
4907 * @msix_index: MSIX table index supplied by the OS
4908 * @reply: reply message frame(lower 32bit addr)
4910 * Callback handler when sending internal generated message frames.
4911 * The callback index passed is `ioc->scsih_cb_idx`
4913 * Return 1 meaning mf should be freed from _base_interrupt
4914 * 0 means the mf is freed from this function.
4917 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4919 MPI2DefaultReply_t
*mpi_reply
;
4921 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4922 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4924 if (ioc
->scsih_cmds
.smid
!= smid
)
4926 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4928 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4929 mpi_reply
->MsgLength
*4);
4930 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4932 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
4933 complete(&ioc
->scsih_cmds
.done
);
4938 * mpt2sas_expander_remove - removing expander object
4939 * @ioc: per adapter object
4940 * @sas_address: expander sas_address
4945 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
4947 struct _sas_node
*sas_expander
;
4948 unsigned long flags
;
4950 if (ioc
->shost_recovery
)
4953 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4954 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4956 if (!sas_expander
) {
4957 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4960 list_del(&sas_expander
->list
);
4961 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4962 _scsih_expander_node_remove(ioc
, sas_expander
);
4966 * _scsih_check_access_status - check access flags
4967 * @ioc: per adapter object
4968 * @sas_address: sas address
4969 * @handle: sas device handle
4970 * @access_flags: errors returned during discovery of the device
4972 * Return 0 for success, else failure
4975 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
4976 u16 handle
, u8 access_status
)
4981 switch (access_status
) {
4982 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
4983 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
4986 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
4987 desc
= "sata capability failed";
4989 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
4990 desc
= "sata affiliation conflict";
4992 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
4993 desc
= "route not addressable";
4995 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
4996 desc
= "smp error not addressable";
4998 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
4999 desc
= "device blocked";
5001 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5002 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5003 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5004 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5005 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5006 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5007 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5008 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5009 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5010 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5011 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5012 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5013 desc
= "sata initialization failed";
5023 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
5024 "handle(0x%04x)\n", ioc
->name
, desc
,
5025 (unsigned long long)sas_address
, handle
);
5030 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5032 Mpi2ConfigReply_t mpi_reply
;
5033 Mpi2SasDevicePage0_t sas_device_pg0
;
5034 struct _sas_device
*sas_device
;
5036 unsigned long flags
;
5038 struct scsi_target
*starget
;
5039 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5042 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5043 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5046 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5047 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5050 /* check if this is end device */
5051 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5052 if (!(_scsih_is_end_device(device_info
)))
5055 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5056 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5057 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5061 printk(MPT2SAS_ERR_FMT
"device is not present "
5062 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
5063 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5067 if (unlikely(sas_device
->handle
!= handle
)) {
5068 starget
= sas_device
->starget
;
5069 sas_target_priv_data
= starget
->hostdata
;
5070 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
5071 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
5072 sas_target_priv_data
->handle
= handle
;
5073 sas_device
->handle
= handle
;
5075 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5077 /* check if device is present */
5078 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5079 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5080 printk(MPT2SAS_ERR_FMT
"device is not present "
5081 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
5085 /* check if there were any issues with discovery */
5086 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5087 sas_device_pg0
.AccessStatus
))
5089 _scsih_ublock_io_device(ioc
, handle
);
5094 * _scsih_add_device - creating sas device object
5095 * @ioc: per adapter object
5096 * @handle: sas device handle
5097 * @phy_num: phy number end device attached to
5098 * @is_pd: is this hidden raid component
5100 * Creating end device object, stored in ioc->sas_device_list.
5102 * Returns 0 for success, non-zero for failure.
5105 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
5107 Mpi2ConfigReply_t mpi_reply
;
5108 Mpi2SasDevicePage0_t sas_device_pg0
;
5109 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5110 struct _sas_device
*sas_device
;
5114 unsigned long flags
;
5116 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5117 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5118 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5119 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5123 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5124 MPI2_IOCSTATUS_MASK
;
5125 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5126 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5127 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5131 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5133 /* check if device is present */
5134 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5135 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5136 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5137 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5138 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
5139 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
5143 /* check if there were any issues with discovery */
5144 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5145 sas_device_pg0
.AccessStatus
))
5148 /* check if this is end device */
5149 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5150 if (!(_scsih_is_end_device(device_info
))) {
5151 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5152 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5157 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5158 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5160 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5165 sas_device
= kzalloc(sizeof(struct _sas_device
),
5168 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5169 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5173 sas_device
->handle
= handle
;
5174 if (_scsih_get_sas_address(ioc
, le16_to_cpu
5175 (sas_device_pg0
.ParentDevHandle
),
5176 &sas_device
->sas_address_parent
) != 0)
5177 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5178 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5179 sas_device
->enclosure_handle
=
5180 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5182 le16_to_cpu(sas_device_pg0
.Slot
);
5183 sas_device
->device_info
= device_info
;
5184 sas_device
->sas_address
= sas_address
;
5185 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5187 /* get enclosure_logical_id */
5188 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
5189 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5190 sas_device
->enclosure_handle
)))
5191 sas_device
->enclosure_logical_id
=
5192 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5194 /* get device name */
5195 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5197 if (ioc
->wait_for_discovery_to_complete
)
5198 _scsih_sas_device_init_add(ioc
, sas_device
);
5200 _scsih_sas_device_add(ioc
, sas_device
);
5206 * _scsih_remove_device - removing sas device object
5207 * @ioc: per adapter object
5208 * @sas_device_delete: the sas_device object
5213 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
5214 struct _sas_device
*sas_device
)
5216 struct _sas_device sas_device_backup
;
5217 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5222 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
5223 _scsih_sas_device_remove(ioc
, sas_device
);
5225 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
5226 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5227 sas_device_backup
.handle
, (unsigned long long)
5228 sas_device_backup
.sas_address
));
5230 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
5231 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
5232 sas_target_priv_data
->deleted
= 1;
5233 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
5234 sas_target_priv_data
->handle
=
5235 MPT2SAS_INVALID_DEVICE_HANDLE
;
5238 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
5240 if (!ioc
->hide_drives
)
5241 mpt2sas_transport_port_remove(ioc
,
5242 sas_device_backup
.sas_address
,
5243 sas_device_backup
.sas_address_parent
);
5245 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
5246 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
5247 (unsigned long long) sas_device_backup
.sas_address
);
5249 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
5250 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5251 sas_device_backup
.handle
, (unsigned long long)
5252 sas_device_backup
.sas_address
));
5256 * mpt2sas_device_remove - removing device object
5257 * @ioc: per adapter object
5258 * @sas_address: expander sas_address
5263 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5265 struct _sas_device
*sas_device
;
5266 unsigned long flags
;
5268 if (ioc
->shost_recovery
)
5271 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5272 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5275 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5278 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5279 _scsih_remove_device(ioc
, sas_device
);
5282 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5284 * _scsih_sas_topology_change_event_debug - debug for topology event
5285 * @ioc: per adapter object
5286 * @event_data: event data payload
5290 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5291 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5297 char *status_str
= NULL
;
5298 u8 link_rate
, prev_link_rate
;
5300 switch (event_data
->ExpStatus
) {
5301 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5304 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5305 status_str
= "remove";
5307 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5309 status_str
= "responding";
5311 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5312 status_str
= "remove delay";
5315 status_str
= "unknown status";
5318 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
5319 ioc
->name
, status_str
);
5320 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
5321 "start_phy(%02d), count(%d)\n",
5322 le16_to_cpu(event_data
->ExpanderDevHandle
),
5323 le16_to_cpu(event_data
->EnclosureHandle
),
5324 event_data
->StartPhyNum
, event_data
->NumEntries
);
5325 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5326 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5329 phy_number
= event_data
->StartPhyNum
+ i
;
5330 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5331 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5332 switch (reason_code
) {
5333 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5334 status_str
= "target add";
5336 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5337 status_str
= "target remove";
5339 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5340 status_str
= "delay target remove";
5342 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5343 status_str
= "link rate change";
5345 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5346 status_str
= "target responding";
5349 status_str
= "unknown";
5352 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5353 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5354 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
5355 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5356 handle
, status_str
, link_rate
, prev_link_rate
);
5363 * _scsih_sas_topology_change_event - handle topology changes
5364 * @ioc: per adapter object
5365 * @fw_event: The fw_event_work object
5370 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5371 struct fw_event_work
*fw_event
)
5374 u16 parent_handle
, handle
;
5376 u8 phy_number
, max_phys
;
5377 struct _sas_node
*sas_expander
;
5378 struct _sas_device
*sas_device
;
5380 unsigned long flags
;
5381 u8 link_rate
, prev_link_rate
;
5382 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
5384 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5385 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5386 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5389 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5392 if (!ioc
->sas_hba
.num_phys
)
5393 _scsih_sas_host_add(ioc
);
5395 _scsih_sas_host_refresh(ioc
);
5397 if (fw_event
->ignore
) {
5398 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
5399 "event\n", ioc
->name
));
5403 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5405 /* handle expander add */
5406 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5407 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5410 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5411 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
5413 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5415 sas_address
= sas_expander
->sas_address
;
5416 max_phys
= sas_expander
->num_phys
;
5417 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5418 sas_address
= ioc
->sas_hba
.sas_address
;
5419 max_phys
= ioc
->sas_hba
.num_phys
;
5423 /* handle siblings events */
5424 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5425 if (fw_event
->ignore
) {
5426 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
5427 "expander event\n", ioc
->name
));
5430 if (ioc
->shost_recovery
|| ioc
->remove_host
||
5431 ioc
->pci_error_recovery
)
5433 phy_number
= event_data
->StartPhyNum
+ i
;
5434 if (phy_number
>= max_phys
)
5436 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5437 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5438 if ((event_data
->PHY
[i
].PhyStatus
&
5439 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5440 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5442 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5445 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5446 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5447 switch (reason_code
) {
5448 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5450 if (ioc
->shost_recovery
)
5453 if (link_rate
== prev_link_rate
)
5456 mpt2sas_transport_update_links(ioc
, sas_address
,
5457 handle
, phy_number
, link_rate
);
5459 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5462 _scsih_check_device(ioc
, handle
);
5464 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5466 if (ioc
->shost_recovery
)
5469 mpt2sas_transport_update_links(ioc
, sas_address
,
5470 handle
, phy_number
, link_rate
);
5472 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5474 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5476 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5477 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
5480 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
5484 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5485 _scsih_remove_device(ioc
, sas_device
);
5490 /* handle expander removal */
5491 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5493 mpt2sas_expander_remove(ioc
, sas_address
);
5497 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5499 * _scsih_sas_device_status_change_event_debug - debug for device event
5500 * @event_data: event data payload
5506 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5507 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5509 char *reason_str
= NULL
;
5511 switch (event_data
->ReasonCode
) {
5512 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5513 reason_str
= "smart data";
5515 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5516 reason_str
= "unsupported device discovered";
5518 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5519 reason_str
= "internal device reset";
5521 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5522 reason_str
= "internal task abort";
5524 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5525 reason_str
= "internal task abort set";
5527 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5528 reason_str
= "internal clear task set";
5530 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5531 reason_str
= "internal query task";
5533 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5534 reason_str
= "sata init failure";
5536 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5537 reason_str
= "internal device reset complete";
5539 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5540 reason_str
= "internal task abort complete";
5542 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5543 reason_str
= "internal async notification";
5545 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5546 reason_str
= "expander reduced functionality";
5548 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5549 reason_str
= "expander reduced functionality complete";
5552 reason_str
= "unknown reason";
5555 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5556 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5557 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5558 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5559 le16_to_cpu(event_data
->TaskTag
));
5560 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5561 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5562 event_data
->ASC
, event_data
->ASCQ
);
5563 printk(KERN_INFO
"\n");
5568 * _scsih_sas_device_status_change_event - handle device status change
5569 * @ioc: per adapter object
5570 * @fw_event: The fw_event_work object
5576 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5577 struct fw_event_work
*fw_event
)
5579 struct MPT2SAS_TARGET
*target_priv_data
;
5580 struct _sas_device
*sas_device
;
5582 unsigned long flags
;
5583 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5584 fw_event
->event_data
;
5586 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5587 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5588 _scsih_sas_device_status_change_event_debug(ioc
,
5592 /* In MPI Revision K (0xC), the internal device reset complete was
5593 * implemented, so avoid setting tm_busy flag for older firmware.
5595 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5598 if (event_data
->ReasonCode
!=
5599 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5600 event_data
->ReasonCode
!=
5601 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5604 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5605 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5606 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5608 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5610 if (!sas_device
|| !sas_device
->starget
)
5613 target_priv_data
= sas_device
->starget
->hostdata
;
5614 if (!target_priv_data
)
5617 if (event_data
->ReasonCode
==
5618 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5619 target_priv_data
->tm_busy
= 1;
5621 target_priv_data
->tm_busy
= 0;
5624 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5626 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5627 * @ioc: per adapter object
5628 * @event_data: event data payload
5634 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5635 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5637 char *reason_str
= NULL
;
5639 switch (event_data
->ReasonCode
) {
5640 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5641 reason_str
= "enclosure add";
5643 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5644 reason_str
= "enclosure remove";
5647 reason_str
= "unknown reason";
5651 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5652 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5653 " number slots(%d)\n", ioc
->name
, reason_str
,
5654 le16_to_cpu(event_data
->EnclosureHandle
),
5655 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5656 le16_to_cpu(event_data
->StartSlot
));
5661 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5662 * @ioc: per adapter object
5663 * @fw_event: The fw_event_work object
5669 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5670 struct fw_event_work
*fw_event
)
5672 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5673 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5674 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5675 fw_event
->event_data
);
5680 * _scsih_sas_broadcast_primative_event - handle broadcast events
5681 * @ioc: per adapter object
5682 * @fw_event: The fw_event_work object
5688 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5689 struct fw_event_work
*fw_event
)
5691 struct scsi_cmnd
*scmd
;
5692 struct scsi_device
*sdev
;
5695 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5696 u32 termination_count
;
5698 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5699 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5701 unsigned long flags
;
5704 u8 task_abort_retries
;
5706 mutex_lock(&ioc
->tm_cmds
.mutex
);
5707 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: phy number(%d), "
5708 "width(%d)\n", ioc
->name
, __func__
, event_data
->PhyNum
,
5709 event_data
->PortWidth
));
5711 _scsih_block_io_all_device(ioc
);
5713 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5714 mpi_reply
= ioc
->tm_cmds
.reply
;
5715 broadcast_aen_retry
:
5717 /* sanity checks for retrying this loop */
5718 if (max_retries
++ == 5) {
5719 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: giving up\n",
5720 ioc
->name
, __func__
));
5722 } else if (max_retries
> 1)
5723 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %d retry\n",
5724 ioc
->name
, __func__
, max_retries
- 1));
5726 termination_count
= 0;
5728 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5729 if (ioc
->shost_recovery
)
5731 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5734 sdev
= scmd
->device
;
5735 sas_device_priv_data
= sdev
->hostdata
;
5736 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5738 /* skip hidden raid components */
5739 if (sas_device_priv_data
->sas_target
->flags
&
5740 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5743 if (sas_device_priv_data
->sas_target
->flags
&
5744 MPT_TARGET_FLAGS_VOLUME
)
5747 handle
= sas_device_priv_data
->sas_target
->handle
;
5748 lun
= sas_device_priv_data
->lun
;
5751 if (ioc
->shost_recovery
)
5754 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5755 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5756 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, 0,
5759 sdev_printk(KERN_WARNING
, sdev
,
5760 "mpt2sas_scsih_issue_tm: FAILED when sending "
5761 "QUERY_TASK: scmd(%p)\n", scmd
);
5762 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5763 goto broadcast_aen_retry
;
5765 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5766 & MPI2_IOCSTATUS_MASK
;
5767 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5768 sdev_printk(KERN_WARNING
, sdev
, "query task: FAILED "
5769 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status
,
5771 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5772 goto broadcast_aen_retry
;
5775 /* see if IO is still owned by IOC and target */
5776 if (mpi_reply
->ResponseCode
==
5777 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5778 mpi_reply
->ResponseCode
==
5779 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5780 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5783 task_abort_retries
= 0;
5785 if (task_abort_retries
++ == 60) {
5786 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5787 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5789 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5790 goto broadcast_aen_retry
;
5793 if (ioc
->shost_recovery
)
5796 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5797 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5798 scmd
->serial_number
, TM_MUTEX_OFF
);
5800 sdev_printk(KERN_WARNING
, sdev
,
5801 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5802 "scmd(%p)\n", scmd
);
5806 if (task_abort_retries
> 1)
5807 sdev_printk(KERN_WARNING
, sdev
,
5808 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5810 task_abort_retries
- 1, scmd
);
5812 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5813 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5816 if (ioc
->broadcast_aen_pending
) {
5817 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: loop back due to"
5818 " pending AEN\n", ioc
->name
, __func__
));
5819 ioc
->broadcast_aen_pending
= 0;
5820 goto broadcast_aen_retry
;
5824 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5827 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5828 "%s - exit, query_count = %d termination_count = %d\n",
5829 ioc
->name
, __func__
, query_count
, termination_count
));
5831 ioc
->broadcast_aen_busy
= 0;
5832 if (!ioc
->shost_recovery
)
5833 _scsih_ublock_io_all_device(ioc
);
5834 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5838 * _scsih_sas_discovery_event - handle discovery events
5839 * @ioc: per adapter object
5840 * @fw_event: The fw_event_work object
5846 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5847 struct fw_event_work
*fw_event
)
5849 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5851 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5852 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5853 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5854 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5856 if (event_data
->DiscoveryStatus
)
5857 printk("discovery_status(0x%08x)",
5858 le32_to_cpu(event_data
->DiscoveryStatus
));
5863 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5864 !ioc
->sas_hba
.num_phys
)
5865 _scsih_sas_host_add(ioc
);
5869 * _scsih_reprobe_lun - reprobing lun
5870 * @sdev: scsi device struct
5871 * @no_uld_attach: sdev->no_uld_attach flag setting
5875 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5879 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5880 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5881 sdev
->no_uld_attach
? "hidding" : "exposing");
5882 rc
= scsi_device_reprobe(sdev
);
5886 * _scsih_reprobe_target - reprobing target
5887 * @starget: scsi target struct
5888 * @no_uld_attach: sdev->no_uld_attach flag setting
5890 * Note: no_uld_attach flag determines whether the disk device is attached
5891 * to block layer. A value of `1` means to not attach.
5894 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5896 struct MPT2SAS_TARGET
*sas_target_priv_data
= starget
->hostdata
;
5899 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5901 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5903 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5904 _scsih_reprobe_lun
);
5907 * _scsih_sas_volume_add - add new volume
5908 * @ioc: per adapter object
5909 * @element: IR config element data
5915 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5916 Mpi2EventIrConfigElement_t
*element
)
5918 struct _raid_device
*raid_device
;
5919 unsigned long flags
;
5921 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5924 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5926 printk(MPT2SAS_ERR_FMT
5927 "failure at %s:%d/%s()!\n", ioc
->name
,
5928 __FILE__
, __LINE__
, __func__
);
5932 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5933 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
5934 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5939 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
5941 printk(MPT2SAS_ERR_FMT
5942 "failure at %s:%d/%s()!\n", ioc
->name
,
5943 __FILE__
, __LINE__
, __func__
);
5947 raid_device
->id
= ioc
->sas_id
++;
5948 raid_device
->channel
= RAID_CHANNEL
;
5949 raid_device
->handle
= handle
;
5950 raid_device
->wwid
= wwid
;
5951 _scsih_raid_device_add(ioc
, raid_device
);
5952 if (!ioc
->wait_for_discovery_to_complete
) {
5953 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
5954 raid_device
->id
, 0);
5956 _scsih_raid_device_remove(ioc
, raid_device
);
5958 _scsih_determine_boot_device(ioc
, raid_device
, 1);
5962 * _scsih_sas_volume_delete - delete volume
5963 * @ioc: per adapter object
5964 * @handle: volume device handle
5970 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5972 struct _raid_device
*raid_device
;
5973 unsigned long flags
;
5974 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5976 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
5977 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
5978 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
5981 if (raid_device
->starget
) {
5982 sas_target_priv_data
= raid_device
->starget
->hostdata
;
5983 sas_target_priv_data
->deleted
= 1;
5984 scsi_remove_target(&raid_device
->starget
->dev
);
5986 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
5987 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
5988 (unsigned long long) raid_device
->wwid
);
5989 _scsih_raid_device_remove(ioc
, raid_device
);
5993 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5994 * @ioc: per adapter object
5995 * @element: IR config element data
6001 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
6002 Mpi2EventIrConfigElement_t
*element
)
6004 struct _sas_device
*sas_device
;
6005 unsigned long flags
;
6006 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6008 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6009 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6010 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6014 /* exposing raid component */
6015 sas_device
->volume_handle
= 0;
6016 sas_device
->volume_wwid
= 0;
6017 clear_bit(handle
, ioc
->pd_handles
);
6018 _scsih_reprobe_target(sas_device
->starget
, 0);
6022 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6023 * @ioc: per adapter object
6024 * @element: IR config element data
6030 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
6031 Mpi2EventIrConfigElement_t
*element
)
6033 struct _sas_device
*sas_device
;
6034 unsigned long flags
;
6035 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6037 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6038 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6039 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6043 /* hiding raid component */
6044 mpt2sas_config_get_volume_handle(ioc
, handle
,
6045 &sas_device
->volume_handle
);
6046 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
6047 &sas_device
->volume_wwid
);
6048 set_bit(handle
, ioc
->pd_handles
);
6049 _scsih_reprobe_target(sas_device
->starget
, 1);
6054 * _scsih_sas_pd_delete - delete pd component
6055 * @ioc: per adapter object
6056 * @element: IR config element data
6062 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
6063 Mpi2EventIrConfigElement_t
*element
)
6065 struct _sas_device
*sas_device
;
6066 unsigned long flags
;
6067 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6069 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6070 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6071 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6074 _scsih_remove_device(ioc
, sas_device
);
6078 * _scsih_sas_pd_add - remove pd component
6079 * @ioc: per adapter object
6080 * @element: IR config element data
6086 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
6087 Mpi2EventIrConfigElement_t
*element
)
6089 struct _sas_device
*sas_device
;
6090 unsigned long flags
;
6091 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6092 Mpi2ConfigReply_t mpi_reply
;
6093 Mpi2SasDevicePage0_t sas_device_pg0
;
6098 set_bit(handle
, ioc
->pd_handles
);
6100 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6101 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6102 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6106 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6107 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6108 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6109 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6113 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6114 MPI2_IOCSTATUS_MASK
;
6115 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6116 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6117 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6121 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6122 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6123 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6124 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6126 _scsih_add_device(ioc
, handle
, 0, 1);
6129 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6131 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6132 * @ioc: per adapter object
6133 * @event_data: event data payload
6139 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6140 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6142 Mpi2EventIrConfigElement_t
*element
;
6145 char *reason_str
= NULL
, *element_str
= NULL
;
6147 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6149 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
6150 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6151 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6152 "foreign" : "native", event_data
->NumElements
);
6153 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6154 switch (element
->ReasonCode
) {
6155 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6158 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6159 reason_str
= "remove";
6161 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6162 reason_str
= "no change";
6164 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6165 reason_str
= "hide";
6167 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6168 reason_str
= "unhide";
6170 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6171 reason_str
= "volume_created";
6173 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6174 reason_str
= "volume_deleted";
6176 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6177 reason_str
= "pd_created";
6179 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6180 reason_str
= "pd_deleted";
6183 reason_str
= "unknown reason";
6186 element_type
= le16_to_cpu(element
->ElementFlags
) &
6187 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6188 switch (element_type
) {
6189 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6190 element_str
= "volume";
6192 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6193 element_str
= "phys disk";
6195 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6196 element_str
= "hot spare";
6199 element_str
= "unknown element";
6202 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
6203 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6204 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6205 le16_to_cpu(element
->PhysDiskDevHandle
),
6206 element
->PhysDiskNum
);
6212 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6213 * @ioc: per adapter object
6214 * @fw_event: The fw_event_work object
6220 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
6221 struct fw_event_work
*fw_event
)
6223 Mpi2EventIrConfigElement_t
*element
;
6226 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
6228 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6229 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6230 && !ioc
->hide_ir_msg
)
6231 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6235 if (ioc
->shost_recovery
)
6238 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6239 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6241 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6242 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6244 switch (element
->ReasonCode
) {
6245 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6246 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6247 if (!foreign_config
)
6248 _scsih_sas_volume_add(ioc
, element
);
6250 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6251 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6252 if (!foreign_config
)
6253 _scsih_sas_volume_delete(ioc
,
6254 le16_to_cpu(element
->VolDevHandle
));
6256 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6257 if (!ioc
->is_warpdrive
)
6258 _scsih_sas_pd_hide(ioc
, element
);
6260 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6261 if (!ioc
->is_warpdrive
)
6262 _scsih_sas_pd_expose(ioc
, element
);
6264 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6265 if (!ioc
->is_warpdrive
)
6266 _scsih_sas_pd_add(ioc
, element
);
6268 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6269 if (!ioc
->is_warpdrive
)
6270 _scsih_sas_pd_delete(ioc
, element
);
6277 * _scsih_sas_ir_volume_event - IR volume event
6278 * @ioc: per adapter object
6279 * @fw_event: The fw_event_work object
6285 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
6286 struct fw_event_work
*fw_event
)
6289 unsigned long flags
;
6290 struct _raid_device
*raid_device
;
6294 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
6296 if (ioc
->shost_recovery
)
6299 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6302 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6303 state
= le32_to_cpu(event_data
->NewValue
);
6304 if (!ioc
->hide_ir_msg
)
6305 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6306 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6307 le32_to_cpu(event_data
->PreviousValue
), state
));
6310 case MPI2_RAID_VOL_STATE_MISSING
:
6311 case MPI2_RAID_VOL_STATE_FAILED
:
6312 _scsih_sas_volume_delete(ioc
, handle
);
6315 case MPI2_RAID_VOL_STATE_ONLINE
:
6316 case MPI2_RAID_VOL_STATE_DEGRADED
:
6317 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6319 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6320 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6321 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6326 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6328 printk(MPT2SAS_ERR_FMT
6329 "failure at %s:%d/%s()!\n", ioc
->name
,
6330 __FILE__
, __LINE__
, __func__
);
6334 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6336 printk(MPT2SAS_ERR_FMT
6337 "failure at %s:%d/%s()!\n", ioc
->name
,
6338 __FILE__
, __LINE__
, __func__
);
6342 raid_device
->id
= ioc
->sas_id
++;
6343 raid_device
->channel
= RAID_CHANNEL
;
6344 raid_device
->handle
= handle
;
6345 raid_device
->wwid
= wwid
;
6346 _scsih_raid_device_add(ioc
, raid_device
);
6347 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6348 raid_device
->id
, 0);
6350 _scsih_raid_device_remove(ioc
, raid_device
);
6353 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6360 * _scsih_sas_ir_physical_disk_event - PD event
6361 * @ioc: per adapter object
6362 * @fw_event: The fw_event_work object
6368 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
6369 struct fw_event_work
*fw_event
)
6371 u16 handle
, parent_handle
;
6373 struct _sas_device
*sas_device
;
6374 unsigned long flags
;
6375 Mpi2ConfigReply_t mpi_reply
;
6376 Mpi2SasDevicePage0_t sas_device_pg0
;
6378 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
6381 if (ioc
->shost_recovery
)
6384 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6387 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6388 state
= le32_to_cpu(event_data
->NewValue
);
6390 if (!ioc
->hide_ir_msg
)
6391 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6392 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6393 le32_to_cpu(event_data
->PreviousValue
), state
));
6396 case MPI2_RAID_PD_STATE_ONLINE
:
6397 case MPI2_RAID_PD_STATE_DEGRADED
:
6398 case MPI2_RAID_PD_STATE_REBUILDING
:
6399 case MPI2_RAID_PD_STATE_OPTIMAL
:
6400 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6402 if (!ioc
->is_warpdrive
)
6403 set_bit(handle
, ioc
->pd_handles
);
6405 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6406 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6407 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6412 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6413 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6415 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6416 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6420 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6421 MPI2_IOCSTATUS_MASK
;
6422 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6423 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6424 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6428 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6429 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6430 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6431 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6433 _scsih_add_device(ioc
, handle
, 0, 1);
6437 case MPI2_RAID_PD_STATE_OFFLINE
:
6438 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6439 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6445 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6447 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6448 * @ioc: per adapter object
6449 * @event_data: event data payload
6455 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6456 Mpi2EventDataIrOperationStatus_t
*event_data
)
6458 char *reason_str
= NULL
;
6460 switch (event_data
->RAIDOperation
) {
6461 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6462 reason_str
= "resync";
6464 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6465 reason_str
= "online capacity expansion";
6467 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6468 reason_str
= "consistency check";
6470 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6471 reason_str
= "background init";
6473 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6474 reason_str
= "make data consistent";
6481 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
6482 "\thandle(0x%04x), percent complete(%d)\n",
6483 ioc
->name
, reason_str
,
6484 le16_to_cpu(event_data
->VolDevHandle
),
6485 event_data
->PercentComplete
);
6490 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6491 * @ioc: per adapter object
6492 * @fw_event: The fw_event_work object
6498 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
6499 struct fw_event_work
*fw_event
)
6501 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
6502 static struct _raid_device
*raid_device
;
6503 unsigned long flags
;
6506 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6507 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6508 && !ioc
->hide_ir_msg
)
6509 _scsih_sas_ir_operation_status_event_debug(ioc
,
6513 /* code added for raid transport support */
6514 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6516 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6518 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6519 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6520 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6525 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
6526 raid_device
->percent_complete
=
6527 event_data
->PercentComplete
;
6532 * _scsih_prep_device_scan - initialize parameters prior to device scan
6533 * @ioc: per adapter object
6535 * Set the deleted flag prior to device scan. If the device is found during
6536 * the scan, then we clear the deleted flag.
6539 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
6541 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
6542 struct scsi_device
*sdev
;
6544 shost_for_each_device(sdev
, ioc
->shost
) {
6545 sas_device_priv_data
= sdev
->hostdata
;
6546 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6547 sas_device_priv_data
->sas_target
->deleted
= 1;
6552 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6553 * @ioc: per adapter object
6554 * @sas_address: sas address
6555 * @slot: enclosure slot id
6556 * @handle: device handle
6558 * After host reset, find out whether devices are still responding.
6559 * Used in _scsi_remove_unresponsive_sas_devices.
6564 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6565 u16 slot
, u16 handle
)
6567 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
6568 struct scsi_target
*starget
;
6569 struct _sas_device
*sas_device
;
6570 unsigned long flags
;
6572 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6573 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6574 if (sas_device
->sas_address
== sas_address
&&
6575 sas_device
->slot
== slot
) {
6576 sas_device
->responding
= 1;
6577 starget
= sas_device
->starget
;
6578 if (starget
&& starget
->hostdata
) {
6579 sas_target_priv_data
= starget
->hostdata
;
6580 sas_target_priv_data
->tm_busy
= 0;
6581 sas_target_priv_data
->deleted
= 0;
6583 sas_target_priv_data
= NULL
;
6585 starget_printk(KERN_INFO
, starget
,
6586 "handle(0x%04x), sas_addr(0x%016llx), "
6587 "enclosure logical id(0x%016llx), "
6588 "slot(%d)\n", handle
,
6589 (unsigned long long)sas_device
->sas_address
,
6590 (unsigned long long)
6591 sas_device
->enclosure_logical_id
,
6593 if (sas_device
->handle
== handle
)
6595 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6596 sas_device
->handle
);
6597 sas_device
->handle
= handle
;
6598 if (sas_target_priv_data
)
6599 sas_target_priv_data
->handle
= handle
;
6604 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6608 * _scsih_search_responding_sas_devices -
6609 * @ioc: per adapter object
6611 * After host reset, find out whether devices are still responding.
6617 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6619 Mpi2SasDevicePage0_t sas_device_pg0
;
6620 Mpi2ConfigReply_t mpi_reply
;
6627 printk(MPT2SAS_INFO_FMT
"search for end-devices: start\n", ioc
->name
);
6629 if (list_empty(&ioc
->sas_device_list
))
6633 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6634 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6636 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6637 MPI2_IOCSTATUS_MASK
;
6638 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6640 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6641 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6642 if (!(_scsih_is_end_device(device_info
)))
6644 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6645 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6646 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6650 printk(MPT2SAS_INFO_FMT
"search for end-devices: complete\n",
6655 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6656 * @ioc: per adapter object
6657 * @wwid: world wide identifier for raid volume
6658 * @handle: device handle
6660 * After host reset, find out whether devices are still responding.
6661 * Used in _scsi_remove_unresponsive_raid_devices.
6666 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6669 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6670 struct scsi_target
*starget
;
6671 struct _raid_device
*raid_device
;
6672 unsigned long flags
;
6674 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6675 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6676 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6677 starget
= raid_device
->starget
;
6678 if (starget
&& starget
->hostdata
) {
6679 sas_target_priv_data
= starget
->hostdata
;
6680 sas_target_priv_data
->deleted
= 0;
6682 sas_target_priv_data
= NULL
;
6683 raid_device
->responding
= 1;
6684 starget_printk(KERN_INFO
, raid_device
->starget
,
6685 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6686 (unsigned long long)raid_device
->wwid
);
6688 * WARPDRIVE: The handles of the PDs might have changed
6689 * across the host reset so re-initialize the
6690 * required data for Direct IO
6692 _scsih_init_warpdrive_properties(ioc
, raid_device
);
6693 if (raid_device
->handle
== handle
)
6695 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6696 raid_device
->handle
);
6697 raid_device
->handle
= handle
;
6698 if (sas_target_priv_data
)
6699 sas_target_priv_data
->handle
= handle
;
6704 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6708 * _scsih_search_responding_raid_devices -
6709 * @ioc: per adapter object
6711 * After host reset, find out whether devices are still responding.
6717 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6719 Mpi2RaidVolPage1_t volume_pg1
;
6720 Mpi2RaidVolPage0_t volume_pg0
;
6721 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6722 Mpi2ConfigReply_t mpi_reply
;
6727 if (!ioc
->ir_firmware
)
6730 printk(MPT2SAS_INFO_FMT
"search for raid volumes: start\n",
6733 if (list_empty(&ioc
->raid_device_list
))
6737 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6738 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6739 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6740 MPI2_IOCSTATUS_MASK
;
6741 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6743 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6745 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6746 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6747 sizeof(Mpi2RaidVolPage0_t
)))
6750 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6751 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6752 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6753 _scsih_mark_responding_raid_device(ioc
,
6754 le64_to_cpu(volume_pg1
.WWID
), handle
);
6757 /* refresh the pd_handles */
6758 if (!ioc
->is_warpdrive
) {
6759 phys_disk_num
= 0xFF;
6760 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6761 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6762 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6764 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6765 MPI2_IOCSTATUS_MASK
;
6766 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6768 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6769 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6770 set_bit(handle
, ioc
->pd_handles
);
6774 printk(MPT2SAS_INFO_FMT
"search for responding raid volumes: "
6775 "complete\n", ioc
->name
);
6779 * _scsih_mark_responding_expander - mark a expander as responding
6780 * @ioc: per adapter object
6781 * @sas_address: sas address
6784 * After host reset, find out whether devices are still responding.
6785 * Used in _scsi_remove_unresponsive_expanders.
6790 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6793 struct _sas_node
*sas_expander
;
6794 unsigned long flags
;
6797 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6798 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6799 if (sas_expander
->sas_address
!= sas_address
)
6801 sas_expander
->responding
= 1;
6802 if (sas_expander
->handle
== handle
)
6804 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6805 " from(0x%04x) to (0x%04x)!!!\n",
6806 (unsigned long long)sas_expander
->sas_address
,
6807 sas_expander
->handle
, handle
);
6808 sas_expander
->handle
= handle
;
6809 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6810 sas_expander
->phy
[i
].handle
= handle
;
6814 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6818 * _scsih_search_responding_expanders -
6819 * @ioc: per adapter object
6821 * After host reset, find out whether devices are still responding.
6827 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6829 Mpi2ExpanderPage0_t expander_pg0
;
6830 Mpi2ConfigReply_t mpi_reply
;
6835 printk(MPT2SAS_INFO_FMT
"search for expanders: start\n", ioc
->name
);
6837 if (list_empty(&ioc
->sas_expander_list
))
6841 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6842 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6844 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6845 MPI2_IOCSTATUS_MASK
;
6846 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6849 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6850 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6851 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6852 "sas_addr(0x%016llx)\n", handle
,
6853 (unsigned long long)sas_address
);
6854 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6858 printk(MPT2SAS_INFO_FMT
"search for expanders: complete\n", ioc
->name
);
6862 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6863 * @ioc: per adapter object
6868 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6870 struct _sas_device
*sas_device
, *sas_device_next
;
6871 struct _sas_node
*sas_expander
;
6872 struct _raid_device
*raid_device
, *raid_device_next
;
6874 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: start\n",
6877 list_for_each_entry_safe(sas_device
, sas_device_next
,
6878 &ioc
->sas_device_list
, list
) {
6879 if (sas_device
->responding
) {
6880 sas_device
->responding
= 0;
6883 if (sas_device
->starget
)
6884 starget_printk(KERN_INFO
, sas_device
->starget
,
6885 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6886 "enclosure logical id(0x%016llx), slot(%d)\n",
6888 (unsigned long long)sas_device
->sas_address
,
6889 (unsigned long long)
6890 sas_device
->enclosure_logical_id
,
6892 _scsih_remove_device(ioc
, sas_device
);
6895 if (!ioc
->ir_firmware
)
6896 goto retry_expander_search
;
6898 list_for_each_entry_safe(raid_device
, raid_device_next
,
6899 &ioc
->raid_device_list
, list
) {
6900 if (raid_device
->responding
) {
6901 raid_device
->responding
= 0;
6904 if (raid_device
->starget
) {
6905 starget_printk(KERN_INFO
, raid_device
->starget
,
6906 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6907 raid_device
->handle
,
6908 (unsigned long long)raid_device
->wwid
);
6909 scsi_remove_target(&raid_device
->starget
->dev
);
6911 _scsih_raid_device_remove(ioc
, raid_device
);
6914 retry_expander_search
:
6915 sas_expander
= NULL
;
6916 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6917 if (sas_expander
->responding
) {
6918 sas_expander
->responding
= 0;
6921 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6922 goto retry_expander_search
;
6924 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: complete\n",
6926 /* unblock devices */
6927 _scsih_ublock_io_all_device(ioc
);
6931 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER
*ioc
,
6932 struct _sas_node
*sas_expander
, u16 handle
)
6934 Mpi2ExpanderPage1_t expander_pg1
;
6935 Mpi2ConfigReply_t mpi_reply
;
6938 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
6939 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
6940 &expander_pg1
, i
, handle
))) {
6941 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6942 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6946 mpt2sas_transport_update_links(ioc
, sas_expander
->sas_address
,
6947 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
6948 expander_pg1
.NegotiatedLinkRate
>> 4);
6953 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6954 * @ioc: per adapter object
6959 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER
*ioc
)
6961 Mpi2ExpanderPage0_t expander_pg0
;
6962 Mpi2SasDevicePage0_t sas_device_pg0
;
6963 Mpi2RaidVolPage1_t volume_pg1
;
6964 Mpi2RaidVolPage0_t volume_pg0
;
6965 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6966 Mpi2EventIrConfigElement_t element
;
6967 Mpi2ConfigReply_t mpi_reply
;
6970 u16 handle
, parent_handle
;
6972 struct _sas_device
*sas_device
;
6973 struct _sas_node
*expander_device
;
6974 static struct _raid_device
*raid_device
;
6976 printk(MPT2SAS_INFO_FMT
"scan devices: start\n", ioc
->name
);
6978 _scsih_sas_host_refresh(ioc
);
6982 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6983 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6984 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6985 MPI2_IOCSTATUS_MASK
;
6986 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6988 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6989 expander_device
= mpt2sas_scsih_expander_find_by_sas_address(
6990 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
6991 if (expander_device
)
6992 _scsih_refresh_expander_links(ioc
, expander_device
,
6995 _scsih_expander_add(ioc
, handle
);
6998 if (!ioc
->ir_firmware
)
7002 phys_disk_num
= 0xFF;
7003 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7004 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7006 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7007 MPI2_IOCSTATUS_MASK
;
7008 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7010 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7011 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7012 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
7015 if (mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7016 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7019 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7020 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7022 mpt2sas_transport_update_links(ioc
, sas_address
,
7023 handle
, sas_device_pg0
.PhyNum
,
7024 MPI2_SAS_NEG_LINK_RATE_1_5
);
7025 set_bit(handle
, ioc
->pd_handles
);
7026 _scsih_add_device(ioc
, handle
, 0, 1);
7032 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7033 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7034 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7035 MPI2_IOCSTATUS_MASK
;
7036 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7038 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7039 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7040 le64_to_cpu(volume_pg1
.WWID
));
7043 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7044 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7045 sizeof(Mpi2RaidVolPage0_t
)))
7047 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7048 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7049 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7050 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7051 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7052 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7053 _scsih_sas_volume_add(ioc
, &element
);
7061 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7062 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7064 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7065 MPI2_IOCSTATUS_MASK
;
7066 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7068 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7069 if (!(_scsih_is_end_device(
7070 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7072 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
7073 le64_to_cpu(sas_device_pg0
.SASAddress
));
7076 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7077 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7078 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
7079 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7080 _scsih_add_device(ioc
, handle
, 0, 0);
7084 printk(MPT2SAS_INFO_FMT
"scan devices: complete\n", ioc
->name
);
7089 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7090 * @ioc: per adapter object
7091 * @reset_phase: phase
7093 * The handler for doing any required cleanup or initialization.
7095 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7096 * MPT2_IOC_DONE_RESET
7101 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
7103 switch (reset_phase
) {
7104 case MPT2_IOC_PRE_RESET
:
7105 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7106 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7108 case MPT2_IOC_AFTER_RESET
:
7109 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7110 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7111 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
7112 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
7113 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7114 complete(&ioc
->scsih_cmds
.done
);
7116 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
7117 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
7118 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7119 complete(&ioc
->tm_cmds
.done
);
7121 _scsih_fw_event_cleanup_queue(ioc
);
7122 _scsih_flush_running_cmds(ioc
);
7124 case MPT2_IOC_DONE_RESET
:
7125 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7126 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7127 _scsih_sas_host_refresh(ioc
);
7128 _scsih_prep_device_scan(ioc
);
7129 _scsih_search_responding_sas_devices(ioc
);
7130 _scsih_search_responding_raid_devices(ioc
);
7131 _scsih_search_responding_expanders(ioc
);
7132 if (!ioc
->is_driver_loading
) {
7133 _scsih_prep_device_scan(ioc
);
7134 _scsih_search_responding_sas_devices(ioc
);
7135 _scsih_search_responding_raid_devices(ioc
);
7136 _scsih_search_responding_expanders(ioc
);
7137 _scsih_error_recovery_delete_devices(ioc
);
7144 * _firmware_event_work - delayed task for processing firmware events
7145 * @ioc: per adapter object
7146 * @work: equal to the fw_event_work object
7152 _firmware_event_work(struct work_struct
*work
)
7154 struct fw_event_work
*fw_event
= container_of(work
,
7155 struct fw_event_work
, delayed_work
.work
);
7156 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
7158 /* the queue is being flushed so ignore this event */
7159 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
7160 ioc
->pci_error_recovery
) {
7161 _scsih_fw_event_free(ioc
, fw_event
);
7165 switch (fw_event
->event
) {
7166 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES
:
7167 while (scsi_host_in_recovery(ioc
->shost
))
7169 _scsih_remove_unresponding_sas_devices(ioc
);
7170 _scsih_scan_for_devices_after_reset(ioc
);
7172 case MPT2SAS_PORT_ENABLE_COMPLETE
:
7173 ioc
->start_scan
= 0;
7177 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"port enable: complete "
7178 "from worker thread\n", ioc
->name
));
7180 case MPT2SAS_TURN_ON_FAULT_LED
:
7181 _scsih_turn_on_fault_led(ioc
, fw_event
->device_handle
);
7183 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7184 _scsih_sas_topology_change_event(ioc
, fw_event
);
7186 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7187 _scsih_sas_device_status_change_event(ioc
,
7190 case MPI2_EVENT_SAS_DISCOVERY
:
7191 _scsih_sas_discovery_event(ioc
,
7194 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7195 _scsih_sas_broadcast_primative_event(ioc
,
7198 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7199 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7202 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7203 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7205 case MPI2_EVENT_IR_VOLUME
:
7206 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7208 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7209 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7211 case MPI2_EVENT_IR_OPERATION_STATUS
:
7212 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7215 _scsih_fw_event_free(ioc
, fw_event
);
7219 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7220 * @ioc: per adapter object
7221 * @msix_index: MSIX table index supplied by the OS
7222 * @reply: reply message frame(lower 32bit addr)
7223 * Context: interrupt.
7225 * This function merely adds a new work task into ioc->firmware_event_thread.
7226 * The tasks are worked from _firmware_event_work in user context.
7228 * Return 1 meaning mf should be freed from _base_interrupt
7229 * 0 means the mf is freed from this function.
7232 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
7235 struct fw_event_work
*fw_event
;
7236 Mpi2EventNotificationReply_t
*mpi_reply
;
7240 /* events turned off due to host reset or driver unloading */
7241 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7244 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
7245 event
= le16_to_cpu(mpi_reply
->Event
);
7249 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7251 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7252 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7253 mpi_reply
->EventData
;
7255 if (baen_data
->Primitive
!=
7256 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7259 if (ioc
->broadcast_aen_busy
) {
7260 ioc
->broadcast_aen_pending
++;
7263 ioc
->broadcast_aen_busy
= 1;
7267 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7268 _scsih_check_topo_delete_events(ioc
,
7269 (Mpi2EventDataSasTopologyChangeList_t
*)
7270 mpi_reply
->EventData
);
7272 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7273 _scsih_check_ir_config_unhide_events(ioc
,
7274 (Mpi2EventDataIrConfigChangeList_t
*)
7275 mpi_reply
->EventData
);
7277 case MPI2_EVENT_IR_VOLUME
:
7278 _scsih_check_volume_delete_events(ioc
,
7279 (Mpi2EventDataIrVolume_t
*)
7280 mpi_reply
->EventData
);
7282 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7284 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7287 if (!ioc
->is_warpdrive
)
7290 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7291 mpi_reply
->EventData
;
7292 log_code
= (u32
*)log_entry
->LogData
;
7294 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7295 != MPT2_WARPDRIVE_LOGENTRY
)
7298 switch (le32_to_cpu(*log_code
)) {
7299 case MPT2_WARPDRIVE_LC_SSDT
:
7300 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7301 "IO Throttling has occurred in the WarpDrive "
7302 "subsystem. Check WarpDrive documentation for "
7303 "additional details.\n", ioc
->name
);
7305 case MPT2_WARPDRIVE_LC_SSDLW
:
7306 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7307 "Program/Erase Cycles for the WarpDrive subsystem "
7308 "in degraded range. Check WarpDrive documentation "
7309 "for additional details.\n", ioc
->name
);
7311 case MPT2_WARPDRIVE_LC_SSDLF
:
7312 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7313 "There are no Program/Erase Cycles for the "
7314 "WarpDrive subsystem. The storage device will be "
7315 "in read-only mode. Check WarpDrive documentation "
7316 "for additional details.\n", ioc
->name
);
7318 case MPT2_WARPDRIVE_LC_BRMF
:
7319 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7320 "The Backup Rail Monitor has failed on the "
7321 "WarpDrive subsystem. Check WarpDrive "
7322 "documentation for additional details.\n",
7329 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7330 case MPI2_EVENT_IR_OPERATION_STATUS
:
7331 case MPI2_EVENT_SAS_DISCOVERY
:
7332 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7333 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7336 default: /* ignore the rest */
7340 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
7342 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7343 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7346 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7347 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
7348 if (!fw_event
->event_data
) {
7349 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7350 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7355 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
7357 fw_event
->ioc
= ioc
;
7358 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7359 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7360 fw_event
->event
= event
;
7361 _scsih_fw_event_add(ioc
, fw_event
);
7365 /* shost template */
7366 static struct scsi_host_template scsih_driver_template
= {
7367 .module
= THIS_MODULE
,
7368 .name
= "Fusion MPT SAS Host",
7369 .proc_name
= MPT2SAS_DRIVER_NAME
,
7370 .queuecommand
= _scsih_qcmd
,
7371 .target_alloc
= _scsih_target_alloc
,
7372 .slave_alloc
= _scsih_slave_alloc
,
7373 .slave_configure
= _scsih_slave_configure
,
7374 .target_destroy
= _scsih_target_destroy
,
7375 .slave_destroy
= _scsih_slave_destroy
,
7376 .scan_finished
= _scsih_scan_finished
,
7377 .scan_start
= _scsih_scan_start
,
7378 .change_queue_depth
= _scsih_change_queue_depth
,
7379 .change_queue_type
= _scsih_change_queue_type
,
7380 .eh_abort_handler
= _scsih_abort
,
7381 .eh_device_reset_handler
= _scsih_dev_reset
,
7382 .eh_target_reset_handler
= _scsih_target_reset
,
7383 .eh_host_reset_handler
= _scsih_host_reset
,
7384 .bios_param
= _scsih_bios_param
,
7387 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
7388 .max_sectors
= 8192,
7390 .use_clustering
= ENABLE_CLUSTERING
,
7391 .shost_attrs
= mpt2sas_host_attrs
,
7392 .sdev_attrs
= mpt2sas_dev_attrs
,
7396 * _scsih_expander_node_remove - removing expander device from list.
7397 * @ioc: per adapter object
7398 * @sas_expander: the sas_device object
7399 * Context: Calling function should acquire ioc->sas_node_lock.
7401 * Removing object and freeing associated memory from the
7402 * ioc->sas_expander_list.
7407 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
7408 struct _sas_node
*sas_expander
)
7410 struct _sas_port
*mpt2sas_port
, *next
;
7412 /* remove sibling ports attached to this expander */
7413 list_for_each_entry_safe(mpt2sas_port
, next
,
7414 &sas_expander
->sas_port_list
, port_list
) {
7415 if (ioc
->shost_recovery
)
7417 if (mpt2sas_port
->remote_identify
.device_type
==
7419 mpt2sas_device_remove(ioc
,
7420 mpt2sas_port
->remote_identify
.sas_address
);
7421 else if (mpt2sas_port
->remote_identify
.device_type
==
7422 SAS_EDGE_EXPANDER_DEVICE
||
7423 mpt2sas_port
->remote_identify
.device_type
==
7424 SAS_FANOUT_EXPANDER_DEVICE
)
7425 mpt2sas_expander_remove(ioc
,
7426 mpt2sas_port
->remote_identify
.sas_address
);
7429 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7430 sas_expander
->sas_address_parent
);
7432 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
7433 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7434 sas_expander
->handle
, (unsigned long long)
7435 sas_expander
->sas_address
);
7437 kfree(sas_expander
->phy
);
7438 kfree(sas_expander
);
7442 * _scsih_ir_shutdown - IR shutdown notification
7443 * @ioc: per adapter object
7445 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7446 * the host system is shutting down.
7451 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
7453 Mpi2RaidActionRequest_t
*mpi_request
;
7454 Mpi2RaidActionReply_t
*mpi_reply
;
7457 /* is IR firmware build loaded ? */
7458 if (!ioc
->ir_firmware
)
7461 /* are there any volumes ? */
7462 if (list_empty(&ioc
->raid_device_list
))
7465 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7467 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
7468 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
7469 ioc
->name
, __func__
);
7472 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
7474 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7476 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
7477 ioc
->name
, __func__
);
7478 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7482 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
7483 ioc
->scsih_cmds
.smid
= smid
;
7484 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7486 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7487 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7489 if (!ioc
->hide_ir_msg
)
7490 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
7491 init_completion(&ioc
->scsih_cmds
.done
);
7492 mpt2sas_base_put_smid_default(ioc
, smid
);
7493 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7495 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
7496 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
7497 ioc
->name
, __func__
);
7501 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
7502 mpi_reply
= ioc
->scsih_cmds
.reply
;
7504 if (!ioc
->hide_ir_msg
)
7505 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
7506 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7507 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7508 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7512 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7513 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7517 * _scsih_shutdown - routine call during system shutdown
7518 * @pdev: PCI device struct
7523 _scsih_shutdown(struct pci_dev
*pdev
)
7525 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7526 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7527 struct workqueue_struct
*wq
;
7528 unsigned long flags
;
7530 ioc
->remove_host
= 1;
7531 _scsih_fw_event_cleanup_queue(ioc
);
7533 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7534 wq
= ioc
->firmware_event_thread
;
7535 ioc
->firmware_event_thread
= NULL
;
7536 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7538 destroy_workqueue(wq
);
7540 _scsih_ir_shutdown(ioc
);
7541 mpt2sas_base_detach(ioc
);
7545 * _scsih_remove - detach and remove add host
7546 * @pdev: PCI device struct
7548 * Routine called when unloading the driver.
7551 static void __devexit
7552 _scsih_remove(struct pci_dev
*pdev
)
7554 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7555 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7556 struct _sas_port
*mpt2sas_port
, *next_port
;
7557 struct _raid_device
*raid_device
, *next
;
7558 struct MPT2SAS_TARGET
*sas_target_priv_data
;
7559 struct workqueue_struct
*wq
;
7560 unsigned long flags
;
7562 ioc
->remove_host
= 1;
7563 _scsih_fw_event_cleanup_queue(ioc
);
7565 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7566 wq
= ioc
->firmware_event_thread
;
7567 ioc
->firmware_event_thread
= NULL
;
7568 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7570 destroy_workqueue(wq
);
7572 /* release all the volumes */
7573 _scsih_ir_shutdown(ioc
);
7574 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7576 if (raid_device
->starget
) {
7577 sas_target_priv_data
=
7578 raid_device
->starget
->hostdata
;
7579 sas_target_priv_data
->deleted
= 1;
7580 scsi_remove_target(&raid_device
->starget
->dev
);
7582 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
7583 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
7584 (unsigned long long) raid_device
->wwid
);
7585 _scsih_raid_device_remove(ioc
, raid_device
);
7588 /* free ports attached to the sas_host */
7589 list_for_each_entry_safe(mpt2sas_port
, next_port
,
7590 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7591 if (mpt2sas_port
->remote_identify
.device_type
==
7593 mpt2sas_device_remove(ioc
,
7594 mpt2sas_port
->remote_identify
.sas_address
);
7595 else if (mpt2sas_port
->remote_identify
.device_type
==
7596 SAS_EDGE_EXPANDER_DEVICE
||
7597 mpt2sas_port
->remote_identify
.device_type
==
7598 SAS_FANOUT_EXPANDER_DEVICE
)
7599 mpt2sas_expander_remove(ioc
,
7600 mpt2sas_port
->remote_identify
.sas_address
);
7603 /* free phys attached to the sas_host */
7604 if (ioc
->sas_hba
.num_phys
) {
7605 kfree(ioc
->sas_hba
.phy
);
7606 ioc
->sas_hba
.phy
= NULL
;
7607 ioc
->sas_hba
.num_phys
= 0;
7610 sas_remove_host(shost
);
7611 mpt2sas_base_detach(ioc
);
7612 list_del(&ioc
->list
);
7613 scsi_remove_host(shost
);
7614 scsi_host_put(shost
);
7618 * _scsih_probe_boot_devices - reports 1st device
7619 * @ioc: per adapter object
7621 * If specified in bios page 2, this routine reports the 1st
7622 * device scsi-ml or sas transport for persistent boot device
7623 * purposes. Please refer to function _scsih_determine_boot_device()
7626 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
7630 struct _sas_device
*sas_device
;
7631 struct _raid_device
*raid_device
;
7633 u64 sas_address_parent
;
7635 unsigned long flags
;
7638 /* no Bios, return immediately */
7639 if (!ioc
->bios_pg3
.BiosVersion
)
7644 if (ioc
->req_boot_device
.device
) {
7645 device
= ioc
->req_boot_device
.device
;
7646 is_raid
= ioc
->req_boot_device
.is_raid
;
7647 } else if (ioc
->req_alt_boot_device
.device
) {
7648 device
= ioc
->req_alt_boot_device
.device
;
7649 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7650 } else if (ioc
->current_boot_device
.device
) {
7651 device
= ioc
->current_boot_device
.device
;
7652 is_raid
= ioc
->current_boot_device
.is_raid
;
7659 raid_device
= device
;
7660 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7661 raid_device
->id
, 0);
7663 _scsih_raid_device_remove(ioc
, raid_device
);
7665 sas_device
= device
;
7666 handle
= sas_device
->handle
;
7667 sas_address_parent
= sas_device
->sas_address_parent
;
7668 sas_address
= sas_device
->sas_address
;
7669 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7670 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7671 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7673 if (ioc
->hide_drives
)
7675 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7676 sas_device
->sas_address_parent
)) {
7677 _scsih_sas_device_remove(ioc
, sas_device
);
7678 } else if (!sas_device
->starget
) {
7679 mpt2sas_transport_port_remove(ioc
, sas_address
,
7680 sas_address_parent
);
7681 _scsih_sas_device_remove(ioc
, sas_device
);
7687 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7688 * @ioc: per adapter object
7690 * Called during initial loading of the driver.
7693 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
7695 struct _raid_device
*raid_device
, *raid_next
;
7698 list_for_each_entry_safe(raid_device
, raid_next
,
7699 &ioc
->raid_device_list
, list
) {
7700 if (raid_device
->starget
)
7702 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7703 raid_device
->id
, 0);
7705 _scsih_raid_device_remove(ioc
, raid_device
);
7710 * _scsih_probe_sas - reporting sas devices to sas transport
7711 * @ioc: per adapter object
7713 * Called during initial loading of the driver.
7716 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
7718 struct _sas_device
*sas_device
, *next
;
7719 unsigned long flags
;
7721 /* SAS Device List */
7722 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7725 if (ioc
->hide_drives
)
7728 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7729 sas_device
->sas_address_parent
)) {
7730 list_del(&sas_device
->list
);
7733 } else if (!sas_device
->starget
) {
7734 mpt2sas_transport_port_remove(ioc
,
7735 sas_device
->sas_address
,
7736 sas_device
->sas_address_parent
);
7737 list_del(&sas_device
->list
);
7742 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7743 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7744 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7749 * _scsih_probe_devices - probing for devices
7750 * @ioc: per adapter object
7752 * Called during initial loading of the driver.
7755 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
7757 u16 volume_mapping_flags
;
7759 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
7760 return; /* return when IOC doesn't support initiator mode */
7762 _scsih_probe_boot_devices(ioc
);
7764 if (ioc
->ir_firmware
) {
7765 volume_mapping_flags
=
7766 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
7767 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
7768 if (volume_mapping_flags
==
7769 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
7770 _scsih_probe_raid(ioc
);
7771 _scsih_probe_sas(ioc
);
7773 _scsih_probe_sas(ioc
);
7774 _scsih_probe_raid(ioc
);
7777 _scsih_probe_sas(ioc
);
7782 * _scsih_scan_start - scsi lld callback for .scan_start
7783 * @shost: SCSI host pointer
7785 * The shost has the ability to discover targets on its own instead
7786 * of scanning the entire bus. In our implemention, we will kick off
7787 * firmware discovery.
7790 _scsih_scan_start(struct Scsi_Host
*shost
)
7792 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7795 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
7796 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
7798 ioc
->start_scan
= 1;
7799 rc
= mpt2sas_port_enable(ioc
);
7802 printk(MPT2SAS_INFO_FMT
"port enable: FAILED\n", ioc
->name
);
7806 * _scsih_scan_finished - scsi lld callback for .scan_finished
7807 * @shost: SCSI host pointer
7808 * @time: elapsed time of the scan in jiffies
7810 * This function will be called periodically until it returns 1 with the
7811 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7812 * we wait for firmware discovery to complete, then return 1.
7815 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
7817 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7819 if (time
>= (300 * HZ
)) {
7820 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
7821 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with timeout "
7822 "(timeout=300s)\n", ioc
->name
);
7823 ioc
->is_driver_loading
= 0;
7827 if (ioc
->start_scan
)
7830 if (ioc
->start_scan_failed
) {
7831 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with "
7832 "(ioc_status=0x%08x)\n", ioc
->name
, ioc
->start_scan_failed
);
7833 ioc
->is_driver_loading
= 0;
7834 ioc
->wait_for_discovery_to_complete
= 0;
7835 ioc
->remove_host
= 1;
7839 printk(MPT2SAS_INFO_FMT
"port enable: SUCCESS\n", ioc
->name
);
7840 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
7842 if (ioc
->wait_for_discovery_to_complete
) {
7843 ioc
->wait_for_discovery_to_complete
= 0;
7844 _scsih_probe_devices(ioc
);
7846 mpt2sas_base_start_watchdog(ioc
);
7847 ioc
->is_driver_loading
= 0;
7853 * _scsih_probe - attach and add scsi host
7854 * @pdev: PCI device struct
7855 * @id: pci device id
7857 * Returns 0 success, anything else error.
7860 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
7862 struct MPT2SAS_ADAPTER
*ioc
;
7863 struct Scsi_Host
*shost
;
7865 shost
= scsi_host_alloc(&scsih_driver_template
,
7866 sizeof(struct MPT2SAS_ADAPTER
));
7870 /* init local params */
7871 ioc
= shost_priv(shost
);
7872 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
7873 INIT_LIST_HEAD(&ioc
->list
);
7874 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
7876 ioc
->id
= mpt_ids
++;
7877 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
7879 if (id
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
7880 ioc
->is_warpdrive
= 1;
7881 ioc
->hide_ir_msg
= 1;
7883 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
7884 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
7885 ioc
->tm_cb_idx
= tm_cb_idx
;
7886 ioc
->ctl_cb_idx
= ctl_cb_idx
;
7887 ioc
->base_cb_idx
= base_cb_idx
;
7888 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
7889 ioc
->transport_cb_idx
= transport_cb_idx
;
7890 ioc
->scsih_cb_idx
= scsih_cb_idx
;
7891 ioc
->config_cb_idx
= config_cb_idx
;
7892 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
7893 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
7894 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
7895 ioc
->logging_level
= logging_level
;
7896 /* misc semaphores and spin locks */
7897 mutex_init(&ioc
->reset_in_progress_mutex
);
7898 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
7899 spin_lock_init(&ioc
->scsi_lookup_lock
);
7900 spin_lock_init(&ioc
->sas_device_lock
);
7901 spin_lock_init(&ioc
->sas_node_lock
);
7902 spin_lock_init(&ioc
->fw_event_lock
);
7903 spin_lock_init(&ioc
->raid_device_lock
);
7905 INIT_LIST_HEAD(&ioc
->sas_device_list
);
7906 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
7907 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
7908 INIT_LIST_HEAD(&ioc
->fw_event_list
);
7909 INIT_LIST_HEAD(&ioc
->raid_device_list
);
7910 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
7911 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
7912 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
7914 /* init shost parameters */
7915 shost
->max_cmd_len
= 32;
7916 shost
->max_lun
= max_lun
;
7917 shost
->transportt
= mpt2sas_transport_template
;
7918 shost
->unique_id
= ioc
->id
;
7920 if (max_sectors
!= 0xFFFF) {
7921 if (max_sectors
< 64) {
7922 shost
->max_sectors
= 64;
7923 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
7924 "for max_sectors, range is 64 to 8192. Assigning "
7925 "value of 64.\n", ioc
->name
, max_sectors
);
7926 } else if (max_sectors
> 8192) {
7927 shost
->max_sectors
= 8192;
7928 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
7929 "for max_sectors, range is 64 to 8192. Assigning "
7930 "default value of 8192.\n", ioc
->name
,
7933 shost
->max_sectors
= max_sectors
& 0xFFFE;
7934 printk(MPT2SAS_INFO_FMT
"The max_sectors value is "
7935 "set to %d\n", ioc
->name
, shost
->max_sectors
);
7939 if ((scsi_add_host(shost
, &pdev
->dev
))) {
7940 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7941 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7942 list_del(&ioc
->list
);
7943 goto out_add_shost_fail
;
7946 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
7947 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
7948 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
7951 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
7952 "fw_event%d", ioc
->id
);
7953 ioc
->firmware_event_thread
= create_singlethread_workqueue(
7954 ioc
->firmware_event_name
);
7955 if (!ioc
->firmware_event_thread
) {
7956 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7957 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7958 goto out_thread_fail
;
7961 ioc
->is_driver_loading
= 1;
7962 if ((mpt2sas_base_attach(ioc
))) {
7963 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7964 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7965 goto out_attach_fail
;
7968 scsi_scan_host(shost
);
7969 if (ioc
->is_warpdrive
) {
7970 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
7971 ioc
->hide_drives
= 0;
7972 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
7973 ioc
->hide_drives
= 1;
7975 if (_scsih_get_num_volumes(ioc
))
7976 ioc
->hide_drives
= 1;
7978 ioc
->hide_drives
= 0;
7981 ioc
->hide_drives
= 0;
7983 _scsih_probe_devices(ioc
);
7987 destroy_workqueue(ioc
->firmware_event_thread
);
7989 list_del(&ioc
->list
);
7990 scsi_remove_host(shost
);
7991 scsi_host_put(shost
);
7998 * _scsih_suspend - power management suspend main entry point
7999 * @pdev: PCI device struct
8000 * @state: PM state change to (usually PCI_D3)
8002 * Returns 0 success, anything else error.
8005 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8007 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8008 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8009 pci_power_t device_state
;
8011 mpt2sas_base_stop_watchdog(ioc
);
8012 scsi_block_requests(shost
);
8013 device_state
= pci_choose_state(pdev
, state
);
8014 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
8015 "operating state [D%d]\n", ioc
->name
, pdev
,
8016 pci_name(pdev
), device_state
);
8018 mpt2sas_base_free_resources(ioc
);
8019 pci_save_state(pdev
);
8020 pci_disable_device(pdev
);
8021 pci_set_power_state(pdev
, device_state
);
8026 * _scsih_resume - power management resume main entry point
8027 * @pdev: PCI device struct
8029 * Returns 0 success, anything else error.
8032 _scsih_resume(struct pci_dev
*pdev
)
8034 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8035 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8036 pci_power_t device_state
= pdev
->current_state
;
8039 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
8040 "operating state [D%d]\n", ioc
->name
, pdev
,
8041 pci_name(pdev
), device_state
);
8043 pci_set_power_state(pdev
, PCI_D0
);
8044 pci_enable_wake(pdev
, PCI_D0
, 0);
8045 pci_restore_state(pdev
);
8047 r
= mpt2sas_base_map_resources(ioc
);
8051 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8052 scsi_unblock_requests(shost
);
8053 mpt2sas_base_start_watchdog(ioc
);
8056 #endif /* CONFIG_PM */
8059 * _scsih_pci_error_detected - Called when a PCI error is detected.
8060 * @pdev: PCI device struct
8061 * @state: PCI channel state
8063 * Description: Called when a PCI error is detected.
8066 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8068 static pci_ers_result_t
8069 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8071 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8072 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8074 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
8078 case pci_channel_io_normal
:
8079 return PCI_ERS_RESULT_CAN_RECOVER
;
8080 case pci_channel_io_frozen
:
8081 /* Fatal error, prepare for slot reset */
8082 ioc
->pci_error_recovery
= 1;
8083 scsi_block_requests(ioc
->shost
);
8084 mpt2sas_base_stop_watchdog(ioc
);
8085 mpt2sas_base_free_resources(ioc
);
8086 return PCI_ERS_RESULT_NEED_RESET
;
8087 case pci_channel_io_perm_failure
:
8088 /* Permanent error, prepare for device removal */
8089 ioc
->pci_error_recovery
= 1;
8090 mpt2sas_base_stop_watchdog(ioc
);
8091 _scsih_flush_running_cmds(ioc
);
8092 return PCI_ERS_RESULT_DISCONNECT
;
8094 return PCI_ERS_RESULT_NEED_RESET
;
8098 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8099 * @pdev: PCI device struct
8101 * Description: This routine is called by the pci error recovery
8102 * code after the PCI slot has been reset, just before we
8103 * should resume normal operations.
8105 static pci_ers_result_t
8106 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
8108 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8109 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8112 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
8115 ioc
->pci_error_recovery
= 0;
8117 pci_restore_state(pdev
);
8118 rc
= mpt2sas_base_map_resources(ioc
);
8120 return PCI_ERS_RESULT_DISCONNECT
;
8123 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8126 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
8127 (rc
== 0) ? "success" : "failed");
8130 return PCI_ERS_RESULT_RECOVERED
;
8132 return PCI_ERS_RESULT_DISCONNECT
;
8136 * _scsih_pci_resume() - resume normal ops after PCI reset
8137 * @pdev: pointer to PCI device
8139 * Called when the error recovery driver tells us that its
8140 * OK to resume normal operation. Use completion to allow
8141 * halted scsi ops to resume.
8144 _scsih_pci_resume(struct pci_dev
*pdev
)
8146 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8147 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8149 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8151 pci_cleanup_aer_uncorrect_error_status(pdev
);
8152 mpt2sas_base_start_watchdog(ioc
);
8153 scsi_unblock_requests(ioc
->shost
);
8157 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8158 * @pdev: pointer to PCI device
8160 static pci_ers_result_t
8161 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8163 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8164 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8166 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
8169 /* TODO - dump whatever for debugging purposes */
8171 /* Request a slot reset. */
8172 return PCI_ERS_RESULT_NEED_RESET
;
8175 static struct pci_error_handlers _scsih_err_handler
= {
8176 .error_detected
= _scsih_pci_error_detected
,
8177 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8178 .slot_reset
= _scsih_pci_slot_reset
,
8179 .resume
= _scsih_pci_resume
,
8182 static struct pci_driver scsih_driver
= {
8183 .name
= MPT2SAS_DRIVER_NAME
,
8184 .id_table
= scsih_pci_table
,
8185 .probe
= _scsih_probe
,
8186 .remove
= __devexit_p(_scsih_remove
),
8187 .shutdown
= _scsih_shutdown
,
8188 .err_handler
= &_scsih_err_handler
,
8190 .suspend
= _scsih_suspend
,
8191 .resume
= _scsih_resume
,
8195 /* raid transport support */
8196 static struct raid_function_template mpt2sas_raid_functions
= {
8197 .cookie
= &scsih_driver_template
,
8198 .is_raid
= _scsih_is_raid
,
8199 .get_resync
= _scsih_get_resync
,
8200 .get_state
= _scsih_get_state
,
8204 * _scsih_init - main entry point for this driver.
8206 * Returns 0 success, anything else error.
8214 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
8215 MPT2SAS_DRIVER_VERSION
);
8217 mpt2sas_transport_template
=
8218 sas_attach_transport(&mpt2sas_transport_functions
);
8219 if (!mpt2sas_transport_template
)
8221 /* raid transport support */
8222 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
8223 if (!mpt2sas_raid_template
) {
8224 sas_release_transport(mpt2sas_transport_template
);
8228 mpt2sas_base_initialize_callback_handler();
8230 /* queuecommand callback hander */
8231 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
8233 /* task management callback handler */
8234 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
8236 /* base internal commands callback handler */
8237 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
8238 port_enable_cb_idx
= mpt2sas_base_register_callback_handler(
8239 mpt2sas_port_enable_done
);
8241 /* transport internal commands callback handler */
8242 transport_cb_idx
= mpt2sas_base_register_callback_handler(
8243 mpt2sas_transport_done
);
8245 /* scsih internal commands callback handler */
8246 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
8248 /* configuration page API internal commands callback handler */
8249 config_cb_idx
= mpt2sas_base_register_callback_handler(
8250 mpt2sas_config_done
);
8252 /* ctl module callback handler */
8253 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
8255 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
8256 _scsih_tm_tr_complete
);
8258 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
8259 _scsih_tm_volume_tr_complete
);
8261 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
8262 _scsih_sas_control_complete
);
8266 error
= pci_register_driver(&scsih_driver
);
8268 /* raid transport support */
8269 raid_class_release(mpt2sas_raid_template
);
8270 sas_release_transport(mpt2sas_transport_template
);
8277 * _scsih_exit - exit point for this driver (when it is a module).
8279 * Returns 0 success, anything else error.
8284 printk(KERN_INFO
"mpt2sas version %s unloading\n",
8285 MPT2SAS_DRIVER_VERSION
);
8287 pci_unregister_driver(&scsih_driver
);
8291 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
8292 mpt2sas_base_release_callback_handler(tm_cb_idx
);
8293 mpt2sas_base_release_callback_handler(base_cb_idx
);
8294 mpt2sas_base_release_callback_handler(port_enable_cb_idx
);
8295 mpt2sas_base_release_callback_handler(transport_cb_idx
);
8296 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
8297 mpt2sas_base_release_callback_handler(config_cb_idx
);
8298 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
8300 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
8301 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8302 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8304 /* raid transport support */
8305 raid_class_release(mpt2sas_raid_template
);
8306 sas_release_transport(mpt2sas_transport_template
);
8310 module_init(_scsih_init
);
8311 module_exit(_scsih_exit
);