2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt3sas/mpt3sas_scsih.c
5 * Copyright (C) 2012-2014 LSI Corporation
6 * Copyright (C) 2013-2014 Avago Technologies
7 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
55 #include <linux/aer.h>
56 #include <linux/raid_class.h>
57 #include <asm/unaligned.h>
59 #include "mpt3sas_base.h"
61 #define RAID_CHANNEL 1
63 #define PCIE_CHANNEL 2
66 static void _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
67 struct _sas_node
*sas_expander
);
68 static void _firmware_event_work(struct work_struct
*work
);
70 static void _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
71 struct _sas_device
*sas_device
);
72 static int _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
73 u8 retry_count
, u8 is_pd
);
74 static int _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
);
75 static void _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
76 struct _pcie_device
*pcie_device
);
78 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
);
79 static u8
_scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
);
81 /* global parameters */
82 LIST_HEAD(mpt3sas_ioc_list
);
83 /* global ioc lock for list operations */
84 DEFINE_SPINLOCK(gioc_lock
);
86 MODULE_AUTHOR(MPT3SAS_AUTHOR
);
87 MODULE_DESCRIPTION(MPT3SAS_DESCRIPTION
);
88 MODULE_LICENSE("GPL");
89 MODULE_VERSION(MPT3SAS_DRIVER_VERSION
);
90 MODULE_ALIAS("mpt2sas");
92 /* local parameters */
93 static u8 scsi_io_cb_idx
= -1;
94 static u8 tm_cb_idx
= -1;
95 static u8 ctl_cb_idx
= -1;
96 static u8 base_cb_idx
= -1;
97 static u8 port_enable_cb_idx
= -1;
98 static u8 transport_cb_idx
= -1;
99 static u8 scsih_cb_idx
= -1;
100 static u8 config_cb_idx
= -1;
104 static u8 tm_tr_cb_idx
= -1 ;
105 static u8 tm_tr_volume_cb_idx
= -1 ;
106 static u8 tm_sas_control_cb_idx
= -1;
108 /* command line options */
109 static u32 logging_level
;
110 MODULE_PARM_DESC(logging_level
,
111 " bits for enabling additional logging info (default=0)");
114 static ushort max_sectors
= 0xFFFF;
115 module_param(max_sectors
, ushort
, 0444);
116 MODULE_PARM_DESC(max_sectors
, "max sectors, range 64 to 32767 default=32767");
119 static int missing_delay
[2] = {-1, -1};
120 module_param_array(missing_delay
, int, NULL
, 0444);
121 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
123 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
124 #define MPT3SAS_MAX_LUN (16895)
125 static u64 max_lun
= MPT3SAS_MAX_LUN
;
126 module_param(max_lun
, ullong
, 0444);
127 MODULE_PARM_DESC(max_lun
, " max lun, default=16895 ");
129 static ushort hbas_to_enumerate
;
130 module_param(hbas_to_enumerate
, ushort
, 0444);
131 MODULE_PARM_DESC(hbas_to_enumerate
,
132 " 0 - enumerates both SAS 2.0 & SAS 3.0 generation HBAs\n \
133 1 - enumerates only SAS 2.0 generation HBAs\n \
134 2 - enumerates only SAS 3.0 generation HBAs (default=0)");
136 /* diag_buffer_enable is bitwise
138 * bit 1 set = SNAPSHOT
139 * bit 2 set = EXTENDED
141 * Either bit can be set, or both
143 static int diag_buffer_enable
= -1;
144 module_param(diag_buffer_enable
, int, 0444);
145 MODULE_PARM_DESC(diag_buffer_enable
,
146 " post diag buffers (TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
147 static int disable_discovery
= -1;
148 module_param(disable_discovery
, int, 0444);
149 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
152 /* permit overriding the host protection capabilities mask (EEDP/T10 PI) */
153 static int prot_mask
= -1;
154 module_param(prot_mask
, int, 0444);
155 MODULE_PARM_DESC(prot_mask
, " host protection capabilities mask, def=7 ");
157 static bool enable_sdev_max_qd
;
158 module_param(enable_sdev_max_qd
, bool, 0444);
159 MODULE_PARM_DESC(enable_sdev_max_qd
,
160 "Enable sdev max qd as can_queue, def=disabled(0)");
162 /* raid transport support */
163 static struct raid_template
*mpt3sas_raid_template
;
164 static struct raid_template
*mpt2sas_raid_template
;
168 * struct sense_info - common structure for obtaining sense keys
170 * @asc: additional sense code
171 * @ascq: additional sense code qualifier
179 #define MPT3SAS_PROCESS_TRIGGER_DIAG (0xFFFB)
180 #define MPT3SAS_TURN_ON_PFA_LED (0xFFFC)
181 #define MPT3SAS_PORT_ENABLE_COMPLETE (0xFFFD)
182 #define MPT3SAS_ABRT_TASK_SET (0xFFFE)
183 #define MPT3SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
185 * struct fw_event_work - firmware event struct
186 * @list: link list framework
187 * @work: work object (ioc->fault_reset_work_q)
188 * @ioc: per adapter object
189 * @device_handle: device handle
190 * @VF_ID: virtual function id
191 * @VP_ID: virtual port id
192 * @ignore: flag meaning this event has been marked to ignore
193 * @event: firmware event MPI2_EVENT_XXX defined in mpi2_ioc.h
194 * @refcount: kref for this event
195 * @event_data: reply event data payload follows
197 * This object stored on ioc->fw_event_list.
199 struct fw_event_work
{
200 struct list_head list
;
201 struct work_struct work
;
203 struct MPT3SAS_ADAPTER
*ioc
;
209 struct kref refcount
;
210 char event_data
[0] __aligned(4);
213 static void fw_event_work_free(struct kref
*r
)
215 kfree(container_of(r
, struct fw_event_work
, refcount
));
218 static void fw_event_work_get(struct fw_event_work
*fw_work
)
220 kref_get(&fw_work
->refcount
);
223 static void fw_event_work_put(struct fw_event_work
*fw_work
)
225 kref_put(&fw_work
->refcount
, fw_event_work_free
);
228 static struct fw_event_work
*alloc_fw_event_work(int len
)
230 struct fw_event_work
*fw_event
;
232 fw_event
= kzalloc(sizeof(*fw_event
) + len
, GFP_ATOMIC
);
236 kref_init(&fw_event
->refcount
);
241 * struct _scsi_io_transfer - scsi io transfer
242 * @handle: sas device handle (assigned by firmware)
243 * @is_raid: flag set for hidden raid components
244 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
245 * @data_length: data transfer length
246 * @data_dma: dma pointer to data
249 * @cdb_length: cdb length
251 * @timeout: timeout for this command
252 * @VF_ID: virtual function id
253 * @VP_ID: virtual port id
254 * @valid_reply: flag set for reply message
255 * @sense_length: sense length
256 * @ioc_status: ioc status
257 * @scsi_state: scsi state
258 * @scsi_status: scsi staus
259 * @log_info: log information
260 * @transfer_length: data length transfer when there is a reply message
262 * Used for sending internal scsi commands to devices within this module.
263 * Refer to _scsi_send_scsi_io().
265 struct _scsi_io_transfer
{
268 enum dma_data_direction dir
;
271 u8 sense
[SCSI_SENSE_BUFFERSIZE
];
279 /* the following bits are only valid when 'valid_reply = 1' */
289 * _scsih_set_debug_level - global setting of ioc->logging_level.
293 * Note: The logging levels are defined in mpt3sas_debug.h.
296 _scsih_set_debug_level(const char *val
, const struct kernel_param
*kp
)
298 int ret
= param_set_int(val
, kp
);
299 struct MPT3SAS_ADAPTER
*ioc
;
304 pr_info("setting logging_level(0x%08x)\n", logging_level
);
305 spin_lock(&gioc_lock
);
306 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
307 ioc
->logging_level
= logging_level
;
308 spin_unlock(&gioc_lock
);
311 module_param_call(logging_level
, _scsih_set_debug_level
, param_get_int
,
312 &logging_level
, 0644);
315 * _scsih_srch_boot_sas_address - search based on sas_address
316 * @sas_address: sas address
317 * @boot_device: boot device object from bios page 2
319 * Return: 1 when there's a match, 0 means no match.
322 _scsih_srch_boot_sas_address(u64 sas_address
,
323 Mpi2BootDeviceSasWwid_t
*boot_device
)
325 return (sas_address
== le64_to_cpu(boot_device
->SASAddress
)) ? 1 : 0;
329 * _scsih_srch_boot_device_name - search based on device name
330 * @device_name: device name specified in INDENTIFY fram
331 * @boot_device: boot device object from bios page 2
333 * Return: 1 when there's a match, 0 means no match.
336 _scsih_srch_boot_device_name(u64 device_name
,
337 Mpi2BootDeviceDeviceName_t
*boot_device
)
339 return (device_name
== le64_to_cpu(boot_device
->DeviceName
)) ? 1 : 0;
343 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
344 * @enclosure_logical_id: enclosure logical id
345 * @slot_number: slot number
346 * @boot_device: boot device object from bios page 2
348 * Return: 1 when there's a match, 0 means no match.
351 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id
, u16 slot_number
,
352 Mpi2BootDeviceEnclosureSlot_t
*boot_device
)
354 return (enclosure_logical_id
== le64_to_cpu(boot_device
->
355 EnclosureLogicalID
) && slot_number
== le16_to_cpu(boot_device
->
356 SlotNumber
)) ? 1 : 0;
360 * _scsih_is_boot_device - search for matching boot device.
361 * @sas_address: sas address
362 * @device_name: device name specified in INDENTIFY fram
363 * @enclosure_logical_id: enclosure logical id
365 * @form: specifies boot device form
366 * @boot_device: boot device object from bios page 2
368 * Return: 1 when there's a match, 0 means no match.
371 _scsih_is_boot_device(u64 sas_address
, u64 device_name
,
372 u64 enclosure_logical_id
, u16 slot
, u8 form
,
373 Mpi2BiosPage2BootDevice_t
*boot_device
)
378 case MPI2_BIOSPAGE2_FORM_SAS_WWID
:
381 rc
= _scsih_srch_boot_sas_address(
382 sas_address
, &boot_device
->SasWwid
);
384 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT
:
385 if (!enclosure_logical_id
)
387 rc
= _scsih_srch_boot_encl_slot(
388 enclosure_logical_id
,
389 slot
, &boot_device
->EnclosureSlot
);
391 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME
:
394 rc
= _scsih_srch_boot_device_name(
395 device_name
, &boot_device
->DeviceName
);
397 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
:
405 * _scsih_get_sas_address - set the sas_address for given device handle
407 * @handle: device handle
408 * @sas_address: sas address
410 * Return: 0 success, non-zero when failure
413 _scsih_get_sas_address(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
416 Mpi2SasDevicePage0_t sas_device_pg0
;
417 Mpi2ConfigReply_t mpi_reply
;
422 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
423 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
424 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
425 __FILE__
, __LINE__
, __func__
);
429 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
430 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
431 /* For HBA, vSES doesn't return HBA SAS address. Instead return
432 * vSES's sas address.
434 if ((handle
<= ioc
->sas_hba
.num_phys
) &&
435 (!(le32_to_cpu(sas_device_pg0
.DeviceInfo
) &
436 MPI2_SAS_DEVICE_INFO_SEP
)))
437 *sas_address
= ioc
->sas_hba
.sas_address
;
439 *sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
443 /* we hit this because the given parent handle doesn't exist */
444 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
447 /* else error case */
448 ioc_err(ioc
, "handle(0x%04x), ioc_status(0x%04x), failure at %s:%d/%s()!\n",
449 handle
, ioc_status
, __FILE__
, __LINE__
, __func__
);
454 * _scsih_determine_boot_device - determine boot device.
455 * @ioc: per adapter object
456 * @device: sas_device or pcie_device object
457 * @channel: SAS or PCIe channel
459 * Determines whether this device should be first reported device to
460 * to scsi-ml or sas transport, this purpose is for persistent boot device.
461 * There are primary, alternate, and current entries in bios page 2. The order
462 * priority is primary, alternate, then current. This routine saves
463 * the corresponding device object.
464 * The saved data to be used later in _scsih_probe_boot_devices().
467 _scsih_determine_boot_device(struct MPT3SAS_ADAPTER
*ioc
, void *device
,
470 struct _sas_device
*sas_device
;
471 struct _pcie_device
*pcie_device
;
472 struct _raid_device
*raid_device
;
475 u64 enclosure_logical_id
;
478 /* only process this function when driver loads */
479 if (!ioc
->is_driver_loading
)
482 /* no Bios, return immediately */
483 if (!ioc
->bios_pg3
.BiosVersion
)
486 if (channel
== RAID_CHANNEL
) {
487 raid_device
= device
;
488 sas_address
= raid_device
->wwid
;
490 enclosure_logical_id
= 0;
492 } else if (channel
== PCIE_CHANNEL
) {
493 pcie_device
= device
;
494 sas_address
= pcie_device
->wwid
;
496 enclosure_logical_id
= 0;
500 sas_address
= sas_device
->sas_address
;
501 device_name
= sas_device
->device_name
;
502 enclosure_logical_id
= sas_device
->enclosure_logical_id
;
503 slot
= sas_device
->slot
;
506 if (!ioc
->req_boot_device
.device
) {
507 if (_scsih_is_boot_device(sas_address
, device_name
,
508 enclosure_logical_id
, slot
,
509 (ioc
->bios_pg2
.ReqBootDeviceForm
&
510 MPI2_BIOSPAGE2_FORM_MASK
),
511 &ioc
->bios_pg2
.RequestedBootDevice
)) {
513 ioc_info(ioc
, "%s: req_boot_device(0x%016llx)\n",
514 __func__
, (u64
)sas_address
));
515 ioc
->req_boot_device
.device
= device
;
516 ioc
->req_boot_device
.channel
= channel
;
520 if (!ioc
->req_alt_boot_device
.device
) {
521 if (_scsih_is_boot_device(sas_address
, device_name
,
522 enclosure_logical_id
, slot
,
523 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
524 MPI2_BIOSPAGE2_FORM_MASK
),
525 &ioc
->bios_pg2
.RequestedAltBootDevice
)) {
527 ioc_info(ioc
, "%s: req_alt_boot_device(0x%016llx)\n",
528 __func__
, (u64
)sas_address
));
529 ioc
->req_alt_boot_device
.device
= device
;
530 ioc
->req_alt_boot_device
.channel
= channel
;
534 if (!ioc
->current_boot_device
.device
) {
535 if (_scsih_is_boot_device(sas_address
, device_name
,
536 enclosure_logical_id
, slot
,
537 (ioc
->bios_pg2
.CurrentBootDeviceForm
&
538 MPI2_BIOSPAGE2_FORM_MASK
),
539 &ioc
->bios_pg2
.CurrentBootDevice
)) {
541 ioc_info(ioc
, "%s: current_boot_device(0x%016llx)\n",
542 __func__
, (u64
)sas_address
));
543 ioc
->current_boot_device
.device
= device
;
544 ioc
->current_boot_device
.channel
= channel
;
549 static struct _sas_device
*
550 __mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
551 struct MPT3SAS_TARGET
*tgt_priv
)
553 struct _sas_device
*ret
;
555 assert_spin_locked(&ioc
->sas_device_lock
);
557 ret
= tgt_priv
->sas_dev
;
564 static struct _sas_device
*
565 mpt3sas_get_sdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
566 struct MPT3SAS_TARGET
*tgt_priv
)
568 struct _sas_device
*ret
;
571 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
572 ret
= __mpt3sas_get_sdev_from_target(ioc
, tgt_priv
);
573 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
578 static struct _pcie_device
*
579 __mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
580 struct MPT3SAS_TARGET
*tgt_priv
)
582 struct _pcie_device
*ret
;
584 assert_spin_locked(&ioc
->pcie_device_lock
);
586 ret
= tgt_priv
->pcie_dev
;
588 pcie_device_get(ret
);
594 * mpt3sas_get_pdev_from_target - pcie device search
595 * @ioc: per adapter object
596 * @tgt_priv: starget private object
598 * Context: This function will acquire ioc->pcie_device_lock and will release
599 * before returning the pcie_device object.
601 * This searches for pcie_device from target, then return pcie_device object.
603 static struct _pcie_device
*
604 mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER
*ioc
,
605 struct MPT3SAS_TARGET
*tgt_priv
)
607 struct _pcie_device
*ret
;
610 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
611 ret
= __mpt3sas_get_pdev_from_target(ioc
, tgt_priv
);
612 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
618 __mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
621 struct _sas_device
*sas_device
;
623 assert_spin_locked(&ioc
->sas_device_lock
);
625 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
626 if (sas_device
->sas_address
== sas_address
)
629 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
630 if (sas_device
->sas_address
== sas_address
)
636 sas_device_get(sas_device
);
641 * mpt3sas_get_sdev_by_addr - sas device search
642 * @ioc: per adapter object
643 * @sas_address: sas address
644 * Context: Calling function should acquire ioc->sas_device_lock
646 * This searches for sas_device based on sas_address, then return sas_device
650 mpt3sas_get_sdev_by_addr(struct MPT3SAS_ADAPTER
*ioc
,
653 struct _sas_device
*sas_device
;
656 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
657 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
659 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
664 static struct _sas_device
*
665 __mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
667 struct _sas_device
*sas_device
;
669 assert_spin_locked(&ioc
->sas_device_lock
);
671 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
)
672 if (sas_device
->handle
== handle
)
675 list_for_each_entry(sas_device
, &ioc
->sas_device_init_list
, list
)
676 if (sas_device
->handle
== handle
)
682 sas_device_get(sas_device
);
687 * mpt3sas_get_sdev_by_handle - sas device search
688 * @ioc: per adapter object
689 * @handle: sas device handle (assigned by firmware)
690 * Context: Calling function should acquire ioc->sas_device_lock
692 * This searches for sas_device based on sas_address, then return sas_device
696 mpt3sas_get_sdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
698 struct _sas_device
*sas_device
;
701 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
702 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
703 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
709 * _scsih_display_enclosure_chassis_info - display device location info
710 * @ioc: per adapter object
711 * @sas_device: per sas device object
712 * @sdev: scsi device struct
713 * @starget: scsi target struct
716 _scsih_display_enclosure_chassis_info(struct MPT3SAS_ADAPTER
*ioc
,
717 struct _sas_device
*sas_device
, struct scsi_device
*sdev
,
718 struct scsi_target
*starget
)
721 if (sas_device
->enclosure_handle
!= 0)
722 sdev_printk(KERN_INFO
, sdev
,
723 "enclosure logical id (0x%016llx), slot(%d) \n",
725 sas_device
->enclosure_logical_id
,
727 if (sas_device
->connector_name
[0] != '\0')
728 sdev_printk(KERN_INFO
, sdev
,
729 "enclosure level(0x%04x), connector name( %s)\n",
730 sas_device
->enclosure_level
,
731 sas_device
->connector_name
);
732 if (sas_device
->is_chassis_slot_valid
)
733 sdev_printk(KERN_INFO
, sdev
, "chassis slot(0x%04x)\n",
734 sas_device
->chassis_slot
);
735 } else if (starget
) {
736 if (sas_device
->enclosure_handle
!= 0)
737 starget_printk(KERN_INFO
, starget
,
738 "enclosure logical id(0x%016llx), slot(%d) \n",
740 sas_device
->enclosure_logical_id
,
742 if (sas_device
->connector_name
[0] != '\0')
743 starget_printk(KERN_INFO
, starget
,
744 "enclosure level(0x%04x), connector name( %s)\n",
745 sas_device
->enclosure_level
,
746 sas_device
->connector_name
);
747 if (sas_device
->is_chassis_slot_valid
)
748 starget_printk(KERN_INFO
, starget
,
749 "chassis slot(0x%04x)\n",
750 sas_device
->chassis_slot
);
752 if (sas_device
->enclosure_handle
!= 0)
753 ioc_info(ioc
, "enclosure logical id(0x%016llx), slot(%d)\n",
754 (u64
)sas_device
->enclosure_logical_id
,
756 if (sas_device
->connector_name
[0] != '\0')
757 ioc_info(ioc
, "enclosure level(0x%04x), connector name( %s)\n",
758 sas_device
->enclosure_level
,
759 sas_device
->connector_name
);
760 if (sas_device
->is_chassis_slot_valid
)
761 ioc_info(ioc
, "chassis slot(0x%04x)\n",
762 sas_device
->chassis_slot
);
767 * _scsih_sas_device_remove - remove sas_device from list.
768 * @ioc: per adapter object
769 * @sas_device: the sas_device object
770 * Context: This function will acquire ioc->sas_device_lock.
772 * If sas_device is on the list, remove it and decrement its reference count.
775 _scsih_sas_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
776 struct _sas_device
*sas_device
)
782 ioc_info(ioc
, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
783 sas_device
->handle
, (u64
)sas_device
->sas_address
);
785 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
788 * The lock serializes access to the list, but we still need to verify
789 * that nobody removed the entry while we were waiting on the lock.
791 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
792 if (!list_empty(&sas_device
->list
)) {
793 list_del_init(&sas_device
->list
);
794 sas_device_put(sas_device
);
796 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
800 * _scsih_device_remove_by_handle - removing device object by handle
801 * @ioc: per adapter object
802 * @handle: device handle
805 _scsih_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
807 struct _sas_device
*sas_device
;
810 if (ioc
->shost_recovery
)
813 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
814 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
816 list_del_init(&sas_device
->list
);
817 sas_device_put(sas_device
);
819 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
821 _scsih_remove_device(ioc
, sas_device
);
822 sas_device_put(sas_device
);
827 * mpt3sas_device_remove_by_sas_address - removing device object by sas address
828 * @ioc: per adapter object
829 * @sas_address: device sas_address
832 mpt3sas_device_remove_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
835 struct _sas_device
*sas_device
;
838 if (ioc
->shost_recovery
)
841 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
842 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
, sas_address
);
844 list_del_init(&sas_device
->list
);
845 sas_device_put(sas_device
);
847 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
849 _scsih_remove_device(ioc
, sas_device
);
850 sas_device_put(sas_device
);
855 * _scsih_sas_device_add - insert sas_device to the list.
856 * @ioc: per adapter object
857 * @sas_device: the sas_device object
858 * Context: This function will acquire ioc->sas_device_lock.
860 * Adding new object to the ioc->sas_device_list.
863 _scsih_sas_device_add(struct MPT3SAS_ADAPTER
*ioc
,
864 struct _sas_device
*sas_device
)
869 ioc_info(ioc
, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
870 __func__
, sas_device
->handle
,
871 (u64
)sas_device
->sas_address
));
873 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
876 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
877 sas_device_get(sas_device
);
878 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
879 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
881 if (ioc
->hide_drives
) {
882 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
886 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
887 sas_device
->sas_address_parent
)) {
888 _scsih_sas_device_remove(ioc
, sas_device
);
889 } else if (!sas_device
->starget
) {
891 * When asyn scanning is enabled, its not possible to remove
892 * devices while scanning is turned on due to an oops in
893 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
895 if (!ioc
->is_driver_loading
) {
896 mpt3sas_transport_port_remove(ioc
,
897 sas_device
->sas_address
,
898 sas_device
->sas_address_parent
);
899 _scsih_sas_device_remove(ioc
, sas_device
);
902 clear_bit(sas_device
->handle
, ioc
->pend_os_device_add
);
906 * _scsih_sas_device_init_add - insert sas_device to the list.
907 * @ioc: per adapter object
908 * @sas_device: the sas_device object
909 * Context: This function will acquire ioc->sas_device_lock.
911 * Adding new object at driver load time to the ioc->sas_device_init_list.
914 _scsih_sas_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
915 struct _sas_device
*sas_device
)
920 ioc_info(ioc
, "%s: handle(0x%04x), sas_addr(0x%016llx)\n",
921 __func__
, sas_device
->handle
,
922 (u64
)sas_device
->sas_address
));
924 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
927 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
928 sas_device_get(sas_device
);
929 list_add_tail(&sas_device
->list
, &ioc
->sas_device_init_list
);
930 _scsih_determine_boot_device(ioc
, sas_device
, 0);
931 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
935 static struct _pcie_device
*
936 __mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
938 struct _pcie_device
*pcie_device
;
940 assert_spin_locked(&ioc
->pcie_device_lock
);
942 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
943 if (pcie_device
->wwid
== wwid
)
946 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
947 if (pcie_device
->wwid
== wwid
)
953 pcie_device_get(pcie_device
);
959 * mpt3sas_get_pdev_by_wwid - pcie device search
960 * @ioc: per adapter object
963 * Context: This function will acquire ioc->pcie_device_lock and will release
964 * before returning the pcie_device object.
966 * This searches for pcie_device based on wwid, then return pcie_device object.
968 static struct _pcie_device
*
969 mpt3sas_get_pdev_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
971 struct _pcie_device
*pcie_device
;
974 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
975 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
976 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
982 static struct _pcie_device
*
983 __mpt3sas_get_pdev_by_idchannel(struct MPT3SAS_ADAPTER
*ioc
, int id
,
986 struct _pcie_device
*pcie_device
;
988 assert_spin_locked(&ioc
->pcie_device_lock
);
990 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
991 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
994 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
995 if (pcie_device
->id
== id
&& pcie_device
->channel
== channel
)
1001 pcie_device_get(pcie_device
);
1005 static struct _pcie_device
*
1006 __mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1008 struct _pcie_device
*pcie_device
;
1010 assert_spin_locked(&ioc
->pcie_device_lock
);
1012 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
)
1013 if (pcie_device
->handle
== handle
)
1016 list_for_each_entry(pcie_device
, &ioc
->pcie_device_init_list
, list
)
1017 if (pcie_device
->handle
== handle
)
1023 pcie_device_get(pcie_device
);
1029 * mpt3sas_get_pdev_by_handle - pcie device search
1030 * @ioc: per adapter object
1031 * @handle: Firmware device handle
1033 * Context: This function will acquire ioc->pcie_device_lock and will release
1034 * before returning the pcie_device object.
1036 * This searches for pcie_device based on handle, then return pcie_device
1039 struct _pcie_device
*
1040 mpt3sas_get_pdev_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1042 struct _pcie_device
*pcie_device
;
1043 unsigned long flags
;
1045 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1046 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1047 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1053 * _scsih_pcie_device_remove - remove pcie_device from list.
1054 * @ioc: per adapter object
1055 * @pcie_device: the pcie_device object
1056 * Context: This function will acquire ioc->pcie_device_lock.
1058 * If pcie_device is on the list, remove it and decrement its reference count.
1061 _scsih_pcie_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1062 struct _pcie_device
*pcie_device
)
1064 unsigned long flags
;
1065 int was_on_pcie_device_list
= 0;
1069 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
1070 pcie_device
->handle
, (u64
)pcie_device
->wwid
);
1071 if (pcie_device
->enclosure_handle
!= 0)
1072 ioc_info(ioc
, "removing enclosure logical id(0x%016llx), slot(%d)\n",
1073 (u64
)pcie_device
->enclosure_logical_id
,
1075 if (pcie_device
->connector_name
[0] != '\0')
1076 ioc_info(ioc
, "removing enclosure level(0x%04x), connector name( %s)\n",
1077 pcie_device
->enclosure_level
,
1078 pcie_device
->connector_name
);
1080 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1081 if (!list_empty(&pcie_device
->list
)) {
1082 list_del_init(&pcie_device
->list
);
1083 was_on_pcie_device_list
= 1;
1085 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1086 if (was_on_pcie_device_list
) {
1087 kfree(pcie_device
->serial_number
);
1088 pcie_device_put(pcie_device
);
1094 * _scsih_pcie_device_remove_by_handle - removing pcie device object by handle
1095 * @ioc: per adapter object
1096 * @handle: device handle
1099 _scsih_pcie_device_remove_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1101 struct _pcie_device
*pcie_device
;
1102 unsigned long flags
;
1103 int was_on_pcie_device_list
= 0;
1105 if (ioc
->shost_recovery
)
1108 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1109 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
1111 if (!list_empty(&pcie_device
->list
)) {
1112 list_del_init(&pcie_device
->list
);
1113 was_on_pcie_device_list
= 1;
1114 pcie_device_put(pcie_device
);
1117 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1118 if (was_on_pcie_device_list
) {
1119 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
1120 pcie_device_put(pcie_device
);
1125 * _scsih_pcie_device_add - add pcie_device object
1126 * @ioc: per adapter object
1127 * @pcie_device: pcie_device object
1129 * This is added to the pcie_device_list link list.
1132 _scsih_pcie_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1133 struct _pcie_device
*pcie_device
)
1135 unsigned long flags
;
1138 ioc_info(ioc
, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1140 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
1141 if (pcie_device
->enclosure_handle
!= 0)
1143 ioc_info(ioc
, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1145 (u64
)pcie_device
->enclosure_logical_id
,
1146 pcie_device
->slot
));
1147 if (pcie_device
->connector_name
[0] != '\0')
1149 ioc_info(ioc
, "%s: enclosure level(0x%04x), connector name( %s)\n",
1150 __func__
, pcie_device
->enclosure_level
,
1151 pcie_device
->connector_name
));
1153 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1154 pcie_device_get(pcie_device
);
1155 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
1156 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1158 if (pcie_device
->access_status
==
1159 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
) {
1160 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1163 if (scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, pcie_device
->id
, 0)) {
1164 _scsih_pcie_device_remove(ioc
, pcie_device
);
1165 } else if (!pcie_device
->starget
) {
1166 if (!ioc
->is_driver_loading
) {
1167 /*TODO-- Need to find out whether this condition will occur or not*/
1168 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1171 clear_bit(pcie_device
->handle
, ioc
->pend_os_device_add
);
1175 * _scsih_pcie_device_init_add - insert pcie_device to the init list.
1176 * @ioc: per adapter object
1177 * @pcie_device: the pcie_device object
1178 * Context: This function will acquire ioc->pcie_device_lock.
1180 * Adding new object at driver load time to the ioc->pcie_device_init_list.
1183 _scsih_pcie_device_init_add(struct MPT3SAS_ADAPTER
*ioc
,
1184 struct _pcie_device
*pcie_device
)
1186 unsigned long flags
;
1189 ioc_info(ioc
, "%s: handle (0x%04x), wwid(0x%016llx)\n",
1191 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
1192 if (pcie_device
->enclosure_handle
!= 0)
1194 ioc_info(ioc
, "%s: enclosure logical id(0x%016llx), slot( %d)\n",
1196 (u64
)pcie_device
->enclosure_logical_id
,
1197 pcie_device
->slot
));
1198 if (pcie_device
->connector_name
[0] != '\0')
1200 ioc_info(ioc
, "%s: enclosure level(0x%04x), connector name( %s)\n",
1201 __func__
, pcie_device
->enclosure_level
,
1202 pcie_device
->connector_name
));
1204 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1205 pcie_device_get(pcie_device
);
1206 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_init_list
);
1207 if (pcie_device
->access_status
!=
1208 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
)
1209 _scsih_determine_boot_device(ioc
, pcie_device
, PCIE_CHANNEL
);
1210 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1213 * _scsih_raid_device_find_by_id - raid device search
1214 * @ioc: per adapter object
1215 * @id: sas device target id
1216 * @channel: sas device channel
1217 * Context: Calling function should acquire ioc->raid_device_lock
1219 * This searches for raid_device based on target id, then return raid_device
1222 static struct _raid_device
*
1223 _scsih_raid_device_find_by_id(struct MPT3SAS_ADAPTER
*ioc
, int id
, int channel
)
1225 struct _raid_device
*raid_device
, *r
;
1228 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1229 if (raid_device
->id
== id
&& raid_device
->channel
== channel
) {
1240 * mpt3sas_raid_device_find_by_handle - raid device search
1241 * @ioc: per adapter object
1242 * @handle: sas device handle (assigned by firmware)
1243 * Context: Calling function should acquire ioc->raid_device_lock
1245 * This searches for raid_device based on handle, then return raid_device
1248 struct _raid_device
*
1249 mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1251 struct _raid_device
*raid_device
, *r
;
1254 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1255 if (raid_device
->handle
!= handle
)
1266 * _scsih_raid_device_find_by_wwid - raid device search
1267 * @ioc: per adapter object
1269 * Context: Calling function should acquire ioc->raid_device_lock
1271 * This searches for raid_device based on wwid, then return raid_device
1274 static struct _raid_device
*
1275 _scsih_raid_device_find_by_wwid(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
)
1277 struct _raid_device
*raid_device
, *r
;
1280 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1281 if (raid_device
->wwid
!= wwid
)
1292 * _scsih_raid_device_add - add raid_device object
1293 * @ioc: per adapter object
1294 * @raid_device: raid_device object
1296 * This is added to the raid_device_list link list.
1299 _scsih_raid_device_add(struct MPT3SAS_ADAPTER
*ioc
,
1300 struct _raid_device
*raid_device
)
1302 unsigned long flags
;
1305 ioc_info(ioc
, "%s: handle(0x%04x), wwid(0x%016llx)\n",
1307 raid_device
->handle
, (u64
)raid_device
->wwid
));
1309 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1310 list_add_tail(&raid_device
->list
, &ioc
->raid_device_list
);
1311 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1315 * _scsih_raid_device_remove - delete raid_device object
1316 * @ioc: per adapter object
1317 * @raid_device: raid_device object
1321 _scsih_raid_device_remove(struct MPT3SAS_ADAPTER
*ioc
,
1322 struct _raid_device
*raid_device
)
1324 unsigned long flags
;
1326 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1327 list_del(&raid_device
->list
);
1329 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1333 * mpt3sas_scsih_expander_find_by_handle - expander device search
1334 * @ioc: per adapter object
1335 * @handle: expander handle (assigned by firmware)
1336 * Context: Calling function should acquire ioc->sas_device_lock
1338 * This searches for expander device based on handle, then returns the
1342 mpt3sas_scsih_expander_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1344 struct _sas_node
*sas_expander
, *r
;
1347 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1348 if (sas_expander
->handle
!= handle
)
1358 * mpt3sas_scsih_enclosure_find_by_handle - exclosure device search
1359 * @ioc: per adapter object
1360 * @handle: enclosure handle (assigned by firmware)
1361 * Context: Calling function should acquire ioc->sas_device_lock
1363 * This searches for enclosure device based on handle, then returns the
1366 static struct _enclosure_node
*
1367 mpt3sas_scsih_enclosure_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
1369 struct _enclosure_node
*enclosure_dev
, *r
;
1372 list_for_each_entry(enclosure_dev
, &ioc
->enclosure_list
, list
) {
1373 if (le16_to_cpu(enclosure_dev
->pg0
.EnclosureHandle
) != handle
)
1382 * mpt3sas_scsih_expander_find_by_sas_address - expander device search
1383 * @ioc: per adapter object
1384 * @sas_address: sas address
1385 * Context: Calling function should acquire ioc->sas_node_lock.
1387 * This searches for expander device based on sas_address, then returns the
1391 mpt3sas_scsih_expander_find_by_sas_address(struct MPT3SAS_ADAPTER
*ioc
,
1394 struct _sas_node
*sas_expander
, *r
;
1397 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
1398 if (sas_expander
->sas_address
!= sas_address
)
1408 * _scsih_expander_node_add - insert expander device to the list.
1409 * @ioc: per adapter object
1410 * @sas_expander: the sas_device object
1411 * Context: This function will acquire ioc->sas_node_lock.
1413 * Adding new object to the ioc->sas_expander_list.
1416 _scsih_expander_node_add(struct MPT3SAS_ADAPTER
*ioc
,
1417 struct _sas_node
*sas_expander
)
1419 unsigned long flags
;
1421 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
1422 list_add_tail(&sas_expander
->list
, &ioc
->sas_expander_list
);
1423 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
1427 * _scsih_is_end_device - determines if device is an end device
1428 * @device_info: bitfield providing information about the device.
1431 * Return: 1 if end device.
1434 _scsih_is_end_device(u32 device_info
)
1436 if (device_info
& MPI2_SAS_DEVICE_INFO_END_DEVICE
&&
1437 ((device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) |
1438 (device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
) |
1439 (device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)))
1446 * _scsih_is_nvme_pciescsi_device - determines if
1447 * device is an pcie nvme/scsi device
1448 * @device_info: bitfield providing information about the device.
1451 * Returns 1 if device is pcie device type nvme/scsi.
1454 _scsih_is_nvme_pciescsi_device(u32 device_info
)
1456 if (((device_info
& MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
)
1457 == MPI26_PCIE_DEVINFO_NVME
) ||
1458 ((device_info
& MPI26_PCIE_DEVINFO_MASK_DEVICE_TYPE
)
1459 == MPI26_PCIE_DEVINFO_SCSI
))
1466 * mpt3sas_scsih_scsi_lookup_get - returns scmd entry
1467 * @ioc: per adapter object
1468 * @smid: system request message index
1470 * Return: the smid stored scmd pointer.
1471 * Then will dereference the stored scmd pointer.
1474 mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1476 struct scsi_cmnd
*scmd
= NULL
;
1477 struct scsiio_tracker
*st
;
1478 Mpi25SCSIIORequest_t
*mpi_request
;
1481 smid
<= ioc
->scsiio_depth
- INTERNAL_SCSIIO_CMDS_COUNT
) {
1482 u32 unique_tag
= smid
- 1;
1484 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1487 * If SCSI IO request is outstanding at driver level then
1488 * DevHandle filed must be non-zero. If DevHandle is zero
1489 * then it means that this smid is free at driver level,
1492 if (!mpi_request
->DevHandle
)
1495 scmd
= scsi_host_find_tag(ioc
->shost
, unique_tag
);
1497 st
= scsi_cmd_priv(scmd
);
1498 if (st
->cb_idx
== 0xFF || st
->smid
== 0)
1506 * scsih_change_queue_depth - setting device queue depth
1507 * @sdev: scsi device struct
1508 * @qdepth: requested queue depth
1510 * Return: queue depth.
1513 scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1515 struct Scsi_Host
*shost
= sdev
->host
;
1517 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1518 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1519 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1520 struct _sas_device
*sas_device
;
1521 unsigned long flags
;
1523 max_depth
= shost
->can_queue
;
1526 * limit max device queue for SATA to 32 if enable_sdev_max_qd
1529 if (ioc
->enable_sdev_max_qd
)
1532 sas_device_priv_data
= sdev
->hostdata
;
1533 if (!sas_device_priv_data
)
1535 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
1536 if (!sas_target_priv_data
)
1538 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
))
1541 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1542 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1544 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
1545 max_depth
= MPT3SAS_SATA_QUEUE_DEPTH
;
1547 sas_device_put(sas_device
);
1549 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1553 if (!sdev
->tagged_supported
)
1555 if (qdepth
> max_depth
)
1557 return scsi_change_queue_depth(sdev
, qdepth
);
1561 * mpt3sas_scsih_change_queue_depth - setting device queue depth
1562 * @sdev: scsi device struct
1563 * @qdepth: requested queue depth
1568 mpt3sas_scsih_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
1570 struct Scsi_Host
*shost
= sdev
->host
;
1571 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1573 if (ioc
->enable_sdev_max_qd
)
1574 qdepth
= shost
->can_queue
;
1576 scsih_change_queue_depth(sdev
, qdepth
);
1580 * scsih_target_alloc - target add routine
1581 * @starget: scsi target struct
1583 * Return: 0 if ok. Any other return is assumed to be an error and
1584 * the device is ignored.
1587 scsih_target_alloc(struct scsi_target
*starget
)
1589 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1590 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1591 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1592 struct _sas_device
*sas_device
;
1593 struct _raid_device
*raid_device
;
1594 struct _pcie_device
*pcie_device
;
1595 unsigned long flags
;
1596 struct sas_rphy
*rphy
;
1598 sas_target_priv_data
= kzalloc(sizeof(*sas_target_priv_data
),
1600 if (!sas_target_priv_data
)
1603 starget
->hostdata
= sas_target_priv_data
;
1604 sas_target_priv_data
->starget
= starget
;
1605 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
1608 if (starget
->channel
== RAID_CHANNEL
) {
1609 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1610 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1613 sas_target_priv_data
->handle
= raid_device
->handle
;
1614 sas_target_priv_data
->sas_address
= raid_device
->wwid
;
1615 sas_target_priv_data
->flags
|= MPT_TARGET_FLAGS_VOLUME
;
1616 if (ioc
->is_warpdrive
)
1617 sas_target_priv_data
->raid_device
= raid_device
;
1618 raid_device
->starget
= starget
;
1620 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1625 if (starget
->channel
== PCIE_CHANNEL
) {
1626 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1627 pcie_device
= __mpt3sas_get_pdev_by_idchannel(ioc
, starget
->id
,
1630 sas_target_priv_data
->handle
= pcie_device
->handle
;
1631 sas_target_priv_data
->sas_address
= pcie_device
->wwid
;
1632 sas_target_priv_data
->pcie_dev
= pcie_device
;
1633 pcie_device
->starget
= starget
;
1634 pcie_device
->id
= starget
->id
;
1635 pcie_device
->channel
= starget
->channel
;
1636 sas_target_priv_data
->flags
|=
1637 MPT_TARGET_FLAGS_PCIE_DEVICE
;
1638 if (pcie_device
->fast_path
)
1639 sas_target_priv_data
->flags
|=
1640 MPT_TARGET_FASTPATH_IO
;
1642 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1646 /* sas/sata devices */
1647 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1648 rphy
= dev_to_rphy(starget
->dev
.parent
);
1649 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1650 rphy
->identify
.sas_address
);
1653 sas_target_priv_data
->handle
= sas_device
->handle
;
1654 sas_target_priv_data
->sas_address
= sas_device
->sas_address
;
1655 sas_target_priv_data
->sas_dev
= sas_device
;
1656 sas_device
->starget
= starget
;
1657 sas_device
->id
= starget
->id
;
1658 sas_device
->channel
= starget
->channel
;
1659 if (test_bit(sas_device
->handle
, ioc
->pd_handles
))
1660 sas_target_priv_data
->flags
|=
1661 MPT_TARGET_FLAGS_RAID_COMPONENT
;
1662 if (sas_device
->fast_path
)
1663 sas_target_priv_data
->flags
|=
1664 MPT_TARGET_FASTPATH_IO
;
1666 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1672 * scsih_target_destroy - target destroy routine
1673 * @starget: scsi target struct
1676 scsih_target_destroy(struct scsi_target
*starget
)
1678 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
1679 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
1680 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1681 struct _sas_device
*sas_device
;
1682 struct _raid_device
*raid_device
;
1683 struct _pcie_device
*pcie_device
;
1684 unsigned long flags
;
1686 sas_target_priv_data
= starget
->hostdata
;
1687 if (!sas_target_priv_data
)
1690 if (starget
->channel
== RAID_CHANNEL
) {
1691 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1692 raid_device
= _scsih_raid_device_find_by_id(ioc
, starget
->id
,
1695 raid_device
->starget
= NULL
;
1696 raid_device
->sdev
= NULL
;
1698 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1702 if (starget
->channel
== PCIE_CHANNEL
) {
1703 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1704 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1705 sas_target_priv_data
);
1706 if (pcie_device
&& (pcie_device
->starget
== starget
) &&
1707 (pcie_device
->id
== starget
->id
) &&
1708 (pcie_device
->channel
== starget
->channel
))
1709 pcie_device
->starget
= NULL
;
1713 * Corresponding get() is in _scsih_target_alloc()
1715 sas_target_priv_data
->pcie_dev
= NULL
;
1716 pcie_device_put(pcie_device
);
1717 pcie_device_put(pcie_device
);
1719 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1723 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1724 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, sas_target_priv_data
);
1725 if (sas_device
&& (sas_device
->starget
== starget
) &&
1726 (sas_device
->id
== starget
->id
) &&
1727 (sas_device
->channel
== starget
->channel
))
1728 sas_device
->starget
= NULL
;
1732 * Corresponding get() is in _scsih_target_alloc()
1734 sas_target_priv_data
->sas_dev
= NULL
;
1735 sas_device_put(sas_device
);
1737 sas_device_put(sas_device
);
1739 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1742 kfree(sas_target_priv_data
);
1743 starget
->hostdata
= NULL
;
1747 * scsih_slave_alloc - device add routine
1748 * @sdev: scsi device struct
1750 * Return: 0 if ok. Any other return is assumed to be an error and
1751 * the device is ignored.
1754 scsih_slave_alloc(struct scsi_device
*sdev
)
1756 struct Scsi_Host
*shost
;
1757 struct MPT3SAS_ADAPTER
*ioc
;
1758 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1759 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
1760 struct scsi_target
*starget
;
1761 struct _raid_device
*raid_device
;
1762 struct _sas_device
*sas_device
;
1763 struct _pcie_device
*pcie_device
;
1764 unsigned long flags
;
1766 sas_device_priv_data
= kzalloc(sizeof(*sas_device_priv_data
),
1768 if (!sas_device_priv_data
)
1771 sas_device_priv_data
->lun
= sdev
->lun
;
1772 sas_device_priv_data
->flags
= MPT_DEVICE_FLAGS_INIT
;
1774 starget
= scsi_target(sdev
);
1775 sas_target_priv_data
= starget
->hostdata
;
1776 sas_target_priv_data
->num_luns
++;
1777 sas_device_priv_data
->sas_target
= sas_target_priv_data
;
1778 sdev
->hostdata
= sas_device_priv_data
;
1779 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
))
1780 sdev
->no_uld_attach
= 1;
1782 shost
= dev_to_shost(&starget
->dev
);
1783 ioc
= shost_priv(shost
);
1784 if (starget
->channel
== RAID_CHANNEL
) {
1785 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1786 raid_device
= _scsih_raid_device_find_by_id(ioc
,
1787 starget
->id
, starget
->channel
);
1789 raid_device
->sdev
= sdev
; /* raid is single lun */
1790 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1792 if (starget
->channel
== PCIE_CHANNEL
) {
1793 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1794 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
1795 sas_target_priv_data
->sas_address
);
1796 if (pcie_device
&& (pcie_device
->starget
== NULL
)) {
1797 sdev_printk(KERN_INFO
, sdev
,
1798 "%s : pcie_device->starget set to starget @ %d\n",
1799 __func__
, __LINE__
);
1800 pcie_device
->starget
= starget
;
1804 pcie_device_put(pcie_device
);
1805 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1807 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1808 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1809 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
1810 sas_target_priv_data
->sas_address
);
1811 if (sas_device
&& (sas_device
->starget
== NULL
)) {
1812 sdev_printk(KERN_INFO
, sdev
,
1813 "%s : sas_device->starget set to starget @ %d\n",
1814 __func__
, __LINE__
);
1815 sas_device
->starget
= starget
;
1819 sas_device_put(sas_device
);
1821 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1828 * scsih_slave_destroy - device destroy routine
1829 * @sdev: scsi device struct
1832 scsih_slave_destroy(struct scsi_device
*sdev
)
1834 struct MPT3SAS_TARGET
*sas_target_priv_data
;
1835 struct scsi_target
*starget
;
1836 struct Scsi_Host
*shost
;
1837 struct MPT3SAS_ADAPTER
*ioc
;
1838 struct _sas_device
*sas_device
;
1839 struct _pcie_device
*pcie_device
;
1840 unsigned long flags
;
1842 if (!sdev
->hostdata
)
1845 starget
= scsi_target(sdev
);
1846 sas_target_priv_data
= starget
->hostdata
;
1847 sas_target_priv_data
->num_luns
--;
1849 shost
= dev_to_shost(&starget
->dev
);
1850 ioc
= shost_priv(shost
);
1852 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
1853 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1854 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
,
1855 sas_target_priv_data
);
1856 if (pcie_device
&& !sas_target_priv_data
->num_luns
)
1857 pcie_device
->starget
= NULL
;
1860 pcie_device_put(pcie_device
);
1862 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1864 } else if (!(sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)) {
1865 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1866 sas_device
= __mpt3sas_get_sdev_from_target(ioc
,
1867 sas_target_priv_data
);
1868 if (sas_device
&& !sas_target_priv_data
->num_luns
)
1869 sas_device
->starget
= NULL
;
1872 sas_device_put(sas_device
);
1873 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1876 kfree(sdev
->hostdata
);
1877 sdev
->hostdata
= NULL
;
1881 * _scsih_display_sata_capabilities - sata capabilities
1882 * @ioc: per adapter object
1883 * @handle: device handle
1884 * @sdev: scsi device struct
1887 _scsih_display_sata_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
1888 u16 handle
, struct scsi_device
*sdev
)
1890 Mpi2ConfigReply_t mpi_reply
;
1891 Mpi2SasDevicePage0_t sas_device_pg0
;
1896 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
1897 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
1898 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
1899 __FILE__
, __LINE__
, __func__
);
1903 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
1904 MPI2_IOCSTATUS_MASK
;
1905 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
1906 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
1907 __FILE__
, __LINE__
, __func__
);
1911 flags
= le16_to_cpu(sas_device_pg0
.Flags
);
1912 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
1914 sdev_printk(KERN_INFO
, sdev
,
1915 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1916 "sw_preserve(%s)\n",
1917 (device_info
& MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE
) ? "y" : "n",
1918 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED
) ? "y" : "n",
1919 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY
) ? "y" :
1921 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED
) ? "y" : "n",
1922 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED
) ? "y" : "n",
1923 (flags
& MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE
) ? "y" : "n");
1927 * raid transport support -
1928 * Enabled for SLES11 and newer, in older kernels the driver will panic when
1929 * unloading the driver followed by a load - I believe that the subroutine
1930 * raid_class_release() is not cleaning up properly.
1934 * scsih_is_raid - return boolean indicating device is raid volume
1935 * @dev: the device struct object
1938 scsih_is_raid(struct device
*dev
)
1940 struct scsi_device
*sdev
= to_scsi_device(dev
);
1941 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1943 if (ioc
->is_warpdrive
)
1945 return (sdev
->channel
== RAID_CHANNEL
) ? 1 : 0;
1949 scsih_is_nvme(struct device
*dev
)
1951 struct scsi_device
*sdev
= to_scsi_device(dev
);
1953 return (sdev
->channel
== PCIE_CHANNEL
) ? 1 : 0;
1957 * scsih_get_resync - get raid volume resync percent complete
1958 * @dev: the device struct object
1961 scsih_get_resync(struct device
*dev
)
1963 struct scsi_device
*sdev
= to_scsi_device(dev
);
1964 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
1965 static struct _raid_device
*raid_device
;
1966 unsigned long flags
;
1967 Mpi2RaidVolPage0_t vol_pg0
;
1968 Mpi2ConfigReply_t mpi_reply
;
1969 u32 volume_status_flags
;
1970 u8 percent_complete
;
1973 percent_complete
= 0;
1975 if (ioc
->is_warpdrive
)
1978 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1979 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
1982 handle
= raid_device
->handle
;
1983 percent_complete
= raid_device
->percent_complete
;
1985 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1990 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
1991 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
1992 sizeof(Mpi2RaidVolPage0_t
))) {
1993 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
1994 __FILE__
, __LINE__
, __func__
);
1995 percent_complete
= 0;
1999 volume_status_flags
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2000 if (!(volume_status_flags
&
2001 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
))
2002 percent_complete
= 0;
2006 switch (ioc
->hba_mpi_version_belonged
) {
2008 raid_set_resync(mpt2sas_raid_template
, dev
, percent_complete
);
2012 raid_set_resync(mpt3sas_raid_template
, dev
, percent_complete
);
2018 * scsih_get_state - get raid volume level
2019 * @dev: the device struct object
2022 scsih_get_state(struct device
*dev
)
2024 struct scsi_device
*sdev
= to_scsi_device(dev
);
2025 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(sdev
->host
);
2026 static struct _raid_device
*raid_device
;
2027 unsigned long flags
;
2028 Mpi2RaidVolPage0_t vol_pg0
;
2029 Mpi2ConfigReply_t mpi_reply
;
2031 enum raid_state state
= RAID_STATE_UNKNOWN
;
2034 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2035 raid_device
= _scsih_raid_device_find_by_id(ioc
, sdev
->id
,
2038 handle
= raid_device
->handle
;
2039 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2044 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, &vol_pg0
,
2045 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
2046 sizeof(Mpi2RaidVolPage0_t
))) {
2047 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
2048 __FILE__
, __LINE__
, __func__
);
2052 volstate
= le32_to_cpu(vol_pg0
.VolumeStatusFlags
);
2053 if (volstate
& MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
2054 state
= RAID_STATE_RESYNCING
;
2058 switch (vol_pg0
.VolumeState
) {
2059 case MPI2_RAID_VOL_STATE_OPTIMAL
:
2060 case MPI2_RAID_VOL_STATE_ONLINE
:
2061 state
= RAID_STATE_ACTIVE
;
2063 case MPI2_RAID_VOL_STATE_DEGRADED
:
2064 state
= RAID_STATE_DEGRADED
;
2066 case MPI2_RAID_VOL_STATE_FAILED
:
2067 case MPI2_RAID_VOL_STATE_MISSING
:
2068 state
= RAID_STATE_OFFLINE
;
2072 switch (ioc
->hba_mpi_version_belonged
) {
2074 raid_set_state(mpt2sas_raid_template
, dev
, state
);
2078 raid_set_state(mpt3sas_raid_template
, dev
, state
);
2084 * _scsih_set_level - set raid level
2086 * @sdev: scsi device struct
2087 * @volume_type: volume type
2090 _scsih_set_level(struct MPT3SAS_ADAPTER
*ioc
,
2091 struct scsi_device
*sdev
, u8 volume_type
)
2093 enum raid_level level
= RAID_LEVEL_UNKNOWN
;
2095 switch (volume_type
) {
2096 case MPI2_RAID_VOL_TYPE_RAID0
:
2097 level
= RAID_LEVEL_0
;
2099 case MPI2_RAID_VOL_TYPE_RAID10
:
2100 level
= RAID_LEVEL_10
;
2102 case MPI2_RAID_VOL_TYPE_RAID1E
:
2103 level
= RAID_LEVEL_1E
;
2105 case MPI2_RAID_VOL_TYPE_RAID1
:
2106 level
= RAID_LEVEL_1
;
2110 switch (ioc
->hba_mpi_version_belonged
) {
2112 raid_set_level(mpt2sas_raid_template
,
2113 &sdev
->sdev_gendev
, level
);
2117 raid_set_level(mpt3sas_raid_template
,
2118 &sdev
->sdev_gendev
, level
);
2125 * _scsih_get_volume_capabilities - volume capabilities
2126 * @ioc: per adapter object
2127 * @raid_device: the raid_device object
2129 * Return: 0 for success, else 1
2132 _scsih_get_volume_capabilities(struct MPT3SAS_ADAPTER
*ioc
,
2133 struct _raid_device
*raid_device
)
2135 Mpi2RaidVolPage0_t
*vol_pg0
;
2136 Mpi2RaidPhysDiskPage0_t pd_pg0
;
2137 Mpi2SasDevicePage0_t sas_device_pg0
;
2138 Mpi2ConfigReply_t mpi_reply
;
2142 if ((mpt3sas_config_get_number_pds(ioc
, raid_device
->handle
,
2143 &num_pds
)) || !num_pds
) {
2145 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2146 __FILE__
, __LINE__
, __func__
));
2150 raid_device
->num_pds
= num_pds
;
2151 sz
= offsetof(Mpi2RaidVolPage0_t
, PhysDisk
) + (num_pds
*
2152 sizeof(Mpi2RaidVol0PhysDisk_t
));
2153 vol_pg0
= kzalloc(sz
, GFP_KERNEL
);
2156 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2157 __FILE__
, __LINE__
, __func__
));
2161 if ((mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
, vol_pg0
,
2162 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, raid_device
->handle
, sz
))) {
2164 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2165 __FILE__
, __LINE__
, __func__
));
2170 raid_device
->volume_type
= vol_pg0
->VolumeType
;
2172 /* figure out what the underlying devices are by
2173 * obtaining the device_info bits for the 1st device
2175 if (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
2176 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM
,
2177 vol_pg0
->PhysDisk
[0].PhysDiskNum
))) {
2178 if (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
2179 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
2180 le16_to_cpu(pd_pg0
.DevHandle
)))) {
2181 raid_device
->device_info
=
2182 le32_to_cpu(sas_device_pg0
.DeviceInfo
);
2191 * _scsih_enable_tlr - setting TLR flags
2192 * @ioc: per adapter object
2193 * @sdev: scsi device struct
2195 * Enabling Transaction Layer Retries for tape devices when
2196 * vpd page 0x90 is present
2200 _scsih_enable_tlr(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_device
*sdev
)
2204 if (sdev
->type
!= TYPE_TAPE
)
2207 if (!(ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
))
2210 sas_enable_tlr(sdev
);
2211 sdev_printk(KERN_INFO
, sdev
, "TLR %s\n",
2212 sas_is_tlr_enabled(sdev
) ? "Enabled" : "Disabled");
2218 * scsih_slave_configure - device configure routine.
2219 * @sdev: scsi device struct
2221 * Return: 0 if ok. Any other return is assumed to be an error and
2222 * the device is ignored.
2225 scsih_slave_configure(struct scsi_device
*sdev
)
2227 struct Scsi_Host
*shost
= sdev
->host
;
2228 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2229 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2230 struct MPT3SAS_TARGET
*sas_target_priv_data
;
2231 struct _sas_device
*sas_device
;
2232 struct _pcie_device
*pcie_device
;
2233 struct _raid_device
*raid_device
;
2234 unsigned long flags
;
2239 u16 handle
, volume_handle
= 0;
2240 u64 volume_wwid
= 0;
2243 sas_device_priv_data
= sdev
->hostdata
;
2244 sas_device_priv_data
->configured_lun
= 1;
2245 sas_device_priv_data
->flags
&= ~MPT_DEVICE_FLAGS_INIT
;
2246 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
2247 handle
= sas_target_priv_data
->handle
;
2249 /* raid volume handling */
2250 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2252 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
2253 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
2254 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
2257 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2258 __FILE__
, __LINE__
, __func__
));
2262 if (_scsih_get_volume_capabilities(ioc
, raid_device
)) {
2264 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2265 __FILE__
, __LINE__
, __func__
));
2270 * WARPDRIVE: Initialize the required data for Direct IO
2272 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
2274 /* RAID Queue Depth Support
2275 * IS volume = underlying qdepth of drive type, either
2276 * MPT3SAS_SAS_QUEUE_DEPTH or MPT3SAS_SATA_QUEUE_DEPTH
2277 * IM/IME/R10 = 128 (MPT3SAS_RAID_QUEUE_DEPTH)
2279 if (raid_device
->device_info
&
2280 MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2281 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2284 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2285 if (raid_device
->device_info
&
2286 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2292 switch (raid_device
->volume_type
) {
2293 case MPI2_RAID_VOL_TYPE_RAID0
:
2296 case MPI2_RAID_VOL_TYPE_RAID1E
:
2297 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2298 if (ioc
->manu_pg10
.OEMIdentifier
&&
2299 (le32_to_cpu(ioc
->manu_pg10
.GenericFlags0
) &
2300 MFG10_GF0_R10_DISPLAY
) &&
2301 !(raid_device
->num_pds
% 2))
2306 case MPI2_RAID_VOL_TYPE_RAID1
:
2307 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2310 case MPI2_RAID_VOL_TYPE_RAID10
:
2311 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2314 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
2316 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
2321 if (!ioc
->hide_ir_msg
)
2322 sdev_printk(KERN_INFO
, sdev
,
2323 "%s: handle(0x%04x), wwid(0x%016llx),"
2324 " pd_count(%d), type(%s)\n",
2325 r_level
, raid_device
->handle
,
2326 (unsigned long long)raid_device
->wwid
,
2327 raid_device
->num_pds
, ds
);
2329 if (shost
->max_sectors
> MPT3SAS_RAID_MAX_SECTORS
) {
2330 blk_queue_max_hw_sectors(sdev
->request_queue
,
2331 MPT3SAS_RAID_MAX_SECTORS
);
2332 sdev_printk(KERN_INFO
, sdev
,
2333 "Set queue's max_sector to: %u\n",
2334 MPT3SAS_RAID_MAX_SECTORS
);
2337 mpt3sas_scsih_change_queue_depth(sdev
, qdepth
);
2339 /* raid transport support */
2340 if (!ioc
->is_warpdrive
)
2341 _scsih_set_level(ioc
, sdev
, raid_device
->volume_type
);
2345 /* non-raid handling */
2346 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2347 if (mpt3sas_config_get_volume_handle(ioc
, handle
,
2350 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2351 __FILE__
, __LINE__
, __func__
));
2354 if (volume_handle
&& mpt3sas_config_get_volume_wwid(ioc
,
2355 volume_handle
, &volume_wwid
)) {
2357 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2358 __FILE__
, __LINE__
, __func__
));
2364 if (sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2365 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2366 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
,
2367 sas_device_priv_data
->sas_target
->sas_address
);
2369 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2371 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2372 __FILE__
, __LINE__
, __func__
));
2376 qdepth
= MPT3SAS_NVME_QUEUE_DEPTH
;
2378 sdev_printk(KERN_INFO
, sdev
,
2379 "%s: handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2380 ds
, handle
, (unsigned long long)pcie_device
->wwid
,
2381 pcie_device
->port_num
);
2382 if (pcie_device
->enclosure_handle
!= 0)
2383 sdev_printk(KERN_INFO
, sdev
,
2384 "%s: enclosure logical id(0x%016llx), slot(%d)\n",
2386 (unsigned long long)pcie_device
->enclosure_logical_id
,
2388 if (pcie_device
->connector_name
[0] != '\0')
2389 sdev_printk(KERN_INFO
, sdev
,
2390 "%s: enclosure level(0x%04x),"
2391 "connector name( %s)\n", ds
,
2392 pcie_device
->enclosure_level
,
2393 pcie_device
->connector_name
);
2395 if (pcie_device
->nvme_mdts
)
2396 blk_queue_max_hw_sectors(sdev
->request_queue
,
2397 pcie_device
->nvme_mdts
/512);
2399 pcie_device_put(pcie_device
);
2400 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2401 mpt3sas_scsih_change_queue_depth(sdev
, qdepth
);
2402 /* Enable QUEUE_FLAG_NOMERGES flag, so that IOs won't be
2403 ** merged and can eliminate holes created during merging
2406 blk_queue_flag_set(QUEUE_FLAG_NOMERGES
,
2407 sdev
->request_queue
);
2408 blk_queue_virt_boundary(sdev
->request_queue
,
2409 ioc
->page_size
- 1);
2413 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2414 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
2415 sas_device_priv_data
->sas_target
->sas_address
);
2417 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2419 ioc_warn(ioc
, "failure at %s:%d/%s()!\n",
2420 __FILE__
, __LINE__
, __func__
));
2424 sas_device
->volume_handle
= volume_handle
;
2425 sas_device
->volume_wwid
= volume_wwid
;
2426 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_SSP_TARGET
) {
2427 qdepth
= MPT3SAS_SAS_QUEUE_DEPTH
;
2429 if (sas_device
->device_info
&
2430 MPI2_SAS_DEVICE_INFO_SEP
) {
2431 sdev_printk(KERN_WARNING
, sdev
,
2432 "set ignore_delay_remove for handle(0x%04x)\n",
2433 sas_device_priv_data
->sas_target
->handle
);
2434 sas_device_priv_data
->ignore_delay_remove
= 1;
2439 qdepth
= MPT3SAS_SATA_QUEUE_DEPTH
;
2440 if (sas_device
->device_info
& MPI2_SAS_DEVICE_INFO_STP_TARGET
)
2442 else if (sas_device
->device_info
&
2443 MPI2_SAS_DEVICE_INFO_SATA_DEVICE
)
2447 sdev_printk(KERN_INFO
, sdev
, "%s: handle(0x%04x), " \
2448 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2449 ds
, handle
, (unsigned long long)sas_device
->sas_address
,
2450 sas_device
->phy
, (unsigned long long)sas_device
->device_name
);
2452 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, sdev
, NULL
);
2454 sas_device_put(sas_device
);
2455 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2458 _scsih_display_sata_capabilities(ioc
, handle
, sdev
);
2461 mpt3sas_scsih_change_queue_depth(sdev
, qdepth
);
2464 sas_read_port_mode_page(sdev
);
2465 _scsih_enable_tlr(ioc
, sdev
);
2472 * scsih_bios_param - fetch head, sector, cylinder info for a disk
2473 * @sdev: scsi device struct
2474 * @bdev: pointer to block device context
2475 * @capacity: device size (in 512 byte sectors)
2476 * @params: three element array to place output:
2477 * params[0] number of heads (max 255)
2478 * params[1] number of sectors (max 63)
2479 * params[2] number of cylinders
2482 scsih_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2483 sector_t capacity
, int params
[])
2493 dummy
= heads
* sectors
;
2494 cylinders
= capacity
;
2495 sector_div(cylinders
, dummy
);
2498 * Handle extended translation size for logical drives
2501 if ((ulong
)capacity
>= 0x200000) {
2504 dummy
= heads
* sectors
;
2505 cylinders
= capacity
;
2506 sector_div(cylinders
, dummy
);
2511 params
[1] = sectors
;
2512 params
[2] = cylinders
;
2518 * _scsih_response_code - translation of device response code
2519 * @ioc: per adapter object
2520 * @response_code: response code returned by the device
2523 _scsih_response_code(struct MPT3SAS_ADAPTER
*ioc
, u8 response_code
)
2527 switch (response_code
) {
2528 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2529 desc
= "task management request completed";
2531 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2532 desc
= "invalid frame";
2534 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2535 desc
= "task management request not supported";
2537 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2538 desc
= "task management request failed";
2540 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2541 desc
= "task management request succeeded";
2543 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2544 desc
= "invalid lun";
2547 desc
= "overlapped tag attempted";
2549 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2550 desc
= "task queued, however not sent to target";
2556 ioc_warn(ioc
, "response_code(0x%01x): %s\n", response_code
, desc
);
2560 * _scsih_tm_done - tm completion routine
2561 * @ioc: per adapter object
2562 * @smid: system request message index
2563 * @msix_index: MSIX table index supplied by the OS
2564 * @reply: reply message frame(lower 32bit addr)
2567 * The callback handler when using scsih_issue_tm.
2569 * Return: 1 meaning mf should be freed from _base_interrupt
2570 * 0 means the mf is freed from this function.
2573 _scsih_tm_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
2575 MPI2DefaultReply_t
*mpi_reply
;
2577 if (ioc
->tm_cmds
.status
== MPT3_CMD_NOT_USED
)
2579 if (ioc
->tm_cmds
.smid
!= smid
)
2581 ioc
->tm_cmds
.status
|= MPT3_CMD_COMPLETE
;
2582 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
2584 memcpy(ioc
->tm_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
2585 ioc
->tm_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
2587 ioc
->tm_cmds
.status
&= ~MPT3_CMD_PENDING
;
2588 complete(&ioc
->tm_cmds
.done
);
2593 * mpt3sas_scsih_set_tm_flag - set per target tm_busy
2594 * @ioc: per adapter object
2595 * @handle: device handle
2597 * During taskmangement request, we need to freeze the device queue.
2600 mpt3sas_scsih_set_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2602 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2603 struct scsi_device
*sdev
;
2606 shost_for_each_device(sdev
, ioc
->shost
) {
2609 sas_device_priv_data
= sdev
->hostdata
;
2610 if (!sas_device_priv_data
)
2612 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2613 sas_device_priv_data
->sas_target
->tm_busy
= 1;
2615 ioc
->ignore_loginfos
= 1;
2621 * mpt3sas_scsih_clear_tm_flag - clear per target tm_busy
2622 * @ioc: per adapter object
2623 * @handle: device handle
2625 * During taskmangement request, we need to freeze the device queue.
2628 mpt3sas_scsih_clear_tm_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
2630 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2631 struct scsi_device
*sdev
;
2634 shost_for_each_device(sdev
, ioc
->shost
) {
2637 sas_device_priv_data
= sdev
->hostdata
;
2638 if (!sas_device_priv_data
)
2640 if (sas_device_priv_data
->sas_target
->handle
== handle
) {
2641 sas_device_priv_data
->sas_target
->tm_busy
= 0;
2643 ioc
->ignore_loginfos
= 0;
2649 * mpt3sas_scsih_issue_tm - main routine for sending tm requests
2650 * @ioc: per adapter struct
2651 * @handle: device handle
2653 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2654 * @smid_task: smid assigned to the task
2655 * @msix_task: MSIX table index supplied by the OS
2656 * @timeout: timeout in seconds
2657 * @tr_method: Target Reset Method
2660 * A generic API for sending task management requests to firmware.
2662 * The callback index is set inside `ioc->tm_cb_idx`.
2663 * The caller is responsible to check for outstanding commands.
2665 * Return: SUCCESS or FAILED.
2668 mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u64 lun
,
2669 u8 type
, u16 smid_task
, u16 msix_task
, u8 timeout
, u8 tr_method
)
2671 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
2672 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
2677 lockdep_assert_held(&ioc
->tm_cmds
.mutex
);
2679 if (ioc
->tm_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2680 ioc_info(ioc
, "%s: tm_cmd busy!!!\n", __func__
);
2684 if (ioc
->shost_recovery
|| ioc
->remove_host
||
2685 ioc
->pci_error_recovery
) {
2686 ioc_info(ioc
, "%s: host reset in progress!\n", __func__
);
2690 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
2691 if (ioc_state
& MPI2_DOORBELL_USED
) {
2692 dhsprintk(ioc
, ioc_info(ioc
, "unexpected doorbell active!\n"));
2693 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2694 return (!rc
) ? SUCCESS
: FAILED
;
2697 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
2698 mpt3sas_base_fault_info(ioc
, ioc_state
&
2699 MPI2_DOORBELL_DATA_MASK
);
2700 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2701 return (!rc
) ? SUCCESS
: FAILED
;
2704 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_cb_idx
);
2706 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
2711 ioc_info(ioc
, "sending tm: handle(0x%04x), task_type(0x%02x), smid(%d), timeout(%d), tr_method(0x%x)\n",
2712 handle
, type
, smid_task
, timeout
, tr_method
));
2713 ioc
->tm_cmds
.status
= MPT3_CMD_PENDING
;
2714 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2715 ioc
->tm_cmds
.smid
= smid
;
2716 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
2717 memset(ioc
->tm_cmds
.reply
, 0, sizeof(Mpi2SCSITaskManagementReply_t
));
2718 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
2719 mpi_request
->DevHandle
= cpu_to_le16(handle
);
2720 mpi_request
->TaskType
= type
;
2721 mpi_request
->MsgFlags
= tr_method
;
2722 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
2723 int_to_scsilun(lun
, (struct scsi_lun
*)mpi_request
->LUN
);
2724 mpt3sas_scsih_set_tm_flag(ioc
, handle
);
2725 init_completion(&ioc
->tm_cmds
.done
);
2726 ioc
->put_smid_hi_priority(ioc
, smid
, msix_task
);
2727 wait_for_completion_timeout(&ioc
->tm_cmds
.done
, timeout
*HZ
);
2728 if (!(ioc
->tm_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2729 if (mpt3sas_base_check_cmd_timeout(ioc
,
2730 ioc
->tm_cmds
.status
, mpi_request
,
2731 sizeof(Mpi2SCSITaskManagementRequest_t
)/4)) {
2732 rc
= mpt3sas_base_hard_reset_handler(ioc
,
2734 rc
= (!rc
) ? SUCCESS
: FAILED
;
2739 /* sync IRQs in case those were busy during flush. */
2740 mpt3sas_base_sync_reply_irqs(ioc
);
2742 if (ioc
->tm_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
2743 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
2744 mpi_reply
= ioc
->tm_cmds
.reply
;
2746 ioc_info(ioc
, "complete tm: ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2747 le16_to_cpu(mpi_reply
->IOCStatus
),
2748 le32_to_cpu(mpi_reply
->IOCLogInfo
),
2749 le32_to_cpu(mpi_reply
->TerminationCount
)));
2750 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
2751 _scsih_response_code(ioc
, mpi_reply
->ResponseCode
);
2752 if (mpi_reply
->IOCStatus
)
2753 _debug_dump_mf(mpi_request
,
2754 sizeof(Mpi2SCSITaskManagementRequest_t
)/4);
2760 mpt3sas_scsih_clear_tm_flag(ioc
, handle
);
2761 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
2765 int mpt3sas_scsih_issue_locked_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
,
2766 u64 lun
, u8 type
, u16 smid_task
, u16 msix_task
,
2767 u8 timeout
, u8 tr_method
)
2771 mutex_lock(&ioc
->tm_cmds
.mutex
);
2772 ret
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
, type
, smid_task
,
2773 msix_task
, timeout
, tr_method
);
2774 mutex_unlock(&ioc
->tm_cmds
.mutex
);
2780 * _scsih_tm_display_info - displays info about the device
2781 * @ioc: per adapter struct
2782 * @scmd: pointer to scsi command object
2784 * Called by task management callback handlers.
2787 _scsih_tm_display_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
)
2789 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2790 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
2791 struct _sas_device
*sas_device
= NULL
;
2792 struct _pcie_device
*pcie_device
= NULL
;
2793 unsigned long flags
;
2794 char *device_str
= NULL
;
2798 if (ioc
->hide_ir_msg
)
2799 device_str
= "WarpDrive";
2801 device_str
= "volume";
2803 scsi_print_command(scmd
);
2804 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2805 starget_printk(KERN_INFO
, starget
,
2806 "%s handle(0x%04x), %s wwid(0x%016llx)\n",
2807 device_str
, priv_target
->handle
,
2808 device_str
, (unsigned long long)priv_target
->sas_address
);
2810 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
2811 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
2812 pcie_device
= __mpt3sas_get_pdev_from_target(ioc
, priv_target
);
2814 starget_printk(KERN_INFO
, starget
,
2815 "handle(0x%04x), wwid(0x%016llx), port(%d)\n",
2816 pcie_device
->handle
,
2817 (unsigned long long)pcie_device
->wwid
,
2818 pcie_device
->port_num
);
2819 if (pcie_device
->enclosure_handle
!= 0)
2820 starget_printk(KERN_INFO
, starget
,
2821 "enclosure logical id(0x%016llx), slot(%d)\n",
2822 (unsigned long long)
2823 pcie_device
->enclosure_logical_id
,
2825 if (pcie_device
->connector_name
[0] != '\0')
2826 starget_printk(KERN_INFO
, starget
,
2827 "enclosure level(0x%04x), connector name( %s)\n",
2828 pcie_device
->enclosure_level
,
2829 pcie_device
->connector_name
);
2830 pcie_device_put(pcie_device
);
2832 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
2835 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
2836 sas_device
= __mpt3sas_get_sdev_from_target(ioc
, priv_target
);
2838 if (priv_target
->flags
&
2839 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2840 starget_printk(KERN_INFO
, starget
,
2841 "volume handle(0x%04x), "
2842 "volume wwid(0x%016llx)\n",
2843 sas_device
->volume_handle
,
2844 (unsigned long long)sas_device
->volume_wwid
);
2846 starget_printk(KERN_INFO
, starget
,
2847 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2849 (unsigned long long)sas_device
->sas_address
,
2852 _scsih_display_enclosure_chassis_info(NULL
, sas_device
,
2855 sas_device_put(sas_device
);
2857 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
2862 * scsih_abort - eh threads main abort routine
2863 * @scmd: pointer to scsi command object
2865 * Return: SUCCESS if command aborted else FAILED
2868 scsih_abort(struct scsi_cmnd
*scmd
)
2870 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2871 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2872 struct scsiio_tracker
*st
= scsi_cmd_priv(scmd
);
2877 struct _pcie_device
*pcie_device
= NULL
;
2878 sdev_printk(KERN_INFO
, scmd
->device
,
2879 "attempting task abort! scmd(%p)\n", scmd
);
2880 _scsih_tm_display_info(ioc
, scmd
);
2882 sas_device_priv_data
= scmd
->device
->hostdata
;
2883 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2885 sdev_printk(KERN_INFO
, scmd
->device
,
2886 "device been deleted! scmd(%p)\n", scmd
);
2887 scmd
->result
= DID_NO_CONNECT
<< 16;
2888 scmd
->scsi_done(scmd
);
2893 /* check for completed command */
2894 if (st
== NULL
|| st
->cb_idx
== 0xFF) {
2895 scmd
->result
= DID_RESET
<< 16;
2900 /* for hidden raid components and volumes this is not supported */
2901 if (sas_device_priv_data
->sas_target
->flags
&
2902 MPT_TARGET_FLAGS_RAID_COMPONENT
||
2903 sas_device_priv_data
->sas_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
2904 scmd
->result
= DID_RESET
<< 16;
2909 mpt3sas_halt_firmware(ioc
);
2911 handle
= sas_device_priv_data
->sas_target
->handle
;
2912 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
2913 if (pcie_device
&& (!ioc
->tm_custom_handling
) &&
2914 (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device
->device_info
))))
2915 timeout
= ioc
->nvme_abort_timeout
;
2916 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2917 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
,
2918 st
->smid
, st
->msix_io
, timeout
, 0);
2919 /* Command must be cleared after abort */
2920 if (r
== SUCCESS
&& st
->cb_idx
!= 0xFF)
2923 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
2924 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
2926 pcie_device_put(pcie_device
);
2931 * scsih_dev_reset - eh threads main device reset routine
2932 * @scmd: pointer to scsi command object
2934 * Return: SUCCESS if command aborted else FAILED
2937 scsih_dev_reset(struct scsi_cmnd
*scmd
)
2939 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
2940 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
2941 struct _sas_device
*sas_device
= NULL
;
2942 struct _pcie_device
*pcie_device
= NULL
;
2948 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
2949 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
2951 sdev_printk(KERN_INFO
, scmd
->device
,
2952 "attempting device reset! scmd(%p)\n", scmd
);
2953 _scsih_tm_display_info(ioc
, scmd
);
2955 sas_device_priv_data
= scmd
->device
->hostdata
;
2956 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
2958 sdev_printk(KERN_INFO
, scmd
->device
,
2959 "device been deleted! scmd(%p)\n", scmd
);
2960 scmd
->result
= DID_NO_CONNECT
<< 16;
2961 scmd
->scsi_done(scmd
);
2966 /* for hidden raid components obtain the volume_handle */
2968 if (sas_device_priv_data
->sas_target
->flags
&
2969 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
2970 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
2973 handle
= sas_device
->volume_handle
;
2975 handle
= sas_device_priv_data
->sas_target
->handle
;
2978 scmd
->result
= DID_RESET
<< 16;
2983 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
2985 if (pcie_device
&& (!ioc
->tm_custom_handling
) &&
2986 (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device
->device_info
)))) {
2987 tr_timeout
= pcie_device
->reset_timeout
;
2988 tr_method
= MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
2990 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
2992 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, scmd
->device
->lun
,
2993 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET
, 0, 0,
2994 tr_timeout
, tr_method
);
2995 /* Check for busy commands after reset */
2996 if (r
== SUCCESS
&& atomic_read(&scmd
->device
->device_busy
))
2999 sdev_printk(KERN_INFO
, scmd
->device
, "device reset: %s scmd(%p)\n",
3000 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3003 sas_device_put(sas_device
);
3005 pcie_device_put(pcie_device
);
3011 * scsih_target_reset - eh threads main target reset routine
3012 * @scmd: pointer to scsi command object
3014 * Return: SUCCESS if command aborted else FAILED
3017 scsih_target_reset(struct scsi_cmnd
*scmd
)
3019 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3020 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3021 struct _sas_device
*sas_device
= NULL
;
3022 struct _pcie_device
*pcie_device
= NULL
;
3027 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
3028 struct MPT3SAS_TARGET
*target_priv_data
= starget
->hostdata
;
3030 starget_printk(KERN_INFO
, starget
, "attempting target reset! scmd(%p)\n",
3032 _scsih_tm_display_info(ioc
, scmd
);
3034 sas_device_priv_data
= scmd
->device
->hostdata
;
3035 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
3037 starget_printk(KERN_INFO
, starget
, "target been deleted! scmd(%p)\n",
3039 scmd
->result
= DID_NO_CONNECT
<< 16;
3040 scmd
->scsi_done(scmd
);
3045 /* for hidden raid components obtain the volume_handle */
3047 if (sas_device_priv_data
->sas_target
->flags
&
3048 MPT_TARGET_FLAGS_RAID_COMPONENT
) {
3049 sas_device
= mpt3sas_get_sdev_from_target(ioc
,
3052 handle
= sas_device
->volume_handle
;
3054 handle
= sas_device_priv_data
->sas_target
->handle
;
3057 scmd
->result
= DID_RESET
<< 16;
3062 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
, handle
);
3064 if (pcie_device
&& (!ioc
->tm_custom_handling
) &&
3065 (!(mpt3sas_scsih_is_pcie_scsi_device(pcie_device
->device_info
)))) {
3066 tr_timeout
= pcie_device
->reset_timeout
;
3067 tr_method
= MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
3069 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
3070 r
= mpt3sas_scsih_issue_locked_tm(ioc
, handle
, 0,
3071 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 0,
3072 tr_timeout
, tr_method
);
3073 /* Check for busy commands after reset */
3074 if (r
== SUCCESS
&& atomic_read(&starget
->target_busy
))
3077 starget_printk(KERN_INFO
, starget
, "target reset: %s scmd(%p)\n",
3078 ((r
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3081 sas_device_put(sas_device
);
3083 pcie_device_put(pcie_device
);
3089 * scsih_host_reset - eh threads main host reset routine
3090 * @scmd: pointer to scsi command object
3092 * Return: SUCCESS if command aborted else FAILED
3095 scsih_host_reset(struct scsi_cmnd
*scmd
)
3097 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(scmd
->device
->host
);
3100 ioc_info(ioc
, "attempting host reset! scmd(%p)\n", scmd
);
3101 scsi_print_command(scmd
);
3103 if (ioc
->is_driver_loading
|| ioc
->remove_host
) {
3104 ioc_info(ioc
, "Blocking the host reset\n");
3109 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
3110 r
= (retval
< 0) ? FAILED
: SUCCESS
;
3112 ioc_info(ioc
, "host reset: %s scmd(%p)\n",
3113 r
== SUCCESS
? "SUCCESS" : "FAILED", scmd
);
3119 * _scsih_fw_event_add - insert and queue up fw_event
3120 * @ioc: per adapter object
3121 * @fw_event: object describing the event
3122 * Context: This function will acquire ioc->fw_event_lock.
3124 * This adds the firmware event object into link list, then queues it up to
3125 * be processed from user context.
3128 _scsih_fw_event_add(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
3130 unsigned long flags
;
3132 if (ioc
->firmware_event_thread
== NULL
)
3135 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3136 fw_event_work_get(fw_event
);
3137 INIT_LIST_HEAD(&fw_event
->list
);
3138 list_add_tail(&fw_event
->list
, &ioc
->fw_event_list
);
3139 INIT_WORK(&fw_event
->work
, _firmware_event_work
);
3140 fw_event_work_get(fw_event
);
3141 queue_work(ioc
->firmware_event_thread
, &fw_event
->work
);
3142 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3146 * _scsih_fw_event_del_from_list - delete fw_event from the list
3147 * @ioc: per adapter object
3148 * @fw_event: object describing the event
3149 * Context: This function will acquire ioc->fw_event_lock.
3151 * If the fw_event is on the fw_event_list, remove it and do a put.
3154 _scsih_fw_event_del_from_list(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
3157 unsigned long flags
;
3159 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3160 if (!list_empty(&fw_event
->list
)) {
3161 list_del_init(&fw_event
->list
);
3162 fw_event_work_put(fw_event
);
3164 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3169 * mpt3sas_send_trigger_data_event - send event for processing trigger data
3170 * @ioc: per adapter object
3171 * @event_data: trigger event data
3174 mpt3sas_send_trigger_data_event(struct MPT3SAS_ADAPTER
*ioc
,
3175 struct SL_WH_TRIGGERS_EVENT_DATA_T
*event_data
)
3177 struct fw_event_work
*fw_event
;
3180 if (ioc
->is_driver_loading
)
3182 sz
= sizeof(*event_data
);
3183 fw_event
= alloc_fw_event_work(sz
);
3186 fw_event
->event
= MPT3SAS_PROCESS_TRIGGER_DIAG
;
3187 fw_event
->ioc
= ioc
;
3188 memcpy(fw_event
->event_data
, event_data
, sizeof(*event_data
));
3189 _scsih_fw_event_add(ioc
, fw_event
);
3190 fw_event_work_put(fw_event
);
3194 * _scsih_error_recovery_delete_devices - remove devices not responding
3195 * @ioc: per adapter object
3198 _scsih_error_recovery_delete_devices(struct MPT3SAS_ADAPTER
*ioc
)
3200 struct fw_event_work
*fw_event
;
3202 if (ioc
->is_driver_loading
)
3204 fw_event
= alloc_fw_event_work(0);
3207 fw_event
->event
= MPT3SAS_REMOVE_UNRESPONDING_DEVICES
;
3208 fw_event
->ioc
= ioc
;
3209 _scsih_fw_event_add(ioc
, fw_event
);
3210 fw_event_work_put(fw_event
);
3214 * mpt3sas_port_enable_complete - port enable completed (fake event)
3215 * @ioc: per adapter object
3218 mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER
*ioc
)
3220 struct fw_event_work
*fw_event
;
3222 fw_event
= alloc_fw_event_work(0);
3225 fw_event
->event
= MPT3SAS_PORT_ENABLE_COMPLETE
;
3226 fw_event
->ioc
= ioc
;
3227 _scsih_fw_event_add(ioc
, fw_event
);
3228 fw_event_work_put(fw_event
);
3231 static struct fw_event_work
*dequeue_next_fw_event(struct MPT3SAS_ADAPTER
*ioc
)
3233 unsigned long flags
;
3234 struct fw_event_work
*fw_event
= NULL
;
3236 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
3237 if (!list_empty(&ioc
->fw_event_list
)) {
3238 fw_event
= list_first_entry(&ioc
->fw_event_list
,
3239 struct fw_event_work
, list
);
3240 list_del_init(&fw_event
->list
);
3242 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
3248 * _scsih_fw_event_cleanup_queue - cleanup event queue
3249 * @ioc: per adapter object
3251 * Walk the firmware event queue, either killing timers, or waiting
3252 * for outstanding events to complete
3255 _scsih_fw_event_cleanup_queue(struct MPT3SAS_ADAPTER
*ioc
)
3257 struct fw_event_work
*fw_event
;
3259 if (list_empty(&ioc
->fw_event_list
) ||
3260 !ioc
->firmware_event_thread
|| in_interrupt())
3263 while ((fw_event
= dequeue_next_fw_event(ioc
))) {
3265 * Wait on the fw_event to complete. If this returns 1, then
3266 * the event was never executed, and we need a put for the
3267 * reference the work had on the fw_event.
3269 * If it did execute, we wait for it to finish, and the put will
3270 * happen from _firmware_event_work()
3272 if (cancel_work_sync(&fw_event
->work
))
3273 fw_event_work_put(fw_event
);
3275 fw_event_work_put(fw_event
);
3280 * _scsih_internal_device_block - block the sdev device
3281 * @sdev: per device object
3282 * @sas_device_priv_data : per device driver private data
3284 * make sure device is blocked without error, if not
3288 _scsih_internal_device_block(struct scsi_device
*sdev
,
3289 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3293 sdev_printk(KERN_INFO
, sdev
, "device_block, handle(0x%04x)\n",
3294 sas_device_priv_data
->sas_target
->handle
);
3295 sas_device_priv_data
->block
= 1;
3297 r
= scsi_internal_device_block_nowait(sdev
);
3299 sdev_printk(KERN_WARNING
, sdev
,
3300 "device_block failed with return(%d) for handle(0x%04x)\n",
3301 r
, sas_device_priv_data
->sas_target
->handle
);
3305 * _scsih_internal_device_unblock - unblock the sdev device
3306 * @sdev: per device object
3307 * @sas_device_priv_data : per device driver private data
3308 * make sure device is unblocked without error, if not retry
3309 * by blocking and then unblocking
3313 _scsih_internal_device_unblock(struct scsi_device
*sdev
,
3314 struct MPT3SAS_DEVICE
*sas_device_priv_data
)
3318 sdev_printk(KERN_WARNING
, sdev
, "device_unblock and setting to running, "
3319 "handle(0x%04x)\n", sas_device_priv_data
->sas_target
->handle
);
3320 sas_device_priv_data
->block
= 0;
3321 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3323 /* The device has been set to SDEV_RUNNING by SD layer during
3324 * device addition but the request queue is still stopped by
3325 * our earlier block call. We need to perform a block again
3326 * to get the device to SDEV_BLOCK and then to SDEV_RUNNING */
3328 sdev_printk(KERN_WARNING
, sdev
,
3329 "device_unblock failed with return(%d) for handle(0x%04x) "
3330 "performing a block followed by an unblock\n",
3331 r
, sas_device_priv_data
->sas_target
->handle
);
3332 sas_device_priv_data
->block
= 1;
3333 r
= scsi_internal_device_block_nowait(sdev
);
3335 sdev_printk(KERN_WARNING
, sdev
, "retried device_block "
3336 "failed with return(%d) for handle(0x%04x)\n",
3337 r
, sas_device_priv_data
->sas_target
->handle
);
3339 sas_device_priv_data
->block
= 0;
3340 r
= scsi_internal_device_unblock_nowait(sdev
, SDEV_RUNNING
);
3342 sdev_printk(KERN_WARNING
, sdev
, "retried device_unblock"
3343 " failed with return(%d) for handle(0x%04x)\n",
3344 r
, sas_device_priv_data
->sas_target
->handle
);
3349 * _scsih_ublock_io_all_device - unblock every device
3350 * @ioc: per adapter object
3352 * change the device state from block to running
3355 _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3357 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3358 struct scsi_device
*sdev
;
3360 shost_for_each_device(sdev
, ioc
->shost
) {
3361 sas_device_priv_data
= sdev
->hostdata
;
3362 if (!sas_device_priv_data
)
3364 if (!sas_device_priv_data
->block
)
3367 dewtprintk(ioc
, sdev_printk(KERN_INFO
, sdev
,
3368 "device_running, handle(0x%04x)\n",
3369 sas_device_priv_data
->sas_target
->handle
));
3370 _scsih_internal_device_unblock(sdev
, sas_device_priv_data
);
3376 * _scsih_ublock_io_device - prepare device to be deleted
3377 * @ioc: per adapter object
3378 * @sas_address: sas address
3380 * unblock then put device in offline state
3383 _scsih_ublock_io_device(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
3385 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3386 struct scsi_device
*sdev
;
3388 shost_for_each_device(sdev
, ioc
->shost
) {
3389 sas_device_priv_data
= sdev
->hostdata
;
3390 if (!sas_device_priv_data
)
3392 if (sas_device_priv_data
->sas_target
->sas_address
3395 if (sas_device_priv_data
->block
)
3396 _scsih_internal_device_unblock(sdev
,
3397 sas_device_priv_data
);
3402 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
3403 * @ioc: per adapter object
3405 * During device pull we need to appropriately set the sdev state.
3408 _scsih_block_io_all_device(struct MPT3SAS_ADAPTER
*ioc
)
3410 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3411 struct scsi_device
*sdev
;
3413 shost_for_each_device(sdev
, ioc
->shost
) {
3414 sas_device_priv_data
= sdev
->hostdata
;
3415 if (!sas_device_priv_data
)
3417 if (sas_device_priv_data
->block
)
3419 if (sas_device_priv_data
->ignore_delay_remove
) {
3420 sdev_printk(KERN_INFO
, sdev
,
3421 "%s skip device_block for SES handle(0x%04x)\n",
3422 __func__
, sas_device_priv_data
->sas_target
->handle
);
3425 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3430 * _scsih_block_io_device - set the device state to SDEV_BLOCK
3431 * @ioc: per adapter object
3432 * @handle: device handle
3434 * During device pull we need to appropriately set the sdev state.
3437 _scsih_block_io_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3439 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3440 struct scsi_device
*sdev
;
3441 struct _sas_device
*sas_device
;
3443 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
3445 shost_for_each_device(sdev
, ioc
->shost
) {
3446 sas_device_priv_data
= sdev
->hostdata
;
3447 if (!sas_device_priv_data
)
3449 if (sas_device_priv_data
->sas_target
->handle
!= handle
)
3451 if (sas_device_priv_data
->block
)
3453 if (sas_device
&& sas_device
->pend_sas_rphy_add
)
3455 if (sas_device_priv_data
->ignore_delay_remove
) {
3456 sdev_printk(KERN_INFO
, sdev
,
3457 "%s skip device_block for SES handle(0x%04x)\n",
3458 __func__
, sas_device_priv_data
->sas_target
->handle
);
3461 _scsih_internal_device_block(sdev
, sas_device_priv_data
);
3465 sas_device_put(sas_device
);
3469 * _scsih_block_io_to_children_attached_to_ex
3470 * @ioc: per adapter object
3471 * @sas_expander: the sas_device object
3473 * This routine set sdev state to SDEV_BLOCK for all devices
3474 * attached to this expander. This function called when expander is
3478 _scsih_block_io_to_children_attached_to_ex(struct MPT3SAS_ADAPTER
*ioc
,
3479 struct _sas_node
*sas_expander
)
3481 struct _sas_port
*mpt3sas_port
;
3482 struct _sas_device
*sas_device
;
3483 struct _sas_node
*expander_sibling
;
3484 unsigned long flags
;
3489 list_for_each_entry(mpt3sas_port
,
3490 &sas_expander
->sas_port_list
, port_list
) {
3491 if (mpt3sas_port
->remote_identify
.device_type
==
3493 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3494 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
3495 mpt3sas_port
->remote_identify
.sas_address
);
3497 set_bit(sas_device
->handle
,
3498 ioc
->blocking_handles
);
3499 sas_device_put(sas_device
);
3501 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3505 list_for_each_entry(mpt3sas_port
,
3506 &sas_expander
->sas_port_list
, port_list
) {
3508 if (mpt3sas_port
->remote_identify
.device_type
==
3509 SAS_EDGE_EXPANDER_DEVICE
||
3510 mpt3sas_port
->remote_identify
.device_type
==
3511 SAS_FANOUT_EXPANDER_DEVICE
) {
3513 mpt3sas_scsih_expander_find_by_sas_address(
3514 ioc
, mpt3sas_port
->remote_identify
.sas_address
);
3515 _scsih_block_io_to_children_attached_to_ex(ioc
,
3522 * _scsih_block_io_to_children_attached_directly
3523 * @ioc: per adapter object
3524 * @event_data: topology change event data
3526 * This routine set sdev state to SDEV_BLOCK for all devices
3527 * direct attached during device pull.
3530 _scsih_block_io_to_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3531 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
3537 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3538 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
3541 reason_code
= event_data
->PHY
[i
].PhyStatus
&
3542 MPI2_EVENT_SAS_TOPO_RC_MASK
;
3543 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
)
3544 _scsih_block_io_device(ioc
, handle
);
3549 * _scsih_block_io_to_pcie_children_attached_directly
3550 * @ioc: per adapter object
3551 * @event_data: topology change event data
3553 * This routine set sdev state to SDEV_BLOCK for all devices
3554 * direct attached during device pull/reconnect.
3557 _scsih_block_io_to_pcie_children_attached_directly(struct MPT3SAS_ADAPTER
*ioc
,
3558 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
3564 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
3566 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
3569 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
3571 MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
)
3572 _scsih_block_io_device(ioc
, handle
);
3576 * _scsih_tm_tr_send - send task management request
3577 * @ioc: per adapter object
3578 * @handle: device handle
3579 * Context: interrupt time.
3581 * This code is to initiate the device removal handshake protocol
3582 * with controller firmware. This function will issue target reset
3583 * using high priority request queue. It will send a sas iounit
3584 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
3586 * This is designed to send muliple task management request at the same
3587 * time to the fifo. If the fifo is full, we will append the request,
3588 * and process it in a future completion.
3591 _scsih_tm_tr_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3593 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3595 struct _sas_device
*sas_device
= NULL
;
3596 struct _pcie_device
*pcie_device
= NULL
;
3597 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
3598 u64 sas_address
= 0;
3599 unsigned long flags
;
3600 struct _tr_list
*delayed_tr
;
3604 if (ioc
->pci_error_recovery
) {
3606 ioc_info(ioc
, "%s: host in pci error recovery: handle(0x%04x)\n",
3610 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3611 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3613 ioc_info(ioc
, "%s: host is not operational: handle(0x%04x)\n",
3618 /* if PD, then return */
3619 if (test_bit(handle
, ioc
->pd_handles
))
3622 clear_bit(handle
, ioc
->pend_os_device_add
);
3624 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
3625 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
3626 if (sas_device
&& sas_device
->starget
&&
3627 sas_device
->starget
->hostdata
) {
3628 sas_target_priv_data
= sas_device
->starget
->hostdata
;
3629 sas_target_priv_data
->deleted
= 1;
3630 sas_address
= sas_device
->sas_address
;
3632 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
3634 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
3635 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
3636 if (pcie_device
&& pcie_device
->starget
&&
3637 pcie_device
->starget
->hostdata
) {
3638 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
3639 sas_target_priv_data
->deleted
= 1;
3640 sas_address
= pcie_device
->wwid
;
3642 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
3643 if (pcie_device
&& (!ioc
->tm_custom_handling
) &&
3644 (!(mpt3sas_scsih_is_pcie_scsi_device(
3645 pcie_device
->device_info
))))
3647 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
;
3649 tr_method
= MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
;
3651 if (sas_target_priv_data
) {
3653 ioc_info(ioc
, "setting delete flag: handle(0x%04x), sas_addr(0x%016llx)\n",
3654 handle
, (u64
)sas_address
));
3656 if (sas_device
->enclosure_handle
!= 0)
3658 ioc_info(ioc
, "setting delete flag:enclosure logical id(0x%016llx), slot(%d)\n",
3659 (u64
)sas_device
->enclosure_logical_id
,
3661 if (sas_device
->connector_name
[0] != '\0')
3663 ioc_info(ioc
, "setting delete flag: enclosure level(0x%04x), connector name( %s)\n",
3664 sas_device
->enclosure_level
,
3665 sas_device
->connector_name
));
3666 } else if (pcie_device
) {
3667 if (pcie_device
->enclosure_handle
!= 0)
3669 ioc_info(ioc
, "setting delete flag: logical id(0x%016llx), slot(%d)\n",
3670 (u64
)pcie_device
->enclosure_logical_id
,
3671 pcie_device
->slot
));
3672 if (pcie_device
->connector_name
[0] != '\0')
3674 ioc_info(ioc
, "setting delete flag:, enclosure level(0x%04x), connector name( %s)\n",
3675 pcie_device
->enclosure_level
,
3676 pcie_device
->connector_name
));
3678 _scsih_ublock_io_device(ioc
, sas_address
);
3679 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
3682 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_cb_idx
);
3684 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3687 INIT_LIST_HEAD(&delayed_tr
->list
);
3688 delayed_tr
->handle
= handle
;
3689 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
3691 ioc_info(ioc
, "DELAYED:tr:handle(0x%04x), (open)\n",
3697 ioc_info(ioc
, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3698 handle
, smid
, ioc
->tm_tr_cb_idx
));
3699 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3700 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3701 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3702 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3703 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3704 mpi_request
->MsgFlags
= tr_method
;
3705 set_bit(handle
, ioc
->device_remove_in_progress
);
3706 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3707 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_DEVICE_REMOVAL
);
3711 sas_device_put(sas_device
);
3713 pcie_device_put(pcie_device
);
3717 * _scsih_tm_tr_complete -
3718 * @ioc: per adapter object
3719 * @smid: system request message index
3720 * @msix_index: MSIX table index supplied by the OS
3721 * @reply: reply message frame(lower 32bit addr)
3722 * Context: interrupt time.
3724 * This is the target reset completion routine.
3725 * This code is part of the code to initiate the device removal
3726 * handshake protocol with controller firmware.
3727 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
3729 * Return: 1 meaning mf should be freed from _base_interrupt
3730 * 0 means the mf is freed from this function.
3733 _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3737 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3738 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3739 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3740 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
3743 struct _sc_list
*delayed_sc
;
3745 if (ioc
->pci_error_recovery
) {
3747 ioc_info(ioc
, "%s: host in pci error recovery\n",
3751 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3752 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3754 ioc_info(ioc
, "%s: host is not operational\n",
3758 if (unlikely(!mpi_reply
)) {
3759 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
3760 __FILE__
, __LINE__
, __func__
);
3763 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3764 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3765 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3767 ioc_err(ioc
, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3769 le16_to_cpu(mpi_reply
->DevHandle
), smid
));
3773 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
3775 ioc_info(ioc
, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
3776 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3777 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3778 le32_to_cpu(mpi_reply
->TerminationCount
)));
3780 smid_sas_ctrl
= mpt3sas_base_get_smid(ioc
, ioc
->tm_sas_control_cb_idx
);
3781 if (!smid_sas_ctrl
) {
3782 delayed_sc
= kzalloc(sizeof(*delayed_sc
), GFP_ATOMIC
);
3784 return _scsih_check_for_pending_tm(ioc
, smid
);
3785 INIT_LIST_HEAD(&delayed_sc
->list
);
3786 delayed_sc
->handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3787 list_add_tail(&delayed_sc
->list
, &ioc
->delayed_sc_list
);
3789 ioc_info(ioc
, "DELAYED:sc:handle(0x%04x), (open)\n",
3791 return _scsih_check_for_pending_tm(ioc
, smid
);
3795 ioc_info(ioc
, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3796 handle
, smid_sas_ctrl
, ioc
->tm_sas_control_cb_idx
));
3797 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid_sas_ctrl
);
3798 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
3799 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
3800 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
3801 mpi_request
->DevHandle
= mpi_request_tm
->DevHandle
;
3802 ioc
->put_smid_default(ioc
, smid_sas_ctrl
);
3804 return _scsih_check_for_pending_tm(ioc
, smid
);
3807 /** _scsih_allow_scmd_to_device - check whether scmd needs to
3808 * issue to IOC or not.
3809 * @ioc: per adapter object
3810 * @scmd: pointer to scsi command object
3812 * Returns true if scmd can be issued to IOC otherwise returns false.
3814 inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER
*ioc
,
3815 struct scsi_cmnd
*scmd
)
3818 if (ioc
->pci_error_recovery
)
3821 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
) {
3822 if (ioc
->remove_host
)
3828 if (ioc
->remove_host
) {
3830 switch (scmd
->cmnd
[0]) {
3831 case SYNCHRONIZE_CACHE
:
3843 * _scsih_sas_control_complete - completion routine
3844 * @ioc: per adapter object
3845 * @smid: system request message index
3846 * @msix_index: MSIX table index supplied by the OS
3847 * @reply: reply message frame(lower 32bit addr)
3848 * Context: interrupt time.
3850 * This is the sas iounit control completion routine.
3851 * This code is part of the code to initiate the device removal
3852 * handshake protocol with controller firmware.
3854 * Return: 1 meaning mf should be freed from _base_interrupt
3855 * 0 means the mf is freed from this function.
3858 _scsih_sas_control_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3859 u8 msix_index
, u32 reply
)
3861 Mpi2SasIoUnitControlReply_t
*mpi_reply
=
3862 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3864 if (likely(mpi_reply
)) {
3866 ioc_info(ioc
, "sc_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3867 le16_to_cpu(mpi_reply
->DevHandle
), smid
,
3868 le16_to_cpu(mpi_reply
->IOCStatus
),
3869 le32_to_cpu(mpi_reply
->IOCLogInfo
)));
3870 if (le16_to_cpu(mpi_reply
->IOCStatus
) ==
3871 MPI2_IOCSTATUS_SUCCESS
) {
3872 clear_bit(le16_to_cpu(mpi_reply
->DevHandle
),
3873 ioc
->device_remove_in_progress
);
3876 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
3877 __FILE__
, __LINE__
, __func__
);
3879 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
3883 * _scsih_tm_tr_volume_send - send target reset request for volumes
3884 * @ioc: per adapter object
3885 * @handle: device handle
3886 * Context: interrupt time.
3888 * This is designed to send muliple task management request at the same
3889 * time to the fifo. If the fifo is full, we will append the request,
3890 * and process it in a future completion.
3893 _scsih_tm_tr_volume_send(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
3895 Mpi2SCSITaskManagementRequest_t
*mpi_request
;
3897 struct _tr_list
*delayed_tr
;
3899 if (ioc
->pci_error_recovery
) {
3901 ioc_info(ioc
, "%s: host reset in progress!\n",
3906 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->tm_tr_volume_cb_idx
);
3908 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
3911 INIT_LIST_HEAD(&delayed_tr
->list
);
3912 delayed_tr
->handle
= handle
;
3913 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_volume_list
);
3915 ioc_info(ioc
, "DELAYED:tr:handle(0x%04x), (open)\n",
3921 ioc_info(ioc
, "tr_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
3922 handle
, smid
, ioc
->tm_tr_volume_cb_idx
));
3923 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3924 memset(mpi_request
, 0, sizeof(Mpi2SCSITaskManagementRequest_t
));
3925 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3926 mpi_request
->DevHandle
= cpu_to_le16(handle
);
3927 mpi_request
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
;
3928 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
3932 * _scsih_tm_volume_tr_complete - target reset completion
3933 * @ioc: per adapter object
3934 * @smid: system request message index
3935 * @msix_index: MSIX table index supplied by the OS
3936 * @reply: reply message frame(lower 32bit addr)
3937 * Context: interrupt time.
3939 * Return: 1 meaning mf should be freed from _base_interrupt
3940 * 0 means the mf is freed from this function.
3943 _scsih_tm_volume_tr_complete(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3944 u8 msix_index
, u32 reply
)
3947 Mpi2SCSITaskManagementRequest_t
*mpi_request_tm
;
3948 Mpi2SCSITaskManagementReply_t
*mpi_reply
=
3949 mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3951 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
) {
3953 ioc_info(ioc
, "%s: host reset in progress!\n",
3957 if (unlikely(!mpi_reply
)) {
3958 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
3959 __FILE__
, __LINE__
, __func__
);
3963 mpi_request_tm
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3964 handle
= le16_to_cpu(mpi_request_tm
->DevHandle
);
3965 if (handle
!= le16_to_cpu(mpi_reply
->DevHandle
)) {
3967 ioc_err(ioc
, "spurious interrupt: handle(0x%04x:0x%04x), smid(%d)!!!\n",
3968 handle
, le16_to_cpu(mpi_reply
->DevHandle
),
3974 ioc_info(ioc
, "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), loginfo(0x%08x), completed(%d)\n",
3975 handle
, smid
, le16_to_cpu(mpi_reply
->IOCStatus
),
3976 le32_to_cpu(mpi_reply
->IOCLogInfo
),
3977 le32_to_cpu(mpi_reply
->TerminationCount
)));
3979 return _scsih_check_for_pending_tm(ioc
, smid
);
3983 * _scsih_issue_delayed_event_ack - issue delayed Event ACK messages
3984 * @ioc: per adapter object
3985 * @smid: system request message index
3987 * @event_context: used to track events uniquely
3989 * Context - processed in interrupt context.
3992 _scsih_issue_delayed_event_ack(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, U16 event
,
3995 Mpi2EventAckRequest_t
*ack_request
;
3996 int i
= smid
- ioc
->internal_smid
;
3997 unsigned long flags
;
3999 /* Without releasing the smid just update the
4000 * call back index and reuse the same smid for
4001 * processing this delayed request
4003 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4004 ioc
->internal_lookup
[i
].cb_idx
= ioc
->base_cb_idx
;
4005 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4008 ioc_info(ioc
, "EVENT ACK: event(0x%04x), smid(%d), cb(%d)\n",
4009 le16_to_cpu(event
), smid
, ioc
->base_cb_idx
));
4010 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4011 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
4012 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
4013 ack_request
->Event
= event
;
4014 ack_request
->EventContext
= event_context
;
4015 ack_request
->VF_ID
= 0; /* TODO */
4016 ack_request
->VP_ID
= 0;
4017 ioc
->put_smid_default(ioc
, smid
);
4021 * _scsih_issue_delayed_sas_io_unit_ctrl - issue delayed
4022 * sas_io_unit_ctrl messages
4023 * @ioc: per adapter object
4024 * @smid: system request message index
4025 * @handle: device handle
4027 * Context - processed in interrupt context.
4030 _scsih_issue_delayed_sas_io_unit_ctrl(struct MPT3SAS_ADAPTER
*ioc
,
4031 u16 smid
, u16 handle
)
4033 Mpi2SasIoUnitControlRequest_t
*mpi_request
;
4035 int i
= smid
- ioc
->internal_smid
;
4036 unsigned long flags
;
4038 if (ioc
->remove_host
) {
4040 ioc_info(ioc
, "%s: host has been removed\n",
4043 } else if (ioc
->pci_error_recovery
) {
4045 ioc_info(ioc
, "%s: host in pci error recovery\n",
4049 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4050 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4052 ioc_info(ioc
, "%s: host is not operational\n",
4057 /* Without releasing the smid just update the
4058 * call back index and reuse the same smid for
4059 * processing this delayed request
4061 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4062 ioc
->internal_lookup
[i
].cb_idx
= ioc
->tm_sas_control_cb_idx
;
4063 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4066 ioc_info(ioc
, "sc_send:handle(0x%04x), (open), smid(%d), cb(%d)\n",
4067 handle
, smid
, ioc
->tm_sas_control_cb_idx
));
4068 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4069 memset(mpi_request
, 0, sizeof(Mpi2SasIoUnitControlRequest_t
));
4070 mpi_request
->Function
= MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
;
4071 mpi_request
->Operation
= MPI2_SAS_OP_REMOVE_DEVICE
;
4072 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4073 ioc
->put_smid_default(ioc
, smid
);
4077 * _scsih_check_for_pending_internal_cmds - check for pending internal messages
4078 * @ioc: per adapter object
4079 * @smid: system request message index
4081 * Context: Executed in interrupt context
4083 * This will check delayed internal messages list, and process the
4086 * Return: 1 meaning mf should be freed from _base_interrupt
4087 * 0 means the mf is freed from this function.
4090 mpt3sas_check_for_pending_internal_cmds(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4092 struct _sc_list
*delayed_sc
;
4093 struct _event_ack_list
*delayed_event_ack
;
4095 if (!list_empty(&ioc
->delayed_event_ack_list
)) {
4096 delayed_event_ack
= list_entry(ioc
->delayed_event_ack_list
.next
,
4097 struct _event_ack_list
, list
);
4098 _scsih_issue_delayed_event_ack(ioc
, smid
,
4099 delayed_event_ack
->Event
, delayed_event_ack
->EventContext
);
4100 list_del(&delayed_event_ack
->list
);
4101 kfree(delayed_event_ack
);
4105 if (!list_empty(&ioc
->delayed_sc_list
)) {
4106 delayed_sc
= list_entry(ioc
->delayed_sc_list
.next
,
4107 struct _sc_list
, list
);
4108 _scsih_issue_delayed_sas_io_unit_ctrl(ioc
, smid
,
4109 delayed_sc
->handle
);
4110 list_del(&delayed_sc
->list
);
4118 * _scsih_check_for_pending_tm - check for pending task management
4119 * @ioc: per adapter object
4120 * @smid: system request message index
4122 * This will check delayed target reset list, and feed the
4125 * Return: 1 meaning mf should be freed from _base_interrupt
4126 * 0 means the mf is freed from this function.
4129 _scsih_check_for_pending_tm(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
4131 struct _tr_list
*delayed_tr
;
4133 if (!list_empty(&ioc
->delayed_tr_volume_list
)) {
4134 delayed_tr
= list_entry(ioc
->delayed_tr_volume_list
.next
,
4135 struct _tr_list
, list
);
4136 mpt3sas_base_free_smid(ioc
, smid
);
4137 _scsih_tm_tr_volume_send(ioc
, delayed_tr
->handle
);
4138 list_del(&delayed_tr
->list
);
4143 if (!list_empty(&ioc
->delayed_tr_list
)) {
4144 delayed_tr
= list_entry(ioc
->delayed_tr_list
.next
,
4145 struct _tr_list
, list
);
4146 mpt3sas_base_free_smid(ioc
, smid
);
4147 _scsih_tm_tr_send(ioc
, delayed_tr
->handle
);
4148 list_del(&delayed_tr
->list
);
4157 * _scsih_check_topo_delete_events - sanity check on topo events
4158 * @ioc: per adapter object
4159 * @event_data: the event data payload
4161 * This routine added to better handle cable breaker.
4163 * This handles the case where driver receives multiple expander
4164 * add and delete events in a single shot. When there is a delete event
4165 * the routine will void any pending add events waiting in the event queue.
4168 _scsih_check_topo_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4169 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
4171 struct fw_event_work
*fw_event
;
4172 Mpi2EventDataSasTopologyChangeList_t
*local_event_data
;
4173 u16 expander_handle
;
4174 struct _sas_node
*sas_expander
;
4175 unsigned long flags
;
4179 for (i
= 0 ; i
< event_data
->NumEntries
; i
++) {
4180 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
4183 reason_code
= event_data
->PHY
[i
].PhyStatus
&
4184 MPI2_EVENT_SAS_TOPO_RC_MASK
;
4185 if (reason_code
== MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
)
4186 _scsih_tm_tr_send(ioc
, handle
);
4189 expander_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
4190 if (expander_handle
< ioc
->sas_hba
.num_phys
) {
4191 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4194 if (event_data
->ExpStatus
==
4195 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
) {
4196 /* put expander attached devices into blocking state */
4197 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
4198 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
4200 _scsih_block_io_to_children_attached_to_ex(ioc
, sas_expander
);
4201 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
4203 handle
= find_first_bit(ioc
->blocking_handles
,
4204 ioc
->facts
.MaxDevHandle
);
4205 if (handle
< ioc
->facts
.MaxDevHandle
)
4206 _scsih_block_io_device(ioc
, handle
);
4207 } while (test_and_clear_bit(handle
, ioc
->blocking_handles
));
4208 } else if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_RESPONDING
)
4209 _scsih_block_io_to_children_attached_directly(ioc
, event_data
);
4211 if (event_data
->ExpStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4214 /* mark ignore flag for pending events */
4215 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4216 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4217 if (fw_event
->event
!= MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
||
4220 local_event_data
= (Mpi2EventDataSasTopologyChangeList_t
*)
4221 fw_event
->event_data
;
4222 if (local_event_data
->ExpStatus
==
4223 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4224 local_event_data
->ExpStatus
==
4225 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4226 if (le16_to_cpu(local_event_data
->ExpanderDevHandle
) ==
4229 ioc_info(ioc
, "setting ignoring flag\n"));
4230 fw_event
->ignore
= 1;
4234 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4238 * _scsih_check_pcie_topo_remove_events - sanity check on topo
4240 * @ioc: per adapter object
4241 * @event_data: the event data payload
4243 * This handles the case where driver receives multiple switch
4244 * or device add and delete events in a single shot. When there
4245 * is a delete event the routine will void any pending add
4246 * events waiting in the event queue.
4249 _scsih_check_pcie_topo_remove_events(struct MPT3SAS_ADAPTER
*ioc
,
4250 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
4252 struct fw_event_work
*fw_event
;
4253 Mpi26EventDataPCIeTopologyChangeList_t
*local_event_data
;
4254 unsigned long flags
;
4256 u16 handle
, switch_handle
;
4258 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
4260 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
4263 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
4264 if (reason_code
== MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
)
4265 _scsih_tm_tr_send(ioc
, handle
);
4268 switch_handle
= le16_to_cpu(event_data
->SwitchDevHandle
);
4269 if (!switch_handle
) {
4270 _scsih_block_io_to_pcie_children_attached_directly(
4274 /* TODO We are not supporting cascaded PCIe Switch removal yet*/
4275 if ((event_data
->SwitchStatus
4276 == MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
) ||
4277 (event_data
->SwitchStatus
==
4278 MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
))
4279 _scsih_block_io_to_pcie_children_attached_directly(
4282 if (event_data
->SwitchStatus
!= MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
)
4285 /* mark ignore flag for pending events */
4286 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
4287 list_for_each_entry(fw_event
, &ioc
->fw_event_list
, list
) {
4288 if (fw_event
->event
!= MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
||
4292 (Mpi26EventDataPCIeTopologyChangeList_t
*)
4293 fw_event
->event_data
;
4294 if (local_event_data
->SwitchStatus
==
4295 MPI2_EVENT_SAS_TOPO_ES_ADDED
||
4296 local_event_data
->SwitchStatus
==
4297 MPI2_EVENT_SAS_TOPO_ES_RESPONDING
) {
4298 if (le16_to_cpu(local_event_data
->SwitchDevHandle
) ==
4301 ioc_info(ioc
, "setting ignoring flag for switch event\n"));
4302 fw_event
->ignore
= 1;
4306 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
4310 * _scsih_set_volume_delete_flag - setting volume delete flag
4311 * @ioc: per adapter object
4312 * @handle: device handle
4314 * This returns nothing.
4317 _scsih_set_volume_delete_flag(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
4319 struct _raid_device
*raid_device
;
4320 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4321 unsigned long flags
;
4323 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
4324 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
4325 if (raid_device
&& raid_device
->starget
&&
4326 raid_device
->starget
->hostdata
) {
4327 sas_target_priv_data
=
4328 raid_device
->starget
->hostdata
;
4329 sas_target_priv_data
->deleted
= 1;
4331 ioc_info(ioc
, "setting delete flag: handle(0x%04x), wwid(0x%016llx)\n",
4332 handle
, (u64
)raid_device
->wwid
));
4334 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
4338 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
4339 * @handle: input handle
4340 * @a: handle for volume a
4341 * @b: handle for volume b
4343 * IR firmware only supports two raid volumes. The purpose of this
4344 * routine is to set the volume handle in either a or b. When the given
4345 * input handle is non-zero, or when a and b have not been set before.
4348 _scsih_set_volume_handle_for_tr(u16 handle
, u16
*a
, u16
*b
)
4350 if (!handle
|| handle
== *a
|| handle
== *b
)
4359 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
4360 * @ioc: per adapter object
4361 * @event_data: the event data payload
4362 * Context: interrupt time.
4364 * This routine will send target reset to volume, followed by target
4365 * resets to the PDs. This is called when a PD has been removed, or
4366 * volume has been deleted or removed. When the target reset is sent
4367 * to volume, the PD target resets need to be queued to start upon
4368 * completion of the volume target reset.
4371 _scsih_check_ir_config_unhide_events(struct MPT3SAS_ADAPTER
*ioc
,
4372 Mpi2EventDataIrConfigChangeList_t
*event_data
)
4374 Mpi2EventIrConfigElement_t
*element
;
4376 u16 handle
, volume_handle
, a
, b
;
4377 struct _tr_list
*delayed_tr
;
4382 if (ioc
->is_warpdrive
)
4385 /* Volume Resets for Deleted or Removed */
4386 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4387 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4388 if (le32_to_cpu(event_data
->Flags
) &
4389 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4391 if (element
->ReasonCode
==
4392 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
||
4393 element
->ReasonCode
==
4394 MPI2_EVENT_IR_CHANGE_RC_REMOVED
) {
4395 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4396 _scsih_set_volume_delete_flag(ioc
, volume_handle
);
4397 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4401 /* Volume Resets for UNHIDE events */
4402 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4403 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4404 if (le32_to_cpu(event_data
->Flags
) &
4405 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
)
4407 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_UNHIDE
) {
4408 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4409 _scsih_set_volume_handle_for_tr(volume_handle
, &a
, &b
);
4414 _scsih_tm_tr_volume_send(ioc
, a
);
4416 _scsih_tm_tr_volume_send(ioc
, b
);
4418 /* PD target resets */
4419 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
4420 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
4421 if (element
->ReasonCode
!= MPI2_EVENT_IR_CHANGE_RC_UNHIDE
)
4423 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
4424 volume_handle
= le16_to_cpu(element
->VolDevHandle
);
4425 clear_bit(handle
, ioc
->pd_handles
);
4427 _scsih_tm_tr_send(ioc
, handle
);
4428 else if (volume_handle
== a
|| volume_handle
== b
) {
4429 delayed_tr
= kzalloc(sizeof(*delayed_tr
), GFP_ATOMIC
);
4430 BUG_ON(!delayed_tr
);
4431 INIT_LIST_HEAD(&delayed_tr
->list
);
4432 delayed_tr
->handle
= handle
;
4433 list_add_tail(&delayed_tr
->list
, &ioc
->delayed_tr_list
);
4435 ioc_info(ioc
, "DELAYED:tr:handle(0x%04x), (open)\n",
4438 _scsih_tm_tr_send(ioc
, handle
);
4444 * _scsih_check_volume_delete_events - set delete flag for volumes
4445 * @ioc: per adapter object
4446 * @event_data: the event data payload
4447 * Context: interrupt time.
4449 * This will handle the case when the cable connected to entire volume is
4450 * pulled. We will take care of setting the deleted flag so normal IO will
4454 _scsih_check_volume_delete_events(struct MPT3SAS_ADAPTER
*ioc
,
4455 Mpi2EventDataIrVolume_t
*event_data
)
4459 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
4461 state
= le32_to_cpu(event_data
->NewValue
);
4462 if (state
== MPI2_RAID_VOL_STATE_MISSING
|| state
==
4463 MPI2_RAID_VOL_STATE_FAILED
)
4464 _scsih_set_volume_delete_flag(ioc
,
4465 le16_to_cpu(event_data
->VolDevHandle
));
4469 * _scsih_temp_threshold_events - display temperature threshold exceeded events
4470 * @ioc: per adapter object
4471 * @event_data: the temp threshold event data
4472 * Context: interrupt time.
4475 _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER
*ioc
,
4476 Mpi2EventDataTemperature_t
*event_data
)
4478 if (ioc
->temp_sensors_count
>= event_data
->SensorNum
) {
4479 ioc_err(ioc
, "Temperature Threshold flags %s%s%s%s exceeded for Sensor: %d !!!\n",
4480 le16_to_cpu(event_data
->Status
) & 0x1 ? "0 " : " ",
4481 le16_to_cpu(event_data
->Status
) & 0x2 ? "1 " : " ",
4482 le16_to_cpu(event_data
->Status
) & 0x4 ? "2 " : " ",
4483 le16_to_cpu(event_data
->Status
) & 0x8 ? "3 " : " ",
4484 event_data
->SensorNum
);
4485 ioc_err(ioc
, "Current Temp In Celsius: %d\n",
4486 event_data
->CurrentTemperature
);
4490 static int _scsih_set_satl_pending(struct scsi_cmnd
*scmd
, bool pending
)
4492 struct MPT3SAS_DEVICE
*priv
= scmd
->device
->hostdata
;
4494 if (scmd
->cmnd
[0] != ATA_12
&& scmd
->cmnd
[0] != ATA_16
)
4498 return test_and_set_bit(0, &priv
->ata_command_pending
);
4500 clear_bit(0, &priv
->ata_command_pending
);
4505 * _scsih_flush_running_cmds - completing outstanding commands.
4506 * @ioc: per adapter object
4508 * The flushing out of all pending scmd commands following host reset,
4509 * where all IO is dropped to the floor.
4512 _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER
*ioc
)
4514 struct scsi_cmnd
*scmd
;
4515 struct scsiio_tracker
*st
;
4519 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
4520 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
4524 _scsih_set_satl_pending(scmd
, false);
4525 st
= scsi_cmd_priv(scmd
);
4526 mpt3sas_base_clear_st(ioc
, st
);
4527 scsi_dma_unmap(scmd
);
4528 if (ioc
->pci_error_recovery
|| ioc
->remove_host
)
4529 scmd
->result
= DID_NO_CONNECT
<< 16;
4531 scmd
->result
= DID_RESET
<< 16;
4532 scmd
->scsi_done(scmd
);
4534 dtmprintk(ioc
, ioc_info(ioc
, "completing %d cmds\n", count
));
4538 * _scsih_setup_eedp - setup MPI request for EEDP transfer
4539 * @ioc: per adapter object
4540 * @scmd: pointer to scsi command object
4541 * @mpi_request: pointer to the SCSI_IO request message frame
4543 * Supporting protection 1 and 3.
4546 _scsih_setup_eedp(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4547 Mpi25SCSIIORequest_t
*mpi_request
)
4550 unsigned char prot_op
= scsi_get_prot_op(scmd
);
4551 unsigned char prot_type
= scsi_get_prot_type(scmd
);
4552 Mpi25SCSIIORequest_t
*mpi_request_3v
=
4553 (Mpi25SCSIIORequest_t
*)mpi_request
;
4555 if (prot_type
== SCSI_PROT_DIF_TYPE0
|| prot_op
== SCSI_PROT_NORMAL
)
4558 if (prot_op
== SCSI_PROT_READ_STRIP
)
4559 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
;
4560 else if (prot_op
== SCSI_PROT_WRITE_INSERT
)
4561 eedp_flags
= MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
;
4565 switch (prot_type
) {
4566 case SCSI_PROT_DIF_TYPE1
:
4567 case SCSI_PROT_DIF_TYPE2
:
4570 * enable ref/guard checking
4571 * auto increment ref tag
4573 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
4574 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
4575 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4576 mpi_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
4577 cpu_to_be32(t10_pi_ref_tag(scmd
->request
));
4580 case SCSI_PROT_DIF_TYPE3
:
4583 * enable guard checking
4585 eedp_flags
|= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
;
4590 mpi_request_3v
->EEDPBlockSize
=
4591 cpu_to_le16(scmd
->device
->sector_size
);
4593 if (ioc
->is_gen35_ioc
)
4594 eedp_flags
|= MPI25_SCSIIO_EEDPFLAGS_APPTAG_DISABLE_MODE
;
4595 mpi_request
->EEDPFlags
= cpu_to_le16(eedp_flags
);
4599 * _scsih_eedp_error_handling - return sense code for EEDP errors
4600 * @scmd: pointer to scsi command object
4601 * @ioc_status: ioc status
4604 _scsih_eedp_error_handling(struct scsi_cmnd
*scmd
, u16 ioc_status
)
4608 switch (ioc_status
) {
4609 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4612 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4615 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4622 scsi_build_sense_buffer(0, scmd
->sense_buffer
, ILLEGAL_REQUEST
, 0x10,
4624 scmd
->result
= DRIVER_SENSE
<< 24 | (DID_ABORT
<< 16) |
4625 SAM_STAT_CHECK_CONDITION
;
4629 * scsih_qcmd - main scsi request entry point
4630 * @shost: SCSI host pointer
4631 * @scmd: pointer to scsi command object
4633 * The callback index is set inside `ioc->scsi_io_cb_idx`.
4635 * Return: 0 on success. If there's a failure, return either:
4636 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
4637 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
4640 scsih_qcmd(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
4642 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
4643 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
4644 struct MPT3SAS_TARGET
*sas_target_priv_data
;
4645 struct _raid_device
*raid_device
;
4646 struct request
*rq
= scmd
->request
;
4648 Mpi25SCSIIORequest_t
*mpi_request
;
4649 struct _pcie_device
*pcie_device
= NULL
;
4654 if (ioc
->logging_level
& MPT_DEBUG_SCSI
)
4655 scsi_print_command(scmd
);
4657 sas_device_priv_data
= scmd
->device
->hostdata
;
4658 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
) {
4659 scmd
->result
= DID_NO_CONNECT
<< 16;
4660 scmd
->scsi_done(scmd
);
4664 if (!(_scsih_allow_scmd_to_device(ioc
, scmd
))) {
4665 scmd
->result
= DID_NO_CONNECT
<< 16;
4666 scmd
->scsi_done(scmd
);
4670 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
4672 /* invalid device handle */
4673 handle
= sas_target_priv_data
->handle
;
4674 if (handle
== MPT3SAS_INVALID_DEVICE_HANDLE
) {
4675 scmd
->result
= DID_NO_CONNECT
<< 16;
4676 scmd
->scsi_done(scmd
);
4681 if (ioc
->shost_recovery
|| ioc
->ioc_link_reset_in_progress
) {
4682 /* host recovery or link resets sent via IOCTLs */
4683 return SCSI_MLQUEUE_HOST_BUSY
;
4684 } else if (sas_target_priv_data
->deleted
) {
4685 /* device has been deleted */
4686 scmd
->result
= DID_NO_CONNECT
<< 16;
4687 scmd
->scsi_done(scmd
);
4689 } else if (sas_target_priv_data
->tm_busy
||
4690 sas_device_priv_data
->block
) {
4691 /* device busy with task management */
4692 return SCSI_MLQUEUE_DEVICE_BUSY
;
4696 * Bug work around for firmware SATL handling. The loop
4697 * is based on atomic operations and ensures consistency
4698 * since we're lockless at this point
4701 if (test_bit(0, &sas_device_priv_data
->ata_command_pending
))
4702 return SCSI_MLQUEUE_DEVICE_BUSY
;
4703 } while (_scsih_set_satl_pending(scmd
, true));
4705 if (scmd
->sc_data_direction
== DMA_FROM_DEVICE
)
4706 mpi_control
= MPI2_SCSIIO_CONTROL_READ
;
4707 else if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
4708 mpi_control
= MPI2_SCSIIO_CONTROL_WRITE
;
4710 mpi_control
= MPI2_SCSIIO_CONTROL_NODATATRANSFER
;
4713 mpi_control
|= MPI2_SCSIIO_CONTROL_SIMPLEQ
;
4714 /* NCQ Prio supported, make sure control indicated high priority */
4715 if (sas_device_priv_data
->ncq_prio_enable
) {
4716 class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq
));
4717 if (class == IOPRIO_CLASS_RT
)
4718 mpi_control
|= 1 << MPI2_SCSIIO_CONTROL_CMDPRI_SHIFT
;
4720 /* Make sure Device is not raid volume.
4721 * We do not expose raid functionality to upper layer for warpdrive.
4723 if (((!ioc
->is_warpdrive
&& !scsih_is_raid(&scmd
->device
->sdev_gendev
))
4724 && !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
4725 && sas_is_tlr_enabled(scmd
->device
) && scmd
->cmd_len
!= 32)
4726 mpi_control
|= MPI2_SCSIIO_CONTROL_TLR_ON
;
4728 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->scsi_io_cb_idx
, scmd
);
4730 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
4731 _scsih_set_satl_pending(scmd
, false);
4734 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4735 memset(mpi_request
, 0, ioc
->request_sz
);
4736 _scsih_setup_eedp(ioc
, scmd
, mpi_request
);
4738 if (scmd
->cmd_len
== 32)
4739 mpi_control
|= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT
;
4740 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4741 if (sas_device_priv_data
->sas_target
->flags
&
4742 MPT_TARGET_FLAGS_RAID_COMPONENT
)
4743 mpi_request
->Function
= MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
;
4745 mpi_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
4746 mpi_request
->DevHandle
= cpu_to_le16(handle
);
4747 mpi_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
4748 mpi_request
->Control
= cpu_to_le32(mpi_control
);
4749 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
);
4750 mpi_request
->MsgFlags
= MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR
;
4751 mpi_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
4752 mpi_request
->SenseBufferLowAddress
=
4753 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
4754 mpi_request
->SGLOffset0
= offsetof(Mpi25SCSIIORequest_t
, SGL
) / 4;
4755 int_to_scsilun(sas_device_priv_data
->lun
, (struct scsi_lun
*)
4757 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
4759 if (mpi_request
->DataLength
) {
4760 pcie_device
= sas_target_priv_data
->pcie_dev
;
4761 if (ioc
->build_sg_scmd(ioc
, scmd
, smid
, pcie_device
)) {
4762 mpt3sas_base_free_smid(ioc
, smid
);
4763 _scsih_set_satl_pending(scmd
, false);
4767 ioc
->build_zero_len_sge(ioc
, &mpi_request
->SGL
);
4769 raid_device
= sas_target_priv_data
->raid_device
;
4770 if (raid_device
&& raid_device
->direct_io_enabled
)
4771 mpt3sas_setup_direct_io(ioc
, scmd
,
4772 raid_device
, mpi_request
);
4774 if (likely(mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)) {
4775 if (sas_target_priv_data
->flags
& MPT_TARGET_FASTPATH_IO
) {
4776 mpi_request
->IoFlags
= cpu_to_le16(scmd
->cmd_len
|
4777 MPI25_SCSIIO_IOFLAGS_FAST_PATH
);
4778 ioc
->put_smid_fast_path(ioc
, smid
, handle
);
4780 ioc
->put_smid_scsi_io(ioc
, smid
,
4781 le16_to_cpu(mpi_request
->DevHandle
));
4783 ioc
->put_smid_default(ioc
, smid
);
4787 return SCSI_MLQUEUE_HOST_BUSY
;
4791 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4792 * @sense_buffer: sense data returned by target
4793 * @data: normalized skey/asc/ascq
4796 _scsih_normalize_sense(char *sense_buffer
, struct sense_info
*data
)
4798 if ((sense_buffer
[0] & 0x7F) >= 0x72) {
4799 /* descriptor format */
4800 data
->skey
= sense_buffer
[1] & 0x0F;
4801 data
->asc
= sense_buffer
[2];
4802 data
->ascq
= sense_buffer
[3];
4805 data
->skey
= sense_buffer
[2] & 0x0F;
4806 data
->asc
= sense_buffer
[12];
4807 data
->ascq
= sense_buffer
[13];
4812 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
4813 * @ioc: per adapter object
4814 * @scmd: pointer to scsi command object
4815 * @mpi_reply: reply mf payload returned from firmware
4818 * scsi_status - SCSI Status code returned from target device
4819 * scsi_state - state info associated with SCSI_IO determined by ioc
4820 * ioc_status - ioc supplied status info
4823 _scsih_scsi_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, struct scsi_cmnd
*scmd
,
4824 Mpi2SCSIIOReply_t
*mpi_reply
, u16 smid
)
4828 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
4829 MPI2_IOCSTATUS_MASK
;
4830 u8 scsi_state
= mpi_reply
->SCSIState
;
4831 u8 scsi_status
= mpi_reply
->SCSIStatus
;
4832 char *desc_ioc_state
= NULL
;
4833 char *desc_scsi_status
= NULL
;
4834 char *desc_scsi_state
= ioc
->tmp_string
;
4835 u32 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
4836 struct _sas_device
*sas_device
= NULL
;
4837 struct _pcie_device
*pcie_device
= NULL
;
4838 struct scsi_target
*starget
= scmd
->device
->sdev_target
;
4839 struct MPT3SAS_TARGET
*priv_target
= starget
->hostdata
;
4840 char *device_str
= NULL
;
4844 if (ioc
->hide_ir_msg
)
4845 device_str
= "WarpDrive";
4847 device_str
= "volume";
4849 if (log_info
== 0x31170000)
4852 switch (ioc_status
) {
4853 case MPI2_IOCSTATUS_SUCCESS
:
4854 desc_ioc_state
= "success";
4856 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
4857 desc_ioc_state
= "invalid function";
4859 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
4860 desc_ioc_state
= "scsi recovered error";
4862 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
4863 desc_ioc_state
= "scsi invalid dev handle";
4865 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
4866 desc_ioc_state
= "scsi device not there";
4868 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
4869 desc_ioc_state
= "scsi data overrun";
4871 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
4872 desc_ioc_state
= "scsi data underrun";
4874 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
4875 desc_ioc_state
= "scsi io data error";
4877 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
4878 desc_ioc_state
= "scsi protocol error";
4880 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
4881 desc_ioc_state
= "scsi task terminated";
4883 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
4884 desc_ioc_state
= "scsi residual mismatch";
4886 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
4887 desc_ioc_state
= "scsi task mgmt failed";
4889 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
4890 desc_ioc_state
= "scsi ioc terminated";
4892 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
4893 desc_ioc_state
= "scsi ext terminated";
4895 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
4896 desc_ioc_state
= "eedp guard error";
4898 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
4899 desc_ioc_state
= "eedp ref tag error";
4901 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
4902 desc_ioc_state
= "eedp app tag error";
4904 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
4905 desc_ioc_state
= "insufficient power";
4908 desc_ioc_state
= "unknown";
4912 switch (scsi_status
) {
4913 case MPI2_SCSI_STATUS_GOOD
:
4914 desc_scsi_status
= "good";
4916 case MPI2_SCSI_STATUS_CHECK_CONDITION
:
4917 desc_scsi_status
= "check condition";
4919 case MPI2_SCSI_STATUS_CONDITION_MET
:
4920 desc_scsi_status
= "condition met";
4922 case MPI2_SCSI_STATUS_BUSY
:
4923 desc_scsi_status
= "busy";
4925 case MPI2_SCSI_STATUS_INTERMEDIATE
:
4926 desc_scsi_status
= "intermediate";
4928 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET
:
4929 desc_scsi_status
= "intermediate condmet";
4931 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT
:
4932 desc_scsi_status
= "reservation conflict";
4934 case MPI2_SCSI_STATUS_COMMAND_TERMINATED
:
4935 desc_scsi_status
= "command terminated";
4937 case MPI2_SCSI_STATUS_TASK_SET_FULL
:
4938 desc_scsi_status
= "task set full";
4940 case MPI2_SCSI_STATUS_ACA_ACTIVE
:
4941 desc_scsi_status
= "aca active";
4943 case MPI2_SCSI_STATUS_TASK_ABORTED
:
4944 desc_scsi_status
= "task aborted";
4947 desc_scsi_status
= "unknown";
4951 desc_scsi_state
[0] = '\0';
4953 desc_scsi_state
= " ";
4954 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
4955 strcat(desc_scsi_state
, "response info ");
4956 if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
4957 strcat(desc_scsi_state
, "state terminated ");
4958 if (scsi_state
& MPI2_SCSI_STATE_NO_SCSI_STATUS
)
4959 strcat(desc_scsi_state
, "no status ");
4960 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_FAILED
)
4961 strcat(desc_scsi_state
, "autosense failed ");
4962 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
)
4963 strcat(desc_scsi_state
, "autosense valid ");
4965 scsi_print_command(scmd
);
4967 if (priv_target
->flags
& MPT_TARGET_FLAGS_VOLUME
) {
4968 ioc_warn(ioc
, "\t%s wwid(0x%016llx)\n",
4969 device_str
, (u64
)priv_target
->sas_address
);
4970 } else if (priv_target
->flags
& MPT_TARGET_FLAGS_PCIE_DEVICE
) {
4971 pcie_device
= mpt3sas_get_pdev_from_target(ioc
, priv_target
);
4973 ioc_info(ioc
, "\twwid(0x%016llx), port(%d)\n",
4974 (u64
)pcie_device
->wwid
, pcie_device
->port_num
);
4975 if (pcie_device
->enclosure_handle
!= 0)
4976 ioc_info(ioc
, "\tenclosure logical id(0x%016llx), slot(%d)\n",
4977 (u64
)pcie_device
->enclosure_logical_id
,
4979 if (pcie_device
->connector_name
[0])
4980 ioc_info(ioc
, "\tenclosure level(0x%04x), connector name( %s)\n",
4981 pcie_device
->enclosure_level
,
4982 pcie_device
->connector_name
);
4983 pcie_device_put(pcie_device
);
4986 sas_device
= mpt3sas_get_sdev_from_target(ioc
, priv_target
);
4988 ioc_warn(ioc
, "\tsas_address(0x%016llx), phy(%d)\n",
4989 (u64
)sas_device
->sas_address
, sas_device
->phy
);
4991 _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
4994 sas_device_put(sas_device
);
4998 ioc_warn(ioc
, "\thandle(0x%04x), ioc_status(%s)(0x%04x), smid(%d)\n",
4999 le16_to_cpu(mpi_reply
->DevHandle
),
5000 desc_ioc_state
, ioc_status
, smid
);
5001 ioc_warn(ioc
, "\trequest_len(%d), underflow(%d), resid(%d)\n",
5002 scsi_bufflen(scmd
), scmd
->underflow
, scsi_get_resid(scmd
));
5003 ioc_warn(ioc
, "\ttag(%d), transfer_count(%d), sc->result(0x%08x)\n",
5004 le16_to_cpu(mpi_reply
->TaskTag
),
5005 le32_to_cpu(mpi_reply
->TransferCount
), scmd
->result
);
5006 ioc_warn(ioc
, "\tscsi_status(%s)(0x%02x), scsi_state(%s)(0x%02x)\n",
5007 desc_scsi_status
, scsi_status
, desc_scsi_state
, scsi_state
);
5009 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5010 struct sense_info data
;
5011 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5012 ioc_warn(ioc
, "\t[sense_key,asc,ascq]: [0x%02x,0x%02x,0x%02x], count(%d)\n",
5013 data
.skey
, data
.asc
, data
.ascq
,
5014 le32_to_cpu(mpi_reply
->SenseCount
));
5016 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
) {
5017 response_info
= le32_to_cpu(mpi_reply
->ResponseInfo
);
5018 response_bytes
= (u8
*)&response_info
;
5019 _scsih_response_code(ioc
, response_bytes
[0]);
5024 * _scsih_turn_on_pfa_led - illuminate PFA LED
5025 * @ioc: per adapter object
5026 * @handle: device handle
5030 _scsih_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5032 Mpi2SepReply_t mpi_reply
;
5033 Mpi2SepRequest_t mpi_request
;
5034 struct _sas_device
*sas_device
;
5036 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
5040 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5041 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5042 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5043 mpi_request
.SlotStatus
=
5044 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT
);
5045 mpi_request
.DevHandle
= cpu_to_le16(handle
);
5046 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS
;
5047 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5048 &mpi_request
)) != 0) {
5049 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5050 __FILE__
, __LINE__
, __func__
);
5053 sas_device
->pfa_led_on
= 1;
5055 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5057 ioc_info(ioc
, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5058 le16_to_cpu(mpi_reply
.IOCStatus
),
5059 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5063 sas_device_put(sas_device
);
5067 * _scsih_turn_off_pfa_led - turn off Fault LED
5068 * @ioc: per adapter object
5069 * @sas_device: sas device whose PFA LED has to turned off
5073 _scsih_turn_off_pfa_led(struct MPT3SAS_ADAPTER
*ioc
,
5074 struct _sas_device
*sas_device
)
5076 Mpi2SepReply_t mpi_reply
;
5077 Mpi2SepRequest_t mpi_request
;
5079 memset(&mpi_request
, 0, sizeof(Mpi2SepRequest_t
));
5080 mpi_request
.Function
= MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
;
5081 mpi_request
.Action
= MPI2_SEP_REQ_ACTION_WRITE_STATUS
;
5082 mpi_request
.SlotStatus
= 0;
5083 mpi_request
.Slot
= cpu_to_le16(sas_device
->slot
);
5084 mpi_request
.DevHandle
= 0;
5085 mpi_request
.EnclosureHandle
= cpu_to_le16(sas_device
->enclosure_handle
);
5086 mpi_request
.Flags
= MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS
;
5087 if ((mpt3sas_base_scsi_enclosure_processor(ioc
, &mpi_reply
,
5088 &mpi_request
)) != 0) {
5089 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5090 __FILE__
, __LINE__
, __func__
);
5094 if (mpi_reply
.IOCStatus
|| mpi_reply
.IOCLogInfo
) {
5096 ioc_info(ioc
, "enclosure_processor: ioc_status (0x%04x), loginfo(0x%08x)\n",
5097 le16_to_cpu(mpi_reply
.IOCStatus
),
5098 le32_to_cpu(mpi_reply
.IOCLogInfo
)));
5104 * _scsih_send_event_to_turn_on_pfa_led - fire delayed event
5105 * @ioc: per adapter object
5106 * @handle: device handle
5107 * Context: interrupt.
5110 _scsih_send_event_to_turn_on_pfa_led(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5112 struct fw_event_work
*fw_event
;
5114 fw_event
= alloc_fw_event_work(0);
5117 fw_event
->event
= MPT3SAS_TURN_ON_PFA_LED
;
5118 fw_event
->device_handle
= handle
;
5119 fw_event
->ioc
= ioc
;
5120 _scsih_fw_event_add(ioc
, fw_event
);
5121 fw_event_work_put(fw_event
);
5125 * _scsih_smart_predicted_fault - process smart errors
5126 * @ioc: per adapter object
5127 * @handle: device handle
5128 * Context: interrupt.
5131 _scsih_smart_predicted_fault(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5133 struct scsi_target
*starget
;
5134 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5135 Mpi2EventNotificationReply_t
*event_reply
;
5136 Mpi2EventDataSasDeviceStatusChange_t
*event_data
;
5137 struct _sas_device
*sas_device
;
5139 unsigned long flags
;
5141 /* only handle non-raid devices */
5142 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5143 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
5147 starget
= sas_device
->starget
;
5148 sas_target_priv_data
= starget
->hostdata
;
5150 if ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_RAID_COMPONENT
) ||
5151 ((sas_target_priv_data
->flags
& MPT_TARGET_FLAGS_VOLUME
)))
5154 _scsih_display_enclosure_chassis_info(NULL
, sas_device
, NULL
, starget
);
5156 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5158 if (ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
)
5159 _scsih_send_event_to_turn_on_pfa_led(ioc
, handle
);
5161 /* insert into event log */
5162 sz
= offsetof(Mpi2EventNotificationReply_t
, EventData
) +
5163 sizeof(Mpi2EventDataSasDeviceStatusChange_t
);
5164 event_reply
= kzalloc(sz
, GFP_ATOMIC
);
5166 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5167 __FILE__
, __LINE__
, __func__
);
5171 event_reply
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5172 event_reply
->Event
=
5173 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5174 event_reply
->MsgLength
= sz
/4;
5175 event_reply
->EventDataLength
=
5176 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t
)/4);
5177 event_data
= (Mpi2EventDataSasDeviceStatusChange_t
*)
5178 event_reply
->EventData
;
5179 event_data
->ReasonCode
= MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
;
5180 event_data
->ASC
= 0x5D;
5181 event_data
->DevHandle
= cpu_to_le16(handle
);
5182 event_data
->SASAddress
= cpu_to_le64(sas_target_priv_data
->sas_address
);
5183 mpt3sas_ctl_add_to_event_log(ioc
, event_reply
);
5187 sas_device_put(sas_device
);
5191 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
5196 * _scsih_io_done - scsi request callback
5197 * @ioc: per adapter object
5198 * @smid: system request message index
5199 * @msix_index: MSIX table index supplied by the OS
5200 * @reply: reply message frame(lower 32bit addr)
5202 * Callback handler when using _scsih_qcmd.
5204 * Return: 1 meaning mf should be freed from _base_interrupt
5205 * 0 means the mf is freed from this function.
5208 _scsih_io_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5210 Mpi25SCSIIORequest_t
*mpi_request
;
5211 Mpi2SCSIIOReply_t
*mpi_reply
;
5212 struct scsi_cmnd
*scmd
;
5213 struct scsiio_tracker
*st
;
5219 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
5220 u32 response_code
= 0;
5222 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5224 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
5228 _scsih_set_satl_pending(scmd
, false);
5230 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5232 if (mpi_reply
== NULL
) {
5233 scmd
->result
= DID_OK
<< 16;
5237 sas_device_priv_data
= scmd
->device
->hostdata
;
5238 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
||
5239 sas_device_priv_data
->sas_target
->deleted
) {
5240 scmd
->result
= DID_NO_CONNECT
<< 16;
5243 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
5246 * WARPDRIVE: If direct_io is set then it is directIO,
5247 * the failed direct I/O should be redirected to volume
5249 st
= scsi_cmd_priv(scmd
);
5250 if (st
->direct_io
&&
5251 ((ioc_status
& MPI2_IOCSTATUS_MASK
)
5252 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
)) {
5255 memcpy(mpi_request
->CDB
.CDB32
, scmd
->cmnd
, scmd
->cmd_len
);
5256 mpi_request
->DevHandle
=
5257 cpu_to_le16(sas_device_priv_data
->sas_target
->handle
);
5258 ioc
->put_smid_scsi_io(ioc
, smid
,
5259 sas_device_priv_data
->sas_target
->handle
);
5262 /* turning off TLR */
5263 scsi_state
= mpi_reply
->SCSIState
;
5264 if (scsi_state
& MPI2_SCSI_STATE_RESPONSE_INFO_VALID
)
5266 le32_to_cpu(mpi_reply
->ResponseInfo
) & 0xFF;
5267 if (!sas_device_priv_data
->tlr_snoop_check
) {
5268 sas_device_priv_data
->tlr_snoop_check
++;
5269 if ((!ioc
->is_warpdrive
&&
5270 !scsih_is_raid(&scmd
->device
->sdev_gendev
) &&
5271 !scsih_is_nvme(&scmd
->device
->sdev_gendev
))
5272 && sas_is_tlr_enabled(scmd
->device
) &&
5273 response_code
== MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
) {
5274 sas_disable_tlr(scmd
->device
);
5275 sdev_printk(KERN_INFO
, scmd
->device
, "TLR disabled\n");
5279 xfer_cnt
= le32_to_cpu(mpi_reply
->TransferCount
);
5280 scsi_set_resid(scmd
, scsi_bufflen(scmd
) - xfer_cnt
);
5281 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
5282 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
5285 ioc_status
&= MPI2_IOCSTATUS_MASK
;
5286 scsi_status
= mpi_reply
->SCSIStatus
;
5288 if (ioc_status
== MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
&& xfer_cnt
== 0 &&
5289 (scsi_status
== MPI2_SCSI_STATUS_BUSY
||
5290 scsi_status
== MPI2_SCSI_STATUS_RESERVATION_CONFLICT
||
5291 scsi_status
== MPI2_SCSI_STATUS_TASK_SET_FULL
)) {
5292 ioc_status
= MPI2_IOCSTATUS_SUCCESS
;
5295 if (scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
5296 struct sense_info data
;
5297 const void *sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
5299 u32 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
5300 le32_to_cpu(mpi_reply
->SenseCount
));
5301 memcpy(scmd
->sense_buffer
, sense_data
, sz
);
5302 _scsih_normalize_sense(scmd
->sense_buffer
, &data
);
5303 /* failure prediction threshold exceeded */
5304 if (data
.asc
== 0x5D)
5305 _scsih_smart_predicted_fault(ioc
,
5306 le16_to_cpu(mpi_reply
->DevHandle
));
5307 mpt3sas_trigger_scsi(ioc
, data
.skey
, data
.asc
, data
.ascq
);
5309 if ((ioc
->logging_level
& MPT_DEBUG_REPLY
) &&
5310 ((scmd
->sense_buffer
[2] == UNIT_ATTENTION
) ||
5311 (scmd
->sense_buffer
[2] == MEDIUM_ERROR
) ||
5312 (scmd
->sense_buffer
[2] == HARDWARE_ERROR
)))
5313 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5315 switch (ioc_status
) {
5316 case MPI2_IOCSTATUS_BUSY
:
5317 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
5318 scmd
->result
= SAM_STAT_BUSY
;
5321 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
5322 scmd
->result
= DID_NO_CONNECT
<< 16;
5325 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
5326 if (sas_device_priv_data
->block
) {
5327 scmd
->result
= DID_TRANSPORT_DISRUPTED
<< 16;
5330 if (log_info
== 0x31110630) {
5331 if (scmd
->retries
> 2) {
5332 scmd
->result
= DID_NO_CONNECT
<< 16;
5333 scsi_device_set_state(scmd
->device
,
5336 scmd
->result
= DID_SOFT_ERROR
<< 16;
5337 scmd
->device
->expecting_cc_ua
= 1;
5340 } else if (log_info
== VIRTUAL_IO_FAILED_RETRY
) {
5341 scmd
->result
= DID_RESET
<< 16;
5343 } else if ((scmd
->device
->channel
== RAID_CHANNEL
) &&
5344 (scsi_state
== (MPI2_SCSI_STATE_TERMINATED
|
5345 MPI2_SCSI_STATE_NO_SCSI_STATUS
))) {
5346 scmd
->result
= DID_RESET
<< 16;
5349 scmd
->result
= DID_SOFT_ERROR
<< 16;
5351 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
5352 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
5353 scmd
->result
= DID_RESET
<< 16;
5356 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
5357 if ((xfer_cnt
== 0) || (scmd
->underflow
> xfer_cnt
))
5358 scmd
->result
= DID_SOFT_ERROR
<< 16;
5360 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5363 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
5364 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5366 if ((scsi_state
& MPI2_SCSI_STATE_AUTOSENSE_VALID
))
5369 if (xfer_cnt
< scmd
->underflow
) {
5370 if (scsi_status
== SAM_STAT_BUSY
)
5371 scmd
->result
= SAM_STAT_BUSY
;
5373 scmd
->result
= DID_SOFT_ERROR
<< 16;
5374 } else if (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5375 MPI2_SCSI_STATE_NO_SCSI_STATUS
))
5376 scmd
->result
= DID_SOFT_ERROR
<< 16;
5377 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5378 scmd
->result
= DID_RESET
<< 16;
5379 else if (!xfer_cnt
&& scmd
->cmnd
[0] == REPORT_LUNS
) {
5380 mpi_reply
->SCSIState
= MPI2_SCSI_STATE_AUTOSENSE_VALID
;
5381 mpi_reply
->SCSIStatus
= SAM_STAT_CHECK_CONDITION
;
5382 scmd
->result
= (DRIVER_SENSE
<< 24) |
5383 SAM_STAT_CHECK_CONDITION
;
5384 scmd
->sense_buffer
[0] = 0x70;
5385 scmd
->sense_buffer
[2] = ILLEGAL_REQUEST
;
5386 scmd
->sense_buffer
[12] = 0x20;
5387 scmd
->sense_buffer
[13] = 0;
5391 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
5392 scsi_set_resid(scmd
, 0);
5394 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
5395 case MPI2_IOCSTATUS_SUCCESS
:
5396 scmd
->result
= (DID_OK
<< 16) | scsi_status
;
5397 if (response_code
==
5398 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
||
5399 (scsi_state
& (MPI2_SCSI_STATE_AUTOSENSE_FAILED
|
5400 MPI2_SCSI_STATE_NO_SCSI_STATUS
)))
5401 scmd
->result
= DID_SOFT_ERROR
<< 16;
5402 else if (scsi_state
& MPI2_SCSI_STATE_TERMINATED
)
5403 scmd
->result
= DID_RESET
<< 16;
5406 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
5407 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
5408 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
5409 _scsih_eedp_error_handling(scmd
, ioc_status
);
5412 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
5413 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
5414 case MPI2_IOCSTATUS_INVALID_SGL
:
5415 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
5416 case MPI2_IOCSTATUS_INVALID_FIELD
:
5417 case MPI2_IOCSTATUS_INVALID_STATE
:
5418 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
5419 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
5420 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
5422 scmd
->result
= DID_SOFT_ERROR
<< 16;
5427 if (scmd
->result
&& (ioc
->logging_level
& MPT_DEBUG_REPLY
))
5428 _scsih_scsi_ioc_info(ioc
, scmd
, mpi_reply
, smid
);
5432 scsi_dma_unmap(scmd
);
5433 mpt3sas_base_free_smid(ioc
, smid
);
5434 scmd
->scsi_done(scmd
);
5439 * _scsih_sas_host_refresh - refreshing sas host object contents
5440 * @ioc: per adapter object
5443 * During port enable, fw will send topology events for every device. Its
5444 * possible that the handles may change from the previous setting, so this
5445 * code keeping handles updating if changed.
5448 _scsih_sas_host_refresh(struct MPT3SAS_ADAPTER
*ioc
)
5453 Mpi2ConfigReply_t mpi_reply
;
5454 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5455 u16 attached_handle
;
5459 ioc_info(ioc
, "updating handles for sas_host(0x%016llx)\n",
5460 (u64
)ioc
->sas_hba
.sas_address
));
5462 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
5463 * sizeof(Mpi2SasIOUnit0PhyData_t
));
5464 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5465 if (!sas_iounit_pg0
) {
5466 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5467 __FILE__
, __LINE__
, __func__
);
5471 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5472 sas_iounit_pg0
, sz
)) != 0)
5474 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5475 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5477 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5478 link_rate
= sas_iounit_pg0
->PhyData
[i
].NegotiatedLinkRate
>> 4;
5480 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5481 PhyData
[0].ControllerDevHandle
);
5482 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5483 attached_handle
= le16_to_cpu(sas_iounit_pg0
->PhyData
[i
].
5485 if (attached_handle
&& link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
5486 link_rate
= MPI2_SAS_NEG_LINK_RATE_1_5
;
5487 mpt3sas_transport_update_links(ioc
, ioc
->sas_hba
.sas_address
,
5488 attached_handle
, i
, link_rate
);
5491 kfree(sas_iounit_pg0
);
5495 * _scsih_sas_host_add - create sas host object
5496 * @ioc: per adapter object
5498 * Creating host side data object, stored in ioc->sas_hba
5501 _scsih_sas_host_add(struct MPT3SAS_ADAPTER
*ioc
)
5504 Mpi2ConfigReply_t mpi_reply
;
5505 Mpi2SasIOUnitPage0_t
*sas_iounit_pg0
= NULL
;
5506 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
5507 Mpi2SasPhyPage0_t phy_pg0
;
5508 Mpi2SasDevicePage0_t sas_device_pg0
;
5509 Mpi2SasEnclosurePage0_t enclosure_pg0
;
5512 u8 device_missing_delay
;
5515 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
5517 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5518 __FILE__
, __LINE__
, __func__
);
5521 ioc
->sas_hba
.phy
= kcalloc(num_phys
,
5522 sizeof(struct _sas_phy
), GFP_KERNEL
);
5523 if (!ioc
->sas_hba
.phy
) {
5524 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5525 __FILE__
, __LINE__
, __func__
);
5528 ioc
->sas_hba
.num_phys
= num_phys
;
5530 /* sas_iounit page 0 */
5531 sz
= offsetof(Mpi2SasIOUnitPage0_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5532 sizeof(Mpi2SasIOUnit0PhyData_t
));
5533 sas_iounit_pg0
= kzalloc(sz
, GFP_KERNEL
);
5534 if (!sas_iounit_pg0
) {
5535 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5536 __FILE__
, __LINE__
, __func__
);
5539 if ((mpt3sas_config_get_sas_iounit_pg0(ioc
, &mpi_reply
,
5540 sas_iounit_pg0
, sz
))) {
5541 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5542 __FILE__
, __LINE__
, __func__
);
5545 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5546 MPI2_IOCSTATUS_MASK
;
5547 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5548 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5549 __FILE__
, __LINE__
, __func__
);
5553 /* sas_iounit page 1 */
5554 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (ioc
->sas_hba
.num_phys
*
5555 sizeof(Mpi2SasIOUnit1PhyData_t
));
5556 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
5557 if (!sas_iounit_pg1
) {
5558 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5559 __FILE__
, __LINE__
, __func__
);
5562 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
5563 sas_iounit_pg1
, sz
))) {
5564 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5565 __FILE__
, __LINE__
, __func__
);
5568 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5569 MPI2_IOCSTATUS_MASK
;
5570 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5571 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5572 __FILE__
, __LINE__
, __func__
);
5576 ioc
->io_missing_delay
=
5577 sas_iounit_pg1
->IODeviceMissingDelay
;
5578 device_missing_delay
=
5579 sas_iounit_pg1
->ReportDeviceMissingDelay
;
5580 if (device_missing_delay
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
5581 ioc
->device_missing_delay
= (device_missing_delay
&
5582 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
5584 ioc
->device_missing_delay
= device_missing_delay
&
5585 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
5587 ioc
->sas_hba
.parent_dev
= &ioc
->shost
->shost_gendev
;
5588 for (i
= 0; i
< ioc
->sas_hba
.num_phys
; i
++) {
5589 if ((mpt3sas_config_get_phy_pg0(ioc
, &mpi_reply
, &phy_pg0
,
5591 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5592 __FILE__
, __LINE__
, __func__
);
5595 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5596 MPI2_IOCSTATUS_MASK
;
5597 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5598 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5599 __FILE__
, __LINE__
, __func__
);
5604 ioc
->sas_hba
.handle
= le16_to_cpu(sas_iounit_pg0
->
5605 PhyData
[0].ControllerDevHandle
);
5606 ioc
->sas_hba
.phy
[i
].handle
= ioc
->sas_hba
.handle
;
5607 ioc
->sas_hba
.phy
[i
].phy_id
= i
;
5608 mpt3sas_transport_add_host_phy(ioc
, &ioc
->sas_hba
.phy
[i
],
5609 phy_pg0
, ioc
->sas_hba
.parent_dev
);
5611 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5612 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, ioc
->sas_hba
.handle
))) {
5613 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5614 __FILE__
, __LINE__
, __func__
);
5617 ioc
->sas_hba
.enclosure_handle
=
5618 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5619 ioc
->sas_hba
.sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5620 ioc_info(ioc
, "host_add: handle(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5621 ioc
->sas_hba
.handle
,
5622 (u64
)ioc
->sas_hba
.sas_address
,
5623 ioc
->sas_hba
.num_phys
);
5625 if (ioc
->sas_hba
.enclosure_handle
) {
5626 if (!(mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
5627 &enclosure_pg0
, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
5628 ioc
->sas_hba
.enclosure_handle
)))
5629 ioc
->sas_hba
.enclosure_logical_id
=
5630 le64_to_cpu(enclosure_pg0
.EnclosureLogicalID
);
5634 kfree(sas_iounit_pg1
);
5635 kfree(sas_iounit_pg0
);
5639 * _scsih_expander_add - creating expander object
5640 * @ioc: per adapter object
5641 * @handle: expander handle
5643 * Creating expander object, stored in ioc->sas_expander_list.
5645 * Return: 0 for success, else error.
5648 _scsih_expander_add(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
5650 struct _sas_node
*sas_expander
;
5651 struct _enclosure_node
*enclosure_dev
;
5652 Mpi2ConfigReply_t mpi_reply
;
5653 Mpi2ExpanderPage0_t expander_pg0
;
5654 Mpi2ExpanderPage1_t expander_pg1
;
5657 u64 sas_address
, sas_address_parent
= 0;
5659 unsigned long flags
;
5660 struct _sas_port
*mpt3sas_port
= NULL
;
5667 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
5670 if ((mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
5671 MPI2_SAS_EXPAND_PGAD_FORM_HNDL
, handle
))) {
5672 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5673 __FILE__
, __LINE__
, __func__
);
5677 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
5678 MPI2_IOCSTATUS_MASK
;
5679 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5680 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5681 __FILE__
, __LINE__
, __func__
);
5685 /* handle out of order topology events */
5686 parent_handle
= le16_to_cpu(expander_pg0
.ParentDevHandle
);
5687 if (_scsih_get_sas_address(ioc
, parent_handle
, &sas_address_parent
)
5689 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5690 __FILE__
, __LINE__
, __func__
);
5693 if (sas_address_parent
!= ioc
->sas_hba
.sas_address
) {
5694 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5695 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5696 sas_address_parent
);
5697 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5698 if (!sas_expander
) {
5699 rc
= _scsih_expander_add(ioc
, parent_handle
);
5705 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5706 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
5707 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5709 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5714 sas_expander
= kzalloc(sizeof(struct _sas_node
),
5716 if (!sas_expander
) {
5717 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5718 __FILE__
, __LINE__
, __func__
);
5722 sas_expander
->handle
= handle
;
5723 sas_expander
->num_phys
= expander_pg0
.NumPhys
;
5724 sas_expander
->sas_address_parent
= sas_address_parent
;
5725 sas_expander
->sas_address
= sas_address
;
5727 ioc_info(ioc
, "expander_add: handle(0x%04x), parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n",
5728 handle
, parent_handle
,
5729 (u64
)sas_expander
->sas_address
, sas_expander
->num_phys
);
5731 if (!sas_expander
->num_phys
)
5733 sas_expander
->phy
= kcalloc(sas_expander
->num_phys
,
5734 sizeof(struct _sas_phy
), GFP_KERNEL
);
5735 if (!sas_expander
->phy
) {
5736 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5737 __FILE__
, __LINE__
, __func__
);
5742 INIT_LIST_HEAD(&sas_expander
->sas_port_list
);
5743 mpt3sas_port
= mpt3sas_transport_port_add(ioc
, handle
,
5744 sas_address_parent
);
5745 if (!mpt3sas_port
) {
5746 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5747 __FILE__
, __LINE__
, __func__
);
5751 sas_expander
->parent_dev
= &mpt3sas_port
->rphy
->dev
;
5753 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
5754 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
5755 &expander_pg1
, i
, handle
))) {
5756 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5757 __FILE__
, __LINE__
, __func__
);
5761 sas_expander
->phy
[i
].handle
= handle
;
5762 sas_expander
->phy
[i
].phy_id
= i
;
5764 if ((mpt3sas_transport_add_expander_phy(ioc
,
5765 &sas_expander
->phy
[i
], expander_pg1
,
5766 sas_expander
->parent_dev
))) {
5767 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
5768 __FILE__
, __LINE__
, __func__
);
5774 if (sas_expander
->enclosure_handle
) {
5776 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
5777 sas_expander
->enclosure_handle
);
5779 sas_expander
->enclosure_logical_id
=
5780 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
5783 _scsih_expander_node_add(ioc
, sas_expander
);
5789 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
5790 sas_address_parent
);
5791 kfree(sas_expander
);
5796 * mpt3sas_expander_remove - removing expander object
5797 * @ioc: per adapter object
5798 * @sas_address: expander sas_address
5801 mpt3sas_expander_remove(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
)
5803 struct _sas_node
*sas_expander
;
5804 unsigned long flags
;
5806 if (ioc
->shost_recovery
)
5809 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
5810 sas_expander
= mpt3sas_scsih_expander_find_by_sas_address(ioc
,
5812 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
5814 _scsih_expander_node_remove(ioc
, sas_expander
);
5818 * _scsih_done - internal SCSI_IO callback handler.
5819 * @ioc: per adapter object
5820 * @smid: system request message index
5821 * @msix_index: MSIX table index supplied by the OS
5822 * @reply: reply message frame(lower 32bit addr)
5824 * Callback handler when sending internal generated SCSI_IO.
5825 * The callback index passed is `ioc->scsih_cb_idx`
5827 * Return: 1 meaning mf should be freed from _base_interrupt
5828 * 0 means the mf is freed from this function.
5831 _scsih_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
, u32 reply
)
5833 MPI2DefaultReply_t
*mpi_reply
;
5835 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5836 if (ioc
->scsih_cmds
.status
== MPT3_CMD_NOT_USED
)
5838 if (ioc
->scsih_cmds
.smid
!= smid
)
5840 ioc
->scsih_cmds
.status
|= MPT3_CMD_COMPLETE
;
5842 memcpy(ioc
->scsih_cmds
.reply
, mpi_reply
,
5843 mpi_reply
->MsgLength
*4);
5844 ioc
->scsih_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5846 ioc
->scsih_cmds
.status
&= ~MPT3_CMD_PENDING
;
5847 complete(&ioc
->scsih_cmds
.done
);
5854 #define MPT3_MAX_LUNS (255)
5858 * _scsih_check_access_status - check access flags
5859 * @ioc: per adapter object
5860 * @sas_address: sas address
5861 * @handle: sas device handle
5862 * @access_status: errors returned during discovery of the device
5864 * Return: 0 for success, else failure
5867 _scsih_check_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 sas_address
,
5868 u16 handle
, u8 access_status
)
5873 switch (access_status
) {
5874 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS
:
5875 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION
:
5878 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED
:
5879 desc
= "sata capability failed";
5881 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT
:
5882 desc
= "sata affiliation conflict";
5884 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE
:
5885 desc
= "route not addressable";
5887 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE
:
5888 desc
= "smp error not addressable";
5890 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED
:
5891 desc
= "device blocked";
5893 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED
:
5894 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN
:
5895 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT
:
5896 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG
:
5897 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION
:
5898 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER
:
5899 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN
:
5900 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN
:
5901 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN
:
5902 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION
:
5903 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE
:
5904 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX
:
5905 desc
= "sata initialization failed";
5915 ioc_err(ioc
, "discovery errors(%s): sas_address(0x%016llx), handle(0x%04x)\n",
5916 desc
, (u64
)sas_address
, handle
);
5921 * _scsih_check_device - checking device responsiveness
5922 * @ioc: per adapter object
5923 * @parent_sas_address: sas address of parent expander or sas host
5924 * @handle: attached device handle
5925 * @phy_number: phy number
5926 * @link_rate: new link rate
5929 _scsih_check_device(struct MPT3SAS_ADAPTER
*ioc
,
5930 u64 parent_sas_address
, u16 handle
, u8 phy_number
, u8 link_rate
)
5932 Mpi2ConfigReply_t mpi_reply
;
5933 Mpi2SasDevicePage0_t sas_device_pg0
;
5934 struct _sas_device
*sas_device
;
5935 struct _enclosure_node
*enclosure_dev
= NULL
;
5937 unsigned long flags
;
5939 struct scsi_target
*starget
;
5940 struct MPT3SAS_TARGET
*sas_target_priv_data
;
5943 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
5944 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
)))
5947 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5948 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5951 /* wide port handling ~ we need only handle device once for the phy that
5952 * is matched in sas device page zero
5954 if (phy_number
!= sas_device_pg0
.PhyNum
)
5957 /* check if this is end device */
5958 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
5959 if (!(_scsih_is_end_device(device_info
)))
5962 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
5963 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
5964 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
5970 if (unlikely(sas_device
->handle
!= handle
)) {
5971 starget
= sas_device
->starget
;
5972 sas_target_priv_data
= starget
->hostdata
;
5973 starget_printk(KERN_INFO
, starget
,
5974 "handle changed from(0x%04x) to (0x%04x)!!!\n",
5975 sas_device
->handle
, handle
);
5976 sas_target_priv_data
->handle
= handle
;
5977 sas_device
->handle
= handle
;
5978 if (le16_to_cpu(sas_device_pg0
.Flags
) &
5979 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
5980 sas_device
->enclosure_level
=
5981 sas_device_pg0
.EnclosureLevel
;
5982 memcpy(sas_device
->connector_name
,
5983 sas_device_pg0
.ConnectorName
, 4);
5984 sas_device
->connector_name
[4] = '\0';
5986 sas_device
->enclosure_level
= 0;
5987 sas_device
->connector_name
[0] = '\0';
5990 sas_device
->enclosure_handle
=
5991 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
5992 sas_device
->is_chassis_slot_valid
= 0;
5993 enclosure_dev
= mpt3sas_scsih_enclosure_find_by_handle(ioc
,
5994 sas_device
->enclosure_handle
);
5995 if (enclosure_dev
) {
5996 sas_device
->enclosure_logical_id
=
5997 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
5998 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
5999 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6000 sas_device
->is_chassis_slot_valid
= 1;
6001 sas_device
->chassis_slot
=
6002 enclosure_dev
->pg0
.ChassisSlot
;
6007 /* check if device is present */
6008 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6009 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6010 ioc_err(ioc
, "device is not present handle(0x%04x), flags!!!\n",
6015 /* check if there were any issues with discovery */
6016 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6017 sas_device_pg0
.AccessStatus
))
6020 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6021 _scsih_ublock_io_device(ioc
, sas_address
);
6024 sas_device_put(sas_device
);
6028 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6030 sas_device_put(sas_device
);
6034 * _scsih_add_device - creating sas device object
6035 * @ioc: per adapter object
6036 * @handle: sas device handle
6037 * @phy_num: phy number end device attached to
6038 * @is_pd: is this hidden raid component
6040 * Creating end device object, stored in ioc->sas_device_list.
6042 * Return: 0 for success, non-zero for failure.
6045 _scsih_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phy_num
,
6048 Mpi2ConfigReply_t mpi_reply
;
6049 Mpi2SasDevicePage0_t sas_device_pg0
;
6050 struct _sas_device
*sas_device
;
6051 struct _enclosure_node
*enclosure_dev
= NULL
;
6056 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
6057 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6058 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6059 __FILE__
, __LINE__
, __func__
);
6063 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6064 MPI2_IOCSTATUS_MASK
;
6065 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6066 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6067 __FILE__
, __LINE__
, __func__
);
6071 /* check if this is end device */
6072 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
6073 if (!(_scsih_is_end_device(device_info
)))
6075 set_bit(handle
, ioc
->pend_os_device_add
);
6076 sas_address
= le64_to_cpu(sas_device_pg0
.SASAddress
);
6078 /* check if device is present */
6079 if (!(le16_to_cpu(sas_device_pg0
.Flags
) &
6080 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT
)) {
6081 ioc_err(ioc
, "device is not present handle(0x04%x)!!!\n",
6086 /* check if there were any issues with discovery */
6087 if (_scsih_check_access_status(ioc
, sas_address
, handle
,
6088 sas_device_pg0
.AccessStatus
))
6091 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
6094 clear_bit(handle
, ioc
->pend_os_device_add
);
6095 sas_device_put(sas_device
);
6099 if (sas_device_pg0
.EnclosureHandle
) {
6101 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6102 le16_to_cpu(sas_device_pg0
.EnclosureHandle
));
6103 if (enclosure_dev
== NULL
)
6104 ioc_info(ioc
, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
6105 sas_device_pg0
.EnclosureHandle
);
6108 sas_device
= kzalloc(sizeof(struct _sas_device
),
6111 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6112 __FILE__
, __LINE__
, __func__
);
6116 kref_init(&sas_device
->refcount
);
6117 sas_device
->handle
= handle
;
6118 if (_scsih_get_sas_address(ioc
,
6119 le16_to_cpu(sas_device_pg0
.ParentDevHandle
),
6120 &sas_device
->sas_address_parent
) != 0)
6121 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6122 __FILE__
, __LINE__
, __func__
);
6123 sas_device
->enclosure_handle
=
6124 le16_to_cpu(sas_device_pg0
.EnclosureHandle
);
6125 if (sas_device
->enclosure_handle
!= 0)
6127 le16_to_cpu(sas_device_pg0
.Slot
);
6128 sas_device
->device_info
= device_info
;
6129 sas_device
->sas_address
= sas_address
;
6130 sas_device
->phy
= sas_device_pg0
.PhyNum
;
6131 sas_device
->fast_path
= (le16_to_cpu(sas_device_pg0
.Flags
) &
6132 MPI25_SAS_DEVICE0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6134 if (le16_to_cpu(sas_device_pg0
.Flags
)
6135 & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
6136 sas_device
->enclosure_level
=
6137 sas_device_pg0
.EnclosureLevel
;
6138 memcpy(sas_device
->connector_name
,
6139 sas_device_pg0
.ConnectorName
, 4);
6140 sas_device
->connector_name
[4] = '\0';
6142 sas_device
->enclosure_level
= 0;
6143 sas_device
->connector_name
[0] = '\0';
6145 /* get enclosure_logical_id & chassis_slot*/
6146 sas_device
->is_chassis_slot_valid
= 0;
6147 if (enclosure_dev
) {
6148 sas_device
->enclosure_logical_id
=
6149 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6150 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
6151 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
6152 sas_device
->is_chassis_slot_valid
= 1;
6153 sas_device
->chassis_slot
=
6154 enclosure_dev
->pg0
.ChassisSlot
;
6158 /* get device name */
6159 sas_device
->device_name
= le64_to_cpu(sas_device_pg0
.DeviceName
);
6161 if (ioc
->wait_for_discovery_to_complete
)
6162 _scsih_sas_device_init_add(ioc
, sas_device
);
6164 _scsih_sas_device_add(ioc
, sas_device
);
6166 sas_device_put(sas_device
);
6171 * _scsih_remove_device - removing sas device object
6172 * @ioc: per adapter object
6173 * @sas_device: the sas_device object
6176 _scsih_remove_device(struct MPT3SAS_ADAPTER
*ioc
,
6177 struct _sas_device
*sas_device
)
6179 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6181 if ((ioc
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_IBM
) &&
6182 (sas_device
->pfa_led_on
)) {
6183 _scsih_turn_off_pfa_led(ioc
, sas_device
);
6184 sas_device
->pfa_led_on
= 0;
6188 ioc_info(ioc
, "%s: enter: handle(0x%04x), sas_addr(0x%016llx)\n",
6190 sas_device
->handle
, (u64
)sas_device
->sas_address
));
6192 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6195 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
6196 sas_target_priv_data
= sas_device
->starget
->hostdata
;
6197 sas_target_priv_data
->deleted
= 1;
6198 _scsih_ublock_io_device(ioc
, sas_device
->sas_address
);
6199 sas_target_priv_data
->handle
=
6200 MPT3SAS_INVALID_DEVICE_HANDLE
;
6203 if (!ioc
->hide_drives
)
6204 mpt3sas_transport_port_remove(ioc
,
6205 sas_device
->sas_address
,
6206 sas_device
->sas_address_parent
);
6208 ioc_info(ioc
, "removing handle(0x%04x), sas_addr(0x%016llx)\n",
6209 sas_device
->handle
, (u64
)sas_device
->sas_address
);
6211 _scsih_display_enclosure_chassis_info(ioc
, sas_device
, NULL
, NULL
);
6214 ioc_info(ioc
, "%s: exit: handle(0x%04x), sas_addr(0x%016llx)\n",
6216 sas_device
->handle
, (u64
)sas_device
->sas_address
));
6217 dewtprintk(ioc
, _scsih_display_enclosure_chassis_info(ioc
, sas_device
,
6222 * _scsih_sas_topology_change_event_debug - debug for topology event
6223 * @ioc: per adapter object
6224 * @event_data: event data payload
6228 _scsih_sas_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6229 Mpi2EventDataSasTopologyChangeList_t
*event_data
)
6235 char *status_str
= NULL
;
6236 u8 link_rate
, prev_link_rate
;
6238 switch (event_data
->ExpStatus
) {
6239 case MPI2_EVENT_SAS_TOPO_ES_ADDED
:
6242 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
:
6243 status_str
= "remove";
6245 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING
:
6247 status_str
= "responding";
6249 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
:
6250 status_str
= "remove delay";
6253 status_str
= "unknown status";
6256 ioc_info(ioc
, "sas topology change: (%s)\n", status_str
);
6257 pr_info("\thandle(0x%04x), enclosure_handle(0x%04x) " \
6258 "start_phy(%02d), count(%d)\n",
6259 le16_to_cpu(event_data
->ExpanderDevHandle
),
6260 le16_to_cpu(event_data
->EnclosureHandle
),
6261 event_data
->StartPhyNum
, event_data
->NumEntries
);
6262 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6263 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6266 phy_number
= event_data
->StartPhyNum
+ i
;
6267 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6268 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6269 switch (reason_code
) {
6270 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6271 status_str
= "target add";
6273 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6274 status_str
= "target remove";
6276 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING
:
6277 status_str
= "delay target remove";
6279 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6280 status_str
= "link rate change";
6282 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE
:
6283 status_str
= "target responding";
6286 status_str
= "unknown";
6289 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6290 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6291 pr_info("\tphy(%02d), attached_handle(0x%04x): %s:" \
6292 " link rate: new(0x%02x), old(0x%02x)\n", phy_number
,
6293 handle
, status_str
, link_rate
, prev_link_rate
);
6299 * _scsih_sas_topology_change_event - handle topology changes
6300 * @ioc: per adapter object
6301 * @fw_event: The fw_event_work object
6306 _scsih_sas_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6307 struct fw_event_work
*fw_event
)
6310 u16 parent_handle
, handle
;
6312 u8 phy_number
, max_phys
;
6313 struct _sas_node
*sas_expander
;
6315 unsigned long flags
;
6316 u8 link_rate
, prev_link_rate
;
6317 Mpi2EventDataSasTopologyChangeList_t
*event_data
=
6318 (Mpi2EventDataSasTopologyChangeList_t
*)
6319 fw_event
->event_data
;
6321 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6322 _scsih_sas_topology_change_event_debug(ioc
, event_data
);
6324 if (ioc
->shost_recovery
|| ioc
->remove_host
|| ioc
->pci_error_recovery
)
6327 if (!ioc
->sas_hba
.num_phys
)
6328 _scsih_sas_host_add(ioc
);
6330 _scsih_sas_host_refresh(ioc
);
6332 if (fw_event
->ignore
) {
6333 dewtprintk(ioc
, ioc_info(ioc
, "ignoring expander event\n"));
6337 parent_handle
= le16_to_cpu(event_data
->ExpanderDevHandle
);
6339 /* handle expander add */
6340 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_ADDED
)
6341 if (_scsih_expander_add(ioc
, parent_handle
) != 0)
6344 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
6345 sas_expander
= mpt3sas_scsih_expander_find_by_handle(ioc
,
6348 sas_address
= sas_expander
->sas_address
;
6349 max_phys
= sas_expander
->num_phys
;
6350 } else if (parent_handle
< ioc
->sas_hba
.num_phys
) {
6351 sas_address
= ioc
->sas_hba
.sas_address
;
6352 max_phys
= ioc
->sas_hba
.num_phys
;
6354 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6357 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
6359 /* handle siblings events */
6360 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6361 if (fw_event
->ignore
) {
6363 ioc_info(ioc
, "ignoring expander event\n"));
6366 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
6368 phy_number
= event_data
->StartPhyNum
+ i
;
6369 if (phy_number
>= max_phys
)
6371 reason_code
= event_data
->PHY
[i
].PhyStatus
&
6372 MPI2_EVENT_SAS_TOPO_RC_MASK
;
6373 if ((event_data
->PHY
[i
].PhyStatus
&
6374 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT
) && (reason_code
!=
6375 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
))
6377 handle
= le16_to_cpu(event_data
->PHY
[i
].AttachedDevHandle
);
6380 link_rate
= event_data
->PHY
[i
].LinkRate
>> 4;
6381 prev_link_rate
= event_data
->PHY
[i
].LinkRate
& 0xF;
6382 switch (reason_code
) {
6383 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED
:
6385 if (ioc
->shost_recovery
)
6388 if (link_rate
== prev_link_rate
)
6391 mpt3sas_transport_update_links(ioc
, sas_address
,
6392 handle
, phy_number
, link_rate
);
6394 if (link_rate
< MPI2_SAS_NEG_LINK_RATE_1_5
)
6397 _scsih_check_device(ioc
, sas_address
, handle
,
6398 phy_number
, link_rate
);
6400 if (!test_bit(handle
, ioc
->pend_os_device_add
))
6405 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED
:
6407 if (ioc
->shost_recovery
)
6410 mpt3sas_transport_update_links(ioc
, sas_address
,
6411 handle
, phy_number
, link_rate
);
6413 _scsih_add_device(ioc
, handle
, phy_number
, 0);
6416 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING
:
6418 _scsih_device_remove_by_handle(ioc
, handle
);
6423 /* handle expander removal */
6424 if (event_data
->ExpStatus
== MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING
&&
6426 mpt3sas_expander_remove(ioc
, sas_address
);
6432 * _scsih_sas_device_status_change_event_debug - debug for device event
6434 * @event_data: event data payload
6438 _scsih_sas_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6439 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6441 char *reason_str
= NULL
;
6443 switch (event_data
->ReasonCode
) {
6444 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
6445 reason_str
= "smart data";
6447 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
6448 reason_str
= "unsupported device discovered";
6450 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
6451 reason_str
= "internal device reset";
6453 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
6454 reason_str
= "internal task abort";
6456 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
6457 reason_str
= "internal task abort set";
6459 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
6460 reason_str
= "internal clear task set";
6462 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
6463 reason_str
= "internal query task";
6465 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE
:
6466 reason_str
= "sata init failure";
6468 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
6469 reason_str
= "internal device reset complete";
6471 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
6472 reason_str
= "internal task abort complete";
6474 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION
:
6475 reason_str
= "internal async notification";
6477 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY
:
6478 reason_str
= "expander reduced functionality";
6480 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY
:
6481 reason_str
= "expander reduced functionality complete";
6484 reason_str
= "unknown reason";
6487 ioc_info(ioc
, "device status change: (%s)\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
6488 reason_str
, le16_to_cpu(event_data
->DevHandle
),
6489 (u64
)le64_to_cpu(event_data
->SASAddress
),
6490 le16_to_cpu(event_data
->TaskTag
));
6491 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA
)
6492 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
6493 event_data
->ASC
, event_data
->ASCQ
);
6498 * _scsih_sas_device_status_change_event - handle device status change
6499 * @ioc: per adapter object
6500 * @event_data: The fw event
6504 _scsih_sas_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
6505 Mpi2EventDataSasDeviceStatusChange_t
*event_data
)
6507 struct MPT3SAS_TARGET
*target_priv_data
;
6508 struct _sas_device
*sas_device
;
6510 unsigned long flags
;
6512 /* In MPI Revision K (0xC), the internal device reset complete was
6513 * implemented, so avoid setting tm_busy flag for older firmware.
6515 if ((ioc
->facts
.HeaderVersion
>> 8) < 0xC)
6518 if (event_data
->ReasonCode
!=
6519 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
6520 event_data
->ReasonCode
!=
6521 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
6524 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
6525 sas_address
= le64_to_cpu(event_data
->SASAddress
);
6526 sas_device
= __mpt3sas_get_sdev_by_addr(ioc
,
6529 if (!sas_device
|| !sas_device
->starget
)
6532 target_priv_data
= sas_device
->starget
->hostdata
;
6533 if (!target_priv_data
)
6536 if (event_data
->ReasonCode
==
6537 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
)
6538 target_priv_data
->tm_busy
= 1;
6540 target_priv_data
->tm_busy
= 0;
6542 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
6544 "%s tm_busy flag for handle(0x%04x)\n",
6545 (target_priv_data
->tm_busy
== 1) ? "Enable" : "Disable",
6546 target_priv_data
->handle
);
6550 sas_device_put(sas_device
);
6552 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
6557 * _scsih_check_pcie_access_status - check access flags
6558 * @ioc: per adapter object
6560 * @handle: sas device handle
6561 * @access_status: errors returned during discovery of the device
6563 * Return: 0 for success, else failure
6566 _scsih_check_pcie_access_status(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
6567 u16 handle
, u8 access_status
)
6572 switch (access_status
) {
6573 case MPI26_PCIEDEV0_ASTATUS_NO_ERRORS
:
6574 case MPI26_PCIEDEV0_ASTATUS_NEEDS_INITIALIZATION
:
6577 case MPI26_PCIEDEV0_ASTATUS_CAPABILITY_FAILED
:
6578 desc
= "PCIe device capability failed";
6580 case MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
:
6581 desc
= "PCIe device blocked";
6583 "Device with Access Status (%s): wwid(0x%016llx), "
6584 "handle(0x%04x)\n ll only be added to the internal list",
6585 desc
, (u64
)wwid
, handle
);
6588 case MPI26_PCIEDEV0_ASTATUS_MEMORY_SPACE_ACCESS_FAILED
:
6589 desc
= "PCIe device mem space access failed";
6591 case MPI26_PCIEDEV0_ASTATUS_UNSUPPORTED_DEVICE
:
6592 desc
= "PCIe device unsupported";
6594 case MPI26_PCIEDEV0_ASTATUS_MSIX_REQUIRED
:
6595 desc
= "PCIe device MSIx Required";
6597 case MPI26_PCIEDEV0_ASTATUS_INIT_FAIL_MAX
:
6598 desc
= "PCIe device init fail max";
6600 case MPI26_PCIEDEV0_ASTATUS_UNKNOWN
:
6601 desc
= "PCIe device status unknown";
6603 case MPI26_PCIEDEV0_ASTATUS_NVME_READY_TIMEOUT
:
6604 desc
= "nvme ready timeout";
6606 case MPI26_PCIEDEV0_ASTATUS_NVME_DEVCFG_UNSUPPORTED
:
6607 desc
= "nvme device configuration unsupported";
6609 case MPI26_PCIEDEV0_ASTATUS_NVME_IDENTIFY_FAILED
:
6610 desc
= "nvme identify failed";
6612 case MPI26_PCIEDEV0_ASTATUS_NVME_QCONFIG_FAILED
:
6613 desc
= "nvme qconfig failed";
6615 case MPI26_PCIEDEV0_ASTATUS_NVME_QCREATION_FAILED
:
6616 desc
= "nvme qcreation failed";
6618 case MPI26_PCIEDEV0_ASTATUS_NVME_EVENTCFG_FAILED
:
6619 desc
= "nvme eventcfg failed";
6621 case MPI26_PCIEDEV0_ASTATUS_NVME_GET_FEATURE_STAT_FAILED
:
6622 desc
= "nvme get feature stat failed";
6624 case MPI26_PCIEDEV0_ASTATUS_NVME_IDLE_TIMEOUT
:
6625 desc
= "nvme idle timeout";
6627 case MPI26_PCIEDEV0_ASTATUS_NVME_FAILURE_STATUS
:
6628 desc
= "nvme failure status";
6631 ioc_err(ioc
, "NVMe discovery error(0x%02x): wwid(0x%016llx), handle(0x%04x)\n",
6632 access_status
, (u64
)wwid
, handle
);
6639 ioc_info(ioc
, "NVMe discovery error(%s): wwid(0x%016llx), handle(0x%04x)\n",
6640 desc
, (u64
)wwid
, handle
);
6645 * _scsih_pcie_device_remove_from_sml - removing pcie device
6646 * from SML and free up associated memory
6647 * @ioc: per adapter object
6648 * @pcie_device: the pcie_device object
6651 _scsih_pcie_device_remove_from_sml(struct MPT3SAS_ADAPTER
*ioc
,
6652 struct _pcie_device
*pcie_device
)
6654 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6657 ioc_info(ioc
, "%s: enter: handle(0x%04x), wwid(0x%016llx)\n",
6659 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
6660 if (pcie_device
->enclosure_handle
!= 0)
6662 ioc_info(ioc
, "%s: enter: enclosure logical id(0x%016llx), slot(%d)\n",
6664 (u64
)pcie_device
->enclosure_logical_id
,
6665 pcie_device
->slot
));
6666 if (pcie_device
->connector_name
[0] != '\0')
6668 ioc_info(ioc
, "%s: enter: enclosure level(0x%04x), connector name(%s)\n",
6670 pcie_device
->enclosure_level
,
6671 pcie_device
->connector_name
));
6673 if (pcie_device
->starget
&& pcie_device
->starget
->hostdata
) {
6674 sas_target_priv_data
= pcie_device
->starget
->hostdata
;
6675 sas_target_priv_data
->deleted
= 1;
6676 _scsih_ublock_io_device(ioc
, pcie_device
->wwid
);
6677 sas_target_priv_data
->handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
6680 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
6681 pcie_device
->handle
, (u64
)pcie_device
->wwid
);
6682 if (pcie_device
->enclosure_handle
!= 0)
6683 ioc_info(ioc
, "removing : enclosure logical id(0x%016llx), slot(%d)\n",
6684 (u64
)pcie_device
->enclosure_logical_id
,
6686 if (pcie_device
->connector_name
[0] != '\0')
6687 ioc_info(ioc
, "removing: enclosure level(0x%04x), connector name( %s)\n",
6688 pcie_device
->enclosure_level
,
6689 pcie_device
->connector_name
);
6691 if (pcie_device
->starget
&& (pcie_device
->access_status
!=
6692 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
))
6693 scsi_remove_target(&pcie_device
->starget
->dev
);
6695 ioc_info(ioc
, "%s: exit: handle(0x%04x), wwid(0x%016llx)\n",
6697 pcie_device
->handle
, (u64
)pcie_device
->wwid
));
6698 if (pcie_device
->enclosure_handle
!= 0)
6700 ioc_info(ioc
, "%s: exit: enclosure logical id(0x%016llx), slot(%d)\n",
6702 (u64
)pcie_device
->enclosure_logical_id
,
6703 pcie_device
->slot
));
6704 if (pcie_device
->connector_name
[0] != '\0')
6706 ioc_info(ioc
, "%s: exit: enclosure level(0x%04x), connector name( %s)\n",
6708 pcie_device
->enclosure_level
,
6709 pcie_device
->connector_name
));
6711 kfree(pcie_device
->serial_number
);
6716 * _scsih_pcie_check_device - checking device responsiveness
6717 * @ioc: per adapter object
6718 * @handle: attached device handle
6721 _scsih_pcie_check_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6723 Mpi2ConfigReply_t mpi_reply
;
6724 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6726 struct _pcie_device
*pcie_device
;
6728 unsigned long flags
;
6729 struct scsi_target
*starget
;
6730 struct MPT3SAS_TARGET
*sas_target_priv_data
;
6733 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6734 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
)))
6737 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
6738 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
6741 /* check if this is end device */
6742 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6743 if (!(_scsih_is_nvme_pciescsi_device(device_info
)))
6746 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6747 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
6748 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6751 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6755 if (unlikely(pcie_device
->handle
!= handle
)) {
6756 starget
= pcie_device
->starget
;
6757 sas_target_priv_data
= starget
->hostdata
;
6758 pcie_device
->access_status
= pcie_device_pg0
.AccessStatus
;
6759 starget_printk(KERN_INFO
, starget
,
6760 "handle changed from(0x%04x) to (0x%04x)!!!\n",
6761 pcie_device
->handle
, handle
);
6762 sas_target_priv_data
->handle
= handle
;
6763 pcie_device
->handle
= handle
;
6765 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6766 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6767 pcie_device
->enclosure_level
=
6768 pcie_device_pg0
.EnclosureLevel
;
6769 memcpy(&pcie_device
->connector_name
[0],
6770 &pcie_device_pg0
.ConnectorName
[0], 4);
6772 pcie_device
->enclosure_level
= 0;
6773 pcie_device
->connector_name
[0] = '\0';
6777 /* check if device is present */
6778 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6779 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6780 ioc_info(ioc
, "device is not present handle(0x%04x), flags!!!\n",
6782 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6783 pcie_device_put(pcie_device
);
6787 /* check if there were any issues with discovery */
6788 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6789 pcie_device_pg0
.AccessStatus
)) {
6790 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6791 pcie_device_put(pcie_device
);
6795 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
6796 pcie_device_put(pcie_device
);
6798 _scsih_ublock_io_device(ioc
, wwid
);
6804 * _scsih_pcie_add_device - creating pcie device object
6805 * @ioc: per adapter object
6806 * @handle: pcie device handle
6808 * Creating end device object, stored in ioc->pcie_device_list.
6810 * Return: 1 means queue the event later, 0 means complete the event
6813 _scsih_pcie_add_device(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
6815 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
6816 Mpi26PCIeDevicePage2_t pcie_device_pg2
;
6817 Mpi2ConfigReply_t mpi_reply
;
6818 struct _pcie_device
*pcie_device
;
6819 struct _enclosure_node
*enclosure_dev
;
6823 if ((mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
6824 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
6825 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6826 __FILE__
, __LINE__
, __func__
);
6829 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6830 MPI2_IOCSTATUS_MASK
;
6831 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6832 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6833 __FILE__
, __LINE__
, __func__
);
6837 set_bit(handle
, ioc
->pend_os_device_add
);
6838 wwid
= le64_to_cpu(pcie_device_pg0
.WWID
);
6840 /* check if device is present */
6841 if (!(le32_to_cpu(pcie_device_pg0
.Flags
) &
6842 MPI26_PCIEDEV0_FLAGS_DEVICE_PRESENT
)) {
6843 ioc_err(ioc
, "device is not present handle(0x04%x)!!!\n",
6848 /* check if there were any issues with discovery */
6849 if (_scsih_check_pcie_access_status(ioc
, wwid
, handle
,
6850 pcie_device_pg0
.AccessStatus
))
6853 if (!(_scsih_is_nvme_pciescsi_device(le32_to_cpu
6854 (pcie_device_pg0
.DeviceInfo
))))
6857 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
6859 clear_bit(handle
, ioc
->pend_os_device_add
);
6860 pcie_device_put(pcie_device
);
6864 /* PCIe Device Page 2 contains read-only information about a
6865 * specific NVMe device; therefore, this page is only
6866 * valid for NVMe devices and skip for pcie devices of type scsi.
6868 if (!(mpt3sas_scsih_is_pcie_scsi_device(
6869 le32_to_cpu(pcie_device_pg0
.DeviceInfo
)))) {
6870 if (mpt3sas_config_get_pcie_device_pg2(ioc
, &mpi_reply
,
6871 &pcie_device_pg2
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
6874 "failure at %s:%d/%s()!\n", __FILE__
,
6875 __LINE__
, __func__
);
6879 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
6880 MPI2_IOCSTATUS_MASK
;
6881 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
6883 "failure at %s:%d/%s()!\n", __FILE__
,
6884 __LINE__
, __func__
);
6889 pcie_device
= kzalloc(sizeof(struct _pcie_device
), GFP_KERNEL
);
6891 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
6892 __FILE__
, __LINE__
, __func__
);
6896 kref_init(&pcie_device
->refcount
);
6897 pcie_device
->id
= ioc
->pcie_target_id
++;
6898 pcie_device
->channel
= PCIE_CHANNEL
;
6899 pcie_device
->handle
= handle
;
6900 pcie_device
->access_status
= pcie_device_pg0
.AccessStatus
;
6901 pcie_device
->device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
6902 pcie_device
->wwid
= wwid
;
6903 pcie_device
->port_num
= pcie_device_pg0
.PortNum
;
6904 pcie_device
->fast_path
= (le32_to_cpu(pcie_device_pg0
.Flags
) &
6905 MPI26_PCIEDEV0_FLAGS_FAST_PATH_CAPABLE
) ? 1 : 0;
6907 pcie_device
->enclosure_handle
=
6908 le16_to_cpu(pcie_device_pg0
.EnclosureHandle
);
6909 if (pcie_device
->enclosure_handle
!= 0)
6910 pcie_device
->slot
= le16_to_cpu(pcie_device_pg0
.Slot
);
6912 if (le32_to_cpu(pcie_device_pg0
.Flags
) &
6913 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) {
6914 pcie_device
->enclosure_level
= pcie_device_pg0
.EnclosureLevel
;
6915 memcpy(&pcie_device
->connector_name
[0],
6916 &pcie_device_pg0
.ConnectorName
[0], 4);
6918 pcie_device
->enclosure_level
= 0;
6919 pcie_device
->connector_name
[0] = '\0';
6922 /* get enclosure_logical_id */
6923 if (pcie_device
->enclosure_handle
) {
6925 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
6926 pcie_device
->enclosure_handle
);
6928 pcie_device
->enclosure_logical_id
=
6929 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
6931 /* TODO -- Add device name once FW supports it */
6932 if (!(mpt3sas_scsih_is_pcie_scsi_device(
6933 le32_to_cpu(pcie_device_pg0
.DeviceInfo
)))) {
6934 pcie_device
->nvme_mdts
=
6935 le32_to_cpu(pcie_device_pg2
.MaximumDataTransferSize
);
6936 if (pcie_device_pg2
.ControllerResetTO
)
6937 pcie_device
->reset_timeout
=
6938 pcie_device_pg2
.ControllerResetTO
;
6940 pcie_device
->reset_timeout
= 30;
6942 pcie_device
->reset_timeout
= 30;
6944 if (ioc
->wait_for_discovery_to_complete
)
6945 _scsih_pcie_device_init_add(ioc
, pcie_device
);
6947 _scsih_pcie_device_add(ioc
, pcie_device
);
6949 pcie_device_put(pcie_device
);
6954 * _scsih_pcie_topology_change_event_debug - debug for topology
6956 * @ioc: per adapter object
6957 * @event_data: event data payload
6961 _scsih_pcie_topology_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
6962 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
)
6968 char *status_str
= NULL
;
6969 u8 link_rate
, prev_link_rate
;
6971 switch (event_data
->SwitchStatus
) {
6972 case MPI26_EVENT_PCIE_TOPO_SS_ADDED
:
6975 case MPI26_EVENT_PCIE_TOPO_SS_NOT_RESPONDING
:
6976 status_str
= "remove";
6978 case MPI26_EVENT_PCIE_TOPO_SS_RESPONDING
:
6980 status_str
= "responding";
6982 case MPI26_EVENT_PCIE_TOPO_SS_DELAY_NOT_RESPONDING
:
6983 status_str
= "remove delay";
6986 status_str
= "unknown status";
6989 ioc_info(ioc
, "pcie topology change: (%s)\n", status_str
);
6990 pr_info("\tswitch_handle(0x%04x), enclosure_handle(0x%04x)"
6991 "start_port(%02d), count(%d)\n",
6992 le16_to_cpu(event_data
->SwitchDevHandle
),
6993 le16_to_cpu(event_data
->EnclosureHandle
),
6994 event_data
->StartPortNum
, event_data
->NumEntries
);
6995 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
6997 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7000 port_number
= event_data
->StartPortNum
+ i
;
7001 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7002 switch (reason_code
) {
7003 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7004 status_str
= "target add";
7006 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7007 status_str
= "target remove";
7009 case MPI26_EVENT_PCIE_TOPO_PS_DELAY_NOT_RESPONDING
:
7010 status_str
= "delay target remove";
7012 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7013 status_str
= "link rate change";
7015 case MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
:
7016 status_str
= "target responding";
7019 status_str
= "unknown";
7022 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
&
7023 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7024 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
&
7025 MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7026 pr_info("\tport(%02d), attached_handle(0x%04x): %s:"
7027 " link rate: new(0x%02x), old(0x%02x)\n", port_number
,
7028 handle
, status_str
, link_rate
, prev_link_rate
);
7033 * _scsih_pcie_topology_change_event - handle PCIe topology
7035 * @ioc: per adapter object
7036 * @fw_event: The fw_event_work object
7041 _scsih_pcie_topology_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7042 struct fw_event_work
*fw_event
)
7047 u8 link_rate
, prev_link_rate
;
7048 unsigned long flags
;
7050 Mpi26EventDataPCIeTopologyChangeList_t
*event_data
=
7051 (Mpi26EventDataPCIeTopologyChangeList_t
*) fw_event
->event_data
;
7052 struct _pcie_device
*pcie_device
;
7054 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7055 _scsih_pcie_topology_change_event_debug(ioc
, event_data
);
7057 if (ioc
->shost_recovery
|| ioc
->remove_host
||
7058 ioc
->pci_error_recovery
)
7061 if (fw_event
->ignore
) {
7062 dewtprintk(ioc
, ioc_info(ioc
, "ignoring switch event\n"));
7066 /* handle siblings events */
7067 for (i
= 0; i
< event_data
->NumEntries
; i
++) {
7068 if (fw_event
->ignore
) {
7070 ioc_info(ioc
, "ignoring switch event\n"));
7073 if (ioc
->remove_host
|| ioc
->pci_error_recovery
)
7075 reason_code
= event_data
->PortEntry
[i
].PortStatus
;
7077 le16_to_cpu(event_data
->PortEntry
[i
].AttachedDevHandle
);
7081 link_rate
= event_data
->PortEntry
[i
].CurrentPortInfo
7082 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7083 prev_link_rate
= event_data
->PortEntry
[i
].PreviousPortInfo
7084 & MPI26_EVENT_PCIE_TOPO_PI_RATE_MASK
;
7086 switch (reason_code
) {
7087 case MPI26_EVENT_PCIE_TOPO_PS_PORT_CHANGED
:
7088 if (ioc
->shost_recovery
)
7090 if (link_rate
== prev_link_rate
)
7092 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7095 _scsih_pcie_check_device(ioc
, handle
);
7097 /* This code after this point handles the test case
7098 * where a device has been added, however its returning
7099 * BUSY for sometime. Then before the Device Missing
7100 * Delay expires and the device becomes READY, the
7101 * device is removed and added back.
7103 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7104 pcie_device
= __mpt3sas_get_pdev_by_handle(ioc
, handle
);
7105 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7108 pcie_device_put(pcie_device
);
7112 if (!test_bit(handle
, ioc
->pend_os_device_add
))
7116 ioc_info(ioc
, "handle(0x%04x) device not found: convert event to a device add\n",
7118 event_data
->PortEntry
[i
].PortStatus
&= 0xF0;
7119 event_data
->PortEntry
[i
].PortStatus
|=
7120 MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
;
7122 case MPI26_EVENT_PCIE_TOPO_PS_DEV_ADDED
:
7123 if (ioc
->shost_recovery
)
7125 if (link_rate
< MPI26_EVENT_PCIE_TOPO_PI_RATE_2_5
)
7128 rc
= _scsih_pcie_add_device(ioc
, handle
);
7130 /* mark entry vacant */
7131 /* TODO This needs to be reviewed and fixed,
7132 * we dont have an entry
7133 * to make an event void like vacant
7135 event_data
->PortEntry
[i
].PortStatus
|=
7136 MPI26_EVENT_PCIE_TOPO_PS_NO_CHANGE
;
7139 case MPI26_EVENT_PCIE_TOPO_PS_NOT_RESPONDING
:
7140 _scsih_pcie_device_remove_by_handle(ioc
, handle
);
7147 * _scsih_pcie_device_status_change_event_debug - debug for device event
7149 * @event_data: event data payload
7153 _scsih_pcie_device_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7154 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
)
7156 char *reason_str
= NULL
;
7158 switch (event_data
->ReasonCode
) {
7159 case MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
:
7160 reason_str
= "smart data";
7162 case MPI26_EVENT_PCIDEV_STAT_RC_UNSUPPORTED
:
7163 reason_str
= "unsupported device discovered";
7165 case MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7166 reason_str
= "internal device reset";
7168 case MPI26_EVENT_PCIDEV_STAT_RC_TASK_ABORT_INTERNAL
:
7169 reason_str
= "internal task abort";
7171 case MPI26_EVENT_PCIDEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7172 reason_str
= "internal task abort set";
7174 case MPI26_EVENT_PCIDEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7175 reason_str
= "internal clear task set";
7177 case MPI26_EVENT_PCIDEV_STAT_RC_QUERY_TASK_INTERNAL
:
7178 reason_str
= "internal query task";
7180 case MPI26_EVENT_PCIDEV_STAT_RC_DEV_INIT_FAILURE
:
7181 reason_str
= "device init failure";
7183 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
:
7184 reason_str
= "internal device reset complete";
7186 case MPI26_EVENT_PCIDEV_STAT_RC_CMP_TASK_ABORT_INTERNAL
:
7187 reason_str
= "internal task abort complete";
7189 case MPI26_EVENT_PCIDEV_STAT_RC_ASYNC_NOTIFICATION
:
7190 reason_str
= "internal async notification";
7192 case MPI26_EVENT_PCIDEV_STAT_RC_PCIE_HOT_RESET_FAILED
:
7193 reason_str
= "pcie hot reset failed";
7196 reason_str
= "unknown reason";
7200 ioc_info(ioc
, "PCIE device status change: (%s)\n"
7201 "\thandle(0x%04x), WWID(0x%016llx), tag(%d)",
7202 reason_str
, le16_to_cpu(event_data
->DevHandle
),
7203 (u64
)le64_to_cpu(event_data
->WWID
),
7204 le16_to_cpu(event_data
->TaskTag
));
7205 if (event_data
->ReasonCode
== MPI26_EVENT_PCIDEV_STAT_RC_SMART_DATA
)
7206 pr_cont(", ASC(0x%x), ASCQ(0x%x)\n",
7207 event_data
->ASC
, event_data
->ASCQ
);
7212 * _scsih_pcie_device_status_change_event - handle device status
7214 * @ioc: per adapter object
7215 * @fw_event: The fw_event_work object
7219 _scsih_pcie_device_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7220 struct fw_event_work
*fw_event
)
7222 struct MPT3SAS_TARGET
*target_priv_data
;
7223 struct _pcie_device
*pcie_device
;
7225 unsigned long flags
;
7226 Mpi26EventDataPCIeDeviceStatusChange_t
*event_data
=
7227 (Mpi26EventDataPCIeDeviceStatusChange_t
*)fw_event
->event_data
;
7228 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7229 _scsih_pcie_device_status_change_event_debug(ioc
,
7232 if (event_data
->ReasonCode
!=
7233 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
&&
7234 event_data
->ReasonCode
!=
7235 MPI26_EVENT_PCIDEV_STAT_RC_CMP_INTERNAL_DEV_RESET
)
7238 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
7239 wwid
= le64_to_cpu(event_data
->WWID
);
7240 pcie_device
= __mpt3sas_get_pdev_by_wwid(ioc
, wwid
);
7242 if (!pcie_device
|| !pcie_device
->starget
)
7245 target_priv_data
= pcie_device
->starget
->hostdata
;
7246 if (!target_priv_data
)
7249 if (event_data
->ReasonCode
==
7250 MPI26_EVENT_PCIDEV_STAT_RC_INTERNAL_DEVICE_RESET
)
7251 target_priv_data
->tm_busy
= 1;
7253 target_priv_data
->tm_busy
= 0;
7256 pcie_device_put(pcie_device
);
7258 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
7262 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure
7264 * @ioc: per adapter object
7265 * @event_data: event data payload
7269 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7270 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
)
7272 char *reason_str
= NULL
;
7274 switch (event_data
->ReasonCode
) {
7275 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7276 reason_str
= "enclosure add";
7278 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7279 reason_str
= "enclosure remove";
7282 reason_str
= "unknown reason";
7286 ioc_info(ioc
, "enclosure status change: (%s)\n"
7287 "\thandle(0x%04x), enclosure logical id(0x%016llx) number slots(%d)\n",
7289 le16_to_cpu(event_data
->EnclosureHandle
),
7290 (u64
)le64_to_cpu(event_data
->EnclosureLogicalID
),
7291 le16_to_cpu(event_data
->StartSlot
));
7295 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
7296 * @ioc: per adapter object
7297 * @fw_event: The fw_event_work object
7301 _scsih_sas_enclosure_dev_status_change_event(struct MPT3SAS_ADAPTER
*ioc
,
7302 struct fw_event_work
*fw_event
)
7304 Mpi2ConfigReply_t mpi_reply
;
7305 struct _enclosure_node
*enclosure_dev
= NULL
;
7306 Mpi2EventDataSasEnclDevStatusChange_t
*event_data
=
7307 (Mpi2EventDataSasEnclDevStatusChange_t
*)fw_event
->event_data
;
7309 u16 enclosure_handle
= le16_to_cpu(event_data
->EnclosureHandle
);
7311 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
7312 _scsih_sas_enclosure_dev_status_change_event_debug(ioc
,
7313 (Mpi2EventDataSasEnclDevStatusChange_t
*)
7314 fw_event
->event_data
);
7315 if (ioc
->shost_recovery
)
7318 if (enclosure_handle
)
7320 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
7322 switch (event_data
->ReasonCode
) {
7323 case MPI2_EVENT_SAS_ENCL_RC_ADDED
:
7324 if (!enclosure_dev
) {
7326 kzalloc(sizeof(struct _enclosure_node
),
7328 if (!enclosure_dev
) {
7329 ioc_info(ioc
, "failure at %s:%d/%s()!\n",
7330 __FILE__
, __LINE__
, __func__
);
7333 rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
7334 &enclosure_dev
->pg0
,
7335 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE
,
7338 if (rc
|| (le16_to_cpu(mpi_reply
.IOCStatus
) &
7339 MPI2_IOCSTATUS_MASK
)) {
7340 kfree(enclosure_dev
);
7344 list_add_tail(&enclosure_dev
->list
,
7345 &ioc
->enclosure_list
);
7348 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING
:
7349 if (enclosure_dev
) {
7350 list_del(&enclosure_dev
->list
);
7351 kfree(enclosure_dev
);
7360 * _scsih_sas_broadcast_primitive_event - handle broadcast events
7361 * @ioc: per adapter object
7362 * @fw_event: The fw_event_work object
7366 _scsih_sas_broadcast_primitive_event(struct MPT3SAS_ADAPTER
*ioc
,
7367 struct fw_event_work
*fw_event
)
7369 struct scsi_cmnd
*scmd
;
7370 struct scsi_device
*sdev
;
7371 struct scsiio_tracker
*st
;
7374 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
7375 u32 termination_count
;
7377 Mpi2SCSITaskManagementReply_t
*mpi_reply
;
7378 Mpi2EventDataSasBroadcastPrimitive_t
*event_data
=
7379 (Mpi2EventDataSasBroadcastPrimitive_t
*)
7380 fw_event
->event_data
;
7382 unsigned long flags
;
7385 u8 task_abort_retries
;
7387 mutex_lock(&ioc
->tm_cmds
.mutex
);
7388 ioc_info(ioc
, "%s: enter: phy number(%d), width(%d)\n",
7389 __func__
, event_data
->PhyNum
, event_data
->PortWidth
);
7391 _scsih_block_io_all_device(ioc
);
7393 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7394 mpi_reply
= ioc
->tm_cmds
.reply
;
7395 broadcast_aen_retry
:
7397 /* sanity checks for retrying this loop */
7398 if (max_retries
++ == 5) {
7399 dewtprintk(ioc
, ioc_info(ioc
, "%s: giving up\n", __func__
));
7401 } else if (max_retries
> 1)
7403 ioc_info(ioc
, "%s: %d retry\n",
7404 __func__
, max_retries
- 1));
7406 termination_count
= 0;
7408 for (smid
= 1; smid
<= ioc
->scsiio_depth
; smid
++) {
7409 if (ioc
->shost_recovery
)
7411 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
7414 st
= scsi_cmd_priv(scmd
);
7415 sdev
= scmd
->device
;
7416 sas_device_priv_data
= sdev
->hostdata
;
7417 if (!sas_device_priv_data
|| !sas_device_priv_data
->sas_target
)
7419 /* skip hidden raid components */
7420 if (sas_device_priv_data
->sas_target
->flags
&
7421 MPT_TARGET_FLAGS_RAID_COMPONENT
)
7424 if (sas_device_priv_data
->sas_target
->flags
&
7425 MPT_TARGET_FLAGS_VOLUME
)
7427 /* skip PCIe devices */
7428 if (sas_device_priv_data
->sas_target
->flags
&
7429 MPT_TARGET_FLAGS_PCIE_DEVICE
)
7432 handle
= sas_device_priv_data
->sas_target
->handle
;
7433 lun
= sas_device_priv_data
->lun
;
7436 if (ioc
->shost_recovery
)
7439 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7440 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, lun
,
7441 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
, st
->smid
,
7442 st
->msix_io
, 30, 0);
7444 sdev_printk(KERN_WARNING
, sdev
,
7445 "mpt3sas_scsih_issue_tm: FAILED when sending "
7446 "QUERY_TASK: scmd(%p)\n", scmd
);
7447 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7448 goto broadcast_aen_retry
;
7450 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
)
7451 & MPI2_IOCSTATUS_MASK
;
7452 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7453 sdev_printk(KERN_WARNING
, sdev
,
7454 "query task: FAILED with IOCSTATUS(0x%04x), scmd(%p)\n",
7456 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7457 goto broadcast_aen_retry
;
7460 /* see if IO is still owned by IOC and target */
7461 if (mpi_reply
->ResponseCode
==
7462 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
||
7463 mpi_reply
->ResponseCode
==
7464 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
) {
7465 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7468 task_abort_retries
= 0;
7470 if (task_abort_retries
++ == 60) {
7472 ioc_info(ioc
, "%s: ABORT_TASK: giving up\n",
7474 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7475 goto broadcast_aen_retry
;
7478 if (ioc
->shost_recovery
)
7481 r
= mpt3sas_scsih_issue_tm(ioc
, handle
, sdev
->lun
,
7482 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
, st
->smid
,
7483 st
->msix_io
, 30, 0);
7484 if (r
== FAILED
|| st
->cb_idx
!= 0xFF) {
7485 sdev_printk(KERN_WARNING
, sdev
,
7486 "mpt3sas_scsih_issue_tm: ABORT_TASK: FAILED : "
7487 "scmd(%p)\n", scmd
);
7491 if (task_abort_retries
> 1)
7492 sdev_printk(KERN_WARNING
, sdev
,
7493 "mpt3sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
7495 task_abort_retries
- 1, scmd
);
7497 termination_count
+= le32_to_cpu(mpi_reply
->TerminationCount
);
7498 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
7501 if (ioc
->broadcast_aen_pending
) {
7504 "%s: loop back due to pending AEN\n",
7506 ioc
->broadcast_aen_pending
= 0;
7507 goto broadcast_aen_retry
;
7511 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
7515 ioc_info(ioc
, "%s - exit, query_count = %d termination_count = %d\n",
7516 __func__
, query_count
, termination_count
));
7518 ioc
->broadcast_aen_busy
= 0;
7519 if (!ioc
->shost_recovery
)
7520 _scsih_ublock_io_all_device(ioc
);
7521 mutex_unlock(&ioc
->tm_cmds
.mutex
);
7525 * _scsih_sas_discovery_event - handle discovery events
7526 * @ioc: per adapter object
7527 * @fw_event: The fw_event_work object
7531 _scsih_sas_discovery_event(struct MPT3SAS_ADAPTER
*ioc
,
7532 struct fw_event_work
*fw_event
)
7534 Mpi2EventDataSasDiscovery_t
*event_data
=
7535 (Mpi2EventDataSasDiscovery_t
*) fw_event
->event_data
;
7537 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) {
7538 ioc_info(ioc
, "discovery event: (%s)",
7539 event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
?
7541 if (event_data
->DiscoveryStatus
)
7542 pr_cont("discovery_status(0x%08x)",
7543 le32_to_cpu(event_data
->DiscoveryStatus
));
7547 if (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
&&
7548 !ioc
->sas_hba
.num_phys
) {
7549 if (disable_discovery
> 0 && ioc
->shost_recovery
) {
7550 /* Wait for the reset to complete */
7551 while (ioc
->shost_recovery
)
7554 _scsih_sas_host_add(ioc
);
7559 * _scsih_sas_device_discovery_error_event - display SAS device discovery error
7561 * @ioc: per adapter object
7562 * @fw_event: The fw_event_work object
7566 _scsih_sas_device_discovery_error_event(struct MPT3SAS_ADAPTER
*ioc
,
7567 struct fw_event_work
*fw_event
)
7569 Mpi25EventDataSasDeviceDiscoveryError_t
*event_data
=
7570 (Mpi25EventDataSasDeviceDiscoveryError_t
*)fw_event
->event_data
;
7572 switch (event_data
->ReasonCode
) {
7573 case MPI25_EVENT_SAS_DISC_ERR_SMP_FAILED
:
7574 ioc_warn(ioc
, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has failed\n",
7575 le16_to_cpu(event_data
->DevHandle
),
7576 (u64
)le64_to_cpu(event_data
->SASAddress
),
7577 event_data
->PhysicalPort
);
7579 case MPI25_EVENT_SAS_DISC_ERR_SMP_TIMEOUT
:
7580 ioc_warn(ioc
, "SMP command sent to the expander (handle:0x%04x, sas_address:0x%016llx, physical_port:0x%02x) has timed out\n",
7581 le16_to_cpu(event_data
->DevHandle
),
7582 (u64
)le64_to_cpu(event_data
->SASAddress
),
7583 event_data
->PhysicalPort
);
7591 * _scsih_pcie_enumeration_event - handle enumeration events
7592 * @ioc: per adapter object
7593 * @fw_event: The fw_event_work object
7597 _scsih_pcie_enumeration_event(struct MPT3SAS_ADAPTER
*ioc
,
7598 struct fw_event_work
*fw_event
)
7600 Mpi26EventDataPCIeEnumeration_t
*event_data
=
7601 (Mpi26EventDataPCIeEnumeration_t
*)fw_event
->event_data
;
7603 if (!(ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
))
7606 ioc_info(ioc
, "pcie enumeration event: (%s) Flag 0x%02x",
7607 (event_data
->ReasonCode
== MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
7608 "started" : "completed",
7610 if (event_data
->EnumerationStatus
)
7611 pr_cont("enumeration_status(0x%08x)",
7612 le32_to_cpu(event_data
->EnumerationStatus
));
7617 * _scsih_ir_fastpath - turn on fastpath for IR physdisk
7618 * @ioc: per adapter object
7619 * @handle: device handle for physical disk
7620 * @phys_disk_num: physical disk number
7622 * Return: 0 for success, else failure.
7625 _scsih_ir_fastpath(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
, u8 phys_disk_num
)
7627 Mpi2RaidActionRequest_t
*mpi_request
;
7628 Mpi2RaidActionReply_t
*mpi_reply
;
7635 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
7638 mutex_lock(&ioc
->scsih_cmds
.mutex
);
7640 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
7641 ioc_err(ioc
, "%s: scsih_cmd in use\n", __func__
);
7645 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
7647 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
7649 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
7650 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7655 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
7656 ioc
->scsih_cmds
.smid
= smid
;
7657 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
7659 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
7660 mpi_request
->Action
= MPI2_RAID_ACTION_PHYSDISK_HIDDEN
;
7661 mpi_request
->PhysDiskNum
= phys_disk_num
;
7664 ioc_info(ioc
, "IR RAID_ACTION: turning fast path on for handle(0x%04x), phys_disk_num (0x%02x)\n",
7665 handle
, phys_disk_num
));
7667 init_completion(&ioc
->scsih_cmds
.done
);
7668 ioc
->put_smid_default(ioc
, smid
);
7669 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
7671 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
7673 mpt3sas_base_check_cmd_timeout(ioc
,
7674 ioc
->scsih_cmds
.status
, mpi_request
,
7675 sizeof(Mpi2RaidActionRequest_t
)/4);
7680 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
7682 mpi_reply
= ioc
->scsih_cmds
.reply
;
7683 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
7684 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
7685 log_info
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
7688 ioc_status
&= MPI2_IOCSTATUS_MASK
;
7689 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7691 ioc_info(ioc
, "IR RAID_ACTION: failed: ioc_status(0x%04x), loginfo(0x%08x)!!!\n",
7692 ioc_status
, log_info
));
7696 ioc_info(ioc
, "IR RAID_ACTION: completed successfully\n"));
7700 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
7701 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
7704 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
7709 * _scsih_reprobe_lun - reprobing lun
7710 * @sdev: scsi device struct
7711 * @no_uld_attach: sdev->no_uld_attach flag setting
7715 _scsih_reprobe_lun(struct scsi_device
*sdev
, void *no_uld_attach
)
7717 sdev
->no_uld_attach
= no_uld_attach
? 1 : 0;
7718 sdev_printk(KERN_INFO
, sdev
, "%s raid component\n",
7719 sdev
->no_uld_attach
? "hiding" : "exposing");
7720 WARN_ON(scsi_device_reprobe(sdev
));
7724 * _scsih_sas_volume_add - add new volume
7725 * @ioc: per adapter object
7726 * @element: IR config element data
7730 _scsih_sas_volume_add(struct MPT3SAS_ADAPTER
*ioc
,
7731 Mpi2EventIrConfigElement_t
*element
)
7733 struct _raid_device
*raid_device
;
7734 unsigned long flags
;
7736 u16 handle
= le16_to_cpu(element
->VolDevHandle
);
7739 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
7741 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7742 __FILE__
, __LINE__
, __func__
);
7746 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7747 raid_device
= _scsih_raid_device_find_by_wwid(ioc
, wwid
);
7748 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7753 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
7755 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7756 __FILE__
, __LINE__
, __func__
);
7760 raid_device
->id
= ioc
->sas_id
++;
7761 raid_device
->channel
= RAID_CHANNEL
;
7762 raid_device
->handle
= handle
;
7763 raid_device
->wwid
= wwid
;
7764 _scsih_raid_device_add(ioc
, raid_device
);
7765 if (!ioc
->wait_for_discovery_to_complete
) {
7766 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
7767 raid_device
->id
, 0);
7769 _scsih_raid_device_remove(ioc
, raid_device
);
7771 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7772 _scsih_determine_boot_device(ioc
, raid_device
, 1);
7773 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7778 * _scsih_sas_volume_delete - delete volume
7779 * @ioc: per adapter object
7780 * @handle: volume device handle
7784 _scsih_sas_volume_delete(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
7786 struct _raid_device
*raid_device
;
7787 unsigned long flags
;
7788 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7789 struct scsi_target
*starget
= NULL
;
7791 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
7792 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
7794 if (raid_device
->starget
) {
7795 starget
= raid_device
->starget
;
7796 sas_target_priv_data
= starget
->hostdata
;
7797 sas_target_priv_data
->deleted
= 1;
7799 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
7800 raid_device
->handle
, (u64
)raid_device
->wwid
);
7801 list_del(&raid_device
->list
);
7804 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
7806 scsi_remove_target(&starget
->dev
);
7810 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
7811 * @ioc: per adapter object
7812 * @element: IR config element data
7816 _scsih_sas_pd_expose(struct MPT3SAS_ADAPTER
*ioc
,
7817 Mpi2EventIrConfigElement_t
*element
)
7819 struct _sas_device
*sas_device
;
7820 struct scsi_target
*starget
= NULL
;
7821 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7822 unsigned long flags
;
7823 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7825 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7826 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7828 sas_device
->volume_handle
= 0;
7829 sas_device
->volume_wwid
= 0;
7830 clear_bit(handle
, ioc
->pd_handles
);
7831 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7832 starget
= sas_device
->starget
;
7833 sas_target_priv_data
= starget
->hostdata
;
7834 sas_target_priv_data
->flags
&=
7835 ~MPT_TARGET_FLAGS_RAID_COMPONENT
;
7838 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7842 /* exposing raid component */
7844 starget_for_each_device(starget
, NULL
, _scsih_reprobe_lun
);
7846 sas_device_put(sas_device
);
7850 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
7851 * @ioc: per adapter object
7852 * @element: IR config element data
7856 _scsih_sas_pd_hide(struct MPT3SAS_ADAPTER
*ioc
,
7857 Mpi2EventIrConfigElement_t
*element
)
7859 struct _sas_device
*sas_device
;
7860 struct scsi_target
*starget
= NULL
;
7861 struct MPT3SAS_TARGET
*sas_target_priv_data
;
7862 unsigned long flags
;
7863 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7864 u16 volume_handle
= 0;
7865 u64 volume_wwid
= 0;
7867 mpt3sas_config_get_volume_handle(ioc
, handle
, &volume_handle
);
7869 mpt3sas_config_get_volume_wwid(ioc
, volume_handle
,
7872 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
7873 sas_device
= __mpt3sas_get_sdev_by_handle(ioc
, handle
);
7875 set_bit(handle
, ioc
->pd_handles
);
7876 if (sas_device
->starget
&& sas_device
->starget
->hostdata
) {
7877 starget
= sas_device
->starget
;
7878 sas_target_priv_data
= starget
->hostdata
;
7879 sas_target_priv_data
->flags
|=
7880 MPT_TARGET_FLAGS_RAID_COMPONENT
;
7881 sas_device
->volume_handle
= volume_handle
;
7882 sas_device
->volume_wwid
= volume_wwid
;
7885 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
7889 /* hiding raid component */
7890 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7893 starget_for_each_device(starget
, (void *)1, _scsih_reprobe_lun
);
7895 sas_device_put(sas_device
);
7899 * _scsih_sas_pd_delete - delete pd component
7900 * @ioc: per adapter object
7901 * @element: IR config element data
7905 _scsih_sas_pd_delete(struct MPT3SAS_ADAPTER
*ioc
,
7906 Mpi2EventIrConfigElement_t
*element
)
7908 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7910 _scsih_device_remove_by_handle(ioc
, handle
);
7914 * _scsih_sas_pd_add - remove pd component
7915 * @ioc: per adapter object
7916 * @element: IR config element data
7920 _scsih_sas_pd_add(struct MPT3SAS_ADAPTER
*ioc
,
7921 Mpi2EventIrConfigElement_t
*element
)
7923 struct _sas_device
*sas_device
;
7924 u16 handle
= le16_to_cpu(element
->PhysDiskDevHandle
);
7925 Mpi2ConfigReply_t mpi_reply
;
7926 Mpi2SasDevicePage0_t sas_device_pg0
;
7931 set_bit(handle
, ioc
->pd_handles
);
7933 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
7935 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7936 sas_device_put(sas_device
);
7940 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
, &sas_device_pg0
,
7941 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
, handle
))) {
7942 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7943 __FILE__
, __LINE__
, __func__
);
7947 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
7948 MPI2_IOCSTATUS_MASK
;
7949 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
7950 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
7951 __FILE__
, __LINE__
, __func__
);
7955 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
7956 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
7957 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
7958 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
7960 _scsih_ir_fastpath(ioc
, handle
, element
->PhysDiskNum
);
7961 _scsih_add_device(ioc
, handle
, 0, 1);
7965 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
7966 * @ioc: per adapter object
7967 * @event_data: event data payload
7971 _scsih_sas_ir_config_change_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
7972 Mpi2EventDataIrConfigChangeList_t
*event_data
)
7974 Mpi2EventIrConfigElement_t
*element
;
7977 char *reason_str
= NULL
, *element_str
= NULL
;
7979 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
7981 ioc_info(ioc
, "raid config change: (%s), elements(%d)\n",
7982 le32_to_cpu(event_data
->Flags
) & MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
?
7983 "foreign" : "native",
7984 event_data
->NumElements
);
7985 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
7986 switch (element
->ReasonCode
) {
7987 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
7990 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
7991 reason_str
= "remove";
7993 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE
:
7994 reason_str
= "no change";
7996 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
7997 reason_str
= "hide";
7999 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8000 reason_str
= "unhide";
8002 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8003 reason_str
= "volume_created";
8005 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8006 reason_str
= "volume_deleted";
8008 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8009 reason_str
= "pd_created";
8011 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8012 reason_str
= "pd_deleted";
8015 reason_str
= "unknown reason";
8018 element_type
= le16_to_cpu(element
->ElementFlags
) &
8019 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK
;
8020 switch (element_type
) {
8021 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT
:
8022 element_str
= "volume";
8024 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT
:
8025 element_str
= "phys disk";
8027 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT
:
8028 element_str
= "hot spare";
8031 element_str
= "unknown element";
8034 pr_info("\t(%s:%s), vol handle(0x%04x), " \
8035 "pd handle(0x%04x), pd num(0x%02x)\n", element_str
,
8036 reason_str
, le16_to_cpu(element
->VolDevHandle
),
8037 le16_to_cpu(element
->PhysDiskDevHandle
),
8038 element
->PhysDiskNum
);
8043 * _scsih_sas_ir_config_change_event - handle ir configuration change events
8044 * @ioc: per adapter object
8045 * @fw_event: The fw_event_work object
8049 _scsih_sas_ir_config_change_event(struct MPT3SAS_ADAPTER
*ioc
,
8050 struct fw_event_work
*fw_event
)
8052 Mpi2EventIrConfigElement_t
*element
;
8055 Mpi2EventDataIrConfigChangeList_t
*event_data
=
8056 (Mpi2EventDataIrConfigChangeList_t
*)
8057 fw_event
->event_data
;
8059 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8060 (!ioc
->hide_ir_msg
))
8061 _scsih_sas_ir_config_change_event_debug(ioc
, event_data
);
8063 foreign_config
= (le32_to_cpu(event_data
->Flags
) &
8064 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG
) ? 1 : 0;
8066 element
= (Mpi2EventIrConfigElement_t
*)&event_data
->ConfigElement
[0];
8067 if (ioc
->shost_recovery
&&
8068 ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
8069 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8070 if (element
->ReasonCode
== MPI2_EVENT_IR_CHANGE_RC_HIDE
)
8071 _scsih_ir_fastpath(ioc
,
8072 le16_to_cpu(element
->PhysDiskDevHandle
),
8073 element
->PhysDiskNum
);
8078 for (i
= 0; i
< event_data
->NumElements
; i
++, element
++) {
8080 switch (element
->ReasonCode
) {
8081 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED
:
8082 case MPI2_EVENT_IR_CHANGE_RC_ADDED
:
8083 if (!foreign_config
)
8084 _scsih_sas_volume_add(ioc
, element
);
8086 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED
:
8087 case MPI2_EVENT_IR_CHANGE_RC_REMOVED
:
8088 if (!foreign_config
)
8089 _scsih_sas_volume_delete(ioc
,
8090 le16_to_cpu(element
->VolDevHandle
));
8092 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED
:
8093 if (!ioc
->is_warpdrive
)
8094 _scsih_sas_pd_hide(ioc
, element
);
8096 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED
:
8097 if (!ioc
->is_warpdrive
)
8098 _scsih_sas_pd_expose(ioc
, element
);
8100 case MPI2_EVENT_IR_CHANGE_RC_HIDE
:
8101 if (!ioc
->is_warpdrive
)
8102 _scsih_sas_pd_add(ioc
, element
);
8104 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE
:
8105 if (!ioc
->is_warpdrive
)
8106 _scsih_sas_pd_delete(ioc
, element
);
8113 * _scsih_sas_ir_volume_event - IR volume event
8114 * @ioc: per adapter object
8115 * @fw_event: The fw_event_work object
8119 _scsih_sas_ir_volume_event(struct MPT3SAS_ADAPTER
*ioc
,
8120 struct fw_event_work
*fw_event
)
8123 unsigned long flags
;
8124 struct _raid_device
*raid_device
;
8128 Mpi2EventDataIrVolume_t
*event_data
=
8129 (Mpi2EventDataIrVolume_t
*) fw_event
->event_data
;
8131 if (ioc
->shost_recovery
)
8134 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED
)
8137 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8138 state
= le32_to_cpu(event_data
->NewValue
);
8139 if (!ioc
->hide_ir_msg
)
8141 ioc_info(ioc
, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8143 le32_to_cpu(event_data
->PreviousValue
),
8146 case MPI2_RAID_VOL_STATE_MISSING
:
8147 case MPI2_RAID_VOL_STATE_FAILED
:
8148 _scsih_sas_volume_delete(ioc
, handle
);
8151 case MPI2_RAID_VOL_STATE_ONLINE
:
8152 case MPI2_RAID_VOL_STATE_DEGRADED
:
8153 case MPI2_RAID_VOL_STATE_OPTIMAL
:
8155 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8156 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8157 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8162 mpt3sas_config_get_volume_wwid(ioc
, handle
, &wwid
);
8164 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8165 __FILE__
, __LINE__
, __func__
);
8169 raid_device
= kzalloc(sizeof(struct _raid_device
), GFP_KERNEL
);
8171 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8172 __FILE__
, __LINE__
, __func__
);
8176 raid_device
->id
= ioc
->sas_id
++;
8177 raid_device
->channel
= RAID_CHANNEL
;
8178 raid_device
->handle
= handle
;
8179 raid_device
->wwid
= wwid
;
8180 _scsih_raid_device_add(ioc
, raid_device
);
8181 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
8182 raid_device
->id
, 0);
8184 _scsih_raid_device_remove(ioc
, raid_device
);
8187 case MPI2_RAID_VOL_STATE_INITIALIZING
:
8194 * _scsih_sas_ir_physical_disk_event - PD event
8195 * @ioc: per adapter object
8196 * @fw_event: The fw_event_work object
8200 _scsih_sas_ir_physical_disk_event(struct MPT3SAS_ADAPTER
*ioc
,
8201 struct fw_event_work
*fw_event
)
8203 u16 handle
, parent_handle
;
8205 struct _sas_device
*sas_device
;
8206 Mpi2ConfigReply_t mpi_reply
;
8207 Mpi2SasDevicePage0_t sas_device_pg0
;
8209 Mpi2EventDataIrPhysicalDisk_t
*event_data
=
8210 (Mpi2EventDataIrPhysicalDisk_t
*) fw_event
->event_data
;
8213 if (ioc
->shost_recovery
)
8216 if (event_data
->ReasonCode
!= MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED
)
8219 handle
= le16_to_cpu(event_data
->PhysDiskDevHandle
);
8220 state
= le32_to_cpu(event_data
->NewValue
);
8222 if (!ioc
->hide_ir_msg
)
8224 ioc_info(ioc
, "%s: handle(0x%04x), old(0x%08x), new(0x%08x)\n",
8226 le32_to_cpu(event_data
->PreviousValue
),
8230 case MPI2_RAID_PD_STATE_ONLINE
:
8231 case MPI2_RAID_PD_STATE_DEGRADED
:
8232 case MPI2_RAID_PD_STATE_REBUILDING
:
8233 case MPI2_RAID_PD_STATE_OPTIMAL
:
8234 case MPI2_RAID_PD_STATE_HOT_SPARE
:
8236 if (!ioc
->is_warpdrive
)
8237 set_bit(handle
, ioc
->pd_handles
);
8239 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
8241 sas_device_put(sas_device
);
8245 if ((mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8246 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
8248 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8249 __FILE__
, __LINE__
, __func__
);
8253 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8254 MPI2_IOCSTATUS_MASK
;
8255 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8256 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8257 __FILE__
, __LINE__
, __func__
);
8261 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
8262 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
))
8263 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
8264 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
8266 _scsih_add_device(ioc
, handle
, 0, 1);
8270 case MPI2_RAID_PD_STATE_OFFLINE
:
8271 case MPI2_RAID_PD_STATE_NOT_CONFIGURED
:
8272 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE
:
8279 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
8280 * @ioc: per adapter object
8281 * @event_data: event data payload
8285 _scsih_sas_ir_operation_status_event_debug(struct MPT3SAS_ADAPTER
*ioc
,
8286 Mpi2EventDataIrOperationStatus_t
*event_data
)
8288 char *reason_str
= NULL
;
8290 switch (event_data
->RAIDOperation
) {
8291 case MPI2_EVENT_IR_RAIDOP_RESYNC
:
8292 reason_str
= "resync";
8294 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION
:
8295 reason_str
= "online capacity expansion";
8297 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK
:
8298 reason_str
= "consistency check";
8300 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT
:
8301 reason_str
= "background init";
8303 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT
:
8304 reason_str
= "make data consistent";
8311 ioc_info(ioc
, "raid operational status: (%s)\thandle(0x%04x), percent complete(%d)\n",
8313 le16_to_cpu(event_data
->VolDevHandle
),
8314 event_data
->PercentComplete
);
8318 * _scsih_sas_ir_operation_status_event - handle RAID operation events
8319 * @ioc: per adapter object
8320 * @fw_event: The fw_event_work object
8324 _scsih_sas_ir_operation_status_event(struct MPT3SAS_ADAPTER
*ioc
,
8325 struct fw_event_work
*fw_event
)
8327 Mpi2EventDataIrOperationStatus_t
*event_data
=
8328 (Mpi2EventDataIrOperationStatus_t
*)
8329 fw_event
->event_data
;
8330 static struct _raid_device
*raid_device
;
8331 unsigned long flags
;
8334 if ((ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
) &&
8335 (!ioc
->hide_ir_msg
))
8336 _scsih_sas_ir_operation_status_event_debug(ioc
,
8339 /* code added for raid transport support */
8340 if (event_data
->RAIDOperation
== MPI2_EVENT_IR_RAIDOP_RESYNC
) {
8342 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8343 handle
= le16_to_cpu(event_data
->VolDevHandle
);
8344 raid_device
= mpt3sas_raid_device_find_by_handle(ioc
, handle
);
8346 raid_device
->percent_complete
=
8347 event_data
->PercentComplete
;
8348 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8353 * _scsih_prep_device_scan - initialize parameters prior to device scan
8354 * @ioc: per adapter object
8356 * Set the deleted flag prior to device scan. If the device is found during
8357 * the scan, then we clear the deleted flag.
8360 _scsih_prep_device_scan(struct MPT3SAS_ADAPTER
*ioc
)
8362 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
8363 struct scsi_device
*sdev
;
8365 shost_for_each_device(sdev
, ioc
->shost
) {
8366 sas_device_priv_data
= sdev
->hostdata
;
8367 if (sas_device_priv_data
&& sas_device_priv_data
->sas_target
)
8368 sas_device_priv_data
->sas_target
->deleted
= 1;
8373 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
8374 * @ioc: per adapter object
8375 * @sas_device_pg0: SAS Device page 0
8377 * After host reset, find out whether devices are still responding.
8378 * Used in _scsih_remove_unresponsive_sas_devices.
8381 _scsih_mark_responding_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
8382 Mpi2SasDevicePage0_t
*sas_device_pg0
)
8384 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8385 struct scsi_target
*starget
;
8386 struct _sas_device
*sas_device
= NULL
;
8387 struct _enclosure_node
*enclosure_dev
= NULL
;
8388 unsigned long flags
;
8390 if (sas_device_pg0
->EnclosureHandle
) {
8392 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
8393 le16_to_cpu(sas_device_pg0
->EnclosureHandle
));
8394 if (enclosure_dev
== NULL
)
8395 ioc_info(ioc
, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
8396 sas_device_pg0
->EnclosureHandle
);
8398 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8399 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
8400 if ((sas_device
->sas_address
== le64_to_cpu(
8401 sas_device_pg0
->SASAddress
)) && (sas_device
->slot
==
8402 le16_to_cpu(sas_device_pg0
->Slot
))) {
8403 sas_device
->responding
= 1;
8404 starget
= sas_device
->starget
;
8405 if (starget
&& starget
->hostdata
) {
8406 sas_target_priv_data
= starget
->hostdata
;
8407 sas_target_priv_data
->tm_busy
= 0;
8408 sas_target_priv_data
->deleted
= 0;
8410 sas_target_priv_data
= NULL
;
8412 starget_printk(KERN_INFO
, starget
,
8413 "handle(0x%04x), sas_addr(0x%016llx)\n",
8414 le16_to_cpu(sas_device_pg0
->DevHandle
),
8415 (unsigned long long)
8416 sas_device
->sas_address
);
8418 if (sas_device
->enclosure_handle
!= 0)
8419 starget_printk(KERN_INFO
, starget
,
8420 "enclosure logical id(0x%016llx),"
8422 (unsigned long long)
8423 sas_device
->enclosure_logical_id
,
8426 if (le16_to_cpu(sas_device_pg0
->Flags
) &
8427 MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID
) {
8428 sas_device
->enclosure_level
=
8429 sas_device_pg0
->EnclosureLevel
;
8430 memcpy(&sas_device
->connector_name
[0],
8431 &sas_device_pg0
->ConnectorName
[0], 4);
8433 sas_device
->enclosure_level
= 0;
8434 sas_device
->connector_name
[0] = '\0';
8437 sas_device
->enclosure_handle
=
8438 le16_to_cpu(sas_device_pg0
->EnclosureHandle
);
8439 sas_device
->is_chassis_slot_valid
= 0;
8440 if (enclosure_dev
) {
8441 sas_device
->enclosure_logical_id
= le64_to_cpu(
8442 enclosure_dev
->pg0
.EnclosureLogicalID
);
8443 if (le16_to_cpu(enclosure_dev
->pg0
.Flags
) &
8444 MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID
) {
8445 sas_device
->is_chassis_slot_valid
= 1;
8446 sas_device
->chassis_slot
=
8447 enclosure_dev
->pg0
.ChassisSlot
;
8451 if (sas_device
->handle
== le16_to_cpu(
8452 sas_device_pg0
->DevHandle
))
8454 pr_info("\thandle changed from(0x%04x)!!!\n",
8455 sas_device
->handle
);
8456 sas_device
->handle
= le16_to_cpu(
8457 sas_device_pg0
->DevHandle
);
8458 if (sas_target_priv_data
)
8459 sas_target_priv_data
->handle
=
8460 le16_to_cpu(sas_device_pg0
->DevHandle
);
8465 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8469 * _scsih_create_enclosure_list_after_reset - Free Existing list,
8470 * And create enclosure list by scanning all Enclosure Page(0)s
8471 * @ioc: per adapter object
8474 _scsih_create_enclosure_list_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
8476 struct _enclosure_node
*enclosure_dev
;
8477 Mpi2ConfigReply_t mpi_reply
;
8478 u16 enclosure_handle
;
8481 /* Free existing enclosure list */
8482 mpt3sas_free_enclosure_list(ioc
);
8484 /* Re constructing enclosure list after reset*/
8485 enclosure_handle
= 0xFFFF;
8488 kzalloc(sizeof(struct _enclosure_node
), GFP_KERNEL
);
8489 if (!enclosure_dev
) {
8490 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8491 __FILE__
, __LINE__
, __func__
);
8494 rc
= mpt3sas_config_get_enclosure_pg0(ioc
, &mpi_reply
,
8495 &enclosure_dev
->pg0
,
8496 MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE
,
8499 if (rc
|| (le16_to_cpu(mpi_reply
.IOCStatus
) &
8500 MPI2_IOCSTATUS_MASK
)) {
8501 kfree(enclosure_dev
);
8504 list_add_tail(&enclosure_dev
->list
,
8505 &ioc
->enclosure_list
);
8507 le16_to_cpu(enclosure_dev
->pg0
.EnclosureHandle
);
8512 * _scsih_search_responding_sas_devices -
8513 * @ioc: per adapter object
8515 * After host reset, find out whether devices are still responding.
8519 _scsih_search_responding_sas_devices(struct MPT3SAS_ADAPTER
*ioc
)
8521 Mpi2SasDevicePage0_t sas_device_pg0
;
8522 Mpi2ConfigReply_t mpi_reply
;
8527 ioc_info(ioc
, "search for end-devices: start\n");
8529 if (list_empty(&ioc
->sas_device_list
))
8533 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
8534 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8536 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8537 MPI2_IOCSTATUS_MASK
;
8538 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8540 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
8541 device_info
= le32_to_cpu(sas_device_pg0
.DeviceInfo
);
8542 if (!(_scsih_is_end_device(device_info
)))
8544 _scsih_mark_responding_sas_device(ioc
, &sas_device_pg0
);
8548 ioc_info(ioc
, "search for end-devices: complete\n");
8552 * _scsih_mark_responding_pcie_device - mark a pcie_device as responding
8553 * @ioc: per adapter object
8554 * @pcie_device_pg0: PCIe Device page 0
8556 * After host reset, find out whether devices are still responding.
8557 * Used in _scsih_remove_unresponding_devices.
8560 _scsih_mark_responding_pcie_device(struct MPT3SAS_ADAPTER
*ioc
,
8561 Mpi26PCIeDevicePage0_t
*pcie_device_pg0
)
8563 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8564 struct scsi_target
*starget
;
8565 struct _pcie_device
*pcie_device
;
8566 unsigned long flags
;
8568 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8569 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
) {
8570 if ((pcie_device
->wwid
== le64_to_cpu(pcie_device_pg0
->WWID
))
8571 && (pcie_device
->slot
== le16_to_cpu(
8572 pcie_device_pg0
->Slot
))) {
8573 pcie_device
->access_status
=
8574 pcie_device_pg0
->AccessStatus
;
8575 pcie_device
->responding
= 1;
8576 starget
= pcie_device
->starget
;
8577 if (starget
&& starget
->hostdata
) {
8578 sas_target_priv_data
= starget
->hostdata
;
8579 sas_target_priv_data
->tm_busy
= 0;
8580 sas_target_priv_data
->deleted
= 0;
8582 sas_target_priv_data
= NULL
;
8584 starget_printk(KERN_INFO
, starget
,
8585 "handle(0x%04x), wwid(0x%016llx) ",
8586 pcie_device
->handle
,
8587 (unsigned long long)pcie_device
->wwid
);
8588 if (pcie_device
->enclosure_handle
!= 0)
8589 starget_printk(KERN_INFO
, starget
,
8590 "enclosure logical id(0x%016llx), "
8592 (unsigned long long)
8593 pcie_device
->enclosure_logical_id
,
8597 if (((le32_to_cpu(pcie_device_pg0
->Flags
)) &
8598 MPI26_PCIEDEV0_FLAGS_ENCL_LEVEL_VALID
) &&
8599 (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)) {
8600 pcie_device
->enclosure_level
=
8601 pcie_device_pg0
->EnclosureLevel
;
8602 memcpy(&pcie_device
->connector_name
[0],
8603 &pcie_device_pg0
->ConnectorName
[0], 4);
8605 pcie_device
->enclosure_level
= 0;
8606 pcie_device
->connector_name
[0] = '\0';
8609 if (pcie_device
->handle
== le16_to_cpu(
8610 pcie_device_pg0
->DevHandle
))
8612 pr_info("\thandle changed from(0x%04x)!!!\n",
8613 pcie_device
->handle
);
8614 pcie_device
->handle
= le16_to_cpu(
8615 pcie_device_pg0
->DevHandle
);
8616 if (sas_target_priv_data
)
8617 sas_target_priv_data
->handle
=
8618 le16_to_cpu(pcie_device_pg0
->DevHandle
);
8624 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8628 * _scsih_search_responding_pcie_devices -
8629 * @ioc: per adapter object
8631 * After host reset, find out whether devices are still responding.
8635 _scsih_search_responding_pcie_devices(struct MPT3SAS_ADAPTER
*ioc
)
8637 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
8638 Mpi2ConfigReply_t mpi_reply
;
8643 ioc_info(ioc
, "search for end-devices: start\n");
8645 if (list_empty(&ioc
->pcie_device_list
))
8649 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
8650 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
8652 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8653 MPI2_IOCSTATUS_MASK
;
8654 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
8655 ioc_info(ioc
, "\tbreak from %s: ioc_status(0x%04x), loginfo(0x%08x)\n",
8656 __func__
, ioc_status
,
8657 le32_to_cpu(mpi_reply
.IOCLogInfo
));
8660 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
8661 device_info
= le32_to_cpu(pcie_device_pg0
.DeviceInfo
);
8662 if (!(_scsih_is_nvme_pciescsi_device(device_info
)))
8664 _scsih_mark_responding_pcie_device(ioc
, &pcie_device_pg0
);
8667 ioc_info(ioc
, "search for PCIe end-devices: complete\n");
8671 * _scsih_mark_responding_raid_device - mark a raid_device as responding
8672 * @ioc: per adapter object
8673 * @wwid: world wide identifier for raid volume
8674 * @handle: device handle
8676 * After host reset, find out whether devices are still responding.
8677 * Used in _scsih_remove_unresponsive_raid_devices.
8680 _scsih_mark_responding_raid_device(struct MPT3SAS_ADAPTER
*ioc
, u64 wwid
,
8683 struct MPT3SAS_TARGET
*sas_target_priv_data
= NULL
;
8684 struct scsi_target
*starget
;
8685 struct _raid_device
*raid_device
;
8686 unsigned long flags
;
8688 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8689 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
8690 if (raid_device
->wwid
== wwid
&& raid_device
->starget
) {
8691 starget
= raid_device
->starget
;
8692 if (starget
&& starget
->hostdata
) {
8693 sas_target_priv_data
= starget
->hostdata
;
8694 sas_target_priv_data
->deleted
= 0;
8696 sas_target_priv_data
= NULL
;
8697 raid_device
->responding
= 1;
8698 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8699 starget_printk(KERN_INFO
, raid_device
->starget
,
8700 "handle(0x%04x), wwid(0x%016llx)\n", handle
,
8701 (unsigned long long)raid_device
->wwid
);
8704 * WARPDRIVE: The handles of the PDs might have changed
8705 * across the host reset so re-initialize the
8706 * required data for Direct IO
8708 mpt3sas_init_warpdrive_properties(ioc
, raid_device
);
8709 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
8710 if (raid_device
->handle
== handle
) {
8711 spin_unlock_irqrestore(&ioc
->raid_device_lock
,
8715 pr_info("\thandle changed from(0x%04x)!!!\n",
8716 raid_device
->handle
);
8717 raid_device
->handle
= handle
;
8718 if (sas_target_priv_data
)
8719 sas_target_priv_data
->handle
= handle
;
8720 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8724 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
8728 * _scsih_search_responding_raid_devices -
8729 * @ioc: per adapter object
8731 * After host reset, find out whether devices are still responding.
8735 _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER
*ioc
)
8737 Mpi2RaidVolPage1_t volume_pg1
;
8738 Mpi2RaidVolPage0_t volume_pg0
;
8739 Mpi2RaidPhysDiskPage0_t pd_pg0
;
8740 Mpi2ConfigReply_t mpi_reply
;
8745 if (!ioc
->ir_firmware
)
8748 ioc_info(ioc
, "search for raid volumes: start\n");
8750 if (list_empty(&ioc
->raid_device_list
))
8754 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
8755 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
8756 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8757 MPI2_IOCSTATUS_MASK
;
8758 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8760 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
8762 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
8763 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
8764 sizeof(Mpi2RaidVolPage0_t
)))
8767 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
8768 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
8769 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
)
8770 _scsih_mark_responding_raid_device(ioc
,
8771 le64_to_cpu(volume_pg1
.WWID
), handle
);
8774 /* refresh the pd_handles */
8775 if (!ioc
->is_warpdrive
) {
8776 phys_disk_num
= 0xFF;
8777 memset(ioc
->pd_handles
, 0, ioc
->pd_handles_sz
);
8778 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
8779 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
8781 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8782 MPI2_IOCSTATUS_MASK
;
8783 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8785 phys_disk_num
= pd_pg0
.PhysDiskNum
;
8786 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
8787 set_bit(handle
, ioc
->pd_handles
);
8791 ioc_info(ioc
, "search for responding raid volumes: complete\n");
8795 * _scsih_mark_responding_expander - mark a expander as responding
8796 * @ioc: per adapter object
8797 * @expander_pg0:SAS Expander Config Page0
8799 * After host reset, find out whether devices are still responding.
8800 * Used in _scsih_remove_unresponsive_expanders.
8803 _scsih_mark_responding_expander(struct MPT3SAS_ADAPTER
*ioc
,
8804 Mpi2ExpanderPage0_t
*expander_pg0
)
8806 struct _sas_node
*sas_expander
= NULL
;
8807 unsigned long flags
;
8809 struct _enclosure_node
*enclosure_dev
= NULL
;
8810 u16 handle
= le16_to_cpu(expander_pg0
->DevHandle
);
8811 u16 enclosure_handle
= le16_to_cpu(expander_pg0
->EnclosureHandle
);
8812 u64 sas_address
= le64_to_cpu(expander_pg0
->SASAddress
);
8814 if (enclosure_handle
)
8816 mpt3sas_scsih_enclosure_find_by_handle(ioc
,
8819 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8820 list_for_each_entry(sas_expander
, &ioc
->sas_expander_list
, list
) {
8821 if (sas_expander
->sas_address
!= sas_address
)
8823 sas_expander
->responding
= 1;
8825 if (enclosure_dev
) {
8826 sas_expander
->enclosure_logical_id
=
8827 le64_to_cpu(enclosure_dev
->pg0
.EnclosureLogicalID
);
8828 sas_expander
->enclosure_handle
=
8829 le16_to_cpu(expander_pg0
->EnclosureHandle
);
8832 if (sas_expander
->handle
== handle
)
8834 pr_info("\texpander(0x%016llx): handle changed" \
8835 " from(0x%04x) to (0x%04x)!!!\n",
8836 (unsigned long long)sas_expander
->sas_address
,
8837 sas_expander
->handle
, handle
);
8838 sas_expander
->handle
= handle
;
8839 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++)
8840 sas_expander
->phy
[i
].handle
= handle
;
8844 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8848 * _scsih_search_responding_expanders -
8849 * @ioc: per adapter object
8851 * After host reset, find out whether devices are still responding.
8855 _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER
*ioc
)
8857 Mpi2ExpanderPage0_t expander_pg0
;
8858 Mpi2ConfigReply_t mpi_reply
;
8863 ioc_info(ioc
, "search for expanders: start\n");
8865 if (list_empty(&ioc
->sas_expander_list
))
8869 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
8870 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
8872 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
8873 MPI2_IOCSTATUS_MASK
;
8874 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
8877 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
8878 sas_address
= le64_to_cpu(expander_pg0
.SASAddress
);
8879 pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n",
8881 (unsigned long long)sas_address
);
8882 _scsih_mark_responding_expander(ioc
, &expander_pg0
);
8886 ioc_info(ioc
, "search for expanders: complete\n");
8890 * _scsih_remove_unresponding_devices - removing unresponding devices
8891 * @ioc: per adapter object
8894 _scsih_remove_unresponding_devices(struct MPT3SAS_ADAPTER
*ioc
)
8896 struct _sas_device
*sas_device
, *sas_device_next
;
8897 struct _sas_node
*sas_expander
, *sas_expander_next
;
8898 struct _raid_device
*raid_device
, *raid_device_next
;
8899 struct _pcie_device
*pcie_device
, *pcie_device_next
;
8900 struct list_head tmp_list
;
8901 unsigned long flags
;
8904 ioc_info(ioc
, "removing unresponding devices: start\n");
8906 /* removing unresponding end devices */
8907 ioc_info(ioc
, "removing unresponding devices: end-devices\n");
8909 * Iterate, pulling off devices marked as non-responding. We become the
8910 * owner for the reference the list had on any object we prune.
8912 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
8913 list_for_each_entry_safe(sas_device
, sas_device_next
,
8914 &ioc
->sas_device_list
, list
) {
8915 if (!sas_device
->responding
)
8916 list_move_tail(&sas_device
->list
, &head
);
8918 sas_device
->responding
= 0;
8920 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
8923 * Now, uninitialize and remove the unresponding devices we pruned.
8925 list_for_each_entry_safe(sas_device
, sas_device_next
, &head
, list
) {
8926 _scsih_remove_device(ioc
, sas_device
);
8927 list_del_init(&sas_device
->list
);
8928 sas_device_put(sas_device
);
8931 ioc_info(ioc
, "Removing unresponding devices: pcie end-devices\n");
8932 INIT_LIST_HEAD(&head
);
8933 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
8934 list_for_each_entry_safe(pcie_device
, pcie_device_next
,
8935 &ioc
->pcie_device_list
, list
) {
8936 if (!pcie_device
->responding
)
8937 list_move_tail(&pcie_device
->list
, &head
);
8939 pcie_device
->responding
= 0;
8941 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
8943 list_for_each_entry_safe(pcie_device
, pcie_device_next
, &head
, list
) {
8944 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
8945 list_del_init(&pcie_device
->list
);
8946 pcie_device_put(pcie_device
);
8949 /* removing unresponding volumes */
8950 if (ioc
->ir_firmware
) {
8951 ioc_info(ioc
, "removing unresponding devices: volumes\n");
8952 list_for_each_entry_safe(raid_device
, raid_device_next
,
8953 &ioc
->raid_device_list
, list
) {
8954 if (!raid_device
->responding
)
8955 _scsih_sas_volume_delete(ioc
,
8956 raid_device
->handle
);
8958 raid_device
->responding
= 0;
8962 /* removing unresponding expanders */
8963 ioc_info(ioc
, "removing unresponding devices: expanders\n");
8964 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
8965 INIT_LIST_HEAD(&tmp_list
);
8966 list_for_each_entry_safe(sas_expander
, sas_expander_next
,
8967 &ioc
->sas_expander_list
, list
) {
8968 if (!sas_expander
->responding
)
8969 list_move_tail(&sas_expander
->list
, &tmp_list
);
8971 sas_expander
->responding
= 0;
8973 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
8974 list_for_each_entry_safe(sas_expander
, sas_expander_next
, &tmp_list
,
8976 _scsih_expander_node_remove(ioc
, sas_expander
);
8979 ioc_info(ioc
, "removing unresponding devices: complete\n");
8981 /* unblock devices */
8982 _scsih_ublock_io_all_device(ioc
);
8986 _scsih_refresh_expander_links(struct MPT3SAS_ADAPTER
*ioc
,
8987 struct _sas_node
*sas_expander
, u16 handle
)
8989 Mpi2ExpanderPage1_t expander_pg1
;
8990 Mpi2ConfigReply_t mpi_reply
;
8993 for (i
= 0 ; i
< sas_expander
->num_phys
; i
++) {
8994 if ((mpt3sas_config_get_expander_pg1(ioc
, &mpi_reply
,
8995 &expander_pg1
, i
, handle
))) {
8996 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
8997 __FILE__
, __LINE__
, __func__
);
9001 mpt3sas_transport_update_links(ioc
, sas_expander
->sas_address
,
9002 le16_to_cpu(expander_pg1
.AttachedDevHandle
), i
,
9003 expander_pg1
.NegotiatedLinkRate
>> 4);
9008 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
9009 * @ioc: per adapter object
9012 _scsih_scan_for_devices_after_reset(struct MPT3SAS_ADAPTER
*ioc
)
9014 Mpi2ExpanderPage0_t expander_pg0
;
9015 Mpi2SasDevicePage0_t sas_device_pg0
;
9016 Mpi26PCIeDevicePage0_t pcie_device_pg0
;
9017 Mpi2RaidVolPage1_t volume_pg1
;
9018 Mpi2RaidVolPage0_t volume_pg0
;
9019 Mpi2RaidPhysDiskPage0_t pd_pg0
;
9020 Mpi2EventIrConfigElement_t element
;
9021 Mpi2ConfigReply_t mpi_reply
;
9024 u16 handle
, parent_handle
;
9026 struct _sas_device
*sas_device
;
9027 struct _pcie_device
*pcie_device
;
9028 struct _sas_node
*expander_device
;
9029 static struct _raid_device
*raid_device
;
9031 unsigned long flags
;
9033 ioc_info(ioc
, "scan devices: start\n");
9035 _scsih_sas_host_refresh(ioc
);
9037 ioc_info(ioc
, "\tscan devices: expanders start\n");
9041 while (!(mpt3sas_config_get_expander_pg0(ioc
, &mpi_reply
, &expander_pg0
,
9042 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL
, handle
))) {
9043 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9044 MPI2_IOCSTATUS_MASK
;
9045 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9046 ioc_info(ioc
, "\tbreak from expander scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9047 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9050 handle
= le16_to_cpu(expander_pg0
.DevHandle
);
9051 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9052 expander_device
= mpt3sas_scsih_expander_find_by_sas_address(
9053 ioc
, le64_to_cpu(expander_pg0
.SASAddress
));
9054 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9055 if (expander_device
)
9056 _scsih_refresh_expander_links(ioc
, expander_device
,
9059 ioc_info(ioc
, "\tBEFORE adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
9061 (u64
)le64_to_cpu(expander_pg0
.SASAddress
));
9062 _scsih_expander_add(ioc
, handle
);
9063 ioc_info(ioc
, "\tAFTER adding expander: handle (0x%04x), sas_addr(0x%016llx)\n",
9065 (u64
)le64_to_cpu(expander_pg0
.SASAddress
));
9069 ioc_info(ioc
, "\tscan devices: expanders complete\n");
9071 if (!ioc
->ir_firmware
)
9074 ioc_info(ioc
, "\tscan devices: phys disk start\n");
9077 phys_disk_num
= 0xFF;
9078 while (!(mpt3sas_config_get_phys_disk_pg0(ioc
, &mpi_reply
,
9079 &pd_pg0
, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM
,
9081 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9082 MPI2_IOCSTATUS_MASK
;
9083 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9084 ioc_info(ioc
, "\tbreak from phys disk scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9085 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9088 phys_disk_num
= pd_pg0
.PhysDiskNum
;
9089 handle
= le16_to_cpu(pd_pg0
.DevHandle
);
9090 sas_device
= mpt3sas_get_sdev_by_handle(ioc
, handle
);
9092 sas_device_put(sas_device
);
9095 if (mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9096 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE
,
9099 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9100 MPI2_IOCSTATUS_MASK
;
9101 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9102 ioc_info(ioc
, "\tbreak from phys disk scan ioc_status(0x%04x), loginfo(0x%08x)\n",
9103 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9106 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9107 if (!_scsih_get_sas_address(ioc
, parent_handle
,
9109 ioc_info(ioc
, "\tBEFORE adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
9111 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9112 mpt3sas_transport_update_links(ioc
, sas_address
,
9113 handle
, sas_device_pg0
.PhyNum
,
9114 MPI2_SAS_NEG_LINK_RATE_1_5
);
9115 set_bit(handle
, ioc
->pd_handles
);
9117 /* This will retry adding the end device.
9118 * _scsih_add_device() will decide on retries and
9119 * return "1" when it should be retried
9121 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9125 ioc_info(ioc
, "\tAFTER adding phys disk: handle (0x%04x), sas_addr(0x%016llx)\n",
9127 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9131 ioc_info(ioc
, "\tscan devices: phys disk complete\n");
9133 ioc_info(ioc
, "\tscan devices: volumes start\n");
9137 while (!(mpt3sas_config_get_raid_volume_pg1(ioc
, &mpi_reply
,
9138 &volume_pg1
, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE
, handle
))) {
9139 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9140 MPI2_IOCSTATUS_MASK
;
9141 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9142 ioc_info(ioc
, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9143 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9146 handle
= le16_to_cpu(volume_pg1
.DevHandle
);
9147 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
9148 raid_device
= _scsih_raid_device_find_by_wwid(ioc
,
9149 le64_to_cpu(volume_pg1
.WWID
));
9150 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
9153 if (mpt3sas_config_get_raid_volume_pg0(ioc
, &mpi_reply
,
9154 &volume_pg0
, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE
, handle
,
9155 sizeof(Mpi2RaidVolPage0_t
)))
9157 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9158 MPI2_IOCSTATUS_MASK
;
9159 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9160 ioc_info(ioc
, "\tbreak from volume scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9161 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9164 if (volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_OPTIMAL
||
9165 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_ONLINE
||
9166 volume_pg0
.VolumeState
== MPI2_RAID_VOL_STATE_DEGRADED
) {
9167 memset(&element
, 0, sizeof(Mpi2EventIrConfigElement_t
));
9168 element
.ReasonCode
= MPI2_EVENT_IR_CHANGE_RC_ADDED
;
9169 element
.VolDevHandle
= volume_pg1
.DevHandle
;
9170 ioc_info(ioc
, "\tBEFORE adding volume: handle (0x%04x)\n",
9171 volume_pg1
.DevHandle
);
9172 _scsih_sas_volume_add(ioc
, &element
);
9173 ioc_info(ioc
, "\tAFTER adding volume: handle (0x%04x)\n",
9174 volume_pg1
.DevHandle
);
9178 ioc_info(ioc
, "\tscan devices: volumes complete\n");
9182 ioc_info(ioc
, "\tscan devices: end devices start\n");
9186 while (!(mpt3sas_config_get_sas_device_pg0(ioc
, &mpi_reply
,
9187 &sas_device_pg0
, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9189 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
9190 MPI2_IOCSTATUS_MASK
;
9191 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9192 ioc_info(ioc
, "\tbreak from end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9193 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9196 handle
= le16_to_cpu(sas_device_pg0
.DevHandle
);
9197 if (!(_scsih_is_end_device(
9198 le32_to_cpu(sas_device_pg0
.DeviceInfo
))))
9200 sas_device
= mpt3sas_get_sdev_by_addr(ioc
,
9201 le64_to_cpu(sas_device_pg0
.SASAddress
));
9203 sas_device_put(sas_device
);
9206 parent_handle
= le16_to_cpu(sas_device_pg0
.ParentDevHandle
);
9207 if (!_scsih_get_sas_address(ioc
, parent_handle
, &sas_address
)) {
9208 ioc_info(ioc
, "\tBEFORE adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
9210 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9211 mpt3sas_transport_update_links(ioc
, sas_address
, handle
,
9212 sas_device_pg0
.PhyNum
, MPI2_SAS_NEG_LINK_RATE_1_5
);
9214 /* This will retry adding the end device.
9215 * _scsih_add_device() will decide on retries and
9216 * return "1" when it should be retried
9218 while (_scsih_add_device(ioc
, handle
, retry_count
++,
9222 ioc_info(ioc
, "\tAFTER adding end device: handle (0x%04x), sas_addr(0x%016llx)\n",
9224 (u64
)le64_to_cpu(sas_device_pg0
.SASAddress
));
9227 ioc_info(ioc
, "\tscan devices: end devices complete\n");
9228 ioc_info(ioc
, "\tscan devices: pcie end devices start\n");
9232 while (!(mpt3sas_config_get_pcie_device_pg0(ioc
, &mpi_reply
,
9233 &pcie_device_pg0
, MPI26_PCIE_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
,
9235 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
)
9236 & MPI2_IOCSTATUS_MASK
;
9237 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
9238 ioc_info(ioc
, "\tbreak from pcie end device scan: ioc_status(0x%04x), loginfo(0x%08x)\n",
9239 ioc_status
, le32_to_cpu(mpi_reply
.IOCLogInfo
));
9242 handle
= le16_to_cpu(pcie_device_pg0
.DevHandle
);
9243 if (!(_scsih_is_nvme_pciescsi_device(
9244 le32_to_cpu(pcie_device_pg0
.DeviceInfo
))))
9246 pcie_device
= mpt3sas_get_pdev_by_wwid(ioc
,
9247 le64_to_cpu(pcie_device_pg0
.WWID
));
9249 pcie_device_put(pcie_device
);
9253 parent_handle
= le16_to_cpu(pcie_device_pg0
.ParentDevHandle
);
9254 _scsih_pcie_add_device(ioc
, handle
);
9256 ioc_info(ioc
, "\tAFTER adding pcie end device: handle (0x%04x), wwid(0x%016llx)\n",
9257 handle
, (u64
)le64_to_cpu(pcie_device_pg0
.WWID
));
9259 ioc_info(ioc
, "\tpcie devices: pcie end devices complete\n");
9260 ioc_info(ioc
, "scan devices: complete\n");
9264 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9265 * @ioc: per adapter object
9267 * The handler for doing any required cleanup or initialization.
9269 void mpt3sas_scsih_pre_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
9271 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_PRE_RESET\n", __func__
));
9275 * mpt3sas_scsih_after_reset_handler - reset callback handler (for scsih)
9276 * @ioc: per adapter object
9278 * The handler for doing any required cleanup or initialization.
9281 mpt3sas_scsih_after_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
9283 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_AFTER_RESET\n", __func__
));
9284 if (ioc
->scsih_cmds
.status
& MPT3_CMD_PENDING
) {
9285 ioc
->scsih_cmds
.status
|= MPT3_CMD_RESET
;
9286 mpt3sas_base_free_smid(ioc
, ioc
->scsih_cmds
.smid
);
9287 complete(&ioc
->scsih_cmds
.done
);
9289 if (ioc
->tm_cmds
.status
& MPT3_CMD_PENDING
) {
9290 ioc
->tm_cmds
.status
|= MPT3_CMD_RESET
;
9291 mpt3sas_base_free_smid(ioc
, ioc
->tm_cmds
.smid
);
9292 complete(&ioc
->tm_cmds
.done
);
9295 memset(ioc
->pend_os_device_add
, 0, ioc
->pend_os_device_add_sz
);
9296 memset(ioc
->device_remove_in_progress
, 0,
9297 ioc
->device_remove_in_progress_sz
);
9298 _scsih_fw_event_cleanup_queue(ioc
);
9299 _scsih_flush_running_cmds(ioc
);
9303 * mpt3sas_scsih_reset_handler - reset callback handler (for scsih)
9304 * @ioc: per adapter object
9306 * The handler for doing any required cleanup or initialization.
9309 mpt3sas_scsih_reset_done_handler(struct MPT3SAS_ADAPTER
*ioc
)
9311 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_DONE_RESET\n", __func__
));
9312 if ((!ioc
->is_driver_loading
) && !(disable_discovery
> 0 &&
9313 !ioc
->sas_hba
.num_phys
)) {
9314 _scsih_prep_device_scan(ioc
);
9315 _scsih_create_enclosure_list_after_reset(ioc
);
9316 _scsih_search_responding_sas_devices(ioc
);
9317 _scsih_search_responding_pcie_devices(ioc
);
9318 _scsih_search_responding_raid_devices(ioc
);
9319 _scsih_search_responding_expanders(ioc
);
9320 _scsih_error_recovery_delete_devices(ioc
);
9325 * _mpt3sas_fw_work - delayed task for processing firmware events
9326 * @ioc: per adapter object
9327 * @fw_event: The fw_event_work object
9331 _mpt3sas_fw_work(struct MPT3SAS_ADAPTER
*ioc
, struct fw_event_work
*fw_event
)
9333 _scsih_fw_event_del_from_list(ioc
, fw_event
);
9335 /* the queue is being flushed so ignore this event */
9336 if (ioc
->remove_host
|| ioc
->pci_error_recovery
) {
9337 fw_event_work_put(fw_event
);
9341 switch (fw_event
->event
) {
9342 case MPT3SAS_PROCESS_TRIGGER_DIAG
:
9343 mpt3sas_process_trigger_data(ioc
,
9344 (struct SL_WH_TRIGGERS_EVENT_DATA_T
*)
9345 fw_event
->event_data
);
9347 case MPT3SAS_REMOVE_UNRESPONDING_DEVICES
:
9348 while (scsi_host_in_recovery(ioc
->shost
) ||
9349 ioc
->shost_recovery
) {
9351 * If we're unloading, bail. Otherwise, this can become
9354 if (ioc
->remove_host
)
9358 _scsih_remove_unresponding_devices(ioc
);
9359 _scsih_scan_for_devices_after_reset(ioc
);
9361 case MPT3SAS_PORT_ENABLE_COMPLETE
:
9362 ioc
->start_scan
= 0;
9363 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
9364 mpt3sas_base_update_missing_delay(ioc
, missing_delay
[0],
9367 ioc_info(ioc
, "port enable: complete from worker thread\n"));
9369 case MPT3SAS_TURN_ON_PFA_LED
:
9370 _scsih_turn_on_pfa_led(ioc
, fw_event
->device_handle
);
9372 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9373 _scsih_sas_topology_change_event(ioc
, fw_event
);
9375 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9376 if (ioc
->logging_level
& MPT_DEBUG_EVENT_WORK_TASK
)
9377 _scsih_sas_device_status_change_event_debug(ioc
,
9378 (Mpi2EventDataSasDeviceStatusChange_t
*)
9379 fw_event
->event_data
);
9381 case MPI2_EVENT_SAS_DISCOVERY
:
9382 _scsih_sas_discovery_event(ioc
, fw_event
);
9384 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
9385 _scsih_sas_device_discovery_error_event(ioc
, fw_event
);
9387 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9388 _scsih_sas_broadcast_primitive_event(ioc
, fw_event
);
9390 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9391 _scsih_sas_enclosure_dev_status_change_event(ioc
,
9394 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9395 _scsih_sas_ir_config_change_event(ioc
, fw_event
);
9397 case MPI2_EVENT_IR_VOLUME
:
9398 _scsih_sas_ir_volume_event(ioc
, fw_event
);
9400 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9401 _scsih_sas_ir_physical_disk_event(ioc
, fw_event
);
9403 case MPI2_EVENT_IR_OPERATION_STATUS
:
9404 _scsih_sas_ir_operation_status_event(ioc
, fw_event
);
9406 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9407 _scsih_pcie_device_status_change_event(ioc
, fw_event
);
9409 case MPI2_EVENT_PCIE_ENUMERATION
:
9410 _scsih_pcie_enumeration_event(ioc
, fw_event
);
9412 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9413 _scsih_pcie_topology_change_event(ioc
, fw_event
);
9418 fw_event_work_put(fw_event
);
9422 * _firmware_event_work
9423 * @work: The fw_event_work object
9426 * wrappers for the work thread handling firmware events
9430 _firmware_event_work(struct work_struct
*work
)
9432 struct fw_event_work
*fw_event
= container_of(work
,
9433 struct fw_event_work
, work
);
9435 _mpt3sas_fw_work(fw_event
->ioc
, fw_event
);
9439 * mpt3sas_scsih_event_callback - firmware event handler (called at ISR time)
9440 * @ioc: per adapter object
9441 * @msix_index: MSIX table index supplied by the OS
9442 * @reply: reply message frame(lower 32bit addr)
9443 * Context: interrupt.
9445 * This function merely adds a new work task into ioc->firmware_event_thread.
9446 * The tasks are worked from _firmware_event_work in user context.
9448 * Return: 1 meaning mf should be freed from _base_interrupt
9449 * 0 means the mf is freed from this function.
9452 mpt3sas_scsih_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
9455 struct fw_event_work
*fw_event
;
9456 Mpi2EventNotificationReply_t
*mpi_reply
;
9459 Mpi26EventDataActiveCableExcept_t
*ActiveCableEventData
;
9461 /* events turned off due to host reset */
9462 if (ioc
->pci_error_recovery
)
9465 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
9467 if (unlikely(!mpi_reply
)) {
9468 ioc_err(ioc
, "mpi_reply not valid at %s:%d/%s()!\n",
9469 __FILE__
, __LINE__
, __func__
);
9473 event
= le16_to_cpu(mpi_reply
->Event
);
9475 if (event
!= MPI2_EVENT_LOG_ENTRY_ADDED
)
9476 mpt3sas_trigger_event(ioc
, event
, 0);
9480 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
9482 Mpi2EventDataSasBroadcastPrimitive_t
*baen_data
=
9483 (Mpi2EventDataSasBroadcastPrimitive_t
*)
9484 mpi_reply
->EventData
;
9486 if (baen_data
->Primitive
!=
9487 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT
)
9490 if (ioc
->broadcast_aen_busy
) {
9491 ioc
->broadcast_aen_pending
++;
9494 ioc
->broadcast_aen_busy
= 1;
9498 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
9499 _scsih_check_topo_delete_events(ioc
,
9500 (Mpi2EventDataSasTopologyChangeList_t
*)
9501 mpi_reply
->EventData
);
9503 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
9504 _scsih_check_pcie_topo_remove_events(ioc
,
9505 (Mpi26EventDataPCIeTopologyChangeList_t
*)
9506 mpi_reply
->EventData
);
9508 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
9509 _scsih_check_ir_config_unhide_events(ioc
,
9510 (Mpi2EventDataIrConfigChangeList_t
*)
9511 mpi_reply
->EventData
);
9513 case MPI2_EVENT_IR_VOLUME
:
9514 _scsih_check_volume_delete_events(ioc
,
9515 (Mpi2EventDataIrVolume_t
*)
9516 mpi_reply
->EventData
);
9518 case MPI2_EVENT_LOG_ENTRY_ADDED
:
9520 Mpi2EventDataLogEntryAdded_t
*log_entry
;
9523 if (!ioc
->is_warpdrive
)
9526 log_entry
= (Mpi2EventDataLogEntryAdded_t
*)
9527 mpi_reply
->EventData
;
9528 log_code
= (u32
*)log_entry
->LogData
;
9530 if (le16_to_cpu(log_entry
->LogEntryQualifier
)
9531 != MPT2_WARPDRIVE_LOGENTRY
)
9534 switch (le32_to_cpu(*log_code
)) {
9535 case MPT2_WARPDRIVE_LC_SSDT
:
9536 ioc_warn(ioc
, "WarpDrive Warning: IO Throttling has occurred in the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
9538 case MPT2_WARPDRIVE_LC_SSDLW
:
9539 ioc_warn(ioc
, "WarpDrive Warning: Program/Erase Cycles for the WarpDrive subsystem in degraded range. Check WarpDrive documentation for additional details.\n");
9541 case MPT2_WARPDRIVE_LC_SSDLF
:
9542 ioc_err(ioc
, "WarpDrive Fatal Error: There are no Program/Erase Cycles for the WarpDrive subsystem. The storage device will be in read-only mode. Check WarpDrive documentation for additional details.\n");
9544 case MPT2_WARPDRIVE_LC_BRMF
:
9545 ioc_err(ioc
, "WarpDrive Fatal Error: The Backup Rail Monitor has failed on the WarpDrive subsystem. Check WarpDrive documentation for additional details.\n");
9551 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
9552 _scsih_sas_device_status_change_event(ioc
,
9553 (Mpi2EventDataSasDeviceStatusChange_t
*)
9554 mpi_reply
->EventData
);
9556 case MPI2_EVENT_IR_OPERATION_STATUS
:
9557 case MPI2_EVENT_SAS_DISCOVERY
:
9558 case MPI2_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
9559 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
9560 case MPI2_EVENT_IR_PHYSICAL_DISK
:
9561 case MPI2_EVENT_PCIE_ENUMERATION
:
9562 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
9565 case MPI2_EVENT_TEMP_THRESHOLD
:
9566 _scsih_temp_threshold_events(ioc
,
9567 (Mpi2EventDataTemperature_t
*)
9568 mpi_reply
->EventData
);
9570 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
9571 ActiveCableEventData
=
9572 (Mpi26EventDataActiveCableExcept_t
*) mpi_reply
->EventData
;
9573 switch (ActiveCableEventData
->ReasonCode
) {
9574 case MPI26_EVENT_ACTIVE_CABLE_INSUFFICIENT_POWER
:
9575 ioc_notice(ioc
, "Currently an active cable with ReceptacleID %d\n",
9576 ActiveCableEventData
->ReceptacleID
);
9577 pr_notice("cannot be powered and devices connected\n");
9578 pr_notice("to this active cable will not be seen\n");
9579 pr_notice("This active cable requires %d mW of power\n",
9580 ActiveCableEventData
->ActiveCablePowerRequirement
);
9583 case MPI26_EVENT_ACTIVE_CABLE_DEGRADED
:
9584 ioc_notice(ioc
, "Currently a cable with ReceptacleID %d\n",
9585 ActiveCableEventData
->ReceptacleID
);
9587 "is not running at optimal speed(12 Gb/s rate)\n");
9593 default: /* ignore the rest */
9597 sz
= le16_to_cpu(mpi_reply
->EventDataLength
) * 4;
9598 fw_event
= alloc_fw_event_work(sz
);
9600 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
9601 __FILE__
, __LINE__
, __func__
);
9605 memcpy(fw_event
->event_data
, mpi_reply
->EventData
, sz
);
9606 fw_event
->ioc
= ioc
;
9607 fw_event
->VF_ID
= mpi_reply
->VF_ID
;
9608 fw_event
->VP_ID
= mpi_reply
->VP_ID
;
9609 fw_event
->event
= event
;
9610 _scsih_fw_event_add(ioc
, fw_event
);
9611 fw_event_work_put(fw_event
);
9616 * _scsih_expander_node_remove - removing expander device from list.
9617 * @ioc: per adapter object
9618 * @sas_expander: the sas_device object
9620 * Removing object and freeing associated memory from the
9621 * ioc->sas_expander_list.
9624 _scsih_expander_node_remove(struct MPT3SAS_ADAPTER
*ioc
,
9625 struct _sas_node
*sas_expander
)
9627 struct _sas_port
*mpt3sas_port
, *next
;
9628 unsigned long flags
;
9630 /* remove sibling ports attached to this expander */
9631 list_for_each_entry_safe(mpt3sas_port
, next
,
9632 &sas_expander
->sas_port_list
, port_list
) {
9633 if (ioc
->shost_recovery
)
9635 if (mpt3sas_port
->remote_identify
.device_type
==
9637 mpt3sas_device_remove_by_sas_address(ioc
,
9638 mpt3sas_port
->remote_identify
.sas_address
);
9639 else if (mpt3sas_port
->remote_identify
.device_type
==
9640 SAS_EDGE_EXPANDER_DEVICE
||
9641 mpt3sas_port
->remote_identify
.device_type
==
9642 SAS_FANOUT_EXPANDER_DEVICE
)
9643 mpt3sas_expander_remove(ioc
,
9644 mpt3sas_port
->remote_identify
.sas_address
);
9647 mpt3sas_transport_port_remove(ioc
, sas_expander
->sas_address
,
9648 sas_expander
->sas_address_parent
);
9650 ioc_info(ioc
, "expander_remove: handle(0x%04x), sas_addr(0x%016llx)\n",
9651 sas_expander
->handle
, (unsigned long long)
9652 sas_expander
->sas_address
);
9654 spin_lock_irqsave(&ioc
->sas_node_lock
, flags
);
9655 list_del(&sas_expander
->list
);
9656 spin_unlock_irqrestore(&ioc
->sas_node_lock
, flags
);
9658 kfree(sas_expander
->phy
);
9659 kfree(sas_expander
);
9663 * _scsih_ir_shutdown - IR shutdown notification
9664 * @ioc: per adapter object
9666 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
9667 * the host system is shutting down.
9670 _scsih_ir_shutdown(struct MPT3SAS_ADAPTER
*ioc
)
9672 Mpi2RaidActionRequest_t
*mpi_request
;
9673 Mpi2RaidActionReply_t
*mpi_reply
;
9676 /* is IR firmware build loaded ? */
9677 if (!ioc
->ir_firmware
)
9680 /* are there any volumes ? */
9681 if (list_empty(&ioc
->raid_device_list
))
9684 mutex_lock(&ioc
->scsih_cmds
.mutex
);
9686 if (ioc
->scsih_cmds
.status
!= MPT3_CMD_NOT_USED
) {
9687 ioc_err(ioc
, "%s: scsih_cmd in use\n", __func__
);
9690 ioc
->scsih_cmds
.status
= MPT3_CMD_PENDING
;
9692 smid
= mpt3sas_base_get_smid(ioc
, ioc
->scsih_cb_idx
);
9694 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
9695 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9699 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
9700 ioc
->scsih_cmds
.smid
= smid
;
9701 memset(mpi_request
, 0, sizeof(Mpi2RaidActionRequest_t
));
9703 mpi_request
->Function
= MPI2_FUNCTION_RAID_ACTION
;
9704 mpi_request
->Action
= MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED
;
9706 if (!ioc
->hide_ir_msg
)
9707 ioc_info(ioc
, "IR shutdown (sending)\n");
9708 init_completion(&ioc
->scsih_cmds
.done
);
9709 ioc
->put_smid_default(ioc
, smid
);
9710 wait_for_completion_timeout(&ioc
->scsih_cmds
.done
, 10*HZ
);
9712 if (!(ioc
->scsih_cmds
.status
& MPT3_CMD_COMPLETE
)) {
9713 ioc_err(ioc
, "%s: timeout\n", __func__
);
9717 if (ioc
->scsih_cmds
.status
& MPT3_CMD_REPLY_VALID
) {
9718 mpi_reply
= ioc
->scsih_cmds
.reply
;
9719 if (!ioc
->hide_ir_msg
)
9720 ioc_info(ioc
, "IR shutdown (complete): ioc_status(0x%04x), loginfo(0x%08x)\n",
9721 le16_to_cpu(mpi_reply
->IOCStatus
),
9722 le32_to_cpu(mpi_reply
->IOCLogInfo
));
9726 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
9727 mutex_unlock(&ioc
->scsih_cmds
.mutex
);
9731 * scsih_remove - detach and remove add host
9732 * @pdev: PCI device struct
9734 * Routine called when unloading the driver.
9736 static void scsih_remove(struct pci_dev
*pdev
)
9738 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9739 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9740 struct _sas_port
*mpt3sas_port
, *next_port
;
9741 struct _raid_device
*raid_device
, *next
;
9742 struct MPT3SAS_TARGET
*sas_target_priv_data
;
9743 struct _pcie_device
*pcie_device
, *pcienext
;
9744 struct workqueue_struct
*wq
;
9745 unsigned long flags
;
9746 Mpi2ConfigReply_t mpi_reply
;
9748 ioc
->remove_host
= 1;
9750 mpt3sas_wait_for_commands_to_complete(ioc
);
9751 _scsih_flush_running_cmds(ioc
);
9753 _scsih_fw_event_cleanup_queue(ioc
);
9755 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9756 wq
= ioc
->firmware_event_thread
;
9757 ioc
->firmware_event_thread
= NULL
;
9758 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9760 destroy_workqueue(wq
);
9762 * Copy back the unmodified ioc page1. so that on next driver load,
9763 * current modified changes on ioc page1 won't take effect.
9765 if (ioc
->is_aero_ioc
)
9766 mpt3sas_config_set_ioc_pg1(ioc
, &mpi_reply
,
9767 &ioc
->ioc_pg1_copy
);
9768 /* release all the volumes */
9769 _scsih_ir_shutdown(ioc
);
9770 sas_remove_host(shost
);
9771 list_for_each_entry_safe(raid_device
, next
, &ioc
->raid_device_list
,
9773 if (raid_device
->starget
) {
9774 sas_target_priv_data
=
9775 raid_device
->starget
->hostdata
;
9776 sas_target_priv_data
->deleted
= 1;
9777 scsi_remove_target(&raid_device
->starget
->dev
);
9779 ioc_info(ioc
, "removing handle(0x%04x), wwid(0x%016llx)\n",
9780 raid_device
->handle
, (u64
)raid_device
->wwid
);
9781 _scsih_raid_device_remove(ioc
, raid_device
);
9783 list_for_each_entry_safe(pcie_device
, pcienext
, &ioc
->pcie_device_list
,
9785 _scsih_pcie_device_remove_from_sml(ioc
, pcie_device
);
9786 list_del_init(&pcie_device
->list
);
9787 pcie_device_put(pcie_device
);
9790 /* free ports attached to the sas_host */
9791 list_for_each_entry_safe(mpt3sas_port
, next_port
,
9792 &ioc
->sas_hba
.sas_port_list
, port_list
) {
9793 if (mpt3sas_port
->remote_identify
.device_type
==
9795 mpt3sas_device_remove_by_sas_address(ioc
,
9796 mpt3sas_port
->remote_identify
.sas_address
);
9797 else if (mpt3sas_port
->remote_identify
.device_type
==
9798 SAS_EDGE_EXPANDER_DEVICE
||
9799 mpt3sas_port
->remote_identify
.device_type
==
9800 SAS_FANOUT_EXPANDER_DEVICE
)
9801 mpt3sas_expander_remove(ioc
,
9802 mpt3sas_port
->remote_identify
.sas_address
);
9805 /* free phys attached to the sas_host */
9806 if (ioc
->sas_hba
.num_phys
) {
9807 kfree(ioc
->sas_hba
.phy
);
9808 ioc
->sas_hba
.phy
= NULL
;
9809 ioc
->sas_hba
.num_phys
= 0;
9812 mpt3sas_base_detach(ioc
);
9813 spin_lock(&gioc_lock
);
9814 list_del(&ioc
->list
);
9815 spin_unlock(&gioc_lock
);
9816 scsi_host_put(shost
);
9820 * scsih_shutdown - routine call during system shutdown
9821 * @pdev: PCI device struct
9824 scsih_shutdown(struct pci_dev
*pdev
)
9826 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9827 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
9828 struct workqueue_struct
*wq
;
9829 unsigned long flags
;
9830 Mpi2ConfigReply_t mpi_reply
;
9832 ioc
->remove_host
= 1;
9834 mpt3sas_wait_for_commands_to_complete(ioc
);
9835 _scsih_flush_running_cmds(ioc
);
9837 _scsih_fw_event_cleanup_queue(ioc
);
9839 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
9840 wq
= ioc
->firmware_event_thread
;
9841 ioc
->firmware_event_thread
= NULL
;
9842 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
9844 destroy_workqueue(wq
);
9846 * Copy back the unmodified ioc page1 so that on next driver load,
9847 * current modified changes on ioc page1 won't take effect.
9849 if (ioc
->is_aero_ioc
)
9850 mpt3sas_config_set_ioc_pg1(ioc
, &mpi_reply
,
9851 &ioc
->ioc_pg1_copy
);
9853 _scsih_ir_shutdown(ioc
);
9854 mpt3sas_base_detach(ioc
);
9859 * _scsih_probe_boot_devices - reports 1st device
9860 * @ioc: per adapter object
9862 * If specified in bios page 2, this routine reports the 1st
9863 * device scsi-ml or sas transport for persistent boot device
9864 * purposes. Please refer to function _scsih_determine_boot_device()
9867 _scsih_probe_boot_devices(struct MPT3SAS_ADAPTER
*ioc
)
9871 struct _sas_device
*sas_device
;
9872 struct _raid_device
*raid_device
;
9873 struct _pcie_device
*pcie_device
;
9875 u64 sas_address_parent
;
9877 unsigned long flags
;
9881 /* no Bios, return immediately */
9882 if (!ioc
->bios_pg3
.BiosVersion
)
9886 if (ioc
->req_boot_device
.device
) {
9887 device
= ioc
->req_boot_device
.device
;
9888 channel
= ioc
->req_boot_device
.channel
;
9889 } else if (ioc
->req_alt_boot_device
.device
) {
9890 device
= ioc
->req_alt_boot_device
.device
;
9891 channel
= ioc
->req_alt_boot_device
.channel
;
9892 } else if (ioc
->current_boot_device
.device
) {
9893 device
= ioc
->current_boot_device
.device
;
9894 channel
= ioc
->current_boot_device
.channel
;
9900 if (channel
== RAID_CHANNEL
) {
9901 raid_device
= device
;
9902 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9903 raid_device
->id
, 0);
9905 _scsih_raid_device_remove(ioc
, raid_device
);
9906 } else if (channel
== PCIE_CHANNEL
) {
9907 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
9908 pcie_device
= device
;
9909 tid
= pcie_device
->id
;
9910 list_move_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
9911 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
9912 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
, tid
, 0);
9914 _scsih_pcie_device_remove(ioc
, pcie_device
);
9916 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9917 sas_device
= device
;
9918 handle
= sas_device
->handle
;
9919 sas_address_parent
= sas_device
->sas_address_parent
;
9920 sas_address
= sas_device
->sas_address
;
9921 list_move_tail(&sas_device
->list
, &ioc
->sas_device_list
);
9922 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9924 if (ioc
->hide_drives
)
9926 if (!mpt3sas_transport_port_add(ioc
, handle
,
9927 sas_address_parent
)) {
9928 _scsih_sas_device_remove(ioc
, sas_device
);
9929 } else if (!sas_device
->starget
) {
9930 if (!ioc
->is_driver_loading
) {
9931 mpt3sas_transport_port_remove(ioc
,
9933 sas_address_parent
);
9934 _scsih_sas_device_remove(ioc
, sas_device
);
9941 * _scsih_probe_raid - reporting raid volumes to scsi-ml
9942 * @ioc: per adapter object
9944 * Called during initial loading of the driver.
9947 _scsih_probe_raid(struct MPT3SAS_ADAPTER
*ioc
)
9949 struct _raid_device
*raid_device
, *raid_next
;
9952 list_for_each_entry_safe(raid_device
, raid_next
,
9953 &ioc
->raid_device_list
, list
) {
9954 if (raid_device
->starget
)
9956 rc
= scsi_add_device(ioc
->shost
, RAID_CHANNEL
,
9957 raid_device
->id
, 0);
9959 _scsih_raid_device_remove(ioc
, raid_device
);
9963 static struct _sas_device
*get_next_sas_device(struct MPT3SAS_ADAPTER
*ioc
)
9965 struct _sas_device
*sas_device
= NULL
;
9966 unsigned long flags
;
9968 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9969 if (!list_empty(&ioc
->sas_device_init_list
)) {
9970 sas_device
= list_first_entry(&ioc
->sas_device_init_list
,
9971 struct _sas_device
, list
);
9972 sas_device_get(sas_device
);
9974 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
9979 static void sas_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
9980 struct _sas_device
*sas_device
)
9982 unsigned long flags
;
9984 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
9987 * Since we dropped the lock during the call to port_add(), we need to
9988 * be careful here that somebody else didn't move or delete this item
9989 * while we were busy with other things.
9991 * If it was on the list, we need a put() for the reference the list
9992 * had. Either way, we need a get() for the destination list.
9994 if (!list_empty(&sas_device
->list
)) {
9995 list_del_init(&sas_device
->list
);
9996 sas_device_put(sas_device
);
9999 sas_device_get(sas_device
);
10000 list_add_tail(&sas_device
->list
, &ioc
->sas_device_list
);
10002 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
10006 * _scsih_probe_sas - reporting sas devices to sas transport
10007 * @ioc: per adapter object
10009 * Called during initial loading of the driver.
10012 _scsih_probe_sas(struct MPT3SAS_ADAPTER
*ioc
)
10014 struct _sas_device
*sas_device
;
10016 if (ioc
->hide_drives
)
10019 while ((sas_device
= get_next_sas_device(ioc
))) {
10020 if (!mpt3sas_transport_port_add(ioc
, sas_device
->handle
,
10021 sas_device
->sas_address_parent
)) {
10022 _scsih_sas_device_remove(ioc
, sas_device
);
10023 sas_device_put(sas_device
);
10025 } else if (!sas_device
->starget
) {
10027 * When asyn scanning is enabled, its not possible to
10028 * remove devices while scanning is turned on due to an
10029 * oops in scsi_sysfs_add_sdev()->add_device()->
10030 * sysfs_addrm_start()
10032 if (!ioc
->is_driver_loading
) {
10033 mpt3sas_transport_port_remove(ioc
,
10034 sas_device
->sas_address
,
10035 sas_device
->sas_address_parent
);
10036 _scsih_sas_device_remove(ioc
, sas_device
);
10037 sas_device_put(sas_device
);
10041 sas_device_make_active(ioc
, sas_device
);
10042 sas_device_put(sas_device
);
10047 * get_next_pcie_device - Get the next pcie device
10048 * @ioc: per adapter object
10050 * Get the next pcie device from pcie_device_init_list list.
10052 * Return: pcie device structure if pcie_device_init_list list is not empty
10053 * otherwise returns NULL
10055 static struct _pcie_device
*get_next_pcie_device(struct MPT3SAS_ADAPTER
*ioc
)
10057 struct _pcie_device
*pcie_device
= NULL
;
10058 unsigned long flags
;
10060 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10061 if (!list_empty(&ioc
->pcie_device_init_list
)) {
10062 pcie_device
= list_first_entry(&ioc
->pcie_device_init_list
,
10063 struct _pcie_device
, list
);
10064 pcie_device_get(pcie_device
);
10066 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10068 return pcie_device
;
10072 * pcie_device_make_active - Add pcie device to pcie_device_list list
10073 * @ioc: per adapter object
10074 * @pcie_device: pcie device object
10076 * Add the pcie device which has registered with SCSI Transport Later to
10077 * pcie_device_list list
10079 static void pcie_device_make_active(struct MPT3SAS_ADAPTER
*ioc
,
10080 struct _pcie_device
*pcie_device
)
10082 unsigned long flags
;
10084 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
10086 if (!list_empty(&pcie_device
->list
)) {
10087 list_del_init(&pcie_device
->list
);
10088 pcie_device_put(pcie_device
);
10090 pcie_device_get(pcie_device
);
10091 list_add_tail(&pcie_device
->list
, &ioc
->pcie_device_list
);
10093 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
10097 * _scsih_probe_pcie - reporting PCIe devices to scsi-ml
10098 * @ioc: per adapter object
10100 * Called during initial loading of the driver.
10103 _scsih_probe_pcie(struct MPT3SAS_ADAPTER
*ioc
)
10105 struct _pcie_device
*pcie_device
;
10108 /* PCIe Device List */
10109 while ((pcie_device
= get_next_pcie_device(ioc
))) {
10110 if (pcie_device
->starget
) {
10111 pcie_device_put(pcie_device
);
10114 if (pcie_device
->access_status
==
10115 MPI26_PCIEDEV0_ASTATUS_DEVICE_BLOCKED
) {
10116 pcie_device_make_active(ioc
, pcie_device
);
10117 pcie_device_put(pcie_device
);
10120 rc
= scsi_add_device(ioc
->shost
, PCIE_CHANNEL
,
10121 pcie_device
->id
, 0);
10123 _scsih_pcie_device_remove(ioc
, pcie_device
);
10124 pcie_device_put(pcie_device
);
10126 } else if (!pcie_device
->starget
) {
10128 * When async scanning is enabled, its not possible to
10129 * remove devices while scanning is turned on due to an
10130 * oops in scsi_sysfs_add_sdev()->add_device()->
10131 * sysfs_addrm_start()
10133 if (!ioc
->is_driver_loading
) {
10134 /* TODO-- Need to find out whether this condition will
10137 _scsih_pcie_device_remove(ioc
, pcie_device
);
10138 pcie_device_put(pcie_device
);
10142 pcie_device_make_active(ioc
, pcie_device
);
10143 pcie_device_put(pcie_device
);
10148 * _scsih_probe_devices - probing for devices
10149 * @ioc: per adapter object
10151 * Called during initial loading of the driver.
10154 _scsih_probe_devices(struct MPT3SAS_ADAPTER
*ioc
)
10156 u16 volume_mapping_flags
;
10158 if (!(ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
))
10159 return; /* return when IOC doesn't support initiator mode */
10161 _scsih_probe_boot_devices(ioc
);
10163 if (ioc
->ir_firmware
) {
10164 volume_mapping_flags
=
10165 le16_to_cpu(ioc
->ioc_pg8
.IRVolumeMappingFlags
) &
10166 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE
;
10167 if (volume_mapping_flags
==
10168 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING
) {
10169 _scsih_probe_raid(ioc
);
10170 _scsih_probe_sas(ioc
);
10172 _scsih_probe_sas(ioc
);
10173 _scsih_probe_raid(ioc
);
10176 _scsih_probe_sas(ioc
);
10177 _scsih_probe_pcie(ioc
);
10182 * scsih_scan_start - scsi lld callback for .scan_start
10183 * @shost: SCSI host pointer
10185 * The shost has the ability to discover targets on its own instead
10186 * of scanning the entire bus. In our implemention, we will kick off
10187 * firmware discovery.
10190 scsih_scan_start(struct Scsi_Host
*shost
)
10192 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10194 if (diag_buffer_enable
!= -1 && diag_buffer_enable
!= 0)
10195 mpt3sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
10196 else if (ioc
->manu_pg11
.HostTraceBufferMaxSizeKB
!= 0)
10197 mpt3sas_enable_diag_buffer(ioc
, 1);
10199 if (disable_discovery
> 0)
10202 ioc
->start_scan
= 1;
10203 rc
= mpt3sas_port_enable(ioc
);
10206 ioc_info(ioc
, "port enable: FAILED\n");
10210 * scsih_scan_finished - scsi lld callback for .scan_finished
10211 * @shost: SCSI host pointer
10212 * @time: elapsed time of the scan in jiffies
10214 * This function will be called periodicallyn until it returns 1 with the
10215 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
10216 * we wait for firmware discovery to complete, then return 1.
10219 scsih_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
10221 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10223 if (disable_discovery
> 0) {
10224 ioc
->is_driver_loading
= 0;
10225 ioc
->wait_for_discovery_to_complete
= 0;
10229 if (time
>= (300 * HZ
)) {
10230 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
10231 ioc_info(ioc
, "port enable: FAILED with timeout (timeout=300s)\n");
10232 ioc
->is_driver_loading
= 0;
10236 if (ioc
->start_scan
)
10239 if (ioc
->start_scan_failed
) {
10240 ioc_info(ioc
, "port enable: FAILED with (ioc_status=0x%08x)\n",
10241 ioc
->start_scan_failed
);
10242 ioc
->is_driver_loading
= 0;
10243 ioc
->wait_for_discovery_to_complete
= 0;
10244 ioc
->remove_host
= 1;
10248 ioc_info(ioc
, "port enable: SUCCESS\n");
10249 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
10251 if (ioc
->wait_for_discovery_to_complete
) {
10252 ioc
->wait_for_discovery_to_complete
= 0;
10253 _scsih_probe_devices(ioc
);
10255 mpt3sas_base_start_watchdog(ioc
);
10256 ioc
->is_driver_loading
= 0;
10260 /* shost template for SAS 2.0 HBA devices */
10261 static struct scsi_host_template mpt2sas_driver_template
= {
10262 .module
= THIS_MODULE
,
10263 .name
= "Fusion MPT SAS Host",
10264 .proc_name
= MPT2SAS_DRIVER_NAME
,
10265 .queuecommand
= scsih_qcmd
,
10266 .target_alloc
= scsih_target_alloc
,
10267 .slave_alloc
= scsih_slave_alloc
,
10268 .slave_configure
= scsih_slave_configure
,
10269 .target_destroy
= scsih_target_destroy
,
10270 .slave_destroy
= scsih_slave_destroy
,
10271 .scan_finished
= scsih_scan_finished
,
10272 .scan_start
= scsih_scan_start
,
10273 .change_queue_depth
= scsih_change_queue_depth
,
10274 .eh_abort_handler
= scsih_abort
,
10275 .eh_device_reset_handler
= scsih_dev_reset
,
10276 .eh_target_reset_handler
= scsih_target_reset
,
10277 .eh_host_reset_handler
= scsih_host_reset
,
10278 .bios_param
= scsih_bios_param
,
10281 .sg_tablesize
= MPT2SAS_SG_DEPTH
,
10282 .max_sectors
= 32767,
10284 .shost_attrs
= mpt3sas_host_attrs
,
10285 .sdev_attrs
= mpt3sas_dev_attrs
,
10286 .track_queue_depth
= 1,
10287 .cmd_size
= sizeof(struct scsiio_tracker
),
10290 /* raid transport support for SAS 2.0 HBA devices */
10291 static struct raid_function_template mpt2sas_raid_functions
= {
10292 .cookie
= &mpt2sas_driver_template
,
10293 .is_raid
= scsih_is_raid
,
10294 .get_resync
= scsih_get_resync
,
10295 .get_state
= scsih_get_state
,
10298 /* shost template for SAS 3.0 HBA devices */
10299 static struct scsi_host_template mpt3sas_driver_template
= {
10300 .module
= THIS_MODULE
,
10301 .name
= "Fusion MPT SAS Host",
10302 .proc_name
= MPT3SAS_DRIVER_NAME
,
10303 .queuecommand
= scsih_qcmd
,
10304 .target_alloc
= scsih_target_alloc
,
10305 .slave_alloc
= scsih_slave_alloc
,
10306 .slave_configure
= scsih_slave_configure
,
10307 .target_destroy
= scsih_target_destroy
,
10308 .slave_destroy
= scsih_slave_destroy
,
10309 .scan_finished
= scsih_scan_finished
,
10310 .scan_start
= scsih_scan_start
,
10311 .change_queue_depth
= scsih_change_queue_depth
,
10312 .eh_abort_handler
= scsih_abort
,
10313 .eh_device_reset_handler
= scsih_dev_reset
,
10314 .eh_target_reset_handler
= scsih_target_reset
,
10315 .eh_host_reset_handler
= scsih_host_reset
,
10316 .bios_param
= scsih_bios_param
,
10319 .sg_tablesize
= MPT3SAS_SG_DEPTH
,
10320 .max_sectors
= 32767,
10321 .max_segment_size
= 0xffffffff,
10323 .shost_attrs
= mpt3sas_host_attrs
,
10324 .sdev_attrs
= mpt3sas_dev_attrs
,
10325 .track_queue_depth
= 1,
10326 .cmd_size
= sizeof(struct scsiio_tracker
),
10329 /* raid transport support for SAS 3.0 HBA devices */
10330 static struct raid_function_template mpt3sas_raid_functions
= {
10331 .cookie
= &mpt3sas_driver_template
,
10332 .is_raid
= scsih_is_raid
,
10333 .get_resync
= scsih_get_resync
,
10334 .get_state
= scsih_get_state
,
10338 * _scsih_determine_hba_mpi_version - determine in which MPI version class
10339 * this device belongs to.
10340 * @pdev: PCI device struct
10342 * return MPI2_VERSION for SAS 2.0 HBA devices,
10343 * MPI25_VERSION for SAS 3.0 HBA devices, and
10344 * MPI26 VERSION for Cutlass & Invader SAS 3.0 HBA devices
10347 _scsih_determine_hba_mpi_version(struct pci_dev
*pdev
)
10350 switch (pdev
->device
) {
10351 case MPI2_MFGPAGE_DEVID_SSS6200
:
10352 case MPI2_MFGPAGE_DEVID_SAS2004
:
10353 case MPI2_MFGPAGE_DEVID_SAS2008
:
10354 case MPI2_MFGPAGE_DEVID_SAS2108_1
:
10355 case MPI2_MFGPAGE_DEVID_SAS2108_2
:
10356 case MPI2_MFGPAGE_DEVID_SAS2108_3
:
10357 case MPI2_MFGPAGE_DEVID_SAS2116_1
:
10358 case MPI2_MFGPAGE_DEVID_SAS2116_2
:
10359 case MPI2_MFGPAGE_DEVID_SAS2208_1
:
10360 case MPI2_MFGPAGE_DEVID_SAS2208_2
:
10361 case MPI2_MFGPAGE_DEVID_SAS2208_3
:
10362 case MPI2_MFGPAGE_DEVID_SAS2208_4
:
10363 case MPI2_MFGPAGE_DEVID_SAS2208_5
:
10364 case MPI2_MFGPAGE_DEVID_SAS2208_6
:
10365 case MPI2_MFGPAGE_DEVID_SAS2308_1
:
10366 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
10367 case MPI2_MFGPAGE_DEVID_SAS2308_3
:
10368 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP
:
10369 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1
:
10370 return MPI2_VERSION
;
10371 case MPI25_MFGPAGE_DEVID_SAS3004
:
10372 case MPI25_MFGPAGE_DEVID_SAS3008
:
10373 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
10374 case MPI25_MFGPAGE_DEVID_SAS3108_2
:
10375 case MPI25_MFGPAGE_DEVID_SAS3108_5
:
10376 case MPI25_MFGPAGE_DEVID_SAS3108_6
:
10377 return MPI25_VERSION
;
10378 case MPI26_MFGPAGE_DEVID_SAS3216
:
10379 case MPI26_MFGPAGE_DEVID_SAS3224
:
10380 case MPI26_MFGPAGE_DEVID_SAS3316_1
:
10381 case MPI26_MFGPAGE_DEVID_SAS3316_2
:
10382 case MPI26_MFGPAGE_DEVID_SAS3316_3
:
10383 case MPI26_MFGPAGE_DEVID_SAS3316_4
:
10384 case MPI26_MFGPAGE_DEVID_SAS3324_1
:
10385 case MPI26_MFGPAGE_DEVID_SAS3324_2
:
10386 case MPI26_MFGPAGE_DEVID_SAS3324_3
:
10387 case MPI26_MFGPAGE_DEVID_SAS3324_4
:
10388 case MPI26_MFGPAGE_DEVID_SAS3508
:
10389 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10390 case MPI26_MFGPAGE_DEVID_SAS3408
:
10391 case MPI26_MFGPAGE_DEVID_SAS3516
:
10392 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10393 case MPI26_MFGPAGE_DEVID_SAS3416
:
10394 case MPI26_MFGPAGE_DEVID_SAS3616
:
10395 case MPI26_ATLAS_PCIe_SWITCH_DEVID
:
10396 case MPI26_MFGPAGE_DEVID_CFG_SEC_3916
:
10397 case MPI26_MFGPAGE_DEVID_HARD_SEC_3916
:
10398 case MPI26_MFGPAGE_DEVID_CFG_SEC_3816
:
10399 case MPI26_MFGPAGE_DEVID_HARD_SEC_3816
:
10400 return MPI26_VERSION
;
10406 * _scsih_probe - attach and add scsi host
10407 * @pdev: PCI device struct
10408 * @id: pci device id
10410 * Return: 0 success, anything else error.
10413 _scsih_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
10415 struct MPT3SAS_ADAPTER
*ioc
;
10416 struct Scsi_Host
*shost
= NULL
;
10418 u16 hba_mpi_version
;
10420 /* Determine in which MPI version class this pci device belongs */
10421 hba_mpi_version
= _scsih_determine_hba_mpi_version(pdev
);
10422 if (hba_mpi_version
== 0)
10425 /* Enumerate only SAS 2.0 HBA's if hbas_to_enumerate is one,
10426 * for other generation HBA's return with -ENODEV
10428 if ((hbas_to_enumerate
== 1) && (hba_mpi_version
!= MPI2_VERSION
))
10431 /* Enumerate only SAS 3.0 HBA's if hbas_to_enumerate is two,
10432 * for other generation HBA's return with -ENODEV
10434 if ((hbas_to_enumerate
== 2) && (!(hba_mpi_version
== MPI25_VERSION
10435 || hba_mpi_version
== MPI26_VERSION
)))
10438 switch (hba_mpi_version
) {
10440 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
|
10441 PCIE_LINK_STATE_L1
| PCIE_LINK_STATE_CLKPM
);
10442 /* Use mpt2sas driver host template for SAS 2.0 HBA's */
10443 shost
= scsi_host_alloc(&mpt2sas_driver_template
,
10444 sizeof(struct MPT3SAS_ADAPTER
));
10447 ioc
= shost_priv(shost
);
10448 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10449 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10450 ioc
->id
= mpt2_ids
++;
10451 sprintf(ioc
->driver_name
, "%s", MPT2SAS_DRIVER_NAME
);
10452 switch (pdev
->device
) {
10453 case MPI2_MFGPAGE_DEVID_SSS6200
:
10454 ioc
->is_warpdrive
= 1;
10455 ioc
->hide_ir_msg
= 1;
10457 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP
:
10458 case MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1
:
10459 ioc
->is_mcpu_endpoint
= 1;
10462 ioc
->mfg_pg10_hide_flag
= MFG_PAGE10_EXPOSE_ALL_DISKS
;
10466 case MPI25_VERSION
:
10467 case MPI26_VERSION
:
10468 /* Use mpt3sas driver host template for SAS 3.0 HBA's */
10469 shost
= scsi_host_alloc(&mpt3sas_driver_template
,
10470 sizeof(struct MPT3SAS_ADAPTER
));
10473 ioc
= shost_priv(shost
);
10474 memset(ioc
, 0, sizeof(struct MPT3SAS_ADAPTER
));
10475 ioc
->hba_mpi_version_belonged
= hba_mpi_version
;
10476 ioc
->id
= mpt3_ids
++;
10477 sprintf(ioc
->driver_name
, "%s", MPT3SAS_DRIVER_NAME
);
10478 switch (pdev
->device
) {
10479 case MPI26_MFGPAGE_DEVID_SAS3508
:
10480 case MPI26_MFGPAGE_DEVID_SAS3508_1
:
10481 case MPI26_MFGPAGE_DEVID_SAS3408
:
10482 case MPI26_MFGPAGE_DEVID_SAS3516
:
10483 case MPI26_MFGPAGE_DEVID_SAS3516_1
:
10484 case MPI26_MFGPAGE_DEVID_SAS3416
:
10485 case MPI26_MFGPAGE_DEVID_SAS3616
:
10486 case MPI26_ATLAS_PCIe_SWITCH_DEVID
:
10487 ioc
->is_gen35_ioc
= 1;
10489 case MPI26_MFGPAGE_DEVID_CFG_SEC_3816
:
10490 case MPI26_MFGPAGE_DEVID_CFG_SEC_3916
:
10491 dev_info(&pdev
->dev
,
10492 "HBA is in Configurable Secure mode\n");
10494 case MPI26_MFGPAGE_DEVID_HARD_SEC_3816
:
10495 case MPI26_MFGPAGE_DEVID_HARD_SEC_3916
:
10496 ioc
->is_aero_ioc
= ioc
->is_gen35_ioc
= 1;
10499 ioc
->is_gen35_ioc
= ioc
->is_aero_ioc
= 0;
10501 if ((ioc
->hba_mpi_version_belonged
== MPI25_VERSION
&&
10502 pdev
->revision
>= SAS3_PCI_DEVICE_C0_REVISION
) ||
10503 (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
)) {
10504 ioc
->combined_reply_queue
= 1;
10505 if (ioc
->is_gen35_ioc
)
10506 ioc
->combined_reply_index_count
=
10507 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G35
;
10509 ioc
->combined_reply_index_count
=
10510 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT_G3
;
10517 INIT_LIST_HEAD(&ioc
->list
);
10518 spin_lock(&gioc_lock
);
10519 list_add_tail(&ioc
->list
, &mpt3sas_ioc_list
);
10520 spin_unlock(&gioc_lock
);
10521 ioc
->shost
= shost
;
10523 ioc
->scsi_io_cb_idx
= scsi_io_cb_idx
;
10524 ioc
->tm_cb_idx
= tm_cb_idx
;
10525 ioc
->ctl_cb_idx
= ctl_cb_idx
;
10526 ioc
->base_cb_idx
= base_cb_idx
;
10527 ioc
->port_enable_cb_idx
= port_enable_cb_idx
;
10528 ioc
->transport_cb_idx
= transport_cb_idx
;
10529 ioc
->scsih_cb_idx
= scsih_cb_idx
;
10530 ioc
->config_cb_idx
= config_cb_idx
;
10531 ioc
->tm_tr_cb_idx
= tm_tr_cb_idx
;
10532 ioc
->tm_tr_volume_cb_idx
= tm_tr_volume_cb_idx
;
10533 ioc
->tm_sas_control_cb_idx
= tm_sas_control_cb_idx
;
10534 ioc
->logging_level
= logging_level
;
10535 ioc
->schedule_dead_ioc_flush_running_cmds
= &_scsih_flush_running_cmds
;
10537 * Enable MEMORY MOVE support flag.
10539 ioc
->drv_support_bitmap
|= MPT_DRV_SUPPORT_BITMAP_MEMMOVE
;
10541 ioc
->enable_sdev_max_qd
= enable_sdev_max_qd
;
10543 /* misc semaphores and spin locks */
10544 mutex_init(&ioc
->reset_in_progress_mutex
);
10545 /* initializing pci_access_mutex lock */
10546 mutex_init(&ioc
->pci_access_mutex
);
10547 spin_lock_init(&ioc
->ioc_reset_in_progress_lock
);
10548 spin_lock_init(&ioc
->scsi_lookup_lock
);
10549 spin_lock_init(&ioc
->sas_device_lock
);
10550 spin_lock_init(&ioc
->sas_node_lock
);
10551 spin_lock_init(&ioc
->fw_event_lock
);
10552 spin_lock_init(&ioc
->raid_device_lock
);
10553 spin_lock_init(&ioc
->pcie_device_lock
);
10554 spin_lock_init(&ioc
->diag_trigger_lock
);
10556 INIT_LIST_HEAD(&ioc
->sas_device_list
);
10557 INIT_LIST_HEAD(&ioc
->sas_device_init_list
);
10558 INIT_LIST_HEAD(&ioc
->sas_expander_list
);
10559 INIT_LIST_HEAD(&ioc
->enclosure_list
);
10560 INIT_LIST_HEAD(&ioc
->pcie_device_list
);
10561 INIT_LIST_HEAD(&ioc
->pcie_device_init_list
);
10562 INIT_LIST_HEAD(&ioc
->fw_event_list
);
10563 INIT_LIST_HEAD(&ioc
->raid_device_list
);
10564 INIT_LIST_HEAD(&ioc
->sas_hba
.sas_port_list
);
10565 INIT_LIST_HEAD(&ioc
->delayed_tr_list
);
10566 INIT_LIST_HEAD(&ioc
->delayed_sc_list
);
10567 INIT_LIST_HEAD(&ioc
->delayed_event_ack_list
);
10568 INIT_LIST_HEAD(&ioc
->delayed_tr_volume_list
);
10569 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
10571 sprintf(ioc
->name
, "%s_cm%d", ioc
->driver_name
, ioc
->id
);
10573 /* init shost parameters */
10574 shost
->max_cmd_len
= 32;
10575 shost
->max_lun
= max_lun
;
10576 shost
->transportt
= mpt3sas_transport_template
;
10577 shost
->unique_id
= ioc
->id
;
10579 if (ioc
->is_mcpu_endpoint
) {
10580 /* mCPU MPI support 64K max IO */
10581 shost
->max_sectors
= 128;
10582 ioc_info(ioc
, "The max_sectors value is set to %d\n",
10583 shost
->max_sectors
);
10585 if (max_sectors
!= 0xFFFF) {
10586 if (max_sectors
< 64) {
10587 shost
->max_sectors
= 64;
10588 ioc_warn(ioc
, "Invalid value %d passed for max_sectors, range is 64 to 32767. Assigning value of 64.\n",
10590 } else if (max_sectors
> 32767) {
10591 shost
->max_sectors
= 32767;
10592 ioc_warn(ioc
, "Invalid value %d passed for max_sectors, range is 64 to 32767.Assigning default value of 32767.\n",
10595 shost
->max_sectors
= max_sectors
& 0xFFFE;
10596 ioc_info(ioc
, "The max_sectors value is set to %d\n",
10597 shost
->max_sectors
);
10601 /* register EEDP capabilities with SCSI layer */
10603 scsi_host_set_prot(shost
, prot_mask
);
10605 scsi_host_set_prot(shost
, SHOST_DIF_TYPE1_PROTECTION
10606 | SHOST_DIF_TYPE2_PROTECTION
10607 | SHOST_DIF_TYPE3_PROTECTION
);
10609 scsi_host_set_guard(shost
, SHOST_DIX_GUARD_CRC
);
10612 snprintf(ioc
->firmware_event_name
, sizeof(ioc
->firmware_event_name
),
10613 "fw_event_%s%d", ioc
->driver_name
, ioc
->id
);
10614 ioc
->firmware_event_thread
= alloc_ordered_workqueue(
10615 ioc
->firmware_event_name
, 0);
10616 if (!ioc
->firmware_event_thread
) {
10617 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
10618 __FILE__
, __LINE__
, __func__
);
10620 goto out_thread_fail
;
10623 ioc
->is_driver_loading
= 1;
10624 if ((mpt3sas_base_attach(ioc
))) {
10625 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
10626 __FILE__
, __LINE__
, __func__
);
10628 goto out_attach_fail
;
10631 if (ioc
->is_warpdrive
) {
10632 if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_EXPOSE_ALL_DISKS
)
10633 ioc
->hide_drives
= 0;
10634 else if (ioc
->mfg_pg10_hide_flag
== MFG_PAGE10_HIDE_ALL_DISKS
)
10635 ioc
->hide_drives
= 1;
10637 if (mpt3sas_get_num_volumes(ioc
))
10638 ioc
->hide_drives
= 1;
10640 ioc
->hide_drives
= 0;
10643 ioc
->hide_drives
= 0;
10645 rv
= scsi_add_host(shost
, &pdev
->dev
);
10647 ioc_err(ioc
, "failure at %s:%d/%s()!\n",
10648 __FILE__
, __LINE__
, __func__
);
10649 goto out_add_shost_fail
;
10652 scsi_scan_host(shost
);
10654 out_add_shost_fail
:
10655 mpt3sas_base_detach(ioc
);
10657 destroy_workqueue(ioc
->firmware_event_thread
);
10659 spin_lock(&gioc_lock
);
10660 list_del(&ioc
->list
);
10661 spin_unlock(&gioc_lock
);
10662 scsi_host_put(shost
);
10668 * scsih_suspend - power management suspend main entry point
10669 * @pdev: PCI device struct
10670 * @state: PM state change to (usually PCI_D3)
10672 * Return: 0 success, anything else error.
10675 scsih_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10677 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10678 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10679 pci_power_t device_state
;
10681 mpt3sas_base_stop_watchdog(ioc
);
10682 flush_scheduled_work();
10683 scsi_block_requests(shost
);
10684 device_state
= pci_choose_state(pdev
, state
);
10685 ioc_info(ioc
, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
10686 pdev
, pci_name(pdev
), device_state
);
10688 pci_save_state(pdev
);
10689 mpt3sas_base_free_resources(ioc
);
10690 pci_set_power_state(pdev
, device_state
);
10695 * scsih_resume - power management resume main entry point
10696 * @pdev: PCI device struct
10698 * Return: 0 success, anything else error.
10701 scsih_resume(struct pci_dev
*pdev
)
10703 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10704 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10705 pci_power_t device_state
= pdev
->current_state
;
10708 ioc_info(ioc
, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
10709 pdev
, pci_name(pdev
), device_state
);
10711 pci_set_power_state(pdev
, PCI_D0
);
10712 pci_enable_wake(pdev
, PCI_D0
, 0);
10713 pci_restore_state(pdev
);
10715 r
= mpt3sas_base_map_resources(ioc
);
10719 mpt3sas_base_hard_reset_handler(ioc
, SOFT_RESET
);
10720 scsi_unblock_requests(shost
);
10721 mpt3sas_base_start_watchdog(ioc
);
10724 #endif /* CONFIG_PM */
10727 * scsih_pci_error_detected - Called when a PCI error is detected.
10728 * @pdev: PCI device struct
10729 * @state: PCI channel state
10731 * Description: Called when a PCI error is detected.
10733 * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT.
10735 static pci_ers_result_t
10736 scsih_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10738 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10739 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10741 ioc_info(ioc
, "PCI error: detected callback, state(%d)!!\n", state
);
10744 case pci_channel_io_normal
:
10745 return PCI_ERS_RESULT_CAN_RECOVER
;
10746 case pci_channel_io_frozen
:
10747 /* Fatal error, prepare for slot reset */
10748 ioc
->pci_error_recovery
= 1;
10749 scsi_block_requests(ioc
->shost
);
10750 mpt3sas_base_stop_watchdog(ioc
);
10751 mpt3sas_base_free_resources(ioc
);
10752 return PCI_ERS_RESULT_NEED_RESET
;
10753 case pci_channel_io_perm_failure
:
10754 /* Permanent error, prepare for device removal */
10755 ioc
->pci_error_recovery
= 1;
10756 mpt3sas_base_stop_watchdog(ioc
);
10757 _scsih_flush_running_cmds(ioc
);
10758 return PCI_ERS_RESULT_DISCONNECT
;
10760 return PCI_ERS_RESULT_NEED_RESET
;
10764 * scsih_pci_slot_reset - Called when PCI slot has been reset.
10765 * @pdev: PCI device struct
10767 * Description: This routine is called by the pci error recovery
10768 * code after the PCI slot has been reset, just before we
10769 * should resume normal operations.
10771 static pci_ers_result_t
10772 scsih_pci_slot_reset(struct pci_dev
*pdev
)
10774 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10775 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10778 ioc_info(ioc
, "PCI error: slot reset callback!!\n");
10780 ioc
->pci_error_recovery
= 0;
10782 pci_restore_state(pdev
);
10783 rc
= mpt3sas_base_map_resources(ioc
);
10785 return PCI_ERS_RESULT_DISCONNECT
;
10787 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
10789 ioc_warn(ioc
, "hard reset: %s\n",
10790 (rc
== 0) ? "success" : "failed");
10793 return PCI_ERS_RESULT_RECOVERED
;
10795 return PCI_ERS_RESULT_DISCONNECT
;
10799 * scsih_pci_resume() - resume normal ops after PCI reset
10800 * @pdev: pointer to PCI device
10802 * Called when the error recovery driver tells us that its
10803 * OK to resume normal operation. Use completion to allow
10804 * halted scsi ops to resume.
10807 scsih_pci_resume(struct pci_dev
*pdev
)
10809 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10810 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10812 ioc_info(ioc
, "PCI error: resume callback!!\n");
10814 mpt3sas_base_start_watchdog(ioc
);
10815 scsi_unblock_requests(ioc
->shost
);
10819 * scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
10820 * @pdev: pointer to PCI device
10822 static pci_ers_result_t
10823 scsih_pci_mmio_enabled(struct pci_dev
*pdev
)
10825 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10826 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
10828 ioc_info(ioc
, "PCI error: mmio enabled callback!!\n");
10830 /* TODO - dump whatever for debugging purposes */
10832 /* This called only if scsih_pci_error_detected returns
10833 * PCI_ERS_RESULT_CAN_RECOVER. Read/write to the device still
10834 * works, no need to reset slot.
10836 return PCI_ERS_RESULT_RECOVERED
;
10840 * scsih__ncq_prio_supp - Check for NCQ command priority support
10841 * @sdev: scsi device struct
10843 * This is called when a user indicates they would like to enable
10844 * ncq command priorities. This works only on SATA devices.
10846 bool scsih_ncq_prio_supp(struct scsi_device
*sdev
)
10848 unsigned char *buf
;
10849 bool ncq_prio_supp
= false;
10851 if (!scsi_device_supports_vpd(sdev
))
10852 return ncq_prio_supp
;
10854 buf
= kmalloc(SCSI_VPD_PG_LEN
, GFP_KERNEL
);
10856 return ncq_prio_supp
;
10858 if (!scsi_get_vpd_page(sdev
, 0x89, buf
, SCSI_VPD_PG_LEN
))
10859 ncq_prio_supp
= (buf
[213] >> 4) & 1;
10862 return ncq_prio_supp
;
10865 * The pci device ids are defined in mpi/mpi2_cnfg.h.
10867 static const struct pci_device_id mpt3sas_pci_table
[] = {
10868 /* Spitfire ~ 2004 */
10869 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2004
,
10870 PCI_ANY_ID
, PCI_ANY_ID
},
10871 /* Falcon ~ 2008 */
10872 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2008
,
10873 PCI_ANY_ID
, PCI_ANY_ID
},
10874 /* Liberator ~ 2108 */
10875 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_1
,
10876 PCI_ANY_ID
, PCI_ANY_ID
},
10877 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_2
,
10878 PCI_ANY_ID
, PCI_ANY_ID
},
10879 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2108_3
,
10880 PCI_ANY_ID
, PCI_ANY_ID
},
10881 /* Meteor ~ 2116 */
10882 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_1
,
10883 PCI_ANY_ID
, PCI_ANY_ID
},
10884 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2116_2
,
10885 PCI_ANY_ID
, PCI_ANY_ID
},
10886 /* Thunderbolt ~ 2208 */
10887 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_1
,
10888 PCI_ANY_ID
, PCI_ANY_ID
},
10889 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_2
,
10890 PCI_ANY_ID
, PCI_ANY_ID
},
10891 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_3
,
10892 PCI_ANY_ID
, PCI_ANY_ID
},
10893 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_4
,
10894 PCI_ANY_ID
, PCI_ANY_ID
},
10895 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_5
,
10896 PCI_ANY_ID
, PCI_ANY_ID
},
10897 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2208_6
,
10898 PCI_ANY_ID
, PCI_ANY_ID
},
10899 /* Mustang ~ 2308 */
10900 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_1
,
10901 PCI_ANY_ID
, PCI_ANY_ID
},
10902 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_2
,
10903 PCI_ANY_ID
, PCI_ANY_ID
},
10904 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SAS2308_3
,
10905 PCI_ANY_ID
, PCI_ANY_ID
},
10906 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP
,
10907 PCI_ANY_ID
, PCI_ANY_ID
},
10908 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SWITCH_MPI_EP_1
,
10909 PCI_ANY_ID
, PCI_ANY_ID
},
10911 { MPI2_MFGPAGE_VENDORID_LSI
, MPI2_MFGPAGE_DEVID_SSS6200
,
10912 PCI_ANY_ID
, PCI_ANY_ID
},
10913 /* Fury ~ 3004 and 3008 */
10914 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3004
,
10915 PCI_ANY_ID
, PCI_ANY_ID
},
10916 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3008
,
10917 PCI_ANY_ID
, PCI_ANY_ID
},
10918 /* Invader ~ 3108 */
10919 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_1
,
10920 PCI_ANY_ID
, PCI_ANY_ID
},
10921 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_2
,
10922 PCI_ANY_ID
, PCI_ANY_ID
},
10923 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_5
,
10924 PCI_ANY_ID
, PCI_ANY_ID
},
10925 { MPI2_MFGPAGE_VENDORID_LSI
, MPI25_MFGPAGE_DEVID_SAS3108_6
,
10926 PCI_ANY_ID
, PCI_ANY_ID
},
10927 /* Cutlass ~ 3216 and 3224 */
10928 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3216
,
10929 PCI_ANY_ID
, PCI_ANY_ID
},
10930 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3224
,
10931 PCI_ANY_ID
, PCI_ANY_ID
},
10932 /* Intruder ~ 3316 and 3324 */
10933 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_1
,
10934 PCI_ANY_ID
, PCI_ANY_ID
},
10935 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_2
,
10936 PCI_ANY_ID
, PCI_ANY_ID
},
10937 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_3
,
10938 PCI_ANY_ID
, PCI_ANY_ID
},
10939 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3316_4
,
10940 PCI_ANY_ID
, PCI_ANY_ID
},
10941 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_1
,
10942 PCI_ANY_ID
, PCI_ANY_ID
},
10943 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_2
,
10944 PCI_ANY_ID
, PCI_ANY_ID
},
10945 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_3
,
10946 PCI_ANY_ID
, PCI_ANY_ID
},
10947 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3324_4
,
10948 PCI_ANY_ID
, PCI_ANY_ID
},
10949 /* Ventura, Crusader, Harpoon & Tomcat ~ 3516, 3416, 3508 & 3408*/
10950 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508
,
10951 PCI_ANY_ID
, PCI_ANY_ID
},
10952 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3508_1
,
10953 PCI_ANY_ID
, PCI_ANY_ID
},
10954 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3408
,
10955 PCI_ANY_ID
, PCI_ANY_ID
},
10956 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516
,
10957 PCI_ANY_ID
, PCI_ANY_ID
},
10958 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3516_1
,
10959 PCI_ANY_ID
, PCI_ANY_ID
},
10960 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3416
,
10961 PCI_ANY_ID
, PCI_ANY_ID
},
10962 /* Mercator ~ 3616*/
10963 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_SAS3616
,
10964 PCI_ANY_ID
, PCI_ANY_ID
},
10966 /* Aero SI 0x00E1 Configurable Secure
10967 * 0x00E2 Hard Secure
10969 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_CFG_SEC_3916
,
10970 PCI_ANY_ID
, PCI_ANY_ID
},
10971 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_HARD_SEC_3916
,
10972 PCI_ANY_ID
, PCI_ANY_ID
},
10974 /* Atlas PCIe Switch Management Port */
10975 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_ATLAS_PCIe_SWITCH_DEVID
,
10976 PCI_ANY_ID
, PCI_ANY_ID
},
10978 /* Sea SI 0x00E5 Configurable Secure
10979 * 0x00E6 Hard Secure
10981 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_CFG_SEC_3816
,
10982 PCI_ANY_ID
, PCI_ANY_ID
},
10983 { MPI2_MFGPAGE_VENDORID_LSI
, MPI26_MFGPAGE_DEVID_HARD_SEC_3816
,
10984 PCI_ANY_ID
, PCI_ANY_ID
},
10986 {0} /* Terminating entry */
10988 MODULE_DEVICE_TABLE(pci
, mpt3sas_pci_table
);
10990 static struct pci_error_handlers _mpt3sas_err_handler
= {
10991 .error_detected
= scsih_pci_error_detected
,
10992 .mmio_enabled
= scsih_pci_mmio_enabled
,
10993 .slot_reset
= scsih_pci_slot_reset
,
10994 .resume
= scsih_pci_resume
,
10997 static struct pci_driver mpt3sas_driver
= {
10998 .name
= MPT3SAS_DRIVER_NAME
,
10999 .id_table
= mpt3sas_pci_table
,
11000 .probe
= _scsih_probe
,
11001 .remove
= scsih_remove
,
11002 .shutdown
= scsih_shutdown
,
11003 .err_handler
= &_mpt3sas_err_handler
,
11005 .suspend
= scsih_suspend
,
11006 .resume
= scsih_resume
,
11011 * scsih_init - main entry point for this driver.
11013 * Return: 0 success, anything else error.
11021 mpt3sas_base_initialize_callback_handler();
11023 /* queuecommand callback hander */
11024 scsi_io_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_io_done
);
11026 /* task management callback handler */
11027 tm_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_tm_done
);
11029 /* base internal commands callback handler */
11030 base_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_base_done
);
11031 port_enable_cb_idx
= mpt3sas_base_register_callback_handler(
11032 mpt3sas_port_enable_done
);
11034 /* transport internal commands callback handler */
11035 transport_cb_idx
= mpt3sas_base_register_callback_handler(
11036 mpt3sas_transport_done
);
11038 /* scsih internal commands callback handler */
11039 scsih_cb_idx
= mpt3sas_base_register_callback_handler(_scsih_done
);
11041 /* configuration page API internal commands callback handler */
11042 config_cb_idx
= mpt3sas_base_register_callback_handler(
11043 mpt3sas_config_done
);
11045 /* ctl module callback handler */
11046 ctl_cb_idx
= mpt3sas_base_register_callback_handler(mpt3sas_ctl_done
);
11048 tm_tr_cb_idx
= mpt3sas_base_register_callback_handler(
11049 _scsih_tm_tr_complete
);
11051 tm_tr_volume_cb_idx
= mpt3sas_base_register_callback_handler(
11052 _scsih_tm_volume_tr_complete
);
11054 tm_sas_control_cb_idx
= mpt3sas_base_register_callback_handler(
11055 _scsih_sas_control_complete
);
11061 * scsih_exit - exit point for this driver (when it is a module).
11063 * Return: 0 success, anything else error.
11069 mpt3sas_base_release_callback_handler(scsi_io_cb_idx
);
11070 mpt3sas_base_release_callback_handler(tm_cb_idx
);
11071 mpt3sas_base_release_callback_handler(base_cb_idx
);
11072 mpt3sas_base_release_callback_handler(port_enable_cb_idx
);
11073 mpt3sas_base_release_callback_handler(transport_cb_idx
);
11074 mpt3sas_base_release_callback_handler(scsih_cb_idx
);
11075 mpt3sas_base_release_callback_handler(config_cb_idx
);
11076 mpt3sas_base_release_callback_handler(ctl_cb_idx
);
11078 mpt3sas_base_release_callback_handler(tm_tr_cb_idx
);
11079 mpt3sas_base_release_callback_handler(tm_tr_volume_cb_idx
);
11080 mpt3sas_base_release_callback_handler(tm_sas_control_cb_idx
);
11082 /* raid transport support */
11083 if (hbas_to_enumerate
!= 1)
11084 raid_class_release(mpt3sas_raid_template
);
11085 if (hbas_to_enumerate
!= 2)
11086 raid_class_release(mpt2sas_raid_template
);
11087 sas_release_transport(mpt3sas_transport_template
);
11091 * _mpt3sas_init - main entry point for this driver.
11093 * Return: 0 success, anything else error.
11096 _mpt3sas_init(void)
11100 pr_info("%s version %s loaded\n", MPT3SAS_DRIVER_NAME
,
11101 MPT3SAS_DRIVER_VERSION
);
11103 mpt3sas_transport_template
=
11104 sas_attach_transport(&mpt3sas_transport_functions
);
11105 if (!mpt3sas_transport_template
)
11108 /* No need attach mpt3sas raid functions template
11109 * if hbas_to_enumarate value is one.
11111 if (hbas_to_enumerate
!= 1) {
11112 mpt3sas_raid_template
=
11113 raid_class_attach(&mpt3sas_raid_functions
);
11114 if (!mpt3sas_raid_template
) {
11115 sas_release_transport(mpt3sas_transport_template
);
11120 /* No need to attach mpt2sas raid functions template
11121 * if hbas_to_enumarate value is two
11123 if (hbas_to_enumerate
!= 2) {
11124 mpt2sas_raid_template
=
11125 raid_class_attach(&mpt2sas_raid_functions
);
11126 if (!mpt2sas_raid_template
) {
11127 sas_release_transport(mpt3sas_transport_template
);
11132 error
= scsih_init();
11138 mpt3sas_ctl_init(hbas_to_enumerate
);
11140 error
= pci_register_driver(&mpt3sas_driver
);
11148 * _mpt3sas_exit - exit point for this driver (when it is a module).
11152 _mpt3sas_exit(void)
11154 pr_info("mpt3sas version %s unloading\n",
11155 MPT3SAS_DRIVER_VERSION
);
11157 mpt3sas_ctl_exit(hbas_to_enumerate
);
11159 pci_unregister_driver(&mpt3sas_driver
);
11164 module_init(_mpt3sas_init
);
11165 module_exit(_mpt3sas_exit
);