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 32767 default=32767");
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
);
615 } else if (!sas_device
->starget
) {
616 /* When asyn scanning is enabled, its not possible to remove
617 * devices while scanning is turned on due to an oops in
618 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
620 if (!ioc
->is_driver_loading
)
621 mpt2sas_transport_port_remove(ioc
,
622 sas_device
->sas_address
,
623 sas_device
->sas_address_parent
);
624 _scsih_sas_device_remove(ioc
, sas_device
);
629 * _scsih_sas_device_init_add - insert sas_device to the list.
630 * @ioc: per adapter object
631 * @sas_device: the sas_device object
632 * Context: This function will acquire ioc->sas_device_lock.
634 * Adding new object at driver load time to the ioc->sas_device_init_list.
637 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER
*ioc
,
638 struct _sas_device
*sas_device
)
642 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
643 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
644 sas_device
->handle
, (unsigned long long)sas_device
->sas_address
));
646 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
647 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
648 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
649 _scsih_determine_boot_device(ioc
, sas_device
, 0);
653 * _scsih_raid_device_find_by_id - raid device search
654 * @ioc: per adapter object
655 * @id: sas device target id
656 * @channel: sas device channel
657 * Context: Calling function should acquire ioc->raid_device_lock
659 * This searches for raid_device based on target id, then return raid_device
662 static struct _raid_device
*
663 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER
*ioc
, int id
, int channel
)
665 struct _raid_device
*raid_device
, *r
;
668 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
669 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
680 * _scsih_raid_device_find_by_handle - raid device search
681 * @ioc: per adapter object
682 * @handle: sas device handle (assigned by firmware)
683 * Context: Calling function should acquire ioc->raid_device_lock
685 * This searches for raid_device based on handle, then return raid_device
688 static struct _raid_device
*
689 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
691 struct _raid_device
*raid_device
, *r
;
694 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
695 if (raid_device
->handle
!= handle
)
706 * _scsih_raid_device_find_by_wwid - raid device search
707 * @ioc: per adapter object
708 * @handle: sas device handle (assigned by firmware)
709 * Context: Calling function should acquire ioc->raid_device_lock
711 * This searches for raid_device based on wwid, then return raid_device
714 static struct _raid_device
*
715 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
)
717 struct _raid_device
*raid_device
, *r
;
720 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
721 if (raid_device
->wwid
!= wwid
)
732 * _scsih_raid_device_add - add raid_device object
733 * @ioc: per adapter object
734 * @raid_device: raid_device object
736 * This is added to the raid_device_list link list.
739 _scsih_raid_device_add(struct MPT2SAS_ADAPTER
*ioc
,
740 struct _raid_device
*raid_device
)
744 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle"
745 "(0x%04x), wwid(0x%016llx)\n", ioc
->name
, __func__
,
746 raid_device
->handle
, (unsigned long long)raid_device
->wwid
));
748 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
749 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
750 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
754 * _scsih_raid_device_remove - delete raid_device object
755 * @ioc: per adapter object
756 * @raid_device: raid_device object
758 * This is removed from the raid_device_list link list.
761 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER
*ioc
,
762 struct _raid_device
*raid_device
)
766 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
767 list_del(&raid_device
->list
);
768 memset(raid_device
, 0, sizeof(struct _raid_device
));
770 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
774 * mpt2sas_scsih_expander_find_by_handle - expander device search
775 * @ioc: per adapter object
776 * @handle: expander handle (assigned by firmware)
777 * Context: Calling function should acquire ioc->sas_device_lock
779 * This searches for expander device based on handle, then returns the
783 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
785 struct _sas_node
*sas_expander
, *r
;
788 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
789 if (sas_expander
->handle
!= handle
)
799 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
800 * @ioc: per adapter object
801 * @sas_address: sas address
802 * Context: Calling function should acquire ioc->sas_node_lock.
804 * This searches for expander device based on sas_address, then returns the
808 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER
*ioc
,
811 struct _sas_node
*sas_expander
, *r
;
814 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
815 if (sas_expander
->sas_address
!= sas_address
)
825 * _scsih_expander_node_add - insert expander device to the list.
826 * @ioc: per adapter object
827 * @sas_expander: the sas_device object
828 * Context: This function will acquire ioc->sas_node_lock.
830 * Adding new object to the ioc->sas_expander_list.
835 _scsih_expander_node_add(struct MPT2SAS_ADAPTER
*ioc
,
836 struct _sas_node
*sas_expander
)
840 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
841 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
842 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
846 * _scsih_is_end_device - determines if device is an end device
847 * @device_info: bitfield providing information about the device.
850 * Returns 1 if end device.
853 _scsih_is_end_device(u32 device_info
)
855 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
856 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
857 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
858 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
865 * _scsih_scsi_lookup_get - returns scmd entry
866 * @ioc: per adapter object
867 * @smid: system request message index
869 * Returns the smid stored scmd pointer.
871 static struct scsi_cmnd
*
872 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
874 return ioc
->scsi_lookup
[smid
- 1].scmd
;
878 * _scsih_scsi_lookup_get_clear - returns scmd entry
879 * @ioc: per adapter object
880 * @smid: system request message index
882 * Returns the smid stored scmd pointer.
883 * Then will derefrence the stored scmd pointer.
885 static inline struct scsi_cmnd
*
886 _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
889 struct scsi_cmnd
*scmd
;
891 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
892 scmd
= ioc
->scsi_lookup
[smid
- 1].scmd
;
893 ioc
->scsi_lookup
[smid
- 1].scmd
= NULL
;
894 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
900 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
901 * @ioc: per adapter object
902 * @smid: system request message index
903 * @scmd: pointer to scsi command object
904 * Context: This function will acquire ioc->scsi_lookup_lock.
906 * This will search for a scmd pointer in the scsi_lookup array,
907 * returning the revelent smid. A returned value of zero means invalid.
910 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
917 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
919 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
920 if (ioc
->scsi_lookup
[i
].scmd
== scmd
) {
921 smid
= ioc
->scsi_lookup
[i
].smid
;
926 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
931 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
932 * @ioc: per adapter object
935 * Context: This function will acquire ioc->scsi_lookup_lock.
937 * This will search for a matching channel:id in the scsi_lookup array,
938 * returning 1 if found.
941 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER
*ioc
, int id
,
948 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
950 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
951 if (ioc
->scsi_lookup
[i
].scmd
&&
952 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
953 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
)) {
959 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
964 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
965 * @ioc: per adapter object
969 * Context: This function will acquire ioc->scsi_lookup_lock.
971 * This will search for a matching channel:id:lun in the scsi_lookup array,
972 * returning 1 if found.
975 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER
*ioc
, int id
,
976 unsigned int lun
, int channel
)
982 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
984 for (i
= 0 ; i
< ioc
->scsiio_depth
; i
++) {
985 if (ioc
->scsi_lookup
[i
].scmd
&&
986 (ioc
->scsi_lookup
[i
].scmd
->device
->id
== id
&&
987 ioc
->scsi_lookup
[i
].scmd
->device
->channel
== channel
&&
988 ioc
->scsi_lookup
[i
].scmd
->device
->lun
== lun
)) {
994 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
999 * _scsih_get_chain_buffer_tracker - obtain chain tracker
1000 * @ioc: per adapter object
1001 * @smid: smid associated to an IO request
1003 * Returns chain tracker(from ioc->free_chain_list)
1005 static struct chain_tracker
*
1006 _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1008 struct chain_tracker
*chain_req
;
1009 unsigned long flags
;
1011 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1012 if (list_empty(&ioc
->free_chain_list
)) {
1013 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1014 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
"chain buffers not "
1015 "available\n", ioc
->name
));
1018 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1019 struct chain_tracker
, tracker_list
);
1020 list_del_init(&chain_req
->tracker_list
);
1021 list_add_tail(&chain_req
->tracker_list
,
1022 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1023 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1028 * _scsih_build_scatter_gather - main sg creation routine
1029 * @ioc: per adapter object
1030 * @scmd: scsi command
1031 * @smid: system request message index
1034 * The main routine that builds scatter gather table from a given
1035 * scsi request sent via the .queuecommand main handler.
1037 * Returns 0 success, anything else error
1040 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER
*ioc
,
1041 struct scsi_cmnd
*scmd
, u16 smid
)
1043 Mpi2SCSIIORequest_t
*mpi_request
;
1044 dma_addr_t chain_dma
;
1045 struct scatterlist
*sg_scmd
;
1046 void *sg_local
, *chain
;
1051 u32 sges_in_segment
;
1053 u32 sgl_flags_last_element
;
1054 u32 sgl_flags_end_buffer
;
1055 struct chain_tracker
*chain_req
;
1057 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1059 /* init scatter gather flags */
1060 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1061 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1062 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1063 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1064 << MPI2_SGE_FLAGS_SHIFT
;
1065 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1066 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1067 << MPI2_SGE_FLAGS_SHIFT
;
1068 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1070 sg_scmd
= scsi_sglist(scmd
);
1071 sges_left
= scsi_dma_map(scmd
);
1072 if (sges_left
< 0) {
1073 sdev_printk(KERN_ERR
, scmd
->device
, "pci_map_sg"
1074 " failed: request for %d bytes!\n", scsi_bufflen(scmd
));
1078 sg_local
= &mpi_request
->SGL
;
1079 sges_in_segment
= ioc
->max_sges_in_main_message
;
1080 if (sges_left
<= sges_in_segment
)
1081 goto fill_in_last_segment
;
1083 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1084 (sges_in_segment
* ioc
->sge_size
))/4;
1086 /* fill in main message segment when there is a chain following */
1087 while (sges_in_segment
) {
1088 if (sges_in_segment
== 1)
1089 ioc
->base_add_sg_single(sg_local
,
1090 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1091 sg_dma_address(sg_scmd
));
1093 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1094 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1095 sg_scmd
= sg_next(sg_scmd
);
1096 sg_local
+= ioc
->sge_size
;
1101 /* initializing the chain flags and pointers */
1102 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1103 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1106 chain
= chain_req
->chain_buffer
;
1107 chain_dma
= chain_req
->chain_buffer_dma
;
1109 sges_in_segment
= (sges_left
<=
1110 ioc
->max_sges_in_chain_message
) ? sges_left
:
1111 ioc
->max_sges_in_chain_message
;
1112 chain_offset
= (sges_left
== sges_in_segment
) ?
1113 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1114 chain_length
= sges_in_segment
* ioc
->sge_size
;
1116 chain_offset
= chain_offset
<<
1117 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1118 chain_length
+= ioc
->sge_size
;
1120 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1121 chain_length
, chain_dma
);
1124 goto fill_in_last_segment
;
1126 /* fill in chain segments */
1127 while (sges_in_segment
) {
1128 if (sges_in_segment
== 1)
1129 ioc
->base_add_sg_single(sg_local
,
1130 sgl_flags_last_element
|
1131 sg_dma_len(sg_scmd
),
1132 sg_dma_address(sg_scmd
));
1134 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1135 sg_dma_len(sg_scmd
),
1136 sg_dma_address(sg_scmd
));
1137 sg_scmd
= sg_next(sg_scmd
);
1138 sg_local
+= ioc
->sge_size
;
1143 chain_req
= _scsih_get_chain_buffer_tracker(ioc
, smid
);
1146 chain
= chain_req
->chain_buffer
;
1147 chain_dma
= chain_req
->chain_buffer_dma
;
1151 fill_in_last_segment
:
1153 /* fill the last segment */
1156 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1157 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1159 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1160 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1161 sg_scmd
= sg_next(sg_scmd
);
1162 sg_local
+= ioc
->sge_size
;
1170 * _scsih_adjust_queue_depth - setting device queue depth
1171 * @sdev: scsi device struct
1172 * @qdepth: requested queue depth
1178 _scsih_adjust_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1180 struct Scsi_Host
*shost
= sdev
->host
;
1182 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1183 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1184 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1185 struct _sas_device
*sas_device
;
1186 unsigned long flags
;
1188 max_depth
= shost
->can_queue
;
1190 /* limit max device queue for SATA to 32 */
1191 sas_device_priv_data
= sdev
->hostdata
;
1192 if (!sas_device_priv_data
)
1194 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1195 if (!sas_target_priv_data
)
1197 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1199 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1200 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1201 sas_device_priv_data
->sas_target
->sas_address
);
1202 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1203 if (sas_device
&& sas_device
->device_info
&
1204 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1205 max_depth
= MPT2SAS_SATA_QUEUE_DEPTH
;
1209 if (!sdev
->tagged_supported
)
1211 if (qdepth
> max_depth
)
1213 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
1217 * _scsih_change_queue_depth - setting device queue depth
1218 * @sdev: scsi device struct
1219 * @qdepth: requested queue depth
1220 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1221 * (see include/scsi/scsi_host.h for definition)
1223 * Returns queue depth.
1226 _scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
, int reason
)
1228 if (reason
== SCSI_QDEPTH_DEFAULT
|| reason
== SCSI_QDEPTH_RAMP_UP
)
1229 _scsih_adjust_queue_depth(sdev
, qdepth
);
1230 else if (reason
== SCSI_QDEPTH_QFULL
)
1231 scsi_track_queue_full(sdev
, qdepth
);
1235 if (sdev
->inquiry_len
> 7)
1236 sdev_printk(KERN_INFO
, sdev
, "qdepth(%d), tagged(%d), "
1237 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1238 sdev
->queue_depth
, sdev
->tagged_supported
, sdev
->simple_tags
,
1239 sdev
->ordered_tags
, sdev
->scsi_level
,
1240 (sdev
->inquiry
[7] & 2) >> 1);
1242 return sdev
->queue_depth
;
1246 * _scsih_change_queue_type - changing device queue tag type
1247 * @sdev: scsi device struct
1248 * @tag_type: requested tag type
1250 * Returns queue tag type.
1253 _scsih_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
1255 if (sdev
->tagged_supported
) {
1256 scsi_set_tag_type(sdev
, tag_type
);
1258 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
1260 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
1268 * _scsih_target_alloc - target add routine
1269 * @starget: scsi target struct
1271 * Returns 0 if ok. Any other return is assumed to be an error and
1272 * the device is ignored.
1275 _scsih_target_alloc(struct scsi_target
*starget
)
1277 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1278 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1279 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1280 struct _sas_device
*sas_device
;
1281 struct _raid_device
*raid_device
;
1282 unsigned long flags
;
1283 struct sas_rphy
*rphy
;
1285 sas_target_priv_data
= kzalloc(sizeof(struct scsi_target
), GFP_KERNEL
);
1286 if (!sas_target_priv_data
)
1289 starget
->hostdata
= sas_target_priv_data
;
1290 sas_target_priv_data
->starget
= starget
;
1291 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
1294 if (starget
->channel
== RAID_CHANNEL
) {
1295 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1296 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1299 sas_target_priv_data
->handle
= raid_device
->handle
;
1300 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1301 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1302 sas_target_priv_data
->raid_device
= raid_device
;
1303 raid_device
->starget
= starget
;
1305 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1309 /* sas/sata devices */
1310 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1311 rphy
= dev_to_rphy(starget
->dev
.parent
);
1312 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1313 rphy
->identify
.sas_address
);
1316 sas_target_priv_data
->handle
= sas_device
->handle
;
1317 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1318 sas_device
->starget
= starget
;
1319 sas_device
->id
= starget
->id
;
1320 sas_device
->channel
= starget
->channel
;
1321 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1322 sas_target_priv_data
->flags
|=
1323 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1325 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1331 * _scsih_target_destroy - target destroy routine
1332 * @starget: scsi target struct
1337 _scsih_target_destroy(struct scsi_target
*starget
)
1339 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1340 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1341 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1342 struct _sas_device
*sas_device
;
1343 struct _raid_device
*raid_device
;
1344 unsigned long flags
;
1345 struct sas_rphy
*rphy
;
1347 sas_target_priv_data
= starget
->hostdata
;
1348 if (!sas_target_priv_data
)
1351 if (starget
->channel
== RAID_CHANNEL
) {
1352 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1353 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1356 raid_device
->starget
= NULL
;
1357 raid_device
->sdev
= NULL
;
1359 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1363 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1364 rphy
= dev_to_rphy(starget
->dev
.parent
);
1365 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1366 rphy
->identify
.sas_address
);
1367 if (sas_device
&& (sas_device
->starget
== starget
) &&
1368 (sas_device
->id
== starget
->id
) &&
1369 (sas_device
->channel
== starget
->channel
))
1370 sas_device
->starget
= NULL
;
1372 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1375 kfree(sas_target_priv_data
);
1376 starget
->hostdata
= NULL
;
1380 * _scsih_slave_alloc - device add routine
1381 * @sdev: scsi device struct
1383 * Returns 0 if ok. Any other return is assumed to be an error and
1384 * the device is ignored.
1387 _scsih_slave_alloc(struct scsi_device
*sdev
)
1389 struct Scsi_Host
*shost
;
1390 struct MPT2SAS_ADAPTER
*ioc
;
1391 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1392 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1393 struct scsi_target
*starget
;
1394 struct _raid_device
*raid_device
;
1395 unsigned long flags
;
1397 sas_device_priv_data
= kzalloc(sizeof(struct scsi_device
), GFP_KERNEL
);
1398 if (!sas_device_priv_data
)
1401 sas_device_priv_data
->lun
= sdev
->lun
;
1402 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1404 starget
= scsi_target(sdev
);
1405 sas_target_priv_data
= starget
->hostdata
;
1406 sas_target_priv_data
->num_luns
++;
1407 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1408 sdev
->hostdata
= sas_device_priv_data
;
1409 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1410 sdev
->no_uld_attach
= 1;
1412 shost
= dev_to_shost(&starget
->dev
);
1413 ioc
= shost_priv(shost
);
1414 if (starget
->channel
== RAID_CHANNEL
) {
1415 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1416 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1417 starget
->id
, starget
->channel
);
1419 raid_device
->sdev
= sdev
; /* raid is single lun */
1420 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1427 * _scsih_slave_destroy - device destroy routine
1428 * @sdev: scsi device struct
1433 _scsih_slave_destroy(struct scsi_device
*sdev
)
1435 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1436 struct scsi_target
*starget
;
1437 struct Scsi_Host
*shost
;
1438 struct MPT2SAS_ADAPTER
*ioc
;
1439 struct _sas_device
*sas_device
;
1440 unsigned long flags
;
1442 if (!sdev
->hostdata
)
1445 starget
= scsi_target(sdev
);
1446 sas_target_priv_data
= starget
->hostdata
;
1447 sas_target_priv_data
->num_luns
--;
1449 shost
= dev_to_shost(&starget
->dev
);
1450 ioc
= shost_priv(shost
);
1452 if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1453 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1454 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
1455 sas_target_priv_data
->sas_address
);
1456 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1457 sas_device
->starget
= NULL
;
1458 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1461 kfree(sdev
->hostdata
);
1462 sdev
->hostdata
= NULL
;
1466 * _scsih_display_sata_capabilities - sata capabilities
1467 * @ioc: per adapter object
1468 * @sas_device: the sas_device object
1469 * @sdev: scsi device struct
1472 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1473 struct _sas_device
*sas_device
, struct scsi_device
*sdev
)
1475 Mpi2ConfigReply_t mpi_reply
;
1476 Mpi2SasDevicePage0_t sas_device_pg0
;
1481 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1482 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, sas_device
->handle
))) {
1483 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1484 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1488 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1489 MPI2_IOCSTATUS_MASK
;
1490 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1491 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1492 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1496 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1497 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1499 sdev_printk(KERN_INFO
, sdev
,
1500 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1501 "sw_preserve(%s)\n",
1502 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1503 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1504 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1506 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1507 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1508 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1512 * _scsih_is_raid - return boolean indicating device is raid volume
1513 * @dev the device struct object
1516 _scsih_is_raid(struct device
*dev
)
1518 struct scsi_device
*sdev
= to_scsi_device(dev
);
1519 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1521 if (ioc
->is_warpdrive
)
1523 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1527 * _scsih_get_resync - get raid volume resync percent complete
1528 * @dev the device struct object
1531 _scsih_get_resync(struct device
*dev
)
1533 struct scsi_device
*sdev
= to_scsi_device(dev
);
1534 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1535 static struct _raid_device
*raid_device
;
1536 unsigned long flags
;
1537 Mpi2RaidVolPage0_t vol_pg0
;
1538 Mpi2ConfigReply_t mpi_reply
;
1539 u32 volume_status_flags
;
1540 u8 percent_complete
= 0;
1542 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1543 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1545 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1547 if (!raid_device
|| ioc
->is_warpdrive
)
1550 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1551 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1552 sizeof(Mpi2RaidVolPage0_t
))) {
1553 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1554 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1558 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1559 if (volume_status_flags
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
1560 percent_complete
= raid_device
->percent_complete
;
1562 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
1566 * _scsih_get_state - get raid volume level
1567 * @dev the device struct object
1570 _scsih_get_state(struct device
*dev
)
1572 struct scsi_device
*sdev
= to_scsi_device(dev
);
1573 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1574 static struct _raid_device
*raid_device
;
1575 unsigned long flags
;
1576 Mpi2RaidVolPage0_t vol_pg0
;
1577 Mpi2ConfigReply_t mpi_reply
;
1579 enum raid_state state
= RAID_STATE_UNKNOWN
;
1581 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1582 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1584 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1589 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1590 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
,
1591 sizeof(Mpi2RaidVolPage0_t
))) {
1592 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
1593 ioc
->name
, __FILE__
, __LINE__
, __func__
);
1597 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
1598 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
1599 state
= RAID_STATE_RESYNCING
;
1603 switch (vol_pg0
.VolumeState
) {
1604 case MPI2_RAID_VOL_STATE_OPTIMAL
:
1605 case MPI2_RAID_VOL_STATE_ONLINE
:
1606 state
= RAID_STATE_ACTIVE
;
1608 case MPI2_RAID_VOL_STATE_DEGRADED
:
1609 state
= RAID_STATE_DEGRADED
;
1611 case MPI2_RAID_VOL_STATE_FAILED
:
1612 case MPI2_RAID_VOL_STATE_MISSING
:
1613 state
= RAID_STATE_OFFLINE
;
1617 raid_set_state(mpt2sas_raid_template
, dev
, state
);
1621 * _scsih_set_level - set raid level
1622 * @sdev: scsi device struct
1623 * @raid_device: raid_device object
1626 _scsih_set_level(struct scsi_device
*sdev
, struct _raid_device
*raid_device
)
1628 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
1630 switch (raid_device
->volume_type
) {
1631 case MPI2_RAID_VOL_TYPE_RAID0
:
1632 level
= RAID_LEVEL_0
;
1634 case MPI2_RAID_VOL_TYPE_RAID10
:
1635 level
= RAID_LEVEL_10
;
1637 case MPI2_RAID_VOL_TYPE_RAID1E
:
1638 level
= RAID_LEVEL_1E
;
1640 case MPI2_RAID_VOL_TYPE_RAID1
:
1641 level
= RAID_LEVEL_1
;
1645 raid_set_level(mpt2sas_raid_template
, &sdev
->sdev_gendev
, level
);
1649 * _scsih_get_volume_capabilities - volume capabilities
1650 * @ioc: per adapter object
1651 * @sas_device: the raid_device object
1653 * Returns 0 for success, else 1
1656 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER
*ioc
,
1657 struct _raid_device
*raid_device
)
1659 Mpi2RaidVolPage0_t
*vol_pg0
;
1660 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1661 Mpi2SasDevicePage0_t sas_device_pg0
;
1662 Mpi2ConfigReply_t mpi_reply
;
1666 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1667 &num_pds
)) || !num_pds
) {
1668 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1669 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1674 raid_device
->num_pds
= num_pds
;
1675 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1676 sizeof(Mpi2RaidVol0PhysDisk_t
));
1677 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1679 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1680 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1685 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1686 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1687 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1688 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
1694 raid_device
->volume_type
= vol_pg0
->VolumeType
;
1696 /* figure out what the underlying devices are by
1697 * obtaining the device_info bits for the 1st device
1699 if (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1700 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1701 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
1702 if (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
1703 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
1704 le16_to_cpu(pd_pg0
.DevHandle
)))) {
1705 raid_device
->device_info
=
1706 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1714 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1715 * @ioc: per adapter object
1718 _scsih_disable_ddio(struct MPT2SAS_ADAPTER
*ioc
)
1720 Mpi2RaidVolPage1_t vol_pg1
;
1721 Mpi2ConfigReply_t mpi_reply
;
1722 struct _raid_device
*raid_device
;
1727 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1728 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1729 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1730 MPI2_IOCSTATUS_MASK
;
1731 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1733 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1734 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
1736 raid_device
->direct_io_enabled
= 0;
1743 * _scsih_get_num_volumes - Get number of volumes in the ioc
1744 * @ioc: per adapter object
1747 _scsih_get_num_volumes(struct MPT2SAS_ADAPTER
*ioc
)
1749 Mpi2RaidVolPage1_t vol_pg1
;
1750 Mpi2ConfigReply_t mpi_reply
;
1756 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
1757 &vol_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
1758 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1759 MPI2_IOCSTATUS_MASK
;
1760 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
1763 handle
= le16_to_cpu(vol_pg1
.DevHandle
);
1770 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1771 * @ioc: per adapter object
1772 * @raid_device: the raid_device object
1775 _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER
*ioc
,
1776 struct _raid_device
*raid_device
)
1778 Mpi2RaidVolPage0_t
*vol_pg0
;
1779 Mpi2RaidPhysDiskPage0_t pd_pg0
;
1780 Mpi2ConfigReply_t mpi_reply
;
1783 unsigned long stripe_sz
, block_sz
;
1784 u8 stripe_exp
, block_exp
;
1787 if (!ioc
->is_warpdrive
)
1790 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
) {
1791 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1792 "globally as drives are exposed\n", ioc
->name
);
1795 if (_scsih_get_num_volumes(ioc
) > 1) {
1796 _scsih_disable_ddio(ioc
);
1797 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1798 "globally as number of drives > 1\n", ioc
->name
);
1801 if ((mpt2sas_config_get_number_pds(ioc
, raid_device
->handle
,
1802 &num_pds
)) || !num_pds
) {
1803 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1804 "Failure in computing number of drives\n", ioc
->name
);
1808 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
1809 sizeof(Mpi2RaidVol0PhysDisk_t
));
1810 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
1812 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1813 "Memory allocation failure for RVPG0\n", ioc
->name
);
1817 if ((mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
1818 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
1819 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1820 "Failure in retrieving RVPG0\n", ioc
->name
);
1826 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1827 * assumed for WARPDRIVE, disable direct I/O
1829 if (num_pds
> MPT_MAX_WARPDRIVE_PDS
) {
1830 printk(MPT2SAS_WARN_FMT
"WarpDrive : Direct IO is disabled "
1831 "for the drive with handle(0x%04x): num_mem=%d, "
1832 "max_mem_allowed=%d\n", ioc
->name
, raid_device
->handle
,
1833 num_pds
, MPT_MAX_WARPDRIVE_PDS
);
1837 for (count
= 0; count
< num_pds
; count
++) {
1838 if (mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
1839 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
1840 vol_pg0
->PhysDisk
[count
].PhysDiskNum
) ||
1841 pd_pg0
.DevHandle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
1842 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1843 "disabled for the drive with handle(0x%04x) member"
1844 "handle retrieval failed for member number=%d\n",
1845 ioc
->name
, raid_device
->handle
,
1846 vol_pg0
->PhysDisk
[count
].PhysDiskNum
);
1849 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1850 dev_max_lba
= le64_to_cpu(pd_pg0
.DeviceMaxLBA
);
1851 if (dev_max_lba
>> 32) {
1852 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is "
1853 "disabled for the drive with handle(0x%04x) member"
1854 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1855 ioc
->name
, raid_device
->handle
,
1856 le16_to_cpu(pd_pg0
.DevHandle
),
1857 (unsigned long long)dev_max_lba
);
1861 raid_device
->pd_handle
[count
] = le16_to_cpu(pd_pg0
.DevHandle
);
1865 * Assumption for WD: Direct I/O is not supported if the volume is
1868 if (raid_device
->volume_type
!= MPI2_RAID_VOL_TYPE_RAID0
) {
1869 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1870 "for the drive with handle(0x%04x): type=%d, "
1871 "s_sz=%uK, blk_size=%u\n", ioc
->name
,
1872 raid_device
->handle
, raid_device
->volume_type
,
1873 (le32_to_cpu(vol_pg0
->StripeSize
) *
1874 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024,
1875 le16_to_cpu(vol_pg0
->BlockSize
));
1879 stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1880 stripe_exp
= find_first_bit(&stripe_sz
, 32);
1881 if (stripe_exp
== 32) {
1882 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1883 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1884 ioc
->name
, raid_device
->handle
,
1885 (le32_to_cpu(vol_pg0
->StripeSize
) *
1886 le16_to_cpu(vol_pg0
->BlockSize
)) / 1024);
1889 raid_device
->stripe_exponent
= stripe_exp
;
1890 block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1891 block_exp
= find_first_bit(&block_sz
, 16);
1892 if (block_exp
== 16) {
1893 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is disabled "
1894 "for the drive with handle(0x%04x) invalid block sz %u\n",
1895 ioc
->name
, raid_device
->handle
,
1896 le16_to_cpu(vol_pg0
->BlockSize
));
1899 raid_device
->block_exponent
= block_exp
;
1900 raid_device
->direct_io_enabled
= 1;
1902 printk(MPT2SAS_INFO_FMT
"WarpDrive : Direct IO is Enabled for the drive"
1903 " with handle(0x%04x)\n", ioc
->name
, raid_device
->handle
);
1905 * WARPDRIVE: Though the following fields are not used for direct IO,
1906 * stored for future purpose:
1908 raid_device
->max_lba
= le64_to_cpu(vol_pg0
->MaxLBA
);
1909 raid_device
->stripe_sz
= le32_to_cpu(vol_pg0
->StripeSize
);
1910 raid_device
->block_sz
= le16_to_cpu(vol_pg0
->BlockSize
);
1917 raid_device
->direct_io_enabled
= 0;
1918 for (count
= 0; count
< num_pds
; count
++)
1919 raid_device
->pd_handle
[count
] = 0;
1925 * _scsih_enable_tlr - setting TLR flags
1926 * @ioc: per adapter object
1927 * @sdev: scsi device struct
1929 * Enabling Transaction Layer Retries for tape devices when
1930 * vpd page 0x90 is present
1934 _scsih_enable_tlr(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
1937 if (sdev
->type
!= TYPE_TAPE
)
1940 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
1943 sas_enable_tlr(sdev
);
1944 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
1945 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
1951 * _scsih_slave_configure - device configure routine.
1952 * @sdev: scsi device struct
1954 * Returns 0 if ok. Any other return is assumed to be an error and
1955 * the device is ignored.
1958 _scsih_slave_configure(struct scsi_device
*sdev
)
1960 struct Scsi_Host
*shost
= sdev
->host
;
1961 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
1962 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
1963 struct MPT2SAS_TARGET
*sas_target_priv_data
;
1964 struct _sas_device
*sas_device
;
1965 struct _raid_device
*raid_device
;
1966 unsigned long flags
;
1973 sas_device_priv_data
= sdev
->hostdata
;
1974 sas_device_priv_data
->configured_lun
= 1;
1975 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
1976 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1978 /* raid volume handling */
1979 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
1981 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1982 raid_device
= _scsih_raid_device_find_by_handle(ioc
,
1983 sas_target_priv_data
->handle
);
1984 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1986 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1987 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1988 __LINE__
, __func__
));
1992 _scsih_get_volume_capabilities(ioc
, raid_device
);
1994 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
1995 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
1996 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
,
1997 __LINE__
, __func__
));
2001 * WARPDRIVE: Initialize the required data for Direct IO
2003 _scsih_init_warpdrive_properties(ioc
, raid_device
);
2005 /* RAID Queue Depth Support
2006 * IS volume = underlying qdepth of drive type, either
2007 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2008 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2010 if (raid_device
->device_info
&
2011 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2012 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2015 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2016 if (raid_device
->device_info
&
2017 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2023 switch (raid_device
->volume_type
) {
2024 case MPI2_RAID_VOL_TYPE_RAID0
:
2027 case MPI2_RAID_VOL_TYPE_RAID1E
:
2028 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2029 if (ioc
->manu_pg10
.OEMIdentifier
&&
2030 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2031 MFG10_GF0_R10_DISPLAY
) &&
2032 !(raid_device
->num_pds
% 2))
2037 case MPI2_RAID_VOL_TYPE_RAID1
:
2038 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2041 case MPI2_RAID_VOL_TYPE_RAID10
:
2042 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2045 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2047 qdepth
= MPT2SAS_RAID_QUEUE_DEPTH
;
2052 if (!ioc
->hide_ir_msg
)
2053 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2054 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2055 r_level
, raid_device
->handle
,
2056 (unsigned long long)raid_device
->wwid
,
2057 raid_device
->num_pds
, ds
);
2058 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2059 /* raid transport support */
2060 if (!ioc
->is_warpdrive
)
2061 _scsih_set_level(sdev
, raid_device
);
2065 /* non-raid handling */
2066 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2067 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2068 sas_device_priv_data
->sas_target
->sas_address
);
2069 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2071 if (sas_target_priv_data
->flags
&
2072 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2073 if (mpt2sas_config_get_volume_handle(ioc
,
2074 sas_device
->handle
, &sas_device
->volume_handle
)) {
2075 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2076 "failure at %s:%d/%s()!\n", ioc
->name
,
2077 __FILE__
, __LINE__
, __func__
));
2080 if (sas_device
->volume_handle
&&
2081 mpt2sas_config_get_volume_wwid(ioc
,
2082 sas_device
->volume_handle
,
2083 &sas_device
->volume_wwid
)) {
2084 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2085 "failure at %s:%d/%s()!\n", ioc
->name
,
2086 __FILE__
, __LINE__
, __func__
));
2090 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2091 qdepth
= MPT2SAS_SAS_QUEUE_DEPTH
;
2095 qdepth
= MPT2SAS_SATA_QUEUE_DEPTH
;
2096 if (sas_device
->device_info
&
2097 MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2099 else if (sas_device
->device_info
&
2100 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2104 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), "
2105 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2106 ds
, sas_device
->handle
,
2107 (unsigned long long)sas_device
->sas_address
,
2109 (unsigned long long)sas_device
->device_name
);
2110 sdev_printk(KERN_INFO
, sdev
, "%s: "
2111 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds
,
2112 (unsigned long long) sas_device
->enclosure_logical_id
,
2116 _scsih_display_sata_capabilities(ioc
, sas_device
, sdev
);
2118 dfailprintk(ioc
, printk(MPT2SAS_WARN_FMT
2119 "failure at %s:%d/%s()!\n", ioc
->name
, __FILE__
, __LINE__
,
2124 _scsih_change_queue_depth(sdev
, qdepth
, SCSI_QDEPTH_DEFAULT
);
2127 sas_read_port_mode_page(sdev
);
2128 _scsih_enable_tlr(ioc
, sdev
);
2134 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
2135 * @sdev: scsi device struct
2136 * @bdev: pointer to block device context
2137 * @capacity: device size (in 512 byte sectors)
2138 * @params: three element array to place output:
2139 * params[0] number of heads (max 255)
2140 * params[1] number of sectors (max 63)
2141 * params[2] number of cylinders
2146 _scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2147 sector_t capacity
, int params
[])
2157 dummy
= heads
* sectors
;
2158 cylinders
= capacity
;
2159 sector_div(cylinders
, dummy
);
2162 * Handle extended translation size for logical drives
2165 if ((ulong
)capacity
>= 0x200000) {
2168 dummy
= heads
* sectors
;
2169 cylinders
= capacity
;
2170 sector_div(cylinders
, dummy
);
2175 params
[1] = sectors
;
2176 params
[2] = cylinders
;
2182 * _scsih_response_code - translation of device response code
2183 * @ioc: per adapter object
2184 * @response_code: response code returned by the device
2189 _scsih_response_code(struct MPT2SAS_ADAPTER
*ioc
, u8 response_code
)
2193 switch (response_code
) {
2194 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2195 desc
= "task management request completed";
2197 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2198 desc
= "invalid frame";
2200 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2201 desc
= "task management request not supported";
2203 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2204 desc
= "task management request failed";
2206 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2207 desc
= "task management request succeeded";
2209 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2210 desc
= "invalid lun";
2213 desc
= "overlapped tag attempted";
2215 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2216 desc
= "task queued, however not sent to target";
2222 printk(MPT2SAS_WARN_FMT
"response_code(0x%01x): %s\n",
2223 ioc
->name
, response_code
, desc
);
2227 * _scsih_tm_done - tm completion routine
2228 * @ioc: per adapter object
2229 * @smid: system request message index
2230 * @msix_index: MSIX table index supplied by the OS
2231 * @reply: reply message frame(lower 32bit addr)
2234 * The callback handler when using scsih_issue_tm.
2236 * Return 1 meaning mf should be freed from _base_interrupt
2237 * 0 means the mf is freed from this function.
2240 _scsih_tm_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2242 MPI2DefaultReply_t
*mpi_reply
;
2244 if (ioc
->tm_cmds
.status
== MPT2_CMD_NOT_USED
)
2246 if (ioc
->tm_cmds
.smid
!= smid
)
2248 mpt2sas_base_flush_reply_queues(ioc
);
2249 ioc
->tm_cmds
.status
|= MPT2_CMD_COMPLETE
;
2250 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
2252 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2253 ioc
->tm_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
2255 ioc
->tm_cmds
.status
&= ~MPT2_CMD_PENDING
;
2256 complete(&ioc
->tm_cmds
.done
);
2261 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2262 * @ioc: per adapter object
2263 * @handle: device handle
2265 * During taskmangement request, we need to freeze the device queue.
2268 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2270 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2271 struct scsi_device
*sdev
;
2274 shost_for_each_device(sdev
, ioc
->shost
) {
2277 sas_device_priv_data
= sdev
->hostdata
;
2278 if (!sas_device_priv_data
)
2280 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2281 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2283 ioc
->ignore_loginfos
= 1;
2289 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2290 * @ioc: per adapter object
2291 * @handle: device handle
2293 * During taskmangement request, we need to freeze the device queue.
2296 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2298 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2299 struct scsi_device
*sdev
;
2302 shost_for_each_device(sdev
, ioc
->shost
) {
2305 sas_device_priv_data
= sdev
->hostdata
;
2306 if (!sas_device_priv_data
)
2308 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2309 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2311 ioc
->ignore_loginfos
= 0;
2318 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2319 * @ioc: per adapter struct
2320 * @device_handle: device handle
2321 * @channel: the channel assigned by the OS
2322 * @id: the id assigned by the OS
2324 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2325 * @smid_task: smid assigned to the task
2326 * @timeout: timeout in seconds
2327 * @serial_number: the serial_number from scmd
2328 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2331 * A generic API for sending task management requests to firmware.
2333 * The callback index is set inside `ioc->tm_cb_idx`.
2335 * Return SUCCESS or FAILED.
2338 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, uint channel
,
2339 uint id
, uint lun
, u8 type
, u16 smid_task
, ulong timeout
,
2340 unsigned long serial_number
, enum mutex_type m_type
)
2342 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2343 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2346 unsigned long timeleft
;
2347 struct scsiio_tracker
*scsi_lookup
= NULL
;
2350 if (m_type
== TM_MUTEX_ON
)
2351 mutex_lock(&ioc
->tm_cmds
.mutex
);
2352 if (ioc
->tm_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2353 printk(MPT2SAS_INFO_FMT
"%s: tm_cmd busy!!!\n",
2354 __func__
, ioc
->name
);
2359 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2360 ioc
->pci_error_recovery
) {
2361 printk(MPT2SAS_INFO_FMT
"%s: host reset in progress!\n",
2362 __func__
, ioc
->name
);
2367 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
2368 if (ioc_state
& MPI2_DOORBELL_USED
) {
2369 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
2370 "active!\n", ioc
->name
));
2371 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2373 rc
= (!rc
) ? SUCCESS
: FAILED
;
2377 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2378 mpt2sas_base_fault_info(ioc
, ioc_state
&
2379 MPI2_DOORBELL_DATA_MASK
);
2380 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2382 rc
= (!rc
) ? SUCCESS
: FAILED
;
2386 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2388 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2389 ioc
->name
, __func__
);
2394 if (type
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
2395 scsi_lookup
= &ioc
->scsi_lookup
[smid_task
- 1];
2397 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sending tm: handle(0x%04x),"
2398 " task_type(0x%02x), smid(%d)\n", ioc
->name
, handle
, type
,
2400 ioc
->tm_cmds
.status
= MPT2_CMD_PENDING
;
2401 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2402 ioc
->tm_cmds
.smid
= smid
;
2403 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2404 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2405 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2406 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2407 mpi_request
->TaskType
= type
;
2408 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2409 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2410 mpt2sas_scsih_set_tm_flag(ioc
, handle
);
2411 init_completion(&ioc
->tm_cmds
.done
);
2412 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
2413 timeleft
= wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2414 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2415 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
2416 ioc
->name
, __func__
);
2417 _debug_dump_mf(mpi_request
,
2418 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2419 if (!(ioc
->tm_cmds
.status
& MPT2_CMD_RESET
)) {
2420 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2422 rc
= (!rc
) ? SUCCESS
: FAILED
;
2423 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2424 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2429 if (ioc
->tm_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
2430 mpi_reply
= ioc
->tm_cmds
.reply
;
2431 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"complete tm: "
2432 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2433 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
2434 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2435 le32_to_cpu(mpi_reply
->TerminationCount
)));
2436 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2437 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2438 if (mpi_reply
->IOCStatus
)
2439 _debug_dump_mf(mpi_request
,
2440 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2445 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
2447 if (scsi_lookup
->scmd
== NULL
)
2452 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
2453 if (_scsih_scsi_lookup_find_by_target(ioc
, id
, channel
))
2459 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
2460 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
:
2461 if (_scsih_scsi_lookup_find_by_lun(ioc
, id
, lun
, channel
))
2466 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
2474 mpt2sas_scsih_clear_tm_flag(ioc
, handle
);
2475 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
2476 if (m_type
== TM_MUTEX_ON
)
2477 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2482 if (m_type
== TM_MUTEX_ON
)
2483 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2488 * _scsih_tm_display_info - displays info about the device
2489 * @ioc: per adapter struct
2490 * @scmd: pointer to scsi command object
2492 * Called by task management callback handlers.
2495 _scsih_tm_display_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2497 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2498 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
2499 struct _sas_device
*sas_device
= NULL
;
2500 unsigned long flags
;
2501 char *device_str
= NULL
;
2505 if (ioc
->hide_ir_msg
)
2506 device_str
= "WarpDrive";
2508 device_str
= "volume";
2510 scsi_print_command(scmd
);
2511 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2512 starget_printk(KERN_INFO
, starget
, "%s handle(0x%04x), "
2513 "%s wwid(0x%016llx)\n", device_str
, priv_target
->handle
,
2514 device_str
, (unsigned long long)priv_target
->sas_address
);
2516 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2517 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
2518 priv_target
->sas_address
);
2520 if (priv_target
->flags
&
2521 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2522 starget_printk(KERN_INFO
, starget
,
2523 "volume handle(0x%04x), "
2524 "volume wwid(0x%016llx)\n",
2525 sas_device
->volume_handle
,
2526 (unsigned long long)sas_device
->volume_wwid
);
2528 starget_printk(KERN_INFO
, starget
,
2529 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2531 (unsigned long long)sas_device
->sas_address
,
2533 starget_printk(KERN_INFO
, starget
,
2534 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2535 (unsigned long long)sas_device
->enclosure_logical_id
,
2538 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2543 * _scsih_abort - eh threads main abort routine
2544 * @scmd: pointer to scsi command object
2546 * Returns SUCCESS if command aborted else FAILED
2549 _scsih_abort(struct scsi_cmnd
*scmd
)
2551 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2552 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2557 sdev_printk(KERN_INFO
, scmd
->device
, "attempting task abort! "
2558 "scmd(%p)\n", scmd
);
2559 _scsih_tm_display_info(ioc
, scmd
);
2561 sas_device_priv_data
= scmd
->device
->hostdata
;
2562 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2563 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
2564 "scmd(%p)\n", scmd
);
2565 scmd
->result
= DID_NO_CONNECT
<< 16;
2566 scmd
->scsi_done(scmd
);
2571 /* search for the command */
2572 smid
= _scsih_scsi_lookup_find_by_scmd(ioc
, scmd
);
2574 scmd
->result
= DID_RESET
<< 16;
2579 /* for hidden raid components and volumes this is not supported */
2580 if (sas_device_priv_data
->sas_target
->flags
&
2581 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2582 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2583 scmd
->result
= DID_RESET
<< 16;
2588 mpt2sas_halt_firmware(ioc
);
2590 handle
= sas_device_priv_data
->sas_target
->handle
;
2591 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2592 scmd
->device
->id
, scmd
->device
->lun
,
2593 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
2594 scmd
->serial_number
, TM_MUTEX_ON
);
2597 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2598 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2603 * _scsih_dev_reset - eh threads main device reset routine
2604 * @scmd: pointer to scsi command object
2606 * Returns SUCCESS if command aborted else FAILED
2609 _scsih_dev_reset(struct scsi_cmnd
*scmd
)
2611 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2612 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2613 struct _sas_device
*sas_device
;
2614 unsigned long flags
;
2618 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2620 starget_printk(KERN_INFO
, starget
, "attempting device reset! "
2621 "scmd(%p)\n", scmd
);
2622 _scsih_tm_display_info(ioc
, scmd
);
2624 sas_device_priv_data
= scmd
->device
->hostdata
;
2625 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2626 starget_printk(KERN_INFO
, starget
, "device been deleted! "
2627 "scmd(%p)\n", scmd
);
2628 scmd
->result
= DID_NO_CONNECT
<< 16;
2629 scmd
->scsi_done(scmd
);
2634 /* for hidden raid components obtain the volume_handle */
2636 if (sas_device_priv_data
->sas_target
->flags
&
2637 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2638 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2639 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2640 sas_device_priv_data
->sas_target
->handle
);
2642 handle
= sas_device
->volume_handle
;
2643 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2645 handle
= sas_device_priv_data
->sas_target
->handle
;
2648 scmd
->result
= DID_RESET
<< 16;
2653 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2654 scmd
->device
->id
, scmd
->device
->lun
,
2655 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 30, 0,
2659 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
2660 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2665 * _scsih_target_reset - eh threads main target reset routine
2666 * @scmd: pointer to scsi command object
2668 * Returns SUCCESS if command aborted else FAILED
2671 _scsih_target_reset(struct scsi_cmnd
*scmd
)
2673 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2674 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2675 struct _sas_device
*sas_device
;
2676 unsigned long flags
;
2679 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2681 starget_printk(KERN_INFO
, starget
, "attempting target reset! "
2682 "scmd(%p)\n", scmd
);
2683 _scsih_tm_display_info(ioc
, scmd
);
2685 sas_device_priv_data
= scmd
->device
->hostdata
;
2686 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
2687 starget_printk(KERN_INFO
, starget
, "target been deleted! "
2688 "scmd(%p)\n", scmd
);
2689 scmd
->result
= DID_NO_CONNECT
<< 16;
2690 scmd
->scsi_done(scmd
);
2695 /* for hidden raid components obtain the volume_handle */
2697 if (sas_device_priv_data
->sas_target
->flags
&
2698 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2699 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2700 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
2701 sas_device_priv_data
->sas_target
->handle
);
2703 handle
= sas_device
->volume_handle
;
2704 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2706 handle
= sas_device_priv_data
->sas_target
->handle
;
2709 scmd
->result
= DID_RESET
<< 16;
2714 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, scmd
->device
->channel
,
2715 scmd
->device
->id
, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
2716 30, 0, TM_MUTEX_ON
);
2719 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
2720 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2725 * _scsih_host_reset - eh threads main host reset routine
2726 * @scmd: pointer to scsi command object
2728 * Returns SUCCESS if command aborted else FAILED
2731 _scsih_host_reset(struct scsi_cmnd
*scmd
)
2733 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2736 printk(MPT2SAS_INFO_FMT
"attempting host reset! scmd(%p)\n",
2738 scsi_print_command(scmd
);
2740 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2742 r
= (retval
< 0) ? FAILED
: SUCCESS
;
2743 printk(MPT2SAS_INFO_FMT
"host reset: %s scmd(%p)\n",
2744 ioc
->name
, ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2750 * _scsih_fw_event_add - insert and queue up fw_event
2751 * @ioc: per adapter object
2752 * @fw_event: object describing the event
2753 * Context: This function will acquire ioc->fw_event_lock.
2755 * This adds the firmware event object into link list, then queues it up to
2756 * be processed from user context.
2761 _scsih_fw_event_add(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
2763 unsigned long flags
;
2765 if (ioc
->firmware_event_thread
== NULL
)
2768 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2769 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
2770 INIT_DELAYED_WORK(&fw_event
->delayed_work
, _firmware_event_work
);
2771 queue_delayed_work(ioc
->firmware_event_thread
,
2772 &fw_event
->delayed_work
, 0);
2773 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2777 * _scsih_fw_event_free - delete fw_event
2778 * @ioc: per adapter object
2779 * @fw_event: object describing the event
2780 * Context: This function will acquire ioc->fw_event_lock.
2782 * This removes firmware event object from link list, frees associated memory.
2787 _scsih_fw_event_free(struct MPT2SAS_ADAPTER
*ioc
, struct fw_event_work
2790 unsigned long flags
;
2792 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2793 list_del(&fw_event
->list
);
2794 kfree(fw_event
->event_data
);
2796 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2801 * _scsih_error_recovery_delete_devices - remove devices not responding
2802 * @ioc: per adapter object
2807 _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER
*ioc
)
2809 struct fw_event_work
*fw_event
;
2811 if (ioc
->is_driver_loading
)
2814 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2818 fw_event
->event
= MPT2SAS_REMOVE_UNRESPONDING_DEVICES
;
2819 fw_event
->ioc
= ioc
;
2820 _scsih_fw_event_add(ioc
, fw_event
);
2824 * mpt2sas_port_enable_complete - port enable completed (fake event)
2825 * @ioc: per adapter object
2830 mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER
*ioc
)
2832 struct fw_event_work
*fw_event
;
2834 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
2837 fw_event
->event
= MPT2SAS_PORT_ENABLE_COMPLETE
;
2838 fw_event
->ioc
= ioc
;
2839 _scsih_fw_event_add(ioc
, fw_event
);
2843 * _scsih_fw_event_cleanup_queue - cleanup event queue
2844 * @ioc: per adapter object
2846 * Walk the firmware event queue, either killing timers, or waiting
2847 * for outstanding events to complete
2852 _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER
*ioc
)
2854 struct fw_event_work
*fw_event
, *next
;
2856 if (list_empty(&ioc
->fw_event_list
) ||
2857 !ioc
->firmware_event_thread
|| in_interrupt())
2860 list_for_each_entry_safe(fw_event
, next
, &ioc
->fw_event_list
, list
) {
2861 if (cancel_delayed_work(&fw_event
->delayed_work
)) {
2862 _scsih_fw_event_free(ioc
, fw_event
);
2865 fw_event
->cancel_pending_work
= 1;
2870 * _scsih_ublock_io_all_device - unblock every device
2871 * @ioc: per adapter object
2873 * change the device state from block to running
2876 _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2878 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2879 struct scsi_device
*sdev
;
2881 shost_for_each_device(sdev
, ioc
->shost
) {
2882 sas_device_priv_data
= sdev
->hostdata
;
2883 if (!sas_device_priv_data
)
2885 if (!sas_device_priv_data
->block
)
2887 sas_device_priv_data
->block
= 0;
2888 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_running, "
2890 sas_device_priv_data
->sas_target
->handle
));
2891 scsi_internal_device_unblock(sdev
);
2895 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2896 * @ioc: per adapter object
2897 * @handle: device handle
2899 * During device pull we need to appropiately set the sdev state.
2902 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2904 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2905 struct scsi_device
*sdev
;
2907 shost_for_each_device(sdev
, ioc
->shost
) {
2908 sas_device_priv_data
= sdev
->hostdata
;
2909 if (!sas_device_priv_data
)
2911 if (!sas_device_priv_data
->block
)
2913 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2914 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2915 MPT2SAS_INFO_FMT
"SDEV_RUNNING: "
2916 "handle(0x%04x)\n", ioc
->name
, handle
));
2917 sas_device_priv_data
->block
= 0;
2918 scsi_internal_device_unblock(sdev
);
2924 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2925 * @ioc: per adapter object
2926 * @handle: device handle
2928 * During device pull we need to appropiately set the sdev state.
2931 _scsih_block_io_all_device(struct MPT2SAS_ADAPTER
*ioc
)
2933 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2934 struct scsi_device
*sdev
;
2936 shost_for_each_device(sdev
, ioc
->shost
) {
2937 sas_device_priv_data
= sdev
->hostdata
;
2938 if (!sas_device_priv_data
)
2940 if (sas_device_priv_data
->block
)
2942 sas_device_priv_data
->block
= 1;
2943 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
, "device_blocked, "
2945 sas_device_priv_data
->sas_target
->handle
));
2946 scsi_internal_device_block(sdev
);
2952 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2953 * @ioc: per adapter object
2954 * @handle: device handle
2956 * During device pull we need to appropiately set the sdev state.
2959 _scsih_block_io_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
2961 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
2962 struct scsi_device
*sdev
;
2964 shost_for_each_device(sdev
, ioc
->shost
) {
2965 sas_device_priv_data
= sdev
->hostdata
;
2966 if (!sas_device_priv_data
)
2968 if (sas_device_priv_data
->block
)
2970 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2971 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
2972 MPT2SAS_INFO_FMT
"SDEV_BLOCK: "
2973 "handle(0x%04x)\n", ioc
->name
, handle
));
2974 sas_device_priv_data
->block
= 1;
2975 scsi_internal_device_block(sdev
);
2981 * _scsih_block_io_to_children_attached_to_ex
2982 * @ioc: per adapter object
2983 * @sas_expander: the sas_device object
2985 * This routine set sdev state to SDEV_BLOCK for all devices
2986 * attached to this expander. This function called when expander is
2990 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER
*ioc
,
2991 struct _sas_node
*sas_expander
)
2993 struct _sas_port
*mpt2sas_port
;
2994 struct _sas_device
*sas_device
;
2995 struct _sas_node
*expander_sibling
;
2996 unsigned long flags
;
3001 list_for_each_entry(mpt2sas_port
,
3002 &sas_expander
->sas_port_list
, port_list
) {
3003 if (mpt2sas_port
->remote_identify
.device_type
==
3005 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3007 mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
3008 mpt2sas_port
->remote_identify
.sas_address
);
3009 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3012 _scsih_block_io_device(ioc
, sas_device
->handle
);
3016 list_for_each_entry(mpt2sas_port
,
3017 &sas_expander
->sas_port_list
, port_list
) {
3019 if (mpt2sas_port
->remote_identify
.device_type
==
3020 SAS_EDGE_EXPANDER_DEVICE
||
3021 mpt2sas_port
->remote_identify
.device_type
==
3022 SAS_FANOUT_EXPANDER_DEVICE
) {
3024 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3026 mpt2sas_scsih_expander_find_by_sas_address(
3027 ioc
, mpt2sas_port
->remote_identify
.sas_address
);
3028 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3029 _scsih_block_io_to_children_attached_to_ex(ioc
,
3036 * _scsih_block_io_to_children_attached_directly
3037 * @ioc: per adapter object
3038 * @event_data: topology change event data
3040 * This routine set sdev state to SDEV_BLOCK for all devices
3041 * direct attached during device pull.
3044 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER
*ioc
,
3045 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3052 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3053 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3056 phy_number
= event_data
->StartPhyNum
+ i
;
3057 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3058 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3059 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3060 _scsih_block_io_device(ioc
, handle
);
3065 * _scsih_tm_tr_send - send task management request
3066 * @ioc: per adapter object
3067 * @handle: device handle
3068 * Context: interrupt time.
3070 * This code is to initiate the device removal handshake protocol
3071 * with controller firmware. This function will issue target reset
3072 * using high priority request queue. It will send a sas iounit
3073 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3075 * This is designed to send muliple task management request at the same
3076 * time to the fifo. If the fifo is full, we will append the request,
3077 * and process it in a future completion.
3080 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3082 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3084 struct _sas_device
*sas_device
;
3085 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
3086 u64 sas_address
= 0;
3087 unsigned long flags
;
3088 struct _tr_list
*delayed_tr
;
3091 if (ioc
->remove_host
) {
3092 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3093 "removed: handle(0x%04x)\n", __func__
, ioc
->name
, handle
));
3095 } else if (ioc
->pci_error_recovery
) {
3096 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3097 "error recovery: handle(0x%04x)\n", __func__
, ioc
->name
,
3101 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3102 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3103 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3104 "operational: handle(0x%04x)\n", __func__
, ioc
->name
,
3109 /* if PD, then return */
3110 if (test_bit(handle
, ioc
->pd_handles
))
3113 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3114 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
3115 if (sas_device
&& sas_device
->starget
&&
3116 sas_device
->starget
->hostdata
) {
3117 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3118 sas_target_priv_data
->deleted
= 1;
3119 sas_address
= sas_device
->sas_address
;
3121 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3123 if (sas_target_priv_data
) {
3124 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"setting delete flag: "
3125 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, handle
,
3126 (unsigned long long)sas_address
));
3127 _scsih_ublock_io_device(ioc
, handle
);
3128 sas_target_priv_data
->handle
= MPT2SAS_INVALID_DEVICE_HANDLE
;
3131 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3133 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3136 INIT_LIST_HEAD(&delayed_tr
->list
);
3137 delayed_tr
->handle
= handle
;
3138 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3139 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3140 "DELAYED:tr:handle(0x%04x), (open)\n",
3141 ioc
->name
, handle
));
3145 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3146 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3147 ioc
->tm_tr_cb_idx
));
3148 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3149 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3150 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3151 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3152 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3153 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3159 * _scsih_sas_control_complete - completion routine
3160 * @ioc: per adapter object
3161 * @smid: system request message index
3162 * @msix_index: MSIX table index supplied by the OS
3163 * @reply: reply message frame(lower 32bit addr)
3164 * Context: interrupt time.
3166 * This is the sas iounit control completion routine.
3167 * This code is part of the code to initiate the device removal
3168 * handshake protocol with controller firmware.
3170 * Return 1 meaning mf should be freed from _base_interrupt
3171 * 0 means the mf is freed from this function.
3174 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3175 u8 msix_index
, u32 reply
)
3177 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3178 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3179 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3181 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3182 "sc_complete:handle(0x%04x), (open) "
3183 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3184 ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3185 le16_to_cpu(mpi_reply
->IOCStatus
),
3186 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3191 * _scsih_tm_tr_volume_send - send target reset request for volumes
3192 * @ioc: per adapter object
3193 * @handle: device handle
3194 * Context: interrupt time.
3196 * This is designed to send muliple task management request at the same
3197 * time to the fifo. If the fifo is full, we will append the request,
3198 * and process it in a future completion.
3201 _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3203 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3205 struct _tr_list
*delayed_tr
;
3207 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3208 ioc
->pci_error_recovery
) {
3209 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3210 "progress!\n", __func__
, ioc
->name
));
3214 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3216 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3219 INIT_LIST_HEAD(&delayed_tr
->list
);
3220 delayed_tr
->handle
= handle
;
3221 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3222 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3223 "DELAYED:tr:handle(0x%04x), (open)\n",
3224 ioc
->name
, handle
));
3228 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"tr_send:handle(0x%04x), "
3229 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid
,
3230 ioc
->tm_tr_volume_cb_idx
));
3231 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3232 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3233 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3234 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3235 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3236 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
3240 * _scsih_tm_volume_tr_complete - target reset completion
3241 * @ioc: per adapter object
3242 * @smid: system request message index
3243 * @msix_index: MSIX table index supplied by the OS
3244 * @reply: reply message frame(lower 32bit addr)
3245 * Context: interrupt time.
3247 * Return 1 meaning mf should be freed from _base_interrupt
3248 * 0 means the mf is freed from this function.
3251 _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
3252 u8 msix_index
, u32 reply
)
3255 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3256 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3257 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3259 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3260 ioc
->pci_error_recovery
) {
3261 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host reset in "
3262 "progress!\n", __func__
, ioc
->name
));
3266 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3267 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3268 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3269 dewtprintk(ioc
, printk("spurious interrupt: "
3270 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle
,
3271 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3275 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3276 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3277 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3278 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3279 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3280 le32_to_cpu(mpi_reply
->TerminationCount
)));
3282 return _scsih_check_for_pending_tm(ioc
, smid
);
3286 * _scsih_tm_tr_complete -
3287 * @ioc: per adapter object
3288 * @smid: system request message index
3289 * @msix_index: MSIX table index supplied by the OS
3290 * @reply: reply message frame(lower 32bit addr)
3291 * Context: interrupt time.
3293 * This is the target reset completion routine.
3294 * This code is part of the code to initiate the device removal
3295 * handshake protocol with controller firmware.
3296 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3298 * Return 1 meaning mf should be freed from _base_interrupt
3299 * 0 means the mf is freed from this function.
3302 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3306 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3307 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3308 mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3309 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3313 if (ioc
->remove_host
) {
3314 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host has been "
3315 "removed\n", __func__
, ioc
->name
));
3317 } else if (ioc
->pci_error_recovery
) {
3318 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host in pci "
3319 "error recovery\n", __func__
, ioc
->name
));
3322 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3323 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3324 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: host is not "
3325 "operational\n", __func__
, ioc
->name
));
3329 mpi_request_tm
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3330 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3331 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3332 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"spurious interrupt: "
3333 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc
->name
, handle
,
3334 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3338 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3339 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3340 "loginfo(0x%08x), completed(%d)\n", ioc
->name
,
3341 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3342 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3343 le32_to_cpu(mpi_reply
->TerminationCount
)));
3345 smid_sas_ctrl
= mpt2sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3346 if (!smid_sas_ctrl
) {
3347 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3348 ioc
->name
, __func__
);
3352 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sc_send:handle(0x%04x), "
3353 "(open), smid(%d), cb(%d)\n", ioc
->name
, handle
, smid_sas_ctrl
,
3354 ioc
->tm_sas_control_cb_idx
));
3355 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3356 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3357 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3358 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3359 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3360 mpt2sas_base_put_smid_default(ioc
, smid_sas_ctrl
);
3362 return _scsih_check_for_pending_tm(ioc
, smid
);
3366 * _scsih_check_for_pending_tm - check for pending task management
3367 * @ioc: per adapter object
3368 * @smid: system request message index
3370 * This will check delayed target reset list, and feed the
3373 * Return 1 meaning mf should be freed from _base_interrupt
3374 * 0 means the mf is freed from this function.
3377 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3379 struct _tr_list
*delayed_tr
;
3381 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
3382 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
3383 struct _tr_list
, list
);
3384 mpt2sas_base_free_smid(ioc
, smid
);
3385 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
3386 list_del(&delayed_tr
->list
);
3391 if (!list_empty(&ioc
->delayed_tr_list
)) {
3392 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
3393 struct _tr_list
, list
);
3394 mpt2sas_base_free_smid(ioc
, smid
);
3395 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
3396 list_del(&delayed_tr
->list
);
3405 * _scsih_check_topo_delete_events - sanity check on topo events
3406 * @ioc: per adapter object
3407 * @event_data: the event data payload
3409 * This routine added to better handle cable breaker.
3411 * This handles the case where driver receives multiple expander
3412 * add and delete events in a single shot. When there is a delete event
3413 * the routine will void any pending add events waiting in the event queue.
3418 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3419 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3421 struct fw_event_work
*fw_event
;
3422 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
3423 u16 expander_handle
;
3424 struct _sas_node
*sas_expander
;
3425 unsigned long flags
;
3429 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
3430 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3433 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3434 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3435 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
3436 _scsih_tm_tr_send(ioc
, handle
);
3439 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
3440 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
3441 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3445 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3446 || event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
) {
3447 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
3448 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
3450 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
3451 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
3452 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
3453 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
3455 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
3458 /* mark ignore flag for pending events */
3459 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3460 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
3461 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
3464 local_event_data
= fw_event
->event_data
;
3465 if (local_event_data
->ExpStatus
==
3466 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
3467 local_event_data
->ExpStatus
==
3468 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
3469 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
3471 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3472 "setting ignoring flag\n", ioc
->name
));
3473 fw_event
->ignore
= 1;
3477 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3481 * _scsih_set_volume_delete_flag - setting volume delete flag
3482 * @ioc: per adapter object
3483 * @handle: device handle
3489 _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
3491 struct _raid_device
*raid_device
;
3492 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3493 unsigned long flags
;
3495 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
3496 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
3497 if (raid_device
&& raid_device
->starget
&&
3498 raid_device
->starget
->hostdata
) {
3499 sas_target_priv_data
=
3500 raid_device
->starget
->hostdata
;
3501 sas_target_priv_data
->deleted
= 1;
3502 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3503 "setting delete flag: handle(0x%04x), "
3504 "wwid(0x%016llx)\n", ioc
->name
, handle
,
3505 (unsigned long long) raid_device
->wwid
));
3507 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
3511 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3512 * @handle: input handle
3513 * @a: handle for volume a
3514 * @b: handle for volume b
3516 * IR firmware only supports two raid volumes. The purpose of this
3517 * routine is to set the volume handle in either a or b. When the given
3518 * input handle is non-zero, or when a and b have not been set before.
3521 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
3523 if (!handle
|| handle
== *a
|| handle
== *b
)
3532 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3533 * @ioc: per adapter object
3534 * @event_data: the event data payload
3535 * Context: interrupt time.
3537 * This routine will send target reset to volume, followed by target
3538 * resets to the PDs. This is called when a PD has been removed, or
3539 * volume has been deleted or removed. When the target reset is sent
3540 * to volume, the PD target resets need to be queued to start upon
3541 * completion of the volume target reset.
3546 _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER
*ioc
,
3547 Mpi2EventDataIrConfigChangeList_t
*event_data
)
3549 Mpi2EventIrConfigElement_t
*element
;
3551 u16 handle
, volume_handle
, a
, b
;
3552 struct _tr_list
*delayed_tr
;
3557 if (ioc
->is_warpdrive
)
3560 /* Volume Resets for Deleted or Removed */
3561 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3562 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3563 if (element
->ReasonCode
==
3564 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
3565 element
->ReasonCode
==
3566 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
3567 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3568 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
3569 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3573 /* Volume Resets for UNHIDE events */
3574 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3575 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3576 if (le32_to_cpu(event_data
->Flags
) &
3577 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
3579 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
3580 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3581 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
3586 _scsih_tm_tr_volume_send(ioc
, a
);
3588 _scsih_tm_tr_volume_send(ioc
, b
);
3590 /* PD target resets */
3591 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
3592 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
3593 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
3595 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
3596 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
3597 clear_bit(handle
, ioc
->pd_handles
);
3599 _scsih_tm_tr_send(ioc
, handle
);
3600 else if (volume_handle
== a
|| volume_handle
== b
) {
3601 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3602 BUG_ON(!delayed_tr
);
3603 INIT_LIST_HEAD(&delayed_tr
->list
);
3604 delayed_tr
->handle
= handle
;
3605 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3606 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
3607 "DELAYED:tr:handle(0x%04x), (open)\n", ioc
->name
,
3610 _scsih_tm_tr_send(ioc
, handle
);
3616 * _scsih_check_volume_delete_events - set delete flag for volumes
3617 * @ioc: per adapter object
3618 * @event_data: the event data payload
3619 * Context: interrupt time.
3621 * This will handle the case when the cable connected to entire volume is
3622 * pulled. We will take care of setting the deleted flag so normal IO will
3628 _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER
*ioc
,
3629 Mpi2EventDataIrVolume_t
*event_data
)
3633 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
3635 state
= le32_to_cpu(event_data
->NewValue
);
3636 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
3637 MPI2_RAID_VOL_STATE_FAILED
)
3638 _scsih_set_volume_delete_flag(ioc
,
3639 le16_to_cpu(event_data
->VolDevHandle
));
3643 * _scsih_flush_running_cmds - completing outstanding commands.
3644 * @ioc: per adapter object
3646 * The flushing out of all pending scmd commands following host reset,
3647 * where all IO is dropped to the floor.
3652 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER
*ioc
)
3654 struct scsi_cmnd
*scmd
;
3658 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
3659 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
3663 mpt2sas_base_free_smid(ioc
, smid
);
3664 scsi_dma_unmap(scmd
);
3665 if (ioc
->pci_error_recovery
)
3666 scmd
->result
= DID_NO_CONNECT
<< 16;
3668 scmd
->result
= DID_RESET
<< 16;
3669 scmd
->scsi_done(scmd
);
3671 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"completing %d cmds\n",
3676 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3677 * @scmd: pointer to scsi command object
3678 * @mpi_request: pointer to the SCSI_IO reqest message frame
3680 * Supporting protection 1 and 3.
3685 _scsih_setup_eedp(struct scsi_cmnd
*scmd
, Mpi2SCSIIORequest_t
*mpi_request
)
3688 unsigned char prot_op
= scsi_get_prot_op(scmd
);
3689 unsigned char prot_type
= scsi_get_prot_type(scmd
);
3691 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
3694 if (prot_op
== SCSI_PROT_READ_STRIP
)
3695 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
3696 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
3697 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
3701 switch (prot_type
) {
3702 case SCSI_PROT_DIF_TYPE1
:
3703 case SCSI_PROT_DIF_TYPE2
:
3706 * enable ref/guard checking
3707 * auto increment ref tag
3709 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
3710 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
3711 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3712 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
3713 cpu_to_be32(scsi_get_lba(scmd
));
3716 case SCSI_PROT_DIF_TYPE3
:
3719 * enable guard checking
3721 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
3724 mpi_request
->EEDPBlockSize
= cpu_to_le32(scmd
->device
->sector_size
);
3725 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
3729 * _scsih_eedp_error_handling - return sense code for EEDP errors
3730 * @scmd: pointer to scsi command object
3731 * @ioc_status: ioc status
3736 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
3742 switch (ioc_status
) {
3743 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
3746 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
3749 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
3757 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
3758 sk
= ILLEGAL_REQUEST
;
3759 host_byte
= DID_ABORT
;
3761 sk
= ABORTED_COMMAND
;
3765 scsi_build_sense_buffer(0, scmd
->sense_buffer
, sk
, 0x10, ascq
);
3766 scmd
->result
= DRIVER_SENSE
<< 24 | (host_byte
<< 16) |
3767 SAM_STAT_CHECK_CONDITION
;
3771 * _scsih_scsi_direct_io_get - returns direct io flag
3772 * @ioc: per adapter object
3773 * @smid: system request message index
3775 * Returns the smid stored scmd pointer.
3778 _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
3780 return ioc
->scsi_lookup
[smid
- 1].direct_io
;
3784 * _scsih_scsi_direct_io_set - sets direct io flag
3785 * @ioc: per adapter object
3786 * @smid: system request message index
3787 * @direct_io: Zero or non-zero value to set in the direct_io flag
3792 _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 direct_io
)
3794 ioc
->scsi_lookup
[smid
- 1].direct_io
= direct_io
;
3799 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3800 * @ioc: per adapter object
3801 * @scmd: pointer to scsi command object
3802 * @raid_device: pointer to raid device data structure
3803 * @mpi_request: pointer to the SCSI_IO reqest message frame
3804 * @smid: system request message index
3809 _scsih_setup_direct_io(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
3810 struct _raid_device
*raid_device
, Mpi2SCSIIORequest_t
*mpi_request
,
3813 u32 v_lba
, p_lba
, stripe_off
, stripe_unit
, column
, io_size
;
3814 u32 stripe_sz
, stripe_exp
;
3815 u8 num_pds
, *cdb_ptr
, i
;
3816 u8 cdb0
= scmd
->cmnd
[0];
3820 * Try Direct I/O to RAID memeber disks
3822 if (cdb0
== READ_16
|| cdb0
== READ_10
||
3823 cdb0
== WRITE_16
|| cdb0
== WRITE_10
) {
3824 cdb_ptr
= mpi_request
->CDB
.CDB32
;
3826 if ((cdb0
< READ_16
) || !(cdb_ptr
[2] | cdb_ptr
[3] | cdb_ptr
[4]
3828 io_size
= scsi_bufflen(scmd
) >>
3829 raid_device
->block_exponent
;
3830 i
= (cdb0
< READ_16
) ? 2 : 6;
3831 /* get virtual lba */
3832 v_lba
= be32_to_cpu(*(__be32
*)(&cdb_ptr
[i
]));
3834 if (((u64
)v_lba
+ (u64
)io_size
- 1) <=
3835 (u32
)raid_device
->max_lba
) {
3836 stripe_sz
= raid_device
->stripe_sz
;
3837 stripe_exp
= raid_device
->stripe_exponent
;
3838 stripe_off
= v_lba
& (stripe_sz
- 1);
3840 /* Check whether IO falls within a stripe */
3841 if ((stripe_off
+ io_size
) <= stripe_sz
) {
3842 num_pds
= raid_device
->num_pds
;
3843 p_lba
= v_lba
>> stripe_exp
;
3844 stripe_unit
= p_lba
/ num_pds
;
3845 column
= p_lba
% num_pds
;
3846 p_lba
= (stripe_unit
<< stripe_exp
) +
3848 mpi_request
->DevHandle
=
3849 cpu_to_le16(raid_device
->
3851 (*(__be32
*)(&cdb_ptr
[i
])) =
3854 * WD: To indicate this I/O is directI/O
3856 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3860 io_size
= scsi_bufflen(scmd
) >>
3861 raid_device
->block_exponent
;
3862 /* get virtual lba */
3863 v_llba
= be64_to_cpu(*(__be64
*)(&cdb_ptr
[2]));
3865 if ((v_llba
+ (u64
)io_size
- 1) <=
3866 raid_device
->max_lba
) {
3867 stripe_sz
= raid_device
->stripe_sz
;
3868 stripe_exp
= raid_device
->stripe_exponent
;
3869 stripe_off
= (u32
) (v_llba
& (stripe_sz
- 1));
3871 /* Check whether IO falls within a stripe */
3872 if ((stripe_off
+ io_size
) <= stripe_sz
) {
3873 num_pds
= raid_device
->num_pds
;
3874 p_lba
= (u32
)(v_llba
>> stripe_exp
);
3875 stripe_unit
= p_lba
/ num_pds
;
3876 column
= p_lba
% num_pds
;
3877 p_lba
= (stripe_unit
<< stripe_exp
) +
3879 mpi_request
->DevHandle
=
3880 cpu_to_le16(raid_device
->
3882 (*(__be64
*)(&cdb_ptr
[2])) =
3883 cpu_to_be64((u64
)p_lba
);
3885 * WD: To indicate this I/O is directI/O
3887 _scsih_scsi_direct_io_set(ioc
, smid
, 1);
3895 * _scsih_qcmd - main scsi request entry point
3896 * @scmd: pointer to scsi command object
3897 * @done: function pointer to be invoked on completion
3899 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3901 * Returns 0 on success. If there's a failure, return either:
3902 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3903 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3906 _scsih_qcmd_lck(struct scsi_cmnd
*scmd
, void (*done
)(struct scsi_cmnd
*))
3908 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3909 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
3910 struct MPT2SAS_TARGET
*sas_target_priv_data
;
3911 struct _raid_device
*raid_device
;
3912 Mpi2SCSIIORequest_t
*mpi_request
;
3916 scmd
->scsi_done
= done
;
3917 sas_device_priv_data
= scmd
->device
->hostdata
;
3918 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
3919 scmd
->result
= DID_NO_CONNECT
<< 16;
3920 scmd
->scsi_done(scmd
);
3924 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
3925 scmd
->result
= DID_NO_CONNECT
<< 16;
3926 scmd
->scsi_done(scmd
);
3930 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3931 /* invalid device handle */
3932 if (sas_target_priv_data
->handle
== MPT2SAS_INVALID_DEVICE_HANDLE
) {
3933 scmd
->result
= DID_NO_CONNECT
<< 16;
3934 scmd
->scsi_done(scmd
);
3938 /* host recovery or link resets sent via IOCTLs */
3939 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
)
3940 return SCSI_MLQUEUE_HOST_BUSY
;
3941 /* device busy with task management */
3942 else if (sas_device_priv_data
->block
|| sas_target_priv_data
->tm_busy
)
3943 return SCSI_MLQUEUE_DEVICE_BUSY
;
3944 /* device has been deleted */
3945 else if (sas_target_priv_data
->deleted
) {
3946 scmd
->result
= DID_NO_CONNECT
<< 16;
3947 scmd
->scsi_done(scmd
);
3951 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
3952 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
3953 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
3954 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
3956 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
3959 if (!(sas_device_priv_data
->flags
& MPT_DEVICE_FLAGS_INIT
)) {
3960 if (scmd
->device
->tagged_supported
) {
3961 if (scmd
->device
->ordered_tags
)
3962 mpi_control
|= MPI2_SCSIIO_CONTROL_ORDEREDQ
;
3964 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3966 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3967 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3969 mpi_control
|= (0x500);
3972 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
3973 /* Make sure Device is not raid volume.
3974 * We do not expose raid functionality to upper layer for warpdrive.
3976 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
3977 sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
3978 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
3980 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
3982 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3983 ioc
->name
, __func__
);
3986 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3987 memset(mpi_request
, 0, sizeof(Mpi2SCSIIORequest_t
));
3988 _scsih_setup_eedp(scmd
, mpi_request
);
3989 if (scmd
->cmd_len
== 32)
3990 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
3991 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3992 if (sas_device_priv_data
->sas_target
->flags
&
3993 MPT_TARGET_FLAGS_RAID_COMPONENT
)
3994 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
3996 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3997 mpi_request
->DevHandle
=
3998 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
3999 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4000 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4001 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4002 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4003 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4004 mpi_request
->SenseBufferLowAddress
=
4005 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
4006 mpi_request
->SGLOffset0
= offsetof(Mpi2SCSIIORequest_t
, SGL
) / 4;
4007 mpi_request
->SGLFlags
= cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI
+
4008 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR
);
4009 mpi_request
->VF_ID
= 0; /* TODO */
4010 mpi_request
->VP_ID
= 0;
4011 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4013 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4015 if (!mpi_request
->DataLength
) {
4016 mpt2sas_base_build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4018 if (_scsih_build_scatter_gather(ioc
, scmd
, smid
)) {
4019 mpt2sas_base_free_smid(ioc
, smid
);
4024 raid_device
= sas_target_priv_data
->raid_device
;
4025 if (raid_device
&& raid_device
->direct_io_enabled
)
4026 _scsih_setup_direct_io(ioc
, scmd
, raid_device
, mpi_request
,
4029 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
))
4030 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4031 le16_to_cpu(mpi_request
->DevHandle
));
4033 mpt2sas_base_put_smid_default(ioc
, smid
);
4037 return SCSI_MLQUEUE_HOST_BUSY
;
4040 static DEF_SCSI_QCMD(_scsih_qcmd
)
4043 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4044 * @sense_buffer: sense data returned by target
4045 * @data: normalized skey/asc/ascq
4050 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4052 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4053 /* descriptor format */
4054 data
->skey
= sense_buffer
[1] & 0x0F;
4055 data
->asc
= sense_buffer
[2];
4056 data
->ascq
= sense_buffer
[3];
4059 data
->skey
= sense_buffer
[2] & 0x0F;
4060 data
->asc
= sense_buffer
[12];
4061 data
->ascq
= sense_buffer
[13];
4065 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4067 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
4068 * @ioc: per adapter object
4069 * @scmd: pointer to scsi command object
4070 * @mpi_reply: reply mf payload returned from firmware
4072 * scsi_status - SCSI Status code returned from target device
4073 * scsi_state - state info associated with SCSI_IO determined by ioc
4074 * ioc_status - ioc supplied status info
4079 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4080 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4084 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4085 MPI2_IOCSTATUS_MASK
;
4086 u8 scsi_state
= mpi_reply
->SCSIState
;
4087 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4088 char *desc_ioc_state
= NULL
;
4089 char *desc_scsi_status
= NULL
;
4090 char *desc_scsi_state
= ioc
->tmp_string
;
4091 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4092 struct _sas_device
*sas_device
= NULL
;
4093 unsigned long flags
;
4094 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4095 struct MPT2SAS_TARGET
*priv_target
= starget
->hostdata
;
4096 char *device_str
= NULL
;
4101 if (ioc
->hide_ir_msg
)
4102 device_str
= "WarpDrive";
4104 device_str
= "volume";
4106 if (log_info
== 0x31170000)
4109 switch (ioc_status
) {
4110 case MPI2_IOCSTATUS_SUCCESS
:
4111 desc_ioc_state
= "success";
4113 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4114 desc_ioc_state
= "invalid function";
4116 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4117 desc_ioc_state
= "scsi recovered error";
4119 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4120 desc_ioc_state
= "scsi invalid dev handle";
4122 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4123 desc_ioc_state
= "scsi device not there";
4125 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4126 desc_ioc_state
= "scsi data overrun";
4128 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4129 desc_ioc_state
= "scsi data underrun";
4131 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4132 desc_ioc_state
= "scsi io data error";
4134 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4135 desc_ioc_state
= "scsi protocol error";
4137 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4138 desc_ioc_state
= "scsi task terminated";
4140 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4141 desc_ioc_state
= "scsi residual mismatch";
4143 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4144 desc_ioc_state
= "scsi task mgmt failed";
4146 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4147 desc_ioc_state
= "scsi ioc terminated";
4149 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4150 desc_ioc_state
= "scsi ext terminated";
4152 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4153 desc_ioc_state
= "eedp guard error";
4155 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4156 desc_ioc_state
= "eedp ref tag error";
4158 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4159 desc_ioc_state
= "eedp app tag error";
4162 desc_ioc_state
= "unknown";
4166 switch (scsi_status
) {
4167 case MPI2_SCSI_STATUS_GOOD
:
4168 desc_scsi_status
= "good";
4170 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4171 desc_scsi_status
= "check condition";
4173 case MPI2_SCSI_STATUS_CONDITION_MET
:
4174 desc_scsi_status
= "condition met";
4176 case MPI2_SCSI_STATUS_BUSY
:
4177 desc_scsi_status
= "busy";
4179 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4180 desc_scsi_status
= "intermediate";
4182 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4183 desc_scsi_status
= "intermediate condmet";
4185 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4186 desc_scsi_status
= "reservation conflict";
4188 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4189 desc_scsi_status
= "command terminated";
4191 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4192 desc_scsi_status
= "task set full";
4194 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4195 desc_scsi_status
= "aca active";
4197 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4198 desc_scsi_status
= "task aborted";
4201 desc_scsi_status
= "unknown";
4205 desc_scsi_state
[0] = '\0';
4207 desc_scsi_state
= " ";
4208 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4209 strcat(desc_scsi_state
, "response info ");
4210 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4211 strcat(desc_scsi_state
, "state terminated ");
4212 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4213 strcat(desc_scsi_state
, "no status ");
4214 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4215 strcat(desc_scsi_state
, "autosense failed ");
4216 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4217 strcat(desc_scsi_state
, "autosense valid ");
4219 scsi_print_command(scmd
);
4221 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4222 printk(MPT2SAS_WARN_FMT
"\t%s wwid(0x%016llx)\n", ioc
->name
,
4223 device_str
, (unsigned long long)priv_target
->sas_address
);
4225 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4226 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
4227 priv_target
->sas_address
);
4229 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
4230 "phy(%d)\n", ioc
->name
, sas_device
->sas_address
,
4232 printk(MPT2SAS_WARN_FMT
4233 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4234 ioc
->name
, sas_device
->enclosure_logical_id
,
4237 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4240 printk(MPT2SAS_WARN_FMT
"\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4241 "smid(%d)\n", ioc
->name
, le16_to_cpu(mpi_reply
->DevHandle
),
4242 desc_ioc_state
, ioc_status
, smid
);
4243 printk(MPT2SAS_WARN_FMT
"\trequest_len(%d), underflow(%d), "
4244 "resid(%d)\n", ioc
->name
, scsi_bufflen(scmd
), scmd
->underflow
,
4245 scsi_get_resid(scmd
));
4246 printk(MPT2SAS_WARN_FMT
"\ttag(%d), transfer_count(%d), "
4247 "sc->result(0x%08x)\n", ioc
->name
, le16_to_cpu(mpi_reply
->TaskTag
),
4248 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
4249 printk(MPT2SAS_WARN_FMT
"\tscsi_status(%s)(0x%02x), "
4250 "scsi_state(%s)(0x%02x)\n", ioc
->name
, desc_scsi_status
,
4251 scsi_status
, desc_scsi_state
, scsi_state
);
4253 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4254 struct sense_info data
;
4255 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4256 printk(MPT2SAS_WARN_FMT
"\t[sense_key,asc,ascq]: "
4257 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc
->name
, data
.skey
,
4258 data
.asc
, data
.ascq
, le32_to_cpu(mpi_reply
->SenseCount
));
4261 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
4262 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
4263 response_bytes
= (u8
*)&response_info
;
4264 _scsih_response_code(ioc
, response_bytes
[0]);
4270 * _scsih_turn_on_fault_led - illuminate Fault LED
4271 * @ioc: per adapter object
4272 * @handle: device handle
4278 _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4280 Mpi2SepReply_t mpi_reply
;
4281 Mpi2SepRequest_t mpi_request
;
4283 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
4284 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
4285 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
4286 mpi_request
.SlotStatus
=
4287 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
4288 mpi_request
.DevHandle
= cpu_to_le16(handle
);
4289 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
4290 if ((mpt2sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
4291 &mpi_request
)) != 0) {
4292 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n", ioc
->name
,
4293 __FILE__
, __LINE__
, __func__
);
4297 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
4298 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"enclosure_processor: "
4299 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc
->name
,
4300 le16_to_cpu(mpi_reply
.IOCStatus
),
4301 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
4307 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4308 * @ioc: per adapter object
4309 * @handle: device handle
4310 * Context: interrupt.
4315 _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4317 struct fw_event_work
*fw_event
;
4319 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
4322 fw_event
->event
= MPT2SAS_TURN_ON_FAULT_LED
;
4323 fw_event
->device_handle
= handle
;
4324 fw_event
->ioc
= ioc
;
4325 _scsih_fw_event_add(ioc
, fw_event
);
4329 * _scsih_smart_predicted_fault - process smart errors
4330 * @ioc: per adapter object
4331 * @handle: device handle
4332 * Context: interrupt.
4337 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4339 struct scsi_target
*starget
;
4340 struct MPT2SAS_TARGET
*sas_target_priv_data
;
4341 Mpi2EventNotificationReply_t
*event_reply
;
4342 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
4343 struct _sas_device
*sas_device
;
4345 unsigned long flags
;
4347 /* only handle non-raid devices */
4348 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
4349 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
4351 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4354 starget
= sas_device
->starget
;
4355 sas_target_priv_data
= starget
->hostdata
;
4357 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
4358 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))) {
4359 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4362 starget_printk(KERN_WARNING
, starget
, "predicted fault\n");
4363 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
4365 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
4366 _scsih_send_event_to_turn_on_fault_led(ioc
, handle
);
4368 /* insert into event log */
4369 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
4370 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
4371 event_reply
= kzalloc(sz
, GFP_ATOMIC
);
4373 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4374 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4378 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4379 event_reply
->Event
=
4380 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4381 event_reply
->MsgLength
= sz
/4;
4382 event_reply
->EventDataLength
=
4383 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
4384 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
4385 event_reply
->EventData
;
4386 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
4387 event_data
->ASC
= 0x5D;
4388 event_data
->DevHandle
= cpu_to_le16(handle
);
4389 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
4390 mpt2sas_ctl_add_to_event_log(ioc
, event_reply
);
4395 * _scsih_io_done - scsi request callback
4396 * @ioc: per adapter object
4397 * @smid: system request message index
4398 * @msix_index: MSIX table index supplied by the OS
4399 * @reply: reply message frame(lower 32bit addr)
4401 * Callback handler when using _scsih_qcmd.
4403 * Return 1 meaning mf should be freed from _base_interrupt
4404 * 0 means the mf is freed from this function.
4407 _scsih_io_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4409 Mpi2SCSIIORequest_t
*mpi_request
;
4410 Mpi2SCSIIOReply_t
*mpi_reply
;
4411 struct scsi_cmnd
*scmd
;
4417 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
4418 u32 response_code
= 0;
4419 unsigned long flags
;
4421 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4422 scmd
= _scsih_scsi_lookup_get_clear(ioc
, smid
);
4426 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
4428 if (mpi_reply
== NULL
) {
4429 scmd
->result
= DID_OK
<< 16;
4433 sas_device_priv_data
= scmd
->device
->hostdata
;
4434 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
4435 sas_device_priv_data
->sas_target
->deleted
) {
4436 scmd
->result
= DID_NO_CONNECT
<< 16;
4439 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
4441 * WARPDRIVE: If direct_io is set then it is directIO,
4442 * the failed direct I/O should be redirected to volume
4444 if (_scsih_scsi_direct_io_get(ioc
, smid
) &&
4445 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
4446 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
4447 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4448 ioc
->scsi_lookup
[smid
- 1].scmd
= scmd
;
4449 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4450 _scsih_scsi_direct_io_set(ioc
, smid
, 0);
4451 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4452 mpi_request
->DevHandle
=
4453 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
4454 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
4455 sas_device_priv_data
->sas_target
->handle
);
4460 /* turning off TLR */
4461 scsi_state
= mpi_reply
->SCSIState
;
4462 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4464 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
4465 if (!sas_device_priv_data
->tlr_snoop_check
) {
4466 sas_device_priv_data
->tlr_snoop_check
++;
4467 /* Make sure Device is not raid volume.
4468 * We do not expose raid functionality to upper layer for warpdrive.
4470 if (!ioc
->is_warpdrive
&& !_scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
4471 sas_is_tlr_enabled(scmd
->device
) &&
4472 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
4473 sas_disable_tlr(scmd
->device
);
4474 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
4478 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
4479 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
4480 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
4481 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4484 ioc_status
&= MPI2_IOCSTATUS_MASK
;
4485 scsi_status
= mpi_reply
->SCSIStatus
;
4487 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
4488 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
4489 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
4490 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
4491 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
4494 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
4495 struct sense_info data
;
4496 const void *sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
4498 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
4499 le32_to_cpu(mpi_reply
->SenseCount
));
4500 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
4501 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
4502 /* failure prediction threshold exceeded */
4503 if (data
.asc
== 0x5D)
4504 _scsih_smart_predicted_fault(ioc
,
4505 le16_to_cpu(mpi_reply
->DevHandle
));
4508 switch (ioc_status
) {
4509 case MPI2_IOCSTATUS_BUSY
:
4510 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
4511 scmd
->result
= SAM_STAT_BUSY
;
4514 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4515 scmd
->result
= DID_NO_CONNECT
<< 16;
4518 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4519 if (sas_device_priv_data
->block
) {
4520 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
4523 scmd
->result
= DID_SOFT_ERROR
<< 16;
4525 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4526 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4527 scmd
->result
= DID_RESET
<< 16;
4530 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4531 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
4532 scmd
->result
= DID_SOFT_ERROR
<< 16;
4534 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4537 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4538 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4540 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
4543 if (xfer_cnt
< scmd
->underflow
) {
4544 if (scsi_status
== SAM_STAT_BUSY
)
4545 scmd
->result
= SAM_STAT_BUSY
;
4547 scmd
->result
= DID_SOFT_ERROR
<< 16;
4548 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4549 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
4550 scmd
->result
= DID_SOFT_ERROR
<< 16;
4551 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4552 scmd
->result
= DID_RESET
<< 16;
4553 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
4554 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
4555 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
4556 scmd
->result
= (DRIVER_SENSE
<< 24) |
4557 SAM_STAT_CHECK_CONDITION
;
4558 scmd
->sense_buffer
[0] = 0x70;
4559 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
4560 scmd
->sense_buffer
[12] = 0x20;
4561 scmd
->sense_buffer
[13] = 0;
4565 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4566 scsi_set_resid(scmd
, 0);
4567 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4568 case MPI2_IOCSTATUS_SUCCESS
:
4569 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
4570 if (response_code
==
4571 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
4572 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
4573 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
4574 scmd
->result
= DID_SOFT_ERROR
<< 16;
4575 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4576 scmd
->result
= DID_RESET
<< 16;
4579 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4580 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4581 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4582 _scsih_eedp_error_handling(scmd
, ioc_status
);
4584 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4585 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4586 case MPI2_IOCSTATUS_INVALID_SGL
:
4587 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
4588 case MPI2_IOCSTATUS_INVALID_FIELD
:
4589 case MPI2_IOCSTATUS_INVALID_STATE
:
4590 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4591 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4593 scmd
->result
= DID_SOFT_ERROR
<< 16;
4598 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4599 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
4600 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
4604 scsi_dma_unmap(scmd
);
4605 scmd
->scsi_done(scmd
);
4610 * _scsih_sas_host_refresh - refreshing sas host object contents
4611 * @ioc: per adapter object
4614 * During port enable, fw will send topology events for every device. Its
4615 * possible that the handles may change from the previous setting, so this
4616 * code keeping handles updating if changed.
4621 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER
*ioc
)
4626 Mpi2ConfigReply_t mpi_reply
;
4627 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4628 u16 attached_handle
;
4631 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
4632 "updating handles for sas_host(0x%016llx)\n",
4633 ioc
->name
, (unsigned long long)ioc
->sas_hba
.sas_address
));
4635 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
4636 * sizeof(Mpi2SasIOUnit0PhyData_t
));
4637 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4638 if (!sas_iounit_pg0
) {
4639 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4640 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4644 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4645 sas_iounit_pg0
, sz
)) != 0)
4647 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4648 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4650 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4651 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
4653 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4654 PhyData
[0].ControllerDevHandle
);
4655 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4656 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
4658 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
4659 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
4660 mpt2sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
4661 attached_handle
, i
, link_rate
);
4664 kfree(sas_iounit_pg0
);
4668 * _scsih_sas_host_add - create sas host object
4669 * @ioc: per adapter object
4671 * Creating host side data object, stored in ioc->sas_hba
4676 _scsih_sas_host_add(struct MPT2SAS_ADAPTER
*ioc
)
4679 Mpi2ConfigReply_t mpi_reply
;
4680 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
4681 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
4682 Mpi2SasPhyPage0_t phy_pg0
;
4683 Mpi2SasDevicePage0_t sas_device_pg0
;
4684 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4687 u16 device_missing_delay
;
4689 mpt2sas_config_get_number_hba_phys(ioc
, &ioc
->sas_hba
.num_phys
);
4690 if (!ioc
->sas_hba
.num_phys
) {
4691 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4692 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4696 /* sas_iounit page 0 */
4697 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4698 sizeof(Mpi2SasIOUnit0PhyData_t
));
4699 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
4700 if (!sas_iounit_pg0
) {
4701 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4702 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4705 if ((mpt2sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
4706 sas_iounit_pg0
, sz
))) {
4707 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4708 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4711 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4712 MPI2_IOCSTATUS_MASK
;
4713 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4714 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4715 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4719 /* sas_iounit page 1 */
4720 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
4721 sizeof(Mpi2SasIOUnit1PhyData_t
));
4722 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
4723 if (!sas_iounit_pg1
) {
4724 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4725 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4728 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
4729 sas_iounit_pg1
, sz
))) {
4730 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4731 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4734 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4735 MPI2_IOCSTATUS_MASK
;
4736 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4737 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4738 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4742 ioc
->io_missing_delay
=
4743 le16_to_cpu(sas_iounit_pg1
->IODeviceMissingDelay
);
4744 device_missing_delay
=
4745 le16_to_cpu(sas_iounit_pg1
->ReportDeviceMissingDelay
);
4746 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
4747 ioc
->device_missing_delay
= (device_missing_delay
&
4748 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
4750 ioc
->device_missing_delay
= device_missing_delay
&
4751 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
4753 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
4754 ioc
->sas_hba
.phy
= kcalloc(ioc
->sas_hba
.num_phys
,
4755 sizeof(struct _sas_phy
), GFP_KERNEL
);
4756 if (!ioc
->sas_hba
.phy
) {
4757 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4758 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4761 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
4762 if ((mpt2sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
4764 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4765 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4768 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4769 MPI2_IOCSTATUS_MASK
;
4770 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4771 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4772 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4777 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
4778 PhyData
[0].ControllerDevHandle
);
4779 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
4780 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
4781 mpt2sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
4782 phy_pg0
, ioc
->sas_hba
.parent_dev
);
4784 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
4785 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
4786 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4787 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4790 ioc
->sas_hba
.enclosure_handle
=
4791 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
4792 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
4793 printk(MPT2SAS_INFO_FMT
"host_add: handle(0x%04x), "
4794 "sas_addr(0x%016llx), phys(%d)\n", ioc
->name
, ioc
->sas_hba
.handle
,
4795 (unsigned long long) ioc
->sas_hba
.sas_address
,
4796 ioc
->sas_hba
.num_phys
) ;
4798 if (ioc
->sas_hba
.enclosure_handle
) {
4799 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4801 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4802 ioc
->sas_hba
.enclosure_handle
))) {
4803 ioc
->sas_hba
.enclosure_logical_id
=
4804 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4809 kfree(sas_iounit_pg1
);
4810 kfree(sas_iounit_pg0
);
4814 * _scsih_expander_add - creating expander object
4815 * @ioc: per adapter object
4816 * @handle: expander handle
4818 * Creating expander object, stored in ioc->sas_expander_list.
4820 * Return 0 for success, else error.
4823 _scsih_expander_add(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
4825 struct _sas_node
*sas_expander
;
4826 Mpi2ConfigReply_t mpi_reply
;
4827 Mpi2ExpanderPage0_t expander_pg0
;
4828 Mpi2ExpanderPage1_t expander_pg1
;
4829 Mpi2SasEnclosurePage0_t enclosure_pg0
;
4832 u64 sas_address
, sas_address_parent
= 0;
4834 unsigned long flags
;
4835 struct _sas_port
*mpt2sas_port
= NULL
;
4841 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
4844 if ((mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
4845 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
4846 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4847 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4851 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
4852 MPI2_IOCSTATUS_MASK
;
4853 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4854 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4855 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4859 /* handle out of order topology events */
4860 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
4861 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
4863 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4864 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4867 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
4868 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4869 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4870 sas_address_parent
);
4871 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4872 if (!sas_expander
) {
4873 rc
= _scsih_expander_add(ioc
, parent_handle
);
4879 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4880 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
4881 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
4883 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4888 sas_expander
= kzalloc(sizeof(struct _sas_node
),
4890 if (!sas_expander
) {
4891 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4892 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4896 sas_expander
->handle
= handle
;
4897 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
4898 sas_expander
->sas_address_parent
= sas_address_parent
;
4899 sas_expander
->sas_address
= sas_address
;
4901 printk(MPT2SAS_INFO_FMT
"expander_add: handle(0x%04x),"
4902 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc
->name
,
4903 handle
, parent_handle
, (unsigned long long)
4904 sas_expander
->sas_address
, sas_expander
->num_phys
);
4906 if (!sas_expander
->num_phys
)
4908 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
4909 sizeof(struct _sas_phy
), GFP_KERNEL
);
4910 if (!sas_expander
->phy
) {
4911 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4912 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4917 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
4918 mpt2sas_port
= mpt2sas_transport_port_add(ioc
, handle
,
4919 sas_address_parent
);
4920 if (!mpt2sas_port
) {
4921 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4922 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4926 sas_expander
->parent_dev
= &mpt2sas_port
->rphy
->dev
;
4928 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
4929 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
4930 &expander_pg1
, i
, handle
))) {
4931 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4932 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4936 sas_expander
->phy
[i
].handle
= handle
;
4937 sas_expander
->phy
[i
].phy_id
= i
;
4939 if ((mpt2sas_transport_add_expander_phy(ioc
,
4940 &sas_expander
->phy
[i
], expander_pg1
,
4941 sas_expander
->parent_dev
))) {
4942 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
4943 ioc
->name
, __FILE__
, __LINE__
, __func__
);
4949 if (sas_expander
->enclosure_handle
) {
4950 if (!(mpt2sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
4951 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
4952 sas_expander
->enclosure_handle
))) {
4953 sas_expander
->enclosure_logical_id
=
4954 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
4958 _scsih_expander_node_add(ioc
, sas_expander
);
4964 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
4965 sas_address_parent
);
4966 kfree(sas_expander
);
4971 * _scsih_done - scsih callback handler.
4972 * @ioc: per adapter object
4973 * @smid: system request message index
4974 * @msix_index: MSIX table index supplied by the OS
4975 * @reply: reply message frame(lower 32bit addr)
4977 * Callback handler when sending internal generated message frames.
4978 * The callback index passed is `ioc->scsih_cb_idx`
4980 * Return 1 meaning mf should be freed from _base_interrupt
4981 * 0 means the mf is freed from this function.
4984 _scsih_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
4986 MPI2DefaultReply_t
*mpi_reply
;
4988 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
4989 if (ioc
->scsih_cmds
.status
== MPT2_CMD_NOT_USED
)
4991 if (ioc
->scsih_cmds
.smid
!= smid
)
4993 ioc
->scsih_cmds
.status
|= MPT2_CMD_COMPLETE
;
4995 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
4996 mpi_reply
->MsgLength
*4);
4997 ioc
->scsih_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
4999 ioc
->scsih_cmds
.status
&= ~MPT2_CMD_PENDING
;
5000 complete(&ioc
->scsih_cmds
.done
);
5005 * mpt2sas_expander_remove - removing expander object
5006 * @ioc: per adapter object
5007 * @sas_address: expander sas_address
5012 mpt2sas_expander_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5014 struct _sas_node
*sas_expander
;
5015 unsigned long flags
;
5017 if (ioc
->shost_recovery
)
5020 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5021 sas_expander
= mpt2sas_scsih_expander_find_by_sas_address(ioc
,
5023 if (!sas_expander
) {
5024 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5027 list_del(&sas_expander
->list
);
5028 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5029 _scsih_expander_node_remove(ioc
, sas_expander
);
5033 * _scsih_check_access_status - check access flags
5034 * @ioc: per adapter object
5035 * @sas_address: sas address
5036 * @handle: sas device handle
5037 * @access_flags: errors returned during discovery of the device
5039 * Return 0 for success, else failure
5042 _scsih_check_access_status(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
5043 u16 handle
, u8 access_status
)
5048 switch (access_status
) {
5049 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5050 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5053 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5054 desc
= "sata capability failed";
5056 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5057 desc
= "sata affiliation conflict";
5059 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5060 desc
= "route not addressable";
5062 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5063 desc
= "smp error not addressable";
5065 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5066 desc
= "device blocked";
5068 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5069 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5070 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5071 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5072 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5073 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5074 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5075 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5076 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5077 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5078 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5079 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5080 desc
= "sata initialization failed";
5090 printk(MPT2SAS_ERR_FMT
"discovery errors(%s): sas_address(0x%016llx), "
5091 "handle(0x%04x)\n", ioc
->name
, desc
,
5092 (unsigned long long)sas_address
, handle
);
5097 _scsih_check_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
5099 Mpi2ConfigReply_t mpi_reply
;
5100 Mpi2SasDevicePage0_t sas_device_pg0
;
5101 struct _sas_device
*sas_device
;
5103 unsigned long flags
;
5105 struct scsi_target
*starget
;
5106 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5109 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5110 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5113 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5114 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5117 /* check if this is end device */
5118 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5119 if (!(_scsih_is_end_device(device_info
)))
5122 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5123 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5124 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5128 printk(MPT2SAS_ERR_FMT
"device is not present "
5129 "handle(0x%04x), no sas_device!!!\n", ioc
->name
, handle
);
5130 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5134 if (unlikely(sas_device
->handle
!= handle
)) {
5135 starget
= sas_device
->starget
;
5136 sas_target_priv_data
= starget
->hostdata
;
5137 starget_printk(KERN_INFO
, starget
, "handle changed from(0x%04x)"
5138 " to (0x%04x)!!!\n", sas_device
->handle
, handle
);
5139 sas_target_priv_data
->handle
= handle
;
5140 sas_device
->handle
= handle
;
5142 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5144 /* check if device is present */
5145 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5146 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5147 printk(MPT2SAS_ERR_FMT
"device is not present "
5148 "handle(0x%04x), flags!!!\n", ioc
->name
, handle
);
5152 /* check if there were any issues with discovery */
5153 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5154 sas_device_pg0
.AccessStatus
))
5156 _scsih_ublock_io_device(ioc
, handle
);
5161 * _scsih_add_device - creating sas device object
5162 * @ioc: per adapter object
5163 * @handle: sas device handle
5164 * @phy_num: phy number end device attached to
5165 * @is_pd: is this hidden raid component
5167 * Creating end device object, stored in ioc->sas_device_list.
5169 * Returns 0 for success, non-zero for failure.
5172 _scsih_add_device(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
, u8 is_pd
)
5174 Mpi2ConfigReply_t mpi_reply
;
5175 Mpi2SasDevicePage0_t sas_device_pg0
;
5176 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5177 struct _sas_device
*sas_device
;
5181 unsigned long flags
;
5183 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5184 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
5185 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5186 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5190 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5191 MPI2_IOCSTATUS_MASK
;
5192 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5193 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5194 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5198 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5200 /* check if device is present */
5201 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
5202 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
5203 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5204 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5205 printk(MPT2SAS_ERR_FMT
"Flags = 0x%04x\n",
5206 ioc
->name
, le16_to_cpu(sas_device_pg0
.Flags
));
5210 /* check if there were any issues with discovery */
5211 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
5212 sas_device_pg0
.AccessStatus
))
5215 /* check if this is end device */
5216 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5217 if (!(_scsih_is_end_device(device_info
))) {
5218 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5219 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5224 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5225 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5227 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5232 sas_device
= kzalloc(sizeof(struct _sas_device
),
5235 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5236 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5240 sas_device
->handle
= handle
;
5241 if (_scsih_get_sas_address(ioc
, le16_to_cpu
5242 (sas_device_pg0
.ParentDevHandle
),
5243 &sas_device
->sas_address_parent
) != 0)
5244 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
5245 ioc
->name
, __FILE__
, __LINE__
, __func__
);
5246 sas_device
->enclosure_handle
=
5247 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5249 le16_to_cpu(sas_device_pg0
.Slot
);
5250 sas_device
->device_info
= device_info
;
5251 sas_device
->sas_address
= sas_address
;
5252 sas_device
->phy
= sas_device_pg0
.PhyNum
;
5254 /* get enclosure_logical_id */
5255 if (sas_device
->enclosure_handle
&& !(mpt2sas_config_get_enclosure_pg0(
5256 ioc
, &mpi_reply
, &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5257 sas_device
->enclosure_handle
)))
5258 sas_device
->enclosure_logical_id
=
5259 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5261 /* get device name */
5262 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
5264 if (ioc
->wait_for_discovery_to_complete
)
5265 _scsih_sas_device_init_add(ioc
, sas_device
);
5267 _scsih_sas_device_add(ioc
, sas_device
);
5273 * _scsih_remove_device - removing sas device object
5274 * @ioc: per adapter object
5275 * @sas_device_delete: the sas_device object
5280 _scsih_remove_device(struct MPT2SAS_ADAPTER
*ioc
,
5281 struct _sas_device
*sas_device
)
5283 struct _sas_device sas_device_backup
;
5284 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5289 memcpy(&sas_device_backup
, sas_device
, sizeof(struct _sas_device
));
5290 _scsih_sas_device_remove(ioc
, sas_device
);
5292 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: "
5293 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5294 sas_device_backup
.handle
, (unsigned long long)
5295 sas_device_backup
.sas_address
));
5297 if (sas_device_backup
.starget
&& sas_device_backup
.starget
->hostdata
) {
5298 sas_target_priv_data
= sas_device_backup
.starget
->hostdata
;
5299 sas_target_priv_data
->deleted
= 1;
5300 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
5301 sas_target_priv_data
->handle
=
5302 MPT2SAS_INVALID_DEVICE_HANDLE
;
5305 _scsih_ublock_io_device(ioc
, sas_device_backup
.handle
);
5307 if (!ioc
->hide_drives
)
5308 mpt2sas_transport_port_remove(ioc
,
5309 sas_device_backup
.sas_address
,
5310 sas_device_backup
.sas_address_parent
);
5312 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), sas_addr"
5313 "(0x%016llx)\n", ioc
->name
, sas_device_backup
.handle
,
5314 (unsigned long long) sas_device_backup
.sas_address
);
5316 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit: "
5317 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
, __func__
,
5318 sas_device_backup
.handle
, (unsigned long long)
5319 sas_device_backup
.sas_address
));
5323 * mpt2sas_device_remove - removing device object
5324 * @ioc: per adapter object
5325 * @sas_address: expander sas_address
5330 mpt2sas_device_remove(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
)
5332 struct _sas_device
*sas_device
;
5333 unsigned long flags
;
5335 if (ioc
->shost_recovery
)
5338 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5339 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5342 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5345 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5346 _scsih_remove_device(ioc
, sas_device
);
5349 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5351 * _scsih_sas_topology_change_event_debug - debug for topology event
5352 * @ioc: per adapter object
5353 * @event_data: event data payload
5357 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5358 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
5364 char *status_str
= NULL
;
5365 u8 link_rate
, prev_link_rate
;
5367 switch (event_data
->ExpStatus
) {
5368 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
5371 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
5372 status_str
= "remove";
5374 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
5376 status_str
= "responding";
5378 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
5379 status_str
= "remove delay";
5382 status_str
= "unknown status";
5385 printk(MPT2SAS_INFO_FMT
"sas topology change: (%s)\n",
5386 ioc
->name
, status_str
);
5387 printk(KERN_INFO
"\thandle(0x%04x), enclosure_handle(0x%04x) "
5388 "start_phy(%02d), count(%d)\n",
5389 le16_to_cpu(event_data
->ExpanderDevHandle
),
5390 le16_to_cpu(event_data
->EnclosureHandle
),
5391 event_data
->StartPhyNum
, event_data
->NumEntries
);
5392 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5393 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5396 phy_number
= event_data
->StartPhyNum
+ i
;
5397 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5398 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5399 switch (reason_code
) {
5400 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5401 status_str
= "target add";
5403 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5404 status_str
= "target remove";
5406 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
5407 status_str
= "delay target remove";
5409 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5410 status_str
= "link rate change";
5412 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
5413 status_str
= "target responding";
5416 status_str
= "unknown";
5419 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5420 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5421 printk(KERN_INFO
"\tphy(%02d), attached_handle(0x%04x): %s:"
5422 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
5423 handle
, status_str
, link_rate
, prev_link_rate
);
5430 * _scsih_sas_topology_change_event - handle topology changes
5431 * @ioc: per adapter object
5432 * @fw_event: The fw_event_work object
5437 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5438 struct fw_event_work
*fw_event
)
5441 u16 parent_handle
, handle
;
5443 u8 phy_number
, max_phys
;
5444 struct _sas_node
*sas_expander
;
5445 struct _sas_device
*sas_device
;
5447 unsigned long flags
;
5448 u8 link_rate
, prev_link_rate
;
5449 Mpi2EventDataSasTopologyChangeList_t
*event_data
= fw_event
->event_data
;
5451 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5452 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5453 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
5456 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
5459 if (!ioc
->sas_hba
.num_phys
)
5460 _scsih_sas_host_add(ioc
);
5462 _scsih_sas_host_refresh(ioc
);
5464 if (fw_event
->ignore
) {
5465 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring expander "
5466 "event\n", ioc
->name
));
5470 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
5472 /* handle expander add */
5473 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
5474 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
5477 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5478 sas_expander
= mpt2sas_scsih_expander_find_by_handle(ioc
,
5480 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5482 sas_address
= sas_expander
->sas_address
;
5483 max_phys
= sas_expander
->num_phys
;
5484 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
5485 sas_address
= ioc
->sas_hba
.sas_address
;
5486 max_phys
= ioc
->sas_hba
.num_phys
;
5490 /* handle siblings events */
5491 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
5492 if (fw_event
->ignore
) {
5493 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"ignoring "
5494 "expander event\n", ioc
->name
));
5497 if (ioc
->shost_recovery
|| ioc
->remove_host
||
5498 ioc
->pci_error_recovery
)
5500 phy_number
= event_data
->StartPhyNum
+ i
;
5501 if (phy_number
>= max_phys
)
5503 reason_code
= event_data
->PHY
[i
].PhyStatus
&
5504 MPI2_EVENT_SAS_TOPO_RC_MASK
;
5505 if ((event_data
->PHY
[i
].PhyStatus
&
5506 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
5507 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
5509 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
5512 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
5513 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
5514 switch (reason_code
) {
5515 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
5517 if (ioc
->shost_recovery
)
5520 if (link_rate
== prev_link_rate
)
5523 mpt2sas_transport_update_links(ioc
, sas_address
,
5524 handle
, phy_number
, link_rate
);
5526 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5529 _scsih_check_device(ioc
, handle
);
5531 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
5533 if (ioc
->shost_recovery
)
5536 mpt2sas_transport_update_links(ioc
, sas_address
,
5537 handle
, phy_number
, link_rate
);
5539 _scsih_add_device(ioc
, handle
, phy_number
, 0);
5541 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
5543 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5544 sas_device
= _scsih_sas_device_find_by_handle(ioc
,
5547 spin_unlock_irqrestore(&ioc
->sas_device_lock
,
5551 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5552 _scsih_remove_device(ioc
, sas_device
);
5557 /* handle expander removal */
5558 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
5560 mpt2sas_expander_remove(ioc
, sas_address
);
5564 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5566 * _scsih_sas_device_status_change_event_debug - debug for device event
5567 * @event_data: event data payload
5573 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5574 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
5576 char *reason_str
= NULL
;
5578 switch (event_data
->ReasonCode
) {
5579 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
5580 reason_str
= "smart data";
5582 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
5583 reason_str
= "unsupported device discovered";
5585 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
5586 reason_str
= "internal device reset";
5588 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
5589 reason_str
= "internal task abort";
5591 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
5592 reason_str
= "internal task abort set";
5594 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
5595 reason_str
= "internal clear task set";
5597 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
5598 reason_str
= "internal query task";
5600 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
5601 reason_str
= "sata init failure";
5603 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
5604 reason_str
= "internal device reset complete";
5606 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
5607 reason_str
= "internal task abort complete";
5609 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
5610 reason_str
= "internal async notification";
5612 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
5613 reason_str
= "expander reduced functionality";
5615 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
5616 reason_str
= "expander reduced functionality complete";
5619 reason_str
= "unknown reason";
5622 printk(MPT2SAS_INFO_FMT
"device status change: (%s)\n"
5623 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5624 ioc
->name
, reason_str
, le16_to_cpu(event_data
->DevHandle
),
5625 (unsigned long long)le64_to_cpu(event_data
->SASAddress
),
5626 le16_to_cpu(event_data
->TaskTag
));
5627 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
5628 printk(MPT2SAS_INFO_FMT
", ASC(0x%x), ASCQ(0x%x)\n", ioc
->name
,
5629 event_data
->ASC
, event_data
->ASCQ
);
5630 printk(KERN_INFO
"\n");
5635 * _scsih_sas_device_status_change_event - handle device status change
5636 * @ioc: per adapter object
5637 * @fw_event: The fw_event_work object
5643 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5644 struct fw_event_work
*fw_event
)
5646 struct MPT2SAS_TARGET
*target_priv_data
;
5647 struct _sas_device
*sas_device
;
5649 unsigned long flags
;
5650 Mpi2EventDataSasDeviceStatusChange_t
*event_data
=
5651 fw_event
->event_data
;
5653 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5654 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5655 _scsih_sas_device_status_change_event_debug(ioc
,
5659 /* In MPI Revision K (0xC), the internal device reset complete was
5660 * implemented, so avoid setting tm_busy flag for older firmware.
5662 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
5665 if (event_data
->ReasonCode
!=
5666 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
5667 event_data
->ReasonCode
!=
5668 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
5671 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5672 sas_address
= le64_to_cpu(event_data
->SASAddress
);
5673 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
5675 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5677 if (!sas_device
|| !sas_device
->starget
)
5680 target_priv_data
= sas_device
->starget
->hostdata
;
5681 if (!target_priv_data
)
5684 if (event_data
->ReasonCode
==
5685 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
5686 target_priv_data
->tm_busy
= 1;
5688 target_priv_data
->tm_busy
= 0;
5691 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5693 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5694 * @ioc: per adapter object
5695 * @event_data: event data payload
5701 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
5702 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
5704 char *reason_str
= NULL
;
5706 switch (event_data
->ReasonCode
) {
5707 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
5708 reason_str
= "enclosure add";
5710 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
5711 reason_str
= "enclosure remove";
5714 reason_str
= "unknown reason";
5718 printk(MPT2SAS_INFO_FMT
"enclosure status change: (%s)\n"
5719 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5720 " number slots(%d)\n", ioc
->name
, reason_str
,
5721 le16_to_cpu(event_data
->EnclosureHandle
),
5722 (unsigned long long)le64_to_cpu(event_data
->EnclosureLogicalID
),
5723 le16_to_cpu(event_data
->StartSlot
));
5728 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5729 * @ioc: per adapter object
5730 * @fw_event: The fw_event_work object
5736 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER
*ioc
,
5737 struct fw_event_work
*fw_event
)
5739 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5740 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
5741 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
5742 fw_event
->event_data
);
5747 * _scsih_sas_broadcast_primative_event - handle broadcast events
5748 * @ioc: per adapter object
5749 * @fw_event: The fw_event_work object
5755 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER
*ioc
,
5756 struct fw_event_work
*fw_event
)
5758 struct scsi_cmnd
*scmd
;
5759 struct scsi_device
*sdev
;
5762 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
5763 u32 termination_count
;
5765 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
5766 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
= fw_event
->event_data
;
5768 unsigned long flags
;
5771 u8 task_abort_retries
;
5773 mutex_lock(&ioc
->tm_cmds
.mutex
);
5774 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter: phy number(%d), "
5775 "width(%d)\n", ioc
->name
, __func__
, event_data
->PhyNum
,
5776 event_data
->PortWidth
));
5778 _scsih_block_io_all_device(ioc
);
5780 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5781 mpi_reply
= ioc
->tm_cmds
.reply
;
5782 broadcast_aen_retry
:
5784 /* sanity checks for retrying this loop */
5785 if (max_retries
++ == 5) {
5786 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: giving up\n",
5787 ioc
->name
, __func__
));
5789 } else if (max_retries
> 1)
5790 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %d retry\n",
5791 ioc
->name
, __func__
, max_retries
- 1));
5793 termination_count
= 0;
5795 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
5796 if (ioc
->shost_recovery
)
5798 scmd
= _scsih_scsi_lookup_get(ioc
, smid
);
5801 sdev
= scmd
->device
;
5802 sas_device_priv_data
= sdev
->hostdata
;
5803 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
5805 /* skip hidden raid components */
5806 if (sas_device_priv_data
->sas_target
->flags
&
5807 MPT_TARGET_FLAGS_RAID_COMPONENT
)
5810 if (sas_device_priv_data
->sas_target
->flags
&
5811 MPT_TARGET_FLAGS_VOLUME
)
5814 handle
= sas_device_priv_data
->sas_target
->handle
;
5815 lun
= sas_device_priv_data
->lun
;
5818 if (ioc
->shost_recovery
)
5821 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5822 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, 0, 0, lun
,
5823 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, smid
, 30, 0,
5826 sdev_printk(KERN_WARNING
, sdev
,
5827 "mpt2sas_scsih_issue_tm: FAILED when sending "
5828 "QUERY_TASK: scmd(%p)\n", scmd
);
5829 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5830 goto broadcast_aen_retry
;
5832 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
5833 & MPI2_IOCSTATUS_MASK
;
5834 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5835 sdev_printk(KERN_WARNING
, sdev
, "query task: FAILED "
5836 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status
,
5838 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5839 goto broadcast_aen_retry
;
5842 /* see if IO is still owned by IOC and target */
5843 if (mpi_reply
->ResponseCode
==
5844 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
5845 mpi_reply
->ResponseCode
==
5846 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
5847 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5850 task_abort_retries
= 0;
5852 if (task_abort_retries
++ == 60) {
5853 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5854 "%s: ABORT_TASK: giving up\n", ioc
->name
,
5856 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5857 goto broadcast_aen_retry
;
5860 if (ioc
->shost_recovery
)
5863 r
= mpt2sas_scsih_issue_tm(ioc
, handle
, sdev
->channel
, sdev
->id
,
5864 sdev
->lun
, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, smid
, 30,
5865 scmd
->serial_number
, TM_MUTEX_OFF
);
5867 sdev_printk(KERN_WARNING
, sdev
,
5868 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
5869 "scmd(%p)\n", scmd
);
5873 if (task_abort_retries
> 1)
5874 sdev_printk(KERN_WARNING
, sdev
,
5875 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5877 task_abort_retries
- 1, scmd
);
5879 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
5880 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5883 if (ioc
->broadcast_aen_pending
) {
5884 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: loop back due to"
5885 " pending AEN\n", ioc
->name
, __func__
));
5886 ioc
->broadcast_aen_pending
= 0;
5887 goto broadcast_aen_retry
;
5891 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5894 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
5895 "%s - exit, query_count = %d termination_count = %d\n",
5896 ioc
->name
, __func__
, query_count
, termination_count
));
5898 ioc
->broadcast_aen_busy
= 0;
5899 if (!ioc
->shost_recovery
)
5900 _scsih_ublock_io_all_device(ioc
);
5901 mutex_unlock(&ioc
->tm_cmds
.mutex
);
5905 * _scsih_sas_discovery_event - handle discovery events
5906 * @ioc: per adapter object
5907 * @fw_event: The fw_event_work object
5913 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER
*ioc
,
5914 struct fw_event_work
*fw_event
)
5916 Mpi2EventDataSasDiscovery_t
*event_data
= fw_event
->event_data
;
5918 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5919 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
5920 printk(MPT2SAS_INFO_FMT
"discovery event: (%s)", ioc
->name
,
5921 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
5923 if (event_data
->DiscoveryStatus
)
5924 printk("discovery_status(0x%08x)",
5925 le32_to_cpu(event_data
->DiscoveryStatus
));
5930 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
5931 !ioc
->sas_hba
.num_phys
)
5932 _scsih_sas_host_add(ioc
);
5936 * _scsih_reprobe_lun - reprobing lun
5937 * @sdev: scsi device struct
5938 * @no_uld_attach: sdev->no_uld_attach flag setting
5942 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
5946 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
5947 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
5948 sdev
->no_uld_attach
? "hidding" : "exposing");
5949 rc
= scsi_device_reprobe(sdev
);
5953 * _scsih_reprobe_target - reprobing target
5954 * @starget: scsi target struct
5955 * @no_uld_attach: sdev->no_uld_attach flag setting
5957 * Note: no_uld_attach flag determines whether the disk device is attached
5958 * to block layer. A value of `1` means to not attach.
5961 _scsih_reprobe_target(struct scsi_target
*starget
, int no_uld_attach
)
5963 struct MPT2SAS_TARGET
*sas_target_priv_data
;
5965 if (starget
== NULL
)
5967 sas_target_priv_data
= starget
->hostdata
;
5969 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_RAID_COMPONENT
;
5971 sas_target_priv_data
->flags
&= ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
5973 starget_for_each_device(starget
, no_uld_attach
? (void *)1 : NULL
,
5974 _scsih_reprobe_lun
);
5977 * _scsih_sas_volume_add - add new volume
5978 * @ioc: per adapter object
5979 * @element: IR config element data
5985 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER
*ioc
,
5986 Mpi2EventIrConfigElement_t
*element
)
5988 struct _raid_device
*raid_device
;
5989 unsigned long flags
;
5991 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
5994 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
5996 printk(MPT2SAS_ERR_FMT
5997 "failure at %s:%d/%s()!\n", ioc
->name
,
5998 __FILE__
, __LINE__
, __func__
);
6002 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6003 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
6004 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6009 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6011 printk(MPT2SAS_ERR_FMT
6012 "failure at %s:%d/%s()!\n", ioc
->name
,
6013 __FILE__
, __LINE__
, __func__
);
6017 raid_device
->id
= ioc
->sas_id
++;
6018 raid_device
->channel
= RAID_CHANNEL
;
6019 raid_device
->handle
= handle
;
6020 raid_device
->wwid
= wwid
;
6021 _scsih_raid_device_add(ioc
, raid_device
);
6022 if (!ioc
->wait_for_discovery_to_complete
) {
6023 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6024 raid_device
->id
, 0);
6026 _scsih_raid_device_remove(ioc
, raid_device
);
6028 _scsih_determine_boot_device(ioc
, raid_device
, 1);
6032 * _scsih_sas_volume_delete - delete volume
6033 * @ioc: per adapter object
6034 * @handle: volume device handle
6040 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
6042 struct _raid_device
*raid_device
;
6043 unsigned long flags
;
6044 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6046 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6047 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6048 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6051 if (raid_device
->starget
) {
6052 sas_target_priv_data
= raid_device
->starget
->hostdata
;
6053 sas_target_priv_data
->deleted
= 1;
6054 scsi_remove_target(&raid_device
->starget
->dev
);
6056 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
6057 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
6058 (unsigned long long) raid_device
->wwid
);
6059 _scsih_raid_device_remove(ioc
, raid_device
);
6063 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6064 * @ioc: per adapter object
6065 * @element: IR config element data
6071 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER
*ioc
,
6072 Mpi2EventIrConfigElement_t
*element
)
6074 struct _sas_device
*sas_device
;
6075 unsigned long flags
;
6076 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6078 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6079 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6080 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6084 /* exposing raid component */
6085 sas_device
->volume_handle
= 0;
6086 sas_device
->volume_wwid
= 0;
6087 clear_bit(handle
, ioc
->pd_handles
);
6088 _scsih_reprobe_target(sas_device
->starget
, 0);
6092 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6093 * @ioc: per adapter object
6094 * @element: IR config element data
6100 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER
*ioc
,
6101 Mpi2EventIrConfigElement_t
*element
)
6103 struct _sas_device
*sas_device
;
6104 unsigned long flags
;
6105 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6107 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6108 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6109 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6113 /* hiding raid component */
6114 mpt2sas_config_get_volume_handle(ioc
, handle
,
6115 &sas_device
->volume_handle
);
6116 mpt2sas_config_get_volume_wwid(ioc
, sas_device
->volume_handle
,
6117 &sas_device
->volume_wwid
);
6118 set_bit(handle
, ioc
->pd_handles
);
6119 _scsih_reprobe_target(sas_device
->starget
, 1);
6124 * _scsih_sas_pd_delete - delete pd component
6125 * @ioc: per adapter object
6126 * @element: IR config element data
6132 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER
*ioc
,
6133 Mpi2EventIrConfigElement_t
*element
)
6135 struct _sas_device
*sas_device
;
6136 unsigned long flags
;
6137 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6139 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6140 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6141 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6144 _scsih_remove_device(ioc
, sas_device
);
6148 * _scsih_sas_pd_add - remove pd component
6149 * @ioc: per adapter object
6150 * @element: IR config element data
6156 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER
*ioc
,
6157 Mpi2EventIrConfigElement_t
*element
)
6159 struct _sas_device
*sas_device
;
6160 unsigned long flags
;
6161 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
6162 Mpi2ConfigReply_t mpi_reply
;
6163 Mpi2SasDevicePage0_t sas_device_pg0
;
6168 set_bit(handle
, ioc
->pd_handles
);
6170 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6171 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6172 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6176 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6177 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6178 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6179 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6183 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6184 MPI2_IOCSTATUS_MASK
;
6185 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6186 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6187 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6191 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6192 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6193 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6194 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6196 _scsih_add_device(ioc
, handle
, 0, 1);
6199 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6201 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6202 * @ioc: per adapter object
6203 * @event_data: event data payload
6209 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6210 Mpi2EventDataIrConfigChangeList_t
*event_data
)
6212 Mpi2EventIrConfigElement_t
*element
;
6215 char *reason_str
= NULL
, *element_str
= NULL
;
6217 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6219 printk(MPT2SAS_INFO_FMT
"raid config change: (%s), elements(%d)\n",
6220 ioc
->name
, (le32_to_cpu(event_data
->Flags
) &
6221 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ?
6222 "foreign" : "native", event_data
->NumElements
);
6223 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6224 switch (element
->ReasonCode
) {
6225 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6228 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6229 reason_str
= "remove";
6231 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
6232 reason_str
= "no change";
6234 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6235 reason_str
= "hide";
6237 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6238 reason_str
= "unhide";
6240 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6241 reason_str
= "volume_created";
6243 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6244 reason_str
= "volume_deleted";
6246 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6247 reason_str
= "pd_created";
6249 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6250 reason_str
= "pd_deleted";
6253 reason_str
= "unknown reason";
6256 element_type
= le16_to_cpu(element
->ElementFlags
) &
6257 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
6258 switch (element_type
) {
6259 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
6260 element_str
= "volume";
6262 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
6263 element_str
= "phys disk";
6265 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
6266 element_str
= "hot spare";
6269 element_str
= "unknown element";
6272 printk(KERN_INFO
"\t(%s:%s), vol handle(0x%04x), "
6273 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
6274 reason_str
, le16_to_cpu(element
->VolDevHandle
),
6275 le16_to_cpu(element
->PhysDiskDevHandle
),
6276 element
->PhysDiskNum
);
6282 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6283 * @ioc: per adapter object
6284 * @fw_event: The fw_event_work object
6290 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER
*ioc
,
6291 struct fw_event_work
*fw_event
)
6293 Mpi2EventIrConfigElement_t
*element
;
6296 Mpi2EventDataIrConfigChangeList_t
*event_data
= fw_event
->event_data
;
6298 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6299 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6300 && !ioc
->hide_ir_msg
)
6301 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
6305 if (ioc
->shost_recovery
)
6308 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
6309 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
6311 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
6312 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
6314 switch (element
->ReasonCode
) {
6315 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
6316 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
6317 if (!foreign_config
)
6318 _scsih_sas_volume_add(ioc
, element
);
6320 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
6321 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
6322 if (!foreign_config
)
6323 _scsih_sas_volume_delete(ioc
,
6324 le16_to_cpu(element
->VolDevHandle
));
6326 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
6327 if (!ioc
->is_warpdrive
)
6328 _scsih_sas_pd_hide(ioc
, element
);
6330 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
6331 if (!ioc
->is_warpdrive
)
6332 _scsih_sas_pd_expose(ioc
, element
);
6334 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
6335 if (!ioc
->is_warpdrive
)
6336 _scsih_sas_pd_add(ioc
, element
);
6338 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
6339 if (!ioc
->is_warpdrive
)
6340 _scsih_sas_pd_delete(ioc
, element
);
6347 * _scsih_sas_ir_volume_event - IR volume event
6348 * @ioc: per adapter object
6349 * @fw_event: The fw_event_work object
6355 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER
*ioc
,
6356 struct fw_event_work
*fw_event
)
6359 unsigned long flags
;
6360 struct _raid_device
*raid_device
;
6364 Mpi2EventDataIrVolume_t
*event_data
= fw_event
->event_data
;
6366 if (ioc
->shost_recovery
)
6369 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
6372 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6373 state
= le32_to_cpu(event_data
->NewValue
);
6374 if (!ioc
->hide_ir_msg
)
6375 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6376 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6377 le32_to_cpu(event_data
->PreviousValue
), state
));
6380 case MPI2_RAID_VOL_STATE_MISSING
:
6381 case MPI2_RAID_VOL_STATE_FAILED
:
6382 _scsih_sas_volume_delete(ioc
, handle
);
6385 case MPI2_RAID_VOL_STATE_ONLINE
:
6386 case MPI2_RAID_VOL_STATE_DEGRADED
:
6387 case MPI2_RAID_VOL_STATE_OPTIMAL
:
6389 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6390 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6391 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6396 mpt2sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
6398 printk(MPT2SAS_ERR_FMT
6399 "failure at %s:%d/%s()!\n", ioc
->name
,
6400 __FILE__
, __LINE__
, __func__
);
6404 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
6406 printk(MPT2SAS_ERR_FMT
6407 "failure at %s:%d/%s()!\n", ioc
->name
,
6408 __FILE__
, __LINE__
, __func__
);
6412 raid_device
->id
= ioc
->sas_id
++;
6413 raid_device
->channel
= RAID_CHANNEL
;
6414 raid_device
->handle
= handle
;
6415 raid_device
->wwid
= wwid
;
6416 _scsih_raid_device_add(ioc
, raid_device
);
6417 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
6418 raid_device
->id
, 0);
6420 _scsih_raid_device_remove(ioc
, raid_device
);
6423 case MPI2_RAID_VOL_STATE_INITIALIZING
:
6430 * _scsih_sas_ir_physical_disk_event - PD event
6431 * @ioc: per adapter object
6432 * @fw_event: The fw_event_work object
6438 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER
*ioc
,
6439 struct fw_event_work
*fw_event
)
6441 u16 handle
, parent_handle
;
6443 struct _sas_device
*sas_device
;
6444 unsigned long flags
;
6445 Mpi2ConfigReply_t mpi_reply
;
6446 Mpi2SasDevicePage0_t sas_device_pg0
;
6448 Mpi2EventDataIrPhysicalDisk_t
*event_data
= fw_event
->event_data
;
6451 if (ioc
->shost_recovery
)
6454 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
6457 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
6458 state
= le32_to_cpu(event_data
->NewValue
);
6460 if (!ioc
->hide_ir_msg
)
6461 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: handle(0x%04x), "
6462 "old(0x%08x), new(0x%08x)\n", ioc
->name
, __func__
, handle
,
6463 le32_to_cpu(event_data
->PreviousValue
), state
));
6466 case MPI2_RAID_PD_STATE_ONLINE
:
6467 case MPI2_RAID_PD_STATE_DEGRADED
:
6468 case MPI2_RAID_PD_STATE_REBUILDING
:
6469 case MPI2_RAID_PD_STATE_OPTIMAL
:
6470 case MPI2_RAID_PD_STATE_HOT_SPARE
:
6472 if (!ioc
->is_warpdrive
)
6473 set_bit(handle
, ioc
->pd_handles
);
6475 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6476 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
6477 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6482 if ((mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6483 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6485 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6486 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6490 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6491 MPI2_IOCSTATUS_MASK
;
6492 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6493 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
6494 ioc
->name
, __FILE__
, __LINE__
, __func__
);
6498 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
6499 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
6500 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
6501 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
6503 _scsih_add_device(ioc
, handle
, 0, 1);
6507 case MPI2_RAID_PD_STATE_OFFLINE
:
6508 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
6509 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
6515 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6517 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6518 * @ioc: per adapter object
6519 * @event_data: event data payload
6525 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER
*ioc
,
6526 Mpi2EventDataIrOperationStatus_t
*event_data
)
6528 char *reason_str
= NULL
;
6530 switch (event_data
->RAIDOperation
) {
6531 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
6532 reason_str
= "resync";
6534 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
6535 reason_str
= "online capacity expansion";
6537 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
6538 reason_str
= "consistency check";
6540 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
6541 reason_str
= "background init";
6543 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
6544 reason_str
= "make data consistent";
6551 printk(MPT2SAS_INFO_FMT
"raid operational status: (%s)"
6552 "\thandle(0x%04x), percent complete(%d)\n",
6553 ioc
->name
, reason_str
,
6554 le16_to_cpu(event_data
->VolDevHandle
),
6555 event_data
->PercentComplete
);
6560 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6561 * @ioc: per adapter object
6562 * @fw_event: The fw_event_work object
6568 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER
*ioc
,
6569 struct fw_event_work
*fw_event
)
6571 Mpi2EventDataIrOperationStatus_t
*event_data
= fw_event
->event_data
;
6572 static struct _raid_device
*raid_device
;
6573 unsigned long flags
;
6576 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6577 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6578 && !ioc
->hide_ir_msg
)
6579 _scsih_sas_ir_operation_status_event_debug(ioc
,
6583 /* code added for raid transport support */
6584 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
6586 handle
= le16_to_cpu(event_data
->VolDevHandle
);
6588 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6589 raid_device
= _scsih_raid_device_find_by_handle(ioc
, handle
);
6590 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6595 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
)
6596 raid_device
->percent_complete
=
6597 event_data
->PercentComplete
;
6602 * _scsih_prep_device_scan - initialize parameters prior to device scan
6603 * @ioc: per adapter object
6605 * Set the deleted flag prior to device scan. If the device is found during
6606 * the scan, then we clear the deleted flag.
6609 _scsih_prep_device_scan(struct MPT2SAS_ADAPTER
*ioc
)
6611 struct MPT2SAS_DEVICE
*sas_device_priv_data
;
6612 struct scsi_device
*sdev
;
6614 shost_for_each_device(sdev
, ioc
->shost
) {
6615 sas_device_priv_data
= sdev
->hostdata
;
6616 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
6617 sas_device_priv_data
->sas_target
->deleted
= 1;
6622 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6623 * @ioc: per adapter object
6624 * @sas_address: sas address
6625 * @slot: enclosure slot id
6626 * @handle: device handle
6628 * After host reset, find out whether devices are still responding.
6629 * Used in _scsi_remove_unresponsive_sas_devices.
6634 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6635 u16 slot
, u16 handle
)
6637 struct MPT2SAS_TARGET
*sas_target_priv_data
= NULL
;
6638 struct scsi_target
*starget
;
6639 struct _sas_device
*sas_device
;
6640 unsigned long flags
;
6642 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6643 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
6644 if (sas_device
->sas_address
== sas_address
&&
6645 sas_device
->slot
== slot
) {
6646 sas_device
->responding
= 1;
6647 starget
= sas_device
->starget
;
6648 if (starget
&& starget
->hostdata
) {
6649 sas_target_priv_data
= starget
->hostdata
;
6650 sas_target_priv_data
->tm_busy
= 0;
6651 sas_target_priv_data
->deleted
= 0;
6653 sas_target_priv_data
= NULL
;
6655 starget_printk(KERN_INFO
, starget
,
6656 "handle(0x%04x), sas_addr(0x%016llx), "
6657 "enclosure logical id(0x%016llx), "
6658 "slot(%d)\n", handle
,
6659 (unsigned long long)sas_device
->sas_address
,
6660 (unsigned long long)
6661 sas_device
->enclosure_logical_id
,
6663 if (sas_device
->handle
== handle
)
6665 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6666 sas_device
->handle
);
6667 sas_device
->handle
= handle
;
6668 if (sas_target_priv_data
)
6669 sas_target_priv_data
->handle
= handle
;
6674 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6678 * _scsih_search_responding_sas_devices -
6679 * @ioc: per adapter object
6681 * After host reset, find out whether devices are still responding.
6687 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6689 Mpi2SasDevicePage0_t sas_device_pg0
;
6690 Mpi2ConfigReply_t mpi_reply
;
6697 printk(MPT2SAS_INFO_FMT
"search for end-devices: start\n", ioc
->name
);
6699 if (list_empty(&ioc
->sas_device_list
))
6703 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
6704 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
6706 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6707 MPI2_IOCSTATUS_MASK
;
6708 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6710 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
6711 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6712 if (!(_scsih_is_end_device(device_info
)))
6714 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6715 slot
= le16_to_cpu(sas_device_pg0
.Slot
);
6716 _scsih_mark_responding_sas_device(ioc
, sas_address
, slot
,
6720 printk(MPT2SAS_INFO_FMT
"search for end-devices: complete\n",
6725 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6726 * @ioc: per adapter object
6727 * @wwid: world wide identifier for raid volume
6728 * @handle: device handle
6730 * After host reset, find out whether devices are still responding.
6731 * Used in _scsi_remove_unresponsive_raid_devices.
6736 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER
*ioc
, u64 wwid
,
6739 struct MPT2SAS_TARGET
*sas_target_priv_data
;
6740 struct scsi_target
*starget
;
6741 struct _raid_device
*raid_device
;
6742 unsigned long flags
;
6744 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
6745 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
6746 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
6747 starget
= raid_device
->starget
;
6748 if (starget
&& starget
->hostdata
) {
6749 sas_target_priv_data
= starget
->hostdata
;
6750 sas_target_priv_data
->deleted
= 0;
6752 sas_target_priv_data
= NULL
;
6753 raid_device
->responding
= 1;
6754 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6755 starget_printk(KERN_INFO
, raid_device
->starget
,
6756 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
6757 (unsigned long long)raid_device
->wwid
);
6759 * WARPDRIVE: The handles of the PDs might have changed
6760 * across the host reset so re-initialize the
6761 * required data for Direct IO
6763 _scsih_init_warpdrive_properties(ioc
, raid_device
);
6764 if (raid_device
->handle
== handle
)
6766 printk(KERN_INFO
"\thandle changed from(0x%04x)!!!\n",
6767 raid_device
->handle
);
6768 raid_device
->handle
= handle
;
6769 if (sas_target_priv_data
)
6770 sas_target_priv_data
->handle
= handle
;
6775 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
6779 * _scsih_search_responding_raid_devices -
6780 * @ioc: per adapter object
6782 * After host reset, find out whether devices are still responding.
6788 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER
*ioc
)
6790 Mpi2RaidVolPage1_t volume_pg1
;
6791 Mpi2RaidVolPage0_t volume_pg0
;
6792 Mpi2RaidPhysDiskPage0_t pd_pg0
;
6793 Mpi2ConfigReply_t mpi_reply
;
6798 if (!ioc
->ir_firmware
)
6801 printk(MPT2SAS_INFO_FMT
"search for raid volumes: start\n",
6804 if (list_empty(&ioc
->raid_device_list
))
6808 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
6809 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
6810 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6811 MPI2_IOCSTATUS_MASK
;
6812 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6814 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
6816 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
6817 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
6818 sizeof(Mpi2RaidVolPage0_t
)))
6821 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
6822 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
6823 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
6824 _scsih_mark_responding_raid_device(ioc
,
6825 le64_to_cpu(volume_pg1
.WWID
), handle
);
6828 /* refresh the pd_handles */
6829 if (!ioc
->is_warpdrive
) {
6830 phys_disk_num
= 0xFF;
6831 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
6832 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
6833 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
6835 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6836 MPI2_IOCSTATUS_MASK
;
6837 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6839 phys_disk_num
= pd_pg0
.PhysDiskNum
;
6840 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
6841 set_bit(handle
, ioc
->pd_handles
);
6845 printk(MPT2SAS_INFO_FMT
"search for responding raid volumes: "
6846 "complete\n", ioc
->name
);
6850 * _scsih_mark_responding_expander - mark a expander as responding
6851 * @ioc: per adapter object
6852 * @sas_address: sas address
6855 * After host reset, find out whether devices are still responding.
6856 * Used in _scsi_remove_unresponsive_expanders.
6861 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER
*ioc
, u64 sas_address
,
6864 struct _sas_node
*sas_expander
;
6865 unsigned long flags
;
6868 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6869 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6870 if (sas_expander
->sas_address
!= sas_address
)
6872 sas_expander
->responding
= 1;
6873 if (sas_expander
->handle
== handle
)
6875 printk(KERN_INFO
"\texpander(0x%016llx): handle changed"
6876 " from(0x%04x) to (0x%04x)!!!\n",
6877 (unsigned long long)sas_expander
->sas_address
,
6878 sas_expander
->handle
, handle
);
6879 sas_expander
->handle
= handle
;
6880 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
6881 sas_expander
->phy
[i
].handle
= handle
;
6885 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6889 * _scsih_search_responding_expanders -
6890 * @ioc: per adapter object
6892 * After host reset, find out whether devices are still responding.
6898 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER
*ioc
)
6900 Mpi2ExpanderPage0_t expander_pg0
;
6901 Mpi2ConfigReply_t mpi_reply
;
6906 printk(MPT2SAS_INFO_FMT
"search for expanders: start\n", ioc
->name
);
6908 if (list_empty(&ioc
->sas_expander_list
))
6912 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
6913 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
6915 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6916 MPI2_IOCSTATUS_MASK
;
6917 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
6920 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
6921 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
6922 printk(KERN_INFO
"\texpander present: handle(0x%04x), "
6923 "sas_addr(0x%016llx)\n", handle
,
6924 (unsigned long long)sas_address
);
6925 _scsih_mark_responding_expander(ioc
, sas_address
, handle
);
6929 printk(MPT2SAS_INFO_FMT
"search for expanders: complete\n", ioc
->name
);
6933 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
6934 * @ioc: per adapter object
6939 _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER
*ioc
)
6941 struct _sas_device
*sas_device
, *sas_device_next
;
6942 struct _sas_node
*sas_expander
;
6943 struct _raid_device
*raid_device
, *raid_device_next
;
6945 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: start\n",
6948 list_for_each_entry_safe(sas_device
, sas_device_next
,
6949 &ioc
->sas_device_list
, list
) {
6950 if (sas_device
->responding
) {
6951 sas_device
->responding
= 0;
6954 if (sas_device
->starget
)
6955 starget_printk(KERN_INFO
, sas_device
->starget
,
6956 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6957 "enclosure logical id(0x%016llx), slot(%d)\n",
6959 (unsigned long long)sas_device
->sas_address
,
6960 (unsigned long long)
6961 sas_device
->enclosure_logical_id
,
6963 _scsih_remove_device(ioc
, sas_device
);
6966 if (!ioc
->ir_firmware
)
6967 goto retry_expander_search
;
6969 list_for_each_entry_safe(raid_device
, raid_device_next
,
6970 &ioc
->raid_device_list
, list
) {
6971 if (raid_device
->responding
) {
6972 raid_device
->responding
= 0;
6975 if (raid_device
->starget
) {
6976 starget_printk(KERN_INFO
, raid_device
->starget
,
6977 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6978 raid_device
->handle
,
6979 (unsigned long long)raid_device
->wwid
);
6980 scsi_remove_target(&raid_device
->starget
->dev
);
6982 _scsih_raid_device_remove(ioc
, raid_device
);
6985 retry_expander_search
:
6986 sas_expander
= NULL
;
6987 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
6988 if (sas_expander
->responding
) {
6989 sas_expander
->responding
= 0;
6992 mpt2sas_expander_remove(ioc
, sas_expander
->sas_address
);
6993 goto retry_expander_search
;
6995 printk(MPT2SAS_INFO_FMT
"removing unresponding devices: complete\n",
6997 /* unblock devices */
6998 _scsih_ublock_io_all_device(ioc
);
7002 _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER
*ioc
,
7003 struct _sas_node
*sas_expander
, u16 handle
)
7005 Mpi2ExpanderPage1_t expander_pg1
;
7006 Mpi2ConfigReply_t mpi_reply
;
7009 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
7010 if ((mpt2sas_config_get_expander_pg1(ioc
, &mpi_reply
,
7011 &expander_pg1
, i
, handle
))) {
7012 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7013 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7017 mpt2sas_transport_update_links(ioc
, sas_expander
->sas_address
,
7018 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
7019 expander_pg1
.NegotiatedLinkRate
>> 4);
7024 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
7025 * @ioc: per adapter object
7030 _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER
*ioc
)
7032 Mpi2ExpanderPage0_t expander_pg0
;
7033 Mpi2SasDevicePage0_t sas_device_pg0
;
7034 Mpi2RaidVolPage1_t volume_pg1
;
7035 Mpi2RaidVolPage0_t volume_pg0
;
7036 Mpi2RaidPhysDiskPage0_t pd_pg0
;
7037 Mpi2EventIrConfigElement_t element
;
7038 Mpi2ConfigReply_t mpi_reply
;
7041 u16 handle
, parent_handle
;
7043 struct _sas_device
*sas_device
;
7044 struct _sas_node
*expander_device
;
7045 static struct _raid_device
*raid_device
;
7047 printk(MPT2SAS_INFO_FMT
"scan devices: start\n", ioc
->name
);
7049 _scsih_sas_host_refresh(ioc
);
7053 while (!(mpt2sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
7054 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
7055 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7056 MPI2_IOCSTATUS_MASK
;
7057 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7059 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
7060 expander_device
= mpt2sas_scsih_expander_find_by_sas_address(
7061 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
7062 if (expander_device
)
7063 _scsih_refresh_expander_links(ioc
, expander_device
,
7066 _scsih_expander_add(ioc
, handle
);
7069 if (!ioc
->ir_firmware
)
7073 phys_disk_num
= 0xFF;
7074 while (!(mpt2sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
7075 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
7077 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7078 MPI2_IOCSTATUS_MASK
;
7079 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7081 phys_disk_num
= pd_pg0
.PhysDiskNum
;
7082 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
7083 sas_device
= _scsih_sas_device_find_by_handle(ioc
, handle
);
7086 if (mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7087 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
7090 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7091 if (!_scsih_get_sas_address(ioc
, parent_handle
,
7093 mpt2sas_transport_update_links(ioc
, sas_address
,
7094 handle
, sas_device_pg0
.PhyNum
,
7095 MPI2_SAS_NEG_LINK_RATE_1_5
);
7096 set_bit(handle
, ioc
->pd_handles
);
7097 _scsih_add_device(ioc
, handle
, 0, 1);
7103 while (!(mpt2sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
7104 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
7105 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7106 MPI2_IOCSTATUS_MASK
;
7107 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7109 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
7110 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
7111 le64_to_cpu(volume_pg1
.WWID
));
7114 if (mpt2sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
7115 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
7116 sizeof(Mpi2RaidVolPage0_t
)))
7118 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
7119 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
7120 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
7121 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
7122 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
7123 element
.VolDevHandle
= volume_pg1
.DevHandle
;
7124 _scsih_sas_volume_add(ioc
, &element
);
7132 while (!(mpt2sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
7133 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
7135 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7136 MPI2_IOCSTATUS_MASK
;
7137 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
7139 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
7140 if (!(_scsih_is_end_device(
7141 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
7143 sas_device
= mpt2sas_scsih_sas_device_find_by_sas_address(ioc
,
7144 le64_to_cpu(sas_device_pg0
.SASAddress
));
7147 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7148 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
7149 mpt2sas_transport_update_links(ioc
, sas_address
, handle
,
7150 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7151 _scsih_add_device(ioc
, handle
, 0, 0);
7155 printk(MPT2SAS_INFO_FMT
"scan devices: complete\n", ioc
->name
);
7160 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7161 * @ioc: per adapter object
7162 * @reset_phase: phase
7164 * The handler for doing any required cleanup or initialization.
7166 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7167 * MPT2_IOC_DONE_RESET
7172 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
7174 switch (reset_phase
) {
7175 case MPT2_IOC_PRE_RESET
:
7176 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7177 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
7179 case MPT2_IOC_AFTER_RESET
:
7180 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7181 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
7182 if (ioc
->scsih_cmds
.status
& MPT2_CMD_PENDING
) {
7183 ioc
->scsih_cmds
.status
|= MPT2_CMD_RESET
;
7184 mpt2sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
7185 complete(&ioc
->scsih_cmds
.done
);
7187 if (ioc
->tm_cmds
.status
& MPT2_CMD_PENDING
) {
7188 ioc
->tm_cmds
.status
|= MPT2_CMD_RESET
;
7189 mpt2sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
7190 complete(&ioc
->tm_cmds
.done
);
7192 _scsih_fw_event_cleanup_queue(ioc
);
7193 _scsih_flush_running_cmds(ioc
);
7195 case MPT2_IOC_DONE_RESET
:
7196 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
7197 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
7198 _scsih_sas_host_refresh(ioc
);
7199 _scsih_prep_device_scan(ioc
);
7200 _scsih_search_responding_sas_devices(ioc
);
7201 _scsih_search_responding_raid_devices(ioc
);
7202 _scsih_search_responding_expanders(ioc
);
7203 if (!ioc
->is_driver_loading
) {
7204 _scsih_prep_device_scan(ioc
);
7205 _scsih_search_responding_sas_devices(ioc
);
7206 _scsih_search_responding_raid_devices(ioc
);
7207 _scsih_search_responding_expanders(ioc
);
7208 _scsih_error_recovery_delete_devices(ioc
);
7215 * _firmware_event_work - delayed task for processing firmware events
7216 * @ioc: per adapter object
7217 * @work: equal to the fw_event_work object
7223 _firmware_event_work(struct work_struct
*work
)
7225 struct fw_event_work
*fw_event
= container_of(work
,
7226 struct fw_event_work
, delayed_work
.work
);
7227 struct MPT2SAS_ADAPTER
*ioc
= fw_event
->ioc
;
7229 /* the queue is being flushed so ignore this event */
7230 if (ioc
->remove_host
|| fw_event
->cancel_pending_work
||
7231 ioc
->pci_error_recovery
) {
7232 _scsih_fw_event_free(ioc
, fw_event
);
7236 switch (fw_event
->event
) {
7237 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES
:
7238 while (scsi_host_in_recovery(ioc
->shost
))
7240 _scsih_remove_unresponding_sas_devices(ioc
);
7241 _scsih_scan_for_devices_after_reset(ioc
);
7243 case MPT2SAS_PORT_ENABLE_COMPLETE
:
7244 ioc
->start_scan
= 0;
7248 dewtprintk(ioc
, printk(MPT2SAS_INFO_FMT
"port enable: complete "
7249 "from worker thread\n", ioc
->name
));
7251 case MPT2SAS_TURN_ON_FAULT_LED
:
7252 _scsih_turn_on_fault_led(ioc
, fw_event
->device_handle
);
7254 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7255 _scsih_sas_topology_change_event(ioc
, fw_event
);
7257 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7258 _scsih_sas_device_status_change_event(ioc
,
7261 case MPI2_EVENT_SAS_DISCOVERY
:
7262 _scsih_sas_discovery_event(ioc
,
7265 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7266 _scsih_sas_broadcast_primative_event(ioc
,
7269 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7270 _scsih_sas_enclosure_dev_status_change_event(ioc
,
7273 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7274 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
7276 case MPI2_EVENT_IR_VOLUME
:
7277 _scsih_sas_ir_volume_event(ioc
, fw_event
);
7279 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7280 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
7282 case MPI2_EVENT_IR_OPERATION_STATUS
:
7283 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
7286 _scsih_fw_event_free(ioc
, fw_event
);
7290 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7291 * @ioc: per adapter object
7292 * @msix_index: MSIX table index supplied by the OS
7293 * @reply: reply message frame(lower 32bit addr)
7294 * Context: interrupt.
7296 * This function merely adds a new work task into ioc->firmware_event_thread.
7297 * The tasks are worked from _firmware_event_work in user context.
7299 * Return 1 meaning mf should be freed from _base_interrupt
7300 * 0 means the mf is freed from this function.
7303 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
7306 struct fw_event_work
*fw_event
;
7307 Mpi2EventNotificationReply_t
*mpi_reply
;
7311 /* events turned off due to host reset or driver unloading */
7312 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7315 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
7316 event
= le16_to_cpu(mpi_reply
->Event
);
7320 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
7322 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
7323 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7324 mpi_reply
->EventData
;
7326 if (baen_data
->Primitive
!=
7327 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
7330 if (ioc
->broadcast_aen_busy
) {
7331 ioc
->broadcast_aen_pending
++;
7334 ioc
->broadcast_aen_busy
= 1;
7338 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
7339 _scsih_check_topo_delete_events(ioc
,
7340 (Mpi2EventDataSasTopologyChangeList_t
*)
7341 mpi_reply
->EventData
);
7343 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
7344 _scsih_check_ir_config_unhide_events(ioc
,
7345 (Mpi2EventDataIrConfigChangeList_t
*)
7346 mpi_reply
->EventData
);
7348 case MPI2_EVENT_IR_VOLUME
:
7349 _scsih_check_volume_delete_events(ioc
,
7350 (Mpi2EventDataIrVolume_t
*)
7351 mpi_reply
->EventData
);
7353 case MPI2_EVENT_LOG_ENTRY_ADDED
:
7355 Mpi2EventDataLogEntryAdded_t
*log_entry
;
7358 if (!ioc
->is_warpdrive
)
7361 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
7362 mpi_reply
->EventData
;
7363 log_code
= (u32
*)log_entry
->LogData
;
7365 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
7366 != MPT2_WARPDRIVE_LOGENTRY
)
7369 switch (le32_to_cpu(*log_code
)) {
7370 case MPT2_WARPDRIVE_LC_SSDT
:
7371 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7372 "IO Throttling has occurred in the WarpDrive "
7373 "subsystem. Check WarpDrive documentation for "
7374 "additional details.\n", ioc
->name
);
7376 case MPT2_WARPDRIVE_LC_SSDLW
:
7377 printk(MPT2SAS_WARN_FMT
"WarpDrive Warning: "
7378 "Program/Erase Cycles for the WarpDrive subsystem "
7379 "in degraded range. Check WarpDrive documentation "
7380 "for additional details.\n", ioc
->name
);
7382 case MPT2_WARPDRIVE_LC_SSDLF
:
7383 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7384 "There are no Program/Erase Cycles for the "
7385 "WarpDrive subsystem. The storage device will be "
7386 "in read-only mode. Check WarpDrive documentation "
7387 "for additional details.\n", ioc
->name
);
7389 case MPT2_WARPDRIVE_LC_BRMF
:
7390 printk(MPT2SAS_ERR_FMT
"WarpDrive Fatal Error: "
7391 "The Backup Rail Monitor has failed on the "
7392 "WarpDrive subsystem. Check WarpDrive "
7393 "documentation for additional details.\n",
7400 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7401 case MPI2_EVENT_IR_OPERATION_STATUS
:
7402 case MPI2_EVENT_SAS_DISCOVERY
:
7403 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
7404 case MPI2_EVENT_IR_PHYSICAL_DISK
:
7407 default: /* ignore the rest */
7411 fw_event
= kzalloc(sizeof(struct fw_event_work
), GFP_ATOMIC
);
7413 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7414 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7417 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
7418 fw_event
->event_data
= kzalloc(sz
, GFP_ATOMIC
);
7419 if (!fw_event
->event_data
) {
7420 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
7421 ioc
->name
, __FILE__
, __LINE__
, __func__
);
7426 memcpy(fw_event
->event_data
, mpi_reply
->EventData
,
7428 fw_event
->ioc
= ioc
;
7429 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
7430 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
7431 fw_event
->event
= event
;
7432 _scsih_fw_event_add(ioc
, fw_event
);
7436 /* shost template */
7437 static struct scsi_host_template scsih_driver_template
= {
7438 .module
= THIS_MODULE
,
7439 .name
= "Fusion MPT SAS Host",
7440 .proc_name
= MPT2SAS_DRIVER_NAME
,
7441 .queuecommand
= _scsih_qcmd
,
7442 .target_alloc
= _scsih_target_alloc
,
7443 .slave_alloc
= _scsih_slave_alloc
,
7444 .slave_configure
= _scsih_slave_configure
,
7445 .target_destroy
= _scsih_target_destroy
,
7446 .slave_destroy
= _scsih_slave_destroy
,
7447 .scan_finished
= _scsih_scan_finished
,
7448 .scan_start
= _scsih_scan_start
,
7449 .change_queue_depth
= _scsih_change_queue_depth
,
7450 .change_queue_type
= _scsih_change_queue_type
,
7451 .eh_abort_handler
= _scsih_abort
,
7452 .eh_device_reset_handler
= _scsih_dev_reset
,
7453 .eh_target_reset_handler
= _scsih_target_reset
,
7454 .eh_host_reset_handler
= _scsih_host_reset
,
7455 .bios_param
= _scsih_bios_param
,
7458 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
7459 .max_sectors
= 32767,
7461 .use_clustering
= ENABLE_CLUSTERING
,
7462 .shost_attrs
= mpt2sas_host_attrs
,
7463 .sdev_attrs
= mpt2sas_dev_attrs
,
7467 * _scsih_expander_node_remove - removing expander device from list.
7468 * @ioc: per adapter object
7469 * @sas_expander: the sas_device object
7470 * Context: Calling function should acquire ioc->sas_node_lock.
7472 * Removing object and freeing associated memory from the
7473 * ioc->sas_expander_list.
7478 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER
*ioc
,
7479 struct _sas_node
*sas_expander
)
7481 struct _sas_port
*mpt2sas_port
, *next
;
7483 /* remove sibling ports attached to this expander */
7484 list_for_each_entry_safe(mpt2sas_port
, next
,
7485 &sas_expander
->sas_port_list
, port_list
) {
7486 if (ioc
->shost_recovery
)
7488 if (mpt2sas_port
->remote_identify
.device_type
==
7490 mpt2sas_device_remove(ioc
,
7491 mpt2sas_port
->remote_identify
.sas_address
);
7492 else if (mpt2sas_port
->remote_identify
.device_type
==
7493 SAS_EDGE_EXPANDER_DEVICE
||
7494 mpt2sas_port
->remote_identify
.device_type
==
7495 SAS_FANOUT_EXPANDER_DEVICE
)
7496 mpt2sas_expander_remove(ioc
,
7497 mpt2sas_port
->remote_identify
.sas_address
);
7500 mpt2sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
7501 sas_expander
->sas_address_parent
);
7503 printk(MPT2SAS_INFO_FMT
"expander_remove: handle"
7504 "(0x%04x), sas_addr(0x%016llx)\n", ioc
->name
,
7505 sas_expander
->handle
, (unsigned long long)
7506 sas_expander
->sas_address
);
7508 kfree(sas_expander
->phy
);
7509 kfree(sas_expander
);
7513 * _scsih_ir_shutdown - IR shutdown notification
7514 * @ioc: per adapter object
7516 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7517 * the host system is shutting down.
7522 _scsih_ir_shutdown(struct MPT2SAS_ADAPTER
*ioc
)
7524 Mpi2RaidActionRequest_t
*mpi_request
;
7525 Mpi2RaidActionReply_t
*mpi_reply
;
7528 /* is IR firmware build loaded ? */
7529 if (!ioc
->ir_firmware
)
7532 /* are there any volumes ? */
7533 if (list_empty(&ioc
->raid_device_list
))
7536 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7538 if (ioc
->scsih_cmds
.status
!= MPT2_CMD_NOT_USED
) {
7539 printk(MPT2SAS_ERR_FMT
"%s: scsih_cmd in use\n",
7540 ioc
->name
, __func__
);
7543 ioc
->scsih_cmds
.status
= MPT2_CMD_PENDING
;
7545 smid
= mpt2sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7547 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
7548 ioc
->name
, __func__
);
7549 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7553 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
7554 ioc
->scsih_cmds
.smid
= smid
;
7555 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7557 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7558 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
7560 if (!ioc
->hide_ir_msg
)
7561 printk(MPT2SAS_INFO_FMT
"IR shutdown (sending)\n", ioc
->name
);
7562 init_completion(&ioc
->scsih_cmds
.done
);
7563 mpt2sas_base_put_smid_default(ioc
, smid
);
7564 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7566 if (!(ioc
->scsih_cmds
.status
& MPT2_CMD_COMPLETE
)) {
7567 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
7568 ioc
->name
, __func__
);
7572 if (ioc
->scsih_cmds
.status
& MPT2_CMD_REPLY_VALID
) {
7573 mpi_reply
= ioc
->scsih_cmds
.reply
;
7575 if (!ioc
->hide_ir_msg
)
7576 printk(MPT2SAS_INFO_FMT
"IR shutdown (complete): "
7577 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7578 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
7579 le32_to_cpu(mpi_reply
->IOCLogInfo
));
7583 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
7584 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7588 * _scsih_shutdown - routine call during system shutdown
7589 * @pdev: PCI device struct
7594 _scsih_shutdown(struct pci_dev
*pdev
)
7596 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7597 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7598 struct workqueue_struct
*wq
;
7599 unsigned long flags
;
7601 ioc
->remove_host
= 1;
7602 _scsih_fw_event_cleanup_queue(ioc
);
7604 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7605 wq
= ioc
->firmware_event_thread
;
7606 ioc
->firmware_event_thread
= NULL
;
7607 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7609 destroy_workqueue(wq
);
7611 _scsih_ir_shutdown(ioc
);
7612 mpt2sas_base_detach(ioc
);
7616 * _scsih_remove - detach and remove add host
7617 * @pdev: PCI device struct
7619 * Routine called when unloading the driver.
7622 static void __devexit
7623 _scsih_remove(struct pci_dev
*pdev
)
7625 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7626 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7627 struct _sas_port
*mpt2sas_port
, *next_port
;
7628 struct _raid_device
*raid_device
, *next
;
7629 struct MPT2SAS_TARGET
*sas_target_priv_data
;
7630 struct workqueue_struct
*wq
;
7631 unsigned long flags
;
7633 ioc
->remove_host
= 1;
7634 _scsih_fw_event_cleanup_queue(ioc
);
7636 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
7637 wq
= ioc
->firmware_event_thread
;
7638 ioc
->firmware_event_thread
= NULL
;
7639 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
7641 destroy_workqueue(wq
);
7643 /* release all the volumes */
7644 _scsih_ir_shutdown(ioc
);
7645 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
7647 if (raid_device
->starget
) {
7648 sas_target_priv_data
=
7649 raid_device
->starget
->hostdata
;
7650 sas_target_priv_data
->deleted
= 1;
7651 scsi_remove_target(&raid_device
->starget
->dev
);
7653 printk(MPT2SAS_INFO_FMT
"removing handle(0x%04x), wwid"
7654 "(0x%016llx)\n", ioc
->name
, raid_device
->handle
,
7655 (unsigned long long) raid_device
->wwid
);
7656 _scsih_raid_device_remove(ioc
, raid_device
);
7659 /* free ports attached to the sas_host */
7660 list_for_each_entry_safe(mpt2sas_port
, next_port
,
7661 &ioc
->sas_hba
.sas_port_list
, port_list
) {
7662 if (mpt2sas_port
->remote_identify
.device_type
==
7664 mpt2sas_device_remove(ioc
,
7665 mpt2sas_port
->remote_identify
.sas_address
);
7666 else if (mpt2sas_port
->remote_identify
.device_type
==
7667 SAS_EDGE_EXPANDER_DEVICE
||
7668 mpt2sas_port
->remote_identify
.device_type
==
7669 SAS_FANOUT_EXPANDER_DEVICE
)
7670 mpt2sas_expander_remove(ioc
,
7671 mpt2sas_port
->remote_identify
.sas_address
);
7674 /* free phys attached to the sas_host */
7675 if (ioc
->sas_hba
.num_phys
) {
7676 kfree(ioc
->sas_hba
.phy
);
7677 ioc
->sas_hba
.phy
= NULL
;
7678 ioc
->sas_hba
.num_phys
= 0;
7681 sas_remove_host(shost
);
7682 mpt2sas_base_detach(ioc
);
7683 list_del(&ioc
->list
);
7684 scsi_remove_host(shost
);
7685 scsi_host_put(shost
);
7689 * _scsih_probe_boot_devices - reports 1st device
7690 * @ioc: per adapter object
7692 * If specified in bios page 2, this routine reports the 1st
7693 * device scsi-ml or sas transport for persistent boot device
7694 * purposes. Please refer to function _scsih_determine_boot_device()
7697 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER
*ioc
)
7701 struct _sas_device
*sas_device
;
7702 struct _raid_device
*raid_device
;
7704 u64 sas_address_parent
;
7706 unsigned long flags
;
7709 /* no Bios, return immediately */
7710 if (!ioc
->bios_pg3
.BiosVersion
)
7715 if (ioc
->req_boot_device
.device
) {
7716 device
= ioc
->req_boot_device
.device
;
7717 is_raid
= ioc
->req_boot_device
.is_raid
;
7718 } else if (ioc
->req_alt_boot_device
.device
) {
7719 device
= ioc
->req_alt_boot_device
.device
;
7720 is_raid
= ioc
->req_alt_boot_device
.is_raid
;
7721 } else if (ioc
->current_boot_device
.device
) {
7722 device
= ioc
->current_boot_device
.device
;
7723 is_raid
= ioc
->current_boot_device
.is_raid
;
7730 raid_device
= device
;
7731 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7732 raid_device
->id
, 0);
7734 _scsih_raid_device_remove(ioc
, raid_device
);
7736 sas_device
= device
;
7737 handle
= sas_device
->handle
;
7738 sas_address_parent
= sas_device
->sas_address_parent
;
7739 sas_address
= sas_device
->sas_address
;
7740 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7741 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7742 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7744 if (ioc
->hide_drives
)
7746 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7747 sas_device
->sas_address_parent
)) {
7748 _scsih_sas_device_remove(ioc
, sas_device
);
7749 } else if (!sas_device
->starget
) {
7750 if (!ioc
->is_driver_loading
)
7751 mpt2sas_transport_port_remove(ioc
, sas_address
,
7752 sas_address_parent
);
7753 _scsih_sas_device_remove(ioc
, sas_device
);
7759 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7760 * @ioc: per adapter object
7762 * Called during initial loading of the driver.
7765 _scsih_probe_raid(struct MPT2SAS_ADAPTER
*ioc
)
7767 struct _raid_device
*raid_device
, *raid_next
;
7770 list_for_each_entry_safe(raid_device
, raid_next
,
7771 &ioc
->raid_device_list
, list
) {
7772 if (raid_device
->starget
)
7774 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7775 raid_device
->id
, 0);
7777 _scsih_raid_device_remove(ioc
, raid_device
);
7782 * _scsih_probe_sas - reporting sas devices to sas transport
7783 * @ioc: per adapter object
7785 * Called during initial loading of the driver.
7788 _scsih_probe_sas(struct MPT2SAS_ADAPTER
*ioc
)
7790 struct _sas_device
*sas_device
, *next
;
7791 unsigned long flags
;
7793 /* SAS Device List */
7794 list_for_each_entry_safe(sas_device
, next
, &ioc
->sas_device_init_list
,
7797 if (ioc
->hide_drives
)
7800 if (!mpt2sas_transport_port_add(ioc
, sas_device
->handle
,
7801 sas_device
->sas_address_parent
)) {
7802 list_del(&sas_device
->list
);
7805 } else if (!sas_device
->starget
) {
7806 if (!ioc
->is_driver_loading
)
7807 mpt2sas_transport_port_remove(ioc
,
7808 sas_device
->sas_address
,
7809 sas_device
->sas_address_parent
);
7810 list_del(&sas_device
->list
);
7815 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7816 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
7817 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7822 * _scsih_probe_devices - probing for devices
7823 * @ioc: per adapter object
7825 * Called during initial loading of the driver.
7828 _scsih_probe_devices(struct MPT2SAS_ADAPTER
*ioc
)
7830 u16 volume_mapping_flags
;
7832 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
7833 return; /* return when IOC doesn't support initiator mode */
7835 _scsih_probe_boot_devices(ioc
);
7837 if (ioc
->ir_firmware
) {
7838 volume_mapping_flags
=
7839 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
7840 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
7841 if (volume_mapping_flags
==
7842 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
7843 _scsih_probe_raid(ioc
);
7844 _scsih_probe_sas(ioc
);
7846 _scsih_probe_sas(ioc
);
7847 _scsih_probe_raid(ioc
);
7850 _scsih_probe_sas(ioc
);
7855 * _scsih_scan_start - scsi lld callback for .scan_start
7856 * @shost: SCSI host pointer
7858 * The shost has the ability to discover targets on its own instead
7859 * of scanning the entire bus. In our implemention, we will kick off
7860 * firmware discovery.
7863 _scsih_scan_start(struct Scsi_Host
*shost
)
7865 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7868 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
7869 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
7871 ioc
->start_scan
= 1;
7872 rc
= mpt2sas_port_enable(ioc
);
7875 printk(MPT2SAS_INFO_FMT
"port enable: FAILED\n", ioc
->name
);
7879 * _scsih_scan_finished - scsi lld callback for .scan_finished
7880 * @shost: SCSI host pointer
7881 * @time: elapsed time of the scan in jiffies
7883 * This function will be called periodically until it returns 1 with the
7884 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7885 * we wait for firmware discovery to complete, then return 1.
7888 _scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
7890 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
7892 if (time
>= (300 * HZ
)) {
7893 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
7894 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with timeout "
7895 "(timeout=300s)\n", ioc
->name
);
7896 ioc
->is_driver_loading
= 0;
7900 if (ioc
->start_scan
)
7903 if (ioc
->start_scan_failed
) {
7904 printk(MPT2SAS_INFO_FMT
"port enable: FAILED with "
7905 "(ioc_status=0x%08x)\n", ioc
->name
, ioc
->start_scan_failed
);
7906 ioc
->is_driver_loading
= 0;
7907 ioc
->wait_for_discovery_to_complete
= 0;
7908 ioc
->remove_host
= 1;
7912 printk(MPT2SAS_INFO_FMT
"port enable: SUCCESS\n", ioc
->name
);
7913 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
7915 if (ioc
->wait_for_discovery_to_complete
) {
7916 ioc
->wait_for_discovery_to_complete
= 0;
7917 _scsih_probe_devices(ioc
);
7919 mpt2sas_base_start_watchdog(ioc
);
7920 ioc
->is_driver_loading
= 0;
7926 * _scsih_probe - attach and add scsi host
7927 * @pdev: PCI device struct
7928 * @id: pci device id
7930 * Returns 0 success, anything else error.
7933 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
7935 struct MPT2SAS_ADAPTER
*ioc
;
7936 struct Scsi_Host
*shost
;
7938 shost
= scsi_host_alloc(&scsih_driver_template
,
7939 sizeof(struct MPT2SAS_ADAPTER
));
7943 /* init local params */
7944 ioc
= shost_priv(shost
);
7945 memset(ioc
, 0, sizeof(struct MPT2SAS_ADAPTER
));
7946 INIT_LIST_HEAD(&ioc
->list
);
7947 list_add_tail(&ioc
->list
, &mpt2sas_ioc_list
);
7949 ioc
->id
= mpt_ids
++;
7950 sprintf(ioc
->name
, "%s%d", MPT2SAS_DRIVER_NAME
, ioc
->id
);
7952 if (id
->device
== MPI2_MFGPAGE_DEVID_SSS6200
) {
7953 ioc
->is_warpdrive
= 1;
7954 ioc
->hide_ir_msg
= 1;
7956 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
7957 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
7958 ioc
->tm_cb_idx
= tm_cb_idx
;
7959 ioc
->ctl_cb_idx
= ctl_cb_idx
;
7960 ioc
->base_cb_idx
= base_cb_idx
;
7961 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
7962 ioc
->transport_cb_idx
= transport_cb_idx
;
7963 ioc
->scsih_cb_idx
= scsih_cb_idx
;
7964 ioc
->config_cb_idx
= config_cb_idx
;
7965 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
7966 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
7967 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
7968 ioc
->logging_level
= logging_level
;
7969 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
7970 /* misc semaphores and spin locks */
7971 mutex_init(&ioc
->reset_in_progress_mutex
);
7972 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
7973 spin_lock_init(&ioc
->scsi_lookup_lock
);
7974 spin_lock_init(&ioc
->sas_device_lock
);
7975 spin_lock_init(&ioc
->sas_node_lock
);
7976 spin_lock_init(&ioc
->fw_event_lock
);
7977 spin_lock_init(&ioc
->raid_device_lock
);
7979 INIT_LIST_HEAD(&ioc
->sas_device_list
);
7980 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
7981 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
7982 INIT_LIST_HEAD(&ioc
->fw_event_list
);
7983 INIT_LIST_HEAD(&ioc
->raid_device_list
);
7984 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
7985 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
7986 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
7988 /* init shost parameters */
7989 shost
->max_cmd_len
= 32;
7990 shost
->max_lun
= max_lun
;
7991 shost
->transportt
= mpt2sas_transport_template
;
7992 shost
->unique_id
= ioc
->id
;
7994 if (max_sectors
!= 0xFFFF) {
7995 if (max_sectors
< 64) {
7996 shost
->max_sectors
= 64;
7997 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
7998 "for max_sectors, range is 64 to 8192. Assigning "
7999 "value of 64.\n", ioc
->name
, max_sectors
);
8000 } else if (max_sectors
> 32767) {
8001 shost
->max_sectors
= 32767;
8002 printk(MPT2SAS_WARN_FMT
"Invalid value %d passed "
8003 "for max_sectors, range is 64 to 8192. Assigning "
8004 "default value of 32767.\n", ioc
->name
,
8007 shost
->max_sectors
= max_sectors
& 0xFFFE;
8008 printk(MPT2SAS_INFO_FMT
"The max_sectors value is "
8009 "set to %d\n", ioc
->name
, shost
->max_sectors
);
8013 if ((scsi_add_host(shost
, &pdev
->dev
))) {
8014 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8015 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8016 list_del(&ioc
->list
);
8017 goto out_add_shost_fail
;
8020 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
8021 | SHOST_DIF_TYPE2_PROTECTION
| SHOST_DIF_TYPE3_PROTECTION
);
8022 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
8025 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
8026 "fw_event%d", ioc
->id
);
8027 ioc
->firmware_event_thread
= create_singlethread_workqueue(
8028 ioc
->firmware_event_name
);
8029 if (!ioc
->firmware_event_thread
) {
8030 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8031 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8032 goto out_thread_fail
;
8035 ioc
->is_driver_loading
= 1;
8036 if ((mpt2sas_base_attach(ioc
))) {
8037 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
8038 ioc
->name
, __FILE__
, __LINE__
, __func__
);
8039 goto out_attach_fail
;
8042 if (ioc
->is_warpdrive
) {
8043 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
8044 ioc
->hide_drives
= 0;
8045 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
8046 ioc
->hide_drives
= 1;
8048 if (_scsih_get_num_volumes(ioc
))
8049 ioc
->hide_drives
= 1;
8051 ioc
->hide_drives
= 0;
8054 ioc
->hide_drives
= 0;
8055 scsi_scan_host(shost
);
8060 destroy_workqueue(ioc
->firmware_event_thread
);
8062 list_del(&ioc
->list
);
8063 scsi_remove_host(shost
);
8064 scsi_host_put(shost
);
8071 * _scsih_suspend - power management suspend main entry point
8072 * @pdev: PCI device struct
8073 * @state: PM state change to (usually PCI_D3)
8075 * Returns 0 success, anything else error.
8078 _scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8080 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8081 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8082 pci_power_t device_state
;
8084 mpt2sas_base_stop_watchdog(ioc
);
8085 scsi_block_requests(shost
);
8086 device_state
= pci_choose_state(pdev
, state
);
8087 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, entering "
8088 "operating state [D%d]\n", ioc
->name
, pdev
,
8089 pci_name(pdev
), device_state
);
8091 mpt2sas_base_free_resources(ioc
);
8092 pci_save_state(pdev
);
8093 pci_disable_device(pdev
);
8094 pci_set_power_state(pdev
, device_state
);
8099 * _scsih_resume - power management resume main entry point
8100 * @pdev: PCI device struct
8102 * Returns 0 success, anything else error.
8105 _scsih_resume(struct pci_dev
*pdev
)
8107 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8108 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8109 pci_power_t device_state
= pdev
->current_state
;
8112 printk(MPT2SAS_INFO_FMT
"pdev=0x%p, slot=%s, previous "
8113 "operating state [D%d]\n", ioc
->name
, pdev
,
8114 pci_name(pdev
), device_state
);
8116 pci_set_power_state(pdev
, PCI_D0
);
8117 pci_enable_wake(pdev
, PCI_D0
, 0);
8118 pci_restore_state(pdev
);
8120 r
= mpt2sas_base_map_resources(ioc
);
8124 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
, SOFT_RESET
);
8125 scsi_unblock_requests(shost
);
8126 mpt2sas_base_start_watchdog(ioc
);
8129 #endif /* CONFIG_PM */
8132 * _scsih_pci_error_detected - Called when a PCI error is detected.
8133 * @pdev: PCI device struct
8134 * @state: PCI channel state
8136 * Description: Called when a PCI error is detected.
8139 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8141 static pci_ers_result_t
8142 _scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8144 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8145 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8147 printk(MPT2SAS_INFO_FMT
"PCI error: detected callback, state(%d)!!\n",
8151 case pci_channel_io_normal
:
8152 return PCI_ERS_RESULT_CAN_RECOVER
;
8153 case pci_channel_io_frozen
:
8154 /* Fatal error, prepare for slot reset */
8155 ioc
->pci_error_recovery
= 1;
8156 scsi_block_requests(ioc
->shost
);
8157 mpt2sas_base_stop_watchdog(ioc
);
8158 mpt2sas_base_free_resources(ioc
);
8159 return PCI_ERS_RESULT_NEED_RESET
;
8160 case pci_channel_io_perm_failure
:
8161 /* Permanent error, prepare for device removal */
8162 ioc
->pci_error_recovery
= 1;
8163 mpt2sas_base_stop_watchdog(ioc
);
8164 _scsih_flush_running_cmds(ioc
);
8165 return PCI_ERS_RESULT_DISCONNECT
;
8167 return PCI_ERS_RESULT_NEED_RESET
;
8171 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8172 * @pdev: PCI device struct
8174 * Description: This routine is called by the pci error recovery
8175 * code after the PCI slot has been reset, just before we
8176 * should resume normal operations.
8178 static pci_ers_result_t
8179 _scsih_pci_slot_reset(struct pci_dev
*pdev
)
8181 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8182 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8185 printk(MPT2SAS_INFO_FMT
"PCI error: slot reset callback!!\n",
8188 ioc
->pci_error_recovery
= 0;
8190 pci_restore_state(pdev
);
8191 rc
= mpt2sas_base_map_resources(ioc
);
8193 return PCI_ERS_RESULT_DISCONNECT
;
8196 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
8199 printk(MPT2SAS_WARN_FMT
"hard reset: %s\n", ioc
->name
,
8200 (rc
== 0) ? "success" : "failed");
8203 return PCI_ERS_RESULT_RECOVERED
;
8205 return PCI_ERS_RESULT_DISCONNECT
;
8209 * _scsih_pci_resume() - resume normal ops after PCI reset
8210 * @pdev: pointer to PCI device
8212 * Called when the error recovery driver tells us that its
8213 * OK to resume normal operation. Use completion to allow
8214 * halted scsi ops to resume.
8217 _scsih_pci_resume(struct pci_dev
*pdev
)
8219 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8220 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8222 printk(MPT2SAS_INFO_FMT
"PCI error: resume callback!!\n", ioc
->name
);
8224 pci_cleanup_aer_uncorrect_error_status(pdev
);
8225 mpt2sas_base_start_watchdog(ioc
);
8226 scsi_unblock_requests(ioc
->shost
);
8230 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8231 * @pdev: pointer to PCI device
8233 static pci_ers_result_t
8234 _scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
8236 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8237 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
8239 printk(MPT2SAS_INFO_FMT
"PCI error: mmio enabled callback!!\n",
8242 /* TODO - dump whatever for debugging purposes */
8244 /* Request a slot reset. */
8245 return PCI_ERS_RESULT_NEED_RESET
;
8248 static struct pci_error_handlers _scsih_err_handler
= {
8249 .error_detected
= _scsih_pci_error_detected
,
8250 .mmio_enabled
= _scsih_pci_mmio_enabled
,
8251 .slot_reset
= _scsih_pci_slot_reset
,
8252 .resume
= _scsih_pci_resume
,
8255 static struct pci_driver scsih_driver
= {
8256 .name
= MPT2SAS_DRIVER_NAME
,
8257 .id_table
= scsih_pci_table
,
8258 .probe
= _scsih_probe
,
8259 .remove
= __devexit_p(_scsih_remove
),
8260 .shutdown
= _scsih_shutdown
,
8261 .err_handler
= &_scsih_err_handler
,
8263 .suspend
= _scsih_suspend
,
8264 .resume
= _scsih_resume
,
8268 /* raid transport support */
8269 static struct raid_function_template mpt2sas_raid_functions
= {
8270 .cookie
= &scsih_driver_template
,
8271 .is_raid
= _scsih_is_raid
,
8272 .get_resync
= _scsih_get_resync
,
8273 .get_state
= _scsih_get_state
,
8277 * _scsih_init - main entry point for this driver.
8279 * Returns 0 success, anything else error.
8287 printk(KERN_INFO
"%s version %s loaded\n", MPT2SAS_DRIVER_NAME
,
8288 MPT2SAS_DRIVER_VERSION
);
8290 mpt2sas_transport_template
=
8291 sas_attach_transport(&mpt2sas_transport_functions
);
8292 if (!mpt2sas_transport_template
)
8294 /* raid transport support */
8295 mpt2sas_raid_template
= raid_class_attach(&mpt2sas_raid_functions
);
8296 if (!mpt2sas_raid_template
) {
8297 sas_release_transport(mpt2sas_transport_template
);
8301 mpt2sas_base_initialize_callback_handler();
8303 /* queuecommand callback hander */
8304 scsi_io_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_io_done
);
8306 /* task management callback handler */
8307 tm_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_tm_done
);
8309 /* base internal commands callback handler */
8310 base_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_base_done
);
8311 port_enable_cb_idx
= mpt2sas_base_register_callback_handler(
8312 mpt2sas_port_enable_done
);
8314 /* transport internal commands callback handler */
8315 transport_cb_idx
= mpt2sas_base_register_callback_handler(
8316 mpt2sas_transport_done
);
8318 /* scsih internal commands callback handler */
8319 scsih_cb_idx
= mpt2sas_base_register_callback_handler(_scsih_done
);
8321 /* configuration page API internal commands callback handler */
8322 config_cb_idx
= mpt2sas_base_register_callback_handler(
8323 mpt2sas_config_done
);
8325 /* ctl module callback handler */
8326 ctl_cb_idx
= mpt2sas_base_register_callback_handler(mpt2sas_ctl_done
);
8328 tm_tr_cb_idx
= mpt2sas_base_register_callback_handler(
8329 _scsih_tm_tr_complete
);
8331 tm_tr_volume_cb_idx
= mpt2sas_base_register_callback_handler(
8332 _scsih_tm_volume_tr_complete
);
8334 tm_sas_control_cb_idx
= mpt2sas_base_register_callback_handler(
8335 _scsih_sas_control_complete
);
8339 error
= pci_register_driver(&scsih_driver
);
8341 /* raid transport support */
8342 raid_class_release(mpt2sas_raid_template
);
8343 sas_release_transport(mpt2sas_transport_template
);
8350 * _scsih_exit - exit point for this driver (when it is a module).
8352 * Returns 0 success, anything else error.
8357 printk(KERN_INFO
"mpt2sas version %s unloading\n",
8358 MPT2SAS_DRIVER_VERSION
);
8360 pci_unregister_driver(&scsih_driver
);
8364 mpt2sas_base_release_callback_handler(scsi_io_cb_idx
);
8365 mpt2sas_base_release_callback_handler(tm_cb_idx
);
8366 mpt2sas_base_release_callback_handler(base_cb_idx
);
8367 mpt2sas_base_release_callback_handler(port_enable_cb_idx
);
8368 mpt2sas_base_release_callback_handler(transport_cb_idx
);
8369 mpt2sas_base_release_callback_handler(scsih_cb_idx
);
8370 mpt2sas_base_release_callback_handler(config_cb_idx
);
8371 mpt2sas_base_release_callback_handler(ctl_cb_idx
);
8373 mpt2sas_base_release_callback_handler(tm_tr_cb_idx
);
8374 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
8375 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx
);
8377 /* raid transport support */
8378 raid_class_release(mpt2sas_raid_template
);
8379 sas_release_transport(mpt2sas_transport_template
);
8383 module_init(_scsih_init
);
8384 module_exit(_scsih_exit
);